图片视频上传到FTP, 视频上传完毕后. 会传给RabbitMQ数据库队列; 解决: 报警录像生成BUG
This commit is contained in:
parent
617bd10348
commit
7d07da6402
1419
.gitignore
vendored
1419
.gitignore
vendored
File diff suppressed because it is too large
Load Diff
8
.vscode/settings.json
vendored
Normal file
8
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"__node_handle": "cpp",
|
||||
"optional": "cpp",
|
||||
"system_error": "cpp",
|
||||
"string": "cpp"
|
||||
}
|
||||
}
|
|
@ -1,18 +1,21 @@
|
|||
#include "HxDataBase.h"
|
||||
|
||||
QMutex DataBase::mutex;
|
||||
QSqlDatabase DataBase::database;
|
||||
QString DataBase::device_id;
|
||||
QString DataBase::ftp_address;
|
||||
QString DataBase::ftp_username;
|
||||
QString DataBase::ftp_password;
|
||||
int DataBase::algorithm_type;
|
||||
QString DataBase::dsm_video_input_source;
|
||||
QString DataBase::adas_video_input_source;
|
||||
QStringList DataBase::bsd_video_input_source;
|
||||
QStringList DataBase::bsd_warn_regions;
|
||||
#include "HxUtils.h"
|
||||
|
||||
QSqlDatabase DataBase::open(QString filepath, QString connectionName)
|
||||
QMutex HxDataBase::mutex;
|
||||
QSqlDatabase HxDataBase::database;
|
||||
QString HxDataBase::device_id;
|
||||
QString HxDataBase::ftp_address, HxDataBase::ftp_username, HxDataBase::ftp_password;
|
||||
QString HxDataBase::qamqp_address, HxDataBase::qamqp_username, HxDataBase::qamqp_password;
|
||||
int HxDataBase::algorithm_type;
|
||||
QString HxDataBase::dsm_video_input_source;
|
||||
QString HxDataBase::adas_video_input_source;
|
||||
QStringList HxDataBase::bsd_video_input_source;
|
||||
QStringList HxDataBase::bsd_warn_regions;
|
||||
EventWarnParamConfig HxDataBase::warm_param_config;
|
||||
CameraCalibration HxDataBase::adas_camera_calibration;
|
||||
|
||||
QSqlDatabase HxDataBase::open(QString filepath, QString connectionName)
|
||||
{
|
||||
QSqlDatabase db;
|
||||
if (QSqlDatabase::contains(connectionName))
|
||||
|
@ -40,14 +43,14 @@ QSqlDatabase DataBase::open(QString filepath, QString connectionName)
|
|||
* @brief 关闭数据库
|
||||
* @param connectionName 连接名
|
||||
*/
|
||||
void DataBase::close(QString connectionName) { QSqlDatabase::removeDatabase(connectionName); }
|
||||
void HxDataBase::close(QString connectionName) { QSqlDatabase::removeDatabase(connectionName); }
|
||||
|
||||
/**
|
||||
* @brief 读取 Setting 表数据
|
||||
* @param name name字段值
|
||||
* @return 返回对应参数
|
||||
*/
|
||||
QVariant DataBase::read_setting(QString name)
|
||||
QVariant HxDataBase::read_setting(QString name)
|
||||
{
|
||||
QVariant value;
|
||||
|
||||
|
@ -74,7 +77,7 @@ QVariant DataBase::read_setting(QString name)
|
|||
* @param defaultValue 默认值(int)
|
||||
* @return 返回对应参数(int)
|
||||
*/
|
||||
int DataBase::read_setting(QString name, int defaultValue)
|
||||
int HxDataBase::read_setting(QString name, int defaultValue)
|
||||
{
|
||||
auto value = read_setting(name);
|
||||
|
||||
|
@ -87,7 +90,7 @@ int DataBase::read_setting(QString name, int defaultValue)
|
|||
* @param defaultValue 默认值(bool)
|
||||
* @return 返回对应参数(bool)
|
||||
*/
|
||||
bool DataBase::read_setting(QString name, bool defaultValue)
|
||||
bool HxDataBase::read_setting(QString name, bool defaultValue)
|
||||
{
|
||||
auto value = read_setting(name);
|
||||
|
||||
|
@ -100,7 +103,7 @@ bool DataBase::read_setting(QString name, bool defaultValue)
|
|||
* @param defaultValue 默认值(string)
|
||||
* @return 返回对应参数(string)
|
||||
*/
|
||||
QString DataBase::read_setting(QString name, QString defaultValue)
|
||||
QString HxDataBase::read_setting(QString name, QString defaultValue)
|
||||
{
|
||||
auto value = read_setting(name);
|
||||
|
||||
|
@ -112,7 +115,7 @@ QString DataBase::read_setting(QString name, QString defaultValue)
|
|||
* @param name name字段值
|
||||
* @param value 对应参数
|
||||
*/
|
||||
void DataBase::write_setting(QString name, QString value)
|
||||
void HxDataBase::write_setting(QString name, QString value)
|
||||
{
|
||||
QMutexLocker lock(&mutex);
|
||||
|
||||
|
@ -128,7 +131,108 @@ void DataBase::write_setting(QString name, QString value)
|
|||
query.clear();
|
||||
}
|
||||
|
||||
void DataBase::initialization()
|
||||
void HxDataBase::read_warm_param_config(void)
|
||||
{
|
||||
auto start_event_warn_kind = read_setting("start_event_warn_kind", QString("1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1")).split(";");
|
||||
auto abnormal_warn_frame_count = read_setting("abnormal_warn_frame_count", QString("0;0;0;0;0;0;0;50;75;25;50;75;50;50;50;25;75;50;50;50;50;50;75;50;50;100")).split(";");
|
||||
auto normal_frame_count = read_setting("normal_frame_count", QString("0;0;0;0;0;0;0;25;25;25;25;25;25;25;25;25;25;25;25;25;25;25;0;0;0;0")).split(";");
|
||||
auto abnormal_warn_interval_frame_count = read_setting("abnormal_warn_interval_frame_count", QString("0;0;125;0;125;0;0;0;0;0;0;0;0;125;0;0;0;0;0;0;0;0;0;0;0;0")).split(";");
|
||||
auto abnormal_warn_score_threshold = read_setting("abnormal_warn_score_threshold", QString("0;0;0;0;0;0;0;0.7;0.8;0.4;0.65;0.95;0.75;0.3;0.65;0.5;0.87;25;25;20;15;0.75;0.3;0.5;0.5;0.5")).split(";");
|
||||
auto normal_warn_score_threshold = read_setting("normal_warn_score_threshold", QString("0;0;0;0;0;0;0;0.35;0.35;0.7;0.7;0.7;0.55;0.8;0.4;0.55;0.13;20;20;15;10;0.55;0.3;0.3;0.5;0.5")).split(";");
|
||||
|
||||
for (int i = 0; i < EVENT_WARN_NUM; i++)
|
||||
{
|
||||
warm_param_config.bStartEventWarnKind[i] = QVariant(start_event_warn_kind.at(i)).toBool();
|
||||
warm_param_config.nAbnormalWarnFrameCount[i] = abnormal_warn_frame_count.at(i).toInt();
|
||||
warm_param_config.nNormalFrameCount[i] = normal_frame_count.at(i).toInt();
|
||||
warm_param_config.nAbnormalWarnIntervalFrameCount[i] = abnormal_warn_interval_frame_count.at(i).toInt();
|
||||
warm_param_config.fAbnormalWarnScoreThreshold[i] = abnormal_warn_score_threshold.at(i).toFloat();
|
||||
warm_param_config.fNormalWarnScoreThreshold[i] = normal_warn_score_threshold.at(i).toFloat();
|
||||
}
|
||||
|
||||
warm_param_config.nHmwTime = read_setting("hmw_time", 1200);
|
||||
warm_param_config.nPcwTime = read_setting("pcw_time", 2000);
|
||||
warm_param_config.nFcwTime = read_setting("fcw_time", 2400);
|
||||
warm_param_config.fHmwVel = read_setting("hmw_vel", 30);
|
||||
warm_param_config.fFcwVel = read_setting("fcw_vel", 30);
|
||||
warm_param_config.fLdwVel = read_setting("ldw_vel", 55);
|
||||
warm_param_config.fPcwVel = read_setting("pcw_vel", 50);
|
||||
warm_param_config.fBsdFirstVel = read_setting("bsd_first_vel", 30);
|
||||
warm_param_config.fBsdSecondVel = read_setting("bsd_second_vel", 30);
|
||||
warm_param_config.fBsdThirdVel = read_setting("bsd_third_vel", 30);
|
||||
warm_param_config.nLdwDistance = read_setting("ldw_distance", -5);
|
||||
warm_param_config.fDsmVel = read_setting("dsm_vel", 5);
|
||||
}
|
||||
|
||||
void HxDataBase::write_warm_param_config(void)
|
||||
{
|
||||
QStringList start_event_warn_kind, abnormal_warn_frame_count, normal_frame_count, abnormal_warn_interval_frame_count, abnormal_warn_score_threshold, normal_warn_score_threshold;
|
||||
|
||||
for (int i = 0; i < EVENT_WARN_NUM; i++)
|
||||
{
|
||||
start_event_warn_kind.append(QString::number(warm_param_config.bStartEventWarnKind[i]));
|
||||
abnormal_warn_frame_count.append(QString::number(warm_param_config.nAbnormalWarnFrameCount[i]));
|
||||
normal_frame_count.append(QString::number(warm_param_config.nNormalFrameCount[i]));
|
||||
abnormal_warn_interval_frame_count.append(QString::number(warm_param_config.nAbnormalWarnIntervalFrameCount[i]));
|
||||
abnormal_warn_score_threshold.append(QString::number(warm_param_config.fAbnormalWarnScoreThreshold[i]));
|
||||
normal_warn_score_threshold.append(QString::number(warm_param_config.fNormalWarnScoreThreshold[i]));
|
||||
}
|
||||
|
||||
write_setting("start_event_warn_kind", start_event_warn_kind.join(";"));
|
||||
write_setting("abnormal_warn_frame_count", abnormal_warn_frame_count.join(";"));
|
||||
write_setting("normal_frame_count", normal_frame_count.join(";"));
|
||||
write_setting("abnormal_warn_interval_frame_count", abnormal_warn_interval_frame_count.join(";"));
|
||||
write_setting("abnormal_warn_score_threshold", abnormal_warn_score_threshold.join(";"));
|
||||
write_setting("normal_warn_score_threshold", normal_warn_score_threshold.join(";"));
|
||||
write_setting("hmw_time", QString::number(warm_param_config.nHmwTime));
|
||||
write_setting("pcw_time", QString::number(warm_param_config.nPcwTime));
|
||||
write_setting("fcw_time", QString::number(warm_param_config.nFcwTime));
|
||||
write_setting("hmw_vel", QString::number(warm_param_config.fHmwVel));
|
||||
write_setting("fcw_vel", QString::number(warm_param_config.fFcwVel));
|
||||
write_setting("ldw_vel", QString::number(warm_param_config.fLdwVel));
|
||||
write_setting("pcw_vel", QString::number(warm_param_config.fPcwVel));
|
||||
write_setting("bsd_first_vel", QString::number(warm_param_config.fBsdFirstVel));
|
||||
write_setting("bsd_second_vel", QString::number(warm_param_config.fBsdSecondVel));
|
||||
write_setting("bsd_third_vel", QString::number(warm_param_config.fBsdThirdVel));
|
||||
write_setting("ldw_distance", QString::number(warm_param_config.nLdwDistance));
|
||||
write_setting("dsm_vel", QString::number(warm_param_config.fDsmVel));
|
||||
}
|
||||
|
||||
void HxDataBase::read_adas_camera_calibration(void)
|
||||
{
|
||||
auto value = read_setting("adas_camera_calibration", QString("4527;1830;0;1695;0;1500;6.00;0.00;-0.32;0.00")).split(";");
|
||||
|
||||
adas_camera_calibration.fCarLen = value[0].toInt();
|
||||
adas_camera_calibration.fCarWidth = value[1].toInt();
|
||||
adas_camera_calibration.fRefCenter = value[2].toInt();
|
||||
adas_camera_calibration.fRefTop = value[3].toInt();
|
||||
adas_camera_calibration.fDisLen2Tyre = value[4].toInt();
|
||||
adas_camera_calibration.fCameraHeight = value[5].toInt();
|
||||
adas_camera_calibration.fCameraFocus = value[6].toFloat();
|
||||
adas_camera_calibration.fCameraDx = value[7].toFloat();
|
||||
adas_camera_calibration.fPitch = value[8].toFloat();
|
||||
adas_camera_calibration.fYaw = value[9].toFloat();
|
||||
}
|
||||
|
||||
void HxDataBase::write_adas_camera_calibration(void)
|
||||
{
|
||||
QStringList value;
|
||||
|
||||
value.append(QString::number(adas_camera_calibration.fCarLen));
|
||||
value.append(QString::number(adas_camera_calibration.fCarWidth));
|
||||
value.append(QString::number(adas_camera_calibration.fRefCenter));
|
||||
value.append(QString::number(adas_camera_calibration.fRefTop));
|
||||
value.append(QString::number(adas_camera_calibration.fDisLen2Tyre));
|
||||
value.append(QString::number(adas_camera_calibration.fCameraHeight));
|
||||
value.append(QString::number(adas_camera_calibration.fCameraFocus, 'f', 2));
|
||||
value.append(QString::number(adas_camera_calibration.fCameraDx, 'f', 2));
|
||||
value.append(QString::number(adas_camera_calibration.fPitch, 'f', 2));
|
||||
value.append(QString::number(adas_camera_calibration.fYaw, 'f', 2));
|
||||
|
||||
write_setting("adas_camera_calibration", value.join(";"));
|
||||
}
|
||||
|
||||
void HxDataBase::initialization()
|
||||
{
|
||||
database = open("DataBase.db", "DataBase");
|
||||
|
||||
|
@ -146,21 +250,22 @@ void DataBase::initialization()
|
|||
" [value] TEXT"
|
||||
");"))
|
||||
{
|
||||
qDebug("配置表创建失败");
|
||||
HxLog::append("database", "setting read failed");
|
||||
return;
|
||||
}
|
||||
|
||||
/* */
|
||||
/* 设备编号 */
|
||||
device_id = read_setting("device_id", QString("TVIS"));
|
||||
|
||||
/* */
|
||||
/* FTP信息 */
|
||||
ftp_address = read_setting("ftp_address", QString("192.168.10.10:7616"));
|
||||
|
||||
/* */
|
||||
ftp_username = read_setting("ftp_username", QString("nvruser"));
|
||||
ftp_password = read_setting("ftp_password", QString("Sztvis_789."));
|
||||
|
||||
/* */
|
||||
ftp_password = read_setting("ftp_password", QString("Sztvis_789."));
|
||||
qamqp_address = read_setting("qamqp_address", QString("192.168.1.227:5672"));
|
||||
qamqp_username = read_setting("qamqp_username", QString("root"));
|
||||
qamqp_password = read_setting("qamqp_password", QString("Sztvis@789."));
|
||||
|
||||
/* 算法类型, 默认 BSD */
|
||||
algorithm_type = read_setting("algorithm_type", 0x02);
|
||||
|
@ -174,6 +279,7 @@ void DataBase::initialization()
|
|||
/* BSD 视频输入源 (string) */
|
||||
bsd_video_input_source = read_setting("bsd_video_input_source", QString(";;;;;;")).split(";");
|
||||
|
||||
/* BSD 报警区域 */
|
||||
bsd_warn_regions = read_setting(
|
||||
"bsd_warn_regions",
|
||||
QString("0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
|
||||
|
@ -183,9 +289,15 @@ void DataBase::initialization()
|
|||
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0*"
|
||||
"0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0$0,0 0,0 0,0 0,0"))
|
||||
.split("*");
|
||||
|
||||
/* 读取报警参数配置 */
|
||||
read_warm_param_config();
|
||||
|
||||
/* 读取 ADAS 相机内外参 */
|
||||
read_adas_camera_calibration();
|
||||
}
|
||||
|
||||
bool DataBase::save_setting()
|
||||
bool HxDataBase::save_setting()
|
||||
{
|
||||
database.transaction();
|
||||
|
||||
|
@ -193,11 +305,16 @@ bool DataBase::save_setting()
|
|||
write_setting("ftp_address", ftp_address);
|
||||
write_setting("ftp_username", ftp_username);
|
||||
write_setting("ftp_password", ftp_password);
|
||||
write_setting("qamqp_address", qamqp_address);
|
||||
write_setting("qamqp_username", qamqp_username);
|
||||
write_setting("qamqp_password", qamqp_password);
|
||||
write_setting("algorithm_type", QString::number(algorithm_type));
|
||||
write_setting("dsm_video_input_source", dsm_video_input_source);
|
||||
write_setting("adas_video_input_source", adas_video_input_source);
|
||||
write_setting("bsd_video_input_source", bsd_video_input_source.join(";"));
|
||||
write_setting("bsd_warn_regions", bsd_warn_regions.join("*"));
|
||||
write_warm_param_config();
|
||||
write_adas_camera_calibration();
|
||||
|
||||
return database.commit();
|
||||
}
|
||||
|
@ -207,7 +324,7 @@ bool DataBase::save_setting()
|
|||
* @param channel 通道号
|
||||
* @return 返回 BsdWarnRegion 结构体
|
||||
*/
|
||||
BsdWarnRegion DataBase::get_bsd_warn_region(int channel)
|
||||
BsdWarnRegion HxDataBase::get_bsd_warn_region(int channel)
|
||||
{
|
||||
BsdWarnRegion ret;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#define BSD_MAX_CHANNEL 6
|
||||
|
||||
class DataBase
|
||||
class HxDataBase
|
||||
{
|
||||
private:
|
||||
/**
|
||||
|
@ -68,6 +68,14 @@ private:
|
|||
*/
|
||||
static void write_setting(QString name, QString value);
|
||||
|
||||
static void read_warm_param_config(void);
|
||||
|
||||
static void write_warm_param_config(void);
|
||||
|
||||
static void read_adas_camera_calibration(void);
|
||||
|
||||
static void write_adas_camera_calibration(void);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief 初始化
|
||||
|
@ -104,30 +112,28 @@ public:
|
|||
/* FTP密码 */
|
||||
static QString ftp_password;
|
||||
|
||||
/**
|
||||
* 算法类型
|
||||
*/
|
||||
static QString qamqp_address, qamqp_username, qamqp_password;
|
||||
|
||||
/* 算法类型 */
|
||||
static int algorithm_type;
|
||||
|
||||
/**
|
||||
* DSM 视频输入源
|
||||
*/
|
||||
/* DSM 视频输入源 */
|
||||
static QString dsm_video_input_source;
|
||||
|
||||
/**
|
||||
* ADAS 视频输入源
|
||||
*/
|
||||
/* ADAS 视频输入源 */
|
||||
static QString adas_video_input_source;
|
||||
|
||||
/**
|
||||
* BSD 视频输入源
|
||||
*/
|
||||
/* BSD 视频输入源 */
|
||||
static QStringList bsd_video_input_source;
|
||||
|
||||
/**
|
||||
* BSD 报警区域
|
||||
*/
|
||||
/* BSD 报警区域 */
|
||||
static QStringList bsd_warn_regions;
|
||||
|
||||
/* 报警参数配置 */
|
||||
static EventWarnParamConfig warm_param_config;
|
||||
|
||||
/* ADAS 相机内外参 */
|
||||
static CameraCalibration adas_camera_calibration;
|
||||
};
|
||||
|
||||
#endif // HXDATABASE_H
|
||||
|
|
|
@ -6,115 +6,141 @@
|
|||
#include <QJsonDocument>
|
||||
|
||||
/* 视频设备 */
|
||||
VideoDevice adas_video_device, bsd_video_device[6], dsm_video_device;
|
||||
HxVideoDevice adas_video_device, bsd_video_device[6], dsm_video_device;
|
||||
|
||||
TaskDispatch *dispatcher = new TaskDispatch();
|
||||
HxTaskDispatch* dispatcher = new HxTaskDispatch();
|
||||
|
||||
QMutex upload_file_mutex;
|
||||
QQueue<QString> upload_file_queue;
|
||||
|
||||
#ifdef USE_RABBITMQ
|
||||
HxRabbitMQUtils HxRabbitMQ;
|
||||
#endif
|
||||
|
||||
/* 倒车灯;1:亮;0:熄灭 */
|
||||
static int reversing_light = 0;
|
||||
|
||||
/* 车辆状态: 1 直行; 2 左转弯; 3 右转弯; 4 倒车 */
|
||||
static int vehicle_status = 0;
|
||||
|
||||
static int detect_channel = 0;
|
||||
|
||||
void TaskDispatch::initialization(void)
|
||||
void HxTaskDispatch::initialization(void)
|
||||
{
|
||||
HxLog::append("initialization", QString("algorithm_type=%1").arg(HxDataBase::algorithm_type));
|
||||
HxLog::append("initialization", QString("ftp=%1,%2,%3").arg(HxDataBase::ftp_address, HxDataBase::ftp_username, HxDataBase::ftp_password));
|
||||
HxLog::append("initialization", QString("rabbitmq=%1,%2,%3").arg(HxDataBase::qamqp_address, HxDataBase::qamqp_username, HxDataBase::qamqp_password));
|
||||
|
||||
/* 算法模块初始化 */
|
||||
#if USE_ALGORITHM
|
||||
/* adas检测配置 */
|
||||
strcpy(dispatcher->event_detect_config.szAdasDetectConfigPathName, "/opt/algmode/adas_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szAdasDetectConfigPathName, "./algmode/adas_detect.bin");
|
||||
/* adas跟踪配置 */
|
||||
strcpy(dispatcher->event_detect_config.szAdasTrackConfigPathName, "/opt/algmode/adas_track.bin");
|
||||
strcpy(dispatcher->event_detect_config.szAdasTrackConfigPathName, "./algmode/adas_track.bin");
|
||||
/* bsd检测配置 */
|
||||
strcpy(dispatcher->event_detect_config.szBsdDetectConfigPathName, "/opt/algmode/bsd_detect.bin");
|
||||
// strcpy(dispatcher->event_detect_config.szRightBsdFrontDetectConfigPathName, "/opt/algmode/bsd_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szBsdDetectConfigPathName, "./algmode/bsd_detect.bin");
|
||||
// strcpy(dispatcher->event_detect_config.szRightBsdFrontDetectConfigPathName, "./algmode/bsd_detect.bin");
|
||||
/* dsm人脸检测配置 */
|
||||
strcpy(dispatcher->event_detect_config.szDsmFaceDetectConfigPathName, "/opt/algmode/dsm_face_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmFaceDetectConfigPathName, "./algmode/dsm_face_detect.bin");
|
||||
/* dsm人脸特征点检测配置 */
|
||||
strcpy(dispatcher->event_detect_config.szDsmFaceLandMarksDetectConfigPathName, "/opt/algmode/dsm_face_landmarks_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmFaceLandMarksDetectConfigPathName, "./algmode/dsm_face_landmarks_detect.bin");
|
||||
/* dsm人脸认证检测配置 */
|
||||
strcpy(dispatcher->event_detect_config.szDsmFaceVerificationDetectConfigPathName, "/opt/algmode/dsm_face_verification_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmFaceVerificationDetectConfigPathName, "./algmode/dsm_face_verification_detect.bin");
|
||||
/* dsm人眼认证检测配置 */
|
||||
strcpy(dispatcher->event_detect_config.szDsmEyeLandMarksDetectConfigPathName, "/opt/algmode/dsm_eye_landmarks_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmEyeLandMarksDetectConfigPathName, "./algmode/dsm_eye_landmarks_detect.bin");
|
||||
/* dsm人脸认证检测配置 */
|
||||
strcpy(dispatcher->event_detect_config.szDsmSmokeConfPathName, "/opt/algmode/dsm_smoke_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmCallConfPathName, "/opt/algmode/dsm_call_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmFaceFeaturePathName, "/opt/algmode/dsm_face_feature.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmHeadPoseConfPathName, "/opt/algmode/data_68kp");
|
||||
strcpy(dispatcher->event_detect_config.szDsmSmokeConfPathName, "./algmode/dsm_smoke_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmCallConfPathName, "./algmode/dsm_call_detect.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmFaceFeaturePathName, "./algmode/dsm_face_feature.bin");
|
||||
strcpy(dispatcher->event_detect_config.szDsmHeadPoseConfPathName, "./algmode/data_68kp");
|
||||
|
||||
/* 输出调试信息 */
|
||||
MvSetPrintf(false);
|
||||
|
||||
/* 目标跟踪事件检测初始化 */
|
||||
auto result = MvObjectEventDetectInit(&dispatcher->event_detect_config, RIGHT_BSD_FRONT_DETECT_CHANNEL |
|
||||
RIGHT_BSD_REAR_DETECT_CHANNEL |
|
||||
LEFT_BSD_FRONT_DETECT_CHANNEL |
|
||||
LEFT_BSD_REAR_DETECT_CHANNEL |
|
||||
FRONT_BSD_DETECT_CHANNEL |
|
||||
REAR_BSD_DETECT_CHANNEL |
|
||||
DMS_DETECT_CHANNEL |
|
||||
ADAS_DETECT_CHANNEL);
|
||||
|
||||
auto result = MvObjectEventDetectInit(&dispatcher->event_detect_config, RIGHT_BSD_FRONT_DETECT_CHANNEL | RIGHT_BSD_REAR_DETECT_CHANNEL | LEFT_BSD_FRONT_DETECT_CHANNEL | LEFT_BSD_REAR_DETECT_CHANNEL | FRONT_BSD_DETECT_CHANNEL | REAR_BSD_DETECT_CHANNEL | DMS_DETECT_CHANNEL | ADAS_DETECT_CHANNEL);
|
||||
if (result != 0)
|
||||
{
|
||||
HxLog::append("initialization", "object event detect init failed!!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* 设置报警参数 */
|
||||
result = MvSetEventWarnParamConfig(&HxDataBase::warm_param_config);
|
||||
if (result != 0)
|
||||
HxLog::append("initialization", "set event warn param config failed!!");
|
||||
|
||||
|
||||
/* 相机标定 */
|
||||
if(MvCameraCalibration(&HxDataBase::adas_camera_calibration) != 0)
|
||||
HxLog::append("initialization", "camera calibration failed!!");
|
||||
#endif
|
||||
|
||||
/* ADAS 通道初始化 */
|
||||
if ((DataBase::algorithm_type & 0x1) == 1)
|
||||
{
|
||||
adas_video_device.set(0, DataBase::adas_video_input_source);
|
||||
}
|
||||
if ((HxDataBase::algorithm_type & 0x1) == 1)
|
||||
adas_video_device.set(0, HxDataBase::adas_video_input_source);
|
||||
|
||||
/* BSD 通道初始化 */
|
||||
if (((DataBase::algorithm_type >> 1) & 0x1) == 1)
|
||||
if (((HxDataBase::algorithm_type >> 1) & 0x1) == 1)
|
||||
{
|
||||
/* BSD-前 */
|
||||
bsd_video_device[0].set(6, DataBase::bsd_video_input_source[0], DataBase::get_bsd_warn_region(0));
|
||||
bsd_video_device[0].set(6, HxDataBase::bsd_video_input_source[0], HxDataBase::get_bsd_warn_region(0));
|
||||
|
||||
/* BSD-后 */
|
||||
bsd_video_device[1].set(7, DataBase::bsd_video_input_source[1], DataBase::get_bsd_warn_region(1));
|
||||
bsd_video_device[1].set(7, HxDataBase::bsd_video_input_source[1], HxDataBase::get_bsd_warn_region(1));
|
||||
|
||||
/* BSD-左前 */
|
||||
bsd_video_device[2].set(4, DataBase::bsd_video_input_source[2], DataBase::get_bsd_warn_region(2));
|
||||
bsd_video_device[2].set(4, HxDataBase::bsd_video_input_source[2], HxDataBase::get_bsd_warn_region(2));
|
||||
|
||||
/* BSD-右前 */
|
||||
bsd_video_device[3].set(1, DataBase::bsd_video_input_source[3], DataBase::get_bsd_warn_region(3));
|
||||
bsd_video_device[3].set(1, HxDataBase::bsd_video_input_source[3], HxDataBase::get_bsd_warn_region(3));
|
||||
|
||||
/* BSD-左后 */
|
||||
bsd_video_device[4].set(5, DataBase::bsd_video_input_source[4], DataBase::get_bsd_warn_region(4));
|
||||
bsd_video_device[4].set(5, HxDataBase::bsd_video_input_source[4], HxDataBase::get_bsd_warn_region(4));
|
||||
|
||||
/* BSD-右后 */
|
||||
bsd_video_device[5].set(3, DataBase::bsd_video_input_source[5], DataBase::get_bsd_warn_region(5));
|
||||
bsd_video_device[5].set(3, HxDataBase::bsd_video_input_source[5], HxDataBase::get_bsd_warn_region(5));
|
||||
}
|
||||
|
||||
/* DSM 通道初始化 */
|
||||
if (((DataBase::algorithm_type >> 2) & 0x1) == 1)
|
||||
{
|
||||
dsm_video_device.set(2, DataBase::dsm_video_input_source);
|
||||
}
|
||||
if (((HxDataBase::algorithm_type >> 2) & 0x1) == 1)
|
||||
dsm_video_device.set(2, HxDataBase::dsm_video_input_source);
|
||||
|
||||
dispatcher->start();
|
||||
|
||||
#ifdef USE_RABBITMQ
|
||||
HxRabbitMQ.set(HxDataBase::qamqp_address, HxDataBase::qamqp_username, HxDataBase::qamqp_password);
|
||||
HxRabbitMQ.set_exchanger_name("vehicle.direct.exchange");
|
||||
HxRabbitMQ.set_queue_name("bsd_video_transcode_tag");
|
||||
HxRabbitMQ.set_routing_key("bsd_video_transcode_tag_1");
|
||||
#endif
|
||||
}
|
||||
|
||||
void TaskDispatch::listern(uint16_t port)
|
||||
void HxTaskDispatch::listern(uint16_t port)
|
||||
{
|
||||
dispatcher->debug_tool = new HxSocketUtils(port);
|
||||
|
||||
connect(dispatcher->debug_tool, &HxSocketUtils::data_receive_event, dispatcher, &TaskDispatch::data_receive_event);
|
||||
connect(dispatcher, &TaskDispatch::data_write_event, dispatcher->debug_tool, &HxSocketUtils::write);
|
||||
connect(dispatcher->debug_tool, &HxSocketUtils::data_receive_event, dispatcher, &HxTaskDispatch::data_receive_event);
|
||||
connect(dispatcher, &HxTaskDispatch::data_write_event, dispatcher->debug_tool, &HxSocketUtils::write);
|
||||
}
|
||||
|
||||
void TaskDispatch::connect_to_host(QString address, int port)
|
||||
void HxTaskDispatch::connect_to_host(QString address, int port)
|
||||
{
|
||||
dispatcher->platform = new HxSocketUtils(address, port);
|
||||
|
||||
connect(dispatcher->platform, &HxSocketUtils::data_receive_event, dispatcher, &TaskDispatch::data_receive_event);
|
||||
connect(dispatcher, &TaskDispatch::data_write_event, dispatcher->platform, &HxSocketUtils::write);
|
||||
connect(dispatcher->platform, &HxSocketUtils::data_receive_event, dispatcher, &HxTaskDispatch::data_receive_event);
|
||||
connect(dispatcher, &HxTaskDispatch::data_write_event, dispatcher->platform, &HxSocketUtils::write);
|
||||
}
|
||||
|
||||
void TaskDispatch::algorithm_alarm_event(int channel, int level, int event_type, int detect_type, int left, int top, int right, int bottom, int distance, int speed, QString base64_string, QString filepath)
|
||||
void HxTaskDispatch::algorithm_alarm_event(QDateTime time, int channel, int level, int event_type, int detect_type, int left, int top, int right, int bottom, int distance, int speed, QString base64_string, QString filepath)
|
||||
{
|
||||
Q_UNUSED(speed);
|
||||
|
||||
QJsonObject root({ {"type", 4} });
|
||||
|
||||
QJsonObject msgInfo({{"channel", channel},
|
||||
QJsonObject msgInfo({ {"time", time.toString("yyyy-MM-dd HH:mm:ss")},
|
||||
{"channel", channel},
|
||||
{"level", level},
|
||||
{"event_type", event_type},
|
||||
{"detect_type", detect_type},
|
||||
|
@ -123,7 +149,7 @@ void TaskDispatch::algorithm_alarm_event(int channel, int level, int event_type,
|
|||
{"right", right},
|
||||
{"bottom", bottom},
|
||||
{"distance", distance},
|
||||
{"speed", speed},
|
||||
{"speed", dispatcher->car_info.fVelocity},
|
||||
{"image", base64_string},
|
||||
{"filepath", filepath} });
|
||||
|
||||
|
@ -131,12 +157,14 @@ void TaskDispatch::algorithm_alarm_event(int channel, int level, int event_type,
|
|||
|
||||
emit dispatcher->data_write_event(QJsonDocument(root).toJson(QJsonDocument::Compact));
|
||||
|
||||
HxLog::append("algorithm", QString("alarm type=0x%1, filepath=%2").arg(QString::number(event_type, 16), filepath));
|
||||
|
||||
// dispatcher->send_can_data(channel, pObjectTrackEventResult->nDangerLevel, pObjectTrackEventResult->objInfo[i].nDetectType);
|
||||
}
|
||||
|
||||
CarInfoInput *TaskDispatch::get_car_info(void) { return &dispatcher->car_info; }
|
||||
CarInfoInput* HxTaskDispatch::get_car_info(void) { return &dispatcher->car_info; }
|
||||
|
||||
QString TaskDispatch::get_video_frame_data(int type, int channel, int id)
|
||||
QString HxTaskDispatch::get_video_frame_data(int type, int channel, int id)
|
||||
{
|
||||
Q_UNUSED(channel);
|
||||
|
||||
|
@ -153,7 +181,22 @@ QString TaskDispatch::get_video_frame_data(int type, int channel, int id)
|
|||
return "";
|
||||
}
|
||||
|
||||
QString TaskDispatch::build_alarm_image(int type, int channel, int frame_id)
|
||||
bool HxTaskDispatch::get_alarm_detection_timestamp(int type, int channel)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
return adas_video_device.get_alarm_detection_timestamp();
|
||||
case 1:
|
||||
return bsd_video_device[channel].get_alarm_detection_timestamp();
|
||||
case 2:
|
||||
return dsm_video_device.get_alarm_detection_timestamp();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QString HxTaskDispatch::build_alarm_image(int type, int channel, int frame_id)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
@ -168,7 +211,7 @@ QString TaskDispatch::build_alarm_image(int type, int channel, int frame_id)
|
|||
return "";
|
||||
}
|
||||
|
||||
QString TaskDispatch::build_alarm_video(int type, int channel, int frame_id)
|
||||
QString HxTaskDispatch::build_alarm_video(int type, int channel, int frame_id)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
@ -183,7 +226,14 @@ QString TaskDispatch::build_alarm_video(int type, int channel, int frame_id)
|
|||
return "";
|
||||
}
|
||||
|
||||
void TaskDispatch::update_heartbeat()
|
||||
void HxTaskDispatch::enqueue_upload_file(QString filename)
|
||||
{
|
||||
upload_file_mutex.lock();
|
||||
upload_file_queue.enqueue(filename);
|
||||
upload_file_mutex.unlock();
|
||||
}
|
||||
|
||||
void HxTaskDispatch::update_heartbeat()
|
||||
{
|
||||
if (QDateTime::currentDateTime() > heartbeat_timestamp.addSecs(30))
|
||||
{
|
||||
|
@ -193,7 +243,7 @@ void TaskDispatch::update_heartbeat()
|
|||
}
|
||||
}
|
||||
|
||||
void TaskDispatch::updata_vehiclue_status(QJsonObject object)
|
||||
void HxTaskDispatch::updata_vehiclue_status(QJsonObject object)
|
||||
{
|
||||
vehicle_status_update_time = QDateTime::currentDateTime();
|
||||
|
||||
|
@ -207,9 +257,11 @@ void TaskDispatch::updata_vehiclue_status(QJsonObject object)
|
|||
car_info.fSteeingWheelAngle = object.value("seeing_wheel_angle").toDouble();
|
||||
|
||||
reversing_light = object.value("reversing_light").toInt();
|
||||
|
||||
HxLog::append("vehiclue status", QString(QJsonDocument(object).toJson(QJsonDocument::Compact)));
|
||||
}
|
||||
|
||||
void TaskDispatch::parsing_vehiclue_status(void)
|
||||
void HxTaskDispatch::parsing_vehiclue_status(void)
|
||||
{
|
||||
if (dispatcher->vehicle_status_update_time.secsTo(QDateTime::currentDateTime()) >= 10)
|
||||
car_info.fVelocity = 0;
|
||||
|
@ -219,19 +271,19 @@ void TaskDispatch::parsing_vehiclue_status(void)
|
|||
auto _detect_channel = 0;
|
||||
|
||||
/* ADAS 通道初始化 */
|
||||
if ((DataBase::algorithm_type & 0x1) == 1)
|
||||
if ((HxDataBase::algorithm_type & 0x1) == 1)
|
||||
{
|
||||
_detect_channel |= ADAS_DETECT_CHANNEL;
|
||||
}
|
||||
|
||||
/* DSM 通道初始化 */
|
||||
if (((DataBase::algorithm_type >> 2) & 0x1) == 1)
|
||||
if (((HxDataBase::algorithm_type >> 2) & 0x1) == 1)
|
||||
{
|
||||
_detect_channel |= DMS_DETECT_CHANNEL;
|
||||
}
|
||||
|
||||
/* BSD 类型 */
|
||||
else if (((DataBase::algorithm_type >> 1) & 0x1) == 1)
|
||||
else if (((HxDataBase::algorithm_type >> 1) & 0x1) == 1)
|
||||
{
|
||||
auto status = 0;
|
||||
|
||||
|
@ -254,7 +306,7 @@ void TaskDispatch::parsing_vehiclue_status(void)
|
|||
/* 车辆状态发生改变 */
|
||||
if (status != 0 && vehicle_status != status)
|
||||
{
|
||||
qDebug() << "车辆状态发生改变 " << vehicle_status << " => " << status;
|
||||
HxLog::append("vehicle status", QString("vehicle status change, %1=>%2").arg(vehicle_status).arg(status));
|
||||
|
||||
vehicle_status = status;
|
||||
|
||||
|
@ -319,12 +371,84 @@ void TaskDispatch::parsing_vehiclue_status(void)
|
|||
#if USE_ALGORITHM
|
||||
MvSetDetectChannel(detect_channel);
|
||||
#endif
|
||||
HxLog::append("algorithm", QString("starting detect channel=0x%1").arg(QString::number(detect_channel, 16)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDispatch::run()
|
||||
void HxTaskDispatch::recording_upload_task(void)
|
||||
{
|
||||
QString command;
|
||||
|
||||
while(true)
|
||||
{
|
||||
if (!upload_file_queue.isEmpty())
|
||||
{
|
||||
upload_file_mutex.lock();
|
||||
auto filename = upload_file_queue.dequeue();
|
||||
upload_file_mutex.unlock();
|
||||
|
||||
if(!QFile::exists(filename))
|
||||
{
|
||||
HxLog::append("recording upload task", QString("file=%1 not exists, upload failed").arg(filename));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
QString path = QString("%1/%2/alarm").arg(QDateTime::currentDateTime().toString("yyyyMMdd"), HxDataBase::device_id);
|
||||
|
||||
while (true)
|
||||
{
|
||||
/* FTP 上传 */
|
||||
HxProcess::execute(QString("curl -u %1:%2 ftp://%3/%4/ --ftp-create-dirs -T %5").arg(HxDataBase::ftp_username, HxDataBase::ftp_password, HxDataBase::ftp_address, path, filename));
|
||||
|
||||
command = QString("curl -u %1:%2 --ftp-ssl --head ftp://%3/%4/%5").arg(HxDataBase::ftp_username, HxDataBase::ftp_password, HxDataBase::ftp_address, path, filename);
|
||||
|
||||
/* 判断FTP文件是否存在 */
|
||||
auto res = HxProcess::start(command);
|
||||
|
||||
QRegExp rx("Content-Length:\\s\\d{1,9}");
|
||||
|
||||
if (rx.indexIn(res, 0) == -1)
|
||||
continue;
|
||||
|
||||
QFileInfo info(filename);
|
||||
|
||||
auto size1 = info.size();
|
||||
auto size2 = rx.cap(0).replace("Content-Length:", "").toInt();
|
||||
|
||||
if (size1 == size2)
|
||||
{
|
||||
HxLog::append("recording upload task", QString("%1 upload finish").arg(filename));
|
||||
|
||||
qDebug() << info.suffix();
|
||||
if(info.suffix() == "mp4")
|
||||
{
|
||||
#ifdef USE_RABBITMQ
|
||||
emit HxRabbitMQ.publish(QString("{\"ftproot\": \"%1\", \"complate\": true}").arg(("/"+path+"/"+filename)));
|
||||
#endif
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
msleep(100);
|
||||
}
|
||||
|
||||
QFile::remove(filename);
|
||||
|
||||
HxLog::append("recording upload task", QString("%1 delete").arg(filename));
|
||||
}
|
||||
|
||||
msleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void HxTaskDispatch::run()
|
||||
{
|
||||
/* 启动 录像上传任务 */
|
||||
QtConcurrent::run(this, &HxTaskDispatch::recording_upload_task);
|
||||
|
||||
while (true)
|
||||
{
|
||||
QCoreApplication::processEvents();
|
||||
|
@ -335,11 +459,11 @@ void TaskDispatch::run()
|
|||
/* 分析车辆行驶状态 */
|
||||
parsing_vehiclue_status();
|
||||
|
||||
QThread::msleep(10);
|
||||
QThread::msleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskDispatch::debug_tool_response_event(int type, std::initializer_list<QPair<QString, QJsonValue>> args)
|
||||
void HxTaskDispatch::debug_tool_response_event(int type, std::initializer_list<QPair<QString, QJsonValue>> args)
|
||||
{
|
||||
QJsonObject root, msginfo;
|
||||
|
||||
|
@ -352,7 +476,137 @@ void TaskDispatch::debug_tool_response_event(int type, std::initializer_list<QPa
|
|||
emit data_write_event(QJsonDocument(root).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
void TaskDispatch::data_receive_event(QByteArray data)
|
||||
void HxTaskDispatch::get_warn_param_config(int type)
|
||||
{
|
||||
#if USE_ALGORITHM
|
||||
if (MvGetEventWarnParamConfig(&HxDataBase::warm_param_config) == -1)
|
||||
return;
|
||||
#endif
|
||||
|
||||
QJsonArray start_event_warn_kind, abnormal_warn_frame_count, normal_frame_count, abnormal_warn_interval_frame_count, abnormal_warn_score_threshold, normal_warn_score_threshold;
|
||||
for (int i = 0; i < EVENT_WARN_NUM; i++)
|
||||
{
|
||||
start_event_warn_kind.append(HxDataBase::warm_param_config.bStartEventWarnKind[i]);
|
||||
abnormal_warn_frame_count.append(HxDataBase::warm_param_config.nAbnormalWarnFrameCount[i] / 25);
|
||||
normal_frame_count.append(HxDataBase::warm_param_config.nNormalFrameCount[i] / 25);
|
||||
abnormal_warn_interval_frame_count.append(HxDataBase::warm_param_config.nAbnormalWarnIntervalFrameCount[i] / 25);
|
||||
abnormal_warn_score_threshold.append((int)(HxDataBase::warm_param_config.fAbnormalWarnScoreThreshold[i] * ((i >= 17 && i <= 20) ? 1 : 100)));
|
||||
normal_warn_score_threshold.append((int)(HxDataBase::warm_param_config.fNormalWarnScoreThreshold[i] * ((i >= 17 && i <= 20) ? 1 : 100)));
|
||||
|
||||
qDebug() << "enable=" << HxDataBase::warm_param_config.bStartEventWarnKind[i]
|
||||
<< "nAbnormalWarnFrameCount=" << HxDataBase::warm_param_config.nAbnormalWarnFrameCount[i]
|
||||
<< "nNormalFrameCount=" << HxDataBase::warm_param_config.nNormalFrameCount[i]
|
||||
<< "nAbnormalWarnIntervalFrameCount" << HxDataBase::warm_param_config.nAbnormalWarnIntervalFrameCount[i]
|
||||
<< "fAbnormalWarnScoreThreshold=" << HxDataBase::warm_param_config.fAbnormalWarnScoreThreshold[i]
|
||||
<< "fNormalWarnScoreThreshold=" << HxDataBase::warm_param_config.fNormalWarnScoreThreshold[i];
|
||||
}
|
||||
|
||||
debug_tool_response_event(type, { {"start_event_warn_kind", start_event_warn_kind},
|
||||
{"abnormal_warn_frame_count", abnormal_warn_frame_count},
|
||||
{"normal_frame_count", normal_frame_count},
|
||||
{"abnormal_warn_interval_frame_count", abnormal_warn_interval_frame_count},
|
||||
{"abnormal_warn_score_threshold", abnormal_warn_score_threshold},
|
||||
{"normal_warn_score_threshold", normal_warn_score_threshold},
|
||||
{"hmw_time", HxDataBase::warm_param_config.nHmwTime},
|
||||
{"pcw_time", HxDataBase::warm_param_config.nPcwTime},
|
||||
{"fcw_time", HxDataBase::warm_param_config.nFcwTime},
|
||||
{"hmw_vel", HxDataBase::warm_param_config.fHmwVel},
|
||||
{"fcw_vel", HxDataBase::warm_param_config.fFcwVel},
|
||||
{"ldw_vel", HxDataBase::warm_param_config.fLdwVel},
|
||||
{"pcw_vel", HxDataBase::warm_param_config.fPcwVel},
|
||||
{"bsd_first_vel", HxDataBase::warm_param_config.fBsdFirstVel},
|
||||
{"bsd_second_vel", HxDataBase::warm_param_config.fBsdSecondVel},
|
||||
{"bsd_third_vel", HxDataBase::warm_param_config.fBsdThirdVel},
|
||||
{"ldw_distance", HxDataBase::warm_param_config.nLdwDistance},
|
||||
{"dsm_vel", HxDataBase::warm_param_config.fDsmVel} });
|
||||
}
|
||||
|
||||
void HxTaskDispatch::set_warn_param_config(int type, QJsonObject object)
|
||||
{
|
||||
QJsonArray start_event_warn_kind = object.value("start_event_warn_kind").toArray();
|
||||
QJsonArray abnormal_warn_frame_count = object.value("abnormal_warn_frame_count").toArray();
|
||||
QJsonArray normal_frame_count = object.value("normal_frame_count").toArray();
|
||||
QJsonArray abnormal_warn_interval_frame_count = object.value("abnormal_warn_interval_frame_count").toArray();
|
||||
QJsonArray abnormal_warn_score_threshold = object.value("abnormal_warn_score_threshold").toArray();
|
||||
QJsonArray normal_warn_score_threshold = object.value("normal_warn_score_threshold").toArray();
|
||||
|
||||
for (int i = 0; i < EVENT_WARN_NUM; i++)
|
||||
{
|
||||
HxDataBase::warm_param_config.bStartEventWarnKind[i] = start_event_warn_kind.at(i).toBool();
|
||||
HxDataBase::warm_param_config.nAbnormalWarnFrameCount[i] = abnormal_warn_frame_count.at(i).toInt() * 25;
|
||||
HxDataBase::warm_param_config.nNormalFrameCount[i] = normal_frame_count.at(i).toInt() * 25;
|
||||
HxDataBase::warm_param_config.nAbnormalWarnIntervalFrameCount[i] = abnormal_warn_interval_frame_count.at(i).toInt() * 25;
|
||||
HxDataBase::warm_param_config.fAbnormalWarnScoreThreshold[i] = abnormal_warn_score_threshold.at(i).toDouble() / ((i >= 17 && i <= 20) ? 1 : 100);
|
||||
HxDataBase::warm_param_config.fNormalWarnScoreThreshold[i] = normal_warn_score_threshold.at(i).toDouble() / ((i >= 17 && i <= 20) ? 1 : 100);
|
||||
}
|
||||
|
||||
HxDataBase::warm_param_config.nHmwTime = object.value("hmw_time").toInt();
|
||||
HxDataBase::warm_param_config.nPcwTime = object.value("pcw_time").toInt();
|
||||
HxDataBase::warm_param_config.nFcwTime = object.value("fcw_time").toInt();
|
||||
HxDataBase::warm_param_config.fHmwVel = object.value("hmw_vel").toDouble();
|
||||
HxDataBase::warm_param_config.fFcwVel = object.value("fcw_vel").toDouble();
|
||||
HxDataBase::warm_param_config.fLdwVel = object.value("ldw_vel").toDouble();
|
||||
HxDataBase::warm_param_config.fPcwVel = object.value("pcw_vel").toDouble();
|
||||
HxDataBase::warm_param_config.fBsdFirstVel = object.value("bsd_first_vel").toDouble();
|
||||
HxDataBase::warm_param_config.fBsdSecondVel = object.value("bsd_second_vel").toDouble();
|
||||
HxDataBase::warm_param_config.fBsdThirdVel = object.value("bsd_third_vel").toDouble();
|
||||
HxDataBase::warm_param_config.nLdwDistance = object.value("ldw_distance").toInt();
|
||||
HxDataBase::warm_param_config.fDsmVel = object.value("dsm_vel").toDouble();
|
||||
|
||||
#if USE_ALGORITHM
|
||||
if(MvSetEventWarnParamConfig(&HxDataBase::warm_param_config) != 0)
|
||||
{
|
||||
debug_tool_response_event(type, { {"status", false} });
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
debug_tool_response_event(type, { {"status", HxDataBase::save_setting()} });
|
||||
}
|
||||
|
||||
void HxTaskDispatch::get_adas_camera_calibration(int type)
|
||||
{
|
||||
#if USE_ALGORITHM
|
||||
if(MvGetCameraCalibrationInfo(&HxDataBase::adas_camera_calibration) != 0)
|
||||
return;
|
||||
#endif
|
||||
|
||||
debug_tool_response_event(type, { {"car_len", HxDataBase::adas_camera_calibration.fCarLen},
|
||||
{"car_width", HxDataBase::adas_camera_calibration.fCarWidth},
|
||||
{"ref_center", HxDataBase::adas_camera_calibration.fRefCenter},
|
||||
{"ref_top", HxDataBase::adas_camera_calibration.fRefTop},
|
||||
{"dis_len_tyre", HxDataBase::adas_camera_calibration.fDisLen2Tyre},
|
||||
{"camera_height", HxDataBase::adas_camera_calibration.fCameraHeight},
|
||||
{"camera_focus", HxDataBase::adas_camera_calibration.fCameraFocus},
|
||||
{"camera_dx", HxDataBase::adas_camera_calibration.fCameraDx},
|
||||
{"pitch", HxDataBase::adas_camera_calibration.fPitch},
|
||||
{"yaw", HxDataBase::adas_camera_calibration.fYaw} });
|
||||
}
|
||||
void HxTaskDispatch::set_adas_camera_calibration(int type, QJsonObject object)
|
||||
{
|
||||
HxDataBase::adas_camera_calibration.fCarLen = object.value("car_len").toInt();
|
||||
HxDataBase::adas_camera_calibration.fCarWidth = object.value("car_width").toInt();
|
||||
HxDataBase::adas_camera_calibration.fRefCenter = object.value("ref_center").toInt();
|
||||
HxDataBase::adas_camera_calibration.fRefTop = object.value("ref_top").toDouble();
|
||||
HxDataBase::adas_camera_calibration.fDisLen2Tyre = object.value("dis_len_tyre").toDouble();
|
||||
HxDataBase::adas_camera_calibration.fCameraHeight = object.value("camera_height").toDouble();
|
||||
HxDataBase::adas_camera_calibration.fCameraFocus = object.value("camera_focus").toDouble();
|
||||
HxDataBase::adas_camera_calibration.fCameraDx = object.value("camera_dx").toDouble();
|
||||
HxDataBase::adas_camera_calibration.fPitch = object.value("pitch").toDouble();
|
||||
HxDataBase::adas_camera_calibration.fYaw = object.value("yaw").toDouble();
|
||||
|
||||
#if USE_ALGORITHM
|
||||
if(MvCameraCalibration(&HxDataBase::adas_camera_calibration) != 0)
|
||||
{
|
||||
debug_tool_response_event(type, { {"status", false} });
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
debug_tool_response_event(type, { {"status", HxDataBase::save_setting()} });
|
||||
}
|
||||
|
||||
void HxTaskDispatch::data_receive_event(QByteArray data)
|
||||
{
|
||||
int type = -1;
|
||||
|
||||
|
@ -376,91 +630,138 @@ void TaskDispatch::data_receive_event(QByteArray data)
|
|||
updata_vehiclue_status(msginfo);
|
||||
break;
|
||||
|
||||
/* 校时 */
|
||||
case 5:
|
||||
HxProcess::start(QString("date -s %1").arg(msginfo.value("date").toString()));
|
||||
HxProcess::start(QString("date -s %1").arg(msginfo.value("time").toString()));
|
||||
debug_tool_response_event(type, { {"status", true} });
|
||||
|
||||
HxLog::append("timing", QString(QJsonDocument(msginfo).toJson(QJsonDocument::Compact)));
|
||||
break;
|
||||
|
||||
/* 重启 */
|
||||
case 200:
|
||||
debug_tool_response_event(type, { {"status", true} });
|
||||
HxProcess::start("systemctl restart app.service");
|
||||
break;
|
||||
|
||||
/* 获取算法类型 */
|
||||
case 0xF0:
|
||||
debug_tool_response_event(type, {{"mode", DataBase::algorithm_type}});
|
||||
case 240:
|
||||
debug_tool_response_event(type, { {"mode", HxDataBase::algorithm_type} });
|
||||
break;
|
||||
|
||||
/* 设置算法类型 */
|
||||
case 0xF1:
|
||||
DataBase::algorithm_type = msginfo.value("mode").toInt();
|
||||
debug_tool_response_event(type, {{"status", DataBase::save_setting()}});
|
||||
case 241:
|
||||
HxDataBase::algorithm_type = msginfo.value("mode").toInt();
|
||||
debug_tool_response_event(type, { {"status", HxDataBase::save_setting()} });
|
||||
break;
|
||||
|
||||
/* 获取ADAS视频输入源 */
|
||||
case 0xF2:
|
||||
debug_tool_response_event(type, {{"source", DataBase::adas_video_input_source}});
|
||||
case 242:
|
||||
debug_tool_response_event(type, { {"source", HxDataBase::adas_video_input_source} });
|
||||
break;
|
||||
|
||||
/* 设置ADAS视频输入源 */
|
||||
case 0xF3:
|
||||
DataBase::adas_video_input_source = msginfo.value("source").toString();
|
||||
debug_tool_response_event(type, {{"status", DataBase::save_setting()}});
|
||||
case 243:
|
||||
HxDataBase::adas_video_input_source = msginfo.value("source").toString();
|
||||
debug_tool_response_event(type, { {"status", HxDataBase::save_setting()} });
|
||||
break;
|
||||
|
||||
/* 抓拍 */
|
||||
case 0xF4:
|
||||
case 244:
|
||||
debug_tool_response_event(type, { {"data", adas_video_device.snap()} });
|
||||
break;
|
||||
|
||||
/* 获取BSD视频输入源 */
|
||||
case 0xF5:
|
||||
debug_tool_response_event(type, {{"source", DataBase::bsd_video_input_source[msginfo.value("channel").toInt()]}});
|
||||
case 245:
|
||||
debug_tool_response_event(type, { {"source", HxDataBase::bsd_video_input_source[msginfo.value("channel").toInt()]} });
|
||||
break;
|
||||
|
||||
/* 设置BSD视频输入源 */
|
||||
case 0xF6:
|
||||
DataBase::bsd_video_input_source[msginfo.value("channel").toInt()] = msginfo.value("source").toString();
|
||||
debug_tool_response_event(type, {{"status", DataBase::save_setting()}});
|
||||
case 246:
|
||||
HxDataBase::bsd_video_input_source[msginfo.value("channel").toInt()] = msginfo.value("source").toString();
|
||||
debug_tool_response_event(type, { {"status", HxDataBase::save_setting()} });
|
||||
break;
|
||||
|
||||
/* 抓拍 */
|
||||
case 0xF7:
|
||||
case 247:
|
||||
debug_tool_response_event(type, { {"data", bsd_video_device[msginfo.value("channel").toInt()].snap()} });
|
||||
break;
|
||||
|
||||
/* 获取Dsm视频输入源 */
|
||||
case 0xF8:
|
||||
debug_tool_response_event(type, {{"source", DataBase::dsm_video_input_source}});
|
||||
case 248:
|
||||
debug_tool_response_event(type, { {"source", HxDataBase::dsm_video_input_source} });
|
||||
break;
|
||||
|
||||
/* 设置Dsm视频输入源 */
|
||||
case 0xF9:
|
||||
DataBase::dsm_video_input_source = msginfo.value("source").toString();
|
||||
debug_tool_response_event(type, {{"status", DataBase::save_setting()}});
|
||||
case 249:
|
||||
HxDataBase::dsm_video_input_source = msginfo.value("source").toString();
|
||||
debug_tool_response_event(type, { {"status", HxDataBase::save_setting()} });
|
||||
break;
|
||||
|
||||
/* 抓拍 */
|
||||
case 0xFA:
|
||||
case 250:
|
||||
debug_tool_response_event(type, { {"data", dsm_video_device.snap()} });
|
||||
break;
|
||||
|
||||
/* 获取BSD报警区域 */
|
||||
case 0xFB:
|
||||
debug_tool_response_event(type, {{"data", DataBase::bsd_warn_regions[msginfo.value("channel").toInt()]}});
|
||||
case 251:
|
||||
debug_tool_response_event(type, { {"data", HxDataBase::bsd_warn_regions[msginfo.value("channel").toInt()]} });
|
||||
break;
|
||||
|
||||
/* 设置BSD报警区域 */
|
||||
case 0xFC:
|
||||
DataBase::bsd_warn_regions[msginfo.value("channel").toInt()] = msginfo.value("data").toString();
|
||||
debug_tool_response_event(type, {{"status", DataBase::save_setting()}});
|
||||
case 252:
|
||||
HxDataBase::bsd_warn_regions[msginfo.value("channel").toInt()] = msginfo.value("data").toString();
|
||||
debug_tool_response_event(type, { {"status", HxDataBase::save_setting()} });
|
||||
break;
|
||||
|
||||
/* 获取设备编号及FTP信息 */
|
||||
case 0xFD:
|
||||
debug_tool_response_event(type, {{"device_id", DataBase::device_id},
|
||||
{"ftp_address", DataBase::ftp_address},
|
||||
{"ftp_username", DataBase::ftp_username},
|
||||
{"ftp_password", DataBase::ftp_password}});
|
||||
case 253:
|
||||
debug_tool_response_event(type, { {"device_id", HxDataBase::device_id},
|
||||
{"ftp_address", HxDataBase::ftp_address},
|
||||
{"ftp_username", HxDataBase::ftp_username},
|
||||
{"ftp_password", HxDataBase::ftp_password}, });
|
||||
break;
|
||||
|
||||
/* 设置设备编号及FTP信息 */
|
||||
case 0xFE:
|
||||
DataBase::device_id = msginfo.value("device_id").toString();
|
||||
DataBase::ftp_address = msginfo.value("ftp_address").toString();
|
||||
DataBase::ftp_username = msginfo.value("ftp_username").toString();
|
||||
DataBase::ftp_password = msginfo.value("ftp_password").toString();
|
||||
debug_tool_response_event(type, {{"status", DataBase::save_setting()}});
|
||||
case 254:
|
||||
HxDataBase::device_id = msginfo.value("device_id").toString();
|
||||
HxDataBase::ftp_address = msginfo.value("ftp_address").toString();
|
||||
HxDataBase::ftp_username = msginfo.value("ftp_username").toString();
|
||||
HxDataBase::ftp_password = msginfo.value("ftp_password").toString();
|
||||
debug_tool_response_event(type, { {"status", HxDataBase::save_setting()} });
|
||||
break;
|
||||
|
||||
|
||||
case 255:
|
||||
get_warn_param_config(type);
|
||||
break;
|
||||
|
||||
case 256:
|
||||
set_warn_param_config(type, msginfo);
|
||||
break;
|
||||
|
||||
case 257:
|
||||
get_adas_camera_calibration(type);
|
||||
break;
|
||||
|
||||
case 258:
|
||||
set_adas_camera_calibration(type, msginfo);
|
||||
break;
|
||||
|
||||
/* 获取 RabbitMQ 信息 */
|
||||
case 259:
|
||||
debug_tool_response_event(type, { {"qamqp_address", HxDataBase::qamqp_address},
|
||||
{"qamqp_username", HxDataBase::qamqp_username},
|
||||
{"qamqp_password", HxDataBase::qamqp_password} });
|
||||
break;
|
||||
|
||||
/* 设置 RabbitMQ 信息 */
|
||||
case 260:
|
||||
HxDataBase::qamqp_address = msginfo.value("qamqp_address").toString();
|
||||
HxDataBase::qamqp_username = msginfo.value("qamqp_username").toString();
|
||||
HxDataBase::qamqp_password = msginfo.value("qamqp_password").toString();
|
||||
debug_tool_response_event(type, { {"status", HxDataBase::save_setting()} });
|
||||
break;
|
||||
|
||||
case 0xFFFF:
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#define ALGORITHM_TYPE_BSD 1
|
||||
#define ALGORITHM_TYPE_DSM 2
|
||||
|
||||
class TaskDispatch : public QThread
|
||||
class HxTaskDispatch : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -32,20 +32,26 @@ public:
|
|||
*/
|
||||
static void connect_to_host(QString address, int port);
|
||||
|
||||
static void algorithm_alarm_event(int channel, int level, int event_type, int detect_type, int left, int top, int right, int bottom, int distance, int speed, QString base64_string, QString filepath);
|
||||
|
||||
static DataBase database(void);
|
||||
static void algorithm_alarm_event(QDateTime time, int channel, int level, int event_type, int detect_type, int left, int top, int right, int bottom, int distance, int speed, QString base64_string, QString filepath);
|
||||
|
||||
static CarInfoInput* get_car_info(void);
|
||||
|
||||
static QString get_video_frame_data(int type, int channel, int id);
|
||||
|
||||
/**
|
||||
* @brief 获取报警检测时间
|
||||
* @param type
|
||||
* @param channel
|
||||
* @return
|
||||
*/
|
||||
static bool get_alarm_detection_timestamp(int type, int channel);
|
||||
|
||||
/**
|
||||
* @brief 生成报警图片
|
||||
* @param type 报警类型
|
||||
* @param channel 视频通道
|
||||
* @param frame_id 视频帧编号
|
||||
* @return 返回 Base64 字符串
|
||||
* @return 返回 图片路径
|
||||
*/
|
||||
static QString build_alarm_image(int type, int channel, int frame_id);
|
||||
|
||||
|
@ -54,17 +60,30 @@ public:
|
|||
* @param type 报警类型
|
||||
* @param channel 视频通道
|
||||
* @param frame_id 视频帧编号
|
||||
* @return 返回 视频路径
|
||||
*/
|
||||
static QString build_alarm_video(int type, int channel, int frame_id);
|
||||
|
||||
/**
|
||||
* @brief enqueue_upload_file
|
||||
* @param filename
|
||||
*/
|
||||
static void enqueue_upload_file(QString filename);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
void update_heartbeat();
|
||||
void update_heartbeat(void);
|
||||
void updata_vehiclue_status(QJsonObject object);
|
||||
void parsing_vehiclue_status(void);
|
||||
void recording_upload_task(void);
|
||||
void upload_file_queue_check(void);
|
||||
void debug_tool_response_event(int type, std::initializer_list<QPair<QString, QJsonValue>> args);
|
||||
void get_warn_param_config(int type);
|
||||
void set_warn_param_config(int type, QJsonObject object);
|
||||
void get_adas_camera_calibration(int type);
|
||||
void set_adas_camera_calibration(int type, QJsonObject object);
|
||||
|
||||
signals:
|
||||
void data_write_event(QByteArray data);
|
||||
|
@ -90,9 +109,6 @@ private:
|
|||
|
||||
/* 车辆状态信息 */
|
||||
CarInfoInput car_info;
|
||||
|
||||
/* 倒车灯;1:亮;0:熄灭 */
|
||||
int reversing_light = 0;
|
||||
};
|
||||
|
||||
#endif // HXTASKDISPATCH_H
|
||||
|
|
147
app/HxUtils.h
147
app/HxUtils.h
|
@ -8,6 +8,15 @@
|
|||
#include <QDateTime>
|
||||
#include <QCoreApplication>
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
|
||||
#ifdef USE_RABBITMQ
|
||||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SocketUtils socket 工具类
|
||||
|
@ -80,15 +89,9 @@ public slots:
|
|||
|
||||
void disconnected()
|
||||
{
|
||||
qDebug("socket disconnect");
|
||||
|
||||
if (is_reconnect)
|
||||
{
|
||||
qDebug("socket will be reconnected... ");
|
||||
|
||||
emit reconnection_event();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 重连
|
||||
|
@ -97,29 +100,21 @@ public slots:
|
|||
{
|
||||
/* 取消已有的连接 */
|
||||
if (socket != nullptr)
|
||||
{
|
||||
socket->disconnectFromHost();
|
||||
qDebug("socket release");
|
||||
}
|
||||
|
||||
qDebug("socket connecting......");
|
||||
|
||||
/* 连接服务器 */
|
||||
socket->connectToHost(address, port);
|
||||
|
||||
/* 等待连接 */
|
||||
if (socket->waitForConnected(500))
|
||||
if (!socket->waitForConnected(500))
|
||||
{
|
||||
qDebug("socket connect success");
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("socket connect failed");
|
||||
|
||||
/* 使用 QThread::msleep 延时,会使 Socket 出现接收不到事件信息 (槽无法响应) */
|
||||
auto time = QTime::currentTime().addMSecs(10000);
|
||||
while (QTime::currentTime() < time)
|
||||
{
|
||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
||||
QThread::msleep(100);
|
||||
}
|
||||
|
||||
emit reconnection_event();
|
||||
}
|
||||
|
@ -133,14 +128,53 @@ private:
|
|||
QTcpSocket *socket = nullptr;
|
||||
};
|
||||
|
||||
class HxProcessUtils
|
||||
class HxDir
|
||||
{
|
||||
public:
|
||||
static bool mkdir(QString name)
|
||||
{
|
||||
QDir dir;
|
||||
return dir.mkpath(name);
|
||||
}
|
||||
};
|
||||
|
||||
class HxLog
|
||||
{
|
||||
public:
|
||||
static void append(QString title, QString message)
|
||||
{
|
||||
static QMutex mutex;
|
||||
|
||||
mutex.lock();
|
||||
|
||||
auto current_time = QDateTime::currentDateTime();
|
||||
|
||||
HxDir::mkdir(QString("log/%1").arg(current_time.toString("yyyyMMdd")));
|
||||
|
||||
QFile file(QString("log/%1/%1.txt").arg(current_time.toString("yyyyMMdd")));
|
||||
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Append))
|
||||
{
|
||||
auto data = QString("[%1] | [%2] | %3\r\n").arg(current_time.toString("yyyy-MM-dd HH:mm:ss"), title, message);
|
||||
|
||||
file.write(data.toLocal8Bit());
|
||||
|
||||
file.close();
|
||||
|
||||
qDebug() << data;
|
||||
}
|
||||
|
||||
mutex.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
class HxProcess
|
||||
{
|
||||
public:
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static int execute(QString command)
|
||||
{
|
||||
qDebug() << command;
|
||||
|
||||
auto array = command.split(" ");
|
||||
|
||||
QString program = array.at(0);
|
||||
|
@ -150,6 +184,75 @@ public:
|
|||
|
||||
return QProcess::execute(program, arguments);
|
||||
}
|
||||
|
||||
static QString start(QString command)
|
||||
{
|
||||
auto array = command.split(" ");
|
||||
|
||||
QString program = array.at(0);
|
||||
QStringList arguments;
|
||||
for (int i = 1; i < array.count(); i++)
|
||||
arguments << array.at(i);
|
||||
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
process.start(program, arguments);
|
||||
process.waitForFinished();
|
||||
return QString(process.readAll());
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef USE_RABBITMQ
|
||||
class HxRabbitMQUtils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
void set(QString host, QString username, QString password)
|
||||
{
|
||||
auto hosts = host.split(":");
|
||||
|
||||
client.setHost(hosts.at(0));
|
||||
client.setPort(hosts.size() == 2 ? hosts.at(1).toInt() : 5672);
|
||||
client.setUsername(username);
|
||||
client.setPassword(password);
|
||||
client.setVirtualHost("/");
|
||||
client.setAutoReconnect(true, 10);
|
||||
|
||||
connect(&client, SIGNAL(connected()), this, SLOT(connected()));
|
||||
connect(&client, SIGNAL(disconnected()), this, SLOT(disconnected()));
|
||||
|
||||
connect(this, &HxRabbitMQUtils::publish, this, &HxRabbitMQUtils::send_message);
|
||||
|
||||
client.connectToHost();
|
||||
}
|
||||
|
||||
void set_exchanger_name(QString exchanger_name) { this->exchanger_name = exchanger_name; }
|
||||
|
||||
void set_queue_name(QString queue_name) { this->queue_name = queue_name; }
|
||||
|
||||
void set_routing_key(QString routing_key) { this->routing_key = routing_key; }
|
||||
|
||||
private:
|
||||
void send_message(QString message)
|
||||
{
|
||||
QAmqpExchange *exchange = client.createExchange(exchanger_name);
|
||||
|
||||
exchange->publish(message, routing_key);
|
||||
|
||||
HxLog::append("RabbitMQ", QString("Key:%1 message:%2").arg(routing_key, message));
|
||||
}
|
||||
|
||||
signals:
|
||||
void publish(QString message);
|
||||
|
||||
public slots:
|
||||
void connected() { HxLog::append("RabbitMQ", "connect success"); }
|
||||
|
||||
void disconnected() { HxLog::append("RabbitMQ", "disconnect"); }
|
||||
|
||||
private:
|
||||
QAmqpClient client;
|
||||
QString exchanger_name, queue_name, routing_key;
|
||||
};
|
||||
#endif
|
||||
#endif // HXUTILS_H
|
||||
|
|
|
@ -6,34 +6,43 @@ void algorithm_alarm_callback(int nDataChannel, ObjectTrackEventResult* pObjectT
|
|||
Q_UNUSED(nDataChannel);
|
||||
Q_UNUSED(pPrivData);
|
||||
|
||||
QDateTime current_time = QDateTime::currentDateTime();
|
||||
|
||||
if (pObjectTrackEventResult->nEventType == 0)
|
||||
return;
|
||||
|
||||
if (nDataChannel == 0) /* ADAS */
|
||||
{
|
||||
printf("ProcessAdasAlgResult nDataChannel=%d,nFrameId=%d,nObjectNumber=%d,nEventType=%x\n", nDataChannel, pObjectTrackEventResult->nFrameId, pObjectTrackEventResult->nObjectNumber, pObjectTrackEventResult->nEventType);
|
||||
if (!HxTaskDispatch::get_alarm_detection_timestamp(ALGORITHM_TYPE_ADAS, 0))
|
||||
return;
|
||||
|
||||
qDebug() << current_time.toString("[yyyy-MM-dd HH:mm:ss] ") << " Adas FrameId=" << pObjectTrackEventResult->nFrameId << " nEventType=" << pObjectTrackEventResult->nEventType;
|
||||
|
||||
|
||||
/* 生成报警图片 */
|
||||
auto base64_string = TaskDispatch::build_alarm_image(ALGORITHM_TYPE_ADAS, 0, pObjectTrackEventResult->nFrameId);
|
||||
auto image_path = HxTaskDispatch::build_alarm_image(ALGORITHM_TYPE_ADAS, 0, pObjectTrackEventResult->nFrameId);
|
||||
|
||||
/* 生成报警视频 */
|
||||
auto filename = TaskDispatch::build_alarm_video(ALGORITHM_TYPE_ADAS, 0, pObjectTrackEventResult->nFrameId);
|
||||
auto record_path = HxTaskDispatch::build_alarm_video(ALGORITHM_TYPE_ADAS, 0, pObjectTrackEventResult->nFrameId);
|
||||
|
||||
/* 上传 */
|
||||
TaskDispatch::algorithm_alarm_event(0, 0, pObjectTrackEventResult->nEventType, 0, 0, 0, 0, 0, 0, 0, base64_string, filename);
|
||||
HxTaskDispatch::algorithm_alarm_event(current_time, 0, 0, pObjectTrackEventResult->nEventType, 0, 0, 0, 0, 0, 0, 0, image_path, record_path);
|
||||
}
|
||||
else if (nDataChannel == 2) /* DSM */
|
||||
{
|
||||
printf("ProcessDsmAlgResult nDataChannel=%d,nFrameId=%d,nObjectNumber=%d,nEventType=%x\n", nDataChannel, pObjectTrackEventResult->nFrameId, pObjectTrackEventResult->nObjectNumber, pObjectTrackEventResult->nEventType);
|
||||
if (!HxTaskDispatch::get_alarm_detection_timestamp(ALGORITHM_TYPE_DSM, 0))
|
||||
return;
|
||||
|
||||
qDebug() << current_time.toString("[yyyy-MM-dd HH:mm:ss] ") << " Dsm FrameId=" << pObjectTrackEventResult->nFrameId << " nEventType=" << pObjectTrackEventResult->nEventType;
|
||||
|
||||
/* 生成报警图片 */
|
||||
auto base64_string = TaskDispatch::build_alarm_image(ALGORITHM_TYPE_DSM, 0, pObjectTrackEventResult->nFrameId);
|
||||
auto image_path = HxTaskDispatch::build_alarm_image(ALGORITHM_TYPE_DSM, 0, pObjectTrackEventResult->nFrameId);
|
||||
|
||||
/* 生成报警视频 */
|
||||
auto filename = TaskDispatch::build_alarm_video(ALGORITHM_TYPE_DSM, 0, pObjectTrackEventResult->nFrameId);
|
||||
auto record_path = HxTaskDispatch::build_alarm_video(ALGORITHM_TYPE_DSM, 0, pObjectTrackEventResult->nFrameId);
|
||||
|
||||
/* 上传 */
|
||||
TaskDispatch::algorithm_alarm_event(1, 0, pObjectTrackEventResult->nEventType, 0, 0, 0, 0, 0, 0, 0, base64_string, filename);
|
||||
HxTaskDispatch::algorithm_alarm_event(current_time, 1, 0, pObjectTrackEventResult->nEventType, 0, 0, 0, 0, 0, 0, 0, image_path, record_path);
|
||||
}
|
||||
else if (nDataChannel == 1 || /* BSD-右前 */
|
||||
nDataChannel == 3 || /* BSD-右后 */
|
||||
|
@ -66,6 +75,9 @@ void algorithm_alarm_callback(int nDataChannel, ObjectTrackEventResult* pObjectT
|
|||
break;
|
||||
}
|
||||
|
||||
if (!HxTaskDispatch::get_alarm_detection_timestamp(ALGORITHM_TYPE_BSD, channel))
|
||||
return;
|
||||
|
||||
qDebug("ProcessBsdAlgResult nDataChannel=%d,nFrameId=%d,nObjectNumber=%d,nEventType=%x,nDangerLevel=%d\n", nDataChannel, pObjectTrackEventResult->nFrameId, pObjectTrackEventResult->nObjectNumber, pObjectTrackEventResult->nEventType, pObjectTrackEventResult->nDangerLevel);
|
||||
|
||||
for (int i = 0; i < pObjectTrackEventResult->nObjectNumber; i++)
|
||||
|
@ -78,13 +90,13 @@ void algorithm_alarm_callback(int nDataChannel, ObjectTrackEventResult* pObjectT
|
|||
continue;
|
||||
|
||||
/* 生成报警图片 */
|
||||
auto base64_string = TaskDispatch::build_alarm_image(ALGORITHM_TYPE_BSD, channel, pObjectTrackEventResult->nFrameId);
|
||||
auto image_path = HxTaskDispatch::build_alarm_image(ALGORITHM_TYPE_BSD, channel, pObjectTrackEventResult->nFrameId);
|
||||
|
||||
/* 生成报警视频 */
|
||||
auto filename = TaskDispatch::build_alarm_video(ALGORITHM_TYPE_BSD, channel, pObjectTrackEventResult->nFrameId);
|
||||
auto record_path = HxTaskDispatch::build_alarm_video(ALGORITHM_TYPE_BSD, channel, pObjectTrackEventResult->nFrameId);
|
||||
|
||||
/* 上传 */
|
||||
TaskDispatch::algorithm_alarm_event(channel,
|
||||
HxTaskDispatch::algorithm_alarm_event(current_time, channel,
|
||||
pObjectTrackEventResult->nDangerLevel,
|
||||
pObjectTrackEventResult->nEventType,
|
||||
pObjectTrackEventResult->objInfo[i].nDetectType,
|
||||
|
@ -94,13 +106,30 @@ void algorithm_alarm_callback(int nDataChannel, ObjectTrackEventResult* pObjectT
|
|||
pObjectTrackEventResult->objInfo[i].nBottom,
|
||||
pObjectTrackEventResult->objInfo[i].fDist,
|
||||
pObjectTrackEventResult->objInfo[i].fVelo,
|
||||
base64_string,
|
||||
filename);
|
||||
image_path,
|
||||
record_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VideoDevice::VideoDevice(void)
|
||||
// adas算法车道线结果处理函数
|
||||
void algorithm_lane_line_callback(DrawPointInfo *pPointInfo, void *pPrivData)
|
||||
{
|
||||
Q_UNUSED(pPrivData);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
printf("ProcessAdasAlgLaneLineResult pPointInfo->nPointCounters[i]=%d\n", pPointInfo->nPointCounters[i]);
|
||||
for (unsigned int j = 0; j < pPointInfo->nPointCounters[i]; j++)
|
||||
{
|
||||
printf("pSrcPointX=%d,pSrcPointY=%d\n", pPointInfo->pSrcPointX[i][j], pPointInfo->pSrcPointY[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
HxVideoDevice::HxVideoDevice(void)
|
||||
{
|
||||
detect_frame_buffer.u32Width = 1280;
|
||||
detect_frame_buffer.u32Height = 720;
|
||||
|
@ -111,7 +140,7 @@ VideoDevice::VideoDevice(void)
|
|||
MvGetFrameBlkInfo(&bgr_frame_buffer);
|
||||
}
|
||||
|
||||
void VideoDevice::set(int type, QString address)
|
||||
void HxVideoDevice::set(int type, QString address)
|
||||
{
|
||||
this->type = type;
|
||||
this->address = address;
|
||||
|
@ -119,12 +148,19 @@ void VideoDevice::set(int type, QString address)
|
|||
auto result = MvSetAlgResultFuncCallback(type, algorithm_alarm_callback, nullptr);
|
||||
if (result != 0)
|
||||
return;
|
||||
|
||||
if (type == 1)
|
||||
{
|
||||
result = MvSetAlgLaneLineFuncCallback(algorithm_lane_line_callback, nullptr);
|
||||
if (result != 0)
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
void VideoDevice::set(int type, QString address, BsdWarnRegion region)
|
||||
void HxVideoDevice::set(int type, QString address, BsdWarnRegion region)
|
||||
{
|
||||
Q_UNUSED(region);
|
||||
|
||||
|
@ -143,97 +179,59 @@ void VideoDevice::set(int type, QString address, BsdWarnRegion region)
|
|||
start();
|
||||
}
|
||||
|
||||
void VideoDevice::set(bool status) { detection_status = status; }
|
||||
void HxVideoDevice::set(bool status) { detection_status = status; }
|
||||
|
||||
QString VideoDevice::snap() { return snap(video_frame); }
|
||||
bool HxVideoDevice::get_alarm_detection_timestamp(void) { return alarm_detection_timestamp.secsTo(QDateTime::currentDateTime()) > 10; }
|
||||
|
||||
QString VideoDevice::build_image(int id)
|
||||
QString HxVideoDevice::snap() { return snap(video_frame); }
|
||||
|
||||
QString HxVideoDevice::build_image(int id)
|
||||
{
|
||||
if (video_frames_string.contains(id))
|
||||
return snap(video_frames_string[id]);
|
||||
auto start_id = id - video_fps * 5, end_id = id + video_fps * 5;
|
||||
|
||||
return "";
|
||||
alarm_detection_timestamp = QDateTime::currentDateTime();
|
||||
|
||||
QString filename = QString("%1_%2_%3.jpg").arg(start_id > 0 ? start_id : 0).arg(end_id).arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmsszzz"));
|
||||
|
||||
Mat frame;
|
||||
record_frames_mutex.lock();
|
||||
if (record_frames.contains(id))
|
||||
frame = imdecode(record_frames[id], CV_LOAD_IMAGE_COLOR);
|
||||
record_frames_mutex.unlock();
|
||||
|
||||
// return snap(record_frames[id]);
|
||||
|
||||
imwrite(filename.toUtf8().data(), frame);
|
||||
|
||||
HxTaskDispatch::enqueue_upload_file(filename);
|
||||
|
||||
return QString("/%1/%2/alarm/%3").arg(QDateTime::currentDateTime().toString("yyyyMMdd"), HxDataBase::device_id, filename);
|
||||
}
|
||||
|
||||
QString VideoDevice::build_video(int id)
|
||||
QString HxVideoDevice::build_video(int id)
|
||||
{
|
||||
QString url = QString("ftp://%3/%4/%5/alarm/").arg(DataBase::ftp_address, QDateTime::currentDateTime().toString("yyyyMMdd"), DataBase::device_id);
|
||||
QString filename = QString("%1.mp4").arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmsszzz"));
|
||||
auto start_id = id - video_fps * 5, end_id = id + video_fps * 5;
|
||||
|
||||
QtConcurrent::run([=]() {
|
||||
if (video_frames_string.contains(id))
|
||||
{
|
||||
frame_mutex.lock();
|
||||
auto first_key = video_frames_string.firstKey();
|
||||
frame_mutex.unlock();
|
||||
QString filename = QString("%1_%2_%3.mp4").arg(start_id > 0 ? start_id : 0).arg(end_id).arg(QDateTime::currentDateTime().toString("yyyyMMddHHmmsszzz"));
|
||||
|
||||
auto start_id = id - frame_fps * 10, end_id = id + frame_fps * 10;
|
||||
record_queue_mutex.lock();
|
||||
record_queue.enqueue(filename);
|
||||
record_queue_mutex.unlock();
|
||||
|
||||
start_id = start_id < first_key ? first_key : start_id;
|
||||
|
||||
qDebug() << "build video; start id = " << start_id << " end id = " << end_id;
|
||||
|
||||
while (true)
|
||||
{
|
||||
frame_mutex.lock();
|
||||
auto last_key = video_frames_string.lastKey();
|
||||
frame_mutex.unlock();
|
||||
|
||||
// qDebug() << " end id = " << end_id << " last id = "<< last_key;
|
||||
|
||||
/* 判断最新的视频帧是否超过设定的时间 */
|
||||
if (last_key >= end_id)
|
||||
{
|
||||
frame_mutex.lock();
|
||||
auto _video_frames_string = video_frames_string;
|
||||
_video_frames_string.detach();
|
||||
frame_mutex.unlock();
|
||||
|
||||
VideoWriter writer(filename.toUtf8().data(), CV_FOURCC('m', 'p', '4', 'v'), frame_fps, Size(video_capture.get(CV_CAP_PROP_FRAME_WIDTH), video_capture.get(CV_CAP_PROP_FRAME_HEIGHT)), true);
|
||||
|
||||
for (int i = start_id; i <= end_id; i++)
|
||||
{
|
||||
auto __frame = imdecode(_video_frames_string[i], CV_LOAD_IMAGE_COLOR);
|
||||
|
||||
writer.write(__frame);
|
||||
|
||||
msleep(frame_fps);
|
||||
|
||||
qDebug() << " write " << filename << ". frame id = " << i;
|
||||
return QString("/%1/%2/alarm/%3").arg(QDateTime::currentDateTime().toString("yyyyMMdd"), HxDataBase::device_id, filename);
|
||||
}
|
||||
|
||||
writer.release();
|
||||
|
||||
qDebug() << "video build finish";
|
||||
|
||||
HxProcessUtils::execute(QString("curl -u %1:%2 %3 --ftp-create-dirs -T %4")
|
||||
.arg(DataBase::ftp_username,
|
||||
DataBase::ftp_password,
|
||||
url,
|
||||
filename));
|
||||
|
||||
QFile::remove(filename);
|
||||
|
||||
return;
|
||||
}
|
||||
msleep(100);
|
||||
}
|
||||
} });
|
||||
|
||||
return url + filename;
|
||||
}
|
||||
|
||||
void VideoDevice::test(void)
|
||||
void HxVideoDevice::test(void)
|
||||
{
|
||||
ObjectTrackEventResult pObjectTrackEventResult = { 0 };
|
||||
pObjectTrackEventResult.nFrameId = video_frames_string.lastKey();
|
||||
ObjectTrackEventResult pObjectTrackEventResult;
|
||||
pObjectTrackEventResult.nFrameId = record_frames.lastKey();
|
||||
pObjectTrackEventResult.nEventType = EVENT_PCW;
|
||||
pObjectTrackEventResult.nObjectNumber = 1;
|
||||
pObjectTrackEventResult.objInfo[0].nDetectType = PEDESTRIAN_TYPE;
|
||||
algorithm_alarm_callback(0, &pObjectTrackEventResult, nullptr);
|
||||
}
|
||||
|
||||
vector<uint8_t> VideoDevice::compress(Mat frame, int quality)
|
||||
vector<uint8_t> HxVideoDevice::compress(Mat frame, int quality)
|
||||
{
|
||||
vector<uint8_t> buffer;
|
||||
|
||||
|
@ -246,98 +244,193 @@ vector<uint8_t> VideoDevice::compress(Mat frame, int quality)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
QString VideoDevice::snap(Mat frame)
|
||||
{
|
||||
if (frame.data != nullptr)
|
||||
return snap(compress(frame, 50));
|
||||
QString HxVideoDevice::snap(Mat frame) { return frame.data == nullptr ? "" : snap(compress(frame, 50)); }
|
||||
|
||||
return "";
|
||||
QString HxVideoDevice::snap(vector<uint8_t> buffer) { return QString(QByteArray::fromRawData((const char *)buffer.data(), buffer.size()).toBase64()); }
|
||||
|
||||
void HxVideoDevice::recording_creation_task(void)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (record_queue.size() > 0)
|
||||
{
|
||||
record_queue_mutex.lock();
|
||||
auto filename = record_queue.dequeue();
|
||||
record_queue_mutex.unlock();
|
||||
|
||||
HxLog::append("recording", QString("type=%1, count=%2, %3 creation task start").arg(type).arg(record_queue.size()).arg(filename));
|
||||
|
||||
auto data = filename.split("_");
|
||||
auto start_id = data[0].toInt(), end_id = data[1].toInt();
|
||||
|
||||
while (true)
|
||||
{
|
||||
record_frames_mutex.lock();
|
||||
auto first_key = record_frames.firstKey();
|
||||
auto last_key = record_frames.lastKey();
|
||||
record_frames_mutex.unlock();
|
||||
|
||||
if (last_key < first_key)
|
||||
{
|
||||
HxLog::append("recording", QString("%1 not found last id, creation failed").arg(filename));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
QString VideoDevice::snap(vector<uint8_t> buffer)
|
||||
/* 判断最新的视频帧是否超过设定的时间 */
|
||||
if (last_key >= end_id)
|
||||
{
|
||||
QByteArray byteArray = QByteArray::fromRawData((const char*)buffer.data(), buffer.size());
|
||||
record_frames_mutex.lock();
|
||||
auto _record_frames = record_frames;
|
||||
_record_frames.detach();
|
||||
record_frames_mutex.unlock();
|
||||
|
||||
return QString(byteArray.toBase64());
|
||||
}
|
||||
VideoWriter writer(filename.toUtf8().data(), CV_FOURCC('m', 'p', '4', 'v'), video_fps, Size(video_capture.get(CV_CAP_PROP_FRAME_WIDTH), video_capture.get(CV_CAP_PROP_FRAME_HEIGHT)), true);
|
||||
|
||||
void VideoDevice::video_frame_queue_check()
|
||||
for (int i = start_id; i <= end_id; i++)
|
||||
{
|
||||
if (video_frames_string.count() > frame_fps * 30)
|
||||
if (_record_frames.contains(i))
|
||||
{
|
||||
frame_mutex.lock();
|
||||
video_frames_string.remove(video_frames_string.firstKey());
|
||||
frame_mutex.unlock();
|
||||
auto __frame = imdecode(_record_frames[i], CV_LOAD_IMAGE_COLOR);
|
||||
|
||||
writer.write(__frame);
|
||||
|
||||
msleep(10);
|
||||
|
||||
HxLog::append("recording", QString("%1 write frame id:%2").arg(filename).arg(i));
|
||||
}
|
||||
}
|
||||
|
||||
void VideoDevice::read_frame()
|
||||
writer.release();
|
||||
|
||||
HxTaskDispatch::enqueue_upload_file(filename);
|
||||
|
||||
HxLog::append("recording", QString("%1 creation success").arg(type).arg(filename));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
msleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
msleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
void HxVideoDevice::video_frame_queue_check(void)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
/* 缓存队列超过30s, 删除掉头数据 */
|
||||
record_frames_mutex.lock();
|
||||
while (record_frames.count() > video_fps * 180)
|
||||
{
|
||||
record_frames.remove(record_frames.firstKey());
|
||||
msleep(1);
|
||||
}
|
||||
record_frames_mutex.unlock();
|
||||
|
||||
msleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void HxVideoDevice::frame_read_task(void)
|
||||
{
|
||||
HxLog::append("videolivestream", QString("type=%1, address=%2, frame read task start").arg(type).arg(address));
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (address.isEmpty())
|
||||
return;
|
||||
|
||||
if (!video_capture.isOpened())
|
||||
{
|
||||
/* 打开 */
|
||||
video_capture = VideoCapture(address.toUtf8().data());
|
||||
|
||||
frame_fps = video_capture.get(CV_CAP_PROP_FPS);
|
||||
if(video_capture.isOpened())
|
||||
{
|
||||
/* 获取视频帧率 */
|
||||
video_fps = video_capture.get(CV_CAP_PROP_FPS);
|
||||
|
||||
qDebug() << address << " open";
|
||||
HxLog::append("videolivestream", QString("type=%1, video open success, fps=%2").arg(video_fps));
|
||||
}
|
||||
}
|
||||
|
||||
if (!video_capture.read(video_frame))
|
||||
{
|
||||
qDebug() << address << " close";
|
||||
|
||||
/* 关闭,释放 */
|
||||
video_capture.release();
|
||||
|
||||
return;
|
||||
HxLog::append("videolivestream", QString("type=%1, video close").arg(type));
|
||||
|
||||
msleep(1000);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// video_frames_mutex.lock();
|
||||
// video_frames.enqueue(video_frame);
|
||||
// video_frames_mutex.unlock();
|
||||
|
||||
msleep(15);
|
||||
}
|
||||
}
|
||||
|
||||
void HxVideoDevice::run()
|
||||
{
|
||||
/* 启动 录像创建任务 */
|
||||
QtConcurrent::run(this, &HxVideoDevice::recording_creation_task);
|
||||
|
||||
/* 创建 缓存队列监控线程 */
|
||||
QtConcurrent::run(this, &HxVideoDevice::video_frame_queue_check);
|
||||
|
||||
/* 创建 视频读取线程 */
|
||||
QtConcurrent::run(this, &HxVideoDevice::frame_read_task);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Mat frame;
|
||||
// video_frames_mutex.lock();
|
||||
// if (video_frames.size() > 0)
|
||||
// frame = video_frames.dequeue();
|
||||
// video_frames_mutex.unlock();
|
||||
|
||||
if (video_frame.data != nullptr)
|
||||
{
|
||||
frame_mutex.lock();
|
||||
video_frames_string.insert(frame_id, compress(video_frame, 80));
|
||||
frame_mutex.unlock();
|
||||
record_frames_mutex.lock();
|
||||
record_frames.insert(frame_id, compress(video_frame, 40));
|
||||
record_frames_mutex.unlock();
|
||||
|
||||
if (detection_status)
|
||||
{
|
||||
auto car = TaskDispatch::get_car_info();
|
||||
auto car_info = HxTaskDispatch::get_car_info();
|
||||
|
||||
if (car->fVelocity >= 10)
|
||||
if (car_info->fVelocity > 10)
|
||||
{
|
||||
#if USE_ALGORITHM
|
||||
bgr_frame_buffer.nFrameId = frame_id; // 帧号
|
||||
bgr_frame_buffer.u64PTS = QDateTime::currentMSecsSinceEpoch(); // 时间戳(毫秒)
|
||||
|
||||
memcpy(bgr_frame_buffer.pu8VirAddr, video_frame.data, 1280 * 720 * 3);
|
||||
|
||||
MvConvertImage(&bgr_frame_buffer, &detect_frame_buffer); // bgr->nv16
|
||||
#if USE_ALGORITHM
|
||||
MvObjectEventDetect(this->type, &detect_frame_buffer, car_info);
|
||||
|
||||
MvObjectEventDetect(this->type, &detect_frame_buffer, TaskDispatch::get_car_info());
|
||||
HxLog::append("algorithm", QString("type: %1, send %2 frame").arg(type).arg(frame_id));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
frame_id++;
|
||||
}
|
||||
}
|
||||
|
||||
void VideoDevice::run()
|
||||
{
|
||||
frame_id = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
video_frame_queue_check();
|
||||
|
||||
read_frame();
|
||||
|
||||
msleep(1);
|
||||
msleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
int VideoDevice::MvGetFrameBlkInfo(VideoFrameDataInfo* pImageDataInfo)
|
||||
int HxVideoDevice::MvGetFrameBlkInfo(VideoFrameDataInfo *pImageDataInfo)
|
||||
{
|
||||
Q_UNUSED(pImageDataInfo);
|
||||
|
||||
|
@ -352,7 +445,7 @@ int VideoDevice::MvGetFrameBlkInfo(VideoFrameDataInfo* pImageDataInfo)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int VideoDevice::MvReleaseFrameBlkInfo(VideoFrameDataInfo* pImageDataInfo)
|
||||
int HxVideoDevice::MvReleaseFrameBlkInfo(VideoFrameDataInfo *pImageDataInfo)
|
||||
{
|
||||
Q_UNUSED(pImageDataInfo);
|
||||
|
||||
|
@ -369,7 +462,7 @@ int VideoDevice::MvReleaseFrameBlkInfo(VideoFrameDataInfo* pImageDataInfo)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int VideoDevice::MvConvertImage(VideoFrameDataInfo* pSrcImageDataInfo, VideoFrameDataInfo* pDstImageDataInfo)
|
||||
int HxVideoDevice::MvConvertImage(VideoFrameDataInfo *pSrcImageDataInfo, VideoFrameDataInfo *pDstImageDataInfo)
|
||||
{
|
||||
Q_UNUSED(pSrcImageDataInfo);
|
||||
Q_UNUSED(pDstImageDataInfo);
|
||||
|
|
|
@ -19,14 +19,15 @@ using namespace std;
|
|||
#include "rkrga/im2d.hpp"
|
||||
#endif
|
||||
|
||||
class VideoDevice : public QThread
|
||||
class HxVideoDevice : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VideoDevice(void);
|
||||
HxVideoDevice(void);
|
||||
void set(int type, QString address);
|
||||
void set(int type, QString address, BsdWarnRegion region);
|
||||
void set(bool status);
|
||||
bool get_alarm_detection_timestamp(void);
|
||||
QString snap(void);
|
||||
|
||||
QString build_image(int id);
|
||||
|
@ -38,8 +39,9 @@ private:
|
|||
vector<uint8_t> compress(Mat frame, int quality);
|
||||
QString snap(Mat frame);
|
||||
QString snap(vector<uint8_t> data);
|
||||
void video_frame_queue_check();
|
||||
void read_frame();
|
||||
void recording_creation_task(void);
|
||||
void video_frame_queue_check(void);
|
||||
void frame_read_task(void);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
@ -51,12 +53,20 @@ private:
|
|||
|
||||
private:
|
||||
int type;
|
||||
int frame_id;
|
||||
int frame_fps;
|
||||
QString address;
|
||||
int frame_id = 0;
|
||||
int video_fps = 25;
|
||||
QString address = "";
|
||||
QDateTime alarm_detection_timestamp = QDateTime::currentDateTime();
|
||||
bool detection_status = true;
|
||||
QMap<int, vector<uint8_t>> video_frames_string;
|
||||
QMutex frame_mutex;
|
||||
|
||||
QMutex record_queue_mutex;
|
||||
QQueue<QString> record_queue;
|
||||
|
||||
QMutex video_frames_mutex;
|
||||
QQueue<Mat> video_frames;
|
||||
|
||||
QMutex record_frames_mutex;
|
||||
QMap<int, vector<uint8_t>> record_frames;
|
||||
|
||||
Mat video_frame;
|
||||
VideoCapture video_capture;
|
||||
|
@ -65,4 +75,4 @@ private:
|
|||
VideoFrameDataInfo bgr_frame_buffer;
|
||||
};
|
||||
|
||||
#endif // HXVIDEODEVICE_H
|
||||
#endif
|
||||
|
|
11
app/app.pro
11
app/app.pro
|
@ -26,10 +26,19 @@ CONFIG += c++11
|
|||
HEADERS += HxDataBase.h HxTaskDispatch.h HxUtils.h HxVideoDevice.h
|
||||
SOURCES += HxDataBase.cpp HxTaskDispatch.cpp HxVideoDevice.cpp main.cpp
|
||||
|
||||
# DEFINES += USE_RABBITMQ
|
||||
# DEFINES += USE_ALGORITHM
|
||||
|
||||
INCLUDEPATH += $$PWD/external
|
||||
|
||||
contains(DEFINES, USE_RABBITMQ) {
|
||||
INCLUDEPATH += $$PWD/external/qamqp
|
||||
LIBS += -L$$PWD/external/qamqp/ -lqamqp
|
||||
|
||||
unix {
|
||||
PRE_TARGETDEPS += $$PWD/external/qamqp/libqamqp.a
|
||||
}
|
||||
}
|
||||
contains(DEFINES, USE_ALGORITHM) {
|
||||
LIBS += -L$$PWD/external/ -lObjectEventDetect
|
||||
PRE_TARGETDEPS += $$PWD/external/libObjectEventDetect.a
|
||||
|
@ -46,6 +55,6 @@ win32 {
|
|||
}
|
||||
|
||||
unix {
|
||||
LIBS += -L/usr/local/lib -lopencv_imgproc -lopencv_videoio -lopencv_imgcodecs -lopencv_highgui -lopencv_core
|
||||
LIBS += -L/usr/local/lib -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -lopencv_core
|
||||
INCLUDEPATH += /usr/local/include
|
||||
}
|
||||
|
|
BIN
app/external/libObjectEventDetect.a
vendored
BIN
app/external/libObjectEventDetect.a
vendored
Binary file not shown.
BIN
app/external/qamqp/libqamqp.a
vendored
Normal file
BIN
app/external/qamqp/libqamqp.a
vendored
Normal file
Binary file not shown.
BIN
app/external/qamqp/qamqp.dll
vendored
Normal file
BIN
app/external/qamqp/qamqp.dll
vendored
Normal file
Binary file not shown.
55
app/external/qamqp/qamqpauthenticator.h
vendored
Normal file
55
app/external/qamqp/qamqpauthenticator.h
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
||||
* Copyright (C) 2014-2015 Matt Broadstone
|
||||
* Contact: https://github.com/mbroadst/qamqp
|
||||
*
|
||||
* This file is part of the QAMQP Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#ifndef QAMQPAUTHENTICATOR_H
|
||||
#define QAMQPAUTHENTICATOR_H
|
||||
|
||||
#include <QString>
|
||||
#include <QDataStream>
|
||||
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
class QAMQP_EXPORT QAmqpAuthenticator
|
||||
{
|
||||
public:
|
||||
virtual ~QAmqpAuthenticator() {}
|
||||
virtual QString type() const = 0;
|
||||
virtual void write(QDataStream &out) = 0;
|
||||
};
|
||||
|
||||
class QAMQP_EXPORT QAmqpPlainAuthenticator : public QAmqpAuthenticator
|
||||
{
|
||||
public:
|
||||
QAmqpPlainAuthenticator(const QString &login = QString(), const QString &password = QString());
|
||||
virtual ~QAmqpPlainAuthenticator();
|
||||
|
||||
QString login() const;
|
||||
void setLogin(const QString &l);
|
||||
|
||||
QString password() const;
|
||||
void setPassword(const QString &p);
|
||||
|
||||
virtual QString type() const;
|
||||
virtual void write(QDataStream &out);
|
||||
|
||||
private:
|
||||
QString login_;
|
||||
QString password_;
|
||||
|
||||
};
|
||||
|
||||
#endif // QAMQPAUTHENTICATOR_H
|
83
app/external/qamqp/qamqpchannel.h
vendored
Normal file
83
app/external/qamqp/qamqpchannel.h
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
||||
* Copyright (C) 2014-2015 Matt Broadstone
|
||||
* Contact: https://github.com/mbroadst/qamqp
|
||||
*
|
||||
* This file is part of the QAMQP Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#ifndef QAMQPCHANNEL_H
|
||||
#define QAMQPCHANNEL_H
|
||||
|
||||
#include <QObject>
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
class QAmqpClient;
|
||||
class QAmqpChannelPrivate;
|
||||
class QAMQP_EXPORT QAmqpChannel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int number READ channelNumber CONSTANT)
|
||||
Q_PROPERTY(bool open READ isOpen CONSTANT)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
public:
|
||||
virtual ~QAmqpChannel();
|
||||
|
||||
int channelNumber() const;
|
||||
bool isOpen() const;
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QAMQP::Error error() const;
|
||||
QString errorString() const;
|
||||
|
||||
qint32 prefetchSize() const;
|
||||
qint16 prefetchCount() const;
|
||||
|
||||
void reset();
|
||||
|
||||
// AMQP Basic
|
||||
void qos(qint16 prefetchCount, qint32 prefetchSize = 0);
|
||||
|
||||
public Q_SLOTS:
|
||||
void close();
|
||||
void reopen();
|
||||
void resume();
|
||||
|
||||
Q_SIGNALS:
|
||||
void opened();
|
||||
void closed();
|
||||
void resumed();
|
||||
void paused();
|
||||
void error(QAMQP::Error error);
|
||||
void qosDefined();
|
||||
|
||||
protected:
|
||||
virtual void channelOpened() = 0;
|
||||
virtual void channelClosed() = 0;
|
||||
|
||||
protected:
|
||||
explicit QAmqpChannel(QAmqpChannelPrivate *dd, QAmqpClient *client);
|
||||
|
||||
Q_DISABLE_COPY(QAmqpChannel)
|
||||
Q_DECLARE_PRIVATE(QAmqpChannel)
|
||||
QScopedPointer<QAmqpChannelPrivate> d_ptr;
|
||||
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_open())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_disconnected())
|
||||
|
||||
friend class QAmqpClientPrivate;
|
||||
friend class QAmqpExchangePrivate;
|
||||
};
|
||||
|
||||
#endif // QAMQPCHANNEL_H
|
84
app/external/qamqp/qamqpchannel_p.h
vendored
Normal file
84
app/external/qamqp/qamqpchannel_p.h
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
#ifndef QAMQPCHANNEL_P_H
|
||||
#define QAMQPCHANNEL_P_H
|
||||
|
||||
#include <QPointer>
|
||||
#include "qamqpframe_p.h"
|
||||
#include "qamqptable.h"
|
||||
|
||||
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
||||
|
||||
class QAmqpChannel;
|
||||
class QAmqpClient;
|
||||
class QAmqpClientPrivate;
|
||||
class QAmqpChannelPrivate : public QAmqpMethodFrameHandler
|
||||
{
|
||||
public:
|
||||
enum MethodId {
|
||||
METHOD_ID_ENUM(miOpen, 10),
|
||||
METHOD_ID_ENUM(miFlow, 20),
|
||||
METHOD_ID_ENUM(miClose, 40)
|
||||
};
|
||||
|
||||
enum BasicMethod {
|
||||
METHOD_ID_ENUM(bmQos, 10),
|
||||
METHOD_ID_ENUM(bmConsume, 20),
|
||||
METHOD_ID_ENUM(bmCancel, 30),
|
||||
bmPublish = 40,
|
||||
bmReturn = 50,
|
||||
bmDeliver = 60,
|
||||
METHOD_ID_ENUM(bmGet, 70),
|
||||
bmGetEmpty = 72,
|
||||
bmAck = 80,
|
||||
bmReject = 90,
|
||||
bmRecoverAsync = 100,
|
||||
METHOD_ID_ENUM(bmRecover, 110),
|
||||
bmNack = 120
|
||||
};
|
||||
|
||||
QAmqpChannelPrivate(QAmqpChannel *q);
|
||||
virtual ~QAmqpChannelPrivate();
|
||||
|
||||
void init(int channel, QAmqpClient *client);
|
||||
void sendFrame(const QAmqpFrame &frame);
|
||||
virtual void resetInternalState();
|
||||
|
||||
void open();
|
||||
void flow(bool active);
|
||||
void flowOk();
|
||||
void close(int code, const QString &text, int classId, int methodId);
|
||||
void notifyClosed();
|
||||
|
||||
// reimp MethodHandler
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
||||
void openOk(const QAmqpMethodFrame &frame);
|
||||
void flow(const QAmqpMethodFrame &frame);
|
||||
void flowOk(const QAmqpMethodFrame &frame);
|
||||
void close(const QAmqpMethodFrame &frame);
|
||||
void closeOk(const QAmqpMethodFrame &frame);
|
||||
void qosOk(const QAmqpMethodFrame &frame);
|
||||
|
||||
// private slots
|
||||
virtual void _q_disconnected();
|
||||
void _q_open();
|
||||
|
||||
QPointer<QAmqpClient> client;
|
||||
QString name;
|
||||
quint16 channelNumber;
|
||||
static quint16 nextChannelNumber;
|
||||
bool opened;
|
||||
bool needOpen;
|
||||
|
||||
qint32 prefetchSize;
|
||||
qint32 requestedPrefetchSize;
|
||||
qint16 prefetchCount;
|
||||
qint16 requestedPrefetchCount;
|
||||
|
||||
QAMQP::Error error;
|
||||
QString errorString;
|
||||
|
||||
Q_DECLARE_PUBLIC(QAmqpChannel)
|
||||
QAmqpChannel * const q_ptr;
|
||||
QAmqpTable arguments;
|
||||
};
|
||||
|
||||
#endif // QAMQPCHANNEL_P_H
|
98
app/external/qamqp/qamqpchannelhash_p.h
vendored
Normal file
98
app/external/qamqp/qamqpchannelhash_p.h
vendored
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
||||
* Copyright (C) 2014-2015 Matt Broadstone
|
||||
* Contact: https://github.com/mbroadst/qamqp
|
||||
*
|
||||
* This file is part of the QAMQP Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#ifndef QAMQPCHANNELHASH_P_H
|
||||
#define QAMQPCHANNELHASH_P_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QObject>
|
||||
|
||||
/* Forward declarations */
|
||||
class QAmqpChannel;
|
||||
class QAmqpQueue;
|
||||
class QAmqpExchange;
|
||||
|
||||
/*!
|
||||
* QAmqpChannelHash is a container for storing queues and exchanges for later
|
||||
* retrieval. When the objects are destroyed, they are automatically removed
|
||||
* from the container.
|
||||
*/
|
||||
class QAmqpChannelHash : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/*!
|
||||
* Retrieve a pointer to the named channel.
|
||||
*
|
||||
* A NULL string is assumed to be equivalent to "" for the purpose
|
||||
* of retrieving the nameless (default) exchange.
|
||||
*
|
||||
* \param[in] name The name of the channel to retrieve.
|
||||
* \retval NULL Channel does not exist.
|
||||
*/
|
||||
QAmqpChannel* get(const QString& name) const;
|
||||
|
||||
/*!
|
||||
* Return true if the named channel exists.
|
||||
*/
|
||||
bool contains(const QString& name) const;
|
||||
|
||||
/**
|
||||
* Returns a list of channels tracked by this hash
|
||||
*/
|
||||
QStringList channels() const;
|
||||
|
||||
/*!
|
||||
* Store an exchange in the hash. The nameless exchange is stored under
|
||||
* the name "".
|
||||
*/
|
||||
void put(QAmqpExchange* exchange);
|
||||
|
||||
/*!
|
||||
* Store a queue in the hash. If the queue is nameless, we hook its
|
||||
* declared signal and store it when the queue receives a name from the
|
||||
* broker, otherwise we store it under the name given.
|
||||
*/
|
||||
void put(QAmqpQueue* queue);
|
||||
|
||||
private Q_SLOTS:
|
||||
/*!
|
||||
* Handle destruction of a channel. Do a full garbage collection run.
|
||||
*/
|
||||
void channelDestroyed(QObject* object);
|
||||
|
||||
/*!
|
||||
* Handle a queue that has just been declared and given a new name. The
|
||||
* caller is assumed to be a QAmqpQueue instance.
|
||||
*/
|
||||
void queueDeclared();
|
||||
|
||||
private:
|
||||
/*!
|
||||
* Store a channel in the hash. This hooks the 'destroyed' signal
|
||||
* so the channel can be removed from our list.
|
||||
*/
|
||||
void put(const QString& name, QAmqpChannel* channel);
|
||||
|
||||
/*! A collection of channels. Key is the channel's "name". */
|
||||
QHash<QString, QAmqpChannel*> m_channels;
|
||||
};
|
||||
|
||||
/* vim: set ts=4 sw=4 et */
|
||||
#endif
|
146
app/external/qamqp/qamqpclient.h
vendored
Normal file
146
app/external/qamqp/qamqpclient.h
vendored
Normal file
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
||||
* Copyright (C) 2014-2015 Matt Broadstone
|
||||
* Contact: https://github.com/mbroadst/qamqp
|
||||
*
|
||||
* This file is part of the QAMQP Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#ifndef QAMQPCLIENT_H
|
||||
#define QAMQPCLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QHostAddress>
|
||||
#include <QSslConfiguration>
|
||||
#include <QSslError>
|
||||
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
class QAmqpExchange;
|
||||
class QAmqpQueue;
|
||||
class QAmqpAuthenticator;
|
||||
class QAmqpClientPrivate;
|
||||
class QAMQP_EXPORT QAmqpClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(quint32 port READ port WRITE setPort)
|
||||
Q_PROPERTY(QString host READ host WRITE setHost)
|
||||
Q_PROPERTY(QString virtualHost READ virtualHost WRITE setVirtualHost)
|
||||
Q_PROPERTY(QString user READ username WRITE setUsername)
|
||||
Q_PROPERTY(QString password READ password WRITE setPassword)
|
||||
Q_PROPERTY(bool autoReconnect READ autoReconnect WRITE setAutoReconnect)
|
||||
Q_PROPERTY(qint16 channelMax READ channelMax WRITE setChannelMax)
|
||||
Q_PROPERTY(qint32 frameMax READ frameMax WRITE setFrameMax)
|
||||
Q_PROPERTY(qint16 heartbeatDelay READ heartbeatDelay() WRITE setHeartbeatDelay)
|
||||
|
||||
public:
|
||||
explicit QAmqpClient(QObject *parent = 0);
|
||||
~QAmqpClient();
|
||||
|
||||
// properties
|
||||
quint16 port() const;
|
||||
void setPort(quint16 port);
|
||||
|
||||
QString host() const;
|
||||
void setHost(const QString &host);
|
||||
|
||||
QString virtualHost() const;
|
||||
void setVirtualHost(const QString &virtualHost);
|
||||
|
||||
QString username() const;
|
||||
void setUsername(const QString &username);
|
||||
|
||||
QString password() const;
|
||||
void setPassword(const QString &password);
|
||||
|
||||
void setAuth(QAmqpAuthenticator *auth);
|
||||
QAmqpAuthenticator *auth() const;
|
||||
|
||||
bool autoReconnect() const;
|
||||
void setAutoReconnect(bool value, int timeout = 0);
|
||||
|
||||
bool isConnected() const;
|
||||
|
||||
qint16 channelMax() const;
|
||||
void setChannelMax(qint16 channelMax);
|
||||
|
||||
qint32 frameMax() const;
|
||||
void setFrameMax(qint32 frameMax);
|
||||
|
||||
qint16 heartbeatDelay() const;
|
||||
void setHeartbeatDelay(qint16 delay);
|
||||
|
||||
int writeTimeout() const;
|
||||
void setWriteTimeout(int msecs);
|
||||
|
||||
void addCustomProperty(const QString &name, const QString &value);
|
||||
QString customProperty(const QString &name) const;
|
||||
|
||||
QAbstractSocket::SocketError socketError() const;
|
||||
QAbstractSocket::SocketState socketState() const;
|
||||
|
||||
QAMQP::Error error() const;
|
||||
QString errorString() const;
|
||||
|
||||
QSslConfiguration sslConfiguration() const;
|
||||
void setSslConfiguration(const QSslConfiguration &config);
|
||||
|
||||
static QString gitVersion();
|
||||
|
||||
// channels
|
||||
QAmqpExchange *createExchange(int channelNumber = -1);
|
||||
QAmqpExchange *createExchange(const QString &name, int channelNumber = -1);
|
||||
|
||||
QAmqpQueue *createQueue(int channelNumber = -1);
|
||||
QAmqpQueue *createQueue(const QString &name, int channelNumber = -1);
|
||||
|
||||
// methods
|
||||
void connectToHost(const QString &uri = QString());
|
||||
void connectToHost(const QHostAddress &address, quint16 port = AMQP_PORT);
|
||||
void disconnectFromHost();
|
||||
void abort();
|
||||
|
||||
Q_SIGNALS:
|
||||
void connected();
|
||||
void disconnected();
|
||||
void heartbeat();
|
||||
void error(QAMQP::Error error);
|
||||
void socketErrorOccurred(QAbstractSocket::SocketError error);
|
||||
void socketStateChanged(QAbstractSocket::SocketState state);
|
||||
void sslErrors(const QList<QSslError> &errors);
|
||||
|
||||
public Q_SLOTS:
|
||||
void ignoreSslErrors(const QList<QSslError> &errors);
|
||||
|
||||
protected:
|
||||
QAmqpClient(QAmqpClientPrivate *dd, QObject *parent = 0);
|
||||
|
||||
Q_DISABLE_COPY(QAmqpClient)
|
||||
Q_DECLARE_PRIVATE(QAmqpClient)
|
||||
QScopedPointer<QAmqpClientPrivate> d_ptr;
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_socketConnected())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_socketDisconnected())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_readyRead())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_socketError(QAbstractSocket::SocketError error))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_heartbeat())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_connect())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_disconnect())
|
||||
|
||||
friend class QAmqpChannelPrivate;
|
||||
friend class QAmqpQueuePrivate;
|
||||
|
||||
};
|
||||
|
||||
#endif // QAMQPCLIENT_H
|
120
app/external/qamqp/qamqpclient_p.h
vendored
Normal file
120
app/external/qamqp/qamqpclient_p.h
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
#ifndef QAMQPCLIENT_P_H
|
||||
#define QAMQPCLIENT_P_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QSharedPointer>
|
||||
#include <QPointer>
|
||||
#include <QAbstractSocket>
|
||||
#include <QSslError>
|
||||
|
||||
#include "qamqpchannelhash_p.h"
|
||||
#include "qamqpglobal.h"
|
||||
#include "qamqpauthenticator.h"
|
||||
#include "qamqptable.h"
|
||||
#include "qamqpframe_p.h"
|
||||
|
||||
#define METHOD_ID_ENUM(name, id) name = id, name ## Ok
|
||||
|
||||
class QTimer;
|
||||
class QSslSocket;
|
||||
class QAmqpClient;
|
||||
class QAmqpQueue;
|
||||
class QAmqpExchange;
|
||||
class QAmqpConnection;
|
||||
class QAmqpAuthenticator;
|
||||
class QAMQP_EXPORT QAmqpClientPrivate : public QAmqpMethodFrameHandler
|
||||
{
|
||||
public:
|
||||
enum MethodId {
|
||||
METHOD_ID_ENUM(miStart, 10),
|
||||
METHOD_ID_ENUM(miSecure, 20),
|
||||
METHOD_ID_ENUM(miTune, 30),
|
||||
METHOD_ID_ENUM(miOpen, 40),
|
||||
METHOD_ID_ENUM(miClose, 50)
|
||||
};
|
||||
|
||||
QAmqpClientPrivate(QAmqpClient *q);
|
||||
virtual ~QAmqpClientPrivate();
|
||||
|
||||
virtual void init();
|
||||
virtual void initSocket();
|
||||
void resetChannelState();
|
||||
void setUsername(const QString &username);
|
||||
void setPassword(const QString &password);
|
||||
void parseConnectionString(const QString &uri);
|
||||
void sendFrame(const QAmqpFrame &frame);
|
||||
|
||||
void closeConnection();
|
||||
|
||||
// private slots
|
||||
void _q_socketConnected();
|
||||
void _q_socketDisconnected();
|
||||
void _q_readyRead();
|
||||
void _q_socketError(QAbstractSocket::SocketError error);
|
||||
void _q_heartbeat();
|
||||
virtual void _q_connect();
|
||||
void _q_disconnect();
|
||||
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
||||
|
||||
// method handlers, FROM server
|
||||
void start(const QAmqpMethodFrame &frame);
|
||||
void secure(const QAmqpMethodFrame &frame);
|
||||
void tune(const QAmqpMethodFrame &frame);
|
||||
void openOk(const QAmqpMethodFrame &frame);
|
||||
void closeOk(const QAmqpMethodFrame &frame);
|
||||
|
||||
// method handlers, TO server
|
||||
void startOk();
|
||||
void secureOk();
|
||||
void tuneOk();
|
||||
void open();
|
||||
|
||||
// method handlers, BOTH ways
|
||||
void close(int code, const QString &text, int classId = 0, int methodId = 0);
|
||||
void close(const QAmqpMethodFrame &frame);
|
||||
|
||||
quint16 port;
|
||||
QString host;
|
||||
QString virtualHost;
|
||||
|
||||
QSharedPointer<QAmqpAuthenticator> authenticator;
|
||||
|
||||
// Network
|
||||
QByteArray buffer;
|
||||
bool autoReconnect;
|
||||
bool reconnectFixedTimeout;
|
||||
int timeout;
|
||||
bool connecting;
|
||||
bool useSsl;
|
||||
|
||||
QSslSocket *socket;
|
||||
QHash<quint16, QList<QAmqpMethodFrameHandler*> > methodHandlersByChannel;
|
||||
QHash<quint16, QList<QAmqpContentFrameHandler*> > contentHandlerByChannel;
|
||||
QHash<quint16, QList<QAmqpContentBodyFrameHandler*> > bodyHandlersByChannel;
|
||||
|
||||
// Connection
|
||||
bool closed;
|
||||
bool connected;
|
||||
QPointer<QTimer> heartbeatTimer;
|
||||
QPointer<QTimer> reconnectTimer;
|
||||
QAmqpTable customProperties;
|
||||
qint16 channelMax;
|
||||
qint16 heartbeatDelay;
|
||||
qint32 frameMax;
|
||||
|
||||
QAMQP::Error error;
|
||||
QString errorString;
|
||||
|
||||
/*! Exchange objects */
|
||||
QAmqpChannelHash exchanges;
|
||||
|
||||
/*! Named queue objects */
|
||||
QAmqpChannelHash queues;
|
||||
|
||||
QAmqpClient * const q_ptr;
|
||||
Q_DECLARE_PUBLIC(QAmqpClient)
|
||||
|
||||
};
|
||||
|
||||
#endif // QAMQPCLIENT_P_H
|
123
app/external/qamqp/qamqpexchange.h
vendored
Normal file
123
app/external/qamqp/qamqpexchange.h
vendored
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
||||
* Copyright (C) 2014-2015 Matt Broadstone
|
||||
* Contact: https://github.com/mbroadst/qamqp
|
||||
*
|
||||
* This file is part of the QAMQP Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#ifndef QAMQPEXCHANGE_H
|
||||
#define QAMQPEXCHANGE_H
|
||||
|
||||
#include "qamqptable.h"
|
||||
#include "qamqpchannel.h"
|
||||
#include "qamqpmessage.h"
|
||||
|
||||
class QAmqpClient;
|
||||
class QAmqpQueue;
|
||||
class QAmqpClientPrivate;
|
||||
class QAmqpExchangePrivate;
|
||||
class QAMQP_EXPORT QAmqpExchange : public QAmqpChannel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString type READ type CONSTANT)
|
||||
Q_PROPERTY(ExchangeOptions options READ options CONSTANT)
|
||||
|
||||
public:
|
||||
virtual ~QAmqpExchange();
|
||||
|
||||
enum ExchangeType {
|
||||
Direct,
|
||||
FanOut,
|
||||
Topic,
|
||||
Headers
|
||||
};
|
||||
QString type() const;
|
||||
|
||||
enum PublishOption {
|
||||
poNoOptions = 0x0,
|
||||
poMandatory = 0x01,
|
||||
poImmediate = 0x02
|
||||
};
|
||||
Q_DECLARE_FLAGS(PublishOptions, PublishOption)
|
||||
|
||||
enum RemoveOption {
|
||||
roForce = 0x0,
|
||||
roIfUnused = 0x01,
|
||||
roNoWait = 0x04
|
||||
};
|
||||
Q_DECLARE_FLAGS(RemoveOptions, RemoveOption)
|
||||
|
||||
enum ExchangeOption {
|
||||
NoOptions = 0x0,
|
||||
Passive = 0x01,
|
||||
Durable = 0x02,
|
||||
AutoDelete = 0x04,
|
||||
Internal = 0x08,
|
||||
NoWait = 0x10
|
||||
};
|
||||
Q_DECLARE_FLAGS(ExchangeOptions, ExchangeOption)
|
||||
ExchangeOptions options() const;
|
||||
Q_ENUM(ExchangeOptions)
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
void enableConfirms(bool noWait = false);
|
||||
bool waitForConfirms(int msecs = 30000);
|
||||
|
||||
Q_SIGNALS:
|
||||
void declared();
|
||||
void removed();
|
||||
|
||||
void confirmsEnabled();
|
||||
void allMessagesDelivered();
|
||||
|
||||
public Q_SLOTS:
|
||||
// AMQP Exchange
|
||||
void declare(QAmqpExchange::ExchangeType type = Direct,
|
||||
QAmqpExchange::ExchangeOptions options = NoOptions,
|
||||
const QAmqpTable &args = QAmqpTable());
|
||||
void declare(const QString &type,
|
||||
QAmqpExchange::ExchangeOptions options = NoOptions,
|
||||
const QAmqpTable &args = QAmqpTable());
|
||||
void remove(int options = roIfUnused|roNoWait);
|
||||
|
||||
// AMQP Basic
|
||||
void publish(const QString &message, const QString &routingKey,
|
||||
const QAmqpMessage::PropertyHash &properties = QAmqpMessage::PropertyHash(),
|
||||
int publishOptions = poNoOptions);
|
||||
void publish(const QByteArray &message, const QString &routingKey, const QString &mimeType,
|
||||
const QAmqpMessage::PropertyHash &properties = QAmqpMessage::PropertyHash(),
|
||||
int publishOptions = poNoOptions);
|
||||
void publish(const QByteArray &message, const QString &routingKey,
|
||||
const QString &mimeType, const QAmqpTable &headers,
|
||||
const QAmqpMessage::PropertyHash &properties = QAmqpMessage::PropertyHash(),
|
||||
int publishOptions = poNoOptions);
|
||||
|
||||
protected:
|
||||
virtual void channelOpened();
|
||||
virtual void channelClosed();
|
||||
|
||||
private:
|
||||
explicit QAmqpExchange(int channelNumber = -1, QAmqpClient *parent = 0);
|
||||
|
||||
Q_DISABLE_COPY(QAmqpExchange)
|
||||
Q_DECLARE_PRIVATE(QAmqpExchange)
|
||||
friend class QAmqpClient;
|
||||
friend class QAmqpClientPrivate;
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QAmqpExchange::ExchangeOptions)
|
||||
Q_DECLARE_METATYPE(QAmqpExchange::ExchangeType)
|
||||
|
||||
#endif // QAMQPEXCHANGE_H
|
45
app/external/qamqp/qamqpexchange_p.h
vendored
Normal file
45
app/external/qamqp/qamqpexchange_p.h
vendored
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef QAMQPEXCHANGE_P_H
|
||||
#define QAMQPEXCHANGE_P_H
|
||||
|
||||
#include "qamqptable.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpchannel_p.h"
|
||||
|
||||
class QAmqpExchangePrivate: public QAmqpChannelPrivate
|
||||
{
|
||||
public:
|
||||
enum MethodId {
|
||||
METHOD_ID_ENUM(miDeclare, 10),
|
||||
METHOD_ID_ENUM(miDelete, 20)
|
||||
};
|
||||
|
||||
enum ConfirmMethod {
|
||||
METHOD_ID_ENUM(cmConfirm, 10)
|
||||
};
|
||||
|
||||
QAmqpExchangePrivate(QAmqpExchange *q);
|
||||
static QString typeToString(QAmqpExchange::ExchangeType type);
|
||||
|
||||
virtual void resetInternalState();
|
||||
|
||||
void declare();
|
||||
|
||||
// method handler related
|
||||
virtual void _q_disconnected();
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
||||
void declareOk(const QAmqpMethodFrame &frame);
|
||||
void deleteOk(const QAmqpMethodFrame &frame);
|
||||
void basicReturn(const QAmqpMethodFrame &frame);
|
||||
void handleAckOrNack(const QAmqpMethodFrame &frame);
|
||||
|
||||
QString type;
|
||||
QAmqpExchange::ExchangeOptions options;
|
||||
bool delayedDeclare;
|
||||
bool declared;
|
||||
qlonglong nextDeliveryTag;
|
||||
QVector<qlonglong> unconfirmedDeliveryTags;
|
||||
|
||||
Q_DECLARE_PUBLIC(QAmqpExchange)
|
||||
};
|
||||
|
||||
#endif // QAMQPEXCHANGE_P_H
|
171
app/external/qamqp/qamqpframe_p.h
vendored
Normal file
171
app/external/qamqp/qamqpframe_p.h
vendored
Normal file
|
@ -0,0 +1,171 @@
|
|||
#ifndef QAMQPFRAME_P_H
|
||||
#define QAMQPFRAME_P_H
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QReadWriteLock>
|
||||
#include <QHash>
|
||||
#include <QVariant>
|
||||
|
||||
#include "qamqpglobal.h"
|
||||
#include "qamqpmessage.h"
|
||||
|
||||
class QAmqpFramePrivate;
|
||||
class QAmqpFrame
|
||||
{
|
||||
public:
|
||||
static const qint64 HEADER_SIZE = 7;
|
||||
static const qint64 FRAME_END_SIZE = 1;
|
||||
static const quint8 FRAME_END = 0xCE;
|
||||
|
||||
enum FrameType
|
||||
{
|
||||
Method = 1,
|
||||
Header = 2,
|
||||
Body = 3,
|
||||
Heartbeat = 8
|
||||
};
|
||||
|
||||
enum MethodClass
|
||||
{
|
||||
Connection = 10,
|
||||
Channel = 20,
|
||||
Exchange = 40,
|
||||
Queue = 50,
|
||||
Basic = 60,
|
||||
Confirm = 85,
|
||||
Tx = 90
|
||||
};
|
||||
|
||||
virtual ~QAmqpFrame();
|
||||
|
||||
FrameType type() const;
|
||||
|
||||
quint16 channel() const;
|
||||
void setChannel(quint16 channel);
|
||||
|
||||
static int writeTimeout();
|
||||
static void setWriteTimeout(int msecs);
|
||||
|
||||
virtual qint32 size() const;
|
||||
|
||||
static QVariant readAmqpField(QDataStream &s, QAmqpMetaType::ValueType type);
|
||||
static void writeAmqpField(QDataStream &s, QAmqpMetaType::ValueType type, const QVariant &value);
|
||||
|
||||
protected:
|
||||
explicit QAmqpFrame(FrameType type);
|
||||
virtual void writePayload(QDataStream &stream) const = 0;
|
||||
virtual void readPayload(QDataStream &stream) = 0;
|
||||
|
||||
qint32 size_;
|
||||
|
||||
private:
|
||||
qint8 type_;
|
||||
quint16 channel_;
|
||||
|
||||
static QReadWriteLock lock_;
|
||||
static int writeTimeout_;
|
||||
|
||||
friend QDataStream &operator<<(QDataStream &stream, const QAmqpFrame &frame);
|
||||
friend QDataStream &operator>>(QDataStream &stream, QAmqpFrame &frame);
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &, const QAmqpFrame &frame);
|
||||
QDataStream &operator>>(QDataStream &, QAmqpFrame &frame);
|
||||
|
||||
class QAMQP_EXPORT QAmqpMethodFrame : public QAmqpFrame
|
||||
{
|
||||
public:
|
||||
QAmqpMethodFrame();
|
||||
QAmqpMethodFrame(MethodClass methodClass, qint16 id);
|
||||
|
||||
qint16 id() const;
|
||||
MethodClass methodClass() const;
|
||||
|
||||
virtual qint32 size() const;
|
||||
|
||||
QByteArray arguments() const;
|
||||
void setArguments(const QByteArray &data);
|
||||
|
||||
private:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
|
||||
short methodClass_;
|
||||
qint16 id_;
|
||||
QByteArray arguments_;
|
||||
};
|
||||
|
||||
class QAmqpContentFrame : public QAmqpFrame
|
||||
{
|
||||
public:
|
||||
QAmqpContentFrame();
|
||||
QAmqpContentFrame(MethodClass methodClass);
|
||||
|
||||
MethodClass methodClass() const;
|
||||
|
||||
virtual qint32 size() const;
|
||||
|
||||
QVariant property(QAmqpMessage::Property prop) const;
|
||||
void setProperty(QAmqpMessage::Property prop, const QVariant &value);
|
||||
|
||||
qlonglong bodySize() const;
|
||||
void setBodySize(qlonglong size);
|
||||
|
||||
private:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
friend class QAmqpQueuePrivate;
|
||||
|
||||
short methodClass_;
|
||||
qint16 id_;
|
||||
mutable QByteArray buffer_;
|
||||
QAmqpMessage::PropertyHash properties_;
|
||||
qlonglong bodySize_;
|
||||
};
|
||||
|
||||
class QAmqpContentBodyFrame : public QAmqpFrame
|
||||
{
|
||||
public:
|
||||
QAmqpContentBodyFrame();
|
||||
|
||||
void setBody(const QByteArray &data);
|
||||
QByteArray body() const;
|
||||
|
||||
virtual qint32 size() const;
|
||||
|
||||
private:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
|
||||
QByteArray body_;
|
||||
};
|
||||
|
||||
class QAmqpHeartbeatFrame : public QAmqpFrame
|
||||
{
|
||||
public:
|
||||
QAmqpHeartbeatFrame();
|
||||
|
||||
private:
|
||||
void writePayload(QDataStream &stream) const;
|
||||
void readPayload(QDataStream &stream);
|
||||
};
|
||||
|
||||
class QAmqpMethodFrameHandler
|
||||
{
|
||||
public:
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame) = 0;
|
||||
};
|
||||
|
||||
class QAmqpContentFrameHandler
|
||||
{
|
||||
public:
|
||||
virtual void _q_content(const QAmqpContentFrame &frame) = 0;
|
||||
};
|
||||
|
||||
class QAmqpContentBodyFrameHandler
|
||||
{
|
||||
public:
|
||||
virtual void _q_body(const QAmqpContentBodyFrame &frame) = 0;
|
||||
};
|
||||
|
||||
#endif // QAMQPFRAME_P_H
|
134
app/external/qamqp/qamqpglobal.h
vendored
Normal file
134
app/external/qamqp/qamqpglobal.h
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
||||
* Copyright (C) 2014-2015 Matt Broadstone
|
||||
* Contact: https://github.com/mbroadst/qamqp
|
||||
*
|
||||
* This file is part of the QAMQP Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#ifndef QAMQPGLOBAL_H
|
||||
#define QAMQPGLOBAL_H
|
||||
|
||||
#include <QMetaType>
|
||||
|
||||
#define AMQP_SCHEME "amqp"
|
||||
#define AMQP_SSL_SCHEME "amqps"
|
||||
#define AMQP_PORT 5672
|
||||
#define AMQP_SSL_PORT 5671
|
||||
#define AMQP_HOST "localhost"
|
||||
#define AMQP_VHOST "/"
|
||||
#define AMQP_LOGIN "guest"
|
||||
#define AMQP_PSWD "guest"
|
||||
|
||||
#define AMQP_FRAME_MAX 131072
|
||||
#define AMQP_FRAME_MIN_SIZE 4096
|
||||
|
||||
#define AMQP_BASIC_CONTENT_TYPE_FLAG (1 << 15)
|
||||
#define AMQP_BASIC_CONTENT_ENCODING_FLAG (1 << 14)
|
||||
#define AMQP_BASIC_HEADERS_FLAG (1 << 13)
|
||||
#define AMQP_BASIC_DELIVERY_MODE_FLAG (1 << 12)
|
||||
#define AMQP_BASIC_PRIORITY_FLAG (1 << 11)
|
||||
#define AMQP_BASIC_CORRELATION_ID_FLAG (1 << 10)
|
||||
#define AMQP_BASIC_REPLY_TO_FLAG (1 << 9)
|
||||
#define AMQP_BASIC_EXPIRATION_FLAG (1 << 8)
|
||||
#define AMQP_BASIC_MESSAGE_ID_FLAG (1 << 7)
|
||||
#define AMQP_BASIC_TIMESTAMP_FLAG (1 << 6)
|
||||
#define AMQP_BASIC_TYPE_FLAG (1 << 5)
|
||||
#define AMQP_BASIC_USER_ID_FLAG (1 << 4)
|
||||
#define AMQP_BASIC_APP_ID_FLAG (1 << 3)
|
||||
#define AMQP_BASIC_CLUSTER_ID_FLAG (1 << 2)
|
||||
|
||||
#define QAMQP_VERSION "0.6.0"
|
||||
|
||||
#define AMQP_CONNECTION_FORCED 320
|
||||
|
||||
#ifdef QAMQP_SHARED
|
||||
# ifdef QAMQP_BUILD
|
||||
# define QAMQP_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define QAMQP_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define QAMQP_EXPORT
|
||||
#endif
|
||||
|
||||
#define qAmqpDebug if (qEnvironmentVariableIsEmpty("QAMQP_DEBUG")); else qDebug
|
||||
|
||||
namespace QAmqpMetaType {
|
||||
|
||||
enum ValueType
|
||||
{
|
||||
Invalid = -1,
|
||||
|
||||
// basic AMQP types
|
||||
Boolean,
|
||||
ShortUint,
|
||||
LongUint,
|
||||
LongLongUint,
|
||||
ShortString,
|
||||
LongString,
|
||||
|
||||
// field-value types
|
||||
ShortShortInt,
|
||||
ShortShortUint,
|
||||
ShortInt,
|
||||
LongInt,
|
||||
LongLongInt,
|
||||
Float,
|
||||
Double,
|
||||
Decimal,
|
||||
Array,
|
||||
Timestamp,
|
||||
Hash,
|
||||
Bytes,
|
||||
Void
|
||||
};
|
||||
|
||||
} // namespace QAmqpMetaType
|
||||
|
||||
namespace QAMQP {
|
||||
|
||||
enum Error
|
||||
{
|
||||
NoError = 0,
|
||||
ContentTooLargeError = 311,
|
||||
NoRouteError = 312,
|
||||
NoConsumersError = 313,
|
||||
ConnectionForcedError = 320,
|
||||
InvalidPathError = 402,
|
||||
AccessRefusedError = 403,
|
||||
NotFoundError = 404,
|
||||
ResourceLockedError = 405,
|
||||
PreconditionFailedError = 406,
|
||||
FrameError = 501,
|
||||
SyntaxError = 502,
|
||||
CommandInvalidError = 503,
|
||||
ChannelError = 504,
|
||||
UnexpectedFrameError = 505,
|
||||
ResourceError = 506,
|
||||
NotAllowedError = 530,
|
||||
NotImplementedError = 540,
|
||||
InternalError = 541
|
||||
};
|
||||
|
||||
struct Decimal
|
||||
{
|
||||
qint8 scale;
|
||||
quint32 value;
|
||||
};
|
||||
|
||||
} // namespace QAMQP
|
||||
|
||||
Q_DECLARE_METATYPE(QAMQP::Error)
|
||||
Q_DECLARE_METATYPE(QAMQP::Decimal)
|
||||
|
||||
#endif // QAMQPGLOBAL_H
|
89
app/external/qamqp/qamqpmessage.h
vendored
Normal file
89
app/external/qamqp/qamqpmessage.h
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
||||
* Copyright (C) 2014-2015 Matt Broadstone
|
||||
* Contact: https://github.com/mbroadst/qamqp
|
||||
*
|
||||
* This file is part of the QAMQP Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#ifndef QAMQPMESSAGE_H
|
||||
#define QAMQPMESSAGE_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QHash>
|
||||
#include <QSharedDataPointer>
|
||||
#include <QVariant>
|
||||
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
class QAmqpMessagePrivate;
|
||||
class QAMQP_EXPORT QAmqpMessage
|
||||
{
|
||||
public:
|
||||
QAmqpMessage();
|
||||
QAmqpMessage(const QAmqpMessage &other);
|
||||
QAmqpMessage &operator=(const QAmqpMessage &other);
|
||||
~QAmqpMessage();
|
||||
|
||||
inline void swap(QAmqpMessage &other) { qSwap(d, other.d); }
|
||||
|
||||
bool operator==(const QAmqpMessage &message) const;
|
||||
inline bool operator!=(const QAmqpMessage &message) const { return !(operator==(message)); }
|
||||
|
||||
enum Property {
|
||||
ContentType = AMQP_BASIC_CONTENT_TYPE_FLAG,
|
||||
ContentEncoding = AMQP_BASIC_CONTENT_ENCODING_FLAG,
|
||||
Headers = AMQP_BASIC_HEADERS_FLAG,
|
||||
DeliveryMode = AMQP_BASIC_DELIVERY_MODE_FLAG,
|
||||
Priority = AMQP_BASIC_PRIORITY_FLAG,
|
||||
CorrelationId = AMQP_BASIC_CORRELATION_ID_FLAG,
|
||||
ReplyTo = AMQP_BASIC_REPLY_TO_FLAG,
|
||||
Expiration = AMQP_BASIC_EXPIRATION_FLAG,
|
||||
MessageId = AMQP_BASIC_MESSAGE_ID_FLAG,
|
||||
Timestamp = AMQP_BASIC_TIMESTAMP_FLAG,
|
||||
Type = AMQP_BASIC_TYPE_FLAG,
|
||||
UserId = AMQP_BASIC_USER_ID_FLAG,
|
||||
AppId = AMQP_BASIC_APP_ID_FLAG,
|
||||
ClusterID = AMQP_BASIC_CLUSTER_ID_FLAG
|
||||
};
|
||||
Q_DECLARE_FLAGS(Properties, Property)
|
||||
typedef QHash<Property, QVariant> PropertyHash;
|
||||
|
||||
bool hasProperty(Property property) const;
|
||||
void setProperty(Property property, const QVariant &value);
|
||||
QVariant property(Property property, const QVariant &defaultValue = QVariant()) const;
|
||||
|
||||
bool hasHeader(const QString &header) const;
|
||||
void setHeader(const QString &header, const QVariant &value);
|
||||
QVariant header(const QString &header, const QVariant &defaultValue = QVariant()) const;
|
||||
QHash<QString, QVariant> headers() const;
|
||||
|
||||
bool isValid() const;
|
||||
bool isRedelivered() const;
|
||||
qlonglong deliveryTag() const;
|
||||
QString exchangeName() const;
|
||||
QString routingKey() const;
|
||||
QByteArray payload() const;
|
||||
|
||||
private:
|
||||
QSharedDataPointer<QAmqpMessagePrivate> d;
|
||||
friend class QAmqpQueuePrivate;
|
||||
friend class QAmqpQueue;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(QAmqpMessage::PropertyHash)
|
||||
Q_DECLARE_SHARED(QAmqpMessage)
|
||||
|
||||
// NOTE: needed only for MSVC support, don't depend on this hash
|
||||
QAMQP_EXPORT uint qHash(const QAmqpMessage &key, uint seed = 0);
|
||||
|
||||
#endif // QAMQPMESSAGE_H
|
26
app/external/qamqp/qamqpmessage_p.h
vendored
Normal file
26
app/external/qamqp/qamqpmessage_p.h
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef QAMQPMESSAGE_P_H
|
||||
#define QAMQPMESSAGE_P_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QSharedData>
|
||||
|
||||
#include "qamqpframe_p.h"
|
||||
#include "qamqpmessage.h"
|
||||
|
||||
class QAmqpMessagePrivate : public QSharedData
|
||||
{
|
||||
public:
|
||||
QAmqpMessagePrivate();
|
||||
|
||||
qlonglong deliveryTag;
|
||||
bool redelivered;
|
||||
QString exchangeName;
|
||||
QString routingKey;
|
||||
QByteArray payload;
|
||||
QHash<QAmqpMessage::Property, QVariant> properties;
|
||||
QHash<QString, QVariant> headers;
|
||||
int leftSize;
|
||||
|
||||
};
|
||||
|
||||
#endif // QAMQPMESSAGE_P_H
|
127
app/external/qamqp/qamqpqueue.h
vendored
Normal file
127
app/external/qamqp/qamqpqueue.h
vendored
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
||||
* Copyright (C) 2014-2015 Matt Broadstone
|
||||
* Contact: https://github.com/mbroadst/qamqp
|
||||
*
|
||||
* This file is part of the QAMQP Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#ifndef QAMQPQUEUE_H
|
||||
#define QAMQPQUEUE_H
|
||||
|
||||
#include <QQueue>
|
||||
|
||||
#include "qamqpchannel.h"
|
||||
#include "qamqpmessage.h"
|
||||
#include "qamqpglobal.h"
|
||||
#include "qamqptable.h"
|
||||
|
||||
class QAmqpClient;
|
||||
class QAmqpClientPrivate;
|
||||
class QAmqpExchange;
|
||||
class QAmqpQueuePrivate;
|
||||
class QAMQP_EXPORT QAmqpQueue : public QAmqpChannel, public QQueue<QAmqpMessage>
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int options READ options CONSTANT)
|
||||
Q_PROPERTY(QString consumerTag READ consumerTag WRITE setConsumerTag)
|
||||
|
||||
public:
|
||||
enum QueueOption {
|
||||
NoOptions = 0x0,
|
||||
Passive = 0x01,
|
||||
Durable = 0x02,
|
||||
Exclusive = 0x04,
|
||||
AutoDelete = 0x08,
|
||||
NoWait = 0x10
|
||||
};
|
||||
Q_DECLARE_FLAGS(QueueOptions, QueueOption)
|
||||
Q_ENUM(QueueOption)
|
||||
Q_ENUM(QueueOptions)
|
||||
int options() const;
|
||||
|
||||
enum ConsumeOption {
|
||||
coNoLocal = 0x01,
|
||||
coNoAck = 0x02,
|
||||
coExclusive = 0x04,
|
||||
coNoWait = 0x08
|
||||
};
|
||||
Q_DECLARE_FLAGS(ConsumeOptions, ConsumeOption)
|
||||
Q_ENUM(ConsumeOption)
|
||||
|
||||
enum RemoveOption {
|
||||
roForce = 0x0,
|
||||
roIfUnused = 0x01,
|
||||
roIfEmpty = 0x02,
|
||||
roNoWait = 0x04
|
||||
};
|
||||
Q_DECLARE_FLAGS(RemoveOptions, RemoveOption)
|
||||
Q_ENUM(RemoveOption)
|
||||
|
||||
~QAmqpQueue();
|
||||
|
||||
bool isConsuming() const;
|
||||
bool isDeclared() const;
|
||||
|
||||
void setConsumerTag(const QString &consumerTag);
|
||||
QString consumerTag() const;
|
||||
|
||||
qint32 messageCount() const;
|
||||
qint32 consumerCount() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void declared();
|
||||
void bound();
|
||||
void unbound();
|
||||
void removed();
|
||||
void purged(int messageCount);
|
||||
|
||||
void messageReceived();
|
||||
void empty();
|
||||
void consuming(const QString &consumerTag);
|
||||
void cancelled(const QString &consumerTag);
|
||||
|
||||
public Q_SLOTS:
|
||||
// AMQP Queue
|
||||
void declare(int options = Durable|AutoDelete, const QAmqpTable &arguments = QAmqpTable());
|
||||
void bind(const QString &exchangeName, const QString &key);
|
||||
void bind(QAmqpExchange *exchange, const QString &key);
|
||||
void unbind(const QString &exchangeName, const QString &key);
|
||||
void unbind(QAmqpExchange *exchange, const QString &key);
|
||||
void purge();
|
||||
void remove(int options = roIfUnused|roIfEmpty|roNoWait);
|
||||
|
||||
// AMQP Basic
|
||||
bool consume(int options = NoOptions);
|
||||
void get(bool noAck = true);
|
||||
bool cancel(bool noWait = false);
|
||||
void ack(const QAmqpMessage &message);
|
||||
void ack(qlonglong deliveryTag, bool multiple);
|
||||
void reject(const QAmqpMessage &message, bool requeue);
|
||||
void reject(qlonglong deliveryTag, bool requeue);
|
||||
|
||||
protected:
|
||||
// reimp Channel
|
||||
virtual void channelOpened();
|
||||
virtual void channelClosed();
|
||||
|
||||
private:
|
||||
explicit QAmqpQueue(int channelNumber = -1, QAmqpClient *parent = 0);
|
||||
|
||||
Q_DISABLE_COPY(QAmqpQueue)
|
||||
Q_DECLARE_PRIVATE(QAmqpQueue)
|
||||
friend class QAmqpClient;
|
||||
friend class QAmqpClientPrivate;
|
||||
|
||||
};
|
||||
|
||||
#endif // QAMQPQUEUE_H
|
64
app/external/qamqp/qamqpqueue_p.h
vendored
Normal file
64
app/external/qamqp/qamqpqueue_p.h
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
#ifndef QAMQPQUEUE_P_H
|
||||
#define QAMQPQUEUE_P_H
|
||||
|
||||
#include <QQueue>
|
||||
#include <QStringList>
|
||||
|
||||
#include "qamqpchannel_p.h"
|
||||
|
||||
class QAmqpQueuePrivate: public QAmqpChannelPrivate,
|
||||
public QAmqpContentFrameHandler,
|
||||
public QAmqpContentBodyFrameHandler
|
||||
{
|
||||
public:
|
||||
enum MethodId {
|
||||
METHOD_ID_ENUM(miDeclare, 10),
|
||||
METHOD_ID_ENUM(miBind, 20),
|
||||
METHOD_ID_ENUM(miUnbind, 50),
|
||||
METHOD_ID_ENUM(miPurge, 30),
|
||||
METHOD_ID_ENUM(miDelete, 40)
|
||||
};
|
||||
|
||||
QAmqpQueuePrivate(QAmqpQueue *q);
|
||||
~QAmqpQueuePrivate();
|
||||
|
||||
virtual void resetInternalState();
|
||||
|
||||
void declare();
|
||||
virtual bool _q_method(const QAmqpMethodFrame &frame);
|
||||
|
||||
// AMQP Queue method handlers
|
||||
void declareOk(const QAmqpMethodFrame &frame);
|
||||
void deleteOk(const QAmqpMethodFrame &frame);
|
||||
void purgeOk(const QAmqpMethodFrame &frame);
|
||||
void bindOk(const QAmqpMethodFrame &frame);
|
||||
void unbindOk(const QAmqpMethodFrame &frame);
|
||||
void consumeOk(const QAmqpMethodFrame &frame);
|
||||
|
||||
// AMQP Basic method handlers
|
||||
virtual void _q_content(const QAmqpContentFrame &frame);
|
||||
virtual void _q_body(const QAmqpContentBodyFrame &frame);
|
||||
void deliver(const QAmqpMethodFrame &frame);
|
||||
void getOk(const QAmqpMethodFrame &frame);
|
||||
void cancelOk(const QAmqpMethodFrame &frame);
|
||||
|
||||
QString type;
|
||||
int options;
|
||||
bool delayedDeclare;
|
||||
bool declared;
|
||||
QQueue<QPair<QString, QString> > delayedBindings;
|
||||
|
||||
QString consumerTag;
|
||||
bool recievingMessage;
|
||||
QAmqpMessage currentMessage;
|
||||
bool consuming;
|
||||
bool consumeRequested;
|
||||
|
||||
qint32 messageCount;
|
||||
qint32 consumerCount;
|
||||
|
||||
Q_DECLARE_PUBLIC(QAmqpQueue)
|
||||
|
||||
};
|
||||
|
||||
#endif // QAMQPQUEUE_P_H
|
43
app/external/qamqp/qamqptable.h
vendored
Normal file
43
app/external/qamqp/qamqptable.h
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
||||
* Copyright (C) 2014-2015 Matt Broadstone
|
||||
* Contact: https://github.com/mbroadst/qamqp
|
||||
*
|
||||
* This file is part of the QAMQP Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
#ifndef QAMQPTABLE_H
|
||||
#define QAMQPTABLE_H
|
||||
|
||||
#include <QVariantHash>
|
||||
|
||||
#include "qamqpglobal.h"
|
||||
|
||||
class QAMQP_EXPORT QAmqpTable : public QVariantHash
|
||||
{
|
||||
public:
|
||||
QAmqpTable() {}
|
||||
inline QAmqpTable(const QVariantHash &variantHash)
|
||||
: QVariantHash(variantHash)
|
||||
{
|
||||
}
|
||||
|
||||
static void writeFieldValue(QDataStream &stream, const QVariant &value);
|
||||
static void writeFieldValue(QDataStream &stream, QAmqpMetaType::ValueType type, const QVariant &value);
|
||||
static QVariant readFieldValue(QDataStream &stream, QAmqpMetaType::ValueType type);
|
||||
};
|
||||
|
||||
QAMQP_EXPORT QDataStream &operator<<(QDataStream &, const QAmqpTable &table);
|
||||
QAMQP_EXPORT QDataStream &operator>>(QDataStream &, QAmqpTable &table);
|
||||
Q_DECLARE_METATYPE(QAmqpTable)
|
||||
|
||||
#endif // QAMQPTABLE_H
|
16
app/main.cpp
16
app/main.cpp
|
@ -1,4 +1,5 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QThreadPool>
|
||||
|
||||
#include "HxTaskDispatch.h"
|
||||
|
||||
|
@ -9,13 +10,20 @@ int main(int argc, char *argv[])
|
|||
/* 需要设置的运行时默认工作路径 */
|
||||
QDir::setCurrent(QCoreApplication::applicationDirPath());
|
||||
|
||||
/* 记录日志 */
|
||||
HxLog::append("application", "startup");
|
||||
|
||||
/* 设置最大线程个数 */
|
||||
QThreadPool::globalInstance()->setMaxThreadCount(100);
|
||||
|
||||
/* 数据库模块初始化 */
|
||||
DataBase::initialization();
|
||||
HxDataBase::initialization();
|
||||
|
||||
TaskDispatch::initialization();
|
||||
HxTaskDispatch::initialization();
|
||||
|
||||
TaskDispatch::listern(9031);
|
||||
TaskDispatch::connect_to_host("192.168.10.10", 9031);
|
||||
HxTaskDispatch::listern(9031);
|
||||
// HxTaskDispatch::listern(9032);
|
||||
HxTaskDispatch::connect_to_host("192.168.10.10", 9031);
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user