Commit 458962a016ebc2cf06a49fc311d285cba85ca27d
1 parent
44a5c5b0
dvpp操作失败直接abort;VpcUtils改为单例
Showing
6 changed files
with
113 additions
and
129 deletions
src/decoder/dvpp/DvppDataMemory.hpp
... | ... | @@ -20,6 +20,7 @@ public: |
20 | 20 | int ret = acldvppMalloc((void **)&pHwRgb, data_size); |
21 | 21 | if(ret != ACL_ERROR_NONE){ |
22 | 22 | LOG_ERROR("[{}]- acldvppMalloc failed", id); |
23 | + std::abort(); | |
23 | 24 | } |
24 | 25 | } |
25 | 26 | |
... | ... | @@ -40,14 +41,14 @@ public: |
40 | 41 | int ret = acldvppMalloc((void **)&pHwRgb, data_size); |
41 | 42 | if(ret != ACL_ERROR_NONE){ |
42 | 43 | LOG_ERROR("[{}]- acldvppMalloc failed", pSrc->getId()); |
43 | - return; | |
44 | + std::abort(); | |
44 | 45 | } |
45 | 46 | |
46 | 47 | ret = aclrtMemcpy(pHwRgb, data_size, pSrc->getMem(), pSrc->getSize(), ACL_MEMCPY_DEVICE_TO_DEVICE); |
47 | 48 | if(ret != ACL_ERROR_NONE){ |
48 | 49 | acldvppFree(pHwRgb); |
49 | 50 | LOG_ERROR("[{}]- aclrtMemcpy failed", pSrc->getId()); |
50 | - return; | |
51 | + std::abort(); | |
51 | 52 | } |
52 | 53 | |
53 | 54 | data_type = 2; |
... | ... | @@ -64,6 +65,7 @@ public: |
64 | 65 | int ret = acldvppFree(pHwRgb); |
65 | 66 | if(ret != ACL_ERROR_NONE){ |
66 | 67 | LOG_ERROR("[{}]- acldvppFree failed", id); |
68 | + std::abort(); | |
67 | 69 | } |
68 | 70 | pHwRgb = nullptr; |
69 | 71 | } | ... | ... |
src/decoder/dvpp/DvppDecoder.cpp
1 | 1 | #include "DvppDecoder.h" |
2 | 2 | #include "DvppSourceManager.h" |
3 | 3 | |
4 | +#include "VpcUtils.h" | |
4 | 5 | |
5 | -#define CHECK_AND_RETURN(ret, message) \ | |
6 | - if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); return ret;} | |
7 | -#define CHECK_NOT_RETURN(ret, message) \ | |
8 | - if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message);} | |
9 | -#define CHECK_AND_RETURN_NOVALUE(ret, message) \ | |
10 | - if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); return;} | |
11 | -#define CHECK_AND_BREAK(ret, message) \ | |
12 | - if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); break;} | |
13 | - | |
14 | - | |
6 | +#define ACL_CHECK_AND_ABORT(ret, message) \ | |
7 | + if(ret != 0) {LOG_ERROR("[{}]- {}:{}", m_dec_name, message, ret); std::abort();} | |
15 | 8 | |
16 | 9 | |
17 | 10 | struct Vdec_CallBack_UserData { |
... | ... | @@ -328,14 +321,13 @@ int DvppDecoder::getVdecType(int videoType, int profile) |
328 | 321 | |
329 | 322 | m_dvpp_deviceId = atoi(cfg.gpuid.c_str()); |
330 | 323 | |
324 | + VpcUtils* pUtil = VpcUtils::getInstance(); | |
325 | + pUtil->init(m_dvpp_deviceId); | |
326 | + | |
331 | 327 | post_decoded_cbk = cfg.post_decoded_cbk; |
332 | 328 | |
333 | 329 | do{ |
334 | - aclError ret = aclrtCreateContext(&m_context, m_dvpp_deviceId); | |
335 | - if (ret != ACL_ERROR_NONE) { | |
336 | - LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); | |
337 | - break; | |
338 | - } | |
330 | + ACL_CHECK_AND_ABORT(aclrtCreateContext(&m_context, m_dvpp_deviceId), "aclrtCreateContext failed !"); | |
339 | 331 | |
340 | 332 | // DvppSourceManager 创建时包含 aclInit,析构时包含 aclFinalize |
341 | 333 | DvppSourceManager* pSrcMgr = DvppSourceManager::getInstance(); |
... | ... | @@ -346,7 +338,6 @@ int DvppDecoder::getVdecType(int videoType, int profile) |
346 | 338 | } |
347 | 339 | |
348 | 340 | m_bResize = cfg.resize; |
349 | - m_vpcUtils.init(m_dvpp_deviceId); | |
350 | 341 | |
351 | 342 | LOG_INFO("[{}]- init vdpp success! device:{} channel:{}", m_dec_name, m_dvpp_deviceId, m_dvpp_channel); |
352 | 343 | return true; |
... | ... | @@ -440,11 +431,7 @@ static int snap_count = 0; |
440 | 431 | |
441 | 432 | DeviceMemory* DvppDecoder::snapshot(){ |
442 | 433 | |
443 | - int ret = aclrtSetCurrentContext(m_context); | |
444 | - if(ret != ACL_ERROR_NONE){ | |
445 | - LOG_ERROR("[{}]- aclrtSetCurrentContext failed", m_dec_name); | |
446 | - return nullptr; | |
447 | - } | |
434 | + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed !"); | |
448 | 435 | |
449 | 436 | // 注意有锁 |
450 | 437 | DeviceMemory* snapshot_mem = nullptr; |
... | ... | @@ -522,26 +509,23 @@ void DvppDecoder::read_thread() { |
522 | 509 | aclvdecChannelDesc *vdecChannelDesc = nullptr; |
523 | 510 | |
524 | 511 | do { |
525 | - int ret = aclrtSetCurrentContext(m_context); | |
526 | - if(ret != ACL_ERROR_NONE){ | |
527 | - LOG_ERROR("[{}]- aclrtSetCurrentContext failed", m_dec_name); | |
528 | - break; | |
529 | - } | |
512 | + aclrtSetDevice(m_dvpp_deviceId); | |
513 | + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed !"); | |
530 | 514 | |
531 | 515 | vdecChannelDesc = aclvdecCreateChannelDesc(); |
532 | 516 | if (vdecChannelDesc == nullptr) { |
533 | 517 | LOG_ERROR("[{}]- aclvdecCreateChannelDesc failed", m_dec_name); |
534 | - break; | |
518 | + std::abort(); | |
535 | 519 | } |
536 | 520 | |
537 | 521 | // 创建 channel dec结构体 |
538 | 522 | // 通道ID在dvpp层面为0~31 |
539 | - CHECK_AND_BREAK(aclvdecSetChannelDescChannelId(vdecChannelDesc, m_dvpp_channel), "aclvdecSetChannelDescChannelId failed"); | |
540 | - CHECK_AND_BREAK(aclvdecSetChannelDescThreadId(vdecChannelDesc, report_thread), "aclvdecSetChannelDescThreadId failed"); | |
541 | - CHECK_AND_BREAK(aclvdecSetChannelDescCallback(vdecChannelDesc, VdecCallback), "aclvdecSetChannelDescCallback failed"); | |
542 | - CHECK_AND_BREAK(aclvdecSetChannelDescEnType(vdecChannelDesc, m_enType), "aclvdecSetChannelDescEnType failed"); | |
543 | - CHECK_AND_BREAK(aclvdecSetChannelDescOutPicFormat(vdecChannelDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420), "aclvdecSetChannelDescOutPicFormat failed"); | |
544 | - CHECK_AND_BREAK(aclvdecCreateChannel(vdecChannelDesc), "aclvdecCreateChannel failed"); | |
523 | + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescChannelId(vdecChannelDesc, m_dvpp_channel), "aclvdecSetChannelDescChannelId failed"); | |
524 | + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescThreadId(vdecChannelDesc, report_thread), "aclvdecSetChannelDescThreadId failed"); | |
525 | + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescCallback(vdecChannelDesc, VdecCallback), "aclvdecSetChannelDescCallback failed"); | |
526 | + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescEnType(vdecChannelDesc, m_enType), "aclvdecSetChannelDescEnType failed"); | |
527 | + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescOutPicFormat(vdecChannelDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420), "aclvdecSetChannelDescOutPicFormat failed"); | |
528 | + ACL_CHECK_AND_ABORT(aclvdecCreateChannel(vdecChannelDesc), "aclvdecCreateChannel failed"); | |
545 | 529 | |
546 | 530 | unsigned long long frame_nb = 0; |
547 | 531 | AVPacket* pkt = av_packet_alloc(); |
... | ... | @@ -638,15 +622,15 @@ void DvppDecoder::read_thread() { |
638 | 622 | } while (0); |
639 | 623 | |
640 | 624 | if (vdecChannelDesc) { |
641 | - CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); | |
642 | - CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed"); | |
625 | + ACL_CHECK_AND_ABORT(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); | |
626 | + ACL_CHECK_AND_ABORT(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed"); | |
643 | 627 | vdecChannelDesc = nullptr; |
644 | 628 | } |
645 | 629 | |
646 | 630 | m_bRunning=false; |
647 | 631 | |
648 | 632 | m_bExitReportThd = true; |
649 | - CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "report_thread join failed"); | |
633 | + ACL_CHECK_AND_ABORT(pthread_join(report_thread, nullptr), "report_thread join failed"); | |
650 | 634 | |
651 | 635 | m_bExitDisplayThd = true; |
652 | 636 | display_thread_.join(); |
... | ... | @@ -672,38 +656,26 @@ int DvppDecoder::sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, uns |
672 | 656 | acldvppStreamDesc *input_stream_desc = nullptr; |
673 | 657 | acldvppPicDesc *output_pic_desc = nullptr; |
674 | 658 | do{ |
675 | - int ret = acldvppMalloc((void **)&vdecInputbuf, pkt->size); | |
676 | - if(ACL_ERROR_NONE != ret){ | |
677 | - LOG_ERROR("[{}]- acldvppMalloc failed!, ret:{}", m_dec_name, ret); | |
678 | - break; | |
679 | - } | |
659 | + int ret = -1; | |
680 | 660 | |
681 | - ret = aclrtMemcpy(vdecInputbuf, pkt->size, pkt->data, pkt->size, ACL_MEMCPY_HOST_TO_DEVICE); | |
682 | - if(ACL_ERROR_NONE != ret){ | |
683 | - LOG_ERROR("[{}]- aclrtMemcpy failed", m_dec_name); | |
684 | - break; | |
685 | - } | |
686 | - | |
687 | - ret = acldvppMalloc((void **)&vdecOutputBuf, m_vdec_out_size); | |
688 | - if(ret != ACL_ERROR_NONE){ | |
689 | - LOG_ERROR("[{}]- acldvppMalloc failed", m_dec_name); | |
690 | - break; | |
691 | - } | |
661 | + ACL_CHECK_AND_ABORT(acldvppMalloc((void **)&vdecInputbuf, pkt->size), "acldvppMalloc failed!"); | |
662 | + ACL_CHECK_AND_ABORT(aclrtMemcpy(vdecInputbuf, pkt->size, pkt->data, pkt->size, ACL_MEMCPY_HOST_TO_DEVICE), "aclrtMemcpy failed!"); | |
663 | + ACL_CHECK_AND_ABORT(acldvppMalloc((void **)&vdecOutputBuf, m_vdec_out_size), "acldvppMalloc failed!"); | |
692 | 664 | |
693 | 665 | input_stream_desc = acldvppCreateStreamDesc(); |
694 | 666 | if (input_stream_desc == nullptr) { |
695 | 667 | LOG_ERROR("[{}]- acldvppCreateStreamDesc failed", m_dec_name); |
696 | - break; | |
668 | + std::abort(); | |
697 | 669 | } |
698 | 670 | output_pic_desc = acldvppCreatePicDesc(); |
699 | 671 | if (output_pic_desc == nullptr) { |
700 | 672 | LOG_ERROR("[{}]- acldvppCreatePicDesc failed", m_dec_name); |
701 | - break; | |
673 | + std::abort(); | |
702 | 674 | } |
703 | - CHECK_AND_BREAK(acldvppSetStreamDescData(input_stream_desc, vdecInputbuf), "acldvppSetStreamDescData failed"); | |
704 | - CHECK_AND_BREAK(acldvppSetStreamDescSize(input_stream_desc, pkt->size), "acldvppSetStreamDescSize failed"); | |
705 | - CHECK_AND_BREAK(acldvppSetPicDescData(output_pic_desc, vdecOutputBuf), "acldvppSetPicDescData failed"); | |
706 | - CHECK_AND_BREAK(acldvppSetPicDescSize(output_pic_desc, m_vdec_out_size), "acldvppSetPicDescSize failed"); | |
675 | + ACL_CHECK_AND_ABORT(acldvppSetStreamDescData(input_stream_desc, vdecInputbuf), "acldvppSetStreamDescData failed"); | |
676 | + ACL_CHECK_AND_ABORT(acldvppSetStreamDescSize(input_stream_desc, pkt->size), "acldvppSetStreamDescSize failed"); | |
677 | + ACL_CHECK_AND_ABORT(acldvppSetPicDescData(output_pic_desc, vdecOutputBuf), "acldvppSetPicDescData failed"); | |
678 | + ACL_CHECK_AND_ABORT(acldvppSetPicDescSize(output_pic_desc, m_vdec_out_size), "acldvppSetPicDescSize failed"); | |
707 | 679 | |
708 | 680 | Vdec_CallBack_UserData *user_data = NULL; |
709 | 681 | user_data = new Vdec_CallBack_UserData; |
... | ... | @@ -735,7 +707,8 @@ int DvppDecoder::sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, uns |
735 | 707 | |
736 | 708 | // 报错情形 |
737 | 709 | if(input_stream_desc){ |
738 | - CHECK_NOT_RETURN(acldvppDestroyStreamDesc(input_stream_desc), "acldvppDestroyStreamDesc failed"); | |
710 | + ACL_CHECK_AND_ABORT(acldvppDestroyStreamDesc(input_stream_desc), "acldvppDestroyStreamDesc failed"); | |
711 | + input_stream_desc = nullptr; | |
739 | 712 | } |
740 | 713 | |
741 | 714 | if (vdecOutputBuf){ |
... | ... | @@ -744,7 +717,8 @@ int DvppDecoder::sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, uns |
744 | 717 | } |
745 | 718 | |
746 | 719 | if(output_pic_desc){ |
747 | - CHECK_NOT_RETURN(acldvppDestroyPicDesc(output_pic_desc), "acldvppDestroyPicDesc failed"); | |
720 | + ACL_CHECK_AND_ABORT(acldvppDestroyPicDesc(output_pic_desc), "acldvppDestroyPicDesc failed"); | |
721 | + output_pic_desc = nullptr; | |
748 | 722 | } |
749 | 723 | |
750 | 724 | return -1; |
... | ... | @@ -752,20 +726,14 @@ int DvppDecoder::sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, uns |
752 | 726 | |
753 | 727 | void DvppDecoder::doProcessReport(){ |
754 | 728 | |
755 | - aclError ret = aclrtSetDevice(m_dvpp_deviceId); | |
756 | - if(ret != ACL_ERROR_NONE){ | |
757 | - LOG_ERROR("[{}]-aclrtSetDevice failed !", m_dec_name); | |
758 | - return; | |
759 | - } | |
729 | + ACL_CHECK_AND_ABORT(aclrtSetDevice(m_dvpp_deviceId), "aclrtSetDevice failed"); | |
760 | 730 | |
761 | 731 | while (!m_bExitReportThd) { |
762 | 732 | aclrtProcessReport(1000); |
763 | 733 | } |
764 | 734 | |
765 | - ret = aclrtResetDevice(m_dvpp_deviceId); | |
766 | - if(ret != ACL_ERROR_NONE){ | |
767 | - LOG_ERROR("aclrtDestroyContext failed !"); | |
768 | - } | |
735 | + ACL_CHECK_AND_ABORT(aclrtResetDevice(m_dvpp_deviceId), "aclrtResetDevice failed"); | |
736 | + | |
769 | 737 | LOG_INFO("doProcessReport exit."); |
770 | 738 | } |
771 | 739 | |
... | ... | @@ -783,7 +751,7 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o |
783 | 751 | |
784 | 752 | m_out_count++; |
785 | 753 | |
786 | - CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed"); | |
754 | + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed"); | |
787 | 755 | |
788 | 756 | void *inputDataDev = acldvppGetStreamDescData(input); |
789 | 757 | acldvppFree(inputDataDev); |
... | ... | @@ -797,13 +765,7 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o |
797 | 765 | uint32_t height_stride = acldvppGetPicDescHeightStride(output); |
798 | 766 | |
799 | 767 | do{ |
800 | - int ret = acldvppGetPicDescRetCode(output); | |
801 | - if(ret != ACL_ERROR_NONE){ | |
802 | - LOG_ERROR("[{}]- decode result error, retCode:{} ", m_dec_name, ret); | |
803 | - acldvppFree(outputDataDev); | |
804 | - outputDataDev = nullptr; | |
805 | - break; | |
806 | - } | |
768 | + ACL_CHECK_AND_ABORT(acldvppGetPicDescRetCode(output), "acldvppGetPicDescRetCode failed"); | |
807 | 769 | |
808 | 770 | bool bCached = false; |
809 | 771 | if(width > 0 && height > 0 && outputSize > 0){ |
... | ... | @@ -828,16 +790,20 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o |
828 | 790 | // 换成解码后数据, 这里这样做的是为了保证解码一直持续进行,避免后续操作阻碍文件读取和解码从而导致花屏 |
829 | 791 | DvppDataMemory* mem = nullptr; |
830 | 792 | if (m_bResize && (width > 1920 || height > 1080)) { |
831 | - | |
832 | - mem = m_vpcUtils.resize(output, out_frame_width, out_frame_height); | |
833 | - if (mem) { | |
834 | - acldvppFree(outputDataDev); | |
835 | - outputDataDev = nullptr; | |
836 | - | |
837 | - mem->setDeviceId(to_string(m_dvpp_deviceId)); | |
838 | - mem->setId(m_dec_name); | |
839 | - mem->setFrameNb(frame_nb); | |
793 | + VpcUtils* pUtil = VpcUtils::getInstance(); | |
794 | + if (pUtil) { | |
795 | + mem = pUtil->resize(output, out_frame_width, out_frame_height); | |
796 | + if (mem) { | |
797 | + acldvppFree(outputDataDev); | |
798 | + outputDataDev = nullptr; | |
799 | + | |
800 | + mem->setDeviceId(to_string(m_dvpp_deviceId)); | |
801 | + mem->setId(m_dec_name); | |
802 | + mem->setFrameNb(frame_nb); | |
803 | + } | |
840 | 804 | } |
805 | + | |
806 | + | |
841 | 807 | } else { |
842 | 808 | mem = new DvppDataMemory(width, width_stride, height, height_stride, outputSize, m_dec_name, to_string(m_dvpp_deviceId), false, frame_nb, (unsigned char *)outputDataDev); |
843 | 809 | } |
... | ... | @@ -857,8 +823,8 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o |
857 | 823 | } |
858 | 824 | }while(0); |
859 | 825 | |
860 | - CHECK_AND_RETURN_NOVALUE(acldvppDestroyStreamDesc(input), "acldvppDestroyStreamDesc failed"); | |
861 | - CHECK_AND_RETURN_NOVALUE(acldvppDestroyPicDesc(output), "acldvppDestroyPicDesc failed"); | |
826 | + ACL_CHECK_AND_ABORT(acldvppDestroyStreamDesc(input), "acldvppDestroyStreamDesc failed"); | |
827 | + ACL_CHECK_AND_ABORT(acldvppDestroyPicDesc(output), "acldvppDestroyPicDesc failed"); | |
862 | 828 | } |
863 | 829 | |
864 | 830 | bool DvppDecoder::sendVdecEos(aclvdecChannelDesc *vdecChannelDesc) { |
... | ... | @@ -931,10 +897,7 @@ void DvppDecoder::display_thread() { |
931 | 897 | |
932 | 898 | void DvppDecoder::release_dvpp(){ |
933 | 899 | if(m_context){ |
934 | - aclError ret = aclrtDestroyContext(m_context); | |
935 | - if(ret != ACL_ERROR_NONE){ | |
936 | - LOG_ERROR("[{}]- aclrtDestroyContext failed !", m_dec_name); | |
937 | - } | |
900 | + ACL_CHECK_AND_ABORT(aclrtDestroyContext(m_context), "aclrtDestroyContext failed"); | |
938 | 901 | m_context = nullptr; |
939 | 902 | } |
940 | 903 | ... | ... |
src/decoder/dvpp/DvppDecoder.h
... | ... | @@ -12,8 +12,6 @@ |
12 | 12 | |
13 | 13 | #include "FFRecoderTaskManager.h" |
14 | 14 | |
15 | -#include "VpcUtils.h" | |
16 | - | |
17 | 15 | using namespace std; |
18 | 16 | |
19 | 17 | typedef void(*RECEIVER_FINISHED_CALLBACK)(const void* userPtr); |
... | ... | @@ -143,6 +141,4 @@ private: |
143 | 141 | |
144 | 142 | std::atomic<int> m_DvppCacheCounter{0}; |
145 | 143 | int m_cache_gop{0}; |
146 | - | |
147 | - VpcUtils m_vpcUtils; | |
148 | 144 | }; |
149 | 145 | \ No newline at end of file | ... | ... |
src/decoder/dvpp/VpcUtils.cpp
... | ... | @@ -3,14 +3,8 @@ |
3 | 3 | |
4 | 4 | #define ALIGN_UP(val, align) (((val) % (align) == 0) ? (val) : (((val) / (align) + 1) * (align))) |
5 | 5 | |
6 | -#define CHECK_AND_RETURN(ret, message) \ | |
7 | - if(ret != 0) {LOG_ERROR("{}", message); return ret;} | |
8 | -#define CHECK_NOT_RETURN(ret, message) \ | |
9 | - if(ret != 0) {LOG_ERROR("{}", message);} | |
10 | -#define CHECK_AND_RETURN_NOVALUE(ret, message) \ | |
11 | - if(ret != 0) {LOG_ERROR("{}", message); return;} | |
12 | -#define CHECK_AND_BREAK(ret, message) \ | |
13 | - if(ret != 0) {LOG_ERROR("{}", message); break;} | |
6 | +#define ACL_CHECK_AND_ABORT(ret, message) \ | |
7 | + if(ret != 0) {LOG_ERROR("{}", message); std::abort();} | |
14 | 8 | |
15 | 9 | VpcUtils::VpcUtils(){ |
16 | 10 | |
... | ... | @@ -22,34 +16,33 @@ VpcUtils::~VpcUtils(){ |
22 | 16 | |
23 | 17 | int VpcUtils::init(int devId){ |
24 | 18 | |
19 | + if (context_) { | |
20 | + return 1; | |
21 | + } | |
22 | + | |
23 | + | |
25 | 24 | m_devId = devId; |
26 | 25 | |
27 | - aclError ret = aclrtCreateContext(&context_, m_devId); | |
28 | - if (ret != ACL_ERROR_NONE) { | |
29 | - LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); | |
30 | - return false; | |
31 | - } | |
26 | + ACL_CHECK_AND_ABORT(aclrtCreateContext(&context_, m_devId), "aclrtCreateContext failed !"); | |
32 | 27 | |
33 | 28 | do |
34 | 29 | { |
35 | - aclrtCreateStream(&stream_); | |
30 | + ACL_CHECK_AND_ABORT(aclrtCreateStream(&stream_), "aclrtCreateStream failed !"); | |
36 | 31 | |
37 | 32 | dvppChannelDesc_ = acldvppCreateChannelDesc(); |
38 | 33 | |
39 | - ret = acldvppCreateChannel(dvppChannelDesc_); | |
40 | - CHECK_AND_BREAK(ret, "acldvppCreateChannel failed !"); | |
41 | - | |
42 | - ret = acldvppSetChannelDescMode(dvppChannelDesc_, DVPP_CHNMODE_VPC); | |
43 | - CHECK_AND_BREAK(ret, "acldvppSetChannelDescMode failed !"); | |
34 | + ACL_CHECK_AND_ABORT(acldvppSetChannelDescMode(dvppChannelDesc_, DVPP_CHNMODE_VPC), "acldvppSetChannelDescMode failed !"); | |
35 | + ACL_CHECK_AND_ABORT(acldvppCreateChannel(dvppChannelDesc_), "acldvppCreateChannel failed !"); | |
36 | + | |
44 | 37 | } while (0); |
45 | 38 | |
46 | - return ret; | |
39 | + return 0; | |
47 | 40 | } |
48 | 41 | |
49 | 42 | void VpcUtils::release() { |
50 | 43 | |
51 | 44 | if(context_){ |
52 | - aclrtSetCurrentContext(context_); | |
45 | + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !"); | |
53 | 46 | |
54 | 47 | if (dvppChannelDesc_) { |
55 | 48 | (void)acldvppDestroyChannel(dvppChannelDesc_); |
... | ... | @@ -63,12 +56,13 @@ void VpcUtils::release() { |
63 | 56 | } |
64 | 57 | |
65 | 58 | aclrtDestroyContext(context_); |
59 | + context_ = nullptr; | |
66 | 60 | } |
67 | 61 | } |
68 | 62 | |
69 | 63 | DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){ |
70 | 64 | |
71 | - aclrtSetCurrentContext(context_); | |
65 | + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !"); | |
72 | 66 | |
73 | 67 | int out_buf_width = ALIGN_UP(out_width, 16) * 3; |
74 | 68 | int out_buf_height = ALIGN_UP(out_height, 2); |
... | ... | @@ -78,6 +72,11 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, |
78 | 72 | void *outBufferDev_ = (void*)rgbMem->getMem(); |
79 | 73 | |
80 | 74 | acldvppPicDesc *outputDesc_= acldvppCreatePicDesc(); |
75 | + if(outputDesc_ == nullptr){ | |
76 | + LOG_ERROR("acldvppCreatePicDesc failed !"); | |
77 | + std::abort(); | |
78 | + } | |
79 | + | |
81 | 80 | acldvppSetPicDescData(outputDesc_, outBufferDev_); |
82 | 81 | acldvppSetPicDescFormat(outputDesc_, PIXEL_FORMAT_BGR_888); |
83 | 82 | acldvppSetPicDescWidth(outputDesc_, out_width); |
... | ... | @@ -92,12 +91,13 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, |
92 | 91 | ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_); |
93 | 92 | if(ret != ACL_ERROR_NONE){ |
94 | 93 | LOG_ERROR("acldvppVpcConvertColorAsync failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size); |
95 | - break; | |
94 | + std::abort(); | |
96 | 95 | } |
96 | + | |
97 | 97 | ret = aclrtSynchronizeStream(stream_); |
98 | 98 | if(ret != ACL_ERROR_NONE){ |
99 | 99 | LOG_ERROR("aclrtSynchronizeStream failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size); |
100 | - break; | |
100 | + std::abort(); | |
101 | 101 | } |
102 | 102 | }while(0); |
103 | 103 | |
... | ... | @@ -113,13 +113,18 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, |
113 | 113 | |
114 | 114 | DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ |
115 | 115 | |
116 | - aclrtSetCurrentContext(context_); | |
116 | + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !"); | |
117 | 117 | |
118 | 118 | int out_width = inMem->getWidth(); |
119 | 119 | int out_height = inMem->getHeight(); |
120 | 120 | |
121 | 121 | |
122 | 122 | acldvppPicDesc *inputDesc_= acldvppCreatePicDesc(); |
123 | + if(inputDesc_ == nullptr){ | |
124 | + LOG_ERROR("acldvppCreatePicDesc failed !"); | |
125 | + std::abort(); | |
126 | + } | |
127 | + | |
123 | 128 | acldvppSetPicDescData(inputDesc_, inMem->getMem()); |
124 | 129 | acldvppSetPicDescFormat(inputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420); |
125 | 130 | acldvppSetPicDescWidth(inputDesc_, out_width); |
... | ... | @@ -136,6 +141,11 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ |
136 | 141 | void *outBufferDev_ = (void*)rgbMem->getMem(); |
137 | 142 | |
138 | 143 | acldvppPicDesc *outputDesc_= acldvppCreatePicDesc(); |
144 | + if(outputDesc_ == nullptr){ | |
145 | + LOG_ERROR("acldvppCreatePicDesc failed !"); | |
146 | + std::abort(); | |
147 | + } | |
148 | + | |
139 | 149 | acldvppSetPicDescData(outputDesc_, outBufferDev_); |
140 | 150 | acldvppSetPicDescFormat(outputDesc_, PIXEL_FORMAT_BGR_888); |
141 | 151 | acldvppSetPicDescWidth(outputDesc_, out_width); |
... | ... | @@ -150,12 +160,12 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ |
150 | 160 | ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_); |
151 | 161 | if(ret != ACL_ERROR_NONE){ |
152 | 162 | LOG_ERROR("acldvppVpcConvertColorAsync failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size); |
153 | - break; | |
163 | + std::abort(); | |
154 | 164 | } |
155 | 165 | ret = aclrtSynchronizeStream(stream_); |
156 | 166 | if(ret != ACL_ERROR_NONE){ |
157 | 167 | LOG_ERROR("aclrtSynchronizeStream failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size); |
158 | - break; | |
168 | + std::abort(); | |
159 | 169 | } |
160 | 170 | }while(0); |
161 | 171 | |
... | ... | @@ -172,7 +182,7 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ |
172 | 182 | |
173 | 183 | DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int out_height){ |
174 | 184 | |
175 | - aclrtSetCurrentContext(context_); | |
185 | + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !"); | |
176 | 186 | |
177 | 187 | int out_buf_width = ALIGN_UP(out_width, 16); |
178 | 188 | int out_buf_height = ALIGN_UP(out_height, 2); |
... | ... | @@ -182,6 +192,10 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int |
182 | 192 | void *outBufferDev_ = (void*)rgbMem->getMem(); |
183 | 193 | |
184 | 194 | acldvppPicDesc *outputDesc_= acldvppCreatePicDesc(); |
195 | + if(outputDesc_ == nullptr){ | |
196 | + LOG_ERROR("acldvppCreatePicDesc failed !"); | |
197 | + std::abort(); | |
198 | + } | |
185 | 199 | acldvppSetPicDescData(outputDesc_, outBufferDev_); |
186 | 200 | acldvppSetPicDescFormat(outputDesc_, acldvppGetPicDescFormat(inputDesc_)); |
187 | 201 | acldvppSetPicDescWidth(outputDesc_, out_width); |
... | ... | @@ -198,12 +212,12 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int |
198 | 212 | ret = acldvppVpcResizeAsync(dvppChannelDesc_, inputDesc_, outputDesc_, resizeConfig_, stream_); |
199 | 213 | if(ret != ACL_ERROR_NONE){ |
200 | 214 | LOG_ERROR("acldvppVpcResizeAsync failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size); |
201 | - break; | |
215 | + std::abort(); | |
202 | 216 | } |
203 | 217 | ret = aclrtSynchronizeStream(stream_); |
204 | 218 | if(ret != ACL_ERROR_NONE){ |
205 | 219 | LOG_ERROR("aclrtSynchronizeStream failed - out_width:{} out_height:{} out_buf_width:{} out_buf_height:{} out_buf_size:{}", out_width, out_height, out_buf_width, out_buf_height, out_buf_size); |
206 | - break; | |
220 | + std::abort(); | |
207 | 221 | } |
208 | 222 | }while(0); |
209 | 223 | ... | ... |
src/decoder/dvpp/VpcUtils.h
... | ... | @@ -5,8 +5,17 @@ |
5 | 5 | |
6 | 6 | class VpcUtils{ |
7 | 7 | public: |
8 | + static VpcUtils* getInstance(){ | |
9 | + static VpcUtils* singleton = nullptr; | |
10 | + if (singleton == nullptr){ | |
11 | + singleton = new VpcUtils(); | |
12 | + } | |
13 | + return singleton; | |
14 | + } | |
15 | + | |
8 | 16 | VpcUtils(); |
9 | 17 | ~VpcUtils(); |
18 | + | |
10 | 19 | int init(int); |
11 | 20 | |
12 | 21 | DvppDataMemory* convert2bgr(acldvppPicDesc *input, int out_width, int out_height, bool key_frame); | ... | ... |