From 17f975390693e751ac96f97e856c171df6288df9 Mon Sep 17 00:00:00 2001 From: cxh Date: Thu, 16 Oct 2025 14:47:00 +0800 Subject: [PATCH] 1 --- src/rtmp_manager.cpp | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/rtmp_manager.cpp b/src/rtmp_manager.cpp index 013ebca..635c63f 100644 --- a/src/rtmp_manager.cpp +++ b/src/rtmp_manager.cpp @@ -407,6 +407,7 @@ std::string RTMPManager::get_stream_url(const std::string &cam_name, StreamType std::vector RTMPManager::process_push_request(const VideoPushRequest &req) { std::vector results; + std::vector> futures; for (const auto &item : req.data) { @@ -414,26 +415,38 @@ std::vector RTMPManager::process_push_request(con for (int ch : item.channels) { - if (ch < 0 || ch >= static_cast(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(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); } }