diff --git a/src/decoder/dvpp/DvppDataMemory.hpp b/src/decoder/dvpp/DvppDataMemory.hpp index 2286532..250781d 100644 --- a/src/decoder/dvpp/DvppDataMemory.hpp +++ b/src/decoder/dvpp/DvppDataMemory.hpp @@ -20,6 +20,7 @@ public: int ret = acldvppMalloc((void **)&pHwRgb, data_size); if(ret != ACL_ERROR_NONE){ LOG_ERROR("[{}]- acldvppMalloc failed", id); + std::abort(); } } @@ -40,14 +41,14 @@ public: int ret = acldvppMalloc((void **)&pHwRgb, data_size); if(ret != ACL_ERROR_NONE){ LOG_ERROR("[{}]- acldvppMalloc failed", pSrc->getId()); - return; + std::abort(); } ret = aclrtMemcpy(pHwRgb, data_size, pSrc->getMem(), pSrc->getSize(), ACL_MEMCPY_DEVICE_TO_DEVICE); if(ret != ACL_ERROR_NONE){ acldvppFree(pHwRgb); LOG_ERROR("[{}]- aclrtMemcpy failed", pSrc->getId()); - return; + std::abort(); } data_type = 2; @@ -64,6 +65,7 @@ public: int ret = acldvppFree(pHwRgb); if(ret != ACL_ERROR_NONE){ LOG_ERROR("[{}]- acldvppFree failed", id); + std::abort(); } pHwRgb = nullptr; } diff --git a/src/decoder/dvpp/DvppDecoder.cpp b/src/decoder/dvpp/DvppDecoder.cpp index e15d78a..d70e38a 100644 --- a/src/decoder/dvpp/DvppDecoder.cpp +++ b/src/decoder/dvpp/DvppDecoder.cpp @@ -1,17 +1,10 @@ #include "DvppDecoder.h" #include "DvppSourceManager.h" +#include "VpcUtils.h" -#define CHECK_AND_RETURN(ret, message) \ - if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); return ret;} -#define CHECK_NOT_RETURN(ret, message) \ - if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message);} -#define CHECK_AND_RETURN_NOVALUE(ret, message) \ - if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); return;} -#define CHECK_AND_BREAK(ret, message) \ - if(ret != 0) {LOG_ERROR("[{}]- {}", m_dec_name, message); break;} - - +#define ACL_CHECK_AND_ABORT(ret, message) \ + if(ret != 0) {LOG_ERROR("[{}]- {}:{}", m_dec_name, message, ret); std::abort();} struct Vdec_CallBack_UserData { @@ -328,14 +321,13 @@ int DvppDecoder::getVdecType(int videoType, int profile) m_dvpp_deviceId = atoi(cfg.gpuid.c_str()); + VpcUtils* pUtil = VpcUtils::getInstance(); + pUtil->init(m_dvpp_deviceId); + post_decoded_cbk = cfg.post_decoded_cbk; do{ - aclError ret = aclrtCreateContext(&m_context, m_dvpp_deviceId); - if (ret != ACL_ERROR_NONE) { - LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); - break; - } + ACL_CHECK_AND_ABORT(aclrtCreateContext(&m_context, m_dvpp_deviceId), "aclrtCreateContext failed !"); // DvppSourceManager 创建时包含 aclInit,析构时包含 aclFinalize DvppSourceManager* pSrcMgr = DvppSourceManager::getInstance(); @@ -346,7 +338,6 @@ int DvppDecoder::getVdecType(int videoType, int profile) } m_bResize = cfg.resize; - m_vpcUtils.init(m_dvpp_deviceId); LOG_INFO("[{}]- init vdpp success! device:{} channel:{}", m_dec_name, m_dvpp_deviceId, m_dvpp_channel); return true; @@ -440,11 +431,7 @@ static int snap_count = 0; DeviceMemory* DvppDecoder::snapshot(){ - int ret = aclrtSetCurrentContext(m_context); - if(ret != ACL_ERROR_NONE){ - LOG_ERROR("[{}]- aclrtSetCurrentContext failed", m_dec_name); - return nullptr; - } + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed !"); // 注意有锁 DeviceMemory* snapshot_mem = nullptr; @@ -522,26 +509,23 @@ void DvppDecoder::read_thread() { aclvdecChannelDesc *vdecChannelDesc = nullptr; do { - int ret = aclrtSetCurrentContext(m_context); - if(ret != ACL_ERROR_NONE){ - LOG_ERROR("[{}]- aclrtSetCurrentContext failed", m_dec_name); - break; - } + aclrtSetDevice(m_dvpp_deviceId); + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed !"); vdecChannelDesc = aclvdecCreateChannelDesc(); if (vdecChannelDesc == nullptr) { LOG_ERROR("[{}]- aclvdecCreateChannelDesc failed", m_dec_name); - break; + std::abort(); } // 创建 channel dec结构体 // 通道ID在dvpp层面为0~31 - CHECK_AND_BREAK(aclvdecSetChannelDescChannelId(vdecChannelDesc, m_dvpp_channel), "aclvdecSetChannelDescChannelId failed"); - CHECK_AND_BREAK(aclvdecSetChannelDescThreadId(vdecChannelDesc, report_thread), "aclvdecSetChannelDescThreadId failed"); - CHECK_AND_BREAK(aclvdecSetChannelDescCallback(vdecChannelDesc, VdecCallback), "aclvdecSetChannelDescCallback failed"); - CHECK_AND_BREAK(aclvdecSetChannelDescEnType(vdecChannelDesc, m_enType), "aclvdecSetChannelDescEnType failed"); - CHECK_AND_BREAK(aclvdecSetChannelDescOutPicFormat(vdecChannelDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420), "aclvdecSetChannelDescOutPicFormat failed"); - CHECK_AND_BREAK(aclvdecCreateChannel(vdecChannelDesc), "aclvdecCreateChannel failed"); + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescChannelId(vdecChannelDesc, m_dvpp_channel), "aclvdecSetChannelDescChannelId failed"); + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescThreadId(vdecChannelDesc, report_thread), "aclvdecSetChannelDescThreadId failed"); + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescCallback(vdecChannelDesc, VdecCallback), "aclvdecSetChannelDescCallback failed"); + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescEnType(vdecChannelDesc, m_enType), "aclvdecSetChannelDescEnType failed"); + ACL_CHECK_AND_ABORT(aclvdecSetChannelDescOutPicFormat(vdecChannelDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420), "aclvdecSetChannelDescOutPicFormat failed"); + ACL_CHECK_AND_ABORT(aclvdecCreateChannel(vdecChannelDesc), "aclvdecCreateChannel failed"); unsigned long long frame_nb = 0; AVPacket* pkt = av_packet_alloc(); @@ -638,15 +622,15 @@ void DvppDecoder::read_thread() { } while (0); if (vdecChannelDesc) { - CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); - CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed"); + ACL_CHECK_AND_ABORT(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); + ACL_CHECK_AND_ABORT(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed"); vdecChannelDesc = nullptr; } m_bRunning=false; m_bExitReportThd = true; - CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "report_thread join failed"); + ACL_CHECK_AND_ABORT(pthread_join(report_thread, nullptr), "report_thread join failed"); m_bExitDisplayThd = true; display_thread_.join(); @@ -672,38 +656,26 @@ int DvppDecoder::sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, uns acldvppStreamDesc *input_stream_desc = nullptr; acldvppPicDesc *output_pic_desc = nullptr; do{ - int ret = acldvppMalloc((void **)&vdecInputbuf, pkt->size); - if(ACL_ERROR_NONE != ret){ - LOG_ERROR("[{}]- acldvppMalloc failed!, ret:{}", m_dec_name, ret); - break; - } + int ret = -1; - ret = aclrtMemcpy(vdecInputbuf, pkt->size, pkt->data, pkt->size, ACL_MEMCPY_HOST_TO_DEVICE); - if(ACL_ERROR_NONE != ret){ - LOG_ERROR("[{}]- aclrtMemcpy failed", m_dec_name); - break; - } - - ret = acldvppMalloc((void **)&vdecOutputBuf, m_vdec_out_size); - if(ret != ACL_ERROR_NONE){ - LOG_ERROR("[{}]- acldvppMalloc failed", m_dec_name); - break; - } + ACL_CHECK_AND_ABORT(acldvppMalloc((void **)&vdecInputbuf, pkt->size), "acldvppMalloc failed!"); + ACL_CHECK_AND_ABORT(aclrtMemcpy(vdecInputbuf, pkt->size, pkt->data, pkt->size, ACL_MEMCPY_HOST_TO_DEVICE), "aclrtMemcpy failed!"); + ACL_CHECK_AND_ABORT(acldvppMalloc((void **)&vdecOutputBuf, m_vdec_out_size), "acldvppMalloc failed!"); input_stream_desc = acldvppCreateStreamDesc(); if (input_stream_desc == nullptr) { LOG_ERROR("[{}]- acldvppCreateStreamDesc failed", m_dec_name); - break; + std::abort(); } output_pic_desc = acldvppCreatePicDesc(); if (output_pic_desc == nullptr) { LOG_ERROR("[{}]- acldvppCreatePicDesc failed", m_dec_name); - break; + std::abort(); } - CHECK_AND_BREAK(acldvppSetStreamDescData(input_stream_desc, vdecInputbuf), "acldvppSetStreamDescData failed"); - CHECK_AND_BREAK(acldvppSetStreamDescSize(input_stream_desc, pkt->size), "acldvppSetStreamDescSize failed"); - CHECK_AND_BREAK(acldvppSetPicDescData(output_pic_desc, vdecOutputBuf), "acldvppSetPicDescData failed"); - CHECK_AND_BREAK(acldvppSetPicDescSize(output_pic_desc, m_vdec_out_size), "acldvppSetPicDescSize failed"); + ACL_CHECK_AND_ABORT(acldvppSetStreamDescData(input_stream_desc, vdecInputbuf), "acldvppSetStreamDescData failed"); + ACL_CHECK_AND_ABORT(acldvppSetStreamDescSize(input_stream_desc, pkt->size), "acldvppSetStreamDescSize failed"); + ACL_CHECK_AND_ABORT(acldvppSetPicDescData(output_pic_desc, vdecOutputBuf), "acldvppSetPicDescData failed"); + ACL_CHECK_AND_ABORT(acldvppSetPicDescSize(output_pic_desc, m_vdec_out_size), "acldvppSetPicDescSize failed"); Vdec_CallBack_UserData *user_data = NULL; user_data = new Vdec_CallBack_UserData; @@ -735,7 +707,8 @@ int DvppDecoder::sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, uns // 报错情形 if(input_stream_desc){ - CHECK_NOT_RETURN(acldvppDestroyStreamDesc(input_stream_desc), "acldvppDestroyStreamDesc failed"); + ACL_CHECK_AND_ABORT(acldvppDestroyStreamDesc(input_stream_desc), "acldvppDestroyStreamDesc failed"); + input_stream_desc = nullptr; } if (vdecOutputBuf){ @@ -744,7 +717,8 @@ int DvppDecoder::sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, uns } if(output_pic_desc){ - CHECK_NOT_RETURN(acldvppDestroyPicDesc(output_pic_desc), "acldvppDestroyPicDesc failed"); + ACL_CHECK_AND_ABORT(acldvppDestroyPicDesc(output_pic_desc), "acldvppDestroyPicDesc failed"); + output_pic_desc = nullptr; } return -1; @@ -752,20 +726,14 @@ int DvppDecoder::sendPkt(aclvdecChannelDesc *vdecChannelDesc, AVPacket* pkt, uns void DvppDecoder::doProcessReport(){ - aclError ret = aclrtSetDevice(m_dvpp_deviceId); - if(ret != ACL_ERROR_NONE){ - LOG_ERROR("[{}]-aclrtSetDevice failed !", m_dec_name); - return; - } + ACL_CHECK_AND_ABORT(aclrtSetDevice(m_dvpp_deviceId), "aclrtSetDevice failed"); while (!m_bExitReportThd) { aclrtProcessReport(1000); } - ret = aclrtResetDevice(m_dvpp_deviceId); - if(ret != ACL_ERROR_NONE){ - LOG_ERROR("aclrtDestroyContext failed !"); - } + ACL_CHECK_AND_ABORT(aclrtResetDevice(m_dvpp_deviceId), "aclrtResetDevice failed"); + LOG_INFO("doProcessReport exit."); } @@ -783,7 +751,7 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o m_out_count++; - CHECK_AND_RETURN_NOVALUE(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed"); + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(m_context), "aclrtSetCurrentContext failed"); void *inputDataDev = acldvppGetStreamDescData(input); acldvppFree(inputDataDev); @@ -797,13 +765,7 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o uint32_t height_stride = acldvppGetPicDescHeightStride(output); do{ - int ret = acldvppGetPicDescRetCode(output); - if(ret != ACL_ERROR_NONE){ - LOG_ERROR("[{}]- decode result error, retCode:{} ", m_dec_name, ret); - acldvppFree(outputDataDev); - outputDataDev = nullptr; - break; - } + ACL_CHECK_AND_ABORT(acldvppGetPicDescRetCode(output), "acldvppGetPicDescRetCode failed"); bool bCached = false; if(width > 0 && height > 0 && outputSize > 0){ @@ -828,16 +790,20 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o // 换成解码后数据, 这里这样做的是为了保证解码一直持续进行,避免后续操作阻碍文件读取和解码从而导致花屏 DvppDataMemory* mem = nullptr; if (m_bResize && (width > 1920 || height > 1080)) { - - mem = m_vpcUtils.resize(output, out_frame_width, out_frame_height); - if (mem) { - acldvppFree(outputDataDev); - outputDataDev = nullptr; - - mem->setDeviceId(to_string(m_dvpp_deviceId)); - mem->setId(m_dec_name); - mem->setFrameNb(frame_nb); + VpcUtils* pUtil = VpcUtils::getInstance(); + if (pUtil) { + mem = pUtil->resize(output, out_frame_width, out_frame_height); + if (mem) { + acldvppFree(outputDataDev); + outputDataDev = nullptr; + + mem->setDeviceId(to_string(m_dvpp_deviceId)); + mem->setId(m_dec_name); + mem->setFrameNb(frame_nb); + } } + + } else { mem = new DvppDataMemory(width, width_stride, height, height_stride, outputSize, m_dec_name, to_string(m_dvpp_deviceId), false, frame_nb, (unsigned char *)outputDataDev); } @@ -857,8 +823,8 @@ void DvppDecoder::doVdppVdecCallBack(acldvppStreamDesc *input, acldvppPicDesc *o } }while(0); - CHECK_AND_RETURN_NOVALUE(acldvppDestroyStreamDesc(input), "acldvppDestroyStreamDesc failed"); - CHECK_AND_RETURN_NOVALUE(acldvppDestroyPicDesc(output), "acldvppDestroyPicDesc failed"); + ACL_CHECK_AND_ABORT(acldvppDestroyStreamDesc(input), "acldvppDestroyStreamDesc failed"); + ACL_CHECK_AND_ABORT(acldvppDestroyPicDesc(output), "acldvppDestroyPicDesc failed"); } bool DvppDecoder::sendVdecEos(aclvdecChannelDesc *vdecChannelDesc) { @@ -931,10 +897,7 @@ void DvppDecoder::display_thread() { void DvppDecoder::release_dvpp(){ if(m_context){ - aclError ret = aclrtDestroyContext(m_context); - if(ret != ACL_ERROR_NONE){ - LOG_ERROR("[{}]- aclrtDestroyContext failed !", m_dec_name); - } + ACL_CHECK_AND_ABORT(aclrtDestroyContext(m_context), "aclrtDestroyContext failed"); m_context = nullptr; } diff --git a/src/decoder/dvpp/DvppDecoder.h b/src/decoder/dvpp/DvppDecoder.h index d65c4f0..690e60c 100644 --- a/src/decoder/dvpp/DvppDecoder.h +++ b/src/decoder/dvpp/DvppDecoder.h @@ -12,8 +12,6 @@ #include "FFRecoderTaskManager.h" -#include "VpcUtils.h" - using namespace std; typedef void(*RECEIVER_FINISHED_CALLBACK)(const void* userPtr); @@ -143,6 +141,4 @@ private: std::atomic m_DvppCacheCounter{0}; int m_cache_gop{0}; - - VpcUtils m_vpcUtils; }; \ No newline at end of file diff --git a/src/decoder/dvpp/VpcUtils.cpp b/src/decoder/dvpp/VpcUtils.cpp index c9d3966..d972079 100644 --- a/src/decoder/dvpp/VpcUtils.cpp +++ b/src/decoder/dvpp/VpcUtils.cpp @@ -3,14 +3,8 @@ #define ALIGN_UP(val, align) (((val) % (align) == 0) ? (val) : (((val) / (align) + 1) * (align))) -#define CHECK_AND_RETURN(ret, message) \ - if(ret != 0) {LOG_ERROR("{}", message); return ret;} -#define CHECK_NOT_RETURN(ret, message) \ - if(ret != 0) {LOG_ERROR("{}", message);} -#define CHECK_AND_RETURN_NOVALUE(ret, message) \ - if(ret != 0) {LOG_ERROR("{}", message); return;} -#define CHECK_AND_BREAK(ret, message) \ - if(ret != 0) {LOG_ERROR("{}", message); break;} +#define ACL_CHECK_AND_ABORT(ret, message) \ + if(ret != 0) {LOG_ERROR("{}", message); std::abort();} VpcUtils::VpcUtils(){ @@ -22,34 +16,33 @@ VpcUtils::~VpcUtils(){ int VpcUtils::init(int devId){ + if (context_) { + return 1; + } + + m_devId = devId; - aclError ret = aclrtCreateContext(&context_, m_devId); - if (ret != ACL_ERROR_NONE) { - LOG_ERROR("[{}]-aclrtCreateContext failed !", m_dec_name); - return false; - } + ACL_CHECK_AND_ABORT(aclrtCreateContext(&context_, m_devId), "aclrtCreateContext failed !"); do { - aclrtCreateStream(&stream_); + ACL_CHECK_AND_ABORT(aclrtCreateStream(&stream_), "aclrtCreateStream failed !"); dvppChannelDesc_ = acldvppCreateChannelDesc(); - ret = acldvppCreateChannel(dvppChannelDesc_); - CHECK_AND_BREAK(ret, "acldvppCreateChannel failed !"); - - ret = acldvppSetChannelDescMode(dvppChannelDesc_, DVPP_CHNMODE_VPC); - CHECK_AND_BREAK(ret, "acldvppSetChannelDescMode failed !"); + ACL_CHECK_AND_ABORT(acldvppSetChannelDescMode(dvppChannelDesc_, DVPP_CHNMODE_VPC), "acldvppSetChannelDescMode failed !"); + ACL_CHECK_AND_ABORT(acldvppCreateChannel(dvppChannelDesc_), "acldvppCreateChannel failed !"); + } while (0); - return ret; + return 0; } void VpcUtils::release() { if(context_){ - aclrtSetCurrentContext(context_); + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !"); if (dvppChannelDesc_) { (void)acldvppDestroyChannel(dvppChannelDesc_); @@ -63,12 +56,13 @@ void VpcUtils::release() { } aclrtDestroyContext(context_); + context_ = nullptr; } } DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, int out_height, bool key_frame){ - aclrtSetCurrentContext(context_); + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !"); int out_buf_width = ALIGN_UP(out_width, 16) * 3; int out_buf_height = ALIGN_UP(out_height, 2); @@ -78,6 +72,11 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, void *outBufferDev_ = (void*)rgbMem->getMem(); acldvppPicDesc *outputDesc_= acldvppCreatePicDesc(); + if(outputDesc_ == nullptr){ + LOG_ERROR("acldvppCreatePicDesc failed !"); + std::abort(); + } + acldvppSetPicDescData(outputDesc_, outBufferDev_); acldvppSetPicDescFormat(outputDesc_, PIXEL_FORMAT_BGR_888); acldvppSetPicDescWidth(outputDesc_, out_width); @@ -92,12 +91,13 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_); if(ret != ACL_ERROR_NONE){ 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); - break; + std::abort(); } + ret = aclrtSynchronizeStream(stream_); if(ret != ACL_ERROR_NONE){ 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); - break; + std::abort(); } }while(0); @@ -113,13 +113,18 @@ DvppDataMemory* VpcUtils::convert2bgr(acldvppPicDesc *inputDesc_, int out_width, DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ - aclrtSetCurrentContext(context_); + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !"); int out_width = inMem->getWidth(); int out_height = inMem->getHeight(); acldvppPicDesc *inputDesc_= acldvppCreatePicDesc(); + if(inputDesc_ == nullptr){ + LOG_ERROR("acldvppCreatePicDesc failed !"); + std::abort(); + } + acldvppSetPicDescData(inputDesc_, inMem->getMem()); acldvppSetPicDescFormat(inputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420); acldvppSetPicDescWidth(inputDesc_, out_width); @@ -136,6 +141,11 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ void *outBufferDev_ = (void*)rgbMem->getMem(); acldvppPicDesc *outputDesc_= acldvppCreatePicDesc(); + if(outputDesc_ == nullptr){ + LOG_ERROR("acldvppCreatePicDesc failed !"); + std::abort(); + } + acldvppSetPicDescData(outputDesc_, outBufferDev_); acldvppSetPicDescFormat(outputDesc_, PIXEL_FORMAT_BGR_888); acldvppSetPicDescWidth(outputDesc_, out_width); @@ -150,12 +160,12 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ ret = acldvppVpcConvertColorAsync(dvppChannelDesc_, inputDesc_, outputDesc_, stream_); if(ret != ACL_ERROR_NONE){ 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); - break; + std::abort(); } ret = aclrtSynchronizeStream(stream_); if(ret != ACL_ERROR_NONE){ 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); - break; + std::abort(); } }while(0); @@ -172,7 +182,7 @@ DvppDataMemory* VpcUtils::convert2bgr(DvppDataMemory* inMem){ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int out_height){ - aclrtSetCurrentContext(context_); + ACL_CHECK_AND_ABORT(aclrtSetCurrentContext(context_), "aclrtSetCurrentContext failed !"); int out_buf_width = ALIGN_UP(out_width, 16); int out_buf_height = ALIGN_UP(out_height, 2); @@ -182,6 +192,10 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int void *outBufferDev_ = (void*)rgbMem->getMem(); acldvppPicDesc *outputDesc_= acldvppCreatePicDesc(); + if(outputDesc_ == nullptr){ + LOG_ERROR("acldvppCreatePicDesc failed !"); + std::abort(); + } acldvppSetPicDescData(outputDesc_, outBufferDev_); acldvppSetPicDescFormat(outputDesc_, acldvppGetPicDescFormat(inputDesc_)); acldvppSetPicDescWidth(outputDesc_, out_width); @@ -198,12 +212,12 @@ DvppDataMemory* VpcUtils::resize(acldvppPicDesc *inputDesc_, int out_width, int ret = acldvppVpcResizeAsync(dvppChannelDesc_, inputDesc_, outputDesc_, resizeConfig_, stream_); if(ret != ACL_ERROR_NONE){ 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); - break; + std::abort(); } ret = aclrtSynchronizeStream(stream_); if(ret != ACL_ERROR_NONE){ 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); - break; + std::abort(); } }while(0); diff --git a/src/decoder/dvpp/VpcUtils.h b/src/decoder/dvpp/VpcUtils.h index dac132f..49523be 100644 --- a/src/decoder/dvpp/VpcUtils.h +++ b/src/decoder/dvpp/VpcUtils.h @@ -5,8 +5,17 @@ class VpcUtils{ public: + static VpcUtils* getInstance(){ + static VpcUtils* singleton = nullptr; + if (singleton == nullptr){ + singleton = new VpcUtils(); + } + return singleton; + } + VpcUtils(); ~VpcUtils(); + int init(int); DvppDataMemory* convert2bgr(acldvppPicDesc *input, int out_width, int out_height, bool key_frame); diff --git a/src/decoder/dvpp/dvpp_headers.h b/src/decoder/dvpp/dvpp_headers.h index 936d2a1..990f0c6 100644 --- a/src/decoder/dvpp/dvpp_headers.h +++ b/src/decoder/dvpp/dvpp_headers.h @@ -26,6 +26,6 @@ #include "acl/acl.h" #include "acl/ops/acl_dvpp.h" #include "acl/dvpp/hi_dvpp.h" - + #endif