RTMP: start streams only when camera.enabled is true

This commit is contained in:
cxh 2025-12-23 08:59:08 +08:00
parent e0a3406689
commit a9c236d5f2

View File

@ -329,12 +329,18 @@ void RTMPManager::stream_loop(Camera cam, StreamContext* ctx)
// ========== 启停与状态 ========== // ========== 启停与状态 ==========
void RTMPManager::start_all() void RTMPManager::start_all()
{ {
LOG_INFO("[RTMP] Starting all record streams..."); LOG_INFO("[RTMP] Starting enabled record streams...");
std::lock_guard<std::mutex> lock(streams_mutex); std::lock_guard<std::mutex> lock(streams_mutex);
int delay_ms = 0; 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); auto key = make_key(cam.name);
if (streams.find(key) != streams.end()) if (streams.find(key) != streams.end())
{ {
@ -353,7 +359,7 @@ void RTMPManager::start_all()
}); });
streams.emplace(key, std::move(ctx)); streams.emplace(key, std::move(ctx));
delay_ms += 200; // 每路错开 200ms delay_ms += 200;
} }
} }
@ -398,29 +404,38 @@ std::vector<RTMPManager::ChannelInfo> RTMPManager::get_all_channels_status()
ch.loc = static_cast<int>(i); ch.loc = static_cast<int>(i);
ch.url.clear(); ch.url.clear();
ch.running = false; 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); auto it = streams.find(key);
if (it != streams.end()) if (it != streams.end())
{ {
auto& ctx = *(it->second); auto& ctx = *(it->second);
std::lock_guard<std::mutex> lk(ctx.status_mutex); std::lock_guard<std::mutex> lk(ctx.status_mutex);
auto& status = it->second->status;
ch.running = status.running; ch.running = ctx.status.running;
if (status.running) if (ctx.status.running)
{ {
ch.url = get_stream_url(cam.name); ch.url = get_stream_url(cam.name);
ch.reason.clear(); ch.reason.clear();
} }
else 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); result.push_back(ch);
} }
return result; return result;
} }