This commit is contained in:
cxh 2025-11-14 17:05:24 +08:00
parent 745f49fd46
commit c01c7e475e
5 changed files with 38 additions and 7 deletions

View File

@ -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_

View File

@ -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<std::pair<std::string, bool>> 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<std::string, std::unique_ptr<StreamContext>> streams;
static std::mutex streams_mutex;

View File

@ -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;

View File

@ -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<RecordSegment> RecordManager::querySegments(const std::string& stream, int64_t start_ms, int64_t end_ms)
{
std::vector<RecordSegment> 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];

View File

@ -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};