diff --git a/src/util/vpc_util.cpp b/src/util/vpc_util.cpp index 7d5ca92..fdc4e07 100755 --- a/src/util/vpc_util.cpp +++ b/src/util/vpc_util.cpp @@ -88,11 +88,33 @@ vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) { acldvppSetPicDescWidthStride(vpcOutputDesc_, cropSizeWidth); acldvppSetPicDescHeightStride(vpcOutputDesc_, cropSizeHeight); acldvppSetPicDescSize(vpcOutputDesc_, vpcOutBufferSize_); + aclrtStream stream_; aclrtCreateStream(&stream_); - int ret = acldvppVpcCropAsync(dvppChannelDesc_, vpcInputDesc_, vpcOutputDesc_, cropArea_, stream_); - ret = aclrtSynchronizeStream(stream_); + bool bRet = false; + do + { + aclError ret = acldvppVpcCropAsync(dvppChannelDesc_, vpcInputDesc_, vpcOutputDesc_, cropArea_, stream_); + if (ret != ACL_SUCCESS) { + LOG_ERROR("acldvppVpcCropAsync failed, task_id : {}", devMem->getId()); + break; + } + ret = aclrtSynchronizeStream(stream_); + if (ret != ACL_SUCCESS) { + LOG_ERROR("aclrtSynchronizeStream failed, task_id : {}", devMem->getId()); + break; + } + + img_info.pic_desc = vpcOutputDesc_; + img_info.object_id = obj.object_id; + img_info.task_id = obj.task_id; //该物体属于的任务ID号 + img_info.task_frame_count = obj.task_frame_count; //该物体当前出现的帧号 + img_info.index = obj.index; //该物体所属类别的编号 + img_info.confidence = obj.confidence; //该物体的置信度 + bRet = true; + } while (0); + if (stream_ != nullptr) { aclrtDestroyStream(stream_); } @@ -103,20 +125,15 @@ vpc_img_info VPCUtil::crop(DeviceMemory *devMem, video_object_info obj) { (void)acldvppDestroyRoiConfig(cropArea_); cropArea_ = nullptr; - img_info.pic_desc = vpcOutputDesc_; - img_info.object_id = obj.object_id; - img_info.task_id = obj.task_id; //该物体属于的任务ID号 - img_info.task_frame_count = obj.task_frame_count; //该物体当前出现的帧号 - img_info.index = obj.index; //该物体所属类别的编号 - img_info.confidence = obj.confidence; //该物体的置信度 - - // (void)acldvppDestroyPicDesc(vpcOutputDesc_); - // vpcOutputDesc_ = nullptr; + if (!bRet) { + (void)acldvppDestroyPicDesc(vpcOutputDesc_); + vpcOutputDesc_ = nullptr; - // if (vpcOutBufferDev_ != nullptr) { - // (void)acldvppFree(vpcOutBufferDev_); - // vpcOutBufferDev_ = nullptr; - // } + if (vpcOutBufferDev_ != nullptr) { + (void)acldvppFree(vpcOutBufferDev_); + vpcOutBufferDev_ = nullptr; + } + } return img_info; } @@ -234,49 +251,62 @@ vector VPCUtil::crop_batch(DeviceMemory *devMem, vectorgetId()); + break; + } + ret = aclrtSynchronizeStream(stream_); + if (ret != ACL_SUCCESS) { + LOG_ERROR("aclrtSynchronizeStream failed, task_id : {}", devMem->getId()); + break; + } + for (uint32_t i = 0; i < outputBatchSize_; i++) { + video_object_info obj = objs[i]; + + vpcOutputDesc = acldvppGetPicDesc(outputBatchPicDesc_, i); + void *outputDataDev = acldvppGetPicDescData(vpcOutputDesc); + uint32_t outputSize = acldvppGetPicDescSize(vpcOutputDesc); + uint32_t width = acldvppGetPicDescWidth(vpcOutputDesc); + uint32_t width_stride = acldvppGetPicDescWidthStride(vpcOutputDesc); + uint32_t height = acldvppGetPicDescHeight(vpcOutputDesc); + uint32_t height_stride = acldvppGetPicDescHeightStride(vpcOutputDesc); + acldvppPixelFormat fmt = acldvppGetPicDescFormat(vpcOutputDesc); + + acldvppPicDesc *vpcInputDesc_= acldvppCreatePicDesc(); + acldvppSetPicDescData(vpcInputDesc_, vecOutPtr_[i]); + acldvppSetPicDescFormat(vpcInputDesc_, fmt); + acldvppSetPicDescWidth(vpcInputDesc_, width); + acldvppSetPicDescHeight(vpcInputDesc_, height); + acldvppSetPicDescWidthStride(vpcInputDesc_, width_stride); + acldvppSetPicDescHeightStride(vpcInputDesc_, height_stride); + acldvppSetPicDescSize(vpcInputDesc_, outputSize); + + vpc_img_info img_info ; + img_info.pic_desc = vpcInputDesc_; + img_info.object_id = obj.object_id; + img_info.task_id = obj.task_id; //该物体属于的任务ID号 + img_info.task_frame_count = obj.task_frame_count; //该物体当前出现的帧号 + img_info.index = obj.index; //该物体所属类别的编号 + img_info.confidence = obj.confidence; //该物体的置信度 + vec_img_info.push_back(img_info); + // vpcOutputDesc = acldvppGetPicDesc(outputBatchPicDesc_, i); + // string file_name = "output"; + // file_name = file_name + to_string(i) + ".jpg"; + // vpc_jpeg_encode(vpcOutputDesc, file_name); + } + + bRet = true; + } while (0); + if (stream_ != nullptr) { aclrtDestroyStream(stream_); } - for (uint32_t i = 0; i < outputBatchSize_; i++) { - video_object_info obj = objs[i]; - - vpcOutputDesc = acldvppGetPicDesc(outputBatchPicDesc_, i); - void *outputDataDev = acldvppGetPicDescData(vpcOutputDesc); - uint32_t outputSize = acldvppGetPicDescSize(vpcOutputDesc); - uint32_t width = acldvppGetPicDescWidth(vpcOutputDesc); - uint32_t width_stride = acldvppGetPicDescWidthStride(vpcOutputDesc); - uint32_t height = acldvppGetPicDescHeight(vpcOutputDesc); - uint32_t height_stride = acldvppGetPicDescHeightStride(vpcOutputDesc); - acldvppPixelFormat fmt = acldvppGetPicDescFormat(vpcOutputDesc); - - acldvppPicDesc *vpcInputDesc_= acldvppCreatePicDesc(); - acldvppSetPicDescData(vpcInputDesc_, vecOutPtr_[i]); - acldvppSetPicDescFormat(vpcInputDesc_, fmt); - acldvppSetPicDescWidth(vpcInputDesc_, width); - acldvppSetPicDescHeight(vpcInputDesc_, height); - acldvppSetPicDescWidthStride(vpcInputDesc_, width_stride); - acldvppSetPicDescHeightStride(vpcInputDesc_, height_stride); - acldvppSetPicDescSize(vpcInputDesc_, outputSize); - - vpc_img_info img_info ; - img_info.pic_desc = vpcInputDesc_; - img_info.object_id = obj.object_id; - img_info.task_id = obj.task_id; //该物体属于的任务ID号 - img_info.task_frame_count = obj.task_frame_count; //该物体当前出现的帧号 - img_info.index = obj.index; //该物体所属类别的编号 - img_info.confidence = obj.confidence; //该物体的置信度 - vec_img_info.push_back(img_info); - // vpcOutputDesc = acldvppGetPicDesc(outputBatchPicDesc_, i); - // string file_name = "output"; - // file_name = file_name + to_string(i) + ".jpg"; - // vpc_jpeg_encode(vpcOutputDesc, file_name); - } - aclrtSetCurrentContext(context_); if (vpcInputBatchDesc_ != nullptr) { @@ -284,11 +314,13 @@ vector VPCUtil::crop_batch(DeviceMemory *devMem, vector