rtsp_tensorrt/main.cpp
sladro e13cb3659c feat: 初始化项目结构
- 创建基本项目结构和目录
- 添加CMake构建系统
- 实现基础的配置解析功能
- 添加YOLO推理框架支持
- 集成RTSP和视频流处理功能
- 添加性能监控和日志系统
2024-12-24 16:25:03 +08:00

70 lines
2.0 KiB
C++

#include <iostream>
#include <chrono>
#include <thread>
#include <csignal>
#include "pipeline/common/pipeline.hpp"
#include "pipeline/common/config_parser.hpp"
using namespace pipeline;
// 全局变量用于信号处理
static std::atomic<bool> g_running{true};
// 信号处理函数
void signalHandler(int signum) {
std::cout << "\nReceived signal " << signum << std::endl;
g_running = false;
}
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <config_file>" << std::endl;
return 1;
}
// 注册信号处理
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
try {
// 创建并初始化Pipeline
Pipeline pipeline(argv[1]);
if (!pipeline.init()) {
std::cerr << "Failed to initialize pipeline" << std::endl;
return 1;
}
// 启动Pipeline
if (!pipeline.start()) {
std::cerr << "Failed to start pipeline" << std::endl;
return 1;
}
std::cout << "Pipeline started successfully" << std::endl;
// 主循环:监控性能指标
while (g_running) {
PerformanceMetrics metrics;
if (pipeline.getMetrics(metrics)) {
std::cout << "\rFPS: " << metrics.fps
<< " | Inference time: " << metrics.inference_time_ms << "ms"
<< " | GPU usage: " << metrics.gpu_usage_percent << "%"
<< std::flush;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
std::cout << "\nStopping pipeline..." << std::endl;
// 停止Pipeline
pipeline.stop();
pipeline.wait();
std::cout << "Pipeline stopped successfully" << std::endl;
return 0;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
}