sweeper_video/src/main.cpp

49 lines
1006 B
C++
Raw Normal View History

2025-09-08 14:55:07 +08:00
// main.cpp
#include "app_config.hpp"
#include "rtsp_manager.hpp"
#include "logger.hpp"
2025-09-08 15:25:59 +08:00
#include "mqtt_client_wrapper.hpp"
#include <thread>
2025-09-08 14:55:07 +08:00
#include <atomic>
#include <csignal>
std::atomic<bool> g_running(true);
void signalHandler(int signum)
{
g_running = false;
RTSPManager::stop();
}
int main()
{
signal(SIGINT, signalHandler);
signal(SIGPIPE, SIG_IGN);
// 初始化日志文件
Logger::set_log_to_file("app.log");
try
{
g_app_config = AppConfig::load_from_file("config.json");
}
catch (const std::exception &e)
{
LOG_ERROR(std::string("Failed to load config: ") + e.what());
return -1;
}
2025-09-08 15:25:59 +08:00
// 启动 RTSP
2025-09-08 14:55:07 +08:00
RTSPManager::init();
2025-09-08 15:25:59 +08:00
std::thread rtsp_thread([&]()
{ RTSPManager::start(g_app_config.cameras); });
// 启动 MQTT 客户端线程
std::thread mqtt_thread(mqtt_client_thread_func);
// 等待退出信号
rtsp_thread.join();
mqtt_thread.join();
2025-09-08 14:55:07 +08:00
return 0;
}