From 055fe9c626da6f70028e6b0d2d5b40eefb04dd93 Mon Sep 17 00:00:00 2001 From: cxh Date: Fri, 14 Nov 2025 14:49:45 +0800 Subject: [PATCH] 1 --- src/main.cpp | 78 ++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 98a1af5..2d087ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,53 +38,53 @@ int main() RecordManager rm("/home/aiec/srs/conf/kun_record.conf"); - // try - // { - // // 加载配置 - // g_app_config = AppConfig::load_from_file(get_executable_dir_file_path("config.json")); - // LOG_INFO("[MAIN] Loaded config from config.json"); - // } - // catch (const std::exception& e) - // { - // LOG_ERROR(std::string("[MAIN] Failed to load config: ") + e.what()); - // return -1; - // } + try + { + // 加载配置 + g_app_config = AppConfig::load_from_file(get_executable_dir_file_path("config.json")); + LOG_INFO("[MAIN] Loaded config from config.json"); + } + catch (const std::exception& e) + { + LOG_ERROR(std::string("[MAIN] Failed to load config: ") + e.what()); + return -1; + } - // // ---------- 初始化 GStreamer ---------- - // RTMPManager::init(); + // ---------- 初始化 GStreamer ---------- + RTMPManager::init(); - // // ---------- 自动推流(8 路录像守护) ---------- - // LOG_INFO("[MAIN] Starting all record streams..."); - // RTMPManager::start_all(); + // ---------- 自动推流(8 路录像守护) ---------- + LOG_INFO("[MAIN] Starting all record streams..."); + RTMPManager::start_all(); - // // 启动 MQTT 线程 - // std::thread mqtt_thread( - // [] - // { - // try - // { - // LOG_INFO("[MAIN] MQTT thread started."); - // mqtt_client_thread_func(); // 在回调里执行推流控制 - // } - // catch (const std::exception& e) - // { - // LOG_ERROR(std::string("[MAIN] MQTT thread crashed: ") + e.what()); - // } - // LOG_INFO("[MAIN] MQTT thread exiting..."); - // }); + // 启动 MQTT 线程 + std::thread mqtt_thread( + [] + { + try + { + LOG_INFO("[MAIN] MQTT thread started."); + mqtt_client_thread_func(); // 在回调里执行推流控制 + } + catch (const std::exception& e) + { + LOG_ERROR(std::string("[MAIN] MQTT thread crashed: ") + e.what()); + } + LOG_INFO("[MAIN] MQTT thread exiting..."); + }); // 主循环,仅等待退出信号 while (g_running.load(std::memory_order_relaxed)) std::this_thread::sleep_for(std::chrono::milliseconds(200)); - // // ---------- 退出清理 ---------- - // LOG_INFO("[MAIN] Shutdown requested. Stopping RTMP streams..."); - // RTMPManager::stop_all(); + // ---------- 退出清理 ---------- + LOG_INFO("[MAIN] Shutdown requested. Stopping RTMP streams..."); + RTMPManager::stop_all(); - // if (mqtt_thread.joinable()) - // { - // mqtt_thread.join(); - // LOG_INFO("[MAIN] MQTT thread joined."); - // } + if (mqtt_thread.joinable()) + { + mqtt_thread.join(); + LOG_INFO("[MAIN] MQTT thread joined."); + } LOG_INFO("[MAIN] ===== Vehicle Video Service Exited Cleanly ====="); return 0;