bonus-edge-proxy/src/rknn/video_service.h

62 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// video_service.h (修改后)
#pragma once
#include "algorithm/IAnalysisModule.h"
#include "nlohmann/json.hpp"
#include <atomic>
#include <condition_variable>
#include <map>
#include <memory>
#include <mutex>
#include <opencv2/core/core.hpp>
#include <opencv2/videoio.hpp>
#include <string>
#include <thread>
#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
class VideoService
{
public:
/**
* @brief 构造函数变更:
* 不再接收 model_path 和 thread_num
* 而是通过依赖注入接收一个抽象的 AI 模块。
*/
VideoService(std::unique_ptr<IAnalysisModule> 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<uint8_t> &dst);
cv::Mat create_aligned_mat(int width, int height, int type);
std::unique_ptr<IAnalysisModule> 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<bool> running_{false};
std::mutex frame_mutex_;
std::condition_variable frame_cv_;
cv::Mat latest_frame_;
bool new_frame_available_{false};
std::string log_prefix_;
};