1
This commit is contained in:
parent
643b64d828
commit
f2d864af0b
@ -122,6 +122,13 @@ RTMPManager::StreamResultInfo RTMPManager::start_camera(const Camera &cam, Strea
|
|||||||
res.loc = get_camera_index(cam.name);
|
res.loc = get_camera_index(cam.name);
|
||||||
res.url = get_stream_url(cam.name, type);
|
res.url = get_stream_url(cam.name, type);
|
||||||
|
|
||||||
|
if (res.loc < 0 || res.loc >= static_cast<int>(g_app_config.cameras.size()))
|
||||||
|
{
|
||||||
|
res.result = 1;
|
||||||
|
res.reason = "Invalid channel index";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string key = make_stream_key(cam.name, type);
|
const std::string key = make_stream_key(cam.name, type);
|
||||||
|
|
||||||
std::unique_ptr<StreamContext> ctx;
|
std::unique_ptr<StreamContext> ctx;
|
||||||
@ -171,27 +178,40 @@ RTMPManager::StreamResultInfo RTMPManager::stop_camera(const std::string &cam_na
|
|||||||
res.loc = get_camera_index(cam_name);
|
res.loc = get_camera_index(cam_name);
|
||||||
res.url = get_stream_url(cam_name, type);
|
res.url = get_stream_url(cam_name, type);
|
||||||
|
|
||||||
|
// 检查通道号是否合法
|
||||||
|
if (res.loc < 0 || res.loc >= static_cast<int>(g_app_config.cameras.size()))
|
||||||
|
{
|
||||||
|
res.result = 1;
|
||||||
|
res.reason = "Invalid channel index";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<StreamContext> ctx;
|
std::unique_ptr<StreamContext> ctx;
|
||||||
std::string key = make_stream_key(cam_name, type);
|
std::string key = make_stream_key(cam_name, type);
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(streams_mutex);
|
std::lock_guard<std::mutex> lock(streams_mutex);
|
||||||
auto it = streams.find(key);
|
auto it = streams.find(key);
|
||||||
if (it == streams.end())
|
if (it == streams.end())
|
||||||
{
|
{
|
||||||
|
// 没有这个流(可能从未推过或启动失败)→ 视为成功,因为状态已经是“未推”
|
||||||
res.result = 0;
|
res.result = 0;
|
||||||
res.reason = "Not streaming";
|
res.reason = "Already stopped (no active stream)";
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
it->second->running.store(false);
|
// 找到了正在推的流 → 停止
|
||||||
ctx = std::move(it->second);
|
ctx = std::move(it->second);
|
||||||
streams.erase(it);
|
streams.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool was_running = ctx->running.load();
|
||||||
|
ctx->running.store(false);
|
||||||
|
|
||||||
if (ctx->thread.joinable()) ctx->thread.join();
|
if (ctx->thread.joinable()) ctx->thread.join();
|
||||||
|
|
||||||
res.result = 0;
|
res.result = 0;
|
||||||
res.reason = "Stopped manually";
|
res.reason = was_running ? "Stopped manually" : "Already stopped";
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user