11.3. API Reference

11.3.1. CVI_GDC_BeginJob

【Description】

Start a Job。

【Syntax】

CVI_S32 CVI_GDC_BeginJob(GDC_HANDLE *phHandle);

【Parameter】

Parameter

Description

Input/Output

phHandle

get HANDLE

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_gdc.h

  • Library files: libvpu.so

【Note】

  • Multiple jobs can be opened simultaneously in GDC.

    For example, while a job for lens distortion correction (LDC) is being performed by VI, a job for rotation can also be executed by VO.

    However, it is important to check if the CVI_GDC_BeginJob function returns successfully before using the HANDLE returned by phHandle.

  • phHandle cannot be a null or illegal pointer.

【Example】

Please refer to  CVI_GDC_AddRotationTask

【Related Topic】

11.3.2. CVI_GDC_EndJob

【Description】

End a job, and all Tasks in this job will be submitted to the GDC module

【Syntax】

CVI_S32 CVI_GDC_EndJob(GDC_HANDLE hHandle);

【Parameter】

Parameter

Description

Input/Output

hHandle

Open Job Handle

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_gdc.h

  • Library files: libvpu.so

【Note】

  • hHandle must be an open job

  • hHandle cannot be a null or illegal pointer.

【Example】

Please refer to CVI_GDC_AddRotationTask

【Related Topic】

11.3.3. CVI_GDC_CancelJob

【Description】

Cancel a job, and all Tasks in this job will not be submitted to the GDC module

【Syntax】

CVI_S32 CVI_GDC_CancelJob(GDC_HANDLE hHandle);

【Parameter】

Parameter

Description

Input/Output

hHandle

opened Job Handle

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_gdc.h

  • Library files: libvpu.so

【Note】

  • hHandle must be an open job.

  • phHandle cannot be a null or illegal pointer.

【Related Topic】

11.3.4. CVI_GDC_AddRotationTask

【Description】

It is possible to insert a rotation task into an existing job.

However, do not support 180-degree rotation.

【Syntax】

CVI_S32 CVI_GDC_AddRotationTask(GDC_HANDLE hHandle, const GDC_TASK_ATTR_S *pstTask, ROTATION_E enRotation);

【Parameter】

Parameter

Description

Input/Output

hHandle

Opened Job Handle

Input

pstTask

GDC Task pointer

Input

enRotation

Rotation angle (0, 90, 180, 270);

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_gdc.h, cvi_comm_gdc.h

  • Library files: libvpu.so

【Note】

  • hHandle must be an open job

  • phHandle cannot be a null or illegal pointer.

【Example】

GDC_HANDLE hHandle;
struct gdc_job *job;
GDC_TASK_ATTR_S stTask;
VB_BLK blk;
VB_S *vb_out;
CVI_U32 buf_size;
CVI_S32 ret;
MMF_CHN_S *_chn;
SIZE_S size_out;

if (rot == ROTATION_90) {
  size_out = vb_in->buf.size;
} else {
  size_out.u32Width = vb_in->buf.size.u32Height;
  size_out.u32Height = vb_in->buf.size.u32Width;
}

// get buf for gdc output.
buf_size = vb_in->buf.length[0] + vb_in->buf.length[1] + vb_in->buf.length[2];
blk = CVI_VB_GetBlock(VB_INVALID_POOLID, buf_size);

vb_in->mod_ids |= BIT(CVI_ID_GDC);
vb_out = (VB_S *)blk;
vb_out->mod_ids = BIT(CVI_ID_GDC);
v4l2_get_frame_info(enPixFormat, size_out, &vb_out->buf, vb_out->phy_addr);

CVI_GDC_BeginJob(&hHandle);

stTask.reserved = CVI_GDC_MAGIC;
CVI_GDC_AddRotationTask(hHandle, &stTask, rot);

job = (struct gdc_job *)hHandle;
job->sync_io = sync_io;
ret = CVI_GDC_EndJob(hHandle);
return ret;

【Related Topic】

11.3.5. CVI_GDC_GenLDCMesh

【Description】

Generating a mesh for LDC properties involves creating a mesh that stores the correspondence between the pixels in the original image and the corrected image.

【Syntax】

CVI_S32 CVI_GDC_GenLDCMesh(CVI_U32 u32Width, CVI_U32 u32Height, const LDC_ATTR_S *pstLDCAttr, const char *name, CVI_U64 *pu64PhyAddr, CVI_VOID **ppVirAddr);

【Parameter】

Parameter

Description

Input/Output

U32Width

Image width after correction

Input

u32Height

Image height after correction

Input

pstLDCAttr

Lens Distortion Correction (LDC) properties

Input

name

Mesh name

Input

pu64PhyAddr

Physical address

Input

ppVirAddr

Virtual address

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_gdc.h, cvi_comm_gdc.h

  • Library files: libvpu.so

【Example】

Please refer to CVI_GDC_AddLDCTask

【Related Topic】

11.3.6. CVI_GDC_AddLDCTask

【Description】

Inserting a lens distortion correction task into an existing job involves two tasks to complete the correction. The first task involves rotating the image by 90 degrees, and the second task involves rotating it by 270 degrees, with correction applied in different directions during each rotation.

【Syntax】

CVI_S32 CVI_GDC_AddLDCTask(GDC_HANDLE hHandle, const GDC_TASK_ATTR_S *pstTask, const LDC_ATTR_S *pstLDCAttr, ROTATION_E enRotation);

【Parameter】

Parameter

Description

Input/Output

hHandle

Opened Job Handle

Input

pstTask

GDC Task pointer

Input

pstLDCAttr

LDC attributes

Input

enRotation

Rotation angle (90, 270);

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_gdc.h, cvi_comm_gdc.h

  • Library files: libvpu.so

【Note】

  • hHandle must be an open job

  • phHandle cannot be a null or illegal pointer.

【Example】

stTask.stImgOut.stVFrame.u32Width = ALIGN(stSize.u32Width, DEFAULT_ALIGN);
stTask.stImgOut.stVFrame.u32Height = ALIGN(stSize.u32Height, DEFAULT_ALIGN);
s32Ret = CVI_GDC_GenLDCMesh(stTask.stImgOut.stVFrame.u32Width,
stTask.stImgOut.stVFrame.u32Height
  , &stLDCAttr, "ldc_user", &u64PhyAddr, &pVirAddr);
if (s32Ret != CVI_SUCCESS) {
  printf("CVI_GDC_GenLDCMesh Failure, s32Ret:0x%x", s32Ret);
  CVI_GDC_CancelJob(hHandle);
  return -1;
}

GDC_TASK_ATTR_S stTaskArr[2];
SIZE_S size_out[2];
ROTATION_E enRotationOut[2];
CVI_U32 mesh_1st_size;

// Rotate 90/270 for 1st job
size_out[0].u32Width = ALIGN(stSize.u32Height, DEFAULT_ALIGN);
size_out[0].u32Height = ALIGN(stSize.u32Width, DEFAULT_ALIGN);

if (enRotation == ROTATION_0 || enRotation == ROTATION_180) {
  size_out[1].u32Width = ALIGN(stSize.u32Width, DEFAULT_ALIGN);
  size_out[1].u32Height = ALIGN(stSize.u32Height, DEFAULT_ALIGN);
} else {
  size_out[1].u32Width = ALIGN(stSize.u32Height, DEFAULT_ALIGN);
  size_out[1].u32Height = ALIGN(stSize.u32Width, DEFAULT_ALIGN);
}
stTask.stImgOut.stVFrame.u32Width = size_out[0].u32Width;
stTask.stImgOut.stVFrame.u32Height = size_out[0].u32Height;
switch (enRotation) {
default:
case ROTATION_0:
  enRotationOut[0] = ROTATION_90;
  enRotationOut[1] = ROTATION_270;
  break;
case ROTATION_90:
  enRotationOut[0] = ROTATION_90;
  enRotationOut[1] = ROTATION_0;
  break;
case ROTATION_180:
  enRotationOut[0] = ROTATION_90;
  enRotationOut[1] = ROTATION_90;
  break;
case ROTATION_270:
  enRotationOut[0] = ROTATION_270;
  enRotationOut[1] = ROTATION_0;
  break;
}
memcpy(&stTaskArr[0], &stTask, sizeof(stTask));
stTaskArr[0].reserved = 0;//magic id
stTaskArr[0].au64privateData[0] = u64PhyAddr;
stTaskArr[0].au64privateData[1] = (uintptr_t)pVirAddr;
stTaskArr[0].au64privateData[2] = CVI_FALSE;
s32Ret = CVI_GDC_AddLDCTask(hHandle, &stTaskArr[0], &stLDCAttr, enRotationOut[0]);
if (s32Ret != CVI_SUCCESS) {
  printf("CVI_GDC_AddLDCTask 1st Failure, s32Ret:0x%x", s32Ret);
  CVI_GDC_CancelJob(hHandle);
  return -1;
}

mesh_gen_get_1st_size(size_out[0], &mesh_1st_size);
memcpy(&stTaskArr[1].stImgIn, &stTask.stImgOut, sizeof(stTask.stImgOut));
memcpy(&stTaskArr[1].stImgOut, &stTask.stImgIn, sizeof(stTask.stImgIn));
stTaskArr[1].stImgOut.stVFrame.u32Width = size_out[1].u32Width;
stTaskArr[1].stImgOut.stVFrame.u32Height = size_out[1].u32Height;
stTaskArr[1].reserved = 0;//magic id
stTaskArr[1].au64privateData[0] = u64PhyAddr + mesh_1st_size;
stTaskArr[1].au64privateData[1] = (uintptr_t)pVirAddr;//save orig mesh addr
stTaskArr[1].au64privateData[2] = CVI_TRUE;
s32Ret = CVI_GDC_AddLDCTask(hHandle, &stTaskArr[1], &stLDCAttr, enRotationOut[1]);
if (s32Ret != CVI_SUCCESS) {
  printf("CVI_GDC_AddLDCTask 2nd Failure, s32Ret:0x%x", s32Ret);
  CVI_GDC_CancelJob(hHandle);
  return -1;
}
memcpy(&stTask, &stTaskArr[1], sizeof(GDC_TASK_ATTR_S));

s32Ret = CVI_GDC_EndJob(hHandle);
if (s32Ret != CVI_SUCCESS) {
  printf("CVI_GDC_EndJob Failure, s32Ret:0x%x\n", s32Ret);
  CVI_GDC_CancelJob(hHandle);
  goto EXIT1;
}
return 0;

【Related Topic】