#ifndef HXVIDEODEVICE_H #define HXVIDEODEVICE_H #include #include #include #include #include #include "HxTaskDispatch.h" #include "HxDataBase.h" #include "HxVideoWriter.h" #include "HxVideoDecoder.h" #if USE_ALGORITHM #include "rga.h" #include "im2d.hpp" #endif extern "C" { #include "libavformat/avformat.h" } using namespace cv; using namespace std; typedef struct __HxVideoFrame { QDateTime time; AVFormatContext *ifmt_ctx; AVPacket *packet; __HxVideoFrame() {} __HxVideoFrame(AVFormatContext *ifmt_ctx, AVPacket *packet) { this->time = QDateTime::currentDateTime(); this->ifmt_ctx = ifmt_ctx; this->packet = av_packet_clone(packet); } __HxVideoFrame(QDateTime time, AVFormatContext *ifmt_ctx, AVPacket *packet) { this->time = time; this->ifmt_ctx = ifmt_ctx; this->packet = av_packet_clone(packet); } __HxVideoFrame copy() { return __HxVideoFrame(this->time, this->ifmt_ctx, this->packet); } void free() { ifmt_ctx = nullptr; if (packet) { av_packet_unref(packet); av_packet_free(&packet); } } } HxVideoFrame; class HxVideoDevice : public QThread { Q_OBJECT public: HxVideoDevice(void); ~HxVideoDevice(void); /** * @brief 设置 * @param type 算法通道类型 * @param address 摄像头地址 */ void set(int type, QString address); /** * @brief 设置 * @param type 算法通道类型 * @param address 摄像头地址 * @param region BSD报警区域 */ void set(int type, QString address, BsdWarnRegion region); /** * @brief 设置算法检测状态 * @param status 状态 true: 允许执行; false: 禁止执行 */ void set(bool status); /** * @brief 判断报警检测时间 * @param event_type 报警类型 * @return true: 超过设置阈值; false: 未超过设置阈值 */ bool determine_alarm_detection_timestamp(int event_type); /** * @brief 创建报警数据(视频与图片) * @param event_type 报警类型 * @param filename 文件名称 */ void create_alarm_data(int event_type, QString filename); /** * @brief 测试 */ void test(void); private: /* 读取线程 */ void read_process(void); /* 解码线程 */ void decoding_process(void); protected: void run() override; ; private: /* 算法通道类型 */ int m_type; /* 视频帧率 */ int m_video_fps = 25; /* 视频地址(RTSP流) */ QString m_address = ""; /* 报警检测时间 */ QMap m_alarm_detection_timestamps; /* 检测状态(是否送帧给算法的标识) */ bool m_detection_status = true; /* 正在创建的录像文件 */ QMutex m_records_mutex; QList m_records; /* 视频图像帧信息 */ VideoFrameDataInfo m_detect_frame_buffer; /* FFmpeg */ AVFormatContext *ifmt_ctx; /* 解码帧队列及锁 */ QMutex m_decoding_frames_mutex; QQueue m_decoding_frames; /* 预录帧队列及锁 */ QMutex m_prerecorded_frames_mutex; QQueue m_prerecorded_frames; /* 视频打包类 */ HxVideoWriter m_video_writer; /* 视频解码类 */ HxVideoDecoder m_video_decoder; }; #endif