diff --git a/include/rtmp_manager.hpp b/include/rtmp_manager.hpp index 9a4e646..d27ae56 100644 --- a/include/rtmp_manager.hpp +++ b/include/rtmp_manager.hpp @@ -17,7 +17,7 @@ public: static void start_camera(const Camera &cam, StreamType type); static void stop_camera(const std::string &cam_name, StreamType type); static void stop_all(); - static bool is_streaming(const std::string &cam_name); + static bool is_streaming(const std::string &cam_name, StreamType type); static bool is_any_streaming(); // 获取推流 URL,用于应答 @@ -26,8 +26,10 @@ public: private: struct StreamContext { + std::atomic running; std::thread thread; - std::atomic running{false}; + + StreamContext() : running(false) {} // 确保 atomic 初始化 }; static std::unordered_map streams; diff --git a/src/rtmp_manager.cpp b/src/rtmp_manager.cpp index a5dbc81..a3a39d9 100644 --- a/src/rtmp_manager.cpp +++ b/src/rtmp_manager.cpp @@ -8,6 +8,8 @@ std::unordered_map RTMPManager::streams; std::mutex RTMPManager::streams_mutex; +LOG_INFO(std::string(debug)); + static inline std::string stream_type_suffix(StreamType type) { return (type == StreamType::MAIN) ? "_main" : "_sub"; @@ -180,7 +182,7 @@ void RTMPManager::start_camera(const Camera &cam, StreamType type) ctx.running = true; ctx.thread = std::thread([cam, type]() { RTMPManager::stream_loop(cam, type); }); - streams[key] = std::move(ctx); + streams.emplace(key, std::move(ctx)); } void RTMPManager::stop_camera(const std::string &cam_name, StreamType type)