1
This commit is contained in:
parent
c537e5521a
commit
17f9753906
@ -407,6 +407,7 @@ std::string RTMPManager::get_stream_url(const std::string &cam_name, StreamType
|
||||
std::vector<RTMPManager::StreamResultInfo> RTMPManager::process_push_request(const VideoPushRequest &req)
|
||||
{
|
||||
std::vector<StreamResultInfo> results;
|
||||
std::vector<std::future<StreamResultInfo>> futures;
|
||||
|
||||
for (const auto &item : req.data)
|
||||
{
|
||||
@ -414,26 +415,38 @@ std::vector<RTMPManager::StreamResultInfo> RTMPManager::process_push_request(con
|
||||
|
||||
for (int ch : item.channels)
|
||||
{
|
||||
if (ch < 0 || ch >= static_cast<int>(g_app_config.cameras.size()))
|
||||
{
|
||||
StreamResultInfo info;
|
||||
info.loc = ch;
|
||||
info.result = 1;
|
||||
info.reason = "Invalid channel index";
|
||||
info.url = "";
|
||||
results.push_back(info);
|
||||
continue;
|
||||
}
|
||||
if (ch < 0 || ch >= static_cast<int>(g_app_config.cameras.size())) continue;
|
||||
|
||||
const auto &cam = g_app_config.cameras[ch];
|
||||
StreamResultInfo info;
|
||||
|
||||
if (item.switchVal == 0)
|
||||
info = start_camera(cam, type);
|
||||
{
|
||||
// 异步启动推流
|
||||
futures.emplace_back(
|
||||
std::async(std::launch::async, [&, cam, type]() { return start_camera(cam, type); }));
|
||||
}
|
||||
else
|
||||
info = stop_camera(cam.name, type);
|
||||
{
|
||||
// 异步停止推流
|
||||
futures.emplace_back(
|
||||
std::async(std::launch::async, [&, cam, type]() { return stop_camera(cam.name, type); }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
results.push_back(info);
|
||||
// 收集所有结果
|
||||
for (auto &f : futures)
|
||||
{
|
||||
try
|
||||
{
|
||||
results.push_back(f.get());
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
StreamResultInfo err;
|
||||
err.result = 1;
|
||||
err.reason = std::string("Exception: ") + e.what();
|
||||
results.push_back(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user