From c9cf03be4a49effaa61af2d5c64bc30898aa2ffc Mon Sep 17 00:00:00 2001 From: fiss <2657262686@qq.com> Date: Thu, 17 Aug 2023 19:00:32 +0800 Subject: [PATCH] 保存失败的图片不发送mq消息 --- src/reprocessing_module/save_snapshot_reprocessing.cpp | 5 +++-- src/util/JpegUtil.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++------------- src/util/JpegUtil.h | 2 +- src/util/vpc_util.cpp | 6 ++++-- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/reprocessing_module/save_snapshot_reprocessing.cpp b/src/reprocessing_module/save_snapshot_reprocessing.cpp index 8320145..0bbe573 100755 --- a/src/reprocessing_module/save_snapshot_reprocessing.cpp +++ b/src/reprocessing_module/save_snapshot_reprocessing.cpp @@ -93,14 +93,15 @@ void save_snapshot_reprocessing::save_img_process() { waitforsave_img_queue.pop(); l.unlock(); + bool bSaved = false; if(!cur_image.file_path.empty()){ - jpegUtil.jpeg_encode(cur_image.img_info.pic_desc, cur_image.file_path); + bSaved = jpegUtil.jpeg_encode(cur_image.img_info.pic_desc, cur_image.file_path); } VPCUtil::vpc_img_release(cur_image.img_info); #ifdef POST_USE_RABBITMQ // LOG_INFO("mq publish process in: {}", cur_image.json_str); - if (callback_ != nullptr && cur_image.json_str.length() > 0) { + if (bSaved && callback_ != nullptr && cur_image.json_str.length() > 0) { // LOG_INFO("mq publish process begin"); callback_(cur_image.json_str.c_str()); LOG_INFO("mq publish process end: {} ", cur_image.json_str); diff --git a/src/util/JpegUtil.cpp b/src/util/JpegUtil.cpp index b47fbc5..396a24a 100755 --- a/src/util/JpegUtil.cpp +++ b/src/util/JpegUtil.cpp @@ -75,7 +75,7 @@ int32_t JpegUtil::jpege_save(char* pcData , uint32_t dataLen, string out_file_na return 0; } -void JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name) { +bool JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name) { aclError aclRet ; aclRet = aclrtSetDevice(deviceId_); @@ -84,23 +84,52 @@ void JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_nam // 8. 申请输出内存,申请Device内存encodeOutBufferDev_,存放编码后的输出数据 uint32_t outBufferSize= 0; int ret = acldvppJpegPredictEncSize(encodeInputDesc_, jpegeConfig_, &outBufferSize); + if (ret != ACL_SUCCESS) { + return false; + } void *encodeOutBufferDev_ = nullptr; ret = acldvppMalloc(&encodeOutBufferDev_, outBufferSize); + if (ret != ACL_SUCCESS) { + return false; + } - // 9. 执行异步编码,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成 - aclRet = acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, &outBufferSize, jpegeConfig_, stream_); - aclRet = aclrtSynchronizeStream(stream_); + bool bRet = false; + do { + // 9. 执行异步编码,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成 + aclRet = acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, &outBufferSize, jpegeConfig_, stream_); + if (ret != ACL_SUCCESS) { + break; + } + aclRet = aclrtSynchronizeStream(stream_); + if (ret != ACL_SUCCESS) { + break; + } - // 该模式下,由于处理结果在Device侧,因此需要调用内存复制接口传输结果数据后,再释放Device侧内存 - // 申请Host内存outputHostBuffer - void* outputHostBuffer = malloc(outBufferSize); - // 通过aclrtMemcpy接口将Device的处理结果数据传输到Host - aclRet = aclrtMemcpy(outputHostBuffer, outBufferSize, encodeOutBufferDev_, outBufferSize, ACL_MEMCPY_DEVICE_TO_HOST); + // 申请Host内存outputHostBuffer + void* outputHostBuffer = malloc(outBufferSize); + + // 通过aclrtMemcpy接口将Device的处理结果数据传输到Host + aclRet = aclrtMemcpy(outputHostBuffer, outBufferSize, encodeOutBufferDev_, outBufferSize, ACL_MEMCPY_DEVICE_TO_HOST); + if (ret != ACL_SUCCESS) { + free(outputHostBuffer); + outputHostBuffer = nullptr; + break; + } + + // 数据使用完成后,释放内存 + ret = jpege_save((char*)outputHostBuffer, outBufferSize, out_file_name); + if(ret != 0) { + free(outputHostBuffer); + outputHostBuffer = nullptr; + break; + } + + bRet = true; + } while (0); + // 释放掉输入输出的device内存 (void)acldvppFree(encodeOutBufferDev_); encodeOutBufferDev_ = nullptr; - // 数据使用完成后,释放内存 - jpege_save((char*)outputHostBuffer, outBufferSize, out_file_name); - free(outputHostBuffer); - outputHostBuffer = nullptr; + + return bRet; } \ No newline at end of file diff --git a/src/util/JpegUtil.h b/src/util/JpegUtil.h index a569a9a..8e74d42 100755 --- a/src/util/JpegUtil.h +++ b/src/util/JpegUtil.h @@ -15,7 +15,7 @@ public: void jpeg_release(); - void jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name); + bool jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name); private: int32_t jpege_save(char* pcData , uint32_t dataLen, string out_file_name); diff --git a/src/util/vpc_util.cpp b/src/util/vpc_util.cpp index d30d8e6..7d5ca92 100755 --- a/src/util/vpc_util.cpp +++ b/src/util/vpc_util.cpp @@ -175,8 +175,10 @@ vector VPCUtil::crop_batch(DeviceMemory *devMem, vector