Commit c9cf03be4a49effaa61af2d5c64bc30898aa2ffc

Authored by Hu Chunming
1 parent 32f28195

保存失败的图片不发送mq消息

src/reprocessing_module/save_snapshot_reprocessing.cpp
... ... @@ -93,14 +93,15 @@ void save_snapshot_reprocessing::save_img_process() {
93 93 waitforsave_img_queue.pop();
94 94 l.unlock();
95 95  
  96 + bool bSaved = false;
96 97 if(!cur_image.file_path.empty()){
97   - jpegUtil.jpeg_encode(cur_image.img_info.pic_desc, cur_image.file_path);
  98 + bSaved = jpegUtil.jpeg_encode(cur_image.img_info.pic_desc, cur_image.file_path);
98 99 }
99 100 VPCUtil::vpc_img_release(cur_image.img_info);
100 101  
101 102 #ifdef POST_USE_RABBITMQ
102 103 // LOG_INFO("mq publish process in: {}", cur_image.json_str);
103   - if (callback_ != nullptr && cur_image.json_str.length() > 0) {
  104 + if (bSaved && callback_ != nullptr && cur_image.json_str.length() > 0) {
104 105 // LOG_INFO("mq publish process begin");
105 106 callback_(cur_image.json_str.c_str());
106 107 LOG_INFO("mq publish process end: {} ", cur_image.json_str);
... ...
src/util/JpegUtil.cpp
... ... @@ -75,7 +75,7 @@ int32_t JpegUtil::jpege_save(char* pcData , uint32_t dataLen, string out_file_na
75 75 return 0;
76 76 }
77 77  
78   -void JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name) {
  78 +bool JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name) {
79 79  
80 80 aclError aclRet ;
81 81 aclRet = aclrtSetDevice(deviceId_);
... ... @@ -84,23 +84,52 @@ void JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_nam
84 84 // 8. 申请输出内存,申请Device内存encodeOutBufferDev_,存放编码后的输出数据
85 85 uint32_t outBufferSize= 0;
86 86 int ret = acldvppJpegPredictEncSize(encodeInputDesc_, jpegeConfig_, &outBufferSize);
  87 + if (ret != ACL_SUCCESS) {
  88 + return false;
  89 + }
87 90 void *encodeOutBufferDev_ = nullptr;
88 91 ret = acldvppMalloc(&encodeOutBufferDev_, outBufferSize);
  92 + if (ret != ACL_SUCCESS) {
  93 + return false;
  94 + }
89 95  
90   - // 9. 执行异步编码,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
91   - aclRet = acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, &outBufferSize, jpegeConfig_, stream_);
92   - aclRet = aclrtSynchronizeStream(stream_);
  96 + bool bRet = false;
  97 + do {
  98 + // 9. 执行异步编码,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成
  99 + aclRet = acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, &outBufferSize, jpegeConfig_, stream_);
  100 + if (ret != ACL_SUCCESS) {
  101 + break;
  102 + }
  103 + aclRet = aclrtSynchronizeStream(stream_);
  104 + if (ret != ACL_SUCCESS) {
  105 + break;
  106 + }
93 107  
94   - // 该模式下,由于处理结果在Device侧,因此需要调用内存复制接口传输结果数据后,再释放Device侧内存
95   - // 申请Host内存outputHostBuffer
96   - void* outputHostBuffer = malloc(outBufferSize);
97   - // 通过aclrtMemcpy接口将Device的处理结果数据传输到Host
98   - aclRet = aclrtMemcpy(outputHostBuffer, outBufferSize, encodeOutBufferDev_, outBufferSize, ACL_MEMCPY_DEVICE_TO_HOST);
  108 + // 申请Host内存outputHostBuffer
  109 + void* outputHostBuffer = malloc(outBufferSize);
  110 +
  111 + // 通过aclrtMemcpy接口将Device的处理结果数据传输到Host
  112 + aclRet = aclrtMemcpy(outputHostBuffer, outBufferSize, encodeOutBufferDev_, outBufferSize, ACL_MEMCPY_DEVICE_TO_HOST);
  113 + if (ret != ACL_SUCCESS) {
  114 + free(outputHostBuffer);
  115 + outputHostBuffer = nullptr;
  116 + break;
  117 + }
  118 +
  119 + // 数据使用完成后,释放内存
  120 + ret = jpege_save((char*)outputHostBuffer, outBufferSize, out_file_name);
  121 + if(ret != 0) {
  122 + free(outputHostBuffer);
  123 + outputHostBuffer = nullptr;
  124 + break;
  125 + }
  126 +
  127 + bRet = true;
  128 + } while (0);
  129 +
99 130 // 释放掉输入输出的device内存
100 131 (void)acldvppFree(encodeOutBufferDev_);
101 132 encodeOutBufferDev_ = nullptr;
102   - // 数据使用完成后,释放内存
103   - jpege_save((char*)outputHostBuffer, outBufferSize, out_file_name);
104   - free(outputHostBuffer);
105   - outputHostBuffer = nullptr;
  133 +
  134 + return bRet;
106 135 }
107 136 \ No newline at end of file
... ...
src/util/JpegUtil.h
... ... @@ -15,7 +15,7 @@ public:
15 15  
16 16 void jpeg_release();
17 17  
18   - void jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name);
  18 + bool jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name);
19 19  
20 20 private:
21 21 int32_t jpege_save(char* pcData , uint32_t dataLen, string out_file_name);
... ...
src/util/vpc_util.cpp
... ... @@ -175,8 +175,10 @@ vector<vpc_img_info> VPCUtil::crop_batch(DeviceMemory *devMem, vector<video_obje
175 175 for (uint32_t i = 0; i < outputBatchSize_; i++) {
176 176 video_object_info obj = objs[i];
177 177  
178   - uint32_t cropSizeWidth = (obj.right - obj.left) / 16 * 16;
179   - uint32_t cropSizeHeight = (obj.bottom - obj.top) / 2 * 2;
  178 + // uint32_t cropSizeWidth = (obj.right - obj.left) / 16 * 16;
  179 + // uint32_t cropSizeHeight = (obj.bottom - obj.top) / 2 * 2;
  180 + uint32_t cropSizeWidth = (obj.right - obj.left + 15) / 16 * 16; //debug by zsh
  181 + uint32_t cropSizeHeight = (obj.bottom - obj.top + 1) / 2 * 2;
180 182  
181 183 uint32_t oddNum = 1;
182 184 uint32_t cropLeftOffset = (obj.left + 1) / 2 * 2; // must even
... ...