Updated on 2022-03-13 GMT+08:00

VPC Functions and Parameters

You are not advised to use the VPC function of the earlier version, which will be removed in later versions. The VPC and CMDLIST functions in the earlier version have been combined into the VPC function. For details, see VPC Parameters.

The VPC APIs of the earlier version are used for media image conversion including scaling, color space conversion (CSC), bit depth reduction, format conversion, block partitioning, overlay, collage, and CMDLIST calling.

  • There is no limit on the number of VPC channels.

    The cropping and resizing operations affect the VPC performance. If the image resolution is changed during image processing, the performance is affected. The following table shows the reference performance specifications in typical scenarios when the image resolution during image processing does not exceed the original resolution.

    Scenario

    Total Frame Rate

    1080p x 32 channels

    1440 fps

    4K x 4 channels

    360 fps

    When image resolution during image processing is greater than the original resolution, use the following formula to calculate the frame rate:

    Total frame rate = (3840 x 2160 x 360)/(W x H) fps

    Where, W and H are the maximum width and height during the VPC processing. For example, if a 1080p image is cropped to 960 x 540 and then resized to 3840 x 2160, W is 3840 and H is 2160.

    During the processing, the VPC performance slightly decreases when the image scaling-down ratio is increased.

  • Restrictions on the width and height of the input and output images of the VPC:
    • The width and height of the input image must be 2-pixel aligned, that is, the width and height must be an even number.
    • The width and height of the output image must be 2-pixel aligned, that is, the width and height must be an even number.

      The image width and height mentioned here refer to the valid area of an image. The actual buffer sent to the VPC must be 128 x 16 aligned.

  • Restrictions on the buffers of the VPC input and output images:
    • Restrictions on the VPC input buffer:
      • Input data address (OS virtual address): 128-byte aligned
      • Input image buffer width restriction: 128-byte aligned
      • Input image buffer height restriction: 16-byte aligned

      A YUV400SP image requires a buffer size that matches the YUV420SP format, that is, the required buffer size is (width_align_128 x high_align_16 x 1.5).

    • Restrictions on the VPC output buffer:
      • Output data address (OS virtual address): 128-byte aligned
      • Output image buffer width restriction: 128-byte aligned
      • Output image buffer height restriction: 16-byte aligned
    • In the same task, the virtual addresses of the input and output buffers must be in the same 4 GB space.

      When the VPC is used to implement image cropping and scaling, DvppCtl needs to be called twice. In the first calling, the input parameter is resize_param_in_msg, and the output parameter is resize_param_out_msg. In the second calling, the input parameter is vpc_in_msg. For details, see Input Parameter: resize_param_in_msg to Input Parameter: vpc_in_msg.

Input Parameter: resize_param_in_msg

Member Variable

Description

Value Range

int src_width

Width of the original image (2-pixel aligned)

NOTICE:

The original image mentioned here refer to the valid area of an image. The actual buffer sent to the VPC must be 128 x 16 aligned.

Minimum resolution:

  • 128 (from VDEC)
  • 16 (not from VDEC)

Maximum resolution:

4096

This parameter is mandatory.

int src_high

Height of the original image (2-pixel aligned)

NOTICE:

The original image mentioned here refer to the valid area of an image. The actual buffer sent to the VPC must be 128 x 16 aligned.

Minimum resolution:

  • 128 (from VDEC)
  • 16 (not from VDEC)

Maximum resolution:

4096

This parameter is mandatory.

int hmax

Maximum horizontal offset from the origin

The value is an odd number. For details, see Input Parameter: vpc_in_msg.

int hmin

Minimum horizontal offset from the origin

The value is an even number. For details, see Input Parameter: vpc_in_msg.

int vmax

Maximum vertical offset from the origin

The value is an odd number. For details, see Input Parameter: vpc_in_msg.

int vmin

Minimum vertical offset from the origin

The value is an even number. For details, see Input Parameter: vpc_in_msg.

int dest_width

Width of the output image

The value is an even number

int dest_high

Height of the output image

The value is an even number

Output Parameter: resize_param_out_msg

Member Variable

Description

Value Range

int dest_width_stride

Width alignment value of the output image

128

int dest_high_stride

Height alignment value of the output image

16

int hmax

Maximum horizontal offset from the origin

The value is an odd number. For details, see Input Parameter: vpc_in_msg.

int hmin

Minimum horizontal offset from the origin

The value is an even number. For details, see Input Parameter: vpc_in_msg.

int vmax

Maximum vertical offset from the origin

The value is an odd number. For details, see Input Parameter: vpc_in_msg.

int vmin

Minimum vertical offset from the origin

The value is an even number. For details, see Input Parameter: vpc_in_msg.

double hinc

Horizontal resizing coefficient

For details, see Input Parameter: vpc_in_msg.

double vinc

Vertical resizing coefficient

For details, see Input Parameter: vpc_in_msg.

Input Parameter: vpc_in_msg

Member Variable

Description

Value Range

int format

Image format defined by the caller. Use a correct number. For example, the number corresponding to yuv420_semi_plannar is 0. If YUV420SP is declared, set this parameter to 0.

yuv420_semi_plannar = 0,//0

yuv400_semi_plannar = 0,//0

yuv422_semi_plannar,//1

yuv444_semi_plannar,//2

yuv422_packed,//3

yuv444_packed,//4

rgb888_packed,//5

xrgb8888_packed,//6

This parameter is mandatory.

int rank

Image rank mode defined by the caller. Use a correct number.

For details, see Table 1.

This parameter is mandatory.

int bitwidth

Bit depth. The default value is 8 bits. The 10-bit depth is used only when the image format is YUV/YVU420 Semi-Planar and HFBC compression is used.

8 or 10

This parameter is optional.

int cvdr_or_rdma

Whether the input image is transmitted through the CVDR or RDMA channel. The CVDR channel is used by default. The input of the RDMA channel can only be HFBC data output by the VDEC.

1: CVDR. 0: RDMA.

This parameter is optional.

int width

Width of the original input image, which is 2-pixel aligned (even number)

NOTICE:

The original image mentioned here refer to the valid area of an image. The actual buffer sent to the VPC must be 128 x 16 aligned.

Minimum resolution:

  • 128 (from VDEC)
  • 16 (not from VDEC)

Maximum resolution:

4096

This parameter is mandatory.

int high

Height of the original input image, which is 2-pixel aligned (even number)

NOTICE:

The original image mentioned here refer to the valid area of an image. The actual buffer sent to the VPC must be 128 x 16 aligned.

Minimum resolution:

  • 128 (from VDEC)
  • 16 (not from VDEC)

Maximum resolution:

4096

This parameter is mandatory.

int stride

Image stride

NOTICE:

The stride is different for different input formats.

YUV400SP, YUV420SP, YUV422SP, and YUV444SP: Align the width to a 128-pixel boundary.

YUV422 Packed: Align (width x 2) to a 128-pixel boundary.

YUV444 Packed and RGB888: Align (width x 3) to a 128-pixel boundary.

XRGB8888: Align (width x 4) to a 128-pixel boundary.

This parameter is mandatory.

double hinc

Horizontal magnification for the AI core output channel

[0.03125, 1) or (1, 4]

If a resizing coefficient exceeds the value range, the VPC reports an error. If resizing is not required, set the value to 1.

This parameter is mandatory.

double vinc

Vertical magnification for the AI core output channel

[0.03125, 1) or (1, 4]

If a resizing coefficient exceeds the value range, the VPC reports an error. If resizing is not required, set the value to 1.

This parameter is mandatory.

double jpeg_hinc

Horizontal magnification for the JPEGE output channel

[0.03125, 1) or (1, 4]

If a resizing coefficient exceeds the value range, the VPC reports an error.

This parameter is optional and is not applicable currently.

double jpeg_vinc

Vertical magnification for the JPEGE output channel

[0.03125, 1) or (1, 4]

If a resizing coefficient exceeds the value range, the VPC reports an error.

This parameter is optional and is not applicable currently.

int hmax

Maximum horizontal offset from the origin

The value must be an odd number. If cropping is not required, set the value to (Input image width – 1).

This parameter is mandatory.

int hmin

Minimum horizontal offset from the origin

The value must be an even number.

If cropping is not required, set the value to 0.

This parameter is mandatory.

int vmax

Maximum vertical offset from the origin

The value must be an odd number.

If cropping is not required, set the value to (Input image width – 1).

This parameter is mandatory.

int vmin

Minimum vertical offset from the origin

The value must be an even number.

If cropping is not required, set the value to 0.

int out_width

Width of the output image

The value must be an even number (2-pixel aligned).

When a smart pointer is used to allocate the output buffer, this parameter is not required. When a buffer allocated by the user is used as the output buffer, this parameter is mandatory.

int out_high

Height of the output image

The value must be an even number (2-pixel aligned).

When a smart pointer is used to allocate the output buffer, this parameter is not required. When a buffer allocated by the user is used as the output buffer, this parameter is mandatory.

int h_stride

Image height stride, which is the same as that described in int stride. You do not need to set this parameter.

The default value is 16. That is, the default input image height is 16-pixel aligned.

This parameter is optional.

char* in_buffer

Input buffer

Ensure that the input buffer size is the same as the length and width configured in in_msg. If the input image is in YUV420 Semi-Planar NV12 format, the image size is (Width x Height x 1.5). If the input buffer size is inconsistent with this calculation result, the VPC fails to be called.

This parameter is mandatory.

int in_buffer_size

Size of the input buffer

This value is used to verify the input buffer.

This parameter is mandatory.

shared_ptr<AutoBuffer> auto_out_buffer_1

Output buffer 1

This buffer needs to be configured when the basic VPC functions (cropping and resizing) are used. This buffer is used for the smart pointer allocated by the caller and is used as an input parameter of the DVPP. The output buffer is allocated inside the DVPP. You can read this buffer to obtain the output image.

You only need to set either this parameter or the subsequent parameter out_buffer.

char* out_buffer

Output buffer

This buffer needs to be configured when the basic VPC functions (cropping and resizing) are used. This buffer is allocated by the caller. The start address of the buffer must be 128-byte aligned, and the allocated memory must be in the 4 GB space. You can read this buffer to obtain the output image.

You only need to set either this parameter or the previous parameter auto_out_buffer_1.

int out_buffer_1_size

Size of output buffer 1

This value is used to verify the output buffer.

If shared_ptr<AutoBuffer> auto_out_buffer_1 is used to allocate the output buffer, this parameter is optional. If char* out_buffer is used to allocate the output buffer, this parameter is mandatory.

shared_ptr<AutoBuffer> auto_out_buffer_2

Output of the other VPC channel (reserved interface)

--

int out_buffer_2_size

Size of output buffer 2 of the auto_out_buffer2 smart pointer. This is a reserved interface.

--

int use_flag

Flag indicating whether the VPC function is used

  • 0: basic functions of the VPC
  • 1: raw data 8K resizing
  • 2: raw data overlay (reserved)
  • 3: raw data stitching (reserved)

The default value is 0.

This parameter is optional.

VpcOverLayReverse overlay

Overlay structure, which is reserved

Reserved

VpcCollageReverse collage

Collage structure, which is reserved

Reserved

RDMACHANNEL rdma

Configuration structure dedicated to the HFBC data

For details, see RDMACHANNEL Structure.

VpcTurningReverse turningReverse1

Reserved interface for VPC tuning

For details, see VpcTurningReverse Structure.

bool isVpcUseTurning1

Flag indicating whether VPC tuning is used. This is a reserved interface and is used together with turningReverse1.

--

VpcTurningReverse turningReverse2

Reserved interface for VPC tuning

For details, see VpcTurningReverse Structure.

bool isVpcUseTurning2

Flag indicating whether VPC tuning is used. This is a reserved interface and is used together with turningReverse2.

--

string *yuvscaler_paraset

Pointer to the file path and file name array of the VPC filtering parameter set.

NOTE:
  • The parameter set must be on the device.
  • Ensure that the input file path is correct.

A parameter set file path consists of an absolute file path on the device and the file name, for example, {"/home/HwHiAiUser/matrix/YUVScaler_pra.h"}.

unsigned int yuvscaler_paraset_size

Number of elements in the string array to which yuvscaler_paraset points. The default value is 1.

yuvscaler_paraset_size<=10

unsigned int index

Index of the yuvscaler_paraset array

0<=index<10

Table 1 Rank configuration table of the input and output image formats

Input Image Format

Rank Parameter Configuration of the VPC

Output Image Format

YUV420sp NV12

NV12 = 0

YUV420sp NV21

YUV420sp NV21

NV21 = 1

YUV420sp NV21

YUV420sp NV12

NV12 = 1

YUV420sp NV12

YUV420sp NV21

NV21 = 0

YUV420sp NV12

YUV422sp NV16

NV16 = 1

YUV420sp NV12

YUV422sp NV61

NV61 = 0

YUV420sp NV12

YUV422sp NV16

NV16 = 0

YUV420sp NV21

YUV422sp NV61

NV61 = 1

YUV420sp NV21

YUV444sp 444spUV

444spUV = 1

YUV420sp NV12

YUV444sp 444spVU

444spVU= 0

YUV420sp NV12

YUV444sp 444spUV

444spUV = 0

YUV420sp NV21

YUV444sp 444spVU

444spVU= 1

YUV420sp NV21

YUV422packet YUYV

YUYV = 2

YUV420sp NV12

YUV422packet YVYU

YVYU = 3

YUV420sp NV21

YUV422packet UYVY

UYVY = 4

YUV420sp NV12

YUV444packet YUV

YUV = 5

YUV420sp NV12

RGB888 RGB

RGB = 6

YUV420sp NV12

RGB888 BGR

BGR = 7

YUV420sp NV21

RGB888 RGB

BGR = 7

YUV420sp NV21

RGB888 BGR

RGB = 6

YUV420sp NV12

XRGB8888 RGBA

RGBA = 8

YUV420sp NV12

XRGB8888 RGBA

BGRA = 9

YUV420sp NV21

Calling Example

  • Example of calling basic VPC functions:

    gXxxxx is a configuration parameter. Configuring the parameter and calling the VPC are two steps.

    Step 1: Use the DVPP_CTL_TOOL_CASE_GET_RESIZE_PARAM command word to call DvppCtl to obtain the configuration parameters. The input parameter of DvppCtl is resize_param_in_msg, and the output parameter is resize_param_out_msg. Use resize_param_in_msg to send the width and height of the original image, cropped area (hmax,hmin,vmax,vmin), and output width and height to the DVPP. The DVPP returns the regenerated cropped area (hmax,hmin,vmax,vmin) and resizing ratio (hinc,vinc) to the caller after calculation.

    Step 2: The caller transfers the parameters returned in step 1 to the DVPP by using vpc_in_msg, changes the DvppCtl command word to DVPP_CTL_VPC_PROC to obtain the processing result.

        dvppapi_ctl_msg dvppApiCtlMsg;
        vpc_in_msg vpcInMsg;
        resize_param_in_msg resize_in_param;
        resize_param_out_msg resize_out_param;
        resize_in_param.src_width = gWidth;
        resize_in_param.src_high = gHigh;
        resize_in_param.hmax = gHmax;
        resize_in_param.hmin = gHmin;
        resize_in_param.vmax = gVmax;
        resize_in_param.vmin = gVmin;
        resize_in_param.dest_width = floor(gHinc * (gHmax - gHmin + 1) + 0.5);
        resize_in_param.dest_high = floor(gVinc * (gVmax - gVmin + 1) + 0.5);
        printf("width  =%d\n", gWidth);
        printf("high   =%d\n", gHigh);
        printf("hmax   =%d\n", gHmax);
        printf("hmin   =%d\n", gHmin);
        printf("vmax   =%d\n", gVmax);
        printf("vmin   =%d\n", gVmin);
        printf("out width   =%d\n", resize_in_param.dest_width);
        printf("out hight   =%d\n", resize_in_param.dest_high );
    
        dvppApiCtlMsg.in = (void *)(&resize_in_param);
        dvppApiCtlMsg.out = (void *)(&resize_out_param);
        IDVPPAPI *pidvppapi = NULL;
        CreateDvppApi(pidvppapi);
        if (DvppCtl(pidvppapi, DVPP_CTL_TOOL_CASE_GET_RESIZE_PARAM, &dvppApiCtlMsg) != 0) {
            printf("call DVPP_CTL_TOOL_CASE_GET_RESIZE_PARAM process faild!\n");
            DestroyDvppApi(pidvppapi);
            return;
        }
    
        int bufferSize        = 0;
        vpcInMsg.format       = gFormat;
        vpcInMsg.cvdr_or_rdma = gcvdr_or_rdma;
        vpcInMsg.bitwidth = gBitwidth;
        vpcInMsg.rank = gRank;
        vpcInMsg.width = gWidth;
        vpcInMsg.high = gHigh;
        vpcInMsg.stride = gStride;
        vpcInMsg.hmax = resize_out_param.hmax;
        vpcInMsg.hmin = resize_out_param.hmin;
        vpcInMsg.vmax = resize_out_param.vmax;
        vpcInMsg.vmin = resize_out_param.vmin;
        vpcInMsg.vinc = resize_out_param.vinc;
        vpcInMsg.hinc = resize_out_param.hinc;
        printf("resize_out_param.hinc = %lf\n", resize_out_param.hinc);
        printf("resize_out_param.vinc = %lf\n", resize_out_param.vinc);
        printf("resize_out_param.hmax = %d\n", resize_out_param.hmax);
        printf("resize_out_param.hmin = %d\n", resize_out_param.hmin);
        printf("resize_out_param.vmax = %d\n", resize_out_param.vmax);
        printf("resize_out_param.vmin = %d\n", resize_out_param.vmin);
    
        printf("format =%d\n", vpcInMsg.format);
        printf("rank   =%d\n", vpcInMsg.rank);
        printf("width  =%d\n", vpcInMsg.width);
        printf("high   =%d\n", vpcInMsg.high);
        printf("stride =%d\n", vpcInMsg.stride);
        printf("hmax   =%d\n", vpcInMsg.hmax);
        printf("hmin   =%d\n", vpcInMsg.hmin);
        printf("vmax   =%d\n", vpcInMsg.vmax);
        printf("vmin   =%d\n", vpcInMsg.vmin);
        printf("vinc   =%F\n", vpcInMsg.vinc);
        printf("hinc   =%F\n", vpcInMsg.hinc);
        if (vpcInMsg.cvdr_or_rdma == 0) {
            printf("rdma channel\n");
            int buffersize ;
            char * payloadY ;
            char * payloadC ;
            char * headY ;
            char * headC ;
            FILE * rdmaimage = fopen(in_file_name, "rb");
    
            if (vpcInMsg.bitwidth == 10) {
                buffersize                        = vpcInMsg.width  * vpcInMsg.high * 2 + 512 * 1024;
                payloadY                          = (char*)memalign(128, buffersize);
                headY                             = payloadY + vpcInMsg.width  * vpcInMsg.high * 2;
                headC                             = headY + 256 * 1024;
                vpcInMsg.rdma.luma_payload_addr   = (long)payloadY;
                vpcInMsg.rdma.chroma_payload_addr = (long)payloadY + 640;
            } else {
                buffersize                        = vpcInMsg.width * vpcInMsg.high * 1.5 + 512 * 1024;
                payloadY                          = (char*)memalign(128, buffersize);
                payloadC                          = payloadY + vpcInMsg.width * vpcInMsg.high;
                headY                             = payloadC + vpcInMsg.width * vpcInMsg.high / 2;
                headC                             = headY + 256 * 1024;
                vpcInMsg.rdma.luma_payload_addr   = (long)payloadY;
                vpcInMsg.rdma.chroma_payload_addr = (long)payloadC;
            }
    
            fread(payloadY, 1, buffersize, rdmaimage);
            vpcInMsg.rdma.luma_head_addr        = (long)headY;
            vpcInMsg.rdma.chroma_head_addr      = (long)headC;
            vpcInMsg.rdma.luma_head_stride      = vpcInMsg.stride;
            vpcInMsg.rdma.chroma_head_stride    = vpcInMsg.stride;
            vpcInMsg.rdma.luma_payload_stride   = gpYStride;
            vpcInMsg.rdma.chroma_payload_stride = gpUVStride;
            fclose(rdmaimage);
            printf("luma payload stride= %d\n", vpcInMsg.rdma.luma_payload_stride );
            printf("chroma payload stride= %d\n", vpcInMsg.rdma.chroma_payload_stride );
        } else {
            alloc_buffer(vpcInMsg.width, vpcInMsg.high, vpcInMsg.stride, bufferSize);
            if (open_image(in_file_name, vpcInMsg.width, vpcInMsg.high, vpcInMsg.stride) != 0) {
                printf("open file failed~\n");
                free(in_buffer);
                return;
            }
            vpcInMsg.in_buffer      = in_buffer;
            vpcInMsg.in_buffer_size = bufferSize;
        }
        //alloc in and out buffer
        shared_ptr<AutoBuffer> auto_out_buffer = make_shared<AutoBuffer>();
        vpcInMsg.auto_out_buffer_1             = auto_out_buffer;
        dvppApiCtlMsg.in                       = (void *)(&vpcInMsg);
        dvppApiCtlMsg.in_size                  = sizeof(vpc_in_msg);
    
        if (pidvppapi != NULL) {
    
            for (int i = 0; i < gLoop; i++) {
                if (DvppCtl(pidvppapi, DVPP_CTL_VPC_PROC, &dvppApiCtlMsg) != 0) {
                    printf("call dvppctl process faild!\n");
                    DestroyDvppApi(pidvppapi);
                    free(in_buffer);
                    return;
                }
            }
    
        } else {
            printf("pidvppapi is null!\n");
        }
    
        free(in_buffer);
    
        FILE *fp = NULL;
        fp = fopen(out_file_name, "wb+");
        if (fp == NULL) {
            printf("open file %s failed~\n", out_file_name);
            free(in_buffer);
            return;
        }
    
        fwrite(vpcInMsg.auto_out_buffer_1->getBuffer(), 1, vpcInMsg.auto_out_buffer_1->getBufferSize(), fp);
        fflush(fp);
        fclose(fp);
        DestroyDvppApi(pidvppapi);
        return;
  • Example of calling basic raw data 8K functions:

    Parameter settings:

        dvppapi_ctl_msg dvppApiCtlMsg;
        vpc_in_msg vpcInMsg;
        vpcInMsg.width = gWidth;
        vpcInMsg.high = gHigh;
        vpcInMsg.stride = gStride;
        vpcInMsg.out_width = gOutWidth;
        vpcInMsg.out_high = gOutHigh;
        printf("width     =%d\n", vpcInMsg.width);
        printf("high      =%d\n", vpcInMsg.high);
        printf("stride    =%d\n", vpcInMsg.stride);
        printf("out_width =%d\n", vpcInMsg.out_width);
        printf("out_high  =%d\n", vpcInMsg.out_high);
        //alloc in and out buffer
        char *in_buffer = (char *)malloc(vpcInMsg.width * vpcInMsg.high * 1.5);
        if (in_buffer = NULL) {
            printf("malloc fail\n");
            return;
        }
    
        shared_ptr<AutoBuffer> auto_out_buffer = make_shared<AutoBuffer>();
        FILE *yuvimage = fopen(in_file_name, "rb");
        if (yuvimage == NULL) {
            printf("no such file!,file_name=[%s]\n", in_file_name);
            free(in_buffer);
            return;
        } else {
            fread(in_buffer, 1, vpcInMsg.width * vpcInMsg.high * 3 / 2, yuvimage);
        }
    
        vpcInMsg.rank = gRank;
        vpcInMsg.in_buffer = in_buffer;
        vpcInMsg.in_buffer_size = vpcInMsg.width * vpcInMsg.high * 1.5;
        vpcInMsg.auto_out_buffer_1 = auto_out_buffer;
        vpcInMsg.use_flag = 1;
        dvppApiCtlMsg.in = (void *)(&vpcInMsg);
        dvppApiCtlMsg.in_size = sizeof(vpc_in_msg);
        IDVPPAPI *pidvppapi = NULL;
        CreateDvppApi(pidvppapi);
        if (pidvppapi != NULL) {
            if (DvppCtl(pidvppapi, DVPP_CTL_VPC_PROC, &dvppApiCtlMsg) != 0) {
                printf("call dvppctl process faild!\n");
                DestroyDvppApi(pidvppapi);
                free(in_buffer);
                fclose(yuvimage);
                return;
            }
        } else {
            printf("pidvppapi is null!\n");
        }
    
        DestroyDvppApi(pidvppapi);
        FILE *fp = NULL;
        fp = fopen(out_file_name, "wb+");
        if (fp != NULL) {
            fwrite(vpcInMsg.auto_out_buffer_1->getBuffer(), 1, vpcInMsg.auto_out_buffer_1->getBufferSize(), fp);
            fflush(fp);
            fclose(fp);
        } else {
            fclose(yuvimage);
            return;
        }
    
        free(in_buffer);
        fclose(yuvimage);
        return;
  • Example of calling basic raw data overlay functions:
        dvppapi_ctl_msg dvppApiCtlMsg;
        vpc_in_msg vpcInMsg;
        // Configures raw data overlay parameters.
        vpcInMsg.use_flag = 2;
        vpcInMsg.overlay.image_type = 0;
        vpcInMsg.overlay.image_rank_type = 0;
        vpcInMsg.overlay.bit_width = 8;
        vpcInMsg.overlay.in_width_image = 1000;
        vpcInMsg.overlay.in_high_image = 1000;
        vpcInMsg.overlay.in_width_text = 500;
        vpcInMsg.overlay.in_high_text = 390;
        vpcInMsg.overlay.image_width_stride = 2;
        vpcInMsg.overlay.image_high_stride = 2;
        vpcInMsg.overlay.text_width_stride = 2;
        vpcInMsg.overlay.text_high_stride = 2;
        vpcInMsg.overlay.in_buffer_image = NULL;
        vpcInMsg.overlay.in_buffer_text = NULL;
        vpcInMsg.overlay.auto_overlay_out_buffer = make_shared<AutoBuffer>();
        // Initializes the image buffer.
        if(NULL == (vpcInMsg.overlay.in_buffer_image = (char*)malloc(vpcInMsg.overlay.in_width_image*vpcInMsg.overlay.in_high_image*3/2)))    {
            printf("in_buffer_image alloc failed!\n");
            return ;
        }
        // Opens the image and sends the data to the allocated buffer.
        char image_file[50] = "yuv_data_0";
        FILE * yuvimage = fopen(image_file,"rb");
        if(NULL == yuvimage)    {
            printf("VPC_TEST: yuv image open faild!");
            return ;
        }    else    {
            fread(vpcInMsg.overlay.in_buffer_image, 1,vpcInMsg.overlay.in_width_image*vpcInMsg.overlay.in_high_image*3/2,yuvimage);
            fclose(yuvimage);
            yuvimage = NULL;
    }
    
        // Initializes the text buffer.
        if(NULL == (vpcInMsg.overlay.in_buffer_text = (char*)malloc(vpcInMsg.overlay.in_width_text*vpcInMsg.overlay.in_high_text*3/2)))    {
            printf("in_buffer_text alloc failed!");
            free(vpcInMsg.overlay.in_buffer_image);
            return ;
        }
    
        // Opens the text-based image and sends the data to the allocated memory.
        char text_file[50] = "text_0";
        FILE * yuvtext = fopen(text_file,"rb");
        if(NULL == yuvtext)    {
            printf("VPC_TEST: yuv text image open faild!");
            free(vpcInMsg.overlay.in_buffer_image);
            return ;
        }    else    {
            fread(vpcInMsg.overlay.in_buffer_text, 1,vpcInMsg.overlay.in_width_text*vpcInMsg.overlay.in_high_text*3/2, yuvtext);
            fclose(yuvtext);
            yuvtext = NULL;
        }
    
        dvppApiCtlMsg.in = (void*)(&vpcInMsg);
        dvppApiCtlMsg.in_size = sizeof(vpc_in_msg);
        IDVPPAPI *pidvppapi = NULL;
        CreateDvppApi(pidvppapi);
        if(pidvppapi!=NULL)    {
            if(DvppCtl(pidvppapi,DVPP_CTL_VPC_PROC,&dvppApiCtlMsg)!= 0)        {
                printf("call dvppctl process faild!\n");
                DestroyDvppApi(pidvppapi);
                free(vpcInMsg.overlay.in_buffer_image);
                free(vpcInMsg.overlay.in_buffer_text);
                return ;
            }
            DestroyDvppApi(pidvppapi);
            FILE * fp   = fopen("./out_overlay_image_share","wb+");
            fwrite(vpcInMsg.overlay.auto_overlay_out_buffer->getBuffer(),1,vpcInMsg.overlay.in_width_image*vpcInMsg.overlay.in_high_image*3/2,fp);
            fflush(fp);
            fclose(fp);
            fp=NULL;
            return ;
        }    else    {
            printf("pidvppapi is null!\n");
            return ;
        }
        if(NULL != vpcInMsg.overlay.in_buffer_image)    {
            free(vpcInMsg.overlay.in_buffer_image);
            vpcInMsg.overlay.in_buffer_image = NULL;
        }
        if(NULL != vpcInMsg.overlay.in_buffer_text)    {
            free(vpcInMsg.overlay.in_buffer_text);
            vpcInMsg.overlay.in_buffer_text = NULL;
        }
  • Example of calling basic raw data stitching functions:
        dvppapi_ctl_msg dvppApiCtlMsg;
        vpc_in_msg vpcInMsg;
         // Configures raw data stitching parameters.
        vpcInMsg.use_flag = 3;
        vpcInMsg.collage.image_type = 0;
        vpcInMsg.collage.image_rank_type = 0;
        vpcInMsg.collage.bit_width = 8;
        vpcInMsg.collage.in_width = 1000;
        vpcInMsg.collage.in_high = 1000;
        vpcInMsg.collage.width_stride = 2;
        vpcInMsg.collage.high_stride = 2;
        vpcInMsg.collage.collage_type = 0;
        vpcInMsg.collage.auto_out_buffer = make_shared<AutoBuffer>();
        char image_file[4][50] = {"yuv_data_0","yuv_data_1","yuv_data_2","yuv_data_3"};
        // Initializes the image buffer (without stride data)************begin************.
        for(int i=0; i<4; i++) {
            if(NULL == (vpcInMsg.collage.in_buffer[i] = (char*)malloc(vpcInMsg.collage.in_width*                                        vpcInMsg.collage.in_high*3/2)))
            {
                printf("in_buffer_image alloc failed!\n");
                for(int j=0; j<i; j++) {
                    free(vpcInMsg.collage.in_buffer[j]);
                }
                return ;
            }
           // Opens the image and sends the data to the allocated buffer.
            FILE * yuvimage = fopen(image_file[i],"rb");
            if(NULL == yuvimage)        {
                printf("PVC_TEST: yuv image open faild!");
                return ;
            }        else        {
                fread(vpcInMsg.collage.in_buffer[i], 1,vpcInMsg.collage.in_width*
                      vpcInMsg.collage.in_high*3/2,yuvimage);
                fclose(yuvimage);
                yuvimage = NULL;
            }
        }
    
        dvppApiCtlMsg.in = (void*)(&vpcInMsg);
        dvppApiCtlMsg.in_size = sizeof(vpc_in_msg);
        IDVPPAPI *pidvppapi = NULL;
        CreateDvppApi(pidvppapi);
        if(pidvppapi!=NULL)    {
            if(DvppCtl(pidvppapi,DVPP_CTL_VPC_PROC,&dvppApiCtlMsg)!= 0)        {
                printf("call dvppctl process faild!\n");
                DestroyDvppApi(pidvppapi);
                for(int i=0; i<4; i++) {
                    free(vpcInMsg.collage.in_buffer[i]);
                }
                return ;
            }
            DestroyDvppApi(pidvppapi);
            FILE * fp   = fopen("./out_collage_image_share","wb+");
            fwrite(vpcInMsg.collage.auto_out_buffer->getBuffer(),1,vpcInMsg.collage.in_width*vpcInMsg.collage.in_high*6,fp);
            fflush(fp);
            fclose(fp);
            fp=NULL;
            return ;
        }    else    {
            printf("pidvppapi is null!\n");
            return ;
        }
        for(int i=0; i<4; i++) {
            if(NULL != vpcInMsg.collage.in_buffer[i])        {
                free(vpcInMsg.collage.in_buffer[i]);
                vpcInMsg.collage.in_buffer[i] = NULL;
            }
        }
  • Example of calling the VPC API:
    IDVPPAPI *pidvppapi = NULL;
    CreateDvppApi(pidvppapi);
    if(pidvppapi!=NULL)
    {
     if(0 != DvppCtl(pidvppapi,DVPP_CTL_VPC_PROC,&dvppApiCtlMsg))
     {
      printf("call dvppctl process faild!\n");
      DestroyDvppApi(pidvppapi);
      return -1;
     }
    }
    else
    printf("pidvppapi is null!\n");
    DestroyDvppApi(pidvppapi);
  • Example of calling functions for configuring and obtaining VPC resizing parameters:

    gXxxxx is a configuration parameter.

    dvppapi_ctl_msg dvppApiCtlMsg;
    vpc_in_msg vpcInMsg;
    resize_param_in_msg resize_in_param;
    resize_param_out_msg resize_out_param;
    resize_in_param.src_width = gWidth;
    resize_in_param.src_high = gHigh;
    resize_in_param.hmax = gHmax;
    resize_in_param.hmin = gHmin;
    resize_in_param.vmax = gVmax;
    resize_in_param.vmin = gVmin;
    resize_in_param.dest_width = floor(gHinc * (gHmax - gHmin + 1) + 0.5);
    resize_in_param.dest_high = floor(gVinc * (gVmax - gVmin + 1) + 0.5);
    dvppApiCtlMsg.in = (void *)(&resize_in_param);
    dvppApiCtlMsg.out = (void *)(&resize_out_param);
    IDVPPAPI *pidvppapi = NULL;
    CreateDvppApi(pidvppapi);
    if (0 != DvppCtl(pidvppapi, DVPP_CTL_TOOL_CASE_GET_RESIZE_PARAM, &dvppApiCtlMsg))
    {
      printf("call dvppctl process faild!\n");
      DestroyDvppApi(pidvppapi);
      return;
    }
    int bufferSize = 0;
    vpcInMsg.format = gFormat;
    vpcInMsg.cvdr_or_rdma = gcvdr_or_rdma;
    vpcInMsg.bitwidth = gBitwidth;
    vpcInMsg.rank = gRank;
    vpcInMsg.width = gWidth;
    vpcInMsg.high = gHigh;
    vpcInMsg.stride = gStride;
    vpcInMsg.hmax = resize_out_param.hmax;
    vpcInMsg.hmin = resize_out_param.hmin;
    vpcInMsg.vmax = resize_out_param.vmax;
    vpcInMsg.vmin = resize_out_param.vmin;
    vpcInMsg.vinc = resize_out_param.vinc;
    vpcInMsg.hinc = resize_out_param.hinc;