diff --git a/src/main.cpp b/src/main.cpp index 79d4cc8..fa0bff8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,16 +100,12 @@ int main() if (ENABLE_RTSP_THREAD) { - RTSPManager::stop(); - - auto stop_deadline = std::chrono::steady_clock::now() + std::chrono::seconds(10); - while (RTSPManager::is_any_streaming() && std::chrono::steady_clock::now() < stop_deadline) - { - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - } + RTSPManager::stop(); // 只负责让 g_main_loop_run 跳出 if (rtsp_thread.joinable()) rtsp_thread.join(); + + LOG_INFO("[MAIN] RTSP thread finished and joined."); } // 重置 MQTT 线程等待的截止时间 diff --git a/src/rtsp_manager.cpp b/src/rtsp_manager.cpp index 213a0f0..6cdd5b3 100644 --- a/src/rtsp_manager.cpp +++ b/src/rtsp_manager.cpp @@ -283,10 +283,16 @@ void RTSPManager::stop() // 退出 main loop if (loop) { - g_main_context_invoke(main_context, [](gpointer data) -> gboolean - { - g_main_loop_quit(static_cast(data)); - return G_SOURCE_REMOVE; }, loop); + g_main_context_invoke( + main_context, + [](gpointer data) -> gboolean + { + GMainLoop *lp = static_cast(data); + if (lp) + g_main_loop_quit(lp); + return G_SOURCE_REMOVE; + }, + loop); } }