Commit 682bbe397215a99c4b9ad2faa75082b4abd93f6f
1 parent
450989b5
修正任务自然退出死锁的问题
Showing
6 changed files
with
76 additions
and
8 deletions
FFNvDecoder/FFNvDecoder.cpp
@@ -257,8 +257,6 @@ void FFNvDecoder::decode_thread() | @@ -257,8 +257,6 @@ void FFNvDecoder::decode_thread() | ||
257 | 257 | ||
258 | m_bRunning = false; | 258 | m_bRunning = false; |
259 | 259 | ||
260 | - decode_finished_cbk(m_userPtr); | ||
261 | - | ||
262 | // long end_time = get_cur_time(); | 260 | // long end_time = get_cur_time(); |
263 | 261 | ||
264 | // cout << "解码用时:" << end_time - start_time << endl; | 262 | // cout << "解码用时:" << end_time - start_time << endl; |
@@ -268,6 +266,8 @@ void FFNvDecoder::decode_thread() | @@ -268,6 +266,8 @@ void FFNvDecoder::decode_thread() | ||
268 | pthread_join(m_post_decode_thread,0); | 266 | pthread_join(m_post_decode_thread,0); |
269 | } | 267 | } |
270 | 268 | ||
269 | + decode_finished_cbk(m_userPtr); | ||
270 | + | ||
271 | decode_finished(); | 271 | decode_finished(); |
272 | 272 | ||
273 | cout << "decode thread exited." << endl; | 273 | cout << "decode thread exited." << endl; |
@@ -291,7 +291,7 @@ void FFNvDecoder::decode_finished() | @@ -291,7 +291,7 @@ void FFNvDecoder::decode_finished() | ||
291 | 291 | ||
292 | void FFNvDecoder::post_decode_thread() | 292 | void FFNvDecoder::post_decode_thread() |
293 | { | 293 | { |
294 | - while (m_bRunning) | 294 | + while (m_bRunning || mFrameQueue.length() > 0) |
295 | { | 295 | { |
296 | AVFrame * gpuFrame = mFrameQueue.getHead(); | 296 | AVFrame * gpuFrame = mFrameQueue.getHead(); |
297 | if (gpuFrame == nullptr) | 297 | if (gpuFrame == nullptr) |
@@ -369,4 +369,8 @@ void FFNvDecoder::resume() | @@ -369,4 +369,8 @@ void FFNvDecoder::resume() | ||
369 | void FFNvDecoder::setDecKeyframe(bool bKeyframe) | 369 | void FFNvDecoder::setDecKeyframe(bool bKeyframe) |
370 | { | 370 | { |
371 | m_dec_keyframe = bKeyframe; | 371 | m_dec_keyframe = bKeyframe; |
372 | +} | ||
373 | + | ||
374 | +int FFNvDecoder::getCachedQueueLength(){ | ||
375 | + return mFrameQueue.length(); | ||
372 | } | 376 | } |
373 | \ No newline at end of file | 377 | \ No newline at end of file |
FFNvDecoder/FFNvDecoder.h
FFNvDecoder/FFNvDecoderManager.cpp
@@ -339,4 +339,21 @@ vector<string> FFNvDecoderManager::getAllDecodeName(){ | @@ -339,4 +339,21 @@ vector<string> FFNvDecoderManager::getAllDecodeName(){ | ||
339 | decode_names.push_back(it->first); | 339 | decode_names.push_back(it->first); |
340 | } | 340 | } |
341 | return decode_names; | 341 | return decode_names; |
342 | +} | ||
343 | + | ||
344 | +int FFNvDecoderManager::getCachedQueueLength(const string name){ | ||
345 | + if (name.empty()){ | ||
346 | + cout << "name 为空!"<< endl; | ||
347 | + return -1; | ||
348 | + } | ||
349 | + | ||
350 | + std::lock_guard<std::mutex> l(m_mutex); | ||
351 | + | ||
352 | + auto dec = decoderMap.find(name); | ||
353 | + if (dec != decoderMap.end()){ | ||
354 | + return dec->second->getCachedQueueLength(); | ||
355 | + } | ||
356 | + | ||
357 | + cout << "没有找到name为" << name << "的解码器!" << endl; | ||
358 | + return -1; | ||
342 | } | 359 | } |
343 | \ No newline at end of file | 360 | \ No newline at end of file |
FFNvDecoder/FFNvDecoderManager.h
@@ -213,6 +213,15 @@ public: | @@ -213,6 +213,15 @@ public: | ||
213 | **************************************************/ | 213 | **************************************************/ |
214 | vector<string> getAllDecodeName(); | 214 | vector<string> getAllDecodeName(); |
215 | 215 | ||
216 | + /************************************************** | ||
217 | + * 接口:getCachedQueueLength | ||
218 | + * 功能:获取解码缓冲队列当前长度 | ||
219 | + * 参数:const string name 解码器名称 | ||
220 | + * 返回:int 解码缓冲队列当前长度 | ||
221 | + * 备注: | ||
222 | + **************************************************/ | ||
223 | + int getCachedQueueLength(const string name); | ||
224 | + | ||
216 | private: | 225 | private: |
217 | FFNvDecoderManager(){} | 226 | FFNvDecoderManager(){} |
218 | 227 |
tsl_aiplatform/ai_platform/MultiSourceProcess.cpp
@@ -50,6 +50,7 @@ void decode_finished_cbk(const void * userPtr){ | @@ -50,6 +50,7 @@ void decode_finished_cbk(const void * userPtr){ | ||
50 | 50 | ||
51 | CMultiSourceProcess::CMultiSourceProcess(){ | 51 | CMultiSourceProcess::CMultiSourceProcess(){ |
52 | m_bfinish = false; | 52 | m_bfinish = false; |
53 | + m_bProcessEnd = false; | ||
53 | } | 54 | } |
54 | 55 | ||
55 | CMultiSourceProcess::~CMultiSourceProcess(){ | 56 | CMultiSourceProcess::~CMultiSourceProcess(){ |
@@ -393,11 +394,43 @@ void CMultiSourceProcess::post_decode_thread(decode_cbk_userdata* userPtr, AVFra | @@ -393,11 +394,43 @@ void CMultiSourceProcess::post_decode_thread(decode_cbk_userdata* userPtr, AVFra | ||
393 | 394 | ||
394 | // 解码线程退出的最后回调的实际任务函数 | 395 | // 解码线程退出的最后回调的实际任务函数 |
395 | void CMultiSourceProcess::decode_finished_thread(task_param t_param){ | 396 | void CMultiSourceProcess::decode_finished_thread(task_param t_param){ |
396 | - // 任务结束,关闭跟踪 | ||
397 | - if (!FinishTaskTracker(VPT_Handle_, t_param.task_id)) | ||
398 | - LOG_ERROR("Finish VPT Tracker failed, task_id: {}", t_param.task_id); | ||
399 | 397 | ||
400 | - finish_task(t_param.task_id,false); | 398 | + FFNvDecoderManager* pDecManager = FFNvDecoderManager::getInstance(); |
399 | + | ||
400 | + while(true){ | ||
401 | + | ||
402 | + if(m_bfinish){ | ||
403 | + break; | ||
404 | + } | ||
405 | + | ||
406 | + std::this_thread::sleep_for(std::chrono::milliseconds(5)); | ||
407 | + | ||
408 | + std::lock_guard<std::mutex> l(m_QueueMtx); | ||
409 | + | ||
410 | + // 确保 m_RgbDataList 中没有任务数据 | ||
411 | + for (auto iter = m_RgbDataList.begin(); iter!=m_RgbDataList.end(); ++ iter){ | ||
412 | + GpuRgbMemory* gpuMem = *iter; | ||
413 | + if(gpuMem->getId() == t_param.task_id){ | ||
414 | + continue; | ||
415 | + } | ||
416 | + } | ||
417 | + | ||
418 | + // 确保 对应解码器中没有缓存的数据 | ||
419 | + if (pDecManager->getCachedQueueLength(t_param.task_id) > 0){ | ||
420 | + continue; | ||
421 | + } | ||
422 | + | ||
423 | + // 确保对应任务没有正在执行算法的数据 | ||
424 | + if (m_bProcessEnd){ | ||
425 | + // 任务结束,关闭跟踪 | ||
426 | + if (!FinishTaskTracker(VPT_Handle_, t_param.task_id)) | ||
427 | + LOG_ERROR("Finish VPT Tracker failed, task_id: {}", t_param.task_id); | ||
428 | + | ||
429 | + finish_task(t_param.task_id,false); | ||
430 | + | ||
431 | + break; | ||
432 | + } | ||
433 | + } | ||
401 | } | 434 | } |
402 | 435 | ||
403 | bool CMultiSourceProcess::task_has_vpt_algor(const std::string &task_id){ | 436 | bool CMultiSourceProcess::task_has_vpt_algor(const std::string &task_id){ |
@@ -446,6 +479,7 @@ void CMultiSourceProcess::algorthim_process_thread(){ | @@ -446,6 +479,7 @@ void CMultiSourceProcess::algorthim_process_thread(){ | ||
446 | 479 | ||
447 | int sum = 0; | 480 | int sum = 0; |
448 | while(true){ | 481 | while(true){ |
482 | + m_bProcessEnd = true; | ||
449 | /* step1. 授权check */ | 483 | /* step1. 授权check */ |
450 | if (licence_status_ <= -3) { | 484 | if (licence_status_ <= -3) { |
451 | LOG_FATAL("authority failed!"); | 485 | LOG_FATAL("authority failed!"); |
@@ -458,6 +492,7 @@ void CMultiSourceProcess::algorthim_process_thread(){ | @@ -458,6 +492,7 @@ void CMultiSourceProcess::algorthim_process_thread(){ | ||
458 | 492 | ||
459 | /* step5. 凑齐的解码数据 拼batch */ | 493 | /* step5. 凑齐的解码数据 拼batch */ |
460 | m_QueueMtx.lock(); | 494 | m_QueueMtx.lock(); |
495 | + m_bProcessEnd = false; | ||
461 | 496 | ||
462 | vector<GpuRgbMemory*> vec_gpuMem; | 497 | vector<GpuRgbMemory*> vec_gpuMem; |
463 | for (auto iter = m_RgbDataList.begin(); iter!=m_RgbDataList.end(); ++ iter){ | 498 | for (auto iter = m_RgbDataList.begin(); iter!=m_RgbDataList.end(); ++ iter){ |
@@ -529,6 +564,7 @@ void CMultiSourceProcess::algorthim_process_thread(){ | @@ -529,6 +564,7 @@ void CMultiSourceProcess::algorthim_process_thread(){ | ||
529 | } | 564 | } |
530 | #endif | 565 | #endif |
531 | 566 | ||
567 | + m_bProcessEnd = true; | ||
532 | cout << "algorthim_process_thread end. " << endl; | 568 | cout << "algorthim_process_thread end. " << endl; |
533 | } | 569 | } |
534 | 570 |
tsl_aiplatform/ai_platform/MultiSourceProcess.h
@@ -192,6 +192,7 @@ private: | @@ -192,6 +192,7 @@ private: | ||
192 | list<GpuRgbMemory*> m_RgbDataList; | 192 | list<GpuRgbMemory*> m_RgbDataList; |
193 | std::mutex m_QueueMtx; | 193 | std::mutex m_QueueMtx; |
194 | bool m_bfinish; | 194 | bool m_bfinish; |
195 | + bool m_bProcessEnd; | ||
195 | 196 | ||
196 | pthread_t m_authority_check_thread; | 197 | pthread_t m_authority_check_thread; |
197 | 198 | ||
@@ -222,7 +223,6 @@ private: | @@ -222,7 +223,6 @@ private: | ||
222 | face_det_ai_engine m_face_det_ai_engine; // 人脸检测 | 223 | face_det_ai_engine m_face_det_ai_engine; // 人脸检测 |
223 | #endif | 224 | #endif |
224 | 225 | ||
225 | -private: | ||
226 | base_reprocessing_unit *m_save_snapshot_reprocessing{nullptr}; | 226 | base_reprocessing_unit *m_save_snapshot_reprocessing{nullptr}; |
227 | 227 | ||
228 | }; | 228 | }; |