HxVideoCaptor/main.h

135 lines
4.1 KiB
C

#ifndef MAIN_H
#define MAIN_H
#include <QCoreApplication>
#include <QList>
#include "HxDisk.h"
#include "HxTask.h"
#include "HxJson.h"
#include "HxThread.h"
#include "HxReadMe.h"
#include "HxBroadcast.h"
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/time.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"
#include <libavutil/audio_fifo.h>
}
#define CHANNEL_MAX 16
#define BROADCAST_PORT 5001
#define WRITE_LOG(type, index, message, data) HxBroadcast::publish_json(4, {{"timestamp", QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")}, \
{"type", type}, \
{"index", index}, \
{"message", message}, \
{"data", data}})
#define WRITE_SYSTEM_LOG(message, data) WRITE_LOG(0, -1, message, data);
#define WRITE_VIDEO_LOG(channel, message, data) WRITE_LOG(2, channel, message, data);
#define REPLACE_RECORD_LOG(record) HxBroadcast::publish_json(6, {{"channel", record.channel}, \
{"start_time", record.start_time.toString("yyyy-MM-dd HH:mm:ss")}, \
{"end_time", record.end_time.toString("yyyy-MM-dd HH:mm:ss")}, \
{"duration", record.duration}, \
{"name", record.name}, \
{"path", record.path}})
typedef enum
{
Null, /* 无状态 */
Recording, /* 录像中 */
Recorded, /* 录像完成 */
} RecordStatus;
typedef struct __HxVideoRecord
{
/* 通道号 */
int channel;
/* 开始时间 */
QDateTime start_time;
/* 结束时间 */
QDateTime end_time;
/* 时长 */
int duration;
/* 名称 */
QString name;
/* 完整路径 */
QString path;
/* 录像状态 */
RecordStatus status = Null;
__HxVideoRecord() {}
void build(int channel, QDateTime startTime, QString rootPath, QString code)
{
this->channel = channel;
this->start_time = startTime;
this->end_time = QDateTime();
this->duration = 0;
this->name = QString("[%1][%2][%3][%4][Scheduled].avi")
.arg(code)
.arg(channel + 1, 2, 10, QChar('0'))
.arg(startTime.toString("yyyyMMdd"),
startTime.toString("HHmmsszzz"));
this->path = QString("%1HVNVR_RECORD/%2/%3/")
#ifdef Q_OS_WIN32
.arg(rootPath)
#else
.arg(rootPath + "/")
#endif
.arg(this->start_time.toString("yyyyMMdd"))
.arg(this->channel + 1, 2, 10, QChar('0'));
HxDisk::mkpath(path);
this->path += name;
}
void reset()
{
this->start_time = QDateTime();
this->duration = 0;
this->name = nullptr;
this->status = RecordStatus::Null;
}
} HxVideoRecord;
typedef struct __HxVideoFrame
{
QDateTime time;
AVPacket *packet;
__HxVideoFrame() {}
__HxVideoFrame(QDateTime time, AVPacket *packet)
{
this->time = time;
this->packet = av_packet_clone(packet);
}
__HxVideoFrame copy() { return __HxVideoFrame(this->time, this->packet); }
void free()
{
if (packet)
{
av_packet_unref(packet);
av_packet_free(&packet);
}
}
} HxVideoFrame;
#endif // MAIN_H