From d9483d645351ada0f400055be8c89580597c38ba Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Mon, 6 Nov 2023 16:16:24 +0800 Subject: [PATCH] 代码优化,没有修改逻辑 --- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp | 22 ++-------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp | 21 +++++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h | 11 +++++++---- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp index d3cdfbd..8500801 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp @@ -791,27 +791,9 @@ void CMutliSourceVideoProcess::algorthim_process() delete tasks[i].taskTcuvid; tasks[i].taskTcuvid = NULL; - int taskid = tasks[i].taskID; - std::unique_lock lock(m_snaphot_helper.analysisThreadMutex); - while (std::find_if(m_snaphot_helper.finished_analysis_ss_info.begin(), m_snaphot_helper.finished_analysis_ss_info.end(), [&taskid](const std::pair & item) ->bool { - if (item.first.videoID == taskid) - { - return true; - } - else - { - return false; - } - - }) != m_snaphot_helper.finished_analysis_ss_info.end()) - { - lock.unlock(); - std::this_thread::yield(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - lock.lock(); - } + m_snaphot_helper.waitSaveAnalysisInfo(tasks[i].taskID); - //�ص�֪ͨ�û� ��·����������� + //回调通知上层任务结束 if (taskFinishCallbackFunc != nullptr) { std::lock_guard l(m_snaphot_helper.callback_tx); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp index 6a23deb..65a5e23 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp @@ -1884,6 +1884,27 @@ void snapshot_helper::snapshot_thread_process() return ; } +void snapshot_helper::waitSaveAnalysisInfo(int taskid) { + std::unique_lock lock(analysisThreadMutex); + while (std::find_if(finished_analysis_ss_info.begin(), finished_analysis_ss_info.end(), [&taskid](const std::pair & item) ->bool { + if (item.first.videoID == taskid) + { + return true; + } + else + { + return false; + } + + }) != finished_analysis_ss_info.end()) + { + lock.unlock(); + std::this_thread::yield(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + lock.lock(); + } +} + int snapshot_helper::save_snapshot(bool is_image, bool on_image_display, OBJ_KEY obj_key, char* filename, char* mode, float* imgData, int width, int height, int taskID, int objID, int recFlag, int left = 0, int top = 0, int right = 0, int bottom = 0) { if (recFlag) diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h index 3695732..10e325f 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h @@ -155,7 +155,7 @@ public: public: std::mutex callback_tx; queue snapshotImageQueue; - map finished_analysis_ss_info; + queue finished_save_ss_info_que; set finished_save_ss_info; unordered_map m_task_info; @@ -163,10 +163,8 @@ public: std::deque cur_image_queue; std::mutex threadMutex; std::mutex writeThreadMutex; - std::mutex analysisThreadMutex; std::mutex finishedThreadMutex; - //std::condition_variable writeThreadCondVar; - //VC_ANALYSIS_TYPE vc_analysis; + V_ANALYSIS_TYPE v_analysis; void snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, sy_command hp_analysis_config, \ sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command vehicle_recg_config, sy_command vehicle_plate_det_recg_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config, sy_command face_detect_config); @@ -202,6 +200,8 @@ public: void clearSnapshotInfo(); + void waitSaveAnalysisInfo(int taskid); + private: int save_snapshot(bool is_image, bool on_image_display, OBJ_KEY obj_key, char* filename, char* mode, float* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom); int save_snapshot(bool is_image, bool on_image_display, OBJ_KEY obj_key, char* filename, char* mode, unsigned char* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom); @@ -260,4 +260,7 @@ private: std::thread* ProcessSnapshotThread; std::vector m_vec_writeThread; bool m_bExit {false}; + + map finished_analysis_ss_info; + std::mutex analysisThreadMutex; }; \ No newline at end of file -- libgit2 0.21.4