diff --git a/include/record_manager.hpp b/include/record_manager.hpp index 9b93f82..084deaa 100644 --- a/include/record_manager.hpp +++ b/include/record_manager.hpp @@ -49,6 +49,7 @@ class RecordManager std::string srs_record_cfg_path_; std::string record_dir_; // /sata/record/ int dvr_duration_sec_ = 60; // 从配置文件读取,默认 60 + int http_port_ = 80; bool loadSrsConfig(); // 解析配置文件,填充 record_dir_ 和 dvr_duration_sec_ diff --git a/include/rtmp_manager.hpp b/include/rtmp_manager.hpp index 392c387..45b6e42 100644 --- a/include/rtmp_manager.hpp +++ b/include/rtmp_manager.hpp @@ -13,6 +13,8 @@ #include "app_config.hpp" #include "logger.hpp" +std::string get_ip_address(const std::string& ifname); + class RTMPManager { public: @@ -26,8 +28,8 @@ class RTMPManager static void init(); static void start_all(); static void stop_all(); - static bool is_streaming(const std::string &cam_name); - static std::string get_stream_url(const std::string &cam_name); + static bool is_streaming(const std::string& cam_name); + static std::string get_stream_url(const std::string& cam_name); // 旧版接口(已保留) static std::vector> get_all_status(); @@ -52,9 +54,9 @@ class RTMPManager StreamStatus status; }; - static void stream_loop(Camera cam, StreamContext *ctx); - static GstElement *create_pipeline(const Camera &cam); - static std::string make_key(const std::string &name); + static void stream_loop(Camera cam, StreamContext* ctx); + static GstElement* create_pipeline(const Camera& cam); + static std::string make_key(const std::string& name); static std::unordered_map> streams; static std::mutex streams_mutex; diff --git a/src/mqtt_client_wrapper.cpp b/src/mqtt_client_wrapper.cpp index 51e582c..5c7800f 100644 --- a/src/mqtt_client_wrapper.cpp +++ b/src/mqtt_client_wrapper.cpp @@ -124,7 +124,7 @@ static void handle_record_query_request(const nlohmann::json& req) int64_t start = d.value("startTime", -1LL); int64_t end = d.value("endTime", -1LL); - if (loc < 0 || start <= 0 || end <= 0) + if (loc < 0 || start <= 0 || end <= 0 || start >= end) { LOG_WARN("[record_query] invalid parameters"); return; diff --git a/src/record_manager.cpp b/src/record_manager.cpp index ae3155a..00cf990 100644 --- a/src/record_manager.cpp +++ b/src/record_manager.cpp @@ -28,6 +28,7 @@ RecordManager::RecordManager(const std::string& srs_record_cfg_path) : srs_recor LOG_INFO("[RecordManager] SRS config loaded successfully."); LOG_INFO("record_dir = " + record_dir_); LOG_INFO("dvr_duration_sec = " + std::to_string(dvr_duration_sec_)); + LOG_INFO("http_port = " + std::to_string(http_port_)); // 自动根据 dvr_duration 启动扫描线程 startAutoScan(dvr_duration_sec_); @@ -48,11 +49,37 @@ bool RecordManager::loadSrsConfig() std::string line; std::string dvr_path; + bool in_http_server = false; + while (std::getline(ifs, line)) { line.erase(0, line.find_first_not_of(" \t")); if (line.empty() || line[0] == '#') continue; + // ---------- 进入 http_server 块 ---------- + if (line.find("http_server") != std::string::npos && line.find("{") != std::string::npos) + { + in_http_server = true; + continue; + } + if (in_http_server && line == "}") + { + in_http_server = false; + continue; + } + + if (in_http_server) + { + if (line.rfind("listen", 0) == 0) + { + int port = 0; + if (sscanf(line.c_str(), "listen %d;", &port) == 1) + { + http_port_ = port; + } + } + } + // 解析 dvr_path if (line.find("dvr_path") != std::string::npos) { @@ -235,6 +262,7 @@ RecordFileInfo RecordManager::parseFile(const fs::path& p) std::vector RecordManager::querySegments(const std::string& stream, int64_t start_ms, int64_t end_ms) { std::vector result; + if (start_ms <= 0 || end_ms <= 0 || start_ms >= end_ms) return result; if (!index_.count(stream)) return result; const auto& files = index_[stream]; diff --git a/src/rtmp_manager.cpp b/src/rtmp_manager.cpp index d0488c3..5ec50cf 100644 --- a/src/rtmp_manager.cpp +++ b/src/rtmp_manager.cpp @@ -19,7 +19,7 @@ static bool device_exists(const std::string& path) } // 动态获取指定网卡 IPv4 地址 -static std::string get_ip_address(const std::string& ifname) +std::string get_ip_address(const std::string& ifname) { struct ifaddrs *ifaddr, *ifa; char ip[INET_ADDRSTRLEN] = {0};