IVA/app/HxVideoDevice.h

169 lines
3.4 KiB
C
Raw Permalink Normal View History

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"
#include "HxDataBase.h"
#include "HxVideoWriter.h"
2023-11-27 14:03:29 +08:00
#include "HxVideoDecoder.h"
#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;
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
2023-10-20 23:36:22 +08:00
{
Q_OBJECT
public:
HxVideoDevice(void);
~HxVideoDevice(void);
/**
* @brief
* @param type
* @param address
*/
2023-10-20 23:36:22 +08:00
void set(int type, QString address);
/**
* @brief
* @param type
* @param address
* @param region BSD报警区域
*/
2023-10-20 23:36:22 +08:00
void set(int type, QString address, BsdWarnRegion region);
/**
* @brief
* @param status true: ; false:
*/
void set(bool status);
2023-10-20 23:36:22 +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:
/* 读取线程 */
void read_process(void);
2023-11-27 14:03:29 +08:00
/* 解码线程 */
void decoding_process(void);
2023-10-20 23:36:22 +08:00
protected:
void run() override;
;
2023-10-20 23:36:22 +08:00
2023-10-20 23:48:21 +08:00
private:
/* 算法通道类型 */
int m_type;
2023-10-20 23:36:22 +08:00
/* 视频帧率 */
int m_video_fps = 25;
/* 视频地址(RTSP流) */
QString m_address = "";
/* 报警检测时间 */
QMap<int, QDateTime> m_alarm_detection_timestamps;
/* 检测状态(是否送帧给算法的标识) */
bool m_detection_status = true;
2023-10-20 23:36:22 +08:00
/* 正在创建的录像文件 */
QMutex m_records_mutex;
QList<QString> m_records;
2023-10-20 23:48:21 +08:00
/* 视频图像帧信息 */
VideoFrameDataInfo m_detect_frame_buffer;
2023-11-27 14:03:29 +08:00
/* FFmpeg */
2023-11-27 14:03:29 +08:00
AVFormatContext *ifmt_ctx;
/* 解码帧队列及锁 */
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
/* 视频打包类 */
HxVideoWriter m_video_writer;
2023-11-27 14:03:29 +08:00
/* 视频解码类 */
HxVideoDecoder m_video_decoder;
2023-10-20 23:36:22 +08:00
};
#endif