From a9c236d5f28c4983794b893131439879964b8988 Mon Sep 17 00:00:00 2001 From: cxh Date: Tue, 23 Dec 2025 08:59:08 +0800 Subject: [PATCH] RTMP: start streams only when camera.enabled is true --- src/rtmp_manager.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/rtmp_manager.cpp b/src/rtmp_manager.cpp index cbfb499..eeaf696 100644 --- a/src/rtmp_manager.cpp +++ b/src/rtmp_manager.cpp @@ -329,12 +329,18 @@ void RTMPManager::stream_loop(Camera cam, StreamContext* ctx) // ========== 启停与状态 ========== void RTMPManager::start_all() { - LOG_INFO("[RTMP] Starting all record streams..."); + LOG_INFO("[RTMP] Starting enabled record streams..."); std::lock_guard lock(streams_mutex); int delay_ms = 0; - for (auto& cam : g_app_config.cameras) + for (const auto& cam : g_app_config.cameras) { + if (!cam.enabled) + { + LOG_INFO("[RTMP] Skip disabled camera: " + cam.name); + continue; + } + auto key = make_key(cam.name); if (streams.find(key) != streams.end()) { @@ -353,7 +359,7 @@ void RTMPManager::start_all() }); streams.emplace(key, std::move(ctx)); - delay_ms += 200; // 每路错开 200ms + delay_ms += 200; } } @@ -398,29 +404,38 @@ std::vector RTMPManager::get_all_channels_status() ch.loc = static_cast(i); ch.url.clear(); ch.running = false; - ch.reason = "Not started"; + + if (!cam.enabled) + { + ch.reason = "Disabled by config"; + result.push_back(ch); + continue; + } auto it = streams.find(key); if (it != streams.end()) { auto& ctx = *(it->second); - std::lock_guard lk(ctx.status_mutex); - auto& status = it->second->status; - ch.running = status.running; - if (status.running) + ch.running = ctx.status.running; + if (ctx.status.running) { ch.url = get_stream_url(cam.name); ch.reason.clear(); } else { - ch.reason = status.last_error.empty() ? "Unknown error" : status.last_error; + ch.reason = ctx.status.last_error.empty() ? "Stopped" : ctx.status.last_error; } } + else + { + ch.reason = "Enabled but not started"; + } result.push_back(ch); } + return result; }