// Get the default parameter for video encodingint32_t hbVPGetDefaultVideoEncParam(hbVPVideoEncParam *param);// Create the video encoding contextint32_t hbVPCreateVideoEncContext(hbVPVideoContext *context, hbVPVideoEncParam const *param);// Release the video encoding contextint32_t hbVPReleaseVideoEncContext(hbVPVideoContext context);// Create video encoding taskint32_t hbVPVideoEncode(hbUCPTaskHandle_t *taskHandle, hbVPImage const *srcImg, hbVPVideoContext context);// Get the output buffer where the encoding data is storedint32_t hbVPGetVideoEncOutputBuffer(hbVPArray *outBuf, hbUCPTaskHandle_t taskHandle);
// Get the default parameter for video decodingint32_t hbVPGetDefaultVideoDecParam(hbVPVideoDecParam *param);// Create the video decoding contextint32_t hbVPCreateVideoDecContext(hbVPVideoContext *context, hbVPVideoDecParam const *param);// Release the video decoding contextint32_t hbVPReleaseVideoDecContext(hbVPVideoContext context);// Create video decoding tasksint32_t hbVPVideoDecode(hbUCPTaskHandle_t *taskHandle, hbVPArray const *srcBuf, hbVPVideoContext const context);// Get the output buffer where the decoding data is storedint32_t hbVPGetVideoDecOutputBuffer(hbVPImage *outImg, hbUCPTaskHandle_t taskHandle);
// Include the header#include "hobot/hb_ucp.h"#include "hobot/vp/hb_vp.h"#include "hobot/vp/hb_vp_video_codec.h"// init encoding paramhbVPVideoEncParam venc_param;venc_param.videoType = HB_VP_VIDEO_TYPE_H265;// default set backend to HB_UCP_VPU_CORE_0hbVPGetDefaultVideoEncParam(&venc_param);venc_param.height = height;venc_param.width = width;venc_param.pixelFormat = image_format;// create video encoding context and the Video Processing Unit internally alloc the output bufferhbVPVideoContext enc_context{nullptr};hbVPCreateVideoEncContext(&enc_context, &venc_param)// init schedule paramhbUCPSchedParam sched_param;HB_UCP_INITIALIZE_SCHED_PARAM(&sched_param);sched_param.backend = HB_UCP_VPU_CORE_0;// init image_buf, alloc memory for image datahbUCPSysMem image_mem;hbUCPMalloc(&image_mem, yuv_size, 0);{ hbVPImage image_buf; image_buf.imageFormat = image_format; image_buf.imageType = image_type; image_buf.width = width; image_buf.height = height; image_buf.dataVirAddr = image_mem.virAddr; image_buf.dataPhyAddr = image_mem.phyAddr; image_buf.uvVirAddr = reinterpret_cast<char *>(image_mem.virAddr) + y_size; image_buf.uvPhyAddr = image_mem.phyAddr + y_size; // init task handle hbUCPTaskHandle_t task_handle{nullptr}; // create video encoding task hbVPVideoEncode(&task_handle, &image_buf, enc_context); // submit video encoding task hbUCPSubmitTask(task_handle, &sched_param); // wait for video encoding task done hbUCPWaitTaskDone(task_handle, 10); // get output buffer from Video Processing Unit hbVPArray out_buf; hbVPGetVideoEncOutputBuffer(&out_buf, task_handle); // process h264 or h265 data // release task handle and dequeue output buffer from Video Processing Unit // since the dequeue output buffer process relies on the context, // you must call the hbUCPReleaseTask interface before calling the hbVPReleaseJPEGEncContext interface hbUCPReleaseTask(task_handle);}// release memoryhbUCPFree(&image_mem);// release encoding context and the Video Processing Unit internally release the output bufferhbVPReleaseVideoEncContext(enc_context);
// Include the header#include "hobot/hb_ucp.h"#include "hobot/vp/hb_vp.h"#include "hobot/vp/hb_vp_video_codec.h"// init decoding paramhbVPVideoDecParam vdec_param;vdec_param.videoType = HB_VP_VIDEO_TYPE_H265;// default set backend to HB_UCP_VPU_CORE_0hbVPGetDefaultVideoDecParam(&vdec_param);vdec_param.pixelFormat = HB_VP_IMAGE_FORMAT_YUV420;vdec_param.inBufSize = ALIGN_1024(height * width * 3 / 2);// create video decoding context and the Video Processing Unit internally alloc the output bufferhbVPVideoContext dec_context{nullptr};hbVPCreateVideoDecContext(&dec_context, &vdec_param)// init schedule paramhbUCPSchedParam sched_param;HB_UCP_INITIALIZE_SCHED_PARAM(&sched_param);sched_param.backend = HB_UCP_VPU_CORE_0;// alloc larger memory for inputhbUCPSysMem src_mem;ret = hbUCPMalloc(&(src_mem), vdec_param.inBufSize, 0);{ // init src_buf, alloc memory for image data memset(src_mem.virAddr, src_mem.memSize, 1); fread(src_mem.virAddr, 1, feedSize, inFile); hbVPArray src_buf; src_buf.phyAddr = src_mem.phyAddr; src_buf.virAddr = src_mem.virAddr; src_buf.memSize = feedSize; src_buf.size = feedSize; // init task handle hbUCPTaskHandle_t task_handle{nullptr}; // create video decoding task hbVPVideoDecode(&task_handle, &src_buf, dec_context); // submit video decoding task hbUCPSubmitTask(task_handle, &sched_param); // wait for video decoding task done hbUCPWaitTaskDone(task_handle, 10); // get output buffer from Video Processing Unit hbVPImage out_img; hbVPGetVideoDecOutputBuffer(&out_img, task_handle); // process yuv data // release task handle and dequeue output buffer from Video Processing Unit // since the dequeue output buffer process relies on the context, // you must call the hbUCPReleaseTask interface before calling the hbVPReleaseJPEGDecContext interface hbUCPReleaseTask(task_handle);}// release memoryhbUCPFree(&src_mem);// release encoding context and the Video Processing Unit internally release the output bufferhbVPReleaseVideoDecContext(dec_context);