Commit caef8aa259a1687ae5f5c717cb34b6012ae12214
1 parent
52d214c5
修复aclrtSetDevice和视频截存的内存泄露
Showing
2 changed files
with
18 additions
and
37 deletions
src/decoder/dvpp/DvppDecoder.cpp
... | ... | @@ -332,13 +332,7 @@ int DvppDecoder::getVdecType(int videoType, int profile) |
332 | 332 | post_decoded_cbk = cfg.post_decoded_cbk; |
333 | 333 | |
334 | 334 | do{ |
335 | - aclError ret = aclrtSetDevice(m_dvpp_deviceId); | |
336 | - if(ret != ACL_ERROR_NONE){ | |
337 | - LOG_ERROR("[{}]-aclrtSetDevice failed !", m_dec_name); | |
338 | - break; | |
339 | - } | |
340 | - | |
341 | - ret = aclrtCreateContext(&m_context, m_dvpp_deviceId); | |
335 | + aclError ret = aclrtCreateContext(&m_context, m_dvpp_deviceId); | |
342 | 336 | if (ret != ACL_ERROR_NONE) { |
343 | 337 | LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); |
344 | 338 | break; |
... | ... | @@ -515,7 +509,7 @@ void DvppDecoder::read_thread() { |
515 | 509 | } |
516 | 510 | |
517 | 511 | m_bExitDisplayThd = false; |
518 | - std::thread display_thread = std::thread( | |
512 | + std::thread display_thread( | |
519 | 513 | [](void* arg) |
520 | 514 | { |
521 | 515 | DvppDecoder* a=(DvppDecoder*)arg; |
... | ... | @@ -525,11 +519,9 @@ void DvppDecoder::read_thread() { |
525 | 519 | this |
526 | 520 | ); |
527 | 521 | |
528 | - aclrtContext ctx = nullptr; | |
529 | 522 | aclvdecChannelDesc *vdecChannelDesc = nullptr; |
530 | 523 | |
531 | 524 | do { |
532 | - CHECK_AND_BREAK(aclrtSetDevice(m_dvpp_deviceId), "aclrtSetDevice failed"); | |
533 | 525 | int ret = aclrtSetCurrentContext(m_context); |
534 | 526 | if(ret != ACL_ERROR_NONE){ |
535 | 527 | LOG_ERROR("[{}]- aclrtSetCurrentContext failed", m_dec_name); |
... | ... | @@ -552,6 +544,8 @@ void DvppDecoder::read_thread() { |
552 | 544 | CHECK_AND_BREAK(aclvdecCreateChannel(vdecChannelDesc), "aclvdecCreateChannel failed"); |
553 | 545 | |
554 | 546 | unsigned long long frame_nb = 0; |
547 | + AVPacket* pkt = av_packet_alloc(); | |
548 | + av_init_packet( pkt ); | |
555 | 549 | while (m_bRunning){ |
556 | 550 | |
557 | 551 | if (!m_bReal){ |
... | ... | @@ -578,12 +572,9 @@ void DvppDecoder::read_thread() { |
578 | 572 | m_last_read_ts = get_cur_time_ms(); |
579 | 573 | } |
580 | 574 | |
581 | - AVPacket* pkt = av_packet_alloc(); | |
582 | - av_init_packet( pkt ); | |
583 | 575 | int result = av_read_frame(fmt_ctx, pkt); |
584 | 576 | if (result == AVERROR_EOF || result < 0){ |
585 | - av_packet_free(&pkt); | |
586 | - pkt = nullptr; | |
577 | + av_packet_unref(pkt); | |
587 | 578 | LOG_WARN("[{}]- Failed to read frame!", m_dec_name); |
588 | 579 | break; |
589 | 580 | } |
... | ... | @@ -591,15 +582,13 @@ void DvppDecoder::read_thread() { |
591 | 582 | if (m_bReal && m_DvppCacheCounter.load() > m_cache_gop){ |
592 | 583 | // 解码器解码不过来。实时流在此处的处理会导致花屏,这是由于解码器性能问题导致,无法避免 |
593 | 584 | // 实时流在这里处理是为了避免长时间不读取数据导致数据中断 |
594 | - av_packet_free(&pkt); | |
595 | - pkt = nullptr; | |
585 | + av_packet_unref(pkt); | |
596 | 586 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
597 | 587 | continue; |
598 | 588 | } |
599 | 589 | |
600 | 590 | if (m_dec_keyframe && !(pkt->flags & AV_PKT_FLAG_KEY)) { |
601 | - av_packet_free(&pkt); | |
602 | - pkt = nullptr; | |
591 | + av_packet_unref(pkt); | |
603 | 592 | continue; |
604 | 593 | } |
605 | 594 | |
... | ... | @@ -608,8 +597,7 @@ void DvppDecoder::read_thread() { |
608 | 597 | ret = av_bsf_send_packet(h264bsfc, pkt); |
609 | 598 | if(ret < 0) { |
610 | 599 | LOG_ERROR("[{}]- av_bsf_send_packet error!", m_dec_name); |
611 | - av_packet_free(&pkt); | |
612 | - pkt = nullptr; | |
600 | + av_packet_unref(pkt); | |
613 | 601 | continue; |
614 | 602 | } |
615 | 603 | |
... | ... | @@ -631,12 +619,14 @@ void DvppDecoder::read_thread() { |
631 | 619 | #ifdef USE_VILLAGE |
632 | 620 | m_recoderManager.cache_pkt(pkt, frame_nb, m_dec_name); |
633 | 621 | #endif |
634 | - } else { | |
635 | - av_packet_free(&pkt); | |
636 | - pkt = nullptr; | |
637 | - } | |
622 | + } | |
623 | + | |
624 | + av_packet_unref(pkt); | |
638 | 625 | } |
639 | 626 | |
627 | + av_packet_free(&pkt); | |
628 | + pkt = nullptr; | |
629 | + | |
640 | 630 | if (vdecChannelDesc) { |
641 | 631 | sendVdecEos(vdecChannelDesc); |
642 | 632 | } |
... | ... | @@ -764,24 +754,15 @@ void DvppDecoder::doProcessReport(){ |
764 | 754 | |
765 | 755 | aclError ret = aclrtSetDevice(m_dvpp_deviceId); |
766 | 756 | if(ret != ACL_ERROR_NONE){ |
767 | - // cout << "aclrtSetDevice failed" << endl; | |
768 | - LOG_ERROR("aclrtSetDevice failed !"); | |
769 | - return ; | |
770 | - } | |
771 | - | |
772 | - aclrtContext ctx; | |
773 | - ret = aclrtCreateContext(&ctx, m_dvpp_deviceId); | |
774 | - if (ret != ACL_ERROR_NONE) { | |
775 | - // cout << "aclrtCreateContext failed " << endl; | |
776 | - LOG_ERROR("aclrtCreateContext failed !"); | |
777 | - return ; | |
757 | + LOG_ERROR("[{}]-aclrtSetDevice failed !", m_dec_name); | |
758 | + return; | |
778 | 759 | } |
779 | 760 | |
780 | 761 | while (!m_bExitReportThd) { |
781 | 762 | aclrtProcessReport(1000); |
782 | 763 | } |
783 | 764 | |
784 | - ret = aclrtDestroyContext(ctx); | |
765 | + ret = aclrtResetDevice(m_dvpp_deviceId); | |
785 | 766 | if(ret != ACL_ERROR_NONE){ |
786 | 767 | LOG_ERROR("aclrtDestroyContext failed !"); |
787 | 768 | } | ... | ... |
src/decoder/dvpp/DvppStreamDecoder.cpp