2023-10-20 23:36:22 +08:00
|
|
|
#ifndef HXVIDEODEVICE_H
|
|
|
|
#define HXVIDEODEVICE_H
|
|
|
|
|
|
|
|
#include <QtConcurrent>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QMutex>
|
|
|
|
|
|
|
|
#include "HxTaskDispatch.h"
|
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
#include "HxDataBase.h"
|
|
|
|
#include "HxVideoWriter.h"
|
2023-11-27 14:03:29 +08:00
|
|
|
#include "HxVideoDecoder.h"
|
|
|
|
|
2023-10-21 16:13:52 +08:00
|
|
|
#if USE_ALGORITHM
|
2023-11-27 14:03:29 +08:00
|
|
|
#include "rga.h"
|
|
|
|
#include "im2d.hpp"
|
2023-10-20 23:36:22 +08:00
|
|
|
#endif
|
|
|
|
|
2023-11-27 14:03:29 +08:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#include "libavformat/avformat.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
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;
|
|
|
|
|
2023-11-12 01:13:43 +08:00
|
|
|
class HxVideoDevice : public QThread
|
2023-10-20 23:36:22 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-11-12 01:13:43 +08:00
|
|
|
HxVideoDevice(void);
|
2023-12-08 14:17:14 +08:00
|
|
|
|
|
|
|
~HxVideoDevice(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 设置
|
|
|
|
* @param type 算法通道类型
|
|
|
|
* @param address 摄像头地址
|
|
|
|
*/
|
2023-10-20 23:36:22 +08:00
|
|
|
void set(int type, QString address);
|
2023-12-08 14:17:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 设置
|
|
|
|
* @param type 算法通道类型
|
|
|
|
* @param address 摄像头地址
|
|
|
|
* @param region BSD报警区域
|
|
|
|
*/
|
2023-10-20 23:36:22 +08:00
|
|
|
void set(int type, QString address, BsdWarnRegion region);
|
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/**
|
|
|
|
* @brief 设置算法检测状态
|
|
|
|
* @param status 状态 true: 允许执行; false: 禁止执行
|
|
|
|
*/
|
|
|
|
void set(bool status);
|
2023-10-20 23:36:22 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/**
|
|
|
|
* @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 测试
|
|
|
|
*/
|
2023-10-20 23:36:22 +08:00
|
|
|
void test(void);
|
|
|
|
|
|
|
|
private:
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 读取线程 */
|
|
|
|
void read_process(void);
|
2023-11-27 14:03:29 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 解码线程 */
|
|
|
|
void decoding_process(void);
|
2023-10-20 23:36:22 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void run() override;
|
2023-12-08 14:17:14 +08:00
|
|
|
;
|
2023-10-20 23:36:22 +08:00
|
|
|
|
2023-10-20 23:48:21 +08:00
|
|
|
private:
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 算法通道类型 */
|
|
|
|
int m_type;
|
2023-10-20 23:36:22 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 视频帧率 */
|
|
|
|
int m_video_fps = 25;
|
2023-11-12 01:13:43 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 视频地址(RTSP流) */
|
|
|
|
QString m_address = "";
|
2023-11-12 01:13:43 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 报警检测时间 */
|
|
|
|
QMap<int, QDateTime> m_alarm_detection_timestamps;
|
2023-11-12 01:13:43 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 检测状态(是否送帧给算法的标识) */
|
|
|
|
bool m_detection_status = true;
|
2023-10-20 23:36:22 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 正在创建的录像文件 */
|
|
|
|
QMutex m_records_mutex;
|
|
|
|
QList<QString> m_records;
|
2023-10-20 23:48:21 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 视频图像帧信息 */
|
|
|
|
VideoFrameDataInfo m_detect_frame_buffer;
|
2023-11-27 14:03:29 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* FFmpeg */
|
2023-11-27 14:03:29 +08:00
|
|
|
AVFormatContext *ifmt_ctx;
|
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 解码帧队列及锁 */
|
|
|
|
QMutex m_decoding_frames_mutex;
|
|
|
|
QQueue<HxVideoFrame> m_decoding_frames;
|
|
|
|
|
|
|
|
/* 预录帧队列及锁 */
|
|
|
|
QMutex m_prerecorded_frames_mutex;
|
|
|
|
QQueue<HxVideoFrame> m_prerecorded_frames;
|
2023-11-27 14:03:29 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 视频打包类 */
|
|
|
|
HxVideoWriter m_video_writer;
|
2023-11-27 14:03:29 +08:00
|
|
|
|
2023-12-08 14:17:14 +08:00
|
|
|
/* 视频解码类 */
|
|
|
|
HxVideoDecoder m_video_decoder;
|
2023-10-20 23:36:22 +08:00
|
|
|
};
|
|
|
|
|
2023-11-12 01:13:43 +08:00
|
|
|
#endif
|