Commit 6d6c8a18e57fa530dc0d6576b4694b67a657e711
1 parent
f340e7ff
优化线程创建,使更便于多路运行
Showing
2 changed files
with
24 additions
and
13 deletions
tsl_aiplatform/reprocessing_module/save_snapshot_reprocessing.cpp
@@ -8,9 +8,8 @@ | @@ -8,9 +8,8 @@ | ||
8 | 8 | ||
9 | const bool DRAW_ON_IMG = false; | 9 | const bool DRAW_ON_IMG = false; |
10 | 10 | ||
11 | -vector<int> compression_params; | ||
12 | DWORD save_image_thread_process(LPVOID param); | 11 | DWORD save_image_thread_process(LPVOID param); |
13 | -bool bFinish = false; | 12 | + |
14 | 13 | ||
15 | map<int, algo_type> index_to_algo_type = {{0, algorithm_type_t::HUMAN_SNAPSHOT}, | 14 | map<int, algo_type> index_to_algo_type = {{0, algorithm_type_t::HUMAN_SNAPSHOT}, |
16 | {1, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, | 15 | {1, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, |
@@ -29,7 +28,7 @@ save_snapshot_reprocessing::save_snapshot_reprocessing() { | @@ -29,7 +28,7 @@ save_snapshot_reprocessing::save_snapshot_reprocessing() { | ||
29 | callback_ = nullptr; | 28 | callback_ = nullptr; |
30 | #endif | 29 | #endif |
31 | 30 | ||
32 | - compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); | 31 | + compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); |
33 | compression_params.push_back(30); | 32 | compression_params.push_back(30); |
34 | 33 | ||
35 | _snapshot_reprocessing = snapshot_reprocessing::getInstance(); | 34 | _snapshot_reprocessing = snapshot_reprocessing::getInstance(); |
@@ -326,21 +325,28 @@ void save_snapshot_reprocessing::reprocessing_process_face(const OBJ_KEY &obj_ke | @@ -326,21 +325,28 @@ void save_snapshot_reprocessing::reprocessing_process_face(const OBJ_KEY &obj_ke | ||
326 | } | 325 | } |
327 | } | 326 | } |
328 | 327 | ||
329 | -// 快照保存子线程 依次从缓存队列中取数据 然后保存图片 然后MQ返回结果 | ||
330 | DWORD save_image_thread_process(LPVOID param) { | 328 | DWORD save_image_thread_process(LPVOID param) { |
331 | save_snapshot_reprocessing *pThreadParam = (save_snapshot_reprocessing *)param; | 329 | save_snapshot_reprocessing *pThreadParam = (save_snapshot_reprocessing *)param; |
330 | + if (pThreadParam != nullptr){ | ||
331 | + pThreadParam->save_image_process(); | ||
332 | + } | ||
333 | + return 0; | ||
334 | +} | ||
335 | + | ||
336 | +// 快照保存子线程 依次从缓存队列中取数据 然后保存图片 然后MQ返回结果 | ||
337 | +void save_snapshot_reprocessing::save_image_process() { | ||
332 | 338 | ||
333 | while (true) { | 339 | while (true) { |
334 | if (bFinish){ | 340 | if (bFinish){ |
335 | break; | 341 | break; |
336 | } | 342 | } |
337 | 343 | ||
338 | - std::unique_lock<std::mutex> l(pThreadParam->waitforsave_image_queue_mutex); | ||
339 | - std::unique_lock<std::mutex> l_taskid(pThreadParam->waitforchange_taskid_mutex); | ||
340 | - if (!pThreadParam->waitforsave_image_queue.empty()) { | ||
341 | - SNAPSHOT_IMAGE_UNIT cur_image = pThreadParam->waitforsave_image_queue.front(); | ||
342 | - pThreadParam->waitforsave_image_queue.pop(); | ||
343 | - if (pThreadParam->task_on_play.find(cur_image.obj_key.video_id) == pThreadParam->task_on_play.end()) { | 344 | + std::unique_lock<std::mutex> l(waitforsave_image_queue_mutex); |
345 | + std::unique_lock<std::mutex> l_taskid(waitforchange_taskid_mutex); | ||
346 | + if (!waitforsave_image_queue.empty()) { | ||
347 | + SNAPSHOT_IMAGE_UNIT cur_image = waitforsave_image_queue.front(); | ||
348 | + waitforsave_image_queue.pop(); | ||
349 | + if (task_on_play.find(cur_image.obj_key.video_id) == task_on_play.end()) { | ||
344 | LOG_DEBUG("opencv nosave img {}", cur_image.ori_file_name.c_str()); | 350 | LOG_DEBUG("opencv nosave img {}", cur_image.ori_file_name.c_str()); |
345 | if (cur_image.ori_image.data != nullptr) { | 351 | if (cur_image.ori_image.data != nullptr) { |
346 | delete[] cur_image.ori_image.data; | 352 | delete[] cur_image.ori_image.data; |
@@ -385,9 +391,9 @@ DWORD save_image_thread_process(LPVOID param) { | @@ -385,9 +391,9 @@ DWORD save_image_thread_process(LPVOID param) { | ||
385 | } | 391 | } |
386 | 392 | ||
387 | #ifdef POST_USE_RABBITMQ | 393 | #ifdef POST_USE_RABBITMQ |
388 | - if (pThreadParam->callback_ != nullptr) { | 394 | + if (callback_ != nullptr) { |
389 | // LOG_DEBUG("mq publish process 00000000000000000"); | 395 | // LOG_DEBUG("mq publish process 00000000000000000"); |
390 | - pThreadParam->callback_(cur_image.json_str.c_str()); | 396 | + callback_(cur_image.json_str.c_str()); |
391 | // LOG_DEBUG("mq publish process 11111111111111111"); | 397 | // LOG_DEBUG("mq publish process 11111111111111111"); |
392 | } | 398 | } |
393 | 399 | ||
@@ -410,7 +416,6 @@ DWORD save_image_thread_process(LPVOID param) { | @@ -410,7 +416,6 @@ DWORD save_image_thread_process(LPVOID param) { | ||
410 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); | 416 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
411 | } | 417 | } |
412 | } | 418 | } |
413 | - return 0; | ||
414 | } | 419 | } |
415 | 420 | ||
416 | void save_snapshot_reprocessing::add_newtask(const string taskid) { | 421 | void save_snapshot_reprocessing::add_newtask(const string taskid) { |
tsl_aiplatform/reprocessing_module/save_snapshot_reprocessing.h
@@ -76,6 +76,9 @@ public: | @@ -76,6 +76,9 @@ public: | ||
76 | ); | 76 | ); |
77 | 77 | ||
78 | public: | 78 | public: |
79 | + void save_image_process(); | ||
80 | + | ||
81 | +private: | ||
79 | queue<SNAPSHOT_IMAGE_UNIT> waitforsave_image_queue; | 82 | queue<SNAPSHOT_IMAGE_UNIT> waitforsave_image_queue; |
80 | mutable std::mutex waitforsave_image_queue_mutex; | 83 | mutable std::mutex waitforsave_image_queue_mutex; |
81 | 84 | ||
@@ -84,6 +87,9 @@ public: | @@ -84,6 +87,9 @@ public: | ||
84 | mutable std::mutex waitforchange_taskid_mutex; | 87 | mutable std::mutex waitforchange_taskid_mutex; |
85 | 88 | ||
86 | std::thread m_save_ss_thread; | 89 | std::thread m_save_ss_thread; |
90 | + bool bFinish = false; | ||
91 | + | ||
92 | + vector<int> compression_params; | ||
87 | 93 | ||
88 | #ifdef POST_USE_RABBITMQ | 94 | #ifdef POST_USE_RABBITMQ |
89 | callback_t callback_; | 95 | callback_t callback_; |