imx VPU解码分析1-wrap
主要有二个库,一个是imx-vpuwrap,另一个是imx-vpu-hantro。从资料上是这么描述的

我是这么理解的,imx-vpu-hantro是更底层的代码,imx-vpuwrap是封装层实现。
本篇介绍vpuwrap的解码,参阅vpu_wrapper.h。
1.基本的数据类型。
返回值。
| VpuDecRetCode value | Description |
| VPU_DEC_RET_SUCCESS | Success. |
| VPU_DEC_RET_FAILURE | Fail. |
| VPU_DEC_RET_INVALID_PARAM | Parameter is invalid. |
| VPU_DEC_RET_INVALID_HANDLE | Handle is invalid. |
| VPU_DEC_RET_INVALID_FRAME_BUFFER | Frame buffer is invalid. |
| VPU_DEC_RET_INSUFFICIENT_FRAME_BUFFERS | Frame buffers is insufficient. |
| VPU_DEC_RET_INVALID_STRIDE | Stride is invalid. |
| VPU_DEC_RET_WRONG_CALL_SEQUENCE | State of the object is not correct. |
| VPU_DEC_RET_FAILURE_TIMEOUT | The wait for HW/SW finish has timed out. |
主要关注这个结构体VpuDecBufRetCode,在解码过程中返回的最重要的信息。
| VpuDecBufRetCode value | Description |
| VPU_DEC_INPUT_NOT_USED | Input data has been consumed. |
| VPU_DEC_INPUT_USED | Input data hasn’t been consumed. |
| VPU_DEC_OUTPUT_EOS | Got eos. |
| VPU_DEC_OUTPUT_DIS | Got one frame to output. |
| VPU_DEC_OUTPUT_NODIS | Got no frame to output. |
| VPU_DEC_OUTPUT_REPEAT | One frame is output repeatly. |
| VPU_DEC_OUTPUT_DROPPED | Got one frame to drop. |
| VPU_DEC_OUTPUT_MOSAIC_DIS | Got one mosaic frame to output. |
| VPU_DEC_NO_ENOUGH_BUF | No enough buffer to hold for output. |
| VPU_DEC_NO_ENOUGH_INBUF | No enough input buffer. |
| VPU_DEC_INIT_OK | Initialization of decoding is ok. |
| VPU_DEC_SKIP | Skip to decode one frame. |
| VPU_DEC_ONE_FRM_CONSUMED | One frame has been decoded. |
| VPU_DEC_RESOLUTION_CHANGED | Resolution of the frame is changed. |
| VPU_DEC_FLUSH | Flush the decoder. |
VpuDecConfig的配置参数
| VpuDecConfig value | Description |
| VPU_DEC_CONF_SKIPMODE = 0 | parameter value: VPU_DEC_SKIPNONE(default); VPU_DEC_SKIPPB; VPU_DEC_SKIPB; VPU_DEC_SKIPALL; VPU_DEC_ISEARCH. |
| VPU_DEC_CONF_INPUTTYPE | parameter value: VPU_DEC_IN_NOMAL: normal(default); VPU_DEC_IN_KICK: kick -- input data/size in VPU_DecDecodeBuf() will be ignored; VPU_DEC_IN_DRAIN: drain -- stream reach end, and input data/size in VPU_DecDecodeBuf() will be ignored. |
| VPU_DEC_CONF_BUFDELAY | For stream mode. The parameter represents buf size(unit: bytes), buffer size==0 indicate no any delay. |
| VPU_DEC_CONF_INIT_CNT_THRESHOLD | At seqinit stage. vpu will report error if data count reach the threshold. |
| VPU_DEC_CONF_ENABLE_TILED | Configure output frame to tiled after parsed sequence header and before register frame buffer. |
VpuColorFormat的格式,一般VPU解码出来是YUV420格式数据。
typedef enum
{
VPU_COLOR_420=0,
VPU_COLOR_422H=1,
VPU_COLOR_422V=2,
VPU_COLOR_444=3,
VPU_COLOR_400=4,
VPU_COLOR_422YUYV=13,
VPU_COLOR_422UYVY=14,
VPU_COLOR_ARGB8888=15,
VPU_COLOR_BGRA8888=16,
VPU_COLOR_RGB565=17,
VPU_COLOR_RGB555=18,
VPU_COLOR_BGR565=19,
}VpuColorFormat;
VpuCodStd的视频格式
typedef enum {
VPU_V_MPEG4 = 0,
VPU_V_DIVX3,
VPU_V_DIVX4,
VPU_V_DIVX56,
VPU_V_XVID,
VPU_V_H263,
VPU_V_AVC, //h264
VPU_V_AVC_MVC,
VPU_V_VC1,
VPU_V_VC1_AP,
VPU_V_MPEG2,
VPU_V_RV,
VPU_V_MJPG,
VPU_V_AVS,
VPU_V_VP8,
VPU_V_VP9,
VPU_V_HEVC, //h265
VPU_V_SORENSON,
VPU_V_VP6,
VPU_V_WEBP,
} VpuCodStd;
VpuDecOpenParam的打开参数
| Members | Type | Description |
| CodecFormat | VpuCodStd | Type of video. |
| nReorderEnable | int | Whether to enable record. |
| nChromaInterleave | int | Should be set to 1 when (nMapType!=0). |
| nMapType | int | Registered frame buffer type: 0--linear; 1--frame tile; 2--field tile. |
| nTiled2LinearEnable | int | Output frame(only valid when nMapType!=0) : 0--tile; 1--linear(not supported). |
| nPicWidth | int | Width of the decoded image. |
| nPicHeight | int | Height of the decoded image. |
| nEnableFileMode | int | Whether filemode is enabled. |
| nEnableVideoCompressor | int | Whether video compressor is enabed. |
| nPixelFormat | int | Output 10 bit or cut to 8 bit for Hantro G2. 0 for output 10 bit, 1 for cut to 8 bit. |
| nAdaptiveMode | int | Whether in adaptive mode. |
| pAppCxt | void * | Reserved for future application extension. |
| nSecureMode | int | Whether in secure mode. |
| nSecureBufferAllocSize | int | Allocated buffer size in secure mode. |
VpuFrameBuffer帧buffer基本结构体
| Members | Type | Description |
| nStrideY | unsigned int | Luma stride information. |
| nStrideC | unsigned int | Chroma stride information. |
| pbufY | unsigned char * | Physical assress of luma frame pointer or top field pointer. |
| pbufCb | unsigned char * | Physical assress of chroma frame pointer or top field pointer. |
| pbufCr | unsigned char * | |
| pbufMvCol | unsigned char * | |
| pbufY_tilebot | unsigned char * | For field tile: physical assress of luma bottom pointer. |
| pbufCb_tilebot | unsigned char * | For field tile: physical assress of chroma bottom pointer. |
| pbufVirtY | unsigned char * | Virtual address of luma frame pointer or top field pointer. |
| pbufVirtCb | unsigned char * | Virtual address of chroma frame pointer or top field pointer. |
| pbufVirtCr | unsigned char * | |
| pbufVirtMvCol | unsigned char * | |
| pbufVirtY_tilebot | unsigned char * | For field tile: virtual address of luma bottom pointer. |
| pbufVirtCb_tilebot | unsigned char * | For field tile: virtual address of chroma bottom pointer. |
| nReserved[5] | int | Reserved for future extension. |
| pPrivate | void * | Reserved for future special extension. |
上层的包装结构体VpuDecOutFrameInfo
| Members | Type | Description |
| pDisplayFrameBuf | VpuFrameBuffer * | Pointer to VpuFrameBuffer struct which contains the display information of the frame. |
| ePicType | VpuPicType | Type of frame. |
| eFieldType | VpuFieldType | Field type of vpu. |
| nMVCViewID | int | Extended info: support dynamic resolution, ... |
| pExtInfo | VpuFrameExtInfo * | Luma offset. |
| nReserved[2] | int | Reserved for future extension. |
| pPrivate | void * | Reserved for future special extension. |
VpuDecInitInfo一些初始化信息
| Members | Type | Description |
| nPicWidth | int | Aligned width of image. |
| nPicHeight | int | Aligned height of image. |
| nFrameRateRes | int | Numerator of framerate. |
| nFrameRateDiv | int | Denominator of framerate. |
| PicCropRect | VpuRect | VpuRect struct that contains crop information of image. |
| nMinFrameBufferCount | int | Minimum frame buffer count in vpu. |
| nMjpgSourceFormat | int | Source color format of jpeg |
| nInterlace | int | Whether video is interlaced. |
| nQ16ShiftWidthDivHeightRatio | unsigned int | Fixed point for width/height: 1: 0x10000; 0.5: 0x8000;... |
| nConsumedByte | int | Reserved to record sequence length: value -1 indicate unknow. |
| nAddressAlignment | int | Address alignment for Y/Cb/Cr (unit: bytes). |
| nFrameSize | int | Hantro video decoder append DMV and compression table in pixel buffer. |
| nBitDepth | int | Bit depth of video. |
| nReserved[3] | int | Reserved for future extension. |
| pSpecialInfo | void * | Reserved for future special extension. |
| hasColorDesc | int | Whether has color description. |
| hasHdr10Meta | int | Whether has hdr10 meta data. |
| Hdr10Meta | VpuHDR10Meta | Hdr10Meta struct which contains hdr10 meta data. |
| ColourDesc | VpuColourDesc | ColourDesc struct which contains color description. |
| ChromaLocInfo | VpuChromaLocInfo | VpuChromaLocInfo struct which contains chroma information. |
VpuCodecData解码数据,数据和大小。
| Members | Type | Description |
| pData | unsigned char * | Codec data virtual address. |
| nSize | unsigned int | Codec data length. |
上一层的包装结构体VpuBufferNode,包含地址。
| Members | Type | Description |
| pPhyAddr | unsigned char * | Buffer physical base address. |
| pVirAddr | unsigned char * | Buffer virtual base address. |
| nSize | unsigned int | Length of data. |
| sCodecData | VpuCodecData | VpuCodecData struct that contains codec data information. |
| nReserved[2] | int | Reserved for future extension. |
| pPrivate | void * | Reserved for future special extension |
2.基本API
a.VPU的打开和关闭
VPU_DecGetVersionInfo
VPU_DecGetWrapperVersionInfo
VPU_DecGetInitialInfo
VPU_DecConfig
VPU_DecOpen :打开一个 vpu handle
VPU_DecGetCapability
VPU_DecDisCapability
VPU_DecGetErrInfo
VPU_DecGetNumAvailableFrameBuffers
VPU_DecLoad :加载VPU
VPU_DecUnLoad
VPU_DecReset
VPU_DecClose
VPU_DecFlushAll
b.VPU解码
VPU_DecDecodeBuf: 解码一帧数据,结果存储在pOutBufRetCode中。
VPU_DecGetOutputFrame:解码帧信息
VPU_DecGetConsumedFrameInfo:帧buffer信息
VPU_DecOutFrameDisplayed:清理帧显示
c.内存申请和释放
VPU_DecQueryMem
VPU_DecGetMem
VPU_DecFreeMem
VPU_DecRegisterFrameBuffer
3.VPU解码流程

完整步骤:
1.加载VPU
VPU_DecLoad()
2.获取vpulib和vpu wrapper版本信息
VPU_DecGetVersionInfo()
VPU_DecGetWrapperVersionInfo()
3.申请buffer
VPU_DecQueryMem()
4.分配内存给vpu
VPU_DecGetMem()
5.打开一个VPU解码器
VPU_DecOpen()
6.设置解码器
VPU_DecGetCapability()
VPU_DecConfig()
7.开始解码
VPU_DecDecodeBuf()
8.解码后,根据输出状态执行
VPU_DecGetOutputFrame()
VPU_DecGetConsumedFrameInfo()
VPU_DecFlushAll()
- If (pOutBufRetCode & VPU_DEC_ONE_FRM_CONSUMED) is not 0, then call VPU_DecGetConsumedFrameInfo() to get the frame information in vpu.
- If (pOutBufRetCode & VPU_DEC_OUTPUT_DIS) is not 0, then call VPU_DecGetOutputFrame() to get the output frame information.
- If (pOutBufRetCode & VPU_DEC_FLUSH) is not 0, then call VPU_DecFlushAll() to flush the decoder.
9.显示帧后将帧缓冲区释放
VPU_DecOutFrameDisplayed()
10.关闭VPU
VPU_DecClose()
VPU_DecUnLoad()
11.释放VPU内存
VPU_DecFreeMem()
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
