Commit 2dad31885e701d926e5a183de6628bfb6fbf1c8c

Authored by Hu Chunming
1 parent 6dddca6a

优化解码任务结束逻辑,避免可能的泄露

Showing 1 changed file with 18 additions and 16 deletions
src/decoder/dvpp/DvppDecoder.cpp
@@ -627,27 +627,25 @@ void DvppDecoder::read_thread() { @@ -627,27 +627,25 @@ void DvppDecoder::read_thread() {
627 av_packet_free(&pkt); 627 av_packet_free(&pkt);
628 pkt = nullptr; 628 pkt = nullptr;
629 629
630 - if (vdecChannelDesc) {  
631 - sendVdecEos(vdecChannelDesc);  
632 - }  
633 -  
634 - while(m_bRunning && m_decoded_data_queue.size() > 0) {  
635 - std::this_thread::sleep_for(std::chrono::milliseconds(5));  
636 - }  
637 -  
638 } while (0); 630 } while (0);
639 631
640 if (vdecChannelDesc) { 632 if (vdecChannelDesc) {
  633 + sendVdecEos(vdecChannelDesc);
  634 +
641 CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); 635 CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed");
642 CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed"); 636 CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed");
643 vdecChannelDesc = nullptr; 637 vdecChannelDesc = nullptr;
644 } 638 }
645 639
646 - m_bRunning=false;  
647 -  
648 m_bExitReportThd = true; 640 m_bExitReportThd = true;
649 CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "report_thread join failed"); 641 CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "report_thread join failed");
650 642
  643 + while(m_bRunning && m_decoded_data_queue.size() > 0) {
  644 + std::this_thread::sleep_for(std::chrono::milliseconds(5));
  645 + }
  646 +
  647 + m_bRunning=false;
  648 +
651 m_bExitDisplayThd = true; 649 m_bExitDisplayThd = true;
652 display_thread.join(); 650 display_thread.join();
653 651
@@ -774,6 +772,12 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o @@ -774,6 +772,12 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o
774 // 内部缓存计数减1 772 // 内部缓存计数减1
775 m_DvppCacheCounter--; 773 m_DvppCacheCounter--;
776 774
  775 + CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed");
  776 +
  777 + void *inputDataDev = acldvppGetStreamDescData(input);
  778 + acldvppFree(inputDataDev);
  779 + inputDataDev = nullptr;
  780 +
777 if(nullptr == pUserData){ 781 if(nullptr == pUserData){
778 return; 782 return;
779 } 783 }
@@ -783,12 +787,6 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o @@ -783,12 +787,6 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o
783 787
784 m_out_count++; 788 m_out_count++;
785 789
786 - CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed");  
787 -  
788 - void *inputDataDev = acldvppGetStreamDescData(input);  
789 - acldvppFree(inputDataDev);  
790 - inputDataDev = nullptr;  
791 -  
792 void *outputDataDev = acldvppGetPicDescData(output); 790 void *outputDataDev = acldvppGetPicDescData(output);
793 uint32_t outputSize = acldvppGetPicDescSize(output); 791 uint32_t outputSize = acldvppGetPicDescSize(output);
794 uint32_t width = acldvppGetPicDescWidth(output); 792 uint32_t width = acldvppGetPicDescWidth(output);
@@ -845,6 +843,10 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o @@ -845,6 +843,10 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o
845 if(mem){ 843 if(mem){
846 m_decoded_data_queue.push(mem); 844 m_decoded_data_queue.push(mem);
847 bCached = true; 845 bCached = true;
  846 + } else {
  847 + // 逻辑完善
  848 + delete mem;
  849 + mem = nullptr;
848 } 850 }
849 } 851 }
850 852