This commit is contained in:
cxh 2025-10-17 13:38:55 +08:00
parent e44e914297
commit f46a23d01d

View File

@ -1,14 +1,15 @@
// main.cpp // main.cpp
#include <unistd.h>
#include <atomic>
#include <chrono>
#include <csignal>
#include <thread>
#include "app_config.hpp" #include "app_config.hpp"
#include "rtmp_manager.hpp"
#include "logger.hpp" #include "logger.hpp"
#include "mqtt_client_wrapper.hpp" #include "mqtt_client_wrapper.hpp"
#include "rtmp_manager.hpp"
#include <thread>
#include <atomic>
#include <csignal>
#include <unistd.h>
#include <chrono>
std::atomic<bool> g_running(true); std::atomic<bool> g_running(true);
@ -48,24 +49,26 @@ int main()
// 初始化 GStreamer // 初始化 GStreamer
RTMPManager::init(); RTMPManager::init();
RTMPManager::start_all_record_streams();
// 启动 MQTT 线程 // 启动 MQTT 线程
std::thread mqtt_thread([] std::thread mqtt_thread(
{ []
try
{ {
LOG_INFO("[MAIN] MQTT thread started."); try
mqtt_client_thread_func(); // 在回调里执行推流控制 {
} LOG_INFO("[MAIN] MQTT thread started.");
catch (const std::exception &e) mqtt_client_thread_func(); // 在回调里执行推流控制
{ }
LOG_ERROR(std::string("[MAIN] MQTT thread crashed: ") + e.what()); catch (const std::exception &e)
} {
LOG_INFO("[MAIN] MQTT thread exiting..."); }); LOG_ERROR(std::string("[MAIN] MQTT thread crashed: ") + e.what());
}
LOG_INFO("[MAIN] MQTT thread exiting...");
});
// 主循环,仅等待退出信号 // 主循环,仅等待退出信号
while (g_running.load(std::memory_order_relaxed)) while (g_running.load(std::memory_order_relaxed)) std::this_thread::sleep_for(std::chrono::milliseconds(200));
std::this_thread::sleep_for(std::chrono::milliseconds(200));
LOG_INFO("[MAIN] Shutdown requested. Cleaning up..."); LOG_INFO("[MAIN] Shutdown requested. Cleaning up...");