Commit d9483d645351ada0f400055be8c89580597c38ba

Authored by Hu Chunming
1 parent 080131b6

代码优化,没有修改逻辑

vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp
@@ -791,27 +791,9 @@ void CMutliSourceVideoProcess::algorthim_process() @@ -791,27 +791,9 @@ void CMutliSourceVideoProcess::algorthim_process()
791 delete tasks[i].taskTcuvid; 791 delete tasks[i].taskTcuvid;
792 tasks[i].taskTcuvid = NULL; 792 tasks[i].taskTcuvid = NULL;
793 793
794 - int taskid = tasks[i].taskID;  
795 - std::unique_lock<std::mutex> lock(m_snaphot_helper.analysisThreadMutex);  
796 - while (std::find_if(m_snaphot_helper.finished_analysis_ss_info.begin(), m_snaphot_helper.finished_analysis_ss_info.end(), [&taskid](const std::pair<OBJ_KEY, video_object_snapshot> & item) ->bool {  
797 - if (item.first.videoID == taskid)  
798 - {  
799 - return true;  
800 - }  
801 - else  
802 - {  
803 - return false;  
804 - }  
805 -  
806 - }) != m_snaphot_helper.finished_analysis_ss_info.end())  
807 - {  
808 - lock.unlock();  
809 - std::this_thread::yield();  
810 - std::this_thread::sleep_for(std::chrono::milliseconds(100));  
811 - lock.lock();  
812 - } 794 + m_snaphot_helper.waitSaveAnalysisInfo(tasks[i].taskID);
813 795
814 - //�ص�֪ͨ�û� ��·����������� 796 + //回调通知上层任务结束
815 if (taskFinishCallbackFunc != nullptr) 797 if (taskFinishCallbackFunc != nullptr)
816 { 798 {
817 std::lock_guard<std::mutex> l(m_snaphot_helper.callback_tx); 799 std::lock_guard<std::mutex> l(m_snaphot_helper.callback_tx);
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp
@@ -1884,6 +1884,27 @@ void snapshot_helper::snapshot_thread_process() @@ -1884,6 +1884,27 @@ void snapshot_helper::snapshot_thread_process()
1884 return ; 1884 return ;
1885 } 1885 }
1886 1886
  1887 +void snapshot_helper::waitSaveAnalysisInfo(int taskid) {
  1888 + std::unique_lock<std::mutex> lock(analysisThreadMutex);
  1889 + while (std::find_if(finished_analysis_ss_info.begin(), finished_analysis_ss_info.end(), [&taskid](const std::pair<OBJ_KEY, video_object_snapshot> & item) ->bool {
  1890 + if (item.first.videoID == taskid)
  1891 + {
  1892 + return true;
  1893 + }
  1894 + else
  1895 + {
  1896 + return false;
  1897 + }
  1898 +
  1899 + }) != finished_analysis_ss_info.end())
  1900 + {
  1901 + lock.unlock();
  1902 + std::this_thread::yield();
  1903 + std::this_thread::sleep_for(std::chrono::milliseconds(100));
  1904 + lock.lock();
  1905 + }
  1906 +}
  1907 +
1887 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) 1908 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)
1888 { 1909 {
1889 if (recFlag) 1910 if (recFlag)
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h
@@ -155,7 +155,7 @@ public: @@ -155,7 +155,7 @@ public:
155 public: 155 public:
156 std::mutex callback_tx; 156 std::mutex callback_tx;
157 queue<SNAPSHOT_IMAGE_UNIT> snapshotImageQueue; 157 queue<SNAPSHOT_IMAGE_UNIT> snapshotImageQueue;
158 - map<OBJ_KEY, video_object_snapshot> finished_analysis_ss_info; 158 +
159 queue<OBJ_KEY> finished_save_ss_info_que; 159 queue<OBJ_KEY> finished_save_ss_info_que;
160 set<OBJ_KEY> finished_save_ss_info; 160 set<OBJ_KEY> finished_save_ss_info;
161 unordered_map<int, TASK_INFO> m_task_info; 161 unordered_map<int, TASK_INFO> m_task_info;
@@ -163,10 +163,8 @@ public: @@ -163,10 +163,8 @@ public:
163 std::deque<SNAPSHOT_IMAGE_UNIT> cur_image_queue; 163 std::deque<SNAPSHOT_IMAGE_UNIT> cur_image_queue;
164 std::mutex threadMutex; 164 std::mutex threadMutex;
165 std::mutex writeThreadMutex; 165 std::mutex writeThreadMutex;
166 - std::mutex analysisThreadMutex;  
167 std::mutex finishedThreadMutex; 166 std::mutex finishedThreadMutex;
168 - //std::condition_variable writeThreadCondVar;  
169 - //VC_ANALYSIS_TYPE vc_analysis; 167 +
170 V_ANALYSIS_TYPE v_analysis; 168 V_ANALYSIS_TYPE v_analysis;
171 void snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, sy_command hp_analysis_config, \ 169 void snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, sy_command hp_analysis_config, \
172 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); 170 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: @@ -202,6 +200,8 @@ public:
202 200
203 void clearSnapshotInfo(); 201 void clearSnapshotInfo();
204 202
  203 + void waitSaveAnalysisInfo(int taskid);
  204 +
205 private: 205 private:
206 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); 206 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);
207 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); 207 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: @@ -260,4 +260,7 @@ private:
260 std::thread* ProcessSnapshotThread; 260 std::thread* ProcessSnapshotThread;
261 std::vector<std::thread*> m_vec_writeThread; 261 std::vector<std::thread*> m_vec_writeThread;
262 bool m_bExit {false}; 262 bool m_bExit {false};
  263 +
  264 + map<OBJ_KEY, video_object_snapshot> finished_analysis_ss_info;
  265 + std::mutex analysisThreadMutex;
263 }; 266 };
264 \ No newline at end of file 267 \ No newline at end of file