Commit 9fc79d4363024d5bfc6c759fd63ff2109e23c470

Authored by Hu Chunming
1 parent fce4580d

同步代码初步跑通

.vscode/launch.json
... ... @@ -5,10 +5,10 @@
5 5 "version": "0.2.0",
6 6 "configurations": [
7 7 {
8   - "name": "dvpp",
  8 + "name": "demo",
9 9 "type": "cppdbg",
10 10 "request": "launch",
11   - "program": "${workspaceFolder}/bin/vpt_proj",
  11 + "program": "${workspaceFolder}/bin/demo",
12 12 "args": ["/home/cmhu/data/woyikewangh265.mp4","0", "0", "1"],
13 13 "stopAtEntry": false,
14 14 "cwd": "${workspaceFolder}/bin",
... ...
readme.md
... ... @@ -33,7 +33,7 @@
33 33 ~~~
34 34 mkdir build
35 35 cd ./build
36   -cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=../release ..
37   -make -j100
  36 +cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=../release -D BUILD_opencv_world=ON ..
  37 +make -j
38 38 make install
39 39 ~~~
40 40 \ No newline at end of file
... ...
src/Makefile
... ... @@ -36,7 +36,7 @@ LIBS= -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \
36 36 -L $(DEPEND_DIR) -lvpt_det -lsycheck \
37 37 -L $(OPENCV_ROOT)/lib -lopencv_video -lopencv_highgui -lopencv_imgproc -lopencv_core -lopencv_features2d -lopencv_flann\
38 38 -L $(JSON_ROOT)/lib -ljsoncpp \
39   - -L $(JSON_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \
  39 + -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \
40 40  
41 41 CXXFLAGS= -g -O0 -fPIC $(include_dir) $(lib_dir) $(lib) $(LIBS) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -fvisibility=hidden -Wall -Wno-deprecated -Wdeprecated-declarations -Wl,-Bsymbolic -ldl
42 42  
... ...
src/ai_platform/Makefile deleted
1   -# 各项目录
2   -LIB_DIR:=$(BUILD_DIR)/$(MODULE)/lib
3   -DEP_DIR:=$(BUILD_DIR)/$(MODULE)/.dep
4   -OBJ_DIR:=$(BUILD_DIR)/$(MODULE)/obj
5   -SRC_DIR:=$(TOP_DIR)/$(MODULE)
6   -
7   -# 源文件以及中间目标文件和依赖文件
8   -SRCS:=$(notdir $(wildcard $(SRC_DIR)/*.cpp))
9   -OBJS:=$(addprefix $(OBJ_DIR)/, $(patsubst %.cpp, %.o, $(SRCS)))
10   -DEPS:=$(addprefix $(DEP_DIR)/, $(patsubst %.cpp, %.d,a $(SRCS)))
11   -
12   -# 自动生成头文件依赖选项
13   -DEPFLAGS=-MT $@ -MMD -MP -MF $(DEP_DIR)/$*.d
14   -
15   -DEFS = -DENABLE_DVPP_INTERFACE
16   -
17   -# 最终目标文件
18   -TARGET:=$(BUILD_DIR)/bin/demo
19   -
20   -
21   -include_dir=-I/usr/local/Ascend/ascend-toolkit/6.3.RC1.alpha001/runtime/include
22   -
23   -lib_dir=-L/usr/lib \
24   - -L/usr/local/lib \
25   - -L/usr/local/Ascend/driver/lib64 \
26   - -L/usr/local/Ascend/ascend-toolkit/6.3.RC1.alpha001/atc/lib64\
27   - -L/usr/local/Ascend/ascend-toolkit/6.3.RC1.alpha001/runtime/lib64 \
28   - -L/usr/local/Ascend/ascend-toolkit/6.3.RC1.alpha001/runtime/lib64/stub \
29   - -L/usr/local/Ascend/ascend-toolkit/6.3.RC1.alpha001/lib64 \
30   - -L/usr/local/Ascend/driver/lib64/driver
31   -
32   -lib=-lacl_dvpp -lascendcl -lmmpa -lglog -lgflags -lpthread -lz -lacl_dvpp_mpi -lruntime -lascendalog -lc_sec -lmsprofiler -lgert -lge_executor -lge_common \
33   - -lgraph -lascend_protobuf -lprofapi -lerror_manager -lexe_graph -lregister -lplatform
34   -
35   -INCLUDE= -I $(TOP_DIR)/interface \
36   -
37   -LIBSPATH= -L $(BUILD_DIR)/interface/lib -l:interface.a \
38   - -L $(BUILD_DIR)/dvpp/lib -l:dvpp.a
39   -
40   -CXXFLAGS= -g -O0 -fPIC $(INCLUDE) $(include_dir) $(LIBSPATH) $(INCS) $(LIBS) $(lib_dir) $(lib) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -fvisibility=hidden -Wl,-Bsymbolic -ldl
41   - # -DUNICODE -D_UNICODE
42   -
43   -# 默认最终目标
44   -.PHONY:all
45   -all:$(TARGET)
46   -
47   -# 生成最终目标
48   -$(TARGET): $(OBJS) | $(LIB_DIR)
49   - @echo -e "\e[32m""Linking static library $(TARGET)""\e[0m"
50   - @echo -e "$(CXX) -o $@ $^ $(DEPFLAGS) $(CXXFLAGS) $(MACROS)"
51   - $(CXX) -o $@ $^ $(DEPFLAGS) $(CXXFLAGS) $(MACROS)
52   -
53   -# 若没有lib目录则自动生成
54   -$(LIB_DIR):
55   - @mkdir -p $@
56   -
57   -# 生成中间目标文件
58   -$(OBJ_DIR)/%.o:$(SRC_DIR)/%.cpp $(DEP_DIR)/%.d | $(OBJ_DIR) $(DEP_DIR)
59   - @echo -e "\e[33m""Building object $@""\e[0m"
60   - @echo -e "$(CXX) -c $(DEPFLAGS) $(CXXFLAGS) -o $@ $<"
61   - $(CXX) -c $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
62   -
63   -# 若没有obj目录则自动生成
64   -$(OBJ_DIR):
65   - @mkdir -p $@
66   -
67   -# 若没有.dep目录则自动生成
68   -$(DEP_DIR):
69   - @mkdir -p $@
70   -
71   -# 依赖文件会在生成中间文件的时候自动生成,这里只是为了防止报错
72   -$(DEPS):
73   -
74   -# 引入中间目标文件头文件依赖关系
75   -include $(wildcard $(DEPS))
76   -
77   -# 直接删除组件build目录
78   -.PHONY:clean
79   -clean:
80   - @rm -rf $(BUILD_DIR)/$(MODULE)
src/ai_platform/MultiSourceProcess.cpp
... ... @@ -12,12 +12,17 @@
12 12 #include "../helpers/time_helper.hpp"
13 13 #include "../helpers/os_helper.hpp"
14 14 #include "../helpers/gen_json.hpp"
  15 +#include "../helpers/img_util.h"
  16 +
15 17 #include "../reprocessing_module/save_snapshot_reprocessing.h"
16 18  
17 19 #include "macro_definition.h"
18 20 #include "SourceSingleton.hpp"
19 21  
20 22 #include "../util/vpc_util.h"
  23 +#include "../util/common_tool.h"
  24 +
  25 +#include "ErrorInfo.h"
21 26  
22 27 // #define VEHICLE_MULTI_BOXES
23 28  
... ... @@ -100,6 +105,15 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){
100 105 return ret;
101 106 }
102 107  
  108 + m_algorthim_region_leave.init(vptParam.gpuid, algorithm_type_t::HUMAN_LEAVE_REGION);
  109 + m_algorthim_region_dismiss.init(vptParam.gpuid, algorithm_type_t::HUMAN_REGION_DISMISS);
  110 + m_algorthim_region_fastmoving.init(vptParam.gpuid, algorithm_type_t::HUMAN_REGION_FAST_MOVING);
  111 +
  112 + m_human_gather.init(algorithm_type_t::HUMAN_GATHER);
  113 + m_human_density.init(algorithm_type_t::HUMAN_DENSITY);
  114 + m_human_region_gather.init(algorithm_type_t::HUMAN_REGION_GATHER);
  115 + m_vehicle_gather.init(algorithm_type_t::VEHICLE_GATHER);
  116 +
103 117 m_task_param_manager = task_param_manager::getInstance();
104 118 m_snapshot_reprocessing = new snapshot_reprocessing(m_devId);
105 119 m_save_snapshot_reprocessing = new save_snapshot_reprocessing(m_devId);
... ... @@ -146,13 +160,29 @@ int CMultiSourceProcess::AddMqConn(mq_type_t mq_type, rabbitmq_conn_params_t mq_
146 160 }
147 161  
148 162 /* 为报警类 绑定回调 传入mq_manager_.publish 内部直接调用*/
149   - if (mq_type_t::ALARM_MQ == mq_type)
150   - m_save_snapshot_reprocessing->set_callback(
  163 + if (mq_type_t::ALARM_MQ == mq_type) {
  164 + if (m_save_snapshot_reprocessing!= nullptr) {
  165 + m_save_snapshot_reprocessing->set_callback(
151 166 std::bind(&mq::Manager::publish, mq_manager_, mq_type, std::placeholders::_1, true));
  167 + }
  168 +
  169 +
  170 + m_algorthim_region_leave.set_callback(
  171 + std::bind(&mq::Manager::publish, mq_manager_, mq_type, std::placeholders::_1, true));
  172 +
  173 + m_algorthim_region_dismiss.set_callback(
  174 + std::bind(&mq::Manager::publish, mq_manager_, mq_type, std::placeholders::_1, true));
  175 +
  176 + m_algorthim_region_fastmoving.set_callback(
  177 + std::bind(&mq::Manager::publish, mq_manager_, mq_type, std::placeholders::_1, true));
  178 + }
  179 +
152 180  
153 181 return SUCCESS;
154 182 }
155 183  
  184 +#endif
  185 +
156 186 /* 获取任务的状态 MQ返回 */
157 187 int CMultiSourceProcess::GetTaskStatus(const string taskID) {
158 188  
... ... @@ -160,22 +190,30 @@ int CMultiSourceProcess::GetTaskStatus(const string taskID) {
160 190  
161 191 std::vector<std::string> taskids;
162 192 std::vector<int> statues;
  193 + int sta = 0;
163 194 if(pDecManager->isPausing(taskID)){
164 195 taskids.emplace_back(taskID);
165 196 statues.emplace_back(2);
166   - }else if(pDecManager->isRunning(taskID)){
  197 + sta = 2;
  198 + } else if(pDecManager->isRunning(taskID)){
167 199 taskids.emplace_back(taskID);
168 200 statues.emplace_back(1);
  201 + sta = 1;
  202 + } else if(pDecManager->isFinished(taskID)){
  203 + taskids.emplace_back(taskID);
  204 + statues.emplace_back(0);
  205 + sta = 0;
169 206 }
170 207  
  208 +#ifdef POST_USE_RABBITMQ
171 209 if (!taskids.empty()) {
172 210 auto json_str = helpers::gen_json::gen_task_status_json(taskids, statues);
173 211 mq_manager_->publish(mq_type_t::GET_TASK_MQ, json_str.c_str(),true);
174 212 }
  213 +#endif
175 214  
176   - return SUCCESS;
  215 + return sta;
177 216 }
178   -#endif
179 217  
180 218 bool CMultiSourceProcess::AddTask(task_param _cur_task_param){
181 219 DecoderManager* pDecManager = DecoderManager::getInstance();
... ... @@ -420,6 +458,16 @@ bool CMultiSourceProcess::finish_task(const string taskID, const bool delete_sna
420 458 pedestrian_vehicle_retrograde_.force_release_result(taskID); //221024 byzsh
421 459 #endif
422 460  
  461 + m_TotalObjMtx.lock();
  462 + for(auto ss = m_total_obj_info.begin(); ss != m_total_obj_info.end(); ) {
  463 + if (strcmp(ss->first.video_id.c_str(), taskID.c_str()) == 0) {
  464 + vector<sy_point>().swap(ss->second.center_points);
  465 + m_total_obj_info.erase(ss++);
  466 + }
  467 + else ss++;
  468 + }
  469 + m_TotalObjMtx.unlock();
  470 +
423 471 m_task_param_manager->delete_task_param(taskID);
424 472  
425 473 return true;
... ... @@ -516,6 +564,11 @@ int CMultiSourceProcess::algorthim_vpt(vector&lt;DeviceMemory*&gt; vec_gpuMem){
516 564 /* 一级检测器,内部已完成跟踪操作 */
517 565 vpt_process.process_gpu(vpt_interest_imgs.data(), vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // do det & track.
518 566  
  567 + gather_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_GATHER); // modified by zsh
  568 + gather_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_DENSITY);
  569 + gather_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_REGION_GATHER);
  570 + gather_process(vec_vptMem, vptResult, algorithm_type_t::VEHICLE_GATHER);
  571 +
519 572 m_snapshot_reprocessing->screen_effective_snapshot(vptResult);
520 573  
521 574 #ifndef VEHICLE_MULTI_BOXES
... ... @@ -542,6 +595,19 @@ int CMultiSourceProcess::algorthim_vpt(vector&lt;DeviceMemory*&gt; vec_gpuMem){
542 595  
543 596 // #endif
544 597  
  598 + m_algorthim_region_leave.process(vec_vptMem, vptResult, deleteObjectID);
  599 + m_algorthim_region_dismiss.process(vec_vptMem, vptResult, deleteObjectID);
  600 + m_algorthim_region_fastmoving.process(vec_vptMem, vptResult, deleteObjectID);
  601 +
  602 + cross_line_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_CROSSING_LINE);
  603 + cross_line_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_CLIMB);
  604 + cross_line_process(vec_vptMem, vptResult, algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE);
  605 +
  606 + wander_detect(vec_vptMem, vptResult, algorithm_type_t::HUMAN_LINGER);
  607 + wander_detect(vec_vptMem, vptResult, algorithm_type_t::VEHICLE_ILLEGAL_PARKING);
  608 + // 轨迹记录
  609 + trace_record(vec_vptMem, vptResult);
  610 +
545 611 if(vptResult.size() > 0){
546 612 cout << vptResult[0].obj_count<< endl;
547 613 }
... ... @@ -557,6 +623,35 @@ int CMultiSourceProcess::algorthim_vpt(vector&lt;DeviceMemory*&gt; vec_gpuMem){
557 623 return 0;
558 624 }
559 625  
  626 +// 轨迹记录
  627 +void CMultiSourceProcess::trace_record(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result>& vptResult) {
  628 +
  629 + for (size_t bidx = 0; bidx < vec_gpuMem.size(); bidx++){
  630 + DeviceMemory* gpuMem = vec_gpuMem[bidx];
  631 + string task_id = gpuMem->getId();
  632 +
  633 + for (int c = 0; c < vptResult[bidx].obj_count; c++) {
  634 + //计算检测框坐标中心点
  635 + sy_point center_point;
  636 + center_point.x_ = vptResult[bidx].obj[c].left + (vptResult[bidx].obj[c].right - vptResult[bidx].obj[c].left) * 0.5;
  637 + // center_point.y_ = vptResult[bidx].obj[c].top + (vptResult[bidx].obj[c].bottom - vptResult[bidx].obj[c].top) * 0.85;
  638 + center_point.y_ = vptResult[bidx].obj[c].bottom; // 越线检测以脚越线为标准
  639 +
  640 + OBJ_KEY new_obj = { task_id, vptResult[bidx].obj[c].id };
  641 + m_TotalObjMtx.lock();
  642 + auto it = m_total_obj_info.find(new_obj);
  643 + if (it == m_total_obj_info.end())
  644 + {
  645 + m_total_obj_info[new_obj].last_frame_nb = gpuMem->getFrameNb();
  646 + m_total_obj_info[new_obj].last_ts = gpuMem->getTimesstamp();
  647 + }
  648 + m_total_obj_info[new_obj].index = vptResult[bidx].obj[c].index;
  649 + m_total_obj_info[new_obj].center_points.push_back(center_point);
  650 + m_TotalObjMtx.unlock();
  651 + }
  652 + }
  653 +}
  654 +
560 655 int CMultiSourceProcess::algorithm_vehicle_relult(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& vptResult, vector<vector<int>>& delete_object_id) {
561 656  
562 657 vector<multi_obj_data_t> results = m_snapshot_reprocessing->get_vehicle_snapshot(vec_devMem, vptResult, skip_frame_);
... ... @@ -988,4 +1083,263 @@ bool CMultiSourceProcess::save_snapshot_process(const OBJ_KEY &amp;obj_key, const al
988 1083 }
989 1084  
990 1085 return true;
  1086 +}
  1087 +
  1088 +void CMultiSourceProcess::cross_line_process(vector<DeviceMemory*> vec_gpuMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType)
  1089 +{
  1090 + map<string, map<algo_type, task_param_manager::algo_param_type_t_*>> && algor_param = m_task_param_manager->get_task_other_params();
  1091 +
  1092 + for (int bidx = 0; bidx < vec_gpuMem.size(); ++ bidx) {
  1093 +
  1094 + DeviceMemory* gpuMem = vec_gpuMem[bidx];
  1095 + string task_id = gpuMem->getId();
  1096 +
  1097 + task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][eType];
  1098 + if (!cur_task_params)
  1099 + {
  1100 + continue;
  1101 + }
  1102 +
  1103 + algor_config_param_illegal_crossing_line* algor_param = (algor_config_param_illegal_crossing_line*)cur_task_params->algor_param;
  1104 + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)cur_task_params->basic_param;
  1105 + if (basic_param == nullptr || basic_param->adapt_param == nullptr) {
  1106 + continue;
  1107 + }
  1108 + universal_algor_adapt_param *adapt_param = basic_param->adapt_param;
  1109 +
  1110 + jxline std_line(algor_param->p1.x_, algor_param->p1.y_, algor_param->p2.x_, algor_param->p2.y_);
  1111 +
  1112 + std::string cur_src_ts = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>());
  1113 + std::string origin_file_path = basic_param->result_folder + helpers::os::sep + task_id + "_origin_" + cur_src_ts + ".jpg";
  1114 +
  1115 + std::vector<box_t> boxes;
  1116 + for (int c = 0; c < vptResult[bidx].obj_count; c++) {
  1117 + auto& obj_c = vptResult[bidx].obj[c];
  1118 +
  1119 + bool bHuman = eType == algorithm_type_t::HUMAN_CROSSING_LINE || eType == algorithm_type_t::HUMAN_CLIMB;
  1120 +
  1121 + bool bCount = false;
  1122 + if(bHuman && obj_c.index == (int)det_class_label_t::HUMAN) {
  1123 + bCount = true;
  1124 + } else if (eType == algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE && obj_c.index >= 4 && obj_c.index <= 8) {
  1125 + bCount = true;
  1126 + }
  1127 +
  1128 + sy_point center;
  1129 + center.x_ = (obj_c.right + obj_c.left)/ 2 ;
  1130 + center.y_ = (obj_c.bottom + obj_c.top) / 2;
  1131 + if (!bCount || !common::isInPolygon(adapt_param->points, adapt_param->points_count, center)) {
  1132 + continue;
  1133 + }
  1134 +
  1135 + if (obj_c.confidence < algor_param->conf_threshold)
  1136 + {
  1137 + continue;
  1138 + }
  1139 +
  1140 + int obj_width = obj_c.right - obj_c.left;
  1141 + int obj_height = obj_c.right - obj_c.left;
  1142 + if (obj_width < algor_param->minmum_width || obj_height < algor_param->minmum_height)
  1143 + {
  1144 + continue;
  1145 + }
  1146 +
  1147 + //计算检测框坐标中心点
  1148 + sy_point center_point;
  1149 + center_point.x_ = obj_c.left + (obj_c.right - obj_c.left) * 0.5;
  1150 + center_point.y_ = obj_c.bottom;
  1151 +
  1152 + m_TotalObjMtx.lock();
  1153 +
  1154 + OBJ_KEY obj_key = { task_id, obj_c.id };
  1155 + auto it = m_total_obj_info.find(obj_key);
  1156 + if (it != m_total_obj_info.end())
  1157 + {
  1158 + vector<sy_point> center_points = m_total_obj_info[obj_key].center_points;
  1159 + sy_point last_pt = center_points[center_points.size() - 1];
  1160 + // 计算越线
  1161 + jxline cur_line(last_pt.x_, last_pt.y_, center_point.x_, center_point.y_);
  1162 + bool bflag = common::is_intersect(cur_line, std_line);
  1163 + if (bflag)
  1164 + {
  1165 + box_t box;
  1166 + box.left = obj_c.left;
  1167 + box.right = obj_c.right;
  1168 + box.top = obj_c.top;
  1169 + box.bottom = obj_c.bottom;
  1170 + box.score = obj_c.confidence;
  1171 + boxes.push_back(box);
  1172 + }
  1173 + }
  1174 + m_TotalObjMtx.unlock();
  1175 + }
  1176 +
  1177 + if (boxes.size() <= 0)
  1178 + {
  1179 + continue;
  1180 + }
  1181 +
  1182 + int algorithm_type = (int)eType;
  1183 + string json_str = helpers::gen_json::gen_boxes_json(task_id, algorithm_type, boxes, origin_file_path);
  1184 +
  1185 + ImgSaveInfo info_origin;
  1186 + info_origin.img_info = VPCUtil::vpc_devMem2vpcImg(gpuMem);
  1187 + info_origin.file_path = origin_file_path;
  1188 + info_origin.json_str = json_str;
  1189 + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(info_origin);
  1190 + }
  1191 +}
  1192 +
  1193 +void CMultiSourceProcess::wander_detect(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType)
  1194 +{
  1195 + map<string, map<algo_type, task_param_manager::algo_param_type_t_*>> && algor_param = m_task_param_manager->get_task_other_params();
  1196 +
  1197 + for (size_t i = 0; i < vec_gpuMem.size(); i++)
  1198 + {
  1199 + DeviceMemory* gpuMem = vec_gpuMem[i];
  1200 + string task_id = gpuMem->getId();
  1201 + long frame_nb = gpuMem->getFrameNb();
  1202 +
  1203 + task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][eType];
  1204 + if (!cur_task_params)
  1205 + {
  1206 + continue;
  1207 + }
  1208 +
  1209 + algor_config_param_behavior* algor_param = (algor_config_param_behavior*)cur_task_params->algor_param;
  1210 + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)cur_task_params->basic_param;
  1211 + if (basic_param == nullptr || basic_param->adapt_param == nullptr) {
  1212 + continue;
  1213 + }
  1214 + universal_algor_adapt_param *adapt_param = basic_param->adapt_param;
  1215 +
  1216 + long algor_skip_gap = algor_param->duration;
  1217 +
  1218 + std::string cur_src_ts = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>());
  1219 + std::string origin_file_path = basic_param->result_folder + helpers::os::sep + task_id + "_origin_" + cur_src_ts + ".jpg";
  1220 +
  1221 + std::vector<box_t> boxes;
  1222 + for (int c = 0; c < vptResult[i].obj_count; c++) {
  1223 + auto& obj_c = vptResult[i].obj[c];
  1224 +
  1225 + bool bCount = false;
  1226 + if(eType == algorithm_type_t::HUMAN_LINGER && obj_c.index == (int)det_class_label_t::HUMAN) {
  1227 + bCount = true;
  1228 + } else if (eType == algorithm_type_t::VEHICLE_ILLEGAL_PARKING && obj_c.index >= 4 && obj_c.index <= 8) {
  1229 + bCount = true;
  1230 + }
  1231 +
  1232 + sy_point center;
  1233 + center.x_ = (obj_c.right + obj_c.left)/ 2 ;
  1234 + center.y_ = (obj_c.bottom + obj_c.top) / 2;
  1235 + if (!bCount || !common::isInPolygon(adapt_param->points, adapt_param->points_count, center)) {
  1236 + continue;
  1237 + }
  1238 +
  1239 + if (obj_c.confidence < algor_param->conf_threshold)
  1240 + {
  1241 + continue;
  1242 + }
  1243 +
  1244 + int obj_width = obj_c.right - obj_c.left;
  1245 + int obj_height = obj_c.right - obj_c.left;
  1246 + if (obj_width < algor_param->minmum_width || obj_height < algor_param->minmum_height)
  1247 + {
  1248 + continue;
  1249 + }
  1250 +
  1251 + OBJ_KEY o_key = { task_id, obj_c.id };
  1252 + m_TotalObjMtx.lock();
  1253 + auto it = m_total_obj_info.find(o_key);
  1254 + if (it != m_total_obj_info.end())
  1255 + {
  1256 + long skip_gap = frame_nb - m_total_obj_info[o_key].last_frame_nb;
  1257 + if (skip_gap > algor_skip_gap)
  1258 + {
  1259 + box_t box;
  1260 + box.left = obj_c.left;
  1261 + box.right = obj_c.right;
  1262 + box.top = obj_c.top;
  1263 + box.bottom = obj_c.bottom;
  1264 + box.score = obj_c.confidence;
  1265 + boxes.push_back(box);
  1266 +
  1267 + m_total_obj_info[o_key].last_frame_nb = frame_nb; // 更新帧号以判断下一次逗留
  1268 + }
  1269 + }
  1270 +
  1271 + m_TotalObjMtx.unlock();
  1272 + }
  1273 +
  1274 + if (boxes.size() <= 0)
  1275 + {
  1276 + continue;
  1277 + }
  1278 +
  1279 + int algorithm_type = (int)eType;
  1280 + string json_str = helpers::gen_json::gen_boxes_json(task_id, algorithm_type, boxes, origin_file_path);
  1281 +
  1282 + ImgSaveInfo info_origin;
  1283 + info_origin.img_info = VPCUtil::vpc_devMem2vpcImg(gpuMem);
  1284 + info_origin.file_path = origin_file_path;
  1285 + info_origin.json_str = json_str;
  1286 + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(info_origin);
  1287 + }
  1288 +}
  1289 +
  1290 +/* 每帧都需要做的算法模块 */
  1291 +int CMultiSourceProcess::gather_process(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result> &ol_det_result, algorithm_type_t algor_type) {
  1292 + /* 人数聚集算法功能 每帧都会获取算法结果 并返回 */
  1293 + std::vector<GatherResult> results;
  1294 + if (algor_type == algorithm_type_t::HUMAN_GATHER) {
  1295 + results = m_human_gather.process(vec_gpuMem, ol_det_result);
  1296 + } else if (algor_type == algorithm_type_t::HUMAN_DENSITY) {
  1297 + results = m_human_density.process(vec_gpuMem, ol_det_result);
  1298 + } else if (algor_type == algorithm_type_t::HUMAN_REGION_GATHER) {
  1299 + results = m_human_region_gather.process(vec_gpuMem, ol_det_result);
  1300 + } else if (algor_type == algorithm_type_t::VEHICLE_GATHER) {
  1301 + results = m_vehicle_gather.process(vec_gpuMem, ol_det_result);
  1302 + }
  1303 +
  1304 + int algorithm_type = (int)algor_type;
  1305 + for (auto &result : results) {
  1306 +
  1307 + if (result.boxes.size() <= 0)
  1308 + {
  1309 + continue;
  1310 + }
  1311 +
  1312 + auto task_id = result.task_id;
  1313 + auto task_other_params = m_task_param_manager->get_task_other_param(task_id);
  1314 + const auto &algor_other_params = task_other_params->find(algor_type);
  1315 + if (algor_other_params == task_other_params->end()) {
  1316 + LOG_ERROR("taskId {} not found algor {}", task_id.c_str(), (int)algor_type);
  1317 + continue;
  1318 + }
  1319 + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param;
  1320 +
  1321 + std::string cur_timestamp_ms = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>());
  1322 + const std::string origin_file_path = basic_param->result_folder + helpers::os::sep + task_id + "_" +
  1323 + std::to_string(result.boxes.size()) + "_" + std::to_string(result.id) + "_" + cur_timestamp_ms + ".jpg";
  1324 +
  1325 + string json_str = helpers::gen_json::gen_boxes_json(task_id, algorithm_type, result.boxes, origin_file_path);
  1326 +
  1327 + ImgSaveInfo info_origin;
  1328 + info_origin.img_info = result.origin_img;
  1329 + info_origin.file_path = origin_file_path;
  1330 + info_origin.json_str = json_str;
  1331 + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(info_origin);
  1332 + }
  1333 +
  1334 + return 0;
  1335 +}
  1336 +
  1337 +int CMultiSourceProcess::CountRunningTask() {
  1338 + DecoderManager* pDecManager = DecoderManager::getInstance();
  1339 + return pDecManager->count();
  1340 +}
  1341 +
  1342 +void CMultiSourceProcess::CloseAllTask2() {
  1343 + DecoderManager* pDecManager = DecoderManager::getInstance();
  1344 + pDecManager->closeAllDecoder();
991 1345 }
992 1346 \ No newline at end of file
... ...
src/ai_platform/MultiSourceProcess.h
... ... @@ -5,8 +5,7 @@
5 5 #include "../ai_engine_module/VPTProcess.h"
6 6 #include "../reprocessing_module/snapshot_reprocessing.h"
7 7 #include "../reprocessing_module/save_snapshot_reprocessing.h"
8   -#include "../ai_engine_module/pedestrian_vehicle_retrograde.h"
9   -#include "../ai_engine_module/pedestrian_vehicle_trespass.h"
  8 +#include "../ai_engine_module/ai_engine_module.h"
10 9 #include "../util/JpegUtil.h"
11 10  
12 11 #include <map>
... ... @@ -17,6 +16,10 @@
17 16 #include <deque>
18 17 #include <set>
19 18  
  19 +#ifdef POST_USE_RABBITMQ
  20 +#include "../reprocessing_module/mq_manager.hpp"
  21 +#endif
  22 +
20 23  
21 24 using namespace std;
22 25  
... ... @@ -37,9 +40,13 @@ public:
37 40  
38 41 #ifdef POST_USE_RABBITMQ
39 42 int AddMqConn(mq_type_t mq_type, rabbitmq_conn_params_t mq_conn_param);
40   - int GetTaskStatus(const string taskID);
41 43 #endif
42 44  
  45 + int GetTaskStatus(const string taskID);
  46 +
  47 + int CountRunningTask();
  48 + void CloseAllTask2();
  49 +
43 50 public:
44 51 int algorthim_process_thread(); // 算法处理线程
45 52 void task_finished(const string task_id);
... ... @@ -72,6 +79,15 @@ private:
72 79 void trespass_snapshot(vector<string>& vpt_interest_task_id, vector<vector<int>> deleteObjectID);
73 80 void retrograde_trespass_alarm(const OBJ_KEY &obj_key, const algorithm_type_t &algor_type) ;
74 81  
  82 + void cross_line_process(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType);
  83 +
  84 + void wander_detect(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType);
  85 +
  86 + int gather_process(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result> &ol_det_result, algorithm_type_t algor_type);
  87 +
  88 + // 轨迹记录
  89 + void trace_record(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result>& vptResult);
  90 +
75 91 private:
76 92 int m_devId;
77 93  
... ... @@ -98,6 +114,9 @@ private:
98 114 set<OBJ_KEY> m_total_snapshot_info_multi_object;
99 115 mutex m_total_mutex;
100 116  
  117 + mutex m_TotalObjMtx ;
  118 + map<OBJ_KEY, OBJ_INDEX> m_total_obj_info; // 记录目标轨迹
  119 +
101 120 JpegUtil jpegUtil;
102 121  
103 122 #ifdef POST_USE_RABBITMQ
... ... @@ -108,4 +127,13 @@ private:
108 127 ai_engine_module::pedestrian_vehicle_retrograde::PedestrianVehicleRetrograde pedestrian_vehicle_retrograde_;
109 128 ai_engine_module::pedestrian_vehicle_trespass::PedestrianVehicleTrespass pedestrian_vehicle_trespass_;
110 129  
  130 + ai_engine_module::RegionLeave m_algorthim_region_leave;
  131 + ai_engine_module::RegionLeave m_algorthim_region_dismiss;
  132 + ai_engine_module::RegionLeave m_algorthim_region_fastmoving;
  133 +
  134 + GatherDetect m_human_gather;
  135 + GatherDetect m_human_density;
  136 + GatherDetect m_human_region_gather;
  137 + GatherDetect m_vehicle_gather;
  138 +
111 139 };
112 140 \ No newline at end of file
... ...
src/ai_platform/det_obj_header.h
... ... @@ -21,6 +21,9 @@ using namespace std;
21 21 struct OBJ_INDEX {
22 22 int index;
23 23 int count; //用于对index的计数
  24 + int last_frame_nb{0};
  25 + int last_ts{0};
  26 + vector<sy_point> center_points; //存储轨迹中心点坐标--
24 27 OBJ_INDEX() : count(0), index(0) {}
25 28 };
26 29  
... ...
src/ai_platform/header.h
... ... @@ -34,12 +34,44 @@ enum class algorithm_type_t {
34 34 PEDESTRIAN_TRESPASS = 211,
35 35 ROAD_WORK_DET = 212, // 221026byzsh施工占道
36 36  
  37 + HUMAN_LINGER = 214, // 人员徘徊
  38 + HUMAN_REGION_GATHER = 215, // 区域人员聚集
  39 + HUMAN_REGION_DISMISS = 216, // 人员逃散
  40 + HUMAN_REGION_FAST_MOVING = 217, // 人员快速移动
  41 + HUMAN_DENSITY = 218, // 人员密度
  42 + HUMAN_CLIMB = 220, // 人员攀爬
  43 + HUMAN_CROSSING_LINE = 221, // 人员越线
  44 + HUMAN_LEAVE_REGION = 222, // 区域离开
  45 +
37 46 VEHICLE_SNAPSHOT = 301,
38 47 VEHICLE_RETROGRADE = 310,
39 48 VEHICLE_TRESPASS = 311,
  49 + VEHICLE_GATHER = 312, // 车辆聚集
  50 + VEHICLE_ILLEGAL_PARKING = 313, // 车辆违停
  51 + VEHICLE_ILLEGAL_CROSSING_LINE = 314, // 车辆压线
  52 + VEHICLE_LEAVE_REGION = 315, // 区域离开
40 53  
41 54 NONMOTOR_VEHICLE_SNAPSHOT = 401,
42 55 TAKEAWAY_MEMBER_CLASSIFICATION = 402,
  56 +
  57 + FLOW_STATISTICS = 500, // 用于数量统计
  58 + NONMOTOR_VEHICLE_NOHELMET = 501,// 电动/摩托车不戴头盔
  59 + NONMOTOR_VEHICLE_OVERMAN = 502, // 电动/摩托车超员
  60 + TRICYCLE_MANNED = 503, // 三轮车载人
  61 + TRUCK_MANNED = 504, // 货车货箱载人
  62 + NONMOTOR_VEHICLE_USEPHONE = 505,// 电动/摩托车驾乘人员使用手机
  63 + NONMOTOR_VEHICLE_REFIT = 506, // 电动车改装(加雨棚)
  64 + PERSON_RUNNING_REDLIGHTS = 507, // 行人闯红灯
  65 + NONMOTOR_RUNNING_REDLIGHTS = 508, // 非机动车闯红灯
  66 + PERSON_IN_VEHICLELANE = 509, // 行人占用机动车道
  67 + NONMOTOR_IN_VEHICLELANE = 510, // 非机动车占用机动车道
  68 + NONMOTOR_CEOSSPARKLINE = 511, // 非机动车越过停止线
  69 + PERSON_CROSS = 512, // 行人翻越护栏
  70 + NONMOTOR_WRONGDIRECTION = 513, // 非机动车逆行
  71 + VEHICLE_WRONGDIRECTION = 514, // 机动车逆行
  72 + VEHICLE_SOLIDLINETURNAROUND = 515,// 机动车实线掉头
  73 + VEHICLE_NOTGIVEWAY = 516, // 机动车不让行
  74 + VEHICLE_NOTDECELERATION = 517, // 机动车不减速
43 75 };
44 76  
45 77  
... ... @@ -243,6 +275,23 @@ typedef struct video_object_info {
243 275 } video_object_info;
244 276 #endif
245 277  
  278 +
  279 +// 二轮车/三轮车/货车载人参数结构体
  280 +#ifndef ___MANNED_INCIDENT_ALGOR_CONFIG_PARAM__
  281 +#define ___MANNED_INCIDENT_ALGOR_CONFIG_PARAM__
  282 +typedef struct algor_config_param_manned_incident {
  283 + int m, n;
  284 + int hs_count_threshold; //报警个数阈值
  285 + int obj_min_height, obj_min_width;
  286 + float obj_confidence_threshold;
  287 +
  288 + algor_config_param_manned_incident()
  289 + : m(10), n(8), hs_count_threshold(1), obj_min_height(6), obj_min_width(17),
  290 + obj_confidence_threshold(0.0f) {}
  291 +} algor_config_param_manned_incident;
  292 +#endif // #ifndef ___MANNED_INCIDENT_ALGOR_CONFIG_PARAM__
  293 +
  294 +
246 295 // 人员聚集参数结构体
247 296 #ifndef ___HUMAN_GATHER_ALGOR_CONFIG_PARAM__
248 297 #define ___HUMAN_GATHER_ALGOR_CONFIG_PARAM__
... ... @@ -352,6 +401,25 @@ typedef algor_config_param_pedestrian_safety_detector_basic algor_config_param_n
352 401 #endif // #ifndef ___PEDESTRIAN_SAFETY_DETECTOR_ALGOR_CONFIG_PARAM__
353 402  
354 403  
  404 +// 越线类
  405 +typedef struct algor_config_param_illegal_crossing_line {
  406 + float conf_threshold{0.0}; // 目标检测阈值,小于该阈值不识别
  407 + unsigned minmum_height, minmum_width; // 最小目标大小,小于该值不识别
  408 + sy_point p1; // 线段起点
  409 + sy_point p2; // 线段终点
  410 +} algor_config_param_illegal_crossing_line; // 车辆压线/人员越线/人员攀爬 共用
  411 +
  412 +
  413 +typedef struct algor_config_param_behavior {
  414 + float conf_threshold; // 目标检测阈值,小于该阈值不识别
  415 + unsigned minmum_height, minmum_width; // 最小目标大小,小于该值不识别
  416 + int duration; // 持续时长
  417 + int moving_distance_threshold; // 像素变动距离阈值
  418 + algor_config_param_behavior()
  419 + : duration(0), conf_threshold(0.0f), minmum_height(0), minmum_width(0), moving_distance_threshold(0) {
  420 + }
  421 +} algor_config_param_behavior;
  422 +
355 423  
356 424 // 行人安全检测参数
357 425 #ifndef ___RETROGRADE_ALGOR_CONFIG_PARAM__
... ... @@ -412,22 +480,39 @@ typedef struct algor_config_param_snapshot {
412 480 #endif
413 481  
414 482  
  483 +#ifndef __UNIVERSAL_ADAPTATON__
  484 +#define __UNIVERSAL_ADAPTATON__
  485 +#define ROI_MAX_POINT 50
  486 +#define MAX_DIRECTION_LINE 50
  487 +typedef struct universal_algor_adapt_param {
  488 + sy_point points[ROI_MAX_POINT];
  489 + int points_count; //多边形顶点数量(不超过ROI_MAX_POINT)
  490 + // sy_direction direction[MAX_DIRECTION_LINE];
  491 + int line_count; //拌线数量(不超过MAX_DIRECTION_LINE)
  492 +
  493 + universal_algor_adapt_param()
  494 + : points_count(0), line_count(0) {
  495 + }
  496 +} universal_algor_adapt_param;
  497 +#endif
  498 +
415 499  
416 500 // 算法的初始化参数
417 501 #ifndef __ALGOR_CONFIG_PARAM__BASIC__
418 502 #define __ALGOR_CONFIG_PARAM__BASIC__
419 503 typedef struct algor_basic_config_param_t {
  504 + universal_algor_adapt_param *adapt_param{nullptr}; //此处传入共性适配参数
420 505 sy_rect algor_valid_rect;
421 506 char *result_folder_little; //目标快照抠图保存地址
422 507 char *result_folder; //目标快照大图保存地址
  508 + char *video_folder; //目标视频保存地址
423 509 explicit algor_basic_config_param_t()
424   - : result_folder_little(nullptr), result_folder(nullptr) {}
  510 + : result_folder_little(nullptr), result_folder(nullptr), video_folder(nullptr), algor_valid_rect(0,0,3840,2160) {}
425 511 } algor_basic_config_param_t;
426 512 #endif // #ifndef __ALGOR_CONFIG_PARAM__BASIC__
427 513  
428 514  
429 515  
430   -
431 516 //算法的初始化参数
432 517 #ifndef __ALGOR_CONFIG_PARAM__
433 518 #define __ALGOR_CONFIG_PARAM__
... ... @@ -456,7 +541,7 @@ typedef struct task_param {
456 541 algor_config_param *algor_config_params; //该路rtsp流配置的所有算法参数
457 542 int algor_counts; //该路rtsp流共配置几种算法
458 543  
459   - int dec_type{0}; // 0: ffmpeg 1: gb28181 2:dvpp
  544 + int dec_type{0}; // 0: ffmpeg 1: gb28181 2:dvpp 3: dvpp_gb28181
460 545 int port; // gb28181时port为必填
461 546 int protocal; // gb28181 数据接收协议 0 : udp 1: tcp
462 547 GB28181_REQUEST_STREAM_CALLBACK gb28181_request_stream_callback;
... ... @@ -552,7 +637,9 @@ typedef struct rabbitmq_conn_params_t
552 637 #define __TSL_AIPLATFORM_PARAM__
553 638 typedef struct tsl_aiplatform_param {
554 639 int gpuid; //指定显卡id
  640 + int sip_server_port; // sip服务端端口
555 641 char *trt_serialize_file; //缓存文件保存路径
  642 + char *models_dir; // 模型文件目录
556 643  
557 644 ai_log_level log_level;
558 645 char *log_path; //日志文件路径
... ...
src/ai_platform/stl_aiplatform.cpp
... ... @@ -24,6 +24,7 @@ int add_mq_conn(void *handle, mq_type_t tstatus, rabbitmq_conn_params_t mq_conn_
24 24 CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
25 25 return tools->AddMqConn(tstatus, mq_conn_param);
26 26 }
  27 +#endif
27 28  
28 29 int get_task_status(void *handle, char *task_id)
29 30 {
... ... @@ -31,8 +32,6 @@ int get_task_status(void *handle, char *task_id)
31 32 return tools->GetTaskStatus(task_id);
32 33 }
33 34  
34   -#endif
35   -
36 35 int add_task(void *handle, task_param param)
37 36 {
38 37 CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
... ... @@ -95,6 +94,17 @@ int tsl_aiplatform_release(void **handle)
95 94 return SUCCESS;
96 95 }
97 96  
  97 +int count_running_task(void *handle)
  98 +{
  99 + CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
  100 + return tools->CountRunningTask();
  101 +}
  102 +
  103 +void close_all_task(void *handle)
  104 +{
  105 + CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
  106 + tools->CloseAllTask2();
  107 +}
98 108  
99 109 const char* get_tsl_aiplatform_version()
100 110 {
... ...
src/ai_platform/stl_aiplatform.h
... ... @@ -43,12 +43,11 @@ extern &quot;C&quot;
43 43 */
44 44 TSL_AIPLATFORM_API int add_mq_conn(void *handle, mq_type_t tstatus, rabbitmq_conn_params_t mq_conn_param);
45 45  
  46 +#endif
46 47  
47 48  
48 49 TSL_AIPLATFORM_API int get_task_status(void *handle, char *task_id);
49 50  
50   -#endif
51   -
52 51 /*************************************************************************
53 52 * FUNCTION: add_task
54 53 * PURPOSE: 添加任务
... ... @@ -120,6 +119,11 @@ extern &quot;C&quot;
120 119 TSL_AIPLATFORM_API int tsl_aiplatform_release(void **handle);
121 120  
122 121  
  122 + TSL_AIPLATFORM_API int count_running_task(void *handle);
  123 +
  124 + TSL_AIPLATFORM_API void close_all_task(void *handle);
  125 +
  126 +
123 127 /*************************************************************************
124 128 * FUNCTION: get_tsl_aiplatform_version
125 129 * PURPOSE: 获取SDK版本号
... ...
src/ai_platform/task_param_manager.cpp
... ... @@ -45,6 +45,68 @@ bool copy_algor_param_aux(const algorithm_type_t &amp;algor_type, const std::string
45 45 }
46 46 } break;
47 47  
  48 + // 农村相关事件
  49 + case algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN:
  50 + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type);
  51 + goto _manned_param_copy;
  52 + case algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET:
  53 + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type);
  54 + goto _manned_param_copy;
  55 + case algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE:
  56 + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type);
  57 + goto _manned_param_copy;
  58 + case algorithm_type_t::NONMOTOR_VEHICLE_REFIT:
  59 + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type);
  60 + goto _manned_param_copy;
  61 + case algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS:
  62 + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type);
  63 + goto _manned_param_copy;
  64 + case algorithm_type_t::NONMOTOR_IN_VEHICLELANE:
  65 + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type);
  66 + goto _manned_param_copy;
  67 + case algorithm_type_t::NONMOTOR_CEOSSPARKLINE:
  68 + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type);
  69 + goto _manned_param_copy;
  70 + case algorithm_type_t::NONMOTOR_WRONGDIRECTION:
  71 + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type);
  72 + goto _manned_param_copy;
  73 + case algorithm_type_t::TRICYCLE_MANNED:
  74 + m_algor_config_params[task_id].nonmotor_vehicle_algors.insert(algor_type);
  75 + goto _manned_param_copy;
  76 + case algorithm_type_t::PERSON_RUNNING_REDLIGHTS:
  77 + m_algor_config_params[task_id].human_algors.insert(algor_type);
  78 + goto _manned_param_copy;
  79 + case algorithm_type_t::PERSON_IN_VEHICLELANE:
  80 + m_algor_config_params[task_id].human_algors.insert(algor_type);
  81 + goto _manned_param_copy;
  82 + case algorithm_type_t::PERSON_CROSS:
  83 + m_algor_config_params[task_id].human_algors.insert(algor_type);
  84 + goto _manned_param_copy;
  85 + case algorithm_type_t::VEHICLE_WRONGDIRECTION:
  86 + m_algor_config_params[task_id].vehicle_algors.insert(algor_type);
  87 + goto _manned_param_copy;
  88 + case algorithm_type_t::VEHICLE_NOTGIVEWAY:
  89 + m_algor_config_params[task_id].vehicle_algors.insert(algor_type);
  90 + goto _manned_param_copy;
  91 + case algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND:
  92 + m_algor_config_params[task_id].vehicle_algors.insert(algor_type);
  93 + goto _manned_param_copy;
  94 + case algorithm_type_t::VEHICLE_NOTDECELERATION:
  95 + m_algor_config_params[task_id].vehicle_algors.insert(algor_type);
  96 + goto _manned_param_copy;
  97 + case algorithm_type_t::TRUCK_MANNED: {
  98 + m_algor_config_params[task_id].vehicle_algors.insert(algor_type);
  99 + _manned_param_copy : {
  100 + using algor_config_param_type = algor_config_param_manned_incident;
  101 + copied_algor_param->algor_param = new algor_config_param_type;
  102 + *((algor_config_param_type *)(copied_algor_param->algor_param)) =
  103 + *((algor_config_param_type *)algor_param); // deep copy.
  104 + }
  105 + } break;
  106 +
  107 + case algorithm_type_t::VEHICLE_GATHER:
  108 + case algorithm_type_t::HUMAN_REGION_GATHER:
  109 + case algorithm_type_t::HUMAN_DENSITY:
48 110 case algorithm_type_t::HUMAN_GATHER: {
49 111 m_algor_config_params[task_id].human_algors.insert(algor_type);
50 112 using algor_config_param_type = algor_config_param_human_gather;
... ... @@ -53,6 +115,27 @@ bool copy_algor_param_aux(const algorithm_type_t &amp;algor_type, const std::string
53 115 *((algor_config_param_type *)algor_param); // deep copy.
54 116 } break;
55 117  
  118 + case algorithm_type_t::HUMAN_CROSSING_LINE:
  119 + case algorithm_type_t::HUMAN_CLIMB:
  120 + case algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE:
  121 + {
  122 + m_algor_config_params[task_id].human_algors.insert(algor_type);
  123 + using algor_config_param_type = algor_config_param_illegal_crossing_line;
  124 + copied_algor_param->algor_param = new algor_config_param_type;
  125 + *((algor_config_param_type *)(copied_algor_param->algor_param)) =
  126 + *((algor_config_param_type *)algor_param); // deep copy.
  127 + } break;
  128 +
  129 + case algorithm_type_t::HUMAN_LINGER:
  130 + case algorithm_type_t::VEHICLE_ILLEGAL_PARKING:
  131 + {
  132 + m_algor_config_params[task_id].human_algors.insert(algor_type);
  133 + using algor_config_param_type = algor_config_param_behavior;
  134 + copied_algor_param->algor_param = new algor_config_param_type;
  135 + *((algor_config_param_type *)(copied_algor_param->algor_param)) =
  136 + *((algor_config_param_type *)algor_param); // deep copy.
  137 + } break;
  138 +
56 139  
57 140 //221026byzsh---------------------------------------------------------
58 141 case algorithm_type_t::ROAD_WORK_DET: {
... ... @@ -216,11 +299,25 @@ void task_param_manager::add_task_param(string task_id, task_param task_param) {
216 299 } else
217 300 dst_basic_param->result_folder = nullptr;
218 301  
  302 + if (src_basic_param->video_folder) {
  303 + dst_basic_param->video_folder = new char[strlen(src_basic_param->video_folder) + 1];
  304 + strcpy(dst_basic_param->video_folder, src_basic_param->video_folder);
  305 + CreateResultFolder(dst_basic_param->video_folder, "");
  306 + } else
  307 + dst_basic_param->video_folder = nullptr;
  308 +
219 309 dst_basic_param->algor_valid_rect.left_ = src_basic_param->algor_valid_rect.left_;
220 310 dst_basic_param->algor_valid_rect.top_ = src_basic_param->algor_valid_rect.top_;
221 311 dst_basic_param->algor_valid_rect.width_ = src_basic_param->algor_valid_rect.width_;
222 312 dst_basic_param->algor_valid_rect.height_ = src_basic_param->algor_valid_rect.height_;
223 313  
  314 + /* 拷贝共性算法适配参数 */
  315 + auto &adapt_param = src_basic_param->adapt_param;
  316 + if (adapt_param) {
  317 + dst_basic_param->adapt_param = new universal_algor_adapt_param;
  318 + *((universal_algor_adapt_param *)(dst_basic_param->adapt_param)) = *((universal_algor_adapt_param *)adapt_param); // deep copy.
  319 + }
  320 +
224 321 copied_algor_param->basic_param = dst_basic_param;
225 322 m_task_params[task_id][algor_config_param.algor_type] = copied_algor_param;
226 323 }
... ... @@ -245,6 +342,18 @@ void task_param_manager::delete_task_param(string task_id) {
245 342 delete[] cur_param->result_folder;
246 343 cur_param->result_folder = nullptr;
247 344 }
  345 + if (cur_param->video_folder) {
  346 + delete[] cur_param->video_folder;
  347 + cur_param->video_folder = nullptr;
  348 + }
  349 +
  350 + universal_algor_adapt_param *adapt_param =
  351 + (universal_algor_adapt_param *)cur_param->adapt_param;
  352 + if (adapt_param) {
  353 + delete (universal_algor_adapt_param *)cur_param->adapt_param;
  354 + cur_param->adapt_param = nullptr;
  355 + }
  356 +
248 357 if (cur_param) {
249 358 delete ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->basic_param;
250 359 ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->basic_param = nullptr;
... ... @@ -273,6 +382,10 @@ void task_param_manager::delete_task_param(string task_id) {
273 382 }
274 383 break;
275 384 }
  385 +
  386 + case algorithm_type_t::VEHICLE_GATHER:
  387 + case algorithm_type_t::HUMAN_REGION_GATHER:
  388 + case algorithm_type_t::HUMAN_DENSITY:
276 389 case algorithm_type_t::HUMAN_GATHER: {
277 390 algor_config_param_human_gather *algor_param =
278 391 (algor_config_param_human_gather *)((algor_init_config_param_t *)m_task_params[task_id][iter.first])
... ... @@ -285,6 +398,34 @@ void task_param_manager::delete_task_param(string task_id) {
285 398 break;
286 399 }
287 400  
  401 + case algorithm_type_t::HUMAN_CROSSING_LINE:
  402 + case algorithm_type_t::HUMAN_CLIMB:
  403 + case algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE:
  404 + {
  405 + algor_config_param_illegal_crossing_line *algor_param =
  406 + (algor_config_param_illegal_crossing_line *)((algor_init_config_param_t *)m_task_params[task_id][iter.first])
  407 + ->algor_param;
  408 + if (algor_param) {
  409 + delete (algor_config_param_illegal_crossing_line *)((algor_init_config_param_t *)m_task_params[task_id][iter.first])
  410 + ->algor_param;
  411 + ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->algor_param = nullptr;
  412 + }
  413 + break;
  414 + }
  415 +
  416 + case algorithm_type_t::HUMAN_LINGER:
  417 + case algorithm_type_t::VEHICLE_ILLEGAL_PARKING:
  418 + {
  419 + algor_config_param_behavior *algor_param =
  420 + (algor_config_param_behavior *)((algor_init_config_param_t *)m_task_params[task_id][iter.first])
  421 + ->algor_param;
  422 + if (algor_param) {
  423 + delete (algor_config_param_behavior *)((algor_init_config_param_t *)m_task_params[task_id][iter.first])
  424 + ->algor_param;
  425 + ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->algor_param = nullptr;
  426 + }
  427 + break;
  428 + }
288 429  
289 430 //221026byzsh---------------------------------------------------------
290 431 case algorithm_type_t::ROAD_WORK_DET: {
... ... @@ -313,6 +454,49 @@ void task_param_manager::delete_task_param(string task_id) {
313 454 break;
314 455 }
315 456 //--------------------------------------------------------------------
  457 + // 农村相关事件
  458 + case algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN:
  459 + goto _manned_param_delete;
  460 + case algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET:
  461 + goto _manned_param_delete;
  462 + case algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE:
  463 + goto _manned_param_delete;
  464 + case algorithm_type_t::NONMOTOR_VEHICLE_REFIT:
  465 + goto _manned_param_delete;
  466 + case algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS:
  467 + goto _manned_param_delete;
  468 + case algorithm_type_t::NONMOTOR_IN_VEHICLELANE:
  469 + goto _manned_param_delete;
  470 + case algorithm_type_t::NONMOTOR_CEOSSPARKLINE:
  471 + goto _manned_param_delete;
  472 + case algorithm_type_t::NONMOTOR_WRONGDIRECTION:
  473 + goto _manned_param_delete;
  474 + case algorithm_type_t::TRICYCLE_MANNED:
  475 + goto _manned_param_delete;
  476 + case algorithm_type_t::PERSON_RUNNING_REDLIGHTS:
  477 + goto _manned_param_delete;
  478 + case algorithm_type_t::PERSON_IN_VEHICLELANE:
  479 + goto _manned_param_delete;
  480 + case algorithm_type_t::PERSON_CROSS:
  481 + goto _manned_param_delete;
  482 + case algorithm_type_t::VEHICLE_WRONGDIRECTION:
  483 + goto _manned_param_delete;
  484 + case algorithm_type_t::VEHICLE_NOTGIVEWAY:
  485 + goto _manned_param_delete;
  486 + case algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND:
  487 + goto _manned_param_delete;
  488 + case algorithm_type_t::VEHICLE_NOTDECELERATION:
  489 + goto _manned_param_delete;
  490 + case algorithm_type_t::TRUCK_MANNED: {
  491 + _manned_param_delete : {
  492 + using ptr_t = algor_config_param_manned_incident;
  493 + ptr_t *algor_param = (ptr_t *)((algor_init_config_param_t *)m_task_params[task_id][iter.first])->algor_param;
  494 + if (algor_param) {
  495 + delete (ptr_t *)((algor_init_config_param_t *)m_task_params[task_id][iter.first])->algor_param;
  496 + ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->algor_param = nullptr;
  497 + }
  498 + }
  499 + } break;
316 500  
317 501 case algorithm_type_t::TAKEAWAY_MEMBER_CLASSIFICATION: {
318 502 algor_config_param_takeaway_member_classification *algor_param =
... ... @@ -373,6 +557,15 @@ void task_param_manager::delete_task_param(string task_id) {
373 557 }
374 558 }
375 559 m_task_params.erase(task_id);
  560 +
  561 + if (m_algor_config_params.count(task_id)) {
  562 + m_algor_config_params[task_id].human_face_algors.clear();
  563 + m_algor_config_params[task_id].human_algors.clear();
  564 + m_algor_config_params[task_id].nonmotor_vehicle_algors.clear();
  565 + m_algor_config_params[task_id].vehicle_algors.clear();
  566 + m_algor_config_params.erase(task_id);
  567 + }
  568 +
376 569 }
377 570  
378 571 void task_param_manager::task_param_manager_release() {
... ... @@ -419,3 +612,89 @@ map&lt;string, algor_open_config_param&gt; task_param_manager::get_task_algor_params()
419 612 map<string, map<algo_type, task_param_manager::algo_param_type_t_ *>> task_param_manager::get_task_other_params() {
420 613 return m_task_params;
421 614 }
  615 +
  616 +bool task_param_manager::task_has_vpt_algor(const std::string &task_id) {
  617 + auto algor_map = get_task_other_param(task_id);
  618 + if (algor_map == nullptr)
  619 + return false;
  620 +
  621 + return (algor_map->find(algorithm_type_t::HUMAN_GATHER) != algor_map->end() ||
  622 + algor_map->find(algorithm_type_t::HUMAN_SNAPSHOT) != algor_map->end() ||
  623 + algor_map->find(algorithm_type_t::VEHICLE_GATHER) != algor_map->end() ||
  624 + algor_map->find(algorithm_type_t::HUMAN_CROSSING_LINE) != algor_map->end() ||
  625 + algor_map->find(algorithm_type_t::HUMAN_DENSITY) != algor_map->end() ||
  626 + algor_map->find(algorithm_type_t::HUMAN_CLIMB) != algor_map->end() ||
  627 + algor_map->find(algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE) != algor_map->end() ||
  628 + algor_map->find(algorithm_type_t::HUMAN_LINGER) != algor_map->end() ||
  629 + algor_map->find(algorithm_type_t::VEHICLE_ILLEGAL_PARKING) != algor_map->end() ||
  630 + algor_map->find(algorithm_type_t::HUMAN_REGION_GATHER) != algor_map->end() ||
  631 + algor_map->find(algorithm_type_t::HUMAN_LEAVE_REGION) != algor_map->end() ||
  632 + algor_map->find(algorithm_type_t::HUMAN_REGION_DISMISS) != algor_map->end() ||
  633 + algor_map->find(algorithm_type_t::HUMAN_REGION_FAST_MOVING) != algor_map->end() ||
  634 + algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT) != algor_map->end() ||
  635 + algor_map->find(algorithm_type_t::SMOKING_DET) != algor_map->end() ||
  636 + algor_map->find(algorithm_type_t::NO_REFLECTIVE_CLOTHING) != algor_map->end() ||
  637 + algor_map->find(algorithm_type_t::NO_SAFETY_HELMET) != algor_map->end() ||
  638 + algor_map->find(algorithm_type_t::CALL_PHONE_DET) != algor_map->end() ||
  639 + algor_map->find(algorithm_type_t::VEHICLE_SNAPSHOT) != algor_map->end() ||
  640 + algor_map->find(algorithm_type_t::TAKEAWAY_MEMBER_CLASSIFICATION) != algor_map->end() ||
  641 + algor_map->find(algorithm_type_t::PEDESTRIAN_FALL) != algor_map->end() ||
  642 + algor_map->find(algorithm_type_t::PEDESTRIAN_FIGHT) != algor_map->end() ||
  643 + algor_map->find(algorithm_type_t::PEDESTRIAN_RETROGRADE) != algor_map->end() ||
  644 + algor_map->find(algorithm_type_t::VEHICLE_RETROGRADE) != algor_map->end() ||
  645 + algor_map->find(algorithm_type_t::PEDESTRIAN_TRESPASS) != algor_map->end() ||
  646 + algor_map->find(algorithm_type_t::VEHICLE_TRESPASS) != algor_map->end() ||
  647 + algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET) != algor_map->end() ||
  648 + algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN) != algor_map->end() ||
  649 + algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != algor_map->end() ||
  650 + algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) != algor_map->end() ||
  651 + algor_map->find(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) != algor_map->end() ||
  652 + algor_map->find(algorithm_type_t::NONMOTOR_CEOSSPARKLINE) != algor_map->end() ||
  653 + algor_map->find(algorithm_type_t::NONMOTOR_IN_VEHICLELANE) != algor_map->end() ||
  654 + algor_map->find(algorithm_type_t::NONMOTOR_WRONGDIRECTION) != algor_map->end() ||
  655 + algor_map->find(algorithm_type_t::PERSON_IN_VEHICLELANE) != algor_map->end() ||
  656 + algor_map->find(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) != algor_map->end() ||
  657 + algor_map->find(algorithm_type_t::PERSON_CROSS) != algor_map->end() ||
  658 + algor_map->find(algorithm_type_t::VEHICLE_WRONGDIRECTION) != algor_map->end() ||
  659 + algor_map->find(algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) != algor_map->end() ||
  660 + algor_map->find(algorithm_type_t::VEHICLE_NOTGIVEWAY) != algor_map->end() ||
  661 + algor_map->find(algorithm_type_t::VEHICLE_NOTDECELERATION) != algor_map->end() ||
  662 + algor_map->find(algorithm_type_t::TRICYCLE_MANNED) != algor_map->end() ||
  663 + algor_map->find(algorithm_type_t::TRUCK_MANNED) != algor_map->end());
  664 +}
  665 +
  666 +bool task_param_manager::task_has_face_algor(const std::string &task_id) {
  667 + auto algor_map = get_task_other_param(task_id);
  668 + if (nullptr != algor_map){
  669 + return algor_map->find(algorithm_type_t::FACE_SNAPSHOT) != algor_map->end();
  670 + }
  671 +
  672 + return false;
  673 +}
  674 +
  675 +int task_param_manager::get_video_timing_snapshot_interval(std::string& task_id) {
  676 + auto algor_map = get_task_other_param(task_id);
  677 + if (algor_map != nullptr) {
  678 +
  679 + // 设置定时截图的时间间隔
  680 + auto algor = algor_map->find(algorithm_type_t::VIDEO_TIMING_SNAPSHOT);
  681 + if(algor != algor_map->end()){
  682 + task_param_manager::algo_param_type_t_* cur_task_params = algor->second;
  683 + if(cur_task_params){
  684 + int frame_stride = ((algor_config_video_timing_snapshot*)cur_task_params->algor_param)->frame_stride;
  685 + LOG_INFO("task {} snap time interval: {} s", task_id, frame_stride);
  686 + // 单位是ms, 乘以 1000 编成s
  687 + return frame_stride * 1000;
  688 + }
  689 + }
  690 +
  691 + // 测试代码
  692 + // auto algor_face = algor_map->find(algorithm_type_t::FACE_SNAPSHOT);
  693 + // if(algor_face != algor_map->end()){
  694 + // const algor_basic_config_param_t *cur_param = ((algor_init_config_param_t *)(algor_face->second))->basic_param;
  695 + // LOG_INFO("face_snapshot, result_folder: {} result_folder_little: {}", cur_param->result_folder, cur_param->result_folder_little);
  696 + // }
  697 + }
  698 +
  699 + return -1;
  700 +}
422 701 \ No newline at end of file
... ...
src/ai_platform/task_param_manager.h
... ... @@ -43,6 +43,11 @@ public:
43 43 map<string, map<algo_type, algo_param_type_t_*>> get_task_other_params();
44 44 void task_param_manager_release();
45 45  
  46 + bool task_has_vpt_algor(const std::string &task_id);
  47 + bool task_has_face_algor(const std::string &task_id);
  48 +
  49 + int get_video_timing_snapshot_interval(std::string& task_id);
  50 +
46 51 private:
47 52 task_param_manager();
48 53 task_param_manager(const task_param_manager& other);
... ...
src/decoder/dvpp/DvppDataMemory.hpp
  1 +#ifndef __DVPP_DATA_MEMORY_HPP__
  2 +#define __DVPP_DATA_MEMORY_HPP__
  3 +
1 4 #include<string>
2 5  
  6 +#include "depend_headers.h"
3 7 #include "dvpp_headers.h"
4 8  
5 9 using namespace std;
6 10  
  11 +// static int snap_free = 0;
  12 +
7 13 class DvppDataMemory : public DeviceMemory
8 14 {
9 15 public:
10   - DvppDataMemory(int _channel, int _width, int _width_stride, int _height, int _height_stride, int _size, string _id, string _dev_id, bool _key_frame)
11   - :DeviceMemory(_channel, _width, _width_stride, _height, _height_stride, _id, _dev_id, _key_frame, false){
  16 + DvppDataMemory(int _channel, int _width, int _width_stride, int _height, int _height_stride, int _size, string _id, string _dev_id, bool _key_frame, unsigned long long frame_nb)
  17 + :DeviceMemory(_channel, _width, _width_stride, _height, _height_stride, _id, _dev_id, _key_frame, frame_nb, false){
12 18 data_size = _size;
  19 + data_type = 1;
13 20 int ret = acldvppMalloc((void **)&pHwRgb, data_size);
14 21 if(ret != ACL_ERROR_NONE){
15   - cout << "acldvppMalloc failed" << endl;
  22 + LOG_ERROR("[{}]- acldvppMalloc failed", id);
16 23 }
17 24 }
18 25  
19   - DvppDataMemory( int _width, int _width_stride, int _height, int _height_stride, int _size, string _id, string _dev_id, bool _key_frame, unsigned char * pHwData)
20   - :DeviceMemory(3, _width, _width_stride, _height, _height_stride, _id, _dev_id, _key_frame, false){
  26 + DvppDataMemory( int _width, int _width_stride, int _height, int _height_stride, int _size, string _id, string _dev_id, bool _key_frame, unsigned long long frame_nb, unsigned char * pHwData)
  27 + :DeviceMemory(-1, _width, _width_stride, _height, _height_stride, _id, _dev_id, _key_frame, frame_nb, false){
21 28 data_size = _size;
22 29 data_type = 1;
23 30 pHwRgb = pHwData;
24 31 }
25 32  
  33 + DvppDataMemory(DvppDataMemory* pSrc):DeviceMemory(-1, pSrc->getWidth(), pSrc->getWidthStride(), pSrc->getHeight(), pSrc->getHeightStride(), pSrc->getId(), pSrc->getDeviceId(), pSrc->isKeyFrame(), pSrc->getFrameNb(), false){
  34 + if(pSrc == nullptr) {
  35 + LOG_ERROR("[{}]- pSrc is nullptr", pSrc->getId());
  36 + return;
  37 + }
  38 +
  39 + data_size = pSrc->getSize();
  40 + int ret = acldvppMalloc((void **)&pHwRgb, data_size);
  41 + if(ret != ACL_ERROR_NONE){
  42 + LOG_ERROR("[{}]- acldvppMalloc failed", pSrc->getId());
  43 + return;
  44 + }
  45 +
  46 + ret = aclrtMemcpy(pHwRgb, data_size, pSrc->getMem(), pSrc->getSize(), ACL_MEMCPY_DEVICE_TO_DEVICE);
  47 + if(ret != ACL_ERROR_NONE){
  48 + acldvppFree(pHwRgb);
  49 + LOG_ERROR("[{}]- aclrtMemcpy failed", pSrc->getId());
  50 + return;
  51 + }
  52 +
  53 + data_type = 2;
  54 + timestamp = UtilTools::get_cur_time_ms();
  55 + }
  56 +
26 57 ~DvppDataMemory(){
  58 + // if (data_type == 2)
  59 + // {
  60 + // snap_free++;
  61 + // LOG_INFO("[{}]- snap_free: {}", getId(), snap_free);
  62 + // }
27 63 if (pHwRgb) {
28   - int ret = acldvppFree((uint8_t*)pHwRgb);
  64 + int ret = acldvppFree(pHwRgb);
29 65 if(ret != ACL_ERROR_NONE){
30   - cout << "acldvppFree failed" << endl;
  66 + LOG_ERROR("[{}]- acldvppFree failed", id);
31 67 }
32 68 pHwRgb = nullptr;
33 69 }
... ... @@ -35,4 +71,7 @@ public:
35 71  
36 72 public:
37 73 int data_type; // 0: rgb , 1: NV12
38   -};
39 74 \ No newline at end of file
  75 +};
  76 +
  77 +
  78 +#endif // __DVPP_DATA_MEMORY_HPP__
40 79 \ No newline at end of file
... ...
src/decoder/dvpp/DvppDecoder.cpp
... ... @@ -2,26 +2,83 @@
2 2 #include "DvppSourceManager.h"
3 3  
4 4  
  5 +#define CHECK_AND_RETURN(ret, message) \
  6 + if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); return ret;}
  7 +#define CHECK_NOT_RETURN(ret, message) \
  8 + if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message);}
  9 +#define CHECK_AND_RETURN_NOVALUE(ret, message) \
  10 + if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); return;}
  11 +#define CHECK_AND_BREAK(ret, message) \
  12 + if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); break;}
  13 +
  14 +
  15 +
  16 +
5 17 struct Vdec_CallBack_UserData {
6 18 uint64_t frameId;
  19 + uint64_t frame_nb;
7 20 long startTime;
8 21 long sendTime;
9   - // void* vdecOutputBuf;
10 22 DvppDecoder* self;
  23 +
11 24 Vdec_CallBack_UserData() {
12 25 frameId = 0;
  26 + frame_nb = 0;
13 27 }
14 28 };
15 29  
  30 +
  31 +static long get_cur_time_ms() {
  32 + chrono::time_point<chrono::system_clock, chrono::milliseconds> tpMicro
  33 + = chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now());
  34 + return tpMicro.time_since_epoch().count();
  35 +}
  36 +
  37 +static void *ReportThd(void *arg)
  38 +{
  39 + DvppDecoder *self = (DvppDecoder *)arg;
  40 + if(nullptr != self){
  41 + self->doProcessReport();
  42 + }
  43 + return (void *)0;
  44 +}
  45 +
  46 +static void VdecCallback(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData)
  47 +{
  48 + Vdec_CallBack_UserData *userData = (Vdec_CallBack_UserData *) pUserData;
  49 + if(nullptr != userData){
  50 + DvppDecoder* self = userData->self;
  51 + if(self != nullptr){
  52 + self->doVdppVdecCallBack(input, output, userData);
  53 + }
  54 + delete userData;
  55 + userData = nullptr;
  56 + }
  57 +}
  58 +
  59 +static int AVInterruptCallBackFun(void *param)
  60 +{
  61 + DvppDecoder *pDecoder = (DvppDecoder*)param;
  62 + if (nullptr == pDecoder) return 0;
  63 +
  64 + long long cur_ts = get_cur_time_ms();
  65 + long time_gap = cur_ts - pDecoder->get_last_read_ts();
  66 + if (time_gap > 1000*30) {
  67 + LOG_WARN("摄像头异常,释放阻塞");
  68 + //通知FFMpeg可以从阻塞工作线程中释放操作
  69 + return 1;
  70 + } else {
  71 + //通知FFMpeg继续阻塞工作
  72 + return 0;
  73 + }
  74 +}
  75 +
16 76 DvppDecoder::DvppDecoder(){
17   - m_read_thread = 0;
18   - m_decode_thread = 0;
19   - m_cached_mem = nullptr;
  77 + m_read_thread = nullptr;
20 78  
21 79 fmt_ctx = nullptr;
22 80 m_bRunning = false;
23 81  
24   - stream = nullptr;
25 82 video_index = -1;
26 83 pix_fmt = AV_PIX_FMT_NONE;
27 84 m_dec_name = "";
... ... @@ -32,72 +89,84 @@ DvppDecoder::DvppDecoder(){
32 89 m_bFinished = false;
33 90 m_dec_keyframe = false;
34 91 m_fps = 0.0;
35   -
36   - m_bSnapShoting = false;
37 92 }
38 93  
39 94 DvppDecoder::~DvppDecoder(){
  95 + close();
  96 +
  97 + LOG_DEBUG("[{}]- ~DvppDecoder() in_count:{} out_count:{}", m_dec_name, m_in_count, m_out_count);
40 98 }
41 99  
42 100 bool DvppDecoder::init(FFDecConfig cfg){
43 101  
44 102 m_dec_name = cfg.dec_name;
  103 + m_frameSkip = cfg.skip_frame;
45 104  
46 105 AVCodecContext* avctx = init_FFmpeg(cfg);
47 106 if(avctx == nullptr){
48 107 return false;
49 108 }
50 109  
51   - bool bRet = init_vdpp(cfg, avctx);
52   - if(!bRet){
53   - return false;
54   - }
  110 + do
  111 + {
  112 + bool bRet = init_dvpp(cfg);
  113 + if(!bRet){
  114 + break;
  115 + }
55 116  
56   - m_cfg = cfg;
  117 + m_cfg = cfg;
57 118  
58   - decode_finished_cbk = cfg.decode_finished_cbk;
  119 + decode_finished_cbk = cfg.decode_finished_cbk;
59 120  
60   - m_bFinished = false;
  121 + m_bFinished = false;
61 122  
62   - return true;
  123 + return true;
  124 + } while (0);
  125 +
  126 + release_ffmpeg();
  127 +
  128 + return false;
63 129 }
64 130  
65 131 AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
66 132  
67   -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
68   - av_register_all();
69   -#endif
70   -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 10, 100)
71   - avcodec_register_all();
72   -#endif
73   -
74   - avformat_network_init();
75   -
76   - const char* uri = config.uri.c_str();
77   - fstream infile(uri);
78   - if (infile.is_open()){
79   - m_bReal = false;
80   - infile.close();
81   - } else {
82   - m_bReal = true;
83   - }
  133 + const char* input_file = config.uri.c_str();
84 134  
85 135 // 打开输入视频文件
86 136 AVDictionary *options = nullptr;
87 137 av_dict_set( &options, "bufsize", "655360", 0 );
88 138 av_dict_set( &options, "rtsp_transport", config.force_tcp ? "tcp" : "udp", 0 );
89 139 av_dict_set( &options, "stimeout", "30000000", 0 ); // 单位为 百万分之一秒
90   -
91   - const char* input_file = uri;
  140 + av_dict_set( &options, "max_delay", "500000", 0); //设置最大时延
92 141  
93 142 do{
94 143 fmt_ctx = avformat_alloc_context();
  144 + // fmt_ctx->flags |= AVFMT_FLAG_NONBLOCK;
95 145 if (avformat_open_input(&fmt_ctx, input_file, nullptr, &options) != 0) {
96 146 LOG_ERROR("[{}]- Cannot open input file: {}", m_dec_name, input_file);
97 147 break;
98 148 }
99 149 av_dump_format(fmt_ctx, 0, input_file, 0);
100 150  
  151 + FILE* infile = fopen(input_file, "r");
  152 + if(nullptr != infile) {
  153 + // 可以作为本地文件打开,那必然是文件
  154 + m_bReal = false;
  155 + fclose(infile);
  156 + infile = nullptr;
  157 + } else {
  158 + // http://xxxx/xxx.mp4 也与文件同
  159 + if (fmt_ctx->iformat && fmt_ctx->iformat->extensions) {
  160 + m_bReal = false;
  161 + } else {
  162 + m_bReal = true;
  163 +
  164 + fmt_ctx->interrupt_callback.callback = AVInterruptCallBackFun;
  165 + fmt_ctx->interrupt_callback.opaque = this;
  166 + m_last_read_ts = get_cur_time_ms();
  167 + }
  168 + }
  169 +
101 170 // 查找流信息
102 171 if (avformat_find_stream_info(fmt_ctx, nullptr) < 0) {
103 172 LOG_ERROR("[{}]- Cannot find input stream information!", m_dec_name);
... ... @@ -111,9 +180,8 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
111 180 LOG_ERROR("[{}]- Cannot find a video stream in the input file!", m_dec_name);
112 181 break;
113 182 }
114   - AVCodec *vcodec = avcodec_find_decoder(decoder->id);
115 183  
116   - avctx = avcodec_alloc_context3(vcodec);
  184 + avctx = avcodec_alloc_context3(decoder);
117 185 if(avctx == nullptr){
118 186 LOG_ERROR("[{}]- alloc AVCodecContext failed!", m_dec_name);
119 187 break;
... ... @@ -125,6 +193,12 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
125 193 if (avcodec_parameters_to_context(avctx, codecpar) < 0)
126 194 break;
127 195  
  196 + int enType = getVdecType(codecpar->codec_id, codecpar->profile);
  197 + if(-1 == enType) {
  198 + break;
  199 + }
  200 + m_enType = static_cast<acldvppStreamFormat>(enType);
  201 +
128 202 const AVBitStreamFilter * filter = nullptr;
129 203 if(codecpar->codec_id == AV_CODEC_ID_H264){
130 204 filter = av_bsf_get_by_name("h264_mp4toannexb");
... ... @@ -146,9 +220,25 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
146 220 frame_width = codecpar->width;
147 221 frame_height = codecpar->height;
148 222 pix_fmt = (AVPixelFormat)codecpar->format;
149   - m_fps = av_q2d(stream ->avg_frame_rate);
150 223  
151   - LOG_INFO("[{}]- init ffmpeg success! input:{} frame_width:{} frame_height:{} fps:{} ", m_dec_name, input_file, frame_width, frame_height, m_fps);
  224 + m_bResize = config.resize;
  225 + calcOutResolution(frame_width, frame_height);
  226 +
  227 + if (stream->avg_frame_rate.den) {
  228 + m_fps = av_q2d(stream ->avg_frame_rate);
  229 + } else {
  230 + m_fps = 0.0;
  231 + }
  232 +
  233 + m_vdec_out_size = frame_width * frame_height * 3 / 2;
  234 +
  235 + if (avctx->gop_size > 0) {
  236 + m_cache_gop = avctx->gop_size + 1;
  237 + } else {
  238 + m_cache_gop = 20;
  239 + }
  240 +
  241 + LOG_INFO("[{}]- init ffmpeg success! input:{} src:({}, {}) out:({}, {}) fps:{} ", m_dec_name, input_file, frame_width, frame_height, out_frame_width, out_frame_height, m_fps);
152 242  
153 243 return avctx;
154 244 }while(0);
... ... @@ -160,42 +250,85 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
160 250 return nullptr;
161 251 }
162 252  
163   - bool DvppDecoder::init_vdpp(FFDecConfig cfg, AVCodecContext* avctx) {
  253 +void DvppDecoder::calcOutResolution(int width, int height) {
  254 + if(m_bResize) {
  255 + float srcRatio = width / (float)height;
  256 + float stdRatio = 1920.0 / 1080.0f ;
  257 + int outWidth = 1920;
  258 + int outHeight = 1080;
  259 + if (srcRatio > stdRatio) {
  260 + outHeight = static_cast<int>(outWidth * (float)height / width) ;
  261 + if (outHeight % 2 == 1) {
  262 + outHeight += 1;
  263 + }
  264 + } else if (srcRatio < stdRatio) {
  265 + outWidth = static_cast<int>(outHeight * (float)width / height) ;
  266 + if (outWidth % 2 == 1) {
  267 + outWidth += 1;
  268 + }
  269 + }
164 270  
165   - LOG_INFO("[{}]- Init device start...", m_dec_name);
  271 + out_frame_width = outWidth;
  272 + out_frame_height = outHeight;
  273 + } else {
  274 + out_frame_width = width;
  275 + out_frame_height = height;
  276 + }
  277 +}
166 278  
167   - m_dvpp_deviceId = atoi(cfg.gpuid.c_str());
168   -
169   - if(avctx->codec_id == AV_CODEC_ID_H264){
170   - // 66:Baseline,77:Main,>=100:High
171   - if(avctx->profile == 77){
172   - enType = H264_MAIN_LEVEL;
173   - }else if(avctx->profile < 77){
174   - enType = H264_BASELINE_LEVEL;
175   - }else{
176   - enType = H264_HIGH_LEVEL;
  279 +int DvppDecoder::getVdecType(int videoType, int profile)
  280 +{
  281 + int streamFormat = H264_MAIN_LEVEL;
  282 +
  283 + // VDEC only support H265 main level,264 baseline level,main level,high level
  284 + if (videoType == AV_CODEC_ID_HEVC) {
  285 + streamFormat = H265_MAIN_LEVEL;
  286 + } else if (videoType == AV_CODEC_ID_H264) {
  287 + switch (profile) {
  288 + case FF_PROFILE_H264_BASELINE:
  289 + streamFormat = H264_BASELINE_LEVEL;
  290 + break;
  291 + case FF_PROFILE_H264_MAIN:
  292 + streamFormat = H264_MAIN_LEVEL;
  293 + break;
  294 + case FF_PROFILE_H264_HIGH:
  295 + case FF_PROFILE_H264_HIGH_10:
  296 + case FF_PROFILE_H264_HIGH_10_INTRA:
  297 + case FF_PROFILE_H264_MULTIVIEW_HIGH:
  298 + case FF_PROFILE_H264_HIGH_422:
  299 + case FF_PROFILE_H264_HIGH_422_INTRA:
  300 + case FF_PROFILE_H264_STEREO_HIGH:
  301 + case FF_PROFILE_H264_HIGH_444:
  302 + case FF_PROFILE_H264_HIGH_444_PREDICTIVE:
  303 + case FF_PROFILE_H264_HIGH_444_INTRA:
  304 + streamFormat = H264_HIGH_LEVEL;
  305 + break;
  306 + default:
  307 + LOG_INFO("Not support h264 profile {}, use as mp", profile);
  308 + streamFormat = H264_MAIN_LEVEL;
  309 + break;
177 310 }
178   - }else if(avctx->codec_id == AV_CODEC_ID_HEVC){
179   - // h265只有main
180   - enType = H265_MAIN_LEVEL;
181   - }else {
182   - LOG_ERROR("[{}]- codec_id is not supported!", m_dec_name);
183   - return false;
  311 + } else {
  312 + streamFormat = -1;
  313 + LOG_ERROR("Not support stream, type {}, profile {}", videoType, profile);
184 314 }
185 315  
  316 + return streamFormat;
  317 +}
  318 +
  319 + bool DvppDecoder::init_dvpp(FFDecConfig cfg) {
  320 +
  321 + LOG_INFO("[{}]- Init device start...", m_dec_name);
  322 +
  323 + m_dvpp_deviceId = atoi(cfg.gpuid.c_str());
  324 +
186 325 post_decoded_cbk = cfg.post_decoded_cbk;
187 326  
188 327 do{
189   - aclError ret = aclrtSetDevice(m_dvpp_deviceId);
190   - if(ret != ACL_ERROR_NONE){
191   - LOG_ERROR("[{}]-aclrtSetDevice failed !", m_dec_name);
192   - return false;
193   - }
194   -
195   - ret = aclrtCreateContext(&m_context, m_dvpp_deviceId);
  328 + aclError ret = aclrtCreateContext(&m_context, m_dvpp_deviceId);
196 329 if (ret != ACL_ERROR_NONE) {
197 330 LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name);
198   - return false;
  331 + break;
199 332 }
200 333  
201 334 // DvppSourceManager 创建时包含 aclInit,析构时包含 aclFinalize
... ... @@ -203,9 +336,10 @@ AVCodecContext* DvppDecoder::init_FFmpeg(FFDecConfig config){
203 336 m_dvpp_channel = pSrcMgr->getChannel(m_dvpp_deviceId);
204 337 if(m_dvpp_channel < 0){
205 338 LOG_ERROR("[{}]-该设备channel已经用完了!", m_dec_name);
206   - return false;
  339 + break;
207 340 }
208   - m_vdec_out_size = avctx->width * avctx->height * 3 / 2;
  341 +
  342 + m_vpcUtils.init(m_dvpp_deviceId);
209 343  
210 344 LOG_INFO("[{}]- init vdpp success! device:{} channel:{}", m_dec_name, m_dvpp_deviceId, m_dvpp_channel);
211 345 return true;
... ... @@ -223,14 +357,12 @@ bool DvppDecoder::isSurport(FFDecConfig&amp; cfg){
223 357 bool DvppDecoder::start(){
224 358 m_bRunning = true;
225 359  
226   - pthread_create(&m_read_thread,0,
227   - [](void* arg)
  360 + m_read_thread = new std::thread([](void* arg)
228 361 {
229 362 DvppDecoder* a=(DvppDecoder*)arg;
230 363 a->read_thread();
231 364 return (void*)0;
232   - }
233   - ,this);
  365 + }, this);
234 366  
235 367 return true;
236 368 }
... ... @@ -238,8 +370,10 @@ bool DvppDecoder::start(){
238 370 void DvppDecoder::close(){
239 371 m_bRunning=false;
240 372  
241   - if(m_read_thread != 0){
242   - pthread_join(m_read_thread,0);
  373 + if(m_read_thread != nullptr){
  374 + m_read_thread->join();
  375 + delete m_read_thread;
  376 + m_read_thread = nullptr;
243 377 }
244 378 }
245 379  
... ... @@ -281,24 +415,56 @@ bool DvppDecoder::getResolution(int &amp;width, int &amp;height){
281 415 return true;
282 416 }
283 417  
  418 +bool DvppDecoder::getOutResolution( int &width, int &height ) {
  419 + width = out_frame_width;
  420 + height = out_frame_height;
  421 + return true;
  422 +}
  423 +
284 424 float DvppDecoder::fps(){
285 425 return m_fps;
286 426 }
287 427  
  428 +long long DvppDecoder::get_last_read_ts() {
  429 + return m_last_read_ts;
  430 +}
  431 +
  432 +static int snap_count = 0;
  433 +
288 434 DeviceMemory* DvppDecoder::snapshot(){
289   - // 注意内部有锁
290   - // 开始抓拍
291   - m_bSnapShoting = true;
292 435  
293   - std::unique_lock<std::mutex> locker(m_cached_mutex);
294   - while (m_cached_mem == nullptr)
295   - m_cached_cond.wait_for(locker, std::chrono::milliseconds(400)); // Unlock mutex and wait to be notified
296   - locker.unlock();
  436 + int ret = aclrtSetCurrentContext(m_context);
  437 + if(ret != ACL_ERROR_NONE){
  438 + LOG_ERROR("[{}]- aclrtSetCurrentContext failed", m_dec_name);
  439 + return nullptr;
  440 + }
  441 +
  442 + // 注意有锁
  443 + DeviceMemory* snapshot_mem = nullptr;
  444 + int loop_times = 0;
  445 + while(m_bRunning) {
  446 + m_decoded_data_queue_mtx.lock();
  447 + if(m_decoded_data_queue.size() <= 0) {
  448 + m_decoded_data_queue_mtx.unlock();
  449 + loop_times++;
  450 + if(loop_times > 100) {
  451 + // 1s都没截取到图,退出
  452 + break;
  453 + }
  454 + std::this_thread::sleep_for(std::chrono::milliseconds(10));
  455 + continue;
  456 + }
  457 +
  458 + DvppDataMemory* mem = m_decoded_data_queue.front();
  459 + snapshot_mem = new DvppDataMemory(mem);
  460 + m_decoded_data_queue_mtx.unlock();
297 461  
298   - DeviceMemory* mem = m_cached_mem;
299   - m_cached_mem = nullptr;
  462 + // snap_count++;
  463 + // LOG_INFO("[{}]- snap_count:{} ", m_dec_name, snap_count);
  464 + break;
  465 + }
300 466  
301   - return mem;
  467 + return snapshot_mem;
302 468 }
303 469  
304 470 int DvppDecoder::getCachedQueueLength(){
... ... @@ -311,465 +477,204 @@ void DvppDecoder::release_ffmpeg() {
311 477 av_bsf_free(&h264bsfc);
312 478 h264bsfc = nullptr;
313 479 }
314   - if (fmt_ctx){
315   - avformat_close_input(&fmt_ctx);
316   - fmt_ctx = nullptr;
317   - }
318 480 if(avctx){
319 481 avcodec_free_context(&avctx);
320 482 avctx = nullptr;
321 483 }
  484 + if (fmt_ctx){
  485 + avformat_close_input(&fmt_ctx);
  486 + fmt_ctx = nullptr;
  487 + }
  488 +
  489 + LOG_DEBUG("[{}]- release_ffmpeg", m_dec_name);
322 490 }
323 491  
324 492 void DvppDecoder::read_thread() {
325 493  
326   - int frame_count = 0;
327 494 int ret = -1;
328 495  
329   - pthread_create(&m_decode_thread,0,
  496 + m_bExitReportThd = false;
  497 + pthread_t report_thread;
  498 + ret = pthread_create(&report_thread, nullptr, ReportThd, (void *)this);
  499 + if(ret != 0){
  500 + LOG_ERROR("[{}]- pthread_create failed", m_dec_name);
  501 + return;
  502 + }
  503 +
  504 + m_bExitDisplayThd = false;
  505 + std::thread display_thread(
330 506 [](void* arg)
331 507 {
332 508 DvppDecoder* a=(DvppDecoder*)arg;
333   - a->decode_thread();
  509 + a->display_thread();
334 510 return (void*)0;
335   - }
336   - ,this);
337   -
338   - AVPacket* pkt = nullptr;
339   - while (m_bRunning){
340   -
341   - if (!m_bReal){
342   - if (m_bPause){
343   - std::this_thread::sleep_for(std::chrono::milliseconds(3));
344   - continue;
345   - }
346   - }
347   -
348   - m_pktQueue_mutex.lock();
349   - if(m_pktQueue.size() > 10){
350   - m_pktQueue_mutex.unlock();
351   - std::this_thread::sleep_for(std::chrono::milliseconds(5));
352   - continue;
353   - }
354   - m_pktQueue_mutex.unlock();
355   -
356   - pkt = av_packet_alloc();
357   - av_init_packet( pkt );
358   -
359   - int result = av_read_frame(fmt_ctx, pkt);
360   - if (result == AVERROR_EOF || result < 0){
361   - av_packet_free(&pkt);
362   - pkt = nullptr;
363   - LOG_ERROR("[{}]- Failed to read frame!", m_dec_name);
364   - break;
365   - }
366   -
367   - if (m_dec_keyframe && !(pkt->flags & AV_PKT_FLAG_KEY)) {
368   - av_packet_free(&pkt);
369   - pkt = nullptr;
370   - continue;
371   - }
372   -
373   - if (video_index == pkt->stream_index){
374   -
375   - ret = av_bsf_send_packet(h264bsfc, pkt);
376   - if(ret < 0) {
377   - LOG_ERROR("[{}]- av_bsf_send_packet error!", m_dec_name);
378   - av_packet_free(&pkt);
379   - pkt = nullptr;
380   - continue;
381   - }
382   -
383   - bool bPushed = false;
384   - while ((ret = av_bsf_receive_packet(h264bsfc, pkt)) == 0) {
385   - if(pkt->size > g_pkt_size){
386   - LOG_ERROR("[{}]- pkt size 大于最大预设值!", m_dec_name);
387   - break;
388   - }
389   -
390   - if(!m_bRunning){
391   - break;
392   - }
393   -
394   - m_pktQueue_mutex.lock();
395   - m_pktQueue.push(pkt);
396   - m_pktQueue_mutex.unlock();
397   -
398   - bPushed = true;
399   - frame_count++;
400   - }
401   -
402   - if(!bPushed){
403   - av_packet_free(&pkt);
404   - pkt = nullptr;
405   - }
406   - } else {
407   - // 音频等其他分量的情形
408   - av_packet_free(&pkt);
409   - pkt = nullptr;
410   - }
411   - }
412   -
413   - m_bRunning=false;
414   -
415   - if(m_decode_thread != 0){
416   - pthread_join(m_decode_thread,0);
417   - }
418   -
419   - m_pktQueue_mutex.lock();
420   - while(m_pktQueue.size() > 0){
421   - pkt = m_pktQueue.front();
422   - av_packet_free(&pkt);
423   - pkt = nullptr;
424   - m_pktQueue.pop();
425   - }
426   - m_pktQueue_mutex.unlock();
427   -
428   - decode_finished_cbk(m_finishedDecArg);
429   -
430   - LOG_INFO("[{}]- read thread exit.", m_dec_name);
431   - m_bFinished = true;
432   -}
433   -
434   -static void *ReportThd(void *arg)
435   -{
436   - DvppDecoder *self = (DvppDecoder *)arg;
437   - if(nullptr != self){
438   - self->doProcessReport();
439   - }
440   - return (void *)0;
441   -}
442   -
443   -void DvppDecoder::doProcessReport(){
444   -
445   - aclError ret = aclrtSetDevice(m_dvpp_deviceId);
446   - if(ret != ACL_ERROR_NONE){
447   - // cout << "aclrtSetDevice failed" << endl;
448   - LOG_ERROR("aclrtSetDevice failed !");
449   - return ;
450   - }
451   -
452   - aclrtContext ctx;
453   - ret = aclrtCreateContext(&ctx, m_dvpp_deviceId);
454   - if (ret != ACL_ERROR_NONE) {
455   - // cout << "aclrtCreateContext failed " << endl;
456   - LOG_ERROR("aclrtCreateContext failed !");
457   - return ;
458   - }
459   -
460   - CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(ctx), "aclrtSetCurrentContext failed");
461   - // 阻塞等待vdec线程开始
462   -
463   - while (!m_bExitReportThd) {
464   - aclrtProcessReport(1000);
465   - }
466   -
467   - ret = aclrtDestroyContext(ctx);
468   - if(ret != ACL_ERROR_NONE){
469   - LOG_ERROR("aclrtDestroyContext failed !");
470   - }
471   - LOG_INFO("doProcessReport exit.");
472   -}
473   -
474   -static void VdecCallback(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData)
475   -{
476   - Vdec_CallBack_UserData *userData = (Vdec_CallBack_UserData *) pUserData;
477   - if(nullptr != userData){
478   - DvppDecoder* self = userData->self;
479   - if(self != nullptr){
480   -
481   - self->doVdppVdecCallBack(input, output);
482   - }
483   - delete userData;
484   - userData = nullptr;
485   - }
486   -}
487   -
488   -void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output){
489   -
490   - m_vdecQueue_mutex.lock();
491   - if(m_vdecQueue.size() > 0){
492   - void* inputData = m_vdecQueue.front();
493   - acldvppFree(inputData);
494   - inputData = nullptr;
495   - m_vdecQueue.pop();
496   - }
497   - m_vdecQueue_mutex.unlock();
498   -
499   -
500   - CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed");
  511 + },
  512 + this
  513 + );
501 514  
502   - void *outputDataDev = acldvppGetPicDescData(output);
503   - uint32_t outputSize = acldvppGetPicDescSize(output);
504   - uint32_t width = acldvppGetPicDescWidth(output);
505   - uint32_t width_stride = acldvppGetPicDescWidthStride(output);
506   - uint32_t height = acldvppGetPicDescHeight(output);
507   - uint32_t height_stride = acldvppGetPicDescHeightStride(output);
  515 + aclvdecChannelDesc *vdecChannelDesc = nullptr;
508 516  
509   - do{
510   - int ret = acldvppGetPicDescRetCode(output);
  517 + do {
  518 + int ret = aclrtSetCurrentContext(m_context);
511 519 if(ret != ACL_ERROR_NONE){
512   - LOG_ERROR("[{}]- decode result error, retCode:{} ", m_dec_name, ret);
513   - acldvppFree(outputDataDev);
514   - outputDataDev = nullptr;
  520 + LOG_ERROR("[{}]- aclrtSetCurrentContext failed", m_dec_name);
515 521 break;
516 522 }
517 523  
518   - if(width > 0 && height > 0 && outputSize > 0){
519   - DvppDataMemory* mem = new DvppDataMemory(width, width_stride, height, height_stride, outputSize, m_dec_name, to_string(m_dvpp_deviceId), false, (unsigned char *)outputDataDev);
520   - if(mem){
521   - post_decoded_cbk(m_postDecArg, mem);
522   -
523   - if(m_bSnapShoting){
524   - // 缓存snapshot
525   - std::unique_lock<std::mutex> locker(m_cached_mutex);
526   -
527   - m_cached_mem = new DvppDataMemory(-1, width, width_stride, height, height_stride, outputSize, m_dec_name, to_string(m_dvpp_deviceId), false);
528   - if(m_cached_mem != nullptr){
529   - aclrtMemcpy(m_cached_mem->getMem(), outputSize, (unsigned char *)outputDataDev, outputSize, ACL_MEMCPY_DEVICE_TO_DEVICE);
530   - }
531   -
532   - locker.unlock();
533   - m_cached_cond.notify_one();
534   - m_bSnapShoting = false;
535   - }
536   - } else {
537   - LOG_ERROR("[{}]- DvppDataMemory 创建失败! ", m_dec_name, ret);
538   - acldvppFree(outputDataDev);
539   - outputDataDev = nullptr;
540   - }
541   -
542   - } else {
543   - LOG_WARN("[{}]- decode result error, width:{} width_stride:{} height:{} height_stride:{} size:{}", m_dec_name, width, width_stride, height, height_stride, outputSize);
544   - acldvppFree(outputDataDev);
545   - outputDataDev = nullptr;
  524 + vdecChannelDesc = aclvdecCreateChannelDesc();
  525 + if (vdecChannelDesc == nullptr) {
  526 + LOG_ERROR("[{}]- aclvdecCreateChannelDesc failed", m_dec_name);
  527 + break;
546 528 }
547   -
548   - // DvppDataMemory* rgbMem = picConverter.convert2bgr(output, width, height, false);
549   - // if(rgbMem != nullptr){
550   - // #ifdef TEST_DECODER
551   - // // D2H
552   - // if(vdecHostAddr == nullptr){
553   - // CHECK_NOT_RETURN(aclrtMallocHost(&vdecHostAddr, width * height * 3), "aclrtMallocHost failed");
554   - // }
555   - // uint32_t data_size = rgbMem->getSize();
556   - // CHECK_AND_RETURN_NOVALUE(aclrtMemcpy(vdecHostAddr, data_size, rgbMem->getMem(), data_size, ACL_MEMCPY_DEVICE_TO_HOST), "D2H aclrtMemcpy failed");
557   -
558   - // // 保存vdec结果
559   - // if(count_frame > 45 && count_frame < 50)
560   - // {
561   - // string file_name = "./yuv_pic/vdec_out_"+ m_dec_name +".rgb" ;
562   - // FILE *outputFile = fopen(file_name.c_str(), "a");
563   - // if(outputFile){
564   - // fwrite(vdecHostAddr, data_size, sizeof(char), outputFile);
565   - // fclose(outputFile);
566   - // }
567   - // }
568   - // else if(count_frame > 50 && vdecHostAddr != nullptr){
569   - // CHECK_NOT_RETURN(aclrtFreeHost(vdecHostAddr), "aclrtFreeHost failed");
570   - // vdecHostAddr = nullptr;
571   - // }
572   - // count_frame++;
573   - // #endif
574   - // post_decoded_cbk(m_postDecArg, rgbMem);
575   - // }else{
576   - // LOG_ERROR("[{}]- convert2bgr failed !", m_dec_name);
577   - // }
578   - }while(0);
579   -
580   - CHECK_AND_RETURN_NOVALUE(acldvppDestroyStreamDesc(input), "acldvppDestroyStreamDesc failed");
581   - CHECK_AND_RETURN_NOVALUE(acldvppDestroyPicDesc(output), "acldvppDestroyPicDesc failed");
582   -}
583   -
584   -void DvppDecoder::decode_thread(){
585   -
586   - long startTime = UtilTools::get_cur_time_ms();
587   -
588   - int ret = -1;
589   -
590   - m_bExitReportThd = false;
591   - pthread_t report_thread;
592   - ret = pthread_create(&report_thread, nullptr, ReportThd, (void *)this);
593   - if(ret != 0){
594   - LOG_ERROR("[{}]- pthread_create failed", m_dec_name);
595   - return;
596   - }
597 529  
598   - aclrtSetDevice(m_dvpp_deviceId);
599   - aclrtContext ctx;
600   - ret = aclrtCreateContext(&ctx, m_dvpp_deviceId);
601   - if (ret != ACL_ERROR_NONE) {
602   - // cout << "aclrtCreateContext failed " << endl;
603   - LOG_ERROR("aclrtCreateContext failed !");
604   - return ;
605   - }
606   -
607   - // 创建aclvdecChannelDesc类型的数据
608   - aclvdecChannelDesc *vdecChannelDesc = aclvdecCreateChannelDesc();
609   - if (vdecChannelDesc == nullptr) {
610   - LOG_ERROR("[{}]- aclvdecCreateChannelDesc failed", m_dec_name);
611   - return;
612   - }
613   - do{
614 530 // 创建 channel dec结构体
615 531 // 通道ID在dvpp层面为0~31
616 532 CHECK_AND_BREAK(aclvdecSetChannelDescChannelId(vdecChannelDesc, m_dvpp_channel), "aclvdecSetChannelDescChannelId failed");
617 533 CHECK_AND_BREAK(aclvdecSetChannelDescThreadId(vdecChannelDesc, report_thread), "aclvdecSetChannelDescThreadId failed");
618 534 CHECK_AND_BREAK(aclvdecSetChannelDescCallback(vdecChannelDesc, VdecCallback), "aclvdecSetChannelDescCallback failed");
619   - CHECK_AND_BREAK(aclvdecSetChannelDescEnType(vdecChannelDesc, enType), "aclvdecSetChannelDescEnType failed");
  535 + CHECK_AND_BREAK(aclvdecSetChannelDescEnType(vdecChannelDesc, m_enType), "aclvdecSetChannelDescEnType failed");
620 536 CHECK_AND_BREAK(aclvdecSetChannelDescOutPicFormat(vdecChannelDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420), "aclvdecSetChannelDescOutPicFormat failed");
621 537 CHECK_AND_BREAK(aclvdecCreateChannel(vdecChannelDesc), "aclvdecCreateChannel failed");
622 538  
623   - uint64_t frame_count = 0;
624   - bool bBreak = false;
625   - while (m_bRunning)
626   - {
627   - if (m_bPause){
628   - std::this_thread::sleep_for(std::chrono::milliseconds(3));
629   - continue;
630   - }
631   - int ret = sentFrame(vdecChannelDesc, frame_count);
632   - if(ret == 2){
633   - bBreak = true;
634   - break;
635   - }else if(ret == 1){
636   - continue;
637   - }
638   -
639   - frame_count++;
640   - }
  539 + unsigned long long frame_nb = 0;
  540 + AVPacket* pkt = av_packet_alloc();
  541 + av_init_packet( pkt );
  542 + while (m_bRunning){
641 543  
642   - // 尽量保证数据全部解码完成
643   - int sum = 0;
644   - if(!bBreak){
645   - aclrtSetDevice(m_dvpp_deviceId);
646   - aclrtSetCurrentContext(ctx);
647   - while(m_pktQueue.size() > 0){
648   - int ret = sentFrame(vdecChannelDesc, frame_count);
649   - if(ret == 2){
650   - break;
  544 + if (!m_bReal){
  545 + if (m_bPause){
  546 + std::this_thread::sleep_for(std::chrono::milliseconds(10));
  547 + continue;
651 548 }
652   - std::this_thread::sleep_for(std::chrono::milliseconds(3));
653   - sum++;
654   - if(sum > 40){
655   - // 避免卡死
656   - break;
  549 +
  550 + // 非实时流,即为文件情形,因为不存在花屏问题,为保证不丢帧,这里做个循环等待
  551 + m_decoded_data_queue_mtx.lock();
  552 + if(m_decoded_data_queue.size() > 5){
  553 + m_decoded_data_queue_mtx.unlock();
  554 + std::this_thread::sleep_for(std::chrono::milliseconds(5));
  555 + continue;
  556 + }
  557 + m_decoded_data_queue_mtx.unlock();
  558 +
  559 + if(m_DvppCacheCounter.load() > m_cache_gop) {
  560 + // 解码器解码不过来
  561 + std::this_thread::sleep_for(std::chrono::milliseconds(10));
  562 + continue;
657 563 }
  564 + } else {
  565 + m_last_read_ts = get_cur_time_ms();
658 566 }
659   - }
660   -
661   - sendVdecEos(vdecChannelDesc);
662 567  
663   - CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed");
664   - }while(0);
665   -
666   - CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed");
  568 + int result = av_read_frame(fmt_ctx, pkt);
  569 + if (result == AVERROR_EOF || result < 0){
  570 + av_packet_unref(pkt);
  571 + LOG_WARN("[{}]- Failed to read frame!", m_dec_name);
  572 + break;
  573 + }
667 574  
668   - // report_thread 需后于destroy退出
669   - m_bRunning = false;
670   - m_bExitReportThd = true;
671   - CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "pthread_join failed");
672   -
673   - // 最后清理一遍未解码的数据
674   - m_vdecQueue_mutex.lock();
675   - if(m_vdecQueue.size() > 0){
676   - void* inputData = m_vdecQueue.front();
677   - acldvppFree(inputData);
678   - inputData = nullptr;
679   - m_vdecQueue.pop();
680   - }
681   - m_vdecQueue_mutex.unlock();
  575 + if (m_bReal && m_DvppCacheCounter.load() > m_cache_gop){
  576 + // 解码器解码不过来。实时流在此处的处理会导致花屏,这是由于解码器性能问题导致,无法避免
  577 + // 实时流在这里处理是为了避免长时间不读取数据导致数据中断
  578 + av_packet_unref(pkt);
  579 + std::this_thread::sleep_for(std::chrono::milliseconds(10));
  580 + continue;
  581 + }
682 582  
683   - release_dvpp();
  583 + if (m_dec_keyframe && !(pkt->flags & AV_PKT_FLAG_KEY)) {
  584 + av_packet_unref(pkt);
  585 + continue;
  586 + }
684 587  
685   - ret = aclrtDestroyContext(ctx);
686   - if(ret != ACL_ERROR_NONE){
687   - LOG_ERROR("aclrtDestroyContext failed !");
688   - }
  588 + if (video_index == pkt->stream_index){
689 589  
690   - LOG_INFO("[{}]- decode thread exit.", m_dec_name);
691   -}
  590 + ret = av_bsf_send_packet(h264bsfc, pkt);
  591 + if(ret < 0) {
  592 + LOG_ERROR("[{}]- av_bsf_send_packet error!", m_dec_name);
  593 + av_packet_unref(pkt);
  594 + continue;
  595 + }
692 596  
693   -#include <fstream>
694   -#include <iostream>
695   -#include <cstring>
  597 + int nSended = -1;
  598 + while ((ret = av_bsf_receive_packet(h264bsfc, pkt)) == 0) {
  599 + if(!m_bRunning){
  600 + break;
  601 + }
  602 + nSended = sendPkt(vdecChannelDesc, pkt, frame_nb);
  603 + }
  604 + frame_nb++;
696 605  
697   -static int nRecoder = 0;
  606 + if(nSended < 0) {
  607 + // 执行出错,强行结束整个任务
  608 + m_bRunning=false;
  609 + break;
  610 + }
  611 + }
698 612  
  613 + av_packet_unref(pkt);
  614 + }
699 615  
  616 + av_packet_free(&pkt);
  617 + pkt = nullptr;
700 618  
701   -int DvppDecoder::sentFrame(aclvdecChannelDesc *vdecChannelDesc, uint64_t frame_count){
  619 + } while (0);
702 620  
703   - // 此处需要判断 m_vdecQueue 队列长度,避免占用过多显存
704   - m_vdecQueue_mutex.lock();
705   - if(m_vdecQueue.size() > 20){
706   - m_vdecQueue_mutex.unlock();
707   - std::this_thread::sleep_for(std::chrono::milliseconds(2));
708   - return 1;
709   - }
710   - m_vdecQueue_mutex.unlock();
  621 + if (vdecChannelDesc) {
  622 + sendVdecEos(vdecChannelDesc);
711 623  
712   - AVPacket * pkt = nullptr;
713   - m_pktQueue_mutex.lock();
714   - if(m_pktQueue.size() <= 0){
715   - m_pktQueue_mutex.unlock();
716   - std::this_thread::sleep_for(std::chrono::milliseconds(10));
717   - return 1;
  624 + CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed");
  625 + CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed");
  626 + vdecChannelDesc = nullptr;
718 627 }
719   - pkt = m_pktQueue.front();
720   - m_pktQueue.pop();
721   - m_pktQueue_mutex.unlock();
722   -
723   - // 解码
724   - void *vdecInputbuf = nullptr;
725   - int ret = acldvppMalloc((void **)&vdecInputbuf, g_pkt_size);
726   - if(ACL_ERROR_NONE != ret){
727   - LOG_ERROR("[{}]- acldvppMalloc failed!, ret:{}", m_dec_name, ret);
728   - av_packet_free(&pkt);
729   - pkt = nullptr;
730   - return 2;
  628 +
  629 + m_bExitReportThd = true;
  630 + CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "report_thread join failed");
  631 +
  632 + while(m_bRunning && m_decoded_data_queue.size() > 0) {
  633 + std::this_thread::sleep_for(std::chrono::milliseconds(5));
731 634 }
732 635  
733   - // std::ofstream outfile;
734   - // string file_name = "./pkt/pkt";
735   - // file_name = file_name + to_string(nRecoder) + ".bin";
736   - // outfile.open(file_name.c_str(), std::ios::binary | std::ios::app);
737   - // if (!outfile) {
738   - // std::cerr << "Failed to open file!" << std::endl;
739   - // return 2;
740   - // }
741   -
742   - // outfile.write((const char*)pkt->data, pkt->size);
743   - // outfile.close();
  636 + m_bRunning=false;
744 637  
745   - // nRecoder ++ ;
746   - // if(nRecoder >= 1000){
747   -
748   - // return 2;
749   - // }
  638 + m_bExitDisplayThd = true;
  639 + display_thread.join();
750 640  
  641 + release_ffmpeg();
  642 + release_dvpp();
751 643  
  644 + m_bFinished = true;
752 645  
753   - ret = aclrtMemcpy(vdecInputbuf, pkt->size, pkt->data, pkt->size, ACL_MEMCPY_HOST_TO_DEVICE);
754   - if(ACL_ERROR_NONE != ret){
755   - LOG_ERROR("[{}]- aclrtMemcpy failed", m_dec_name);
756   - av_packet_free(&pkt);
757   - pkt = nullptr;
758   - return 2;
759   - }
  646 + LOG_INFO("[{}]- read thread exit.", m_dec_name);
760 647  
761   - void *vdecOutputBuf = nullptr;
762   - ret = acldvppMalloc((void **)&vdecOutputBuf, m_vdec_out_size);
763   - if(ret != ACL_ERROR_NONE){
764   - LOG_ERROR("[{}]- acldvppMalloc failed", m_dec_name);
765   - av_packet_free(&pkt);
766   - pkt = nullptr;
767   - return 2;
  648 + if(decode_finished_cbk) {
  649 + decode_finished_cbk(m_finishedDecArg);
768 650 }
  651 +}
  652 +
  653 +int DvppDecoder::sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, unsigned long long frame_nb){
769 654  
  655 + void *vdecInputbuf = nullptr;
  656 + void *vdecOutputBuf = nullptr;
770 657 acldvppStreamDesc *input_stream_desc = nullptr;
771 658 acldvppPicDesc *output_pic_desc = nullptr;
772 659 do{
  660 + int ret = acldvppMalloc((void **)&vdecInputbuf, pkt->size);
  661 + if(ACL_ERROR_NONE != ret){
  662 + LOG_ERROR("[{}]- acldvppMalloc failed!, ret:{}", m_dec_name, ret);
  663 + break;
  664 + }
  665 +
  666 + ret = aclrtMemcpy(vdecInputbuf, pkt->size, pkt->data, pkt->size, ACL_MEMCPY_HOST_TO_DEVICE);
  667 + if(ACL_ERROR_NONE != ret){
  668 + LOG_ERROR("[{}]- aclrtMemcpy failed", m_dec_name);
  669 + break;
  670 + }
  671 +
  672 + ret = acldvppMalloc((void **)&vdecOutputBuf, m_vdec_out_size);
  673 + if(ret != ACL_ERROR_NONE){
  674 + LOG_ERROR("[{}]- acldvppMalloc failed", m_dec_name);
  675 + break;
  676 + }
  677 +
773 678 input_stream_desc = acldvppCreateStreamDesc();
774 679 if (input_stream_desc == nullptr) {
775 680 LOG_ERROR("[{}]- acldvppCreateStreamDesc failed", m_dec_name);
... ... @@ -784,49 +689,178 @@ int DvppDecoder::sentFrame(aclvdecChannelDesc *vdecChannelDesc, uint64_t frame_c
784 689 CHECK_AND_BREAK(acldvppSetStreamDescSize(input_stream_desc, pkt->size), "acldvppSetStreamDescSize failed");
785 690 CHECK_AND_BREAK(acldvppSetPicDescData(output_pic_desc, vdecOutputBuf), "acldvppSetPicDescData failed");
786 691 CHECK_AND_BREAK(acldvppSetPicDescSize(output_pic_desc, m_vdec_out_size), "acldvppSetPicDescSize failed");
  692 + CHECK_AND_BREAK(acldvppSetPicDescRetCode(output_pic_desc, 0), "acldvppSetPicDescRetCode failed");
787 693  
788 694 Vdec_CallBack_UserData *user_data = NULL;
789 695 user_data = new Vdec_CallBack_UserData;
790   - user_data->frameId = frame_count;
  696 + user_data->frameId = frame_nb;
  697 + user_data->frame_nb = frame_nb;
791 698 // user_data->startTime = startTime;
792 699 user_data->sendTime = UtilTools::get_cur_time_ms();
793 700 user_data->self = this;
  701 +
  702 + m_in_count++;
  703 +
  704 + // 内部缓存计数加1
  705 + m_DvppCacheCounter++;
794 706 ret = aclvdecSendFrame(vdecChannelDesc, input_stream_desc, output_pic_desc, nullptr, reinterpret_cast<void *>(user_data));
795   - av_packet_free(&pkt);
796   - pkt = nullptr;
797 707 if(ret != ACL_ERROR_NONE){
  708 + LOG_ERROR("[{}]- aclvdecSendFrame failed", m_dec_name);
798 709 delete user_data;
799 710 user_data = nullptr;
800   - LOG_ERROR("[{}]- aclvdecSendFrame failed", m_dec_name);
801   - break;
  711 + return -2;
802 712 }
803 713  
804   - m_vdecQueue_mutex.lock();
805   - m_vdecQueue.push(vdecInputbuf);
806   - m_vdecQueue_mutex.unlock();
807   -
808 714 return 0;
809 715 }while (0);
810 716  
811   - if(pkt != nullptr){
812   - av_packet_free(&pkt);
813   - pkt = nullptr;
  717 + if (vdecInputbuf){
  718 + acldvppFree(vdecInputbuf);
  719 + vdecInputbuf = nullptr;
814 720 }
815 721  
816 722 // 报错情形
817 723 if(input_stream_desc){
818 724 CHECK_NOT_RETURN(acldvppDestroyStreamDesc(input_stream_desc), "acldvppDestroyStreamDesc failed");
819 725 }
820   - if(output_pic_desc){
821   - CHECK_NOT_RETURN(acldvppDestroyPicDesc(output_pic_desc), "acldvppDestroyPicDesc failed");
822   - }
823 726  
824 727 if (vdecOutputBuf){
825 728 acldvppFree(vdecOutputBuf);
826 729 vdecOutputBuf = nullptr;
827 730 }
828 731  
829   - return 1;
  732 + if(output_pic_desc){
  733 + CHECK_NOT_RETURN(acldvppDestroyPicDesc(output_pic_desc), "acldvppDestroyPicDesc failed");
  734 + }
  735 +
  736 + return -1;
  737 +}
  738 +
  739 +void DvppDecoder::doProcessReport(){
  740 +
  741 + aclError ret = aclrtSetDevice(m_dvpp_deviceId);
  742 + if(ret != ACL_ERROR_NONE){
  743 + LOG_ERROR("[{}]-aclrtSetDevice failed !", m_dec_name);
  744 + return;
  745 + }
  746 +
  747 + while (!m_bExitReportThd) {
  748 + aclrtProcessReport(1000);
  749 + }
  750 +
  751 + ret = aclrtResetDevice(m_dvpp_deviceId);
  752 + if(ret != ACL_ERROR_NONE){
  753 + LOG_ERROR("aclrtDestroyContext failed !");
  754 + }
  755 + LOG_INFO("doProcessReport exit.");
  756 +}
  757 +
  758 +void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData){
  759 +
  760 + // 内部缓存计数减1
  761 + m_DvppCacheCounter--;
  762 +
  763 + CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed");
  764 +
  765 + void *inputDataDev = acldvppGetStreamDescData(input);
  766 + acldvppFree(inputDataDev);
  767 + inputDataDev = nullptr;
  768 +
  769 + if(nullptr == pUserData){
  770 + return;
  771 + }
  772 +
  773 + Vdec_CallBack_UserData *userData = (Vdec_CallBack_UserData *) pUserData;
  774 + uint64_t frame_nb = userData->frame_nb;
  775 +
  776 + m_out_count++;
  777 +
  778 + void *outputDataDev = acldvppGetPicDescData(output);
  779 + uint32_t outputSize = acldvppGetPicDescSize(output);
  780 + uint32_t width = acldvppGetPicDescWidth(output);
  781 + uint32_t width_stride = acldvppGetPicDescWidthStride(output);
  782 + uint32_t height = acldvppGetPicDescHeight(output);
  783 + uint32_t height_stride = acldvppGetPicDescHeightStride(output);
  784 +
  785 + do{
  786 + int ret = acldvppGetPicDescRetCode(output);
  787 + if(ret != ACL_ERROR_NONE){
  788 + LOG_ERROR("[{}]- decode result error, retCode:{} ", m_dec_name, ret);
  789 + acldvppFree(outputDataDev);
  790 + outputDataDev = nullptr;
  791 + break;
  792 + }
  793 +
  794 + if (m_bReal) {
  795 + // 实时流缓存长度大于25时做丢帧处理
  796 + m_decoded_data_queue_mtx.lock();
  797 + if(m_decoded_data_queue.size() >= 25){
  798 + m_decoded_data_queue_mtx.unlock();
  799 + LOG_WARN("[{}]- m_decoded_data_queue >= 25 ", m_dec_name);
  800 + acldvppFree(outputDataDev);
  801 + outputDataDev = nullptr;
  802 + break;
  803 + }
  804 + m_decoded_data_queue_mtx.unlock();
  805 + }
  806 +
  807 + bool bCached = false;
  808 + if(width > 0 && height > 0 && outputSize > 0){
  809 +
  810 + if (!m_bReal) {
  811 + while(!m_bExitReportThd) {
  812 + // 非实时流,即为文件情形,因为不存在花屏问题,为保证不丢帧,这里做个循环等待
  813 + m_decoded_data_queue_mtx.lock();
  814 + if(m_decoded_data_queue.size() >= 5){
  815 + m_decoded_data_queue_mtx.unlock();
  816 + std::this_thread::sleep_for(std::chrono::milliseconds(5));
  817 + continue;
  818 + }
  819 + m_decoded_data_queue_mtx.unlock();
  820 + break;
  821 + }
  822 + }
  823 +
  824 + // cout << m_dec_name << " 解码时间间隔: " << get_cur_time_ms() - last_ts << endl;
  825 + // last_ts = get_cur_time_ms();
  826 +
  827 + // 换成解码后数据, 这里这样做的是为了保证解码一直持续进行,避免后续操作阻碍文件读取和解码从而导致花屏
  828 + DvppDataMemory* mem = nullptr;
  829 + if (m_bResize && (width > 1920 || height > 1080)) {
  830 +
  831 + mem = m_vpcUtils.resize(output, out_frame_width, out_frame_height);
  832 + CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed");
  833 + if (mem) {
  834 + acldvppFree(outputDataDev);
  835 + outputDataDev = nullptr;
  836 +
  837 + mem->setDeviceId(to_string(m_dvpp_deviceId));
  838 + mem->setId(m_dec_name);
  839 + mem->setFrameNb(frame_nb);
  840 + }
  841 + } else {
  842 + mem = new DvppDataMemory(width, width_stride, height, height_stride, outputSize, m_dec_name, to_string(m_dvpp_deviceId), false, frame_nb, (unsigned char *)outputDataDev);
  843 + }
  844 +
  845 + if(mem){
  846 + m_decoded_data_queue.push(mem);
  847 + bCached = true;
  848 + } else {
  849 + // 逻辑完善
  850 + delete mem;
  851 + mem = nullptr;
  852 + }
  853 + }
  854 +
  855 + if(!bCached) {
  856 + LOG_WARN("[{}]- decode result warning, width:{} width_stride:{} height:{} height_stride:{} size:{}", m_dec_name, width, width_stride, height, height_stride, outputSize);
  857 + acldvppFree(outputDataDev);
  858 + outputDataDev = nullptr;
  859 + }
  860 + }while(0);
  861 +
  862 + CHECK_AND_RETURN_NOVALUE(acldvppDestroyStreamDesc(input), "acldvppDestroyStreamDesc failed");
  863 + CHECK_AND_RETURN_NOVALUE(acldvppDestroyPicDesc(output), "acldvppDestroyPicDesc failed");
830 864 }
831 865  
832 866 bool DvppDecoder::sendVdecEos(aclvdecChannelDesc *vdecChannelDesc) {
... ... @@ -855,14 +889,60 @@ bool DvppDecoder::sendVdecEos(aclvdecChannelDesc *vdecChannelDesc) {
855 889 return true;
856 890 }
857 891  
  892 +void DvppDecoder::display_thread() {
  893 + LOG_INFO("[{}]- display_thread start...", m_dec_name);
  894 + unsigned long index = 0;
  895 + while(!m_bExitDisplayThd) {
  896 + m_decoded_data_queue_mtx.lock();
  897 + if(m_decoded_data_queue.size() <= 0) {
  898 + m_decoded_data_queue_mtx.unlock();
  899 + std::this_thread::sleep_for(std::chrono::milliseconds(5));
  900 + continue;
  901 + }
  902 +
  903 + DvppDataMemory* mem = m_decoded_data_queue.front();
  904 + m_decoded_data_queue.pop();
  905 + m_decoded_data_queue_mtx.unlock();
  906 +
  907 + if (mem) {
  908 + if ((m_frameSkip == 1 || index % m_frameSkip == 0) && post_decoded_cbk){
  909 + post_decoded_cbk(m_postDecArg, mem);
  910 + } else {
  911 + delete mem;
  912 + mem = nullptr;
  913 + }
  914 + }
  915 +
  916 + index++;
  917 + if(index >= 100000){
  918 + index = 0;
  919 + }
  920 + }
  921 +
  922 + m_decoded_data_queue_mtx.lock();
  923 + while (m_decoded_data_queue.size() > 0){
  924 + DvppDataMemory* mem = m_decoded_data_queue.front();
  925 + m_decoded_data_queue.pop();
  926 + delete mem;
  927 + mem = nullptr;
  928 + }
  929 + m_decoded_data_queue_mtx.unlock();
  930 +
  931 + LOG_INFO("[{}]- display_thread exit.", m_dec_name);
  932 +}
  933 +
858 934 void DvppDecoder::release_dvpp(){
859 935 if(m_context){
860 936 aclError ret = aclrtDestroyContext(m_context);
861 937 if(ret != ACL_ERROR_NONE){
862 938 LOG_ERROR("[{}]- aclrtDestroyContext failed !", m_dec_name);
863 939 }
  940 + m_context = nullptr;
864 941 }
865 942  
866   - DvppSourceManager* pSrcMgr = DvppSourceManager::getInstance();
867   - pSrcMgr->releaseChannel(m_dvpp_deviceId, m_dvpp_channel);
  943 + if(m_dvpp_channel >= 0){
  944 + DvppSourceManager* pSrcMgr = DvppSourceManager::getInstance();
  945 + pSrcMgr->releaseChannel(m_dvpp_deviceId, m_dvpp_channel);
  946 + m_dvpp_channel = -1;
  947 + }
868 948 }
869 949 \ No newline at end of file
... ...
src/decoder/dvpp/DvppDecoder.h
... ... @@ -6,14 +6,18 @@
6 6  
7 7 #include <queue>
8 8 #include <mutex>
9   -#include <condition_variable>
  9 +#include <thread>
  10 +#include <chrono>
  11 +#include <atomic>
10 12  
  13 +#include "VpcUtils.h"
11 14  
12 15 using namespace std;
13 16  
14 17 typedef void(*RECEIVER_FINISHED_CALLBACK)(const void* userPtr);
15 18  
16   -const int g_pkt_size = 1024 * 1024; // 单个AVPacket大小的最大值
  19 +
  20 +struct Vdec_CallBack_UserData;
17 21  
18 22 class DvppDecoder{
19 23 public:
... ... @@ -31,6 +35,7 @@ public:
31 35 bool isFinished();
32 36 bool isPausing();
33 37 bool getResolution( int &width, int &height );
  38 + bool getOutResolution( int &width, int &height );
34 39  
35 40 bool isSurport(FFDecConfig& cfg);
36 41  
... ... @@ -52,34 +57,41 @@ public:
52 57 int getCachedQueueLength();
53 58  
54 59 public:
55   - void doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output);
  60 + void doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *output, void *pUserData);
56 61 void doProcessReport();
  62 + long long get_last_read_ts();
57 63  
58 64 private:
59 65 AVCodecContext* init_FFmpeg(FFDecConfig config);
60   - bool init_vdpp(FFDecConfig cfg, AVCodecContext* avctx);
  66 + bool init_dvpp(FFDecConfig cfg);
61 67 void release_ffmpeg();
62 68 void read_thread();
63 69  
64   - void decode_thread();
65   - int sentFrame(aclvdecChannelDesc *vdecChannelDesc, uint64_t frame_count);
  70 + int sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, unsigned long long frame_nb);
66 71 bool sendVdecEos(aclvdecChannelDesc *vdecChannelDesc);
67 72 void release_dvpp();
68 73  
  74 + void display_thread();
  75 +
  76 + int getVdecType(int videoType, int profile);
  77 +
  78 + void calcOutResolution(int w, int h);
  79 +
69 80 private:
70 81 FFDecConfig m_cfg;
71 82 string m_dec_name;
72 83  
73   - const void * m_finishedDecArg;
74   - DECODE_FINISHED_CALLBACK decode_finished_cbk;
  84 + const void * m_finishedDecArg {nullptr};
  85 + DECODE_FINISHED_CALLBACK decode_finished_cbk {nullptr};
75 86  
76 87 bool m_bFinished{false};
77 88 bool m_bRunning{false};
78 89 bool m_bPause{false};
  90 +
79 91 bool m_bExitReportThd{false};
  92 + bool m_bExitDisplayThd{false};
80 93  
81 94 // 读取数据
82   - AVStream* stream{nullptr};
83 95 int video_index{-1};
84 96 AVFormatContext *fmt_ctx{nullptr};
85 97 AVPixelFormat pix_fmt;
... ... @@ -88,36 +100,41 @@ private:
88 100  
89 101 int frame_width{0};
90 102 int frame_height{0};
91   - bool m_bReal; // 是否实时流
  103 + int out_frame_width{0};
  104 + int out_frame_height{0};
  105 + bool m_bReal {false}; // 是否实时流
92 106 float m_fps{0.0};
93 107  
94   - RECEIVER_FINISHED_CALLBACK receiver_finished_cbk;
95   -
96   - pthread_t m_read_thread{0};
97   -
98   - bool m_dec_keyframe;
  108 + std::thread* m_read_thread{nullptr};
99 109  
100   - mutex m_pktQueue_mutex;
101   - queue<AVPacket*> m_pktQueue;
  110 + bool m_dec_keyframe {false};
  111 + bool m_bResize {false};
102 112  
103 113 // 解码
104 114 int m_dvpp_deviceId {-1};
105 115 int m_dvpp_channel {-1};
106 116 aclrtContext m_context{nullptr};
107   - acldvppStreamFormat enType;
  117 + acldvppStreamFormat m_enType;
108 118  
109   - pthread_t m_decode_thread{0};
110   - mutex m_vdecQueue_mutex;
111   - queue<void*> m_vdecQueue;
112   -
113   - const void * m_postDecArg;
114   - POST_DECODE_CALLBACK post_decoded_cbk;
  119 + const void * m_postDecArg {nullptr};
  120 + POST_DECODE_CALLBACK post_decoded_cbk {nullptr};
115 121  
116 122 int m_vdec_out_size {-1};
117 123  
118   - // 截图
119   - bool m_bSnapShoting{false};
120   - DvppDataMemory* m_cached_mem{nullptr};
121   - mutex m_cached_mutex;
122   - condition_variable m_cached_cond;
  124 + queue<DvppDataMemory*> m_decoded_data_queue;
  125 + mutex m_decoded_data_queue_mtx;
  126 +
  127 + long long last_ts {0};
  128 +
  129 + long long m_last_read_ts {0};
  130 +
  131 + uint64_t m_in_count {0};
  132 + uint64_t m_out_count {0};
  133 +
  134 + int m_frameSkip {1};
  135 +
  136 + std::atomic<int> m_DvppCacheCounter{0};
  137 + int m_cache_gop{0};
  138 +
  139 + VpcUtils m_vpcUtils;
123 140 };
124 141 \ No newline at end of file
... ...
src/decoder/dvpp/VpcPicConverter.cpp deleted
1   -#include "VpcPicConverter.h"
2   -#include "depend_headers.h"
3   -
4   -#define ALIGN_UP(val, align) (((val) % (align) == 0) ? (val) : (((val) / (align) + 1) * (align)))
5   -
6   -VpcPicConverter::VpcPicConverter(){
7   -
8   -}
9   -
10   -VpcPicConverter::~VpcPicConverter(){
11   - if(nullptr == stream_){
12   - aclrtDestroyStream(stream_);
13   - }
14   -}
15   -
16   -int VpcPicConverter::init(aclrtContext context, string dec_name){
17   -
18   - m_dec_name = dec_name;
19   -
20   - CHECK_AND_RETURN(aclrtSetCurrentContext(context), "aclrtSetCurrentContext failed");
21   - CHECK_AND_RETURN(aclrtCreateStream(&stream_), "aclrtCreateStream failed! ");
22   -
23   - dvppChannelDesc_ = acldvppCreateChannelDesc();
24   -
25   - int ret = ACL_ERROR_NONE;
26   - do
27   - {
28   - ret = acldvppCreateChannel(dvppChannelDesc_);
29   - CHECK_AND_BREAK(ret, "acldvppCreateChannel failed !");
30   -
31   - ret = acldvppSetChannelDescMode(dvppChannelDesc_, DVPP_CHNMODE_VPC);
32   - CHECK_AND_BREAK(ret, "acldvppSetChannelDescMode failed !");
33   - } while (0);
34   -
35   - return ret;
36   -}
37   -
38   -DvppDataMemory* VpcPicConverter::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){
39   -
40   - int out_buf_width = ALIGN_UP(out_width, 16) * 3;
41   - int out_buf_height = ALIGN_UP(out_height, 2);
42   - int out_buf_size = out_buf_width * out_buf_height;
43   -
44   - DvppDataMemory* rgbMem = new DvppDataMemory(3, out_buf_width, out_buf_width, out_buf_height, out_buf_height, out_buf_size, "", to_string(m_devId), key_frame);
45   - void *outBufferDev_ = (void*)rgbMem->getMem();
46   -
47   - acldvppPicDesc *outputDesc_= acldvppCreatePicDesc();
48   - acldvppSetPicDescData(outputDesc_, outBufferDev_);
49   - acldvppSetPicDescFormat(outputDesc_, PIXEL_FORMAT_BGR_888);
50   - acldvppSetPicDescWidth(outputDesc_, out_width);
51   - acldvppSetPicDescHeight(outputDesc_, out_height);
52   - acldvppSetPicDescWidthStride(outputDesc_, out_buf_width);
53   - acldvppSetPicDescHeightStride(outputDesc_, out_buf_height);
54   - acldvppSetPicDescSize(outputDesc_, out_buf_size);
55   -
56   - aclError ret = ACL_ERROR_NONE;
57   - do{
58   - // 9. 执行异步色域转换,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
59   - ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_);
60   - if(ret != ACL_ERROR_NONE){
61   - LOG_ERROR("acldvppVpcConvertColorAsync failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
62   - break;
63   - }
64   - ret = aclrtSynchronizeStream(stream_);
65   - if(ret != ACL_ERROR_NONE){
66   - LOG_ERROR("aclrtSynchronizeStream failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size);
67   - break;
68   - }
69   - }while(0);
70   -
71   - acldvppDestroyPicDesc(outputDesc_);
72   -
73   - if(ret != ACL_ERROR_NONE){
74   - delete rgbMem;
75   - rgbMem = nullptr;
76   - }
77   -
78   - return rgbMem;
79   -}
80 0 \ No newline at end of file
src/decoder/interface/DeviceMemory.hpp
... ... @@ -10,7 +10,7 @@ using namespace std;
10 10 class DeviceMemory{
11 11  
12 12 public:
13   - DeviceMemory(int _channel, int _width, int _width_stride, int _height, int _height_stride, string _id, string _dev_id, bool _key_frame, bool _isused){
  13 + DeviceMemory(int _channel, int _width, int _width_stride, int _height, int _height_stride, string _id, string _dev_id, bool _key_frame, unsigned long long _frame_nb, bool _isused){
14 14 channel = _channel;
15 15 width = _width;
16 16 width_stride = _width_stride;
... ... @@ -21,14 +21,19 @@ public:
21 21 id = _id;
22 22 device_id = _dev_id;
23 23 key_frame = _key_frame;
  24 + frame_nb = _frame_nb;
24 25 timestamp = UtilTools::get_cur_time_ms();
25 26 }
26 27  
27 28 virtual ~DeviceMemory(){}
28   -
  29 +
29 30 int getSize() {
30 31 return data_size;
31 32 }
  33 +
  34 + void setSize(int size) {
  35 + data_size = size;
  36 + }
32 37  
33 38 bool isIsused() {
34 39 return isused;
... ... @@ -44,42 +49,90 @@ public:
44 49 return id;
45 50 }
46 51  
  52 + void setId(string _id) {
  53 + id = _id;
  54 + }
  55 +
47 56 string getDeviceId() {
48 57 return device_id;
49 58 }
50 59  
  60 + void setDeviceId(string _device_id) {
  61 + device_id = _device_id;
  62 + }
  63 +
51 64 unsigned char* getMem(){
52 65 return pHwRgb;
53 66 }
54 67  
  68 + void setMem(unsigned char* _pHwRgb) {
  69 + pHwRgb = _pHwRgb;
  70 + }
  71 +
55 72 long long getTimesstamp(){
56 73 return timestamp;
57 74 }
58 75  
  76 + void setTimesstamp(long long _timestamp) {
  77 + timestamp = _timestamp;
  78 + }
  79 +
59 80 int getWidth(){
60 81 return width;
61 82 }
62 83  
  84 + void setWidth(int _width) {
  85 + width = _width;
  86 + }
  87 +
63 88 int getWidthStride(){
64 89 return width_stride;
65 90 }
66 91  
  92 + void setWidthStride(int _width_stride) {
  93 + width_stride = _width_stride;
  94 + }
  95 +
67 96 int getHeight(){
68 97 return height;
69 98 }
70 99  
  100 + void setHeight(int _height) {
  101 + height = _height;
  102 + }
  103 +
71 104 int getHeightStride(){
72 105 return height_stride;
73 106 }
74 107  
  108 + void setHeightStride(int _height_stride) {
  109 + height_stride = _height_stride;
  110 + }
  111 +
75 112 int getChannel(){
76 113 return channel;
77 114 }
78 115  
  116 + void setChannel(int _channel) {
  117 + channel = _channel;
  118 + }
  119 +
79 120 bool isKeyFrame(){
80 121 return key_frame;
81 122 }
82 123  
  124 + void setKeyFrame(bool _key_frame) {
  125 + key_frame = _key_frame;
  126 + }
  127 +
  128 + unsigned long long getFrameNb() {
  129 + return frame_nb;
  130 + }
  131 +
  132 + void setFrameNb(unsigned long long _frame_nb) {
  133 + frame_nb = _frame_nb;
  134 + }
  135 +
83 136 public:
84 137 int data_size;
85 138 bool isused;
... ... @@ -94,6 +147,7 @@ public:
94 147 int channel{3};
95 148 bool key_frame;
96 149 long index;
  150 + unsigned long long frame_nb;
97 151 };
98 152  
99 153 #endif
100 154 \ No newline at end of file
... ...
src/decoder/interface/interface_headers.h
... ... @@ -35,6 +35,7 @@ struct FFDecConfig{
35 35 bool force_tcp{true}; // 是否指定使用tcp连接
36 36 int skip_frame{1}; // 跳帧数
37 37 string dec_name;
  38 + bool resize{false}; // 是否resize到1920,1080
38 39  
39 40 int port; // gb28181接收数据的端口号
40 41 DECODE_REQUEST_STREAM_CALLBACK request_stream_cbk; // gb28181请求流
... ... @@ -43,7 +44,8 @@ struct FFDecConfig{
43 44 enum DECODER_TYPE{
44 45 DECODER_TYPE_GB28181,
45 46 DECODER_TYPE_FFMPEG,
46   - DECODER_TYPE_DVPP
  47 + DECODER_TYPE_DVPP,
  48 + DECODER_TYPE_DVPP_GB28181
47 49 };
48 50  
49 51 #endif
50 52 \ No newline at end of file
... ...
src/demo/demo.cpp
1 1 #include "../ai_platform/stl_aiplatform.h"
2 2 #include <chrono>
  3 +#include <thread>
  4 +#include <stdio.h>
  5 +#include <string.h>
  6 +#include <stdlib.h>
  7 +#include <unistd.h>
3 8  
4 9 using namespace std;
5 10  
  11 +#ifdef POST_USE_RABBITMQ
  12 +
  13 +void init_mq_conn(void *handle) {
  14 + for (auto key : {mq_type_t::ALARM_MQ, mq_type_t::GET_TASK_MQ, mq_type_t::HEART_BEAT_MQ, mq_type_t::SCREENSHORT_TASK_MQ, mq_type_t::TIMING_SCREENSHORT_TASK_MQ}) {
  15 + rabbitmq_conn_params_t mq_conn_params;
  16 + mq_conn_params.port = 5672;
  17 +
  18 + strcpy(mq_conn_params.ip, "192.168.60.126");
  19 + strcpy(mq_conn_params.uname, "admin");
  20 + strcpy(mq_conn_params.passwd, "123456");
  21 + strcpy(mq_conn_params.vhost, "/");
  22 + strcpy(mq_conn_params.exchange, "topExchange");
  23 + strcpy(mq_conn_params.exchange_type, "topic");
  24 +
  25 + // mq_conn_params.port = 5673;
  26 + // strcpy(mq_conn_params.ip, "192.168.10.187");
  27 + // strcpy(mq_conn_params.uname, "admin");
  28 + // strcpy(mq_conn_params.passwd, "admin123456");
  29 + // strcpy(mq_conn_params.vhost, "/");
  30 + // strcpy(mq_conn_params.exchange, "topExchange");
  31 + // strcpy(mq_conn_params.exchange_type, "topic");
  32 +
  33 + switch (key) {
  34 + case mq_type_t::ALARM_MQ: {
  35 + strcpy(mq_conn_params.queue, "topic.queue.alarm");
  36 + strcpy(mq_conn_params.routing_key, "topic.queue.alarm.key");
  37 + } break;
  38 + case mq_type_t::GET_TASK_MQ: {
  39 + strcpy(mq_conn_params.queue, "tsl.test.queue.get");
  40 + strcpy(mq_conn_params.routing_key, "tsl.test.queue.get.key");
  41 + } break;
  42 + case mq_type_t::HEART_BEAT_MQ: {
  43 + strcpy(mq_conn_params.queue, "tsl.test.queue.hb");
  44 + strcpy(mq_conn_params.routing_key, "tsl.test.queue.hb.key");
  45 + } break;
  46 + case mq_type_t::SCREENSHORT_TASK_MQ: {
  47 + strcpy(mq_conn_params.queue, "video.screenshort.queue.get");
  48 + strcpy(mq_conn_params.routing_key, "video.screenshort.queue.key");
  49 + } break;
  50 + case mq_type_t::TIMING_SCREENSHORT_TASK_MQ: {
  51 + strcpy(mq_conn_params.queue, "video.timingscreenshort.queue.get");
  52 + strcpy(mq_conn_params.routing_key, "video.timingscreenshort.queue.key");
  53 + } break;
  54 + }
  55 +
  56 + mq_conn_params.durable_exchange = true;
  57 + mq_conn_params.durable_queue = true;
  58 +
  59 + if (0 != add_mq_conn(handle, key, mq_conn_params)) // 队列走接口创建
  60 + fprintf(stderr, "ip is %s port is %d\n", mq_conn_params.ip, mq_conn_params.port);
  61 + }
  62 +}
  63 +
  64 +#endif // #ifdef POST_USE_RABBITMQ
6 65  
7 66 void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_type_t &algor_type) {
8 67 auto algor_init_params = new algor_init_config_param_t;
... ... @@ -10,15 +69,19 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
10 69 case algorithm_type_t::FACE_SNAPSHOT: {
11 70 auto basic_params = new algor_basic_config_param_t;
12 71 {
13   - basic_params->algor_valid_rect.top_ = 0;
14   - basic_params->algor_valid_rect.left_ = 0;
15   - basic_params->algor_valid_rect.width_ = 1920;
16   - basic_params->algor_valid_rect.height_ = 1080;
17   -
18 72 basic_params->result_folder = "res/face";
19   - ;
20 73 basic_params->result_folder_little = "res/face_little";
21   - ;
  74 +
  75 + //共性算法适配测试用
  76 + auto adapt_params = new universal_algor_adapt_param;
  77 + {
  78 + adapt_params->points_count = 4; // 0表示不生效
  79 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  80 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  81 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  82 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  83 + }
  84 + basic_params->adapt_param = adapt_params;
22 85 }
23 86 auto algor_params = new algor_config_param_snapshot;
24 87 { algor_params->threshold = 0.5f; }
... ... @@ -30,13 +93,19 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
30 93 case algorithm_type_t::HUMAN_SNAPSHOT: {
31 94 auto basic_params = new algor_basic_config_param_t;
32 95 {
33   - basic_params->algor_valid_rect.top_ = 0;
34   - basic_params->algor_valid_rect.left_ = 0;
35   - basic_params->algor_valid_rect.width_ = 1920;
36   - basic_params->algor_valid_rect.height_ = 1080;
37   -
38 96 basic_params->result_folder = "res/human";
39 97 basic_params->result_folder_little = "res/human_little";
  98 +
  99 + //共性算法适配测试用
  100 + auto adapt_params = new universal_algor_adapt_param;
  101 + {
  102 + adapt_params->points_count = 4; // 0表示不生效
  103 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  104 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  105 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  106 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  107 + }
  108 + basic_params->adapt_param = adapt_params;
40 109 }
41 110 auto algor_params = new algor_config_param_snapshot;
42 111 { algor_params->threshold = 0.5f; }
... ... @@ -47,17 +116,27 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
47 116  
48 117 case algorithm_type_t::PEDESTRIAN_FALL: {
49 118 auto algor_params = new algor_config_param_pedestrian_fall;
50   - { algor_params->threshold = 0.7f; }
  119 + {
  120 + algor_params->threshold = 0.85f;
  121 + algor_params->pedestrian_min_width = 20;
  122 + algor_params->pedestrian_min_height = 20;
  123 + algor_params->pedestrian_confidence_threshold = 0.85;
  124 + }
51 125  
52 126 auto basic_params = new algor_basic_config_param_t;
53 127 {
54   - basic_params->algor_valid_rect.top_ = 0;
55   - basic_params->algor_valid_rect.left_ = 0;
56   - basic_params->algor_valid_rect.width_ = 1920;
57   - basic_params->algor_valid_rect.height_ = 1080;
58   -
59 128 basic_params->result_folder = "res/fall";
60 129 basic_params->result_folder_little = "res/fall_little";
  130 +
  131 + auto adapt_params = new universal_algor_adapt_param;
  132 + {
  133 + adapt_params->points_count = 4; // 0表示不生效
  134 + adapt_params->points[0].x_ = 0; adapt_params->points[0].y_ = 0;
  135 + adapt_params->points[1].x_ = 1920; adapt_params->points[1].y_ = 0;
  136 + adapt_params->points[2].x_ = 1920; adapt_params->points[2].y_ = 1080;
  137 + adapt_params->points[3].x_ = 0; adapt_params->points[3].y_ = 1080;
  138 + }
  139 + basic_params->adapt_param = adapt_params;
61 140 }
62 141  
63 142 algor_init_params->algor_param = algor_params;
... ... @@ -67,19 +146,26 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
67 146 case algorithm_type_t::PEDESTRIAN_FIGHT: {
68 147 auto algor_params = new algor_config_param_pedestrian_fight;
69 148 {
70   - algor_params->threshold = 0.7f;
71   - algor_params->iou_threshold = 0.1f;
  149 + algor_params->threshold = 0.85f;
  150 + algor_params->pedestrian_min_width = 20;
  151 + algor_params->pedestrian_min_height = 20;
  152 + algor_params->pedestrian_confidence_threshold = 0.85;
72 153 }
73 154  
74 155 auto basic_params = new algor_basic_config_param_t;
75 156 {
76   -
77   - basic_params->algor_valid_rect.top_ = 0;
78   - basic_params->algor_valid_rect.left_ = 0;
79   - basic_params->algor_valid_rect.width_ = 1920;
80   - basic_params->algor_valid_rect.height_ = 1080;
81 157 basic_params->result_folder = "res/fight";
82 158 basic_params->result_folder_little = "res/fight_little";
  159 +
  160 + auto adapt_params = new universal_algor_adapt_param;
  161 + {
  162 + adapt_params->points_count = 4; // 0表示不生效
  163 + adapt_params->points[0].x_ = 0; adapt_params->points[0].y_ = 0;
  164 + adapt_params->points[1].x_ = 1920; adapt_params->points[1].y_ = 0;
  165 + adapt_params->points[2].x_ = 1920; adapt_params->points[2].y_ = 1080;
  166 + adapt_params->points[3].x_ = 0; adapt_params->points[3].y_ = 1080;
  167 + }
  168 + basic_params->adapt_param = adapt_params;
83 169 }
84 170  
85 171 algor_init_params->algor_param = algor_params;
... ... @@ -90,19 +176,111 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
90 176  
91 177 auto algor_params = new algor_config_param_human_gather;
92 178 {
93   - algor_params->frame_stride = 1;
94   - // algor_params->human_count_threshold = 3;
95   - algor_params->human_count_threshold = 1;
  179 + algor_params->frame_stride = 3;
  180 + algor_params->human_count_threshold = 3;
96 181 }
97 182  
98 183 auto basic_params = new algor_basic_config_param_t;
99 184 {
100   - basic_params->algor_valid_rect.top_ = 0;
101   - basic_params->algor_valid_rect.left_ = 0;
102   - basic_params->algor_valid_rect.width_ = 1920;
103   - basic_params->algor_valid_rect.height_ = 1080;
104 185 basic_params->result_folder = "res/gather";
105 186 basic_params->result_folder_little = "res/gather_little";
  187 +
  188 + //共性算法适配测试用
  189 + auto adapt_params = new universal_algor_adapt_param;
  190 + {
  191 + adapt_params->points_count = 4; // 0表示不生效
  192 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  193 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  194 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  195 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  196 + }
  197 + basic_params->adapt_param = adapt_params;
  198 + }
  199 +
  200 + algor_init_params->algor_param = algor_params;
  201 + algor_init_params->basic_param = basic_params;
  202 + } break;
  203 +
  204 + case algorithm_type_t::HUMAN_REGION_GATHER: {
  205 +
  206 + auto algor_params = new algor_config_param_human_gather;
  207 + {
  208 + algor_params->frame_stride = 3;
  209 + algor_params->human_count_threshold = 3;
  210 + }
  211 +
  212 + auto basic_params = new algor_basic_config_param_t;
  213 + {
  214 + basic_params->result_folder = "res/region_gather";
  215 + basic_params->result_folder_little = "res/region_gather_little";
  216 +
  217 + //共性算法适配测试用
  218 + auto adapt_params = new universal_algor_adapt_param;
  219 + {
  220 + adapt_params->points_count = 4; // 0表示不生效
  221 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  222 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  223 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  224 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  225 + }
  226 + basic_params->adapt_param = adapt_params;
  227 + }
  228 +
  229 + algor_init_params->algor_param = algor_params;
  230 + algor_init_params->basic_param = basic_params;
  231 + } break;
  232 +
  233 + case algorithm_type_t::HUMAN_DENSITY: {
  234 +
  235 + auto algor_params = new algor_config_param_human_gather;
  236 + {
  237 + algor_params->frame_stride = 3;
  238 + algor_params->human_count_threshold = 3;
  239 + }
  240 +
  241 + auto basic_params = new algor_basic_config_param_t;
  242 + {
  243 + basic_params->result_folder = "res/human_density";
  244 + basic_params->result_folder_little = "res/human_density_little";
  245 +
  246 + //共性算法适配测试用
  247 + auto adapt_params = new universal_algor_adapt_param;
  248 + {
  249 + adapt_params->points_count = 4; // 0表示不生效
  250 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  251 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  252 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  253 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  254 + }
  255 + basic_params->adapt_param = adapt_params;
  256 + }
  257 +
  258 + algor_init_params->algor_param = algor_params;
  259 + algor_init_params->basic_param = basic_params;
  260 + } break;
  261 +
  262 + case algorithm_type_t::VEHICLE_GATHER: {
  263 +
  264 + auto algor_params = new algor_config_param_human_gather;
  265 + {
  266 + algor_params->frame_stride = 3;
  267 + algor_params->human_count_threshold = 1;
  268 + }
  269 +
  270 + auto basic_params = new algor_basic_config_param_t;
  271 + {
  272 + basic_params->result_folder = "res/vehicle_gather";
  273 + basic_params->result_folder_little = "res/vehicle_gather_little";
  274 +
  275 + auto adapt_params = new universal_algor_adapt_param;
  276 + {
  277 + adapt_params->points_count = 4; // 0表示不生效
  278 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  279 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  280 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  281 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  282 + }
  283 + basic_params->adapt_param = adapt_params;
106 284 }
107 285  
108 286 algor_init_params->algor_param = algor_params;
... ... @@ -122,12 +300,11 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
122 300  
123 301 auto basic_params = new algor_basic_config_param_t;
124 302 {
125   - basic_params->algor_valid_rect.top_ = 0;
126   - basic_params->algor_valid_rect.left_ = 0;
127   - basic_params->algor_valid_rect.width_ = 1920;
128   - basic_params->algor_valid_rect.height_ = 1080;
129 303 basic_params->result_folder = "res/no_reflective_clothing";
130 304 basic_params->result_folder_little = "res/no_reflective_clothing_little";
  305 +
  306 + auto adapt_params = new universal_algor_adapt_param;
  307 + basic_params->adapt_param = adapt_params;
131 308 }
132 309  
133 310 algor_init_params->algor_param = algor_params;
... ... @@ -147,12 +324,11 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
147 324  
148 325 auto basic_params = new algor_basic_config_param_t;
149 326 {
150   - basic_params->algor_valid_rect.top_ = 0;
151   - basic_params->algor_valid_rect.left_ = 0;
152   - basic_params->algor_valid_rect.width_ = 1920;
153   - basic_params->algor_valid_rect.height_ = 1080;
154 327 basic_params->result_folder = "res/no_safety_helmet";
155 328 basic_params->result_folder_little = "res/no_safety_helmet_little";
  329 +
  330 + auto adapt_params = new universal_algor_adapt_param;
  331 + basic_params->adapt_param = adapt_params;
156 332 }
157 333  
158 334 algor_init_params->algor_param = algor_params;
... ... @@ -172,12 +348,11 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
172 348  
173 349 auto basic_params = new algor_basic_config_param_t;
174 350 {
175   - basic_params->algor_valid_rect.top_ = 0;
176   - basic_params->algor_valid_rect.left_ = 0;
177   - basic_params->algor_valid_rect.width_ = 1920;
178   - basic_params->algor_valid_rect.height_ = 1080;
179 351 basic_params->result_folder = "res/call_phone";
180 352 basic_params->result_folder_little = "res/call_phone_little";
  353 +
  354 + auto adapt_params = new universal_algor_adapt_param;
  355 + basic_params->adapt_param = adapt_params;
181 356 }
182 357  
183 358 algor_init_params->algor_param = algor_params;
... ... @@ -197,12 +372,11 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
197 372  
198 373 auto basic_params = new algor_basic_config_param_t;
199 374 {
200   - basic_params->algor_valid_rect.top_ = 0;
201   - basic_params->algor_valid_rect.left_ = 0;
202   - basic_params->algor_valid_rect.width_ = 1920;
203   - basic_params->algor_valid_rect.height_ = 1080;
204 375 basic_params->result_folder = "res/smoking";
205 376 basic_params->result_folder_little = "res/smoking_little";
  377 +
  378 + auto adapt_params = new universal_algor_adapt_param;
  379 + basic_params->adapt_param = adapt_params;
206 380 }
207 381  
208 382 algor_init_params->algor_param = algor_params;
... ... @@ -213,18 +387,25 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
213 387  
214 388 auto basic_params = new algor_basic_config_param_t;
215 389 {
216   - basic_params->algor_valid_rect.top_ = 0;
217   - basic_params->algor_valid_rect.left_ = 0;
218   - basic_params->algor_valid_rect.width_ = 1920;
219   - basic_params->algor_valid_rect.height_ = 1080;
220 390 basic_params->result_folder = "res/vehicle";
221 391 basic_params->result_folder_little = "res/vehicle_little";
  392 +
  393 + //共性算法适配测试用
  394 + auto adapt_params = new universal_algor_adapt_param;
  395 + {
  396 + adapt_params->points_count = 4; // 0表示不生效
  397 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  398 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  399 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  400 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  401 + }
  402 + basic_params->adapt_param = adapt_params;
222 403 }
223   -
224 404 auto algor_params = new algor_config_param_snapshot;
225   - algor_params->threshold = 0.5f;
226   - algor_params->snap_frame_interval = 5;
227   -
  405 + {
  406 + algor_params->threshold = 0.5f;
  407 + algor_params->snap_frame_interval = 1;
  408 + }
228 409 algor_init_params->algor_param = algor_params;
229 410 algor_init_params->basic_param = basic_params;
230 411 } break;
... ... @@ -233,12 +414,18 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
233 414  
234 415 auto basic_params = new algor_basic_config_param_t;
235 416 {
236   - basic_params->algor_valid_rect.top_ = 0;
237   - basic_params->algor_valid_rect.left_ = 0;
238   - basic_params->algor_valid_rect.width_ = 1920;
239   - basic_params->algor_valid_rect.height_ = 1080;
240 417 basic_params->result_folder = "res/nonmotor";
241 418 basic_params->result_folder_little = "res/nonmotor_little";
  419 +
  420 + auto adapt_params = new universal_algor_adapt_param;
  421 + {
  422 + adapt_params->points_count = 4; // 0表示不生效
  423 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  424 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  425 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  426 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  427 + }
  428 + basic_params->adapt_param = adapt_params;
242 429 }
243 430  
244 431 auto algor_params = new algor_config_param_snapshot;
... ... @@ -247,6 +434,7 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
247 434 algor_init_params->algor_param = algor_params;
248 435 algor_init_params->basic_param = basic_params;
249 436 } break;
  437 +
250 438  
251 439 case algorithm_type_t::TAKEAWAY_MEMBER_CLASSIFICATION: {
252 440 auto algor_params = new algor_config_param_takeaway_member_classification;
... ... @@ -258,12 +446,11 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
258 446  
259 447 auto basic_params = new algor_basic_config_param_t;
260 448 {
261   - basic_params->algor_valid_rect.top_ = 0;
262   - basic_params->algor_valid_rect.left_ = 0;
263   - basic_params->algor_valid_rect.width_ = 1920;
264   - basic_params->algor_valid_rect.height_ = 1080;
265 449 basic_params->result_folder = "res/takeaway";
266 450 basic_params->result_folder_little = "res/takeaway_little";
  451 +
  452 + auto adapt_params = new universal_algor_adapt_param;
  453 + basic_params->adapt_param = adapt_params;
267 454 }
268 455  
269 456 algor_init_params->algor_param = algor_params;
... ... @@ -288,12 +475,11 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
288 475  
289 476 auto basic_params = new algor_basic_config_param_t;
290 477 {
291   - basic_params->algor_valid_rect.top_ = 0;
292   - basic_params->algor_valid_rect.left_ = 0;
293   - basic_params->algor_valid_rect.width_ = 1920;
294   - basic_params->algor_valid_rect.height_ = 1080;
295 478 basic_params->result_folder = "res/pedestrian_retrograde";
296 479 basic_params->result_folder_little = "res/pedestrian_retrograde_little";
  480 +
  481 + auto adapt_params = new universal_algor_adapt_param;
  482 + basic_params->adapt_param = adapt_params;
297 483 }
298 484  
299 485 algor_init_params->algor_param = algor_params;
... ... @@ -319,13 +505,10 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
319 505  
320 506 auto basic_params = new algor_basic_config_param_t;
321 507 {
322   - basic_params->algor_valid_rect.top_ = 0;
323   -
324   - basic_params->algor_valid_rect.left_ = 0;
325   - basic_params->algor_valid_rect.width_ = 1920;
326   - basic_params->algor_valid_rect.height_ = 1080;
327 508 basic_params->result_folder = "res/vehicle_retrograde";
328 509 basic_params->result_folder_little = "res/vehicle_retrograde_little";
  510 + auto adapt_params = new universal_algor_adapt_param;
  511 + basic_params->adapt_param = adapt_params;
329 512 }
330 513  
331 514 algor_init_params->algor_param = algor_params;
... ... @@ -338,31 +521,123 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
338 521 auto algor_params = new algor_config_param_pedestrian_trespass;
339 522 {
340 523 algor_params->conf_threshold = 0.5f;
341   - algor_params->minmum_height = 64;
342   - algor_params->minmum_width = 32;
  524 + algor_params->minmum_height = 20;
  525 + algor_params->minmum_width = 20;
343 526 algor_params->points_count = 4;
344 527  
345   - algor_params->points[0].x_ = 200;
346   - algor_params->points[0].y_ = 200;
  528 + algor_params->points[0].x_ = 505;
  529 + algor_params->points[0].y_ = 481;
347 530  
348   - algor_params->points[1].x_ = 600;
349   - algor_params->points[1].y_ = 200;
  531 + algor_params->points[1].x_ = 741;
  532 + algor_params->points[1].y_ = 881;
350 533  
351   - algor_params->points[2].x_ = 600;
352   - algor_params->points[2].y_ = 500;
  534 + algor_params->points[2].x_ = 1911;
  535 + algor_params->points[2].y_ = 667;
353 536  
354   - algor_params->points[3].x_ = 200;
355   - algor_params->points[3].y_ = 500;
  537 + algor_params->points[3].x_ = 1484;
  538 + algor_params->points[3].y_ = 410;
356 539 }
357 540  
358 541 auto basic_params = new algor_basic_config_param_t;
359 542 {
360   - basic_params->algor_valid_rect.top_ = 0;
361   - basic_params->algor_valid_rect.left_ = 0;
362   - basic_params->algor_valid_rect.width_ = 1920;
363   - basic_params->algor_valid_rect.height_ = 1080;
364 543 basic_params->result_folder = "res/pedestrian_trespass";
365 544 basic_params->result_folder_little = "res/pedestrian_trespass_little";
  545 + auto adapt_params = new universal_algor_adapt_param;
  546 + {
  547 + adapt_params->points_count = 4; // 0表示不生效
  548 + adapt_params->points[0].x_ = 0; adapt_params->points[0].y_ = 0;
  549 + adapt_params->points[1].x_ = 1920; adapt_params->points[1].y_ = 0;
  550 + adapt_params->points[2].x_ = 1920; adapt_params->points[2].y_ = 1080;
  551 + adapt_params->points[3].x_ = 0; adapt_params->points[3].y_ = 1080;
  552 + }
  553 + basic_params->adapt_param = adapt_params;
  554 + }
  555 +
  556 + algor_init_params->algor_param = algor_params;
  557 + algor_init_params->basic_param = basic_params;
  558 +
  559 + } break;
  560 +
  561 + case algorithm_type_t::HUMAN_LEAVE_REGION: {
  562 + // 578 1300 600
  563 + auto algor_params = new algor_config_param_trespass_basic;
  564 + {
  565 + algor_params->conf_threshold = 0.5f;
  566 + algor_params->minmum_height = 20;
  567 + algor_params->minmum_width = 20;
  568 + }
  569 +
  570 + auto basic_params = new algor_basic_config_param_t;
  571 + {
  572 + basic_params->result_folder = "res/human_region_leave";
  573 + basic_params->result_folder_little = "res/human_region_leave_little";
  574 + auto adapt_params = new universal_algor_adapt_param;
  575 + {
  576 + adapt_params->points_count = 4; // 0表示不生效
  577 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  578 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  579 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  580 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  581 + }
  582 + basic_params->adapt_param = adapt_params;
  583 + }
  584 +
  585 + algor_init_params->algor_param = algor_params;
  586 + algor_init_params->basic_param = basic_params;
  587 +
  588 + } break;
  589 +
  590 + case algorithm_type_t::HUMAN_REGION_DISMISS: {
  591 + // 578 1300 600
  592 + auto algor_params = new algor_config_param_trespass_basic;
  593 + {
  594 + algor_params->conf_threshold = 0.5f;
  595 + algor_params->minmum_height = 20;
  596 + algor_params->minmum_width = 20;
  597 + }
  598 +
  599 + auto basic_params = new algor_basic_config_param_t;
  600 + {
  601 + basic_params->result_folder = "res/human_region_dismiss";
  602 + basic_params->result_folder_little = "res/human_region_dismiss_little";
  603 + auto adapt_params = new universal_algor_adapt_param;
  604 + {
  605 + adapt_params->points_count = 4; // 0表示不生效
  606 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  607 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  608 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  609 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  610 + }
  611 + basic_params->adapt_param = adapt_params;
  612 + }
  613 +
  614 + algor_init_params->algor_param = algor_params;
  615 + algor_init_params->basic_param = basic_params;
  616 +
  617 + } break;
  618 +
  619 + case algorithm_type_t::HUMAN_REGION_FAST_MOVING: {
  620 + // 578 1300 600
  621 + auto algor_params = new algor_config_param_trespass_basic;
  622 + {
  623 + algor_params->conf_threshold = 0.5f;
  624 + algor_params->minmum_height = 20;
  625 + algor_params->minmum_width = 20;
  626 + }
  627 +
  628 + auto basic_params = new algor_basic_config_param_t;
  629 + {
  630 + basic_params->result_folder = "res/human_region_fastmoving";
  631 + basic_params->result_folder_little = "res/human_region_fastmoving_little";
  632 + auto adapt_params = new universal_algor_adapt_param;
  633 + {
  634 + adapt_params->points_count = 4; // 0表示不生效
  635 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  636 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  637 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  638 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  639 + }
  640 + basic_params->adapt_param = adapt_params;
366 641 }
367 642  
368 643 algor_init_params->algor_param = algor_params;
... ... @@ -375,31 +650,36 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
375 650 auto algor_params = new algor_config_param_vehicle_trespass;
376 651 {
377 652 algor_params->conf_threshold = 0.5f;
378   - algor_params->minmum_height = 64;
379   - algor_params->minmum_width = 64;
380   - algor_params->points_count = 4;
  653 + algor_params->minmum_height = 20;
  654 + algor_params->minmum_width = 20;
381 655  
382   - algor_params->points[0].x_ = 500;
383   - algor_params->points[0].y_ = 500;
  656 + algor_params->points_count = 4;
  657 + algor_params->points[0].x_ = 505;
  658 + algor_params->points[0].y_ = 481;
384 659  
385   - algor_params->points[1].x_ = 1500;
386   - algor_params->points[1].y_ = 500;
  660 + algor_params->points[1].x_ = 741;
  661 + algor_params->points[1].y_ = 881;
387 662  
388   - algor_params->points[2].x_ = 1500;
389   - algor_params->points[2].y_ = 900;
  663 + algor_params->points[2].x_ = 1911;
  664 + algor_params->points[2].y_ = 667;
390 665  
391   - algor_params->points[3].x_ = 500;
392   - algor_params->points[3].y_ = 900;
  666 + algor_params->points[3].x_ = 1484;
  667 + algor_params->points[3].y_ = 410;
393 668 }
394 669  
395 670 auto basic_params = new algor_basic_config_param_t;
396 671 {
397   - basic_params->algor_valid_rect.top_ = 0;
398   - basic_params->algor_valid_rect.left_ = 0;
399   - basic_params->algor_valid_rect.width_ = 1920;
400   - basic_params->algor_valid_rect.height_ = 1080;
401 672 basic_params->result_folder = "res/vehicle_trespass";
402 673 basic_params->result_folder_little = "res/vehicle_trespass_little";
  674 + auto adapt_params = new universal_algor_adapt_param;
  675 + {
  676 + adapt_params->points_count = 4; // 0表示不生效
  677 + adapt_params->points[0].x_ = 0; adapt_params->points[0].y_ = 0;
  678 + adapt_params->points[1].x_ = 1920; adapt_params->points[1].y_ = 0;
  679 + adapt_params->points[2].x_ = 1920; adapt_params->points[2].y_ = 1080;
  680 + adapt_params->points[3].x_ = 0; adapt_params->points[3].y_ = 1080;
  681 + }
  682 + basic_params->adapt_param = adapt_params;
403 683 }
404 684  
405 685 algor_init_params->algor_param = algor_params;
... ... @@ -426,12 +706,6 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
426 706  
427 707 auto basic_params = new algor_basic_config_param_t;
428 708 {
429   - basic_params->algor_valid_rect.top_ = 0;
430   - basic_params->algor_valid_rect.left_ = 0;
431   - // basic_params->algor_valid_rect.width_ = 1920;
432   - // basic_params->algor_valid_rect.height_ = 1080;
433   - basic_params->algor_valid_rect.width_ = 2560;
434   - basic_params->algor_valid_rect.height_ = 1440;
435 709 basic_params->result_folder = "res/road_work";
436 710 basic_params->result_folder_little = "res/road_work_little";
437 711 }
... ... @@ -456,6 +730,155 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
456 730 algor_init_params->basic_param = basic_params;
457 731 } break;
458 732  
  733 + case algorithm_type_t::HUMAN_CROSSING_LINE: {
  734 + auto algor_params = new algor_config_param_illegal_crossing_line;
  735 + {
  736 + algor_params->p1.x_ = 827;
  737 + algor_params->p1.y_ = 321;
  738 + algor_params->p2.x_ = 1911;
  739 + algor_params->p2.y_ = 1072;
  740 + algor_params->conf_threshold = 0.6;
  741 + algor_params->minmum_width = 20;
  742 + algor_params->minmum_height = 20;
  743 + }
  744 +
  745 + auto basic_params = new algor_basic_config_param_t;
  746 + {
  747 + basic_params->result_folder = "res/human_cross_line";
  748 + basic_params->result_folder_little = "res/human_cross_line_little";
  749 + //共性算法适配测试用
  750 + auto adapt_params = new universal_algor_adapt_param;
  751 + {
  752 + adapt_params->points_count = 4; // 0表示不生效
  753 + adapt_params->points[0].x_ = 0; adapt_params->points[0].y_ = 0;
  754 + adapt_params->points[1].x_ = 1920; adapt_params->points[1].y_ = 0;
  755 + adapt_params->points[2].x_ = 1920; adapt_params->points[2].y_ = 1080;
  756 + adapt_params->points[3].x_ = 0; adapt_params->points[3].y_ = 1080;
  757 + }
  758 + basic_params->adapt_param = adapt_params;
  759 + }
  760 +
  761 + algor_init_params->algor_param = algor_params;
  762 + algor_init_params->basic_param = basic_params;
  763 + } break;
  764 +
  765 + case algorithm_type_t::HUMAN_CLIMB: {
  766 + auto algor_params = new algor_config_param_illegal_crossing_line;
  767 + {
  768 + algor_params->p1.x_ = 827;
  769 + algor_params->p1.y_ = 321;
  770 + algor_params->p2.x_ = 1911;
  771 + algor_params->p2.y_ = 1072;
  772 + algor_params->conf_threshold = 0.5;
  773 + algor_params->minmum_width = 20;
  774 + algor_params->minmum_height = 20;
  775 + }
  776 +
  777 + auto basic_params = new algor_basic_config_param_t;
  778 + {
  779 + basic_params->result_folder = "res/human_climb";
  780 + basic_params->result_folder_little = "res/human_climb_little";
  781 +
  782 + auto adapt_params = new universal_algor_adapt_param;
  783 + {
  784 + adapt_params->points_count = 4; // 0表示不生效
  785 + adapt_params->points[0].x_ = 0; adapt_params->points[0].y_ = 0;
  786 + adapt_params->points[1].x_ = 1920; adapt_params->points[1].y_ = 0;
  787 + adapt_params->points[2].x_ = 1920; adapt_params->points[2].y_ = 1080;
  788 + adapt_params->points[3].x_ = 0; adapt_params->points[3].y_ = 1080;
  789 + }
  790 + basic_params->adapt_param = adapt_params;
  791 + }
  792 +
  793 + algor_init_params->algor_param = algor_params;
  794 + algor_init_params->basic_param = basic_params;
  795 + } break;
  796 +
  797 + case algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE: {
  798 + auto algor_params = new algor_config_param_illegal_crossing_line;
  799 + {
  800 + algor_params->p1.x_ = 827;
  801 + algor_params->p1.y_ = 321;
  802 + algor_params->p2.x_ = 1911;
  803 + algor_params->p2.y_ = 1072;
  804 + algor_params->minmum_width = 10;
  805 + algor_params->minmum_height = 10;
  806 + }
  807 +
  808 + auto basic_params = new algor_basic_config_param_t;
  809 + {
  810 + basic_params->result_folder = "res/vehicle_cross_line";
  811 + basic_params->result_folder_little = "res/vehicle_cross_line_little";
  812 + auto adapt_params = new universal_algor_adapt_param;
  813 + {
  814 + adapt_params->points_count = 4; // 0表示不生效
  815 + adapt_params->points[0].x_ = 0; adapt_params->points[0].y_ = 0;
  816 + adapt_params->points[1].x_ = 1920; adapt_params->points[1].y_ = 0;
  817 + adapt_params->points[2].x_ = 1920; adapt_params->points[2].y_ = 1080;
  818 + adapt_params->points[3].x_ = 0; adapt_params->points[3].y_ = 1080;
  819 + }
  820 + basic_params->adapt_param = adapt_params;
  821 + }
  822 +
  823 + algor_init_params->algor_param = algor_params;
  824 + algor_init_params->basic_param = basic_params;
  825 + } break;
  826 +
  827 + case algorithm_type_t::HUMAN_LINGER: {
  828 + auto algor_params = new algor_config_param_behavior;
  829 + {
  830 + algor_params->duration = 50; //帧
  831 + algor_params->minmum_width = 20;
  832 + algor_params->minmum_height = 20;
  833 + algor_params->conf_threshold = 0.5;
  834 + }
  835 +
  836 + auto basic_params = new algor_basic_config_param_t;
  837 + {
  838 + basic_params->result_folder = "res/human_linger";
  839 + basic_params->result_folder_little = "res/human_linger_little";
  840 +
  841 + auto adapt_params = new universal_algor_adapt_param;
  842 + {
  843 + adapt_params->points_count = 4; // 0表示不生效
  844 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  845 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  846 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  847 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  848 + }
  849 + basic_params->adapt_param = adapt_params;
  850 + }
  851 +
  852 + algor_init_params->algor_param = algor_params;
  853 + algor_init_params->basic_param = basic_params;
  854 + } break;
  855 + case algorithm_type_t::VEHICLE_ILLEGAL_PARKING: {
  856 + auto algor_params = new algor_config_param_behavior;
  857 + {
  858 + algor_params->duration = 25; //帧
  859 + algor_params->minmum_width = 10;
  860 + algor_params->minmum_height = 10;
  861 + }
  862 +
  863 + auto basic_params = new algor_basic_config_param_t;
  864 + {
  865 + basic_params->result_folder = "res/vehicle_parking";
  866 + basic_params->result_folder_little = "res/vehicle_parking_little";
  867 + auto adapt_params = new universal_algor_adapt_param;
  868 + {
  869 + adapt_params->points_count = 4; // 0表示不生效
  870 + adapt_params->points[0].x_ = 505; adapt_params->points[0].y_ = 481;
  871 + adapt_params->points[1].x_ = 741; adapt_params->points[1].y_ = 881;
  872 + adapt_params->points[2].x_ = 1911; adapt_params->points[2].y_ = 667;
  873 + adapt_params->points[3].x_ = 1484; adapt_params->points[3].y_ = 410;
  874 + }
  875 + basic_params->adapt_param = adapt_params;
  876 + }
  877 +
  878 + algor_init_params->algor_param = algor_params;
  879 + algor_init_params->basic_param = basic_params;
  880 + } break;
  881 +
459 882 default: {
460 883 if (algor_init_params != nullptr) {
461 884 delete algor_init_params;
... ... @@ -469,24 +892,148 @@ void set_task_params(task_param &amp;tparam, const unsigned &amp;idx, const algorithm_ty
469 892 tparam.algor_config_params[idx].algor_init_config_param = algor_init_params;
470 893 }
471 894  
  895 +
472 896 static long long get_cur_time(){
473 897 chrono::time_point<chrono::system_clock, chrono::milliseconds> tpMicro
474 898 = chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now());
475 899 return tpMicro.time_since_epoch().count();
476 900 }
477 901  
478   -string createTask(void *handle, std::vector<algorithm_type_t> algor_vec, int gi){
  902 +static int nTaskId = 0;
  903 +
  904 +string createTask(void *handle, std::vector<algorithm_type_t> algor_vec, int gi, bool bFlag = true){
479 905 task_param tparam;
480   - // tparam.ipc_url = "rtsp://admin:ad123456@192.168.60.108:554/cam/realmonitor?channel=1&subtype=0";
481   - // tparam.ipc_url = "/data1/cmhu/data/bayue.mp4";
482   - tparam.ipc_url = "/data1/cmhu/data/Street.uvf";
483   - // tparam.ipc_url = "rtsp://admin:ad123456@192.168.60.165:554/cam/realmonitor?channel=1&subtype=0";
  906 +
  907 + switch(gi){
  908 + case 0:
  909 + tparam.ipc_url = "rtsp://admin:admin@123456@192.168.60.176:554/cam/realmonitor?channel=1&subtype=0";
  910 + break;
  911 + case 1:
  912 + tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/V5nXRHa?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiMTBjZjM4N2JjY2Y5NDg3YzhjNWYzNjE2M2ViMWUyNTJ8MXwwfDEiLCJ0IjoxfQ==";
  913 + break;
  914 + case 2:
  915 + tparam.ipc_url = "rtsp://admin:ad123456@192.168.10.166:554/cam/realmonitor?channel=1&subtype=0";
  916 + break;
  917 + case 3:
  918 + tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/LBBYTra?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiOTgzYjRjMmUxMThlNGU1OTlkYThmMTI3NTkyMGViODV8MXwwfDEiLCJ0IjoxfQ==";
  919 + // tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/V5nXRHa?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiMTBjZjM4N2JjY2Y5NDg3YzhjNWYzNjE2M2ViMWUyNTJ8MXwwfDEiLCJ0IjoxfQ==";
  920 + break;
  921 + case 4:
  922 + tparam.ipc_url = "/data/share/data/Street.uvf";
  923 + break;
  924 + case 5:
  925 + tparam.ipc_url = "/data/share/data/公安局老桥头_CVR15F89410_1465819864_1B.mp4";
  926 + break;
  927 + case 6:
  928 + tparam.ipc_url = "/data/share/data/不带头盔2.mp4";
  929 + break;
  930 + case 7:
  931 + tparam.ipc_url = "/data/share/data/hczr1.mp4";
  932 + break;
  933 + case 8:
  934 + tparam.ipc_url = "/data/share/data/燕高路口高点_CVR_2015-12-30_09-00-00_2015-12-30.mp4";
  935 + break;
  936 + case 9:
  937 + // tparam.ipc_url = "/opt/share/data/1-00000002d55_h265.mp4";
  938 + tparam.ipc_url = "/data/share/data/duan1.mp4";
  939 + break;
  940 + case 10:
  941 + tparam.ipc_url = "/data/share/data/gs1-00000001.mp4";
  942 + break;
  943 + case 11:
  944 + tparam.ipc_url = "/data/share/data/98.mp4";
  945 + break;
  946 + case 12:
  947 + tparam.ipc_url = "/data/share/data/AV_12345_1_20230108110849847_D_1673147329847729.mp4";
  948 + break;
  949 + case 13:
  950 + tparam.ipc_url = "/data/share/data/nx_1-00000002.mp4";
  951 + break;
  952 + case 14:
  953 + tparam.ipc_url = "/data/share/data/nx1-0000001.mp4";
  954 + break;
  955 + case 15:
  956 + tparam.ipc_url = "/data/share/data/nx1-00000002.mp4";
  957 + break;
  958 + case 16:
  959 + tparam.ipc_url = "/data/share/data/Street.uvf";
  960 + break;
  961 + case 17:
  962 + tparam.ipc_url = "/data/share/data/xiancun.mp4";
  963 + break;
  964 + case 18:
  965 + tparam.ipc_url = "rtsp://192.168.60.146:8554/w_1_out";
  966 + break;
  967 + case 19:
  968 + tparam.ipc_url = "/data/share/data/42_44.avi";
  969 + break;
  970 + case 20:
  971 + tparam.ipc_url = "/data/share/data/37_70.avi";
  972 + break;
  973 + case 21:
  974 + tparam.ipc_url = "/data/share/data/192_25.avi";
  975 + break;
  976 + case 22:
  977 + tparam.ipc_url = "/data/share/data/31_4.avi";
  978 + break;
  979 + case 23:
  980 + tparam.ipc_url = "/data/share/data/146_192.avi";
  981 + break;
  982 + case 24:
  983 + tparam.ipc_url = "/data/share/data/146_187.mp4";
  984 + break;
  985 + case 25:
  986 + // 公安内网
  987 + tparam.ipc_url = "rtsp://192.168.51.200:8554/320202202308231001001002";
  988 + break;
  989 + case 26:
  990 + // FFmpeg生成的解码错误数据流
  991 + tparam.ipc_url = "rtsp://192.168.10.4:8554/street";
  992 + break;
  993 + case 27:
  994 + tparam.ipc_url = "/data/share/data/Street_4k_265.mp4";
  995 + break;
  996 + case 28:
  997 + tparam.ipc_url = "http://192.168.60.179:10016/公安局老桥头_CVR15F89410_1465819864_1B.mp4";
  998 + break;
  999 + case 29:
  1000 + tparam.ipc_url = "http://192.168.60.179:10016/不带头盔2.mp4";
  1001 + break;
  1002 + case 30:
  1003 + tparam.ipc_url = "/data/share/data/149_45.avi";
  1004 + break;
  1005 + case 31:
  1006 + tparam.ipc_url = "/data/share/data/146_88.avi";
  1007 + break;
  1008 + case 32:
  1009 + tparam.ipc_url = "/data/share/data/141_74.avi";
  1010 + break;
  1011 + case 33:
  1012 + tparam.ipc_url = "/data/share/data/human_gather.mp4";
  1013 + break;
  1014 + case 34:
  1015 + tparam.ipc_url = "/data/share/data/12.mp4";
  1016 + break;
  1017 + case 35:
  1018 + tparam.ipc_url = "/data/cmhu/data/铁路文化宫-门口1_20D40580_1607648331.avi";
  1019 + break;
  1020 + default:
  1021 + tparam.ipc_url = "/opt/share/data/Street.uvf";
  1022 + break;
  1023 + }
  1024 +
484 1025 tparam.algor_counts = algor_vec.size();
485 1026 tparam.dec_type = 2;
486 1027  
487   - std::string task_id_str = "test_task_id_" + std::to_string(gi);
  1028 + if (bFlag){
  1029 + nTaskId = gi;
  1030 + }
  1031 +
  1032 + std::string task_id_str = "test_task_id_" + std::to_string(nTaskId);
488 1033 tparam.task_id = task_id_str.c_str();
489 1034  
  1035 + nTaskId++;
  1036 +
490 1037 tparam.algor_config_params = new algor_config_param[tparam.algor_counts];
491 1038  
492 1039 for (size_t idx = 0; idx < algor_vec.size(); ++idx)
... ... @@ -496,13 +1043,151 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi)
496 1043 if (result_code != 0)
497 1044 printf("[Error]: ");
498 1045 printf("--- task_id: %s result code: %d\n", tparam.task_id, result_code);
  1046 +
  1047 +
  1048 + // 释放参数
  1049 + for (size_t idx = 0; idx < algor_vec.size(); ++idx) {
  1050 + if(tparam.algor_config_params[idx].algor_type == algorithm_type_t::VIDEO_TIMING_SNAPSHOT) {
  1051 + algor_config_param_road_work* algor_param = (algor_config_param_road_work*)tparam.algor_config_params[idx].algor_init_config_param->algor_param;
  1052 + delete algor_param;
  1053 + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)tparam.algor_config_params[idx].algor_init_config_param->basic_param;
  1054 + delete basic_param;
  1055 +
  1056 + algor_init_config_param_t* config_param = tparam.algor_config_params[idx].algor_init_config_param;
  1057 + delete config_param;
  1058 + } else if(tparam.algor_config_params[idx].algor_type == algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) {
  1059 + algor_config_param_manned_incident* algor_param = (algor_config_param_manned_incident*)tparam.algor_config_params[idx].algor_init_config_param->algor_param;
  1060 + delete algor_param;
  1061 + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)tparam.algor_config_params[idx].algor_init_config_param->basic_param;
  1062 + delete basic_param;
  1063 +
  1064 + algor_init_config_param_t* config_param = tparam.algor_config_params[idx].algor_init_config_param;
  1065 + delete config_param;
  1066 + }else if(tparam.algor_config_params[idx].algor_type == algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) {
  1067 + algor_config_param_manned_incident* algor_param = (algor_config_param_manned_incident*)tparam.algor_config_params[idx].algor_init_config_param->algor_param;
  1068 + delete algor_param;
  1069 + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)tparam.algor_config_params[idx].algor_init_config_param->basic_param;
  1070 + delete basic_param;
  1071 +
  1072 + algor_init_config_param_t* config_param = tparam.algor_config_params[idx].algor_init_config_param;
  1073 + delete config_param;
  1074 + }
  1075 + }
  1076 + delete[] tparam.algor_config_params;
  1077 +
499 1078 return task_id_str;
500 1079 }
501 1080  
  1081 +
  1082 +string createTask_dvpp28181(void *handle, std::vector<algorithm_type_t> algor_vec, int gi, bool bFlag = true){
  1083 + task_param tparam;
  1084 +
  1085 + switch(gi){
  1086 + case 0:
  1087 + tparam.ipc_url = "34020000001310004065";
  1088 + break;
  1089 + case 1:
  1090 + tparam.ipc_url = "34020000001310000001";
  1091 + break;
  1092 + case 2:
  1093 + tparam.ipc_url = "34020000001320000166";
  1094 + break;
  1095 + case 3:
  1096 + tparam.ipc_url = "32120200002160000077";
  1097 + break;
  1098 + case 4:
  1099 + tparam.ipc_url = "34020000001320000207";
  1100 + break;
  1101 + case 5:
  1102 + tparam.ipc_url = "34020000001310000176";
  1103 + break;
  1104 + default:
  1105 + tparam.ipc_url = "34020000001310004065";
  1106 + break;
  1107 + }
  1108 +
  1109 + tparam.algor_counts = algor_vec.size();
  1110 + tparam.dec_type = 3;
  1111 + tparam.protocal = 0;
  1112 +
  1113 + if (bFlag){
  1114 + nTaskId = gi;
  1115 + }
  1116 +
  1117 + std::string task_id_str = "test_task_id_" + std::to_string(nTaskId);
  1118 + tparam.task_id = task_id_str.c_str();
  1119 +
  1120 + nTaskId++;
  1121 +
  1122 + tparam.algor_config_params = new algor_config_param[tparam.algor_counts];
  1123 +
  1124 + for (size_t idx = 0; idx < algor_vec.size(); ++idx)
  1125 + set_task_params(tparam, idx, algor_vec.at(idx));
  1126 +
  1127 + const int result_code = add_task(handle, tparam);
  1128 + if (result_code != 0)
  1129 + printf("[Error]: ");
  1130 + printf("--- task_id: %s result code: %d\n", tparam.task_id, result_code);
  1131 +
  1132 +
  1133 + // 释放参数
  1134 + for (size_t idx = 0; idx < algor_vec.size(); ++idx) {
  1135 + if(tparam.algor_config_params[idx].algor_type == algorithm_type_t::VIDEO_TIMING_SNAPSHOT) {
  1136 + algor_config_param_road_work* algor_param = (algor_config_param_road_work*)tparam.algor_config_params[idx].algor_init_config_param->algor_param;
  1137 + delete algor_param;
  1138 + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)tparam.algor_config_params[idx].algor_init_config_param->basic_param;
  1139 + delete basic_param;
  1140 +
  1141 + algor_init_config_param_t* config_param = tparam.algor_config_params[idx].algor_init_config_param;
  1142 + delete config_param;
  1143 + } else if(tparam.algor_config_params[idx].algor_type == algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) {
  1144 + algor_config_param_manned_incident* algor_param = (algor_config_param_manned_incident*)tparam.algor_config_params[idx].algor_init_config_param->algor_param;
  1145 + delete algor_param;
  1146 + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)tparam.algor_config_params[idx].algor_init_config_param->basic_param;
  1147 + delete basic_param;
  1148 +
  1149 + algor_init_config_param_t* config_param = tparam.algor_config_params[idx].algor_init_config_param;
  1150 + delete config_param;
  1151 + } else if(tparam.algor_config_params[idx].algor_type == algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) {
  1152 + algor_config_param_manned_incident* algor_param = (algor_config_param_manned_incident*)tparam.algor_config_params[idx].algor_init_config_param->algor_param;
  1153 + delete algor_param;
  1154 + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)tparam.algor_config_params[idx].algor_init_config_param->basic_param;
  1155 + delete basic_param;
  1156 +
  1157 + algor_init_config_param_t* config_param = tparam.algor_config_params[idx].algor_init_config_param;
  1158 + delete config_param;
  1159 + }
  1160 + }
  1161 + delete[] tparam.algor_config_params;
  1162 +
  1163 + return task_id_str;
  1164 +}
  1165 +
  1166 +void test_snapshot(void *handle){
  1167 + task_param tparam;
  1168 + tparam.ipc_url = "rtsp://admin:ad123456@192.168.60.165:554/cam/realmonitor?channel=1&subtype=0";
  1169 +
  1170 + tparam.algor_counts = 1;
  1171 + tparam.dec_type = 2;
  1172 +
  1173 + std::string task_id_str = "test_task_id_default" ;
  1174 + tparam.task_id = task_id_str.c_str();
  1175 +
  1176 + tparam.algor_config_params = new algor_config_param[tparam.algor_counts];
  1177 +
  1178 + set_task_params(tparam, 0, algorithm_type_t::VIDEO_SNAPSHOT);
  1179 +
  1180 + const int result_code = screenshot_task(handle, tparam);
  1181 + if (result_code != 0)
  1182 + printf("[Error]: ");
  1183 + printf("--- task_id: %s result code: %d\n", tparam.task_id, result_code);
  1184 +}
  1185 +
502 1186 void test_gpu(int gpuID){
503 1187 tsl_aiplatform_param vptParam;
504 1188 vptParam.gpuid = gpuID;
505 1189 vptParam.trt_serialize_file = "";
  1190 + vptParam.models_dir = ".";
506 1191  
507 1192 vptParam.log_days = 1;
508 1193 vptParam.log_level = AI_LOG_LEVEL_TRACE;
... ... @@ -521,16 +1206,222 @@ void test_gpu(int gpuID){
521 1206 printf("Init Success\n");
522 1207 }
523 1208  
  1209 +#ifdef POST_USE_RABBITMQ
  1210 + init_mq_conn(handle);
  1211 +#endif // #ifdef POST_USE_RABBITMQ
  1212 +
524 1213 std::vector<algorithm_type_t> algor_vec = {algorithm_type_t::FACE_SNAPSHOT, algorithm_type_t::HUMAN_SNAPSHOT,algorithm_type_t::ROAD_WORK_DET, algorithm_type_t::PEDESTRIAN_RETROGRADE, algorithm_type_t::VEHICLE_RETROGRADE,
525   - algorithm_type_t::PEDESTRIAN_TRESPASS, algorithm_type_t::VEHICLE_TRESPASS, algorithm_type_t::VEHICLE_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT, algorithm_type_t::VIDEO_TIMING_SNAPSHOT};
  1214 + algorithm_type_t::PEDESTRIAN_TRESPASS, algorithm_type_t::VEHICLE_TRESPASS, algorithm_type_t::VEHICLE_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT, algorithm_type_t::VIDEO_TIMING_SNAPSHOT
  1215 + , algorithm_type_t::VIDEO_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED};
  1216 +
  1217 +
  1218 + std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE,
  1219 + algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS, algorithm_type_t::PERSON_IN_VEHICLELANE, algorithm_type_t::NONMOTOR_IN_VEHICLELANE,
  1220 + algorithm_type_t::NONMOTOR_CEOSSPARKLINE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY,
  1221 + algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND, algorithm_type_t::VEHICLE_NOTDECELERATION};
526 1222  
527   - string task_id = createTask(handle, algor_vec, 0 + gpuID * 10);
528   - // string task_id1 = createTask(handle, algor_vec, 1 + gpuID * 10);
529   - // string task_id2 = createTask(handle, algor_vec, 2 + gpuID * 10);
  1223 + std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY,
  1224 + algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND};
  1225 +
  1226 + std::vector<algorithm_type_t> algor_vec_human = {algorithm_type_t::HUMAN_SNAPSHOT, algorithm_type_t::VIDEO_TIMING_SNAPSHOT, algorithm_type_t::FACE_SNAPSHOT, algorithm_type_t::HUMAN_GATHER, algorithm_type_t::HUMAN_REGION_GATHER
  1227 + ,algorithm_type_t::HUMAN_DENSITY,algorithm_type_t::HUMAN_LINGER, algorithm_type_t::HUMAN_REGION_FAST_MOVING, algorithm_type_t::HUMAN_REGION_DISMISS, algorithm_type_t::HUMAN_CLIMB, algorithm_type_t::HUMAN_CROSSING_LINE
  1228 + , algorithm_type_t::HUMAN_LEAVE_REGION};
  1229 +
  1230 + std::vector<algorithm_type_t> algor_vec_car = {algorithm_type_t::VEHICLE_SNAPSHOT, algorithm_type_t::VEHICLE_TRESPASS, algorithm_type_t::VEHICLE_GATHER, algorithm_type_t::VEHICLE_ILLEGAL_PARKING
  1231 + ,algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE};
  1232 +
  1233 + std::vector<algorithm_type_t> algor_wenhuagong = {algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT, algorithm_type_t::VEHICLE_TRESPASS,algorithm_type_t::VEHICLE_SNAPSHOT,algorithm_type_t::VEHICLE_GATHER,algorithm_type_t::VEHICLE_ILLEGAL_PARKING,algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE
  1234 + ,algorithm_type_t::HUMAN_GATHER, algorithm_type_t::FACE_SNAPSHOT, algorithm_type_t::HUMAN_LEAVE_REGION, algorithm_type_t::HUMAN_REGION_DISMISS, algorithm_type_t::HUMAN_REGION_FAST_MOVING, algorithm_type_t::HUMAN_SNAPSHOT, algorithm_type_t::HUMAN_REGION_GATHER, algorithm_type_t::HUMAN_DENSITY, algorithm_type_t::HUMAN_CROSSING_LINE, algorithm_type_t::HUMAN_CLIMB, algorithm_type_t::HUMAN_LINGER
  1235 + };
  1236 +
  1237 + // int repeat_num = 1000;
  1238 + // createTask(handle, algor_vec2, 0, false);
  1239 + // createTask(handle, algor_vec2, 2, false);
  1240 + // while(repeat_num--) {
  1241 + // printf("============================:%d\n",repeat_num);
  1242 + // vector<string> task_ids;
  1243 + // for (int i = 4; i < 10; i ++) {
  1244 + // string task_id = createTask(handle, algor_vec2, i, false);
  1245 + // task_ids.push_back(task_id);
  1246 + // }
  1247 +
  1248 + // // test_snapshot(handle);
  1249 + // sleep(60); //60s
  1250 + // close_all_task(handle);
  1251 + // for (auto& task_id : task_ids) {
  1252 + // finish_task(handle, (char*)task_id.data(), 0);
  1253 + // sleep(5);
  1254 + // }
  1255 +
  1256 + // }
  1257 +
  1258 + // createTask(handle, algor_vec2, 19, false);
  1259 + // createTask(handle, algor_vec2, 20, false);
  1260 + // createTask(handle, algor_vec2, 21, false);
  1261 + // createTask(handle, algor_vec2, 22, false);
  1262 + // createTask(handle, algor_vec2, 23, false);
  1263 + // createTask(handle, algor_vec2, 24, false);
  1264 + // createTask(handle, algor_vec2, 30, false);
  1265 + // createTask(handle, algor_vec2, 31, false);
  1266 +
  1267 + // createTask(handle, algor_vec_human, 33, false);
  1268 +
  1269 + createTask(handle, algor_wenhuagong, 35, false);
  1270 +
  1271 + // int task_index = 0;
  1272 + // while (true)
  1273 + // {
  1274 + // int task_count = count_running_task(handle);
  1275 + // if (task_count < 1)
  1276 + // {
  1277 + // // if (task_index > 7)
  1278 + // // {
  1279 + // // task_index = 0;
  1280 + // // break;
  1281 + // // }
  1282 +
  1283 + // createTask(handle, algor_vec2, 19, false);
  1284 + // task_index++;
  1285 + // // createTask(handle, algor_vec2, 29, false);
  1286 + // // task_index++;
  1287 + // }
  1288 +
  1289 + // std::this_thread::sleep_for(std::chrono::seconds(5));
  1290 + // }
  1291 +
  1292 +
  1293 +
  1294 + // char ch = 'a';
  1295 + // while (ch != 'q') {
  1296 + // ch = getchar();
  1297 + // switch (ch)
  1298 + // {
  1299 + // case 'a':
  1300 + // createTask(handle, algor_vec2, 28, false);
  1301 + // break;
  1302 + // case 'c':
  1303 + // close_all_task(handle);
  1304 + // break;
  1305 + // default:
  1306 + // break;
  1307 + // }
  1308 +
  1309 + // }
  1310 +
  1311 + // finish_task(handle, (char*)task_id.data(), 0);
  1312 +
  1313 + // finish_task(handle, (char*)task_id1.data(), 0);
530 1314  
531 1315 while (getchar() != 'q');
  1316 +
  1317 + tsl_aiplatform_release(&handle);
  1318 +}
  1319 +
  1320 +void test_dvpp28181(int gpuID) {
  1321 + tsl_aiplatform_param vptParam;
  1322 + vptParam.gpuid = gpuID;
  1323 + vptParam.sip_server_port = 15080;
  1324 + vptParam.trt_serialize_file = "";
  1325 + vptParam.models_dir = ".";
  1326 +
  1327 + vptParam.log_days = 1;
  1328 + vptParam.log_level = AI_LOG_LEVEL_TRACE;
  1329 + // vptParam.log_level = AI_LOG_LEVEL_DEBUG;
  1330 + vptParam.log_mem = 64 * 1024 * 1024; // 64MB.
  1331 + vptParam.log_path = "logs/main.log";
  1332 + vptParam.vpt_thred = 0.45;
  1333 + vptParam.rblock_thred = 0.4;
  1334 +
  1335 + void *handle;
  1336 + int flag = tsl_aiplatform_init(&handle, vptParam);
  1337 + if (0 != flag) {
  1338 + printf("Init Failed! Error Code: %d\n", flag);
  1339 + return;
  1340 + } else {
  1341 + printf("Init Success\n");
  1342 + }
  1343 +
  1344 +#ifdef POST_USE_RABBITMQ
  1345 +init_mq_conn(handle);
  1346 +#endif // #ifdef POST_USE_RABBITMQ
  1347 +
  1348 + std::vector<algorithm_type_t> algor_vec = {algorithm_type_t::FACE_SNAPSHOT, algorithm_type_t::HUMAN_SNAPSHOT,algorithm_type_t::ROAD_WORK_DET, algorithm_type_t::PEDESTRIAN_RETROGRADE, algorithm_type_t::VEHICLE_RETROGRADE,
  1349 + algorithm_type_t::PEDESTRIAN_TRESPASS, algorithm_type_t::VEHICLE_TRESPASS, algorithm_type_t::VEHICLE_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT, algorithm_type_t::VIDEO_TIMING_SNAPSHOT
  1350 + , algorithm_type_t::VIDEO_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED};
  1351 +
  1352 +
  1353 + std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE,
  1354 + algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS, algorithm_type_t::PERSON_IN_VEHICLELANE, algorithm_type_t::NONMOTOR_IN_VEHICLELANE,
  1355 + algorithm_type_t::NONMOTOR_CEOSSPARKLINE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY,
  1356 + algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND, algorithm_type_t::VEHICLE_NOTDECELERATION};
  1357 + // std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE,
  1358 + // algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS};
  1359 + std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY,
  1360 + algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND};
  1361 +
  1362 +
  1363 +
  1364 + int status = -1;
  1365 + while (true)
  1366 + {
  1367 + status = get_task_status(handle,"34020000001320000207");
  1368 + if (status == 0)
  1369 + {
  1370 + createTask_dvpp28181(handle, algor_vec, 4, false);
  1371 + }
532 1372  
533   - finish_task(handle, (char*)task_id.data(), 0);
  1373 + status = get_task_status(handle,"34020000001310000176");
  1374 + if (status == 0)
  1375 + {
  1376 + createTask_dvpp28181(handle, algor_vec, 5, false);
  1377 + }
  1378 +
  1379 + std::this_thread::sleep_for(std::chrono::seconds(5));
  1380 + }
  1381 +
  1382 +
  1383 +
  1384 +char ch = 'a';
  1385 +while (ch != 'q') {
  1386 + ch = getchar();
  1387 + switch (ch)
  1388 + {
  1389 + case '0':
  1390 + createTask_dvpp28181(handle, algor_vec, 0, false);
  1391 + break;
  1392 + case '1':
  1393 + createTask_dvpp28181(handle, algor_vec, 1, false);
  1394 + break;
  1395 + case '2':
  1396 + createTask_dvpp28181(handle, algor_vec, 2, false);
  1397 + break;
  1398 + case '3':
  1399 + createTask_dvpp28181(handle, algor_vec, 3, false);
  1400 + break;
  1401 + case '4':
  1402 + createTask_dvpp28181(handle, algor_vec, 4, false);
  1403 + break;
  1404 + case '5':
  1405 + createTask_dvpp28181(handle, algor_vec, 5, false);
  1406 + break;
  1407 + case '6':
  1408 + createTask(handle, algor_vec2, 2, false);
  1409 + break;
  1410 + case '7':
  1411 + createTask(handle, algor_vec2, 0, false);
  1412 + break;
  1413 + case 'c':
  1414 + close_all_task(handle);
  1415 + break;
  1416 + default:
  1417 + break;
  1418 + }
  1419 +
  1420 +}
  1421 +
  1422 + // finish_task(handle, (char*)task_id.data(), 0);
  1423 +
  1424 + // finish_task(handle, (char*)task_id1.data(), 0);
534 1425  
535 1426 tsl_aiplatform_release(&handle);
536 1427 }
... ... @@ -538,23 +1429,23 @@ void test_gpu(int gpuID){
538 1429 int main(int argc, char *argv[]) {
539 1430 printf("new test\n");
540 1431  
541   - if (argc < 4) {
542   - fprintf(stderr, "./xxx 0 2 10 1 ## [start_ai_id, end_ai_id) repeat_num gpu_id\n");
543   - return -1;
544   - }
  1432 + // if (argc < 4) {
  1433 + // fprintf(stderr, "./xxx 0 2 10 1 ## [start_ai_id, end_ai_id) repeat_num gpu_id\n");
  1434 + // return -1;
  1435 + // }
545 1436  
546   - //! load params.
547   - int start_id = atoi(argv[1]);
548   - int end_id = atoi(argv[2]);
549   - int repeat_num = atoi(argv[3]);
550   - int gpuID = atoi(argv[4]);
  1437 + // //! load params.
  1438 + // int start_id = atoi(argv[1]);
  1439 + // int end_id = atoi(argv[2]);
  1440 + // int repeat_num = atoi(argv[3]);
  1441 + // int gpuID = atoi(argv[4]);
551 1442  
552 1443 test_gpu(0);
553 1444 // test_gpu(1);
554 1445 // test_gpu(2);
555 1446 // test_gpu(3);
556 1447  
557   - while (getchar() != 'q');
  1448 + // test_dvpp28181(0);
558 1449  
559 1450 printf("Done.\n");
560 1451  
... ...
src/readme.txt
... ... @@ -18,6 +18,22 @@
18 18 注意事项说明:
19 19 - 当前版本跟踪前三帧无结果输出
20 20  
21   -中科院自动化所 模式识别实验室图像视频组
22 21  
23   -2023年03月16日
24 22 \ No newline at end of file
  23 +### ffmpeg编译
  24 +~~~
  25 +./configure --enable-debug --extra-cflags=-g --extra-ldflags=-g --disable-optimizations --disable-stripping --disable-x86asm --enable-nonfree --disable-vaapi --extra-cflags=-fPIC --enable-shared --enable-pic --enable-ffplay --prefix=./release
  26 +~~~
  27 +其中以下是用于调试的,编译release可以去掉:
  28 +~~~
  29 +--enable-debug --extra-cflags=-g --extra-ldflags=-g --disable-optimizations --disable-stripping
  30 +~~~
  31 +然后 make , make install
  32 +
  33 +### jsoncpp/opencv/spdlog 编译
  34 +~~~
  35 +mkdir build
  36 +cd ./build
  37 +cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=../release -D BUILD_opencv_world=ON -D WITH_CUDA=OFF -D WITH_CUDNN=OFF -D BUILD_opencv_ml=OFF -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.4/modules ..
  38 +make -j
  39 +make install
  40 +~~~
25 41 \ No newline at end of file
... ...
src/reprocessing_module/save_snapshot_reprocessing.h
... ... @@ -42,6 +42,7 @@ public:
42 42 void save_snapshot_reprocessing_release();
43 43  
44 44 #ifdef POST_USE_RABBITMQ
  45 + typedef std::function<bool(const char *msg)> callback_t;
45 46 void set_callback(callback_t cb);
46 47 #endif
47 48  
... ...