// video_service.h (修改后) #pragma once #include "algorithm/IAnalysisModule.h" #include "nlohmann/json.hpp" #include #include #include #include #include #include #include #include #include #include #include class VideoService { public: /** * @brief 构造函数变更: * 不再接收 model_path 和 thread_num, * 而是通过依赖注入接收一个抽象的 AI 模块。 */ VideoService(std::unique_ptr module, std::string input_url, std::string output_rtsp_url, nlohmann::json module_config); ~VideoService(); bool start(); void stop(); private: void processing_loop(); void reading_loop(); void bgr_to_nv12(const cv::Mat &src, std::vector &dst); cv::Mat create_aligned_mat(int width, int height, int type); std::unique_ptr module_; nlohmann::json module_config_; std::string input_url_; std::string output_rtsp_url_; int frame_width_ = 0; int frame_height_ = 0; double frame_fps_ = 0.0; cv::VideoCapture capture_; cv::VideoWriter writer_; GstElement *gst_pipeline_ = nullptr; GstElement *gst_appsrc_ = nullptr; std::thread processing_thread_; std::thread reading_thread_; std::atomic running_{false}; std::mutex frame_mutex_; std::condition_variable frame_cv_; cv::Mat latest_frame_; bool new_frame_available_{false}; std::string log_prefix_; };