This commit is contained in:
cxh 2025-10-14 17:44:59 +08:00
parent 5137f45e30
commit f6a332d120
2 changed files with 7 additions and 3 deletions

View File

@ -17,7 +17,7 @@ public:
static void start_camera(const Camera &cam, StreamType type); static void start_camera(const Camera &cam, StreamType type);
static void stop_camera(const std::string &cam_name, StreamType type); static void stop_camera(const std::string &cam_name, StreamType type);
static void stop_all(); 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(); static bool is_any_streaming();
// 获取推流 URL用于应答 // 获取推流 URL用于应答
@ -26,8 +26,10 @@ public:
private: private:
struct StreamContext struct StreamContext
{ {
std::atomic<bool> running;
std::thread thread; std::thread thread;
std::atomic<bool> running{false};
StreamContext() : running(false) {} // 确保 atomic 初始化
}; };
static std::unordered_map<std::string, StreamContext> streams; static std::unordered_map<std::string, StreamContext> streams;

View File

@ -8,6 +8,8 @@
std::unordered_map<std::string, RTMPManager::StreamContext> RTMPManager::streams; std::unordered_map<std::string, RTMPManager::StreamContext> RTMPManager::streams;
std::mutex RTMPManager::streams_mutex; std::mutex RTMPManager::streams_mutex;
LOG_INFO(std::string(debug));
static inline std::string stream_type_suffix(StreamType type) static inline std::string stream_type_suffix(StreamType type)
{ {
return (type == StreamType::MAIN) ? "_main" : "_sub"; return (type == StreamType::MAIN) ? "_main" : "_sub";
@ -180,7 +182,7 @@ void RTMPManager::start_camera(const Camera &cam, StreamType type)
ctx.running = true; ctx.running = true;
ctx.thread = std::thread([cam, type]() ctx.thread = std::thread([cam, type]()
{ RTMPManager::stream_loop(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) void RTMPManager::stop_camera(const std::string &cam_name, StreamType type)