diff --git a/src/ai_platform/MultiSourceProcess.cpp b/src/ai_platform/MultiSourceProcess.cpp index b74bd73..242528b 100644 --- a/src/ai_platform/MultiSourceProcess.cpp +++ b/src/ai_platform/MultiSourceProcess.cpp @@ -9,7 +9,6 @@ #include "../decoder/interface/DecoderManager.h" #include "../decoder/interface/utiltools.hpp" -#include "../util/vpc_util.h" #include "../util/crop_process.h" #include "../helpers/time_helper.hpp" #include "../helpers/os_helper.hpp" @@ -17,6 +16,7 @@ #include "../reprocessing_module/save_snapshot_reprocessing.h" #include "macro_definition.h" +#include "SourceSingleton.hpp" #define VEHICLE_MULTI_BOXES @@ -59,12 +59,10 @@ void decode_finished_cbk(const void * userPtr){ } CMultiSourceProcess::CMultiSourceProcess(){ - aclInit(nullptr); } CMultiSourceProcess::~CMultiSourceProcess(){ - dvpp_crop_release(); - aclFinalize(); + vpc_util.vpc_crop_release(); } int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ @@ -72,6 +70,8 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ set_default_logger(LogLevel(vptParam.log_level), "multi_source_process", vptParam.log_path, vptParam.log_mem, vptParam.log_mem); LOG_INFO("编译时间:{} {}", __DATE__, __TIME__); + SourceSingleton::getInstance(); + skip_frame_ = 5; m_batch_size = 16; @@ -93,7 +93,7 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ m_snapshot_reprocessing = snapshot_reprocessing::getInstance(); m_save_snapshot_reprocessing = new save_snapshot_reprocessing(m_devId); - dvpp_crop_init(m_devId); + vpc_util.vpc_crop_init(m_devId); m_pAlgorthimThread = new thread([](void* arg) { CMultiSourceProcess* process = (CMultiSourceProcess*)arg ; @@ -483,13 +483,13 @@ int CMultiSourceProcess::algorithm_vehicle_relult(vector vec_devM ImgSaveInfo saveInfo; saveInfo.file_path = fpath_origin; - saveInfo.img_info = dvpp_devMem2vpcImg(result.memPtr); + saveInfo.img_info = vpc_util.vpc_devMem2vpcImg(result.memPtr); m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(saveInfo); - vector vec_obj_info_list = dvpp_crop_batch(result.memPtr, result.objs); + vector vec_obj_info_list = vpc_util.vpc_crop_batch(result.memPtr, result.objs); if(vec_obj_info_list.size() != result.objs.size()){ LOG_ERROR("vpc_crop size error !"); - dvpp_imgList_release(vec_obj_info_list); + vpc_util.vpc_imgList_release(vec_obj_info_list); continue; } diff --git a/src/ai_platform/MultiSourceProcess.h b/src/ai_platform/MultiSourceProcess.h index 0302a4f..846f95c 100644 --- a/src/ai_platform/MultiSourceProcess.h +++ b/src/ai_platform/MultiSourceProcess.h @@ -5,6 +5,7 @@ #include "../ai_engine_module/VPTProcess.h" #include "../reprocessing_module/snapshot_reprocessing.h" #include "../reprocessing_module/save_snapshot_reprocessing.h" +#include "../util/vpc_util.h" #include #include @@ -78,6 +79,8 @@ private: set m_total_snapshot_info_multi_object; mutex m_total_mutex; + VPCUtil vpc_util; + #ifdef POST_USE_RABBITMQ mq::Manager *mq_manager_{nullptr}; #endif diff --git a/src/ai_platform/SourceSingleton.hpp b/src/ai_platform/SourceSingleton.hpp new file mode 100644 index 0000000..9acc32f --- /dev/null +++ b/src/ai_platform/SourceSingleton.hpp @@ -0,0 +1,28 @@ +#include "acl/acl.h" +#include "acl/ops/acl_dvpp.h" + +class SourceSingleton { +public: + /************************************************** + * 接口:getInstance + * 功能:获取解码器管理者实例 + * 参数:无 + * 返回:成功返回 解码器管理者实例, 失败返回 nullptr + * 备注:调用其他接口前,需要先调用该接口获取管理者实例 + **************************************************/ + static SourceSingleton* getInstance(){ + static SourceSingleton* singleton = nullptr; + if (singleton == nullptr){ + singleton = new SourceSingleton(); + } + return singleton; + } + + SourceSingleton(){ + aclInit(nullptr); + } + + ~SourceSingleton(){ + aclFinalize(); + } +}; \ No newline at end of file diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index acdc43e..7cd2fec 100644 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -499,20 +499,7 @@ string createTask(void *handle, std::vector algor_vec, int gi) return task_id_str; } -int main(int argc, char *argv[]) { - printf("new test\n"); - - if (argc < 4) { - fprintf(stderr, "./xxx 0 2 10 1 ## [start_ai_id, end_ai_id) repeat_num gpu_id\n"); - return -1; - } - - //! load params. - int start_id = atoi(argv[1]); - int end_id = atoi(argv[2]); - int repeat_num = atoi(argv[3]); - int gpuID = atoi(argv[4]); - +void test_gpu(int gpuID){ tsl_aiplatform_param vptParam; vptParam.gpuid = gpuID; vptParam.trt_serialize_file = ""; @@ -529,8 +516,7 @@ int main(int argc, char *argv[]) { int flag = tsl_aiplatform_init(&handle, vptParam); if (0 != flag) { printf("Init Failed! Error Code: %d\n", flag); - system("pause"); - return 0; + return; } else { printf("Init Success\n"); } @@ -538,14 +524,36 @@ int main(int argc, char *argv[]) { std::vector algor_vec = {algorithm_type_t::FACE_SNAPSHOT, algorithm_type_t::HUMAN_SNAPSHOT,algorithm_type_t::ROAD_WORK_DET, algorithm_type_t::VEHICLE_SNAPSHOT, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT, algorithm_type_t::VIDEO_TIMING_SNAPSHOT}; - string task_id = createTask(handle, algor_vec, 0); + string task_id = createTask(handle, algor_vec, 0 + gpuID * 10); + string task_id1 = createTask(handle, algor_vec, 1 + gpuID * 10); + string task_id2 = createTask(handle, algor_vec, 2 + gpuID * 10); - while (getchar() != 'q'); - finish_task(handle, (char*)task_id.data(), 0); + // finish_task(handle, (char*)task_id.data(), 0); + + // tsl_aiplatform_release(&handle); +} + +int main(int argc, char *argv[]) { + printf("new test\n"); + + if (argc < 4) { + fprintf(stderr, "./xxx 0 2 10 1 ## [start_ai_id, end_ai_id) repeat_num gpu_id\n"); + return -1; + } + + //! load params. + int start_id = atoi(argv[1]); + int end_id = atoi(argv[2]); + int repeat_num = atoi(argv[3]); + int gpuID = atoi(argv[4]); + + test_gpu(0); + test_gpu(1); + + while (getchar() != 'q'); - tsl_aiplatform_release(&handle); - printf("Done.\n"); + printf("Done.\n"); return 0; } \ No newline at end of file diff --git a/src/reprocessing_module/save_snapshot_reprocessing.cpp b/src/reprocessing_module/save_snapshot_reprocessing.cpp index 91d90ab..d4dbf96 100644 --- a/src/reprocessing_module/save_snapshot_reprocessing.cpp +++ b/src/reprocessing_module/save_snapshot_reprocessing.cpp @@ -5,8 +5,6 @@ #include #include #include "../common/logger.hpp" -#include "../util/JpegUtil.h" -#include "../util/vpc_util.h" const bool DRAW_ON_IMG = false; @@ -28,14 +26,14 @@ save_snapshot_reprocessing::save_snapshot_reprocessing(int devId) { m_save_img_thread = std::thread(save_img_thread_process, this); m_devId = devId; - DVPP_UTIL::dvpp_jpeg_init(m_devId); + jpegUtil.jpeg_init(m_devId); } save_snapshot_reprocessing::~save_snapshot_reprocessing(){ // 结束线程 bFinish = true; m_save_img_thread.join(); - DVPP_UTIL::dvpp_jpeg_release(); + jpegUtil.jpeg_release(); } // 释放资源 @@ -48,7 +46,7 @@ void save_snapshot_reprocessing::save_snapshot_reprocessing_release() { waitforsave_img_queue.pop(); if(!cur_image.file_path.empty()){ - dvpp_img_release(cur_image.img_info); + vpc_util.vpc_img_release(cur_image.img_info); } } @@ -96,9 +94,9 @@ void save_snapshot_reprocessing::save_img_process() { l.unlock(); if(!cur_image.file_path.empty()){ - DVPP_UTIL::dvpp_jpeg_encode(cur_image.img_info.pic_desc, cur_image.file_path); + jpegUtil.jpeg_encode(cur_image.img_info.pic_desc, cur_image.file_path); } - dvpp_img_release(cur_image.img_info); + vpc_util.vpc_img_release(cur_image.img_info); #ifdef POST_USE_RABBITMQ if (callback_ != nullptr && cur_image.json_str.length() > 0) { diff --git a/src/reprocessing_module/save_snapshot_reprocessing.h b/src/reprocessing_module/save_snapshot_reprocessing.h index 3bc0cc6..7147dce 100644 --- a/src/reprocessing_module/save_snapshot_reprocessing.h +++ b/src/reprocessing_module/save_snapshot_reprocessing.h @@ -16,6 +16,7 @@ #include "../ai_platform/det_obj_header.h" #include "../util/vpc_util.h" +#include "../util/JpegUtil.h" #ifdef POST_USE_RABBITMQ #include "post_reprocessing.hpp" @@ -57,6 +58,9 @@ private: bool bFinish = false; int m_devId; + JpegUtil jpegUtil; + VPCUtil vpc_util; + #ifdef POST_USE_RABBITMQ callback_t callback_; std::shared_ptr rbmq_handler_; diff --git a/src/reprocessing_module/snapshot_reprocessing.cpp b/src/reprocessing_module/snapshot_reprocessing.cpp index f9c9ead..3272423 100644 --- a/src/reprocessing_module/snapshot_reprocessing.cpp +++ b/src/reprocessing_module/snapshot_reprocessing.cpp @@ -150,7 +150,7 @@ void snapshot_reprocessing::filter_vehicle(vector vec_devMem, vec int task_idx = 0; for (auto memPtr : vec_devMem){ - string taskid = memPtr ->getId(); + string taskid = memPtr->getId(); int effective_count = 0; int effective_idx = 0; diff --git a/src/util/JpegUtil.cpp b/src/util/JpegUtil.cpp index 71f7b4f..afb3622 100644 --- a/src/util/JpegUtil.cpp +++ b/src/util/JpegUtil.cpp @@ -5,110 +5,102 @@ using namespace std; -namespace DVPP_UTIL { - int32_t deviceId_; - aclrtContext context_; - aclrtStream stream_; - acldvppChannelDesc *dvppChannelDesc_; +int JpegUtil::jpeg_init(int32_t devId){ + deviceId_ = devId; - int dvpp_jpeg_init(int32_t devId){ - deviceId_ = devId; + aclError ret; + /* 2.Run the management resource application, including Device, Context, Stream */ + aclrtSetDevice(deviceId_); + aclrtCreateContext(&context_, deviceId_); + aclrtCreateStream(&stream_); - aclError ret; - /* 2.Run the management resource application, including Device, Context, Stream */ - aclrtSetDevice(deviceId_); - aclrtCreateContext(&context_, deviceId_); - aclrtCreateStream(&stream_); + // channel 准备 + dvppChannelDesc_ = acldvppCreateChannelDesc(); + ret = acldvppCreateChannel(dvppChannelDesc_); +} - // channel 准备 - dvppChannelDesc_ = acldvppCreateChannelDesc(); - ret = acldvppCreateChannel(dvppChannelDesc_); - } +void JpegUtil::jpeg_release(){ + aclError ret; + ret = aclrtSetDevice(deviceId_); + aclrtSetCurrentContext(context_); - void dvpp_jpeg_release(){ - aclError ret; - ret = aclrtSetDevice(deviceId_); - aclrtSetCurrentContext(context_); - - ret = acldvppDestroyChannel(dvppChannelDesc_); - ret = acldvppDestroyChannelDesc(dvppChannelDesc_); - dvppChannelDesc_ = nullptr; - - if (stream_ != nullptr) { - ret = aclrtDestroyStream(stream_); - if (ret != ACL_SUCCESS) { - printf("destroy stream failed"); - } - stream_ = nullptr; - } - printf("end to destroy stream"); - - if (context_ != nullptr) { - ret = aclrtDestroyContext(context_); - if (ret != ACL_SUCCESS) { - printf("destroy context failed"); - } - context_ = nullptr; - } - printf("end to destroy context"); + ret = acldvppDestroyChannel(dvppChannelDesc_); + ret = acldvppDestroyChannelDesc(dvppChannelDesc_); + dvppChannelDesc_ = nullptr; - ret = aclrtResetDevice(deviceId_); + if (stream_ != nullptr) { + ret = aclrtDestroyStream(stream_); if (ret != ACL_SUCCESS) { - printf("reset device failed"); + printf("destroy stream failed"); } - printf("end to reset device is %d", deviceId_); + stream_ = nullptr; } + printf("end to destroy stream"); - int32_t dvpp_jpege_save(char* pcData , uint32_t dataLen, string out_file_name) - { - FILE* fd = nullptr; - fd = fopen(out_file_name.c_str(), "wb"); - if (fd == nullptr) { - printf("open output file err\n"); - return 1; + if (context_ != nullptr) { + ret = aclrtDestroyContext(context_); + if (ret != ACL_SUCCESS) { + printf("destroy context failed"); } - - fwrite(pcData, dataLen, 1, fd); - fflush(fd); - - fclose(fd); - return 0; + context_ = nullptr; } + printf("end to destroy context"); - void dvpp_jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name){ - - aclError aclRet ; - aclRet = aclrtSetDevice(deviceId_); - aclrtSetCurrentContext(context_); - - // 7. 创建图片编码配置数据,设置编码质量 - // 编码质量范围[0, 100],其中level 0编码质量与level 100差不多,而在[1, 100]内数值越小输出图片质量越差。 - acldvppJpegeConfig *jpegeConfig_ = acldvppCreateJpegeConfig(); - acldvppSetJpegeConfigLevel(jpegeConfig_, 100); - - // 8. 申请输出内存,申请Device内存encodeOutBufferDev_,存放编码后的输出数据 - uint32_t outBufferSize= 0; - int ret = acldvppJpegPredictEncSize(encodeInputDesc_, jpegeConfig_, &outBufferSize); - void *encodeOutBufferDev_ = nullptr; - ret = acldvppMalloc(&encodeOutBufferDev_, outBufferSize); - - // 9. 执行异步编码,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成 - aclRet = acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, &outBufferSize, jpegeConfig_, stream_); - aclRet = aclrtSynchronizeStream(stream_); - - // 该模式下,由于处理结果在Device侧,因此需要调用内存复制接口传输结果数据后,再释放Device侧内存 - // 申请Host内存outputHostBuffer - void* outputHostBuffer = malloc(outBufferSize); - // 通过aclrtMemcpy接口将Device的处理结果数据传输到Host - aclRet = aclrtMemcpy(outputHostBuffer, outBufferSize, encodeOutBufferDev_, outBufferSize, ACL_MEMCPY_DEVICE_TO_HOST); - // 释放掉输入输出的device内存 - (void)acldvppFree(encodeOutBufferDev_); - encodeOutBufferDev_ = nullptr; - // 数据使用完成后,释放内存 - dvpp_jpege_save((char*)outputHostBuffer, outBufferSize, out_file_name); - free(outputHostBuffer); - outputHostBuffer = nullptr; + ret = aclrtResetDevice(deviceId_); + if (ret != ACL_SUCCESS) { + printf("reset device failed"); + } + printf("end to reset device is %d", deviceId_); +} + +int32_t JpegUtil::jpege_save(char* pcData , uint32_t dataLen, string out_file_name) +{ + FILE* fd = nullptr; + fd = fopen(out_file_name.c_str(), "wb"); + if (fd == nullptr) { + printf("open output file err\n"); + return 1; } + fwrite(pcData, dataLen, 1, fd); + fflush(fd); + + fclose(fd); + return 0; +} + +void JpegUtil::jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name){ + + aclError aclRet ; + aclRet = aclrtSetDevice(deviceId_); + aclrtSetCurrentContext(context_); + + // 7. 创建图片编码配置数据,设置编码质量 + // 编码质量范围[0, 100],其中level 0编码质量与level 100差不多,而在[1, 100]内数值越小输出图片质量越差。 + acldvppJpegeConfig *jpegeConfig_ = acldvppCreateJpegeConfig(); + acldvppSetJpegeConfigLevel(jpegeConfig_, 100); + + // 8. 申请输出内存,申请Device内存encodeOutBufferDev_,存放编码后的输出数据 + uint32_t outBufferSize= 0; + int ret = acldvppJpegPredictEncSize(encodeInputDesc_, jpegeConfig_, &outBufferSize); + void *encodeOutBufferDev_ = nullptr; + ret = acldvppMalloc(&encodeOutBufferDev_, outBufferSize); + + // 9. 执行异步编码,再调用aclrtSynchronizeStream接口阻塞程序运行,直到指定Stream中的所有任务都完成 + aclRet = acldvppJpegEncodeAsync(dvppChannelDesc_, encodeInputDesc_, encodeOutBufferDev_, &outBufferSize, jpegeConfig_, stream_); + aclRet = aclrtSynchronizeStream(stream_); + + // 该模式下,由于处理结果在Device侧,因此需要调用内存复制接口传输结果数据后,再释放Device侧内存 + // 申请Host内存outputHostBuffer + void* outputHostBuffer = malloc(outBufferSize); + // 通过aclrtMemcpy接口将Device的处理结果数据传输到Host + aclRet = aclrtMemcpy(outputHostBuffer, outBufferSize, encodeOutBufferDev_, outBufferSize, ACL_MEMCPY_DEVICE_TO_HOST); + // 释放掉输入输出的device内存 + (void)acldvppFree(encodeOutBufferDev_); + encodeOutBufferDev_ = nullptr; + // 数据使用完成后,释放内存 + jpege_save((char*)outputHostBuffer, outBufferSize, out_file_name); + free(outputHostBuffer); + outputHostBuffer = nullptr; } \ No newline at end of file diff --git a/src/util/JpegUtil.h b/src/util/JpegUtil.h index c2147be..4c73c92 100644 --- a/src/util/JpegUtil.h +++ b/src/util/JpegUtil.h @@ -9,13 +9,22 @@ using namespace std; -namespace DVPP_UTIL { +class JpegUtil { +public: + int jpeg_init(int32_t deviceId_); - int dvpp_jpeg_init(int32_t deviceId_); + void jpeg_release(); - void dvpp_jpeg_release(); + void jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name); - void dvpp_jpeg_encode(acldvppPicDesc *encodeInputDesc_, string out_file_name); -} +private: + int32_t jpege_save(char* pcData , uint32_t dataLen, string out_file_name); + +private: + int32_t deviceId_; + aclrtContext context_; + aclrtStream stream_; + acldvppChannelDesc *dvppChannelDesc_; +}; #endif // __JPEG_UTIL_H__ \ No newline at end of file diff --git a/src/util/vpc_util.cpp b/src/util/vpc_util.cpp index bbf7c8b..a659d70 100644 --- a/src/util/vpc_util.cpp +++ b/src/util/vpc_util.cpp @@ -21,54 +21,9 @@ #define WARN_LOG(fmt, args...) fprintf(stdout, "[WARN] " fmt "\n", ##args) #define ERROR_LOG(fmt, args...) fprintf(stderr, "[ERROR] " fmt "\n", ##args) -typedef enum Result { - SUCCESS = 0, - FAILED = 1 -} Result; - -typedef struct PicDesc { - std::string picName; - int width; - int height; -}PicDesc; - -typedef struct CropPicDesc { - std::string picName; - int left; - int top; - int width; - int height; -}CropPicDesc; - -int32_t deviceId_; -aclrtContext context_; -aclrtStream stream_; - -aclvdecChannelDesc *vdecChannelDesc_; -acldvppStreamDesc *streamInputDesc_; -acldvppPicDesc *picOutputDesc_; -acldvppChannelDesc *dvppChannelDesc_; -uint32_t inBufferSize; -uint32_t inputWidth; -uint32_t inputHeight; -aclrtRunMode runMode; - -PicDesc inPicDesc; -CropPicDesc outPicDesc; - - - -uint32_t AlignmentHelper(uint32_t origSize, uint32_t alignment) -{ - if (alignment == 0) { - return 0; - } - uint32_t alignmentH = alignment - 1; - return (origSize + alignmentH) / alignment * alignment; -} -void dvpp_crop_release() +void VPCUtil::vpc_crop_release() { aclError ret; // ret = aclrtSetDevice(deviceId_); @@ -103,33 +58,12 @@ void dvpp_crop_release() } -int dvpp_crop(acldvppPicDesc *input_pic_desc) +int VPCUtil::vpc_crop(acldvppPicDesc *input_pic_desc, video_object_info obj) { - /* 1.ACL initialization */ - // aclInit(nullptr); - - /* 2.Run the management resource application, including Device, Context, Stream */ - aclrtSetDevice(deviceId_); - aclrtCreateContext(&context_, deviceId_); - aclrtCreateStream(&stream_); - aclrtGetRunMode(&runMode); - - /* 3.Initialization parameters: width and height of the original image, crop width and height. - * Initialize folder: Output folder */ - - outPicDesc={"output.jpg", 100, 100, 300, 300}; - - const int orimodelInputWidth = outPicDesc.width; // cur model shape is 224 * 224 - const int orimodelInputHeight = outPicDesc.height; - const int modelInputLeft = outPicDesc.left; // cur model shape is 224 * 224 - const int modelInputTop = outPicDesc.top; - - /* 4. Channel description information when creating image data processing channels, - * dvppChannelDesc_ is acldvppChannelDesc type */ - dvppChannelDesc_ = acldvppCreateChannelDesc(); - - /* 5. Create the image data processing channel. */ - acldvppCreateChannel(dvppChannelDesc_); + const int orimodelInputWidth = obj.right - obj.left; // cur model shape is 224 * 224 + const int orimodelInputHeight = obj.bottom - obj.top; + const int modelInputLeft = obj.left; // cur model shape is 224 * 224 + const int modelInputTop = obj.top; // GetPicDevBuffer4JpegD int modelInputWidth = (orimodelInputWidth + 15) / 16 * 16; @@ -161,8 +95,6 @@ int dvpp_crop(acldvppPicDesc *input_pic_desc) ret = aclrtSynchronizeStream(stream_); - DVPP_UTIL::dvpp_jpeg_encode(vpcOutputDesc_, "output.jpg"); - /* DestroycropResource */ (void)acldvppDestroyRoiConfig(cropArea_); cropArea_ = nullptr; @@ -174,10 +106,10 @@ int dvpp_crop(acldvppPicDesc *input_pic_desc) vpcOutBufferDev_ = nullptr; } - return SUCCESS; + return 0; } -int dvpp_crop_init(int32_t devId){ +int VPCUtil::vpc_crop_init(int32_t devId){ deviceId_ = devId; aclError ret; @@ -185,7 +117,6 @@ int dvpp_crop_init(int32_t devId){ aclrtSetDevice(deviceId_); aclrtCreateContext(&context_, deviceId_); aclrtCreateStream(&stream_); - aclrtGetRunMode(&runMode); // channel 准备 dvppChannelDesc_ = acldvppCreateChannelDesc(); @@ -193,7 +124,7 @@ int dvpp_crop_init(int32_t devId){ } -void check_coordinate(uint32_t& cropLeftOffset, uint32_t& cropRightOffset, uint32_t& cropTopOffset, uint32_t& cropBottomOffset, uint32_t width, uint32_t height){ +static void check_coordinate(uint32_t& cropLeftOffset, uint32_t& cropRightOffset, uint32_t& cropTopOffset, uint32_t& cropBottomOffset, uint32_t width, uint32_t height){ if (cropLeftOffset < 0){ cropLeftOffset = 0; } @@ -209,7 +140,7 @@ void check_coordinate(uint32_t& cropLeftOffset, uint32_t& cropRightOffset, uint3 } -vector dvpp_crop_batch(DeviceMemory *devMem, vector objs){ +vector VPCUtil::vpc_crop_batch(DeviceMemory *devMem, vector objs){ vector vec_img_info; @@ -324,7 +255,7 @@ vector dvpp_crop_batch(DeviceMemory *devMem, vector dvpp_crop_batch(DeviceMemory *devMem, vectorgetSize(); @@ -398,7 +329,7 @@ vpc_img_info dvpp_devMem2vpcImg(DeviceMemory *devMem){ return img_info; } -void dvpp_img_release(vpc_img_info img_info){ +void VPCUtil::vpc_img_release(vpc_img_info img_info){ if(img_info.pic_desc != nullptr){ void *outputDataDev = acldvppGetPicDescData(img_info.pic_desc); acldvppFree(outputDataDev); @@ -406,9 +337,9 @@ void dvpp_img_release(vpc_img_info img_info){ } } -void dvpp_imgList_release(vector& imgList){ +void VPCUtil::vpc_imgList_release(vector& imgList){ for(int i=0; i < imgList.size(); i++){ - dvpp_img_release(imgList[i]); + vpc_img_release(imgList[i]); } imgList.clear(); } \ No newline at end of file diff --git a/src/util/vpc_util.h b/src/util/vpc_util.h index 7019425..f0199d0 100644 --- a/src/util/vpc_util.h +++ b/src/util/vpc_util.h @@ -22,17 +22,31 @@ struct vpc_img_info{ class DeviceMemory; -int dvpp_crop(acldvppPicDesc *input_pic_desc); +class VPCUtil { -int dvpp_crop_init(int32_t devId); +public: + int vpc_crop(acldvppPicDesc *input_pic_desc, video_object_info obj); -vector dvpp_crop_batch(DeviceMemory *devMem, vector objs); + int vpc_crop_init(int32_t devId); -void dvpp_img_release(vpc_img_info ); -void dvpp_imgList_release(vector& ); + vector vpc_crop_batch(DeviceMemory *devMem, vector objs); + + void vpc_img_release(vpc_img_info ); + + void vpc_imgList_release(vector& ); + + void vpc_crop_release(); + + vpc_img_info vpc_devMem2vpcImg(DeviceMemory *devMem); + +private: + int32_t deviceId_; + aclrtContext context_; + aclrtStream stream_; + + acldvppChannelDesc *dvppChannelDesc_; +}; -void dvpp_crop_release(); -vpc_img_info dvpp_devMem2vpcImg(DeviceMemory *devMem); #endif //___VPC_UTIL_H__ \ No newline at end of file