i.MX VPU Application Programming Interface Linux Reference Manual
i.MX VPU Application Programming Interface Linux Reference Manual
Contents
1 Overview 1 Overview....................................................................1
This section discusses the capabilities of i.MX 6 series VPU, 2 Host Interface............................................................ 5
and explains its block diagram. 3 API Features............................... ...............................7
The i.MX 6 series Video Processing Unit (VPU) is a high 4 VPU Control.............................. ............................. 68
performance multi-standard video decoder and encoder engine
that performs multiple standard decoding and encoding 5 Revision History......................... ............................ 86
operations. VPU codec is fully compliant with H.264
BP/MP/HP, VC-1 SP/MP/AP, MPEG-4 SP/ASP except GMC,
DivX (Xvid), MPEG-1/2, VP8, AVS and MJPEG decoding
and H.264, MPEG-4, H.263, and MJPG encoding. The VPU
supports up to full HD 1920x1080 60i or 30p decoding and
1920x1088 encoding. It can encode or decode multiple video
clips with multiple standards simultaneously. A block diagram
of the i.MX 6 series VPU is shown in the figure below.
The VPU connects with the system through the 32-bit
AMBA3 APB bus for system control and the 64-bit AMBA3
AXI for data throughput. The VPU also takes advantage of on-
chip memories to achieve high performance.
Most video hardware blocks in the VPU are optimally
designed for shared usage between different video standards
which provides ultra low power and low gate count with
powerful performance. As shown in the figure below, the VPU
has a 16-bit DSP core, the BIT processor, which controls the
internal video codec operations.
Overview
For simple and efficient control of the VPU by the host processor, the VPU provides a set of registers called the host
interface registers. Most commands and responses between the host processor and the VPU are transmitted through the host
interface registers. Stream data and some output picture data are directly accessed by the host processor and the VPU. For a
more comprehensive way of controlling the VPU, a set of API functions is provided that includes all of the required
operations from the host processor side.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
2 NXP Semiconductors
Overview
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 3
Overview
• 16-bit DSP processor dedicated to processing bitstream and controlling the codec hardware
• General purpose registers and interrupt for communication to and from a host processor
• Optimal external memory accesses
• Configurable frame buffer formats (linear or tiled) for longer burst-length
• 2D cache for motion estimation and compensation to reduce external memory accesses
• Secondary AXI port for on-chip memory to enhance performance
• Performance
• All video decoder standards up to 1920x1088 @ 30 fps at 266 MHz
• H264 encoder standards up to 1920x1088 @ 30 fps at 266 MHz, MPEG4 encoder up to 720p@30fps at 266MHz
• MJPG decoder on 4:4:4 supports 120M pixel per second @ 266MHz
• MJPG encoder on 4:4:4 supports 160M pixel per second @ 266MHz
• Interrupt
• Interrupt from and to external host processor or interrupt controller
1.2 Programmability
The VPU has an internal DSP called the BIT processor which controls the internal hardware blocks for video decoder
operations. The operation of the BIT processor is determined by the dedicated microcode called the BIT firmware. VPU has a
complete set of BIT firmware code as well as a complete set of VPU control functions called VPU API. Therefore,
application developers do not need to manage codec-specific issues on host processor.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
4 NXP Semiconductors
Host Interface
1.2.3 Multi-Instances
The VPU supports multiple instances which can be helpful for multi-channel decoder applications. In order to support this
multi-instance operation, the BIT processor uses an internal context parameter set for each decoder instance. When creating a
new instance and starting a picture processing operation, a set of context parameters is created and updated automatically
within VPU. This internal context management scheme allows different decoder tasks running on the host processor to
control VPU operations independently with their own instance numbers.
When creating a new instance, an application task receives a new handle specifying an instance if a new handle is available
on the VPU. All the subsequent operations for the given application task are handled separately by VPU using this task-
specific handle. When writing a VPU driver, this handle can be regard as a device-ID or a port-ID of the VPU for each task.
Since the VPU can only perform one picture processing task at a time, the application task should check if VPU is ready
before starting a new picture operation. An application can easily terminate a single task on VPU by calling a function for
closing a certain instance.
2 Host Interface
This section describes the interfaces used by host processor to control i.MX 6 VPU.
This section presents a general description of the host interfaces provided for a host processor to control i.MX 6 VPU.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 5
Host Interface
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
6 NXP Semiconductors
API Features
• BIT processor global registers store all the global variables which are reserved even while an active instance is
changed. All the buffer addresses and some global options are safely stored in these registers.
• BIT processor command I/O registers are overwritten or updated whenever a new command is transmitted from the
host processor. All commands with input arguments and all corresponding responses with return values are handled
using these registers.
In addition, command I/O registers are used in a pre-defined way for each command to control VPU.
3 API Features
This section describes the important features of i.MX 6 VPU API, which is an API that includes a set of API functions to
efficiently control VPU.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 7
API Features
A set of API functions is provided to efficiently control VPU. VPU API covers all functions of the i.MX 6 VPU. This API-
based approach speeds up the development process of application software. Important features of the API for i.MX 6 VPU
are summarized in the following sections.
3.2.1.1 Uint8
typedef unsigned char Uint8;
Description
8-bit unsigned integer type used for declaring pixel data.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
8 NXP Semiconductors
API Features
3.2.1.2 Uint16
typedef unsigned short Uint16;
Description
16-bit unsigned integer type.
3.2.1.3 Uint32
typedef unsigned long Uint32;
Description
32-bit unsigned integer type used for declaring unsigned variables with wide ranges such as the size of a buffer.
3.2.1.4 Uint64
typedef unsigned long long Uint64;
Description
64-bit unsigned integer type used for multiplication operation.
3.2.1.5 Int64
typedef long long Int64;
Description
64-bit signed integer type used for multiplication operation.
3.2.1.6 PhysicalAddress
typedef Uint32 PhysicalAddress;
Description
Represents physical addresses that are recognizable by VPU. In general, VPU hardware does not know about the virtual
address space that is set and handled by the host processor. The virtual addresses are translated into physical addresses by the
Memory Management Unit (MMU). Data buffer addresses, such as input bitstream buffer or frame buffer, are given to VPU
as an address in the physical address space.
3.2.1.7 VirtualAddress
typedef Uint32 VirtualAddress;
Description
Represents virtual addresses that are recognizable by CPU.
3.2.1.8 CodStd
typedef enum {
STD_MPEG4 = 0,
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 9
API Features
STD_H263 = 1,
STD_AVC = 2,
STD_VC1 = 3,
STD_MPEG2 = 4,
STD_DIV3 = 5,
STD_RV = 6,
STD_MJPG = 7,
STD_AVS = 8,
STD_VP8 = 9,
} CodStd;
Description
Enumeration for declaring code standard type variables. The following video standards are supported by VPU:
• MPEG4 SP/ASP
• H.263 Profile 3
• AVC (H.264) BP/MP/HP
• VC-1 SP/MP/AP
• MPEG-2, MPEG-1
• Divx3
• AVS
• On2 VP8
NOTE
The MPEG-1 decoder operation is handled as a special case of the MPEG-2 decoder.
3.2.1.9 RetCode
typedef enum {
RETCODE_SUCCESS = 0,
RETCODE_FAILURE = -1,
RETCODE_INVALID_HANDLE = -2,
RETCODE_INVALID_PARAM = -3,
RETCODE_INVALID_COMMAND = -4,
RETCODE_ROTATOR_OUTPUT_NOT_SET = -5,
RETCODE_ROTATOR_STRIDE_NOT_SET = -11,
RETCODE_FRAME_NOT_COMPLETE = -6,
RETCODE_INVALID_FRAME_BUFFER = -7,
RETCODE_INSUFFICIENT_FRAME_BUFFERS = -8,
RETCODE_INVALID_STRIDE = -9,
RETCODE_WRONG_CALL_SEQUENCE = -10,
RETCODE_CALLED_BEFORE = -12,
RETCODE_NOT_INITIALIZED = -13,
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
10 NXP Semiconductors
API Features
RETCODE_DEBLOCKING_OUTPUT_NOT_SET = -14,
RETCODE_NOT_SUPPORTED = -15,
RETCODE_REPORT_BUF_NOT_SET = -16,
RETCODE_FAILURE_TIMEOUT = -17,
RETCODE_MEMORY_ACCESS_VIOLATION = -18,
RETCODE_JPEG_EOS = -19,
RETCODE_JPEG_BIT_EMPTY = -20
} RetCode;
Description
Enumeration for declaring the return codes from API function calls. The meaning of each return code is the same for all API
functions, but the reason of non-successful return might be different. Table 1 shows the basic meaning of each return code.
Table 1. Return Codes
Code Description
RETCODE_SUCCESS Operation successful
RETCODE_FAILURE Operation not successfully; this value is returned when an un-
recoverable decoder error occurs such as a header parsing error
RETCODE_INVALID_HANDLE Given handle for current API function call is invalid, for example, not
initialized yet or improper function call for the given handle
RETCODE_INVALID_PARAM Given argument parameters (for example, input data structure) is invalid
(not initialized yet or not valid anymore)
RETCODE_INVALID_COMMAND Given command is invalid, for example, undefined or not allowed in the
given instance
RETCODE_ROTATOR_OUTPUT_NOT_SET Rotator output buffer is not allocated even though rotation is enabled
RETCODE_ROTATOR_STRIDE_NOT_SET Rotator stride is not provided even though rotation is enabled
RETCODE_FRAME_NOT_COMPLETE Frame decoding operation is not completed, so the given API function
call is not allowed
RETCODE_INVALID_FRAME_BUFFER Certain frame buffer pointers are invalid (not initialized yet or not valid)
RETCODE_INSUFFICIENT_FRAME_BUFFERS Given numbers of frame buffers are not enough for the operations of the
given handle. This return code is only received when calling the
DecRegisterFrameBuffer() function
RETCODE_INVALID_STRIDE Given stride is invalid (for example, 0, not a multiple of 8 or smaller than
the picture size). This return code is only allowed in API functions which
set stride
RETCODE_WRONG_CALL_SEQUENCE Current API function call is invalid considering the allowed sequences
between API functions (for example, missing one crucial function call
before this function call)
RETCODE_CALLED_BEFORE Multiple calls of current API function for a given instance are invalid
RETCODE_NOT_INITIALIZED VPU is not initialized yet. Before calling any API functions, the
initialization API function, vpu_Init(), should be called
RETCODE_DEBLOCKING_OUTPUT_NOT_SET Not used in i.MX 6
RETCODE_NOT_SUPPORTED One feature is not supported
RETCODE_REPORT_BUF_NOT_SET Data report buffer address is not set with a valid value if report of MB,
MV, frame status, slice information or user data is enabled
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 11
API Features
3.2.1.10 CodecCommand
typedef enum {
ENABLE_ROTATION,
DISABLE_ROTATION,
ENABLE_MIRRORING,
DISABLE_MIRRORING,
ENABLE_DERING,
DISABLE_DERING,
SET_MIRROR_DIRECTION,
SET_ROTATION_ANGLE,
SET_ROTATOR_OUTPUT,
SET_ROTATOR_STRIDE,
ENC_GET_SPS_RBSP,
ENC_GET_PPS_RBSP,
DEC_SET_SPS_RBSP,
DEC_SET_PPS_RBSP,
ENC_PUT_MP4_HEADER,
ENC_PUT_AVC_HEADER,
ENC_SET_SEARCHRAM_PARAM,
ENC_GET_VIDEO_HEADER,
ENC_GET_VOS_HEADER,
ENC_GET_VO_HEADER,
ENC_GET_VOL_HEADER,
ENC_GET_JPEG_HEADER,
ENC_SET_INTRA_MB_REFRESH_NUMBER,
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
12 NXP Semiconductors
API Features
DEC_SET_DEBLOCK_OUTPUT,
ENC_ENABLE_HEC,
ENC_DISABLE_HEC,
ENC_SET_SLICE_INFO,
ENC_SET_GOP_NUMBER,
ENC_SET_INTRA_QP,
ENC_SET_BITRATE,
ENC_SET_FRAME_RATE,
ENC_SET_REPORT_MBINFO,
ENC_SET_REPORT_MVINFO,
ENC_SET_REPORT_SLICEINFO,
DEC_SET_REPORT_BUFSTAT,
DEC_SET_REPORT_MBINFO,
DEC_SET_REPORT_MVINFO,
DEC_SET_REPORT_USERDATA,
SET_DBK_OFFSET,
SET_WRITE_MEM_PROTECT,
ENC_SET_SUB_FRAME_SYNC,
ENC_ENABLE_SUB_FRAME_SYNC,
ENC_DISABLE_SUB_FRAME_SYNC,
DEC_SET_FRAME_DELAY,
ENC_SET_INTRA_REFRESH_MODE,
ENC_ENABLE_SOF_STUFF
} CodecCommand;
Description
Special enumeration type for configuration commands from the host processor to VPU. Most of these commands are called
occasionally (not periodically) for changing VPU operation configuration. Details of these commands are presented in
vpu_EncGiveCommand() and vpu_DecGiveCommand().
Following commands aren't used on i.MX 6 platform:
SET_WRITE_MEM_PROTECT
ENC_SET_SUB_FRAME_SYNC
ENC_ENABLE_SUB_FRAME_SYNC
ENC_DISABLE_SUB_FRAME_SYNC
3.2.1.11 GDI_TILED_MAP_TYPE
typedef enum {
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 13
API Features
LINEAR_FRAME_MAP = 0,
TILED_FRAME_MB_RASTER_MAP = 1,
TILED_FIELD_MB_RASTER_MAP = 2,
TILED_MAP_TYPE_MAX
} GDI_TILED_MAP_TYPE;
Description
Enumeration type for the GDI type.
3.2.1.12 MirrorDirection
typedef enum {
MIRDIR_NONE,
MIRDIR_VER,
MIRDIR_HOR,
MIRDIR_HOR_VER
} MirrorDirection;
Description
Enumeration type for representing the mirroring direction.
3.2.1.13 Mp4HeaderType
typedef enum {
VOL_HEADER,
VOS_HEADER,
VIS_HEADER
} Mp4HeaderType;
Description
Special enumeration type for MPEG-4 top-level header classes such as visual sequence header, visual object header, and
video object layer header.
3.2.1.14 AvcHeaderType
typedef enum {
SPS_RBSP,
PPS_RBS,
SPS_RBSP_MVC,
PPS_RBSP_MVC
} AvcHeaderType;
Description
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
14 NXP Semiconductors
API Features
Special enumeration type for AVC parameter sets such as sequence parameter set and picture parameter set.
3.2.1.15 EncHandle
typedef EncInst * EncHandle;
Description
Dedicated type for encoder handles returned when an encoder instance is opened. An encoder instance can be referred to by
the corresponding handle. EncInst is a type managed internally by API and the application does not need to use it.
3.2.1.16 DecHandle
typedef DecInst * DecHandle;
Description
Dedicated type for decoder handles returned when a decoder instance is opened. A decoder instance can be referred to by the
corresponding handle. DecInst is a type managed internally by API and the application does not need to use it.
3.2.2.1 FrameBuffer
typedef struct {
Uint32 strideY;
Uint32 strideC;
int myIndex;
PhysicalAddress bufY;
PhysicalAddress bufCb;
PhysicalAddress bufCr;
PhysicalAddress bufMvCol;
} FrameBuffer;
Description
Data structure for representing frame buffer pointers for each color component
strideY is a Y stride value of the given frame buffers.
myIndex is an A frame buffer index to identify each frame buffer that will be processed by VPU. The index of each buffer
should be unique and less than 32.
bufY is an address for Y component in the physical address space.
bufMvCol is an address for co-located motion vector buffers in the physical address space.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 15
API Features
The host application must allocate contiguous physical memory from SDRAM space for the components using this data
structure. All four addresses must be 8-byte aligned. One pixel value of a component occupies one byte and the frame data is
in YCbCr 4:2:0 format for H.264, H.264 and MPEG-4 codecs. The sizes of the Cb and Cr buffers are 1/4 the size of the Y
buffer size for H.264, H.263 and MPEG-4 codecs. For MJPEG, the frame data format can be YCbCr 4:2:0, 4:2:2 horizontal,
4:2:2 vertical, 4:4:4 and 4:0:0 and the sizes of the Cb and Cr buffers vary. The co-located motion vector is only required for
B-frame decoding in MPEG-2, AVC MP/HP, MPEG-4 ASP, VC-1 MP/AP, and so on.
3.2.2.2 DecMaxFrmInfo
typedef struct {
int maxMbX;
int maxMbY;
int maxMbNum;
} DecMaxFrmInfo;
Description
Data structure for representing maximum frame buffer info for decoder.
maxMbX means maximum supported macro blocks of horizontal direction.
This structure is provided to the host application to specify maximum frame buffer information. Normally, without resolution
change picture decoder support, maxMbX value is picture width/16, maxMbY is picture height/16, maxMbNum is width *
height / 256. If the user knows there is a resolution change from smaller to bigger, the user must give the information as
needed and allocate corresponding maximum frame buffer.
3.2.2.3 Rect
typedef struct {
Uint32 left;
Uint32 top;
Uint32 right;
Uint32 bottom;
} Rect;
Description
Data structure for representing a rectangular window in a frame.
left is a horizontal pixel offset of the top-left corner of the rectangle from top-left corner of the frame.
top is a vertical pixel offset of the top-left corner of the rectangle from top-left corner of the frame.
right is a horizontal pixel offset of the bottom-right corner of the rectangle from top-left corner of the frame.
bottom is a vertical pixel offset of the bottom-right corner of the rectangle from top-left corner of the frame.
This structure is provided to the host application to specify display window for the H.264 cropping option. Each value is
offset from the start point of a frame. Therefore, all values are positive.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
16 NXP Semiconductors
API Features
3.2.2.4 EncHeaderParam
typedef struct {
PhysicalAddress buf;
Uint8 *pBuf;
int size;
int headerType;
int userProfileLevelEnable;
int userProfileLevelIndication;
} EncHeaderParam;
Description
This structure is used for adding a header syntax layer to the encoded bit stream. The parameter headerType is the input
parameter for VPU. The other two parameters are returned from VPU after completing the requested operation. If the encoder
ringbuffer reset option is enabled, the parameters buf and size are also input parameters. In this situation, the host
application must allocate the physical buffer to save the encoded header syntax to VPU.
headerType is the encode header code. In MPEG-4.
3.2.2.5 EncParamSet
typedef struct {
Uint32 *paraSet;
Uint8 *pParaSet;
int size;
} EncParamSet;
Description
This is a structure used when the host processor requires SPS or PPS data from an encoder instance. The resulting SPS or
PPS data is used in an application as a type of out-of-band information.
paraSet is the address of the SPS or PPS data.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 17
API Features
pParaSet is the address of the MJPG encoder header data. It is only for MJPG.
3.2.2.6 EncMp4Param
typedef struct {
int mp4_dataPartitionEnable;
int mp4_reversibleVlcEnable;
int mp4_intraDcVlcThr;
int mp4_hecEnable;
int mp4_verid;
} EncMp4Param;
Description
This is the data structure for configuring MPEG4-specific parameters in encoder applications.
mp4_dataPartitionEnable where 0 = disable, 1 = enable
mp4_intraDcVlcThr is the value of intra_dc_vlc_thr in MPEG-4 part 2 standard. Valid range is 0-7.
mp4_verid is the value of MPEG-4 part 2 standard version ID. Both version 1 and 2 are allowed.
3.2.2.7 EncH263Param
typedef struct {
int h263_annexIEnable;
int h263_annexJEnable;
int h263_annexKEnable;
int h263_annexTEnable;
} EncH263Param;
Description
This is a data structure for configuring H.263-specific parameters in encoder applications.
h263_annexIEnable where 0 = disable, 1 = enable . Not in use for i.MX 6.
3.2.2.8 EncAvcParam
typedef struct {
int avc_constrainedIntraPredFlag;
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
18 NXP Semiconductors
API Features
int avc_disableDeblk;
int avc_deblkFilterOffsetAlpha;
int avc_deblkFilterOffsetBeta;
int avc_chromaQpOffset;
int avc_audEnable;
int avc_fmoEnable;
int avc_fmoSliceNum;
int avc_fmoType;
int avc_fmoSliceSaveBufSize;
int avc_frameCroppingFlag;
int avc_frameCropLeft;
int avc_frameCropRight;
int avc_frameCropTop;
int avc_frameCropBottom;
int mvc_extension;
int interview_en;
int paraset_refresh_en;
int prefix_nal_en;
int avc_vui_present_flag;
VuiParam avc_vui_param;
int avc_level;
} EncAvcParam;
Description
This is a data structure for configuring AVC-specific parameters in encoder applications.
avc_constrainedIntraPredFlag where 0 = disable, 1 = enable
avc_audEnable where 0 = disable, 1 = enable. The encoder generates AUD RBSP at the start of every picture.
avc_fmoEnable is not used in the i.MX 6 since FMO encoding is not supported.
avc_fmoSliceNum is not used in the i.MX 6 since FMO encoding is not supported.
avc_fmoType is not used in the i.MX 6 since FMO encoding is not supported.
avc_fmoSliceSaveBufSize is not used in the i.MX 6 since FMO encoding is not supported.
avc_frameCroppingFlag where 0 = disable, 1 = enable. If this is 1, the encoder will generate frame_cropping_flag syntax
at the SPS header.
avc_frameCropLeft is the sample number of left cropping region in a line.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 19
API Features
prefix_nal_en where 0 = disable, 1 = enable to add prefix nal unit before every 2nd view of MVC stream.
3.2.2.9 EncMjpgParam
typedef struct {
int mjpg_sourceFormat;
int mjpg_restartInterval;
int mjpg_thumbNailEnable;
int mjpg_thumbNailWidth;
int mjpg_thumbNailHeight;
Uint8 * mjpg_hufTable;
Unit8 * mjpg_qMatTable;
Uint8 huffVal[4][162];
Uint8 huffBits[4][256];
Uint8 qMatTab[4][64];
Uint8 cInfoTab[4][6];
} EncMjpgParam;
Description
This is a data structure for configuring MJPEG-specific parameters in encoder applications.
mjpg_sourceFormat is the chroma format. The format means chrominance size of source image and can be a value
between 0 and 4: 0 = 4:2:0, 1 = 4:2:2 horizontal, 2 = 4:2:2 vertical, 3 = 4:4:4, 4 = 4:0:0.
mjpg_restartInterval is the value for representing interval of restart marker in MB unit.
mjpg_thumbNailEnable where 0 = disable, 1 = enable and the encoder enables thumbnail encoding.
mjpg_thumbNailWidth is the variable representing the width (in pixels) of the thumbnail to be encoded. This variable can
have a value between 0 and the source image width. This value must be larger than a specific value and must be a multiple of
the value shown in table below.
Table 2. mjpg_thumbNailWidth and mjpg_thumbNailHeight Values
Format Value
4:2:0 16
4:2:2 16
2:2:4 8
4:4:4 8
4:0:0 8
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
20 NXP Semiconductors
API Features
mjpg_thumbNailHeight is the variable representing the width (in pixels) of the thumbnail to be encoded. This variable can
have a value between 0 and the source image width. This value must be larger than a specific value and must be a multiple of
the value shown in table above.
mjpg_qMatTable is the variable representing a pointer to an address in the Q-Matrix.
mjpg_hufTable is the variable representing a pointer to an address in the Huffman table (not used in i.MX 6).
3.2.2.10 EncSliceMode
typedef struct {
int sliceMode;
int sliceSizeMode;
int sliceSize;
} EncSliceMode;
Description
This is a structure used for declaring encoder slice mode and its options. This structure value is ignored for a MJPEG
encoder.
sliceMode where 0 = one slice per picture, 1 = multiple slices per picture. In normal MPEG-4 mode, the resync-marker
and packet header are inserted between slice boundaries. In short video header with Annex K = 0, the GOB header is inserted
at every GOB layer start. In short video header with Annex K = 1, multiple slices are generated. In AVC mode, multiple slice
layer RBSP is generated.
sliceSizeMode is the size of a generated slice when sliceMode = 1, 0 means sliceSize is defined by amount of bits, and
1 means sliceSize is defined by MB(macro block) in a slice. This parameter is ignored when sliceMode = 0 or in short video
header mode with Annex K = 0.
sliceSize is the size of a slice in bits or MB specified by sliceSizeMode. This parameter is ignored when sliceMode = 0, or
in short video header mode with Annex K = 0.
3.2.2.11 EncOpenParam
typedef struct {
PhysicalAddress bitstreamBuffer;
Uint32 bitstreamBufferSize;
CodStd bitstreamFormat;
int picWidth;
int picHeight;
Uint32 frameRateInfo;
int bitRate;
int initialDelay;
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 21
API Features
int vbvBufferSize;
int gopSize;
int linear2TiledEnable;
int mapType;
EncSliceMode slicemode;
int intraRefresh;
int sliceReport;
int mbReport;
int mbQpReport;
int rcIntraQp;
int chromaInterleave;
int dynamicAllocEnable;
int ringBufferEnable;
union {
EncMp4Param mp4Param;
EncH263Param h263Param;
EncAvcParam avcParam;
EncMjpgParam mjpgParam;
} EncStdParam;
int userQpMin;
int userQpMax;
int userQpMinEnable;
int userQpMaxEnable;
Uint32 userGamma;
int RcIntervalMode;
int MbInterval;
int avcIntra16x16OnlyModeEnable;
int MESearchRange;
int MEUseZeroPmv;
int IntraCostWeight;
} EncOpenParam;
Description
This is a data structure for parameters when an encoder instance is opened.
bitstreamBuffer is a start address of bit stream buffer into which encoder places the bit streams. This address must be 512
byte-aligned.
bitstreamBufferSize is the size in bytes of a buffer pointed to by bitstreamBuffer. This value must be a multiple of 1024.
The maximum size is 16383x1024 bytes.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
22 NXP Semiconductors
API Features
bitstreamFormat is the standard type of bitstream in encoder operation: STD_MPEG4, STD_H263, STD_AVC,
STD_VP8, STD_AVS or STD_MJPG.
picWidth is the width of a picture to be encoded in pixels.
frameRateInfo is the 16 least significant bits, [15:0] is a numerator and 16 most significant bits, [31:16] is a denominator
for calculating the frame rate. The numerator is clock ticks per second and the denominator is clock ticks between frames
minus 1. The frame rate can be defined by (numerator/(denominator + 1)), which equals (frameRateInfo & 0xffff) /
((frameRateInfo >> 16) + 1). For example, a frameRateInfo value of 30 represents 30 frames/sec and the value 0x3e87530
represents 29.97 frames/sec.
bitRate is the target bit rate in kbps. If 0, there is no rate control and pictures are encoded with a quantization parameter
equal to quantParam in EncParam. For MJPEG, this value is ignored. Users can control the MJPEG compression rate by
setting qMatTab[4][64] of EncMjpgParam.
initialDelay is a time delay (in ms) for the bit stream to reach initial occupancy of the vbv buffer from zero level. This
value is ignored if rate control is disabled. The value 0 means the encoder does not check for reference decoder buffer delay
constraints.
vbvBufferSize vbv_buffer_size in bits. This value is ignored if rate control is disabled or initialDelay is 0. The value
0 means the encoder does not check for reference decoder buffer size constraints.
gopSize is the GOP size where 0 = only first picture is I, 1 = all I pictures, 2 = IPIP, 3 = IPPIPP, and so on. The maximum
value is 32,767, but in practice, a smaller value should be chosen by the application for proper error concealment. This value
is ignored for STD_MJPG.
linear2TiledEnable where 0 = disable, 1 = enable to convert linear to tiled format in vpu
mapType where 0 = Linear frame map; 1 = Frame tiled map; 2 = Field tiled map
intraRefresh where 0 = Intra MB refresh is not used. Otherwise = At least N MB's in every P-frame are encoded as intra
MB's. This value is ignored in for STD_MJPG.
sliceReport is not used in i.MX 6.
rcIntraQp is the quantization parameter for I frame. When this value is -1, the quantization parameter for I frames is
automatically determined by VPU. In MPEG4/H.263 mode, the range is 1-31. In H.264 mode, the range is from 0-51. This is
ignored for STD_MJPG.
dynamicAllocEnable is not used in i.MX 6.
ringBufferEnable where 0 = disable, 1 = enable. This flag enables the streaming mode for the current encoder instance.
Two streaming modes, packet-based streaming with ring-buffer (buffer-reset mode), and frame-based streaming with line
buffer (buffer-flush mode) can be configured using this flag. When this field is set, packet-based streaming with ring-buffer is
used. When this field is not set, frame-based streaming with line-buffer is used.
mp4Param is a parameter for MPEG-4 part 2 Visual.
userQpMin sets the minimum quantized step parameter for encoding process. -1 disables this setting and VPU uses the
default minimum quantize step (Qp(H.264 12, MPEG-4/H.263 2). In MPEG-4/H.263 mode, the value of userQpMix is in the
range of 1 to 31 and less than userQpMax. In H.264 mode, the value of userQpMix is in the range of 0 to 51 and less than
userQpMax.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 23
API Features
userQpMax sets the maximum quantized step parameter for the encoding process. -1 disables this setting and VPU uses the
default maximum quantized step. In MPEG-4/H.263 mode, the value of userQpMax is in the range of 1 to 31. In H.264
mode, the value of userQpMax is in the range of 0 to 51. userQpMin and userQpMax must be set simultaneously.
userQpMinEnable userQpMinEable equal to 1 indicates that macroblock QP, generated in rate control, is cropped to be
bigger than, or equal to, userQpMin.
userQpMaxEnable userQpMaxEable equal to 1 indicates that macroblock QP, generated in rate control, is cropped to be
smaller than, or equal to, userQpMax.
userGamma is a smoothing factor in the estimation. A value for gamma is factorx32768, where the value for factor must be
between 0 and 1. If the smoothing factor is close to 0, Qp changes slowly. If the smoothing factor is close to 1, Qp changes
quickly. The default Gamma value is 0.75x32768.
RcIntervalMode is an encoder rate control mode setting. The host sets the bitrate control mode according to the required
use case. The default value is 1. 0 = normal mode rate control 1 = FRAME_LEVEL rate control 2 = SLICE_LEVEL rate
control 3 = USER DEFINED MB LEVEL rate control.
MbInterval is a user defined Mbyte interval value. The default value is 2 macroblock rows. For example, if the resolution is
720x470, then the two macroblock row is 2x(720/16) = 90. This value is used only when the RcIntervalMode is 3.
avcIntra16x16OnlyModeEnable is not used in i.MX 6.
3.2.2.12 EncReportBufSize
typedef struct {
int sliceInfoBufSize;
int mbInfoBufSize;
int mvInfoBufSize;
} EncReportBufSize;
Description
This is a data structure to get the data report buffer size to start encoding from the encoder. Then the application allocates the
memory according to the size information from the data report.
sliceInfoBufSize is a buffer size for slice information.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
24 NXP Semiconductors
API Features
3.2.2.13 EncInitialInfo
typedef struct {
int minFrameBufferCount;
EncReportBufSize reportBufSize;
} EncInitialInfo;
Description
This is a data structure for parameters of vpu_EncGetInitialInfo() which are needed to get the initial information for
encoder.
minFrameBufferCount is a minimum required buffer count in host applications. This returned value is used to allocate
frame buffers in vpu_EncRegisterFrameBuffer().
reportBufSize is the data report requested buffer size information.
3.2.2.14 EncParam
typedef struct {
FrameBuffer * sourceFrame;
int encTopOffset;
int encLeftOffset;
int forceIPicture;
int skipPicture;
int quantParam;
PhysicalAddress picStreamBufferAddr;
int picStreamBufferSize;
int enableAutoSkip;
} EncParam;
Description
This is a data structure for configuring one frame encoding:
encTopOffset is the top offset for cropping from source image to be encoded.
encLeftOffset is the left offset for cropping from source image to be encoded.
forceIPicture. If this value is 0, the picture type is determined by the VPU according to the various parameters such as
encoded frame number and GOP size. If this value is 1, the frame is encoded as an I-picture regardless of the frame number
or GOP size and I-picture period calculation is reset to the initial state. For MPEG-4 and H.263, I-picture is sufficient for
decoder refresh. For H.264 mode, the picture is encoded as an Instantaneous Decoding Refresh (IDR) picture. This value is
ignored if skipPicture = 1.
skipPicture. If this value is 0, the encoder encodes the picture normally. If this value is 1, the encoder ignores
sourceFrame and generates a skipped picture. In this situation, the reconstructed image is a duplication of the previous
picture. The skipped picture is encoded as P-type regardless of GOP size.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 25
API Features
quantParam is used for all quantization parameters with VBR (no rate control). The range of value is 1-31 for MPEG-4 and
0-51 for H.264. When rate control is enabled, this field is ignored.
picStreamBufferAddr is a start address of a picture stream buffer under line-buffer mode and dynamic buffer allocation.
This variable represents the start of a picture stream for encoded output. In buffer-reset mode, an application might use
multiple picture stream buffers for the best performance. Using this variable, an application re-registers the start position of
the picture stream while issuing a picture encoding operation. This start address of this buffer must be 8-byte aligned. Its size
is specified by picStreamBufferSize. In packet-based streaming with ring-buffer, this variable is ignored. This variable is
only meaningful when both line-buffer mode and dynamic buffer allocation are enabled.
picStreamBufferSize is a byte size of a picture stream chunk. This variable represents byte size of a picture stream buffer
and is crucial in line-buffer mode because encoder output can be corrupted if this size is smaller than any picture encoded
output. Therefore, this value should be big enough for storing multiple picture streams with average size. In packet-based
streaming with ring-buffer, this variable is ignored. This variable specifies the picture stream buffer size for encoded output
in line-buffer mode.
enableAutoSkip. The value 0 disables automatic skip and 1 enables automatic skip in encoder operation. Automatic skip
means encoder can skip frame encoding when generated Bitstream so far is too big considering target bitrate. This parameter
will be ignored if rate control is not used (bitRate = 0).
3.2.2.15 EncReportInfo
typedef struct {
int enable;
int type;
int size;
Uint8 *addr;
} EncReportInfo;
Description
This is a structure used for reporting encoder information.
enable is a data report enabled or disabled; type, size and addr are valid when this flag is 1.
ReportInfo
typedef struct {
int enable;
int size;
Uint32 *addr;
union {
int mvNumPerMb;
int userDataNum;
int type;
};
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
26 NXP Semiconductors
API Features
union {
int userDataBufFull;
int reserved;
};
} ReportInfo;
Description
This is a data structure for reporting the encoding/decoding information.
enable 0 - Disable the information report; 1- Enable the information report;
size The size of the buffer pointed by the addr to save the specific returned information while calling the
vpu_DecGiveCommand or vpu_EncGiveCommand to set the buffer while it's used as input parameter. The size of returned
information that's saved in the buffer pointed by the addr after vpu_DecGetOutputInfo or vpu_EncGetOutputInfo calling
while it's used as output parameter. The size has different meanings for different information report cases. For MV
information report in decoding, it represents the total number of MB.
addr The base address of the buffer to save the specific information.
mvNumPerMb When the MB report feature is enabled, decoder will report the motion vector into the buffer pointed by addr.
mvNumPerMb is motion vector number of an macrobloc (MB). the size above is the total number of macroblock. Therefore
total size of MB information in byte is size* mvNumPerMb *4.
userDataNum When the user data report is enabled, decoder will report user data content into the buffer pointed by addr. The
size is the size of user data in byte. When user data report mode is 1 and user data size is bigger than user data buffer size,
VPU reports user data as much as buffer size, skips the remains and sets userDataBufFull.
type When the MV report is enabled in the encoder, this value is used for picture type reporting in MVInfo.
userDataBufFull While user data report is enabled and the user data size is too small to save all decoded user data, VPU will
set userDataBufFull as 1.
reserved Used by driver internally, host application should never use it.
3.2.2.16 EncOutputInfo
typedef struct {
PhysicalAddress bitstreamBuffer;
Uint32 bitstreamSize;
int bitstreamWrapAround;
int skipEncoded;
int picType;
int numOfSlices;
int reconFrameIndex;
Uint32 *pSliceInfo;
Uint32 *pMBInfo;
Uint32 *pMBQpInfo;
EncReportInfo mbInfo;
EncReportInfo mvInfo;
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 27
API Features
EncReportInfo sliceInfo;
} EncOutputInfo;
Description
This is a data structure for reporting the results of picture encoding operations:
bitstreamBuffer is a physical address of the starting point of a newly encoded picture stream. If dynamic buffer allocation
is enabled in line-buffer mode, this value is identical to the picture stream buffer address specified by the host application.
bitstreamSize is a byte size of the encoded bitstream.
bitstreamWrapAround is a flag for bitstream buffer wrap-around. When this flag is set, the bitstream buffer wrapped
around and a larger buffer size is required.
skipEncoded. 0 means current frame was encoded as non-skipped frame. 1 means current Frame was encoded as skipped
frame.
picType is a picture type of the current decoded picture. This value has different meaning for different codecs: for VC1
SP/MP: 0 = I picture, 1 = P picture, 2 = BI picture, 3 = B picture, 4 = SKIPPED picture. For VC1 AP interlacing, picType
contains two picture type information fields: bit[2:0] and bit[5:3] and the respective value has same meaning as SP/MP use
case: 0 = I picture, 1 = P picture, 2 = BI picture, 3 = B picture, 4 = SKIPPED picture. For example, 0 = 000_000: both first
and second field are I picture, 1 = 000_001: first field is I picture and second field is P picture In other codec use cases, 0 = I
picture, 1 = P picture, 2 = B picture.
numOfSlices is a number of slices included in the newly encoded picture. When sliceReport in EncOpenParam is 0, this
value is invalid.
pSliceInfo is not used in the i.MX 6.
mbInfo is the MB information in the encoded picture. If the application does not give the ENC_SET_REPORT_MBINFO
command to enable it before starting one frame encoding, this information is invalid.
mvInfo is a motion vector information in the encoded picture. If the application does not give the
ENC_SET_REPORT_MVINFO command to enable it before starting one frame encoding, this information is invalid.
sliceInfo is a slice information in the encoded picture. If the application does not give the ENC_SET_REPORT_SLICEINFO
command to enable it before starting one frame encoding, this information is invalid.
3.2.2.17 SearchRamParam
typedef struct {
PhysicalAddress searchRamAddr;
int SearchRamSize;
} SearchRamParam;
Description
This is not used in the i.MX 6.
3.2.2.18 DecParamSet
typedef struct {
Uint32 * paraSet;
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
28 NXP Semiconductors
API Features
int size;
} DecParamSet;
Description
Structure used when the host processor requires to send SPS data or PPS data. The SPS data or PPS data is used in real
applications as a type of out-of-band information.
3.2.2.19 DecOpenParam
typedef struct {
CodStd bitstreamFormat;
PhysicalAddress bitstreamBuffer;
Uint8 *pBitStream;
int bitstreamBufferSize;
int qpReport;
int mp4DeblkEnable;
int reorderEnable;
int chromaInterleave;
int filePlayEnable;
int picWidth;
int picHeight;
int avcExtension;
int dynamicAllocEnable;
int streamStartByteOffset;
int mjpg_thumbNailDecEnable;
PhysicalAddress psSaveBuffer;
int psSaveBufferSize;
int mp4Class;
int mapType;
int tiled2LinearEnable;
int bitstreamMode;
int jpgLineBufferMode;
} DecOpenParam;
Description
This is a data structure used to open a new decoder instance:
bitstreamFormat is a standard type of bitstream in decoder operation. One of codec standards defined in CodStd.
bitstreamBuffer is a start physical address of bit stream buffer from which the decoder retrieves the next bitstream. This
address must be 512 byte-aligned.
bitstreamBufferSize is a size in bytes of a buffer pointed by bitstreamBuffer. This value must be a multiple of 1024. The
maximum size is 16383x1024 bytes.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 29
API Features
mp4DeblkEnable where 0 = disable, 1 = enable. In MPEG4 and H.263 (post-processing) modes, the decoder applies
MPEG-4 deblocking filtered output to the host application.
reorderEnable where 1 = enables display buffer reordering when decoding H.264 streams. In H.264 mode, the output
decoded picture is re-ordered if pic_order_cnt_type is 0 or 1 and the decoder must delay the output display for re-ordering.
However, some applications (such as video telephony) do not require such display delay. The host may set this flag to 0 to
disable output display buffer reordering. Then the BIT processor does not re-order the output buffer when pic_order_cnt_type
is 0 or 1. If pic_order_cnt_type is 2 or in MPEG4 or H.263 modes, this flag is ignored because output display buffer
reordering is not allowed.
chromaInterleave where 0 = CbCr not interleaved, 1 = CbCr interleaved.
picWidth is a horizontal picture size read from the file format header used for codecs for which the picture size is not
available in the bitstream, for example DivX3.11.
picHeight is a vertical picture size read from the file format header used for codecs for which the picture size is not
available in the bitstream, for example DivX3.11.
avcExtension where 0 = no extension of AVC, 1 = MVC extension of AVC.
streamStartByteOffset is a start byte offset of the stream buffer. Since the VPU has an internal limitation that the stream
buffer start address must be 8-byte aligned, the host application may be required to copy the stream data to an 8-byte aligned
buffer. This offset allows this overhead to be saved. The values should be between 0 and 7.
mjpg_thumbNailDecEnable is not used in the i.MX 6.
psSaveBuffer is a start address of the PS (SPS/PPS) save buffer which the decoder saves PS (SPS/PPS) RBSP. This
address must be 8 byte-aligned. This variable is only valid for H.264 decoder mode.
psSaveBufferSize is a size in bytes of a buffer pointed to by psSaveBuffer. This value must be a multiple of 1024. The
maximum size is 65565x1024 bytes. This variable is only valid when decoding H.264 streams.
mp4Class is a MPEG4 class when codec is MPEG4 type 0 = MPEG-4; 1 = DivX 5.0 or higher; 2 = Xvid; 5 = DivX 4.0
mapType is an A Map type for GDI inferface. 0 is a linear frame map. 1 is a frame tiled map. 2 is a filed tiled map.
tiled2LinearEnable is a tiled to linear map enable mode. The map type can be changed from tiled to linear in the post
processing unit for display.
bitstreamMode. When read pointer reaches write pointer in the middle of decoding one picture. 0 means VPU sends an
interrupt to HOST and waits for more bitstream to decode. (interrupt mode). 1 means VPU returns to the status right before
the PIC_RUN command (rollback mode).
jpgLineBufferMode where 0 is a LineBuffer mode and 1 is a streaming mode.
3.2.2.20 DecReportBufSize
typedef struct {
int frameBufStatBufSize;
int mbInfoBufSize;
int mvInfoBufSize;
} DecReportBufSize;
Description
Not used in the i.MX 6.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
30 NXP Semiconductors
API Features
3.2.2.21 DecInitialInfo
typedef struct {
int picWidth;
int picHeight;
Uint32 frameRateInfo;
Uint32 frameRateRes;
Uint32 frameRateDiv;
Rect picCropRect;
int mp4_dataPartitionEnable;
int mp4_reversibleVlcEnable;
int mp4_shortVideoHeader;
int h263_annexJEnable;
int minFrameBufferCount;
int frameBufDelay;
int nextDecodedIdxNum;
int normalSliceSize;
int worstSliceSize;
int mjpg_thumbNailEnable;
int mjpg_sourceFormat;
int streamInfoObtained;
int profile;
int level;
int interlace;
int constraint_set_flag[4];
int direct8x8Flag;
int vc1_psf;
int aspectRateInfo;
Uint32 errorcode;;
int bitRate;
Vp8ScaleInfo vp8ScaleInfo;
int mjpg_ecsPtr;
DecReportBufSize reportBufSize;
AvcVuiInfo avcVuiInfo;
} DecInitialInfo;
Description
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 31
API Features
picCropRect is a picture cropping rectangle information. If picCropEnable = 0, this field is invalid. This structure
specifies the cropping rectangle information only for a H.264 decoder. The size and position of the cropping window in a full
frame buffer is presented in this structure. This structure is only valid for H.264 decoder mode.
mp4_dataPartitionEnable where 0 = disable. 1 = enable.
minFrameBufferCount is a minimum number of frame buffers required for decoding. The application must allocate at least
this number of frame buffers and register those number of buffers to the VPU using vpu_DecRegisterFrameBuffer()
before decoding pictures.
frameBufDelay is a maximum display frame buffer delay for buffering decoded picture reorder. The VPU may delay
decoded picture displays for display reordering H.264 mode, when pic_order_cnt_type is 0 or 1 and for B-frame handling in
VC-1 decoder. (By default, some H.264 encoder set pic_order_cnt_type to 0 or 1, but in BP applications, this setting is not
actually used in practice.)
nextDecodedIdxNum is a maximum number of indexes which are returned after decoding one frame. the VPU may return 1
for MPEG-4, H.264, DivX, and MPEG-2 use cases. For VC-1 decoding only, this variable may have a value between 1 and
3.
normalSliceSize is a recommended size of buffer to save slice in normal use case. Value is determined by a quarter of the
memory size of one raw YUV image in Kbytes.
worstSliceSize is a recommended size of buffer used to save slice in worst case. Value is determined by half of the
memory size for one raw YUV image in Kbytes.
mjpg_thumbNailEnable where 0 = disable. 1 = enable. The stream which is decoded as thumbnail.
mjpg_sourceFormat is the chroma format of encoded image of the stream. The format defines the chrominance size of the
source image and can be a value between 0 and 4. 0 = 4:2:0, 1 = 4:2:2 horizontal, 2 = 4:2:2 vertical, 3 = 4:4:4, 4 = 4:0:0
streamInfoObtained. Set to zero so the stream information cannot be obtained in the current firmware. It is true always
on i.MX 6.
profile is the profile information in the stream. This value is used as outlined below:
• H.264 : profile_idc
• Vc1 : 0~2 (SMTPE reserved), 3(advanced profile)
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
32 NXP Semiconductors
API Features
• MP2 : 3'b101: Simple, 3'b100: Main, 3'b011: SNR Scalable, 3'b10: Spatially Scalable, 3'b001: High
• MP4 : If VOS header is existed, 8'b00000000: Simple Profile, 8'b00001000: Advanced coding efficiency;
8'b00001111: Advanced Simple Profile
• If there is only VOL header, 8'b00000001: Simple Profile, 8'b00001100: Advance coding efficiency, 8'b00010001:
Advanced Simple Profile
level is the level information in the stream. This value is used as outlined below:
• H.264 : level_idc
• Vc1 : level
• MP2 : 4'b1010: Low, 4'b1000: Main, 4'b0110: High 1440, 4'b0100: High
• MP4 : If VOS header is existed (high bit is 1, 8'b10000000), 4'b0000 or 4'b1000: L0, 4'b0001: L1, 4'b0010: L2,
4'b0011: L3...; If there is VOS header, level cannot be obtained.
interlace is the interlace information in the stream where 0 means only progressive frames in the stream, and 1 means
there may be interlaced frame in the stream.
constraint_set_flag is a syntax element in H.264 used to make level in H.264. Ignored in other standards.
aspectRateInfo is an aspect rate information in stream information. If the value is 0, then aspect ratio information is not
present.
• [H.264] - if aspectRateInfo [31:16] is 0, aspectRateInfo [7:0] means aspect_ratio_idc. Otherwise, AspectRatio means
Extended_SAR.
• sar_width = aspectRateInfo [31:16]
• sar_height = aspectRateInfo [15:0]
• [VC-1]- Aspect Width = aspectRateInfo [31:16]
• Aspect Height = aspectRateInfo [15:0]
• [MP4] - This value is index of Table 6-12 in ISO/IEC 14496-2.
• [MP2] - This value is index of Table 6-3 in ISO/IEC 13818-2. It is determined by half of the memory size for one raw
YUV image in KB unit.
bitRate is the bitrate value written in bitstream syntax. Available only when value is not 1.
mjpg_ecsPtr is the consumed mjpg size for using software GetInitialInfo for MJPG decoder.
3.2.2.22 ExtBufCfg
typedef struct {
PhysicalAddress bufferBase;
int bufferSize;
} ExtBufCfg
Description
This data structure is used when the host application wants to give external memory configuration to VPU.
bufferBase is the start address of external memory.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 33
API Features
3.2.2.23 DecBufInfo
typedef struct {
ExtBufCfg avcSliceBufInfo;
ExtBufCfg vp8MbDataBufInfo;
DecMaxFrmInfo maxDecFrmInfo;
} DecBufInfo;
Description
This data structure is used when the host application wants to transfer additional buffer information without the frame buffer.
avcSliceBufInfo is the start address and size of the slice save buffer where decoder can save slice RBSP. This variable is
only valid for H.264 decoder.
vp8MbDataBufInfo is the start address and the size of macroblock prediction data save buffer in which the VP8 decoder
can save inflated macroblock information for a frame. This buffer is temporal scratch memory that sustains while decoding a
picture. The start address must be 8-byte aligned.
maxDecFrmInfo is the maximum supported info of the frame buffer. Not used in the i.MX 6.
3.2.2.24 DecParam
typedef struct {
int prescanEnable;
int prescanMode;
int dispReorderBuf;
int iframeSearchEnable;
int skipframeMode;
int skipframeNum;
int chunkSize;
int picStartByteOffset;
PhysicalAddress picStreamBufferAddr;
PhysicalAddress phyJpgChunkBase;
}DecParam;
Description
This is a data structure for picture decoding options:
prescanEnable is not used in the i.MX 6.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
34 NXP Semiconductors
API Features
iframeSearchEnable where 0 = disable, 1 = enable, and the decoder performs skipping frame decoding until decoder
meets an I (IDR) frame. If there is no I frame in the stream, the decoder waits for a I (IDR) frame. If skipframeNum is n, the
decoder seeks the (n + 1)th I (IDR) frame. When decoder meets an EOS (End Of Sequence) code during I-Search, the decoder
returns -1 (0xFFFF). If this option is enabled, skipframeMode options are ignored.
skipframeMode is a skip frame function enable and operation mode. 0 means skip frame disable, 1 means skip frame
enabled (skip frames but I (IDR) frame), 2 means skip frame enabled (skip any frames). If this option is enabled, the decoder
skips decoding as far as skipframeNum frames. After the decoder skips frames, the decoder returns decoded index -2
(0xFFFE) when it does not have any frames displayed. When decoder meets EOS (End Of Sequence) code during frame skip,
the decoder returns -1 (= 0xFFFF).
skipframeNum is not used in the i.MX 6.
virtJpgChunkBase is the point of virtual memory address of input bitstream buffer for Jpg.
3.2.2.25 DecReportInfo
typedef struct {
int enable;
int size;
union {
int mvNumPerMb;
int userDataNum;
};
union {
int reserved;
int userDataBufFull;
};
Uint8 *addr;
} DecReportInfo;
Description
This function is not used in the i.MX 6.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 35
API Features
3.2.2.26 Vp8ScaleInfo
typedef struct {
unsigned hScaleFactor : 2;
unsigned vScaleFactor : 2;
} Vp8ScaleInfo;
Description
This is data structure of picture up-scaling information for post-processing out of decoding loop.
This structure is valid only for VP8 decoding use case and can never be used by VPU itself. If host has an up sampling
device, this information is useful. When the host allocates a frame buffer, application needs up-scaled resolution derived by
this information to allocate enough (maximum) memory for variable resolution picture decoding.
hScaleFactor is an up-scaling factor for horizontal expansion. The value could be 0 to 3. The meaning of each value is
described below:
• 0 means 1 up-sampling ratio
• 1 means 5/4 up-sampling ratio
• 2 means 5/3 up-sampling ratio
• 3 means 2/1 up-sampling ratio.
vScaleFactor is an up-scaling factor for vertical expansion. The value could be 0 to 3. The meaning of each value is
described below:
• picWidth is a picture width in units of sample.
• picHeight is a picture height in units of sample.
3.2.2.27 Vp8PicInfo
typedef struct {
unsigned showFrame : 1;
unsigned versionNumber : 3;
unsigned refIdxLast : 8;
unsigned refIdxAltr : 8;
unsigned refIdxGold : 8;
} Vp8PicInfo;
Description
This is a data structure for VP8-specific header information and reference frame indices. Only VP8 decoder returns this
structure after decoding a frame.
showFrame is the frame header syntax which means whether the current decoded frame is displayable or not. It is 0 when
current frame is not for display and 1 when current frame is for display.
versionNumber is the VP8 profile version number information in the frame header. The version number enables or disables
certain features in bitstream. It can be defined with one of the four different profiles: 0 to 3. Each indicates different decoding
complexity.
refIdxLast is the frame buffer index for the Last reference frame. This field is valid only for next inter frame decoding.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
36 NXP Semiconductors
API Features
refIdxAltr is the frame buffer index for the altref (Alternative Reference) reference frame. This field is valid only for next
inter frame decoding.
refIdxGold is the frame buffer index for the Golden reference frame. This field is valid only for next inter frame decoding.
3.2.2.28 AvcFpaSei
typedef struct {
unsigned exist;
unsigned frame_packing_arrangement_id;
unsigned frame_packing_arrangement_cancel_flag;
unsigned quincunx_sampling_flag;
unsigned spatial_flipping_flag;
unsigned frame0_flipped_flag;
unsigned field_views_flag;
unsigned current_frame_is_frame0_flag;
unsigned frame0_self_contained_flag;
unsigned frame1_self_contained_flag;
unsigned frame_packing_arrangement_ext_flag;
unsigned frame_packing_arrangement_type;
unsigned content_interpretation_type;
unsigned frame0_grid_position_x;
unsigned frame0_grid_position_y;
unsigned frame1_grid_position_x;
unsigned frame1_grid_position_y;
unsigned frame_packing_arrangement_repetition_period;
} AvcFpaSei;
Description
This is a data structure for AVC FPA (frame packing arrangement) SEI.
0 means AVC FPA SEI does not exist. 1 means AVC FPA SEI exists.
frame_packing_arrangement_id 0 ~ 2^32-1 is an identifying number that may be used to identify the usage of the
frame packing arrangement SEI message.
frame_packing_arrangement_cancel_flag indicates whether the frame packing arrangement SEI message cancels the
persistence of any previous frame packing arrangement SEI message in output order.
quincunx_sampling_flag indicates whether each color component plane of each constituent frame is quincunx sampled.
spatial_flipping_flag indicates that one of the two constituent frames is spatially flipped.
field_views_flag 1 indicates that all pictures in the current coded video sequence are coded as complementary field
pairs.
current_frame_is_frame0_flag indicates the current decoded frame and the next decoded frame in output order.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 37
API Features
frame0_self_contained_flag indicates whether inter prediction operations within the decoding process for the samples
of constituent frame 0 of the coded video sequence refer to samples of any constituent frame 1.
frame1_self_contained_flag indicates whether inter prediction operations within the decoding process for the samples
of constituent frame 1 of the coded video sequence refer to samples of any constituent frame 0.
frame_packing_arrangement_extension_flag 0 indicates that no additional data follows within the frame packing
arrangement SEI message.
frame_packing_arrangement_type is the type of packing arrangement of the frames as specified in Table D-8, ISO/IEC
14496-10D.2.25.
content_interpretation_type indicates the intended interpretation of the constituent frames.
frame0_grid_position_x specifies the horizontal location of the upper left sample of constituent frame 0 to the right of
the spatial reference point.
frame0_grid_position_y specifies the vertical location of the upper left sample of constituent frame 0 below the spatial
reference point.
frame1_grid_position_x specifies the horizontal location of the upper left sample of constituent frame 1 to the right of
the spatial reference point.
frame1_grid_position_y specifies the vertical location of the upper left sample of constituent frame 1 below the spatial
reference point.
frame_packing_arrangement_repetition_period indicates persistence of the frame packing arrangement SEI
message.
3.2.2.29 MvcPicInfo
typedef struct {
int viewIdxDisplay;
int viewIdxDecoded;
} MvcPicInfo;
Description
This is a data structure for MVC-specific picture information. Only MVC decoder returns this structure after decoding a
frame.
viewIdxDisplay is the view index order of display frame buffer corresponding to indexFrameDisplay of DecOutputInfo
structure.
viewIdxDecoded is the view index order of decoded frame buffer corresponding to indexFrameDecoded of DecOutputInfo
structure.
3.2.2.30 DecOutputInfo
typedef struct {
int indexFrameDisplay;
int indexFrameDecoded;
int NumDecFrameBuf;
int picType;
int picTypeFirst;
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
38 NXP Semiconductors
API Features
int idrFlg;
int numOfErrMBs;
Uint32 *qpInfo;
int hScaleFlag;
int vScaleFlag;
int indexFrameRangemap;
int prescanresult;
int notSufficientPsBuffer;
int notSufficientSliceBuffer;
int decodingSuccess;
int interlacedFrame;
int mp4PackedPBframe;
int h264Npf;
int pictureStructure;
int topFieldFirst;
int repeatFirstField;
union {
int progressiveFrame;
int vc1_repeatFrame;
};
int fieldSequence;
int decPicHeight;
int decPicWidth;
Rect decPicCrop;
int aspectRateInfo;
Uint32 frameRateRes;
Uint32 frameRateDiv;
Vp8ScaleInfo vp8ScaleInfo;
Vp8PicInfo vp8PicInfo;
MvcPicInfo mvcPicInfo;
AvcFpaSei avcFpaSei;
AvcVuiInfo avcVuiInfo;
int frameStartPos;
int frameEndPos;
int consumedByte;
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 39
API Features
DecReportInfo mbInfo;
DecReportInfo mvInfo;
DecReportInfo frameBufStat;
DecReportInfo userData;
} DecOutputInfo;
Description
This is a data structure to get information resulting from decoding a frame.
indexFrameDisplay is a frame buffer index of a picture to be displayed among frame buffers which were registered using
vpu_DecRegisterFrameBuffer(). Frame data to be displayed is stored into the frame buffer specified by this index.
When a delay in display does not exist, this index is the same as indexFrameDecoded. But if not, (for example, display
reordering in AVC or B-frames in VC-1), this index is not the same value as indexFrameDecoded. If the decoder cannot
provide a display output at the beginning of sequence decoding with different display order, this index always has -2
(0xFFFE) or -3 (0xFFFD) depending on the decoder skip option. And at the end of sequence decoding, if there is no more
output for display, this value has -1 (0xFFFF). By checking this index, the host application can easily know whether sequence
decoding has finished or not.
indexFrameDecoded is a frame buffer index of decoded picture among frame buffers which were registered using
vpu_DecRegisterFrameBuffer(). A decoded frame during current picture decoding operation is stored into the frame
buffer specified by this index. If decoder meets EOS or skip, the decoder returns -1 (0xFFFF) to represent that no decoded
output is generated. Because of delays in display, the return value of -1 does not mean end of decoding. In order to check the
end of decoding, the host application should refer toindexFrameDisplay.
picType is a picture type of the decoded picture where 0 = I picture, 1 = P picture, 2 = B picture. For H.264, bit[0] indicates
IDR frame. 0 means current frame is IDR. 1 means non-IDR frame. If 0, the bit [2:1] should be ignored. If 1 of bit [0], bit
[2:1] represents the slice types of current picture. 0 means I-slice, 1 means P-slice, 2 means B-slice. The actual value is the
value of the ORed value of all slices of the current picture.
numOfErrMBs is a number of erroneous macroblocks while decoding a picture.
hScaleFlag is a flag for reduced resolution output in horizontal direction. For VC1 decoding, the resulting picture width
from the decoder may be half the decoded picture width. In this situation, this flag is set. The host application should scale up
the picture by two times in the horizontal direction to get proper display output.
vScaleFlag is a flag for reduced resolution output in vertical direction. For VC1 decoding, the resulting picture height from
the decoder may be half the decoded picture height. In this situation, this flag is set. The host application should scale up this
picture by two times in the vertical direction to get proper display output.
indexFrameRangemap is not used in the i.MX 6.
notSufficientPsBuffer is a flag that represents whether PS (SPS/PPS) save buffer is sufficient to decode the current
picture. VPU does not get the last part of the current picture stream because of the buffer overflow. The host must close the
current instance since the picture streams cannot be decoded properly because of loss of SPS/PPS data.
notSufficientSliceBuffer is a flag that represents whether slice save buffer is sufficient to decode the current picture.
VPU does not get the last part of the current picture stream, and macroblock errors issue because of buffer overflow. The host
can continue decoding the remaining pictures of the current input stream without closing the current instance, even though
several pictures can be error-corrupted.
decodingSuccess where bit 0 = 0 means incomplete finish of decoding process and bit 0 = 1 means complete finish of
decode process. This variable means that the decoding process is finished completely. If stream has errors in the picture
header syntax or the first slice header syntax of H.264 stream, VPU does not initiate the MB decoding routine and returns
immediately. In this situation, VPU returns bit 0 = 0, which means incomplete end of decoding process. Additionally, this
variable uses some bits to indicate error reasons why VPU returns from picture decoding. In rollback mode, if bitstream
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
40 NXP Semiconductors
API Features
buffer doesn't have enough bits for decoding a picture, VPU returns from decoding and rolls back its read pointer to the
beginning of that picture. In this situation, bit 4 of decodingSuccess is 1. When sequence parameters are changed, bit 20 of
decodingSuccess is 1.
interlacedFrame where 0 means progressive frame which consists of one frame picture and 1 means interlaced frame
which consists of two field picture (top field and bottom field). This variable indicates that the frame is the interlaced frame.
If this value is set, the host application may use a de-interlacing filter to enhance image quality.
mp4PackedPBframe where 0 means normal frame chunk data and 1 means packed PB frame chunk data. This variable
indicates that the frame chunk data is a packed PB frame chunk. If this value is set, the host application must re-use this
chunk in the next decoding command. This variable is only valid for MPEG-4 file-play mode.
h264Npf indicates that a top or bottom field is absent when NPF occurres in display picture.
PictureStructure is a picture structure in picture coding ext in MP2, interlaced in Video Object Layer in MP4, MBAFF
(MB Adaptive frame/field mode) flag in H.264, and FCM in picture header in VC1.
topFieldFirst where 0 means bottom field first and 1 means top field first. Ignored if interlacedFrame is 0.
vc1_repeatFrame where 0 means not repeat frame and 1 means repeat frame.
decPicWidth is a picture width of current decoded frame. For MJPEG decoding, the decPicHeight and decPicWidth are the
size of the decoded rotator frame saved in the rotation frame buffer that is registered by the SET_ROTATOR_OUTPUT
command. VPU supports the changed resolution decoding. VPU only supports the changed resolution not larger than the
original size. For example, the changed sequence of VGA > QVGA > VGA is supported.
decPicCrop is a picture crop information of current decoded frame. Only effective with the H.264 decoder.
aspectRateInfo H.264 - It is aspect_ratio_idc [7:0] when [31:8] is 0. Otherwise it is ssar_width in [31:16] and sar_height
in [15:0]. VC-1 - ASPECT_RATIO h:v are reported in [15:8] : [7:0] as described in the spec. MPEG4 - This value is index of
Table 6-12 in ISO/IEC 14496-2; MPEG2 - This value is index of Table 6-3 in ISO/IEC 13818-2.
frameRateRes is the numerator part of frame rate fraction. This is the value of time_scale in the H.264 VUI syntax for AVC
decoding.
frameRateDiv is the denominator part of the frame rate fraction. In case of AVC decoding, this is the value of
num_units_in_tick in the H.264 VUI syntax. User can get the frame rate with this parameter. For AVC decoder, frame rate =
frameRateRes / (frameRateDiv*2). Otherwise, frame rate = frameRateRes / frameRateDiv.
vp8ScaleInfo is VP8 up sampling information. Refer to the Vp8ScaleInfo.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 41
API Features
userData is a motion vector in the decoded picture. If the application does not give the DEC_SET_REPORT_USERDATA
command to enable the report before starting one frame decoder, this information is invalid.
3.2.2.31 vpu_versioninfo
typedef struct {
} vpu_versioninfo;
Description
This is a data structure to get the VPU firmware and library version:
fw_major, fw_minor, fw_release Firmware version, naming convention which are similar to Linux kernel.
lib_major, lib_minor, lib_release VPU library version, naming convention which are all similar to Linux kernel.
3.2.2.32 VPUMemAlloc
typedef struct {
int size;
} vpu_mem_desc;
Description
Data structure used when the host application allocates physically contiguous memory for the VPU:
size is a requested memory size.
phy_addr is a physical base address of the buffer allocated by driver if allocated successfully.
cpu_addr is a kernel virtual address corresponding to phy_addr. The programmer of the user-space application does not
need to care about this.
virt_uaddr is an user-space virtual address corresponding to phy_addr, which the host application can access.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
42 NXP Semiconductors
API Features
3.2.2.33 iram_t
typedef struct iram_t {
} iram_t;
Description
start is a start address of the internal memory for VPU use.
i.MX 6 VPU API functions are based on a frame-by-frame picture processing scheme. To run a picture decoder or encoder,
the application calls an API function. After completion of the processing, the application can check the results of the picture
processing.
To support multi-instance decoding and encoding, i.MX 6 VPU API functions use a handle to specify a certain instance. The
handle for each instance is provided when the application creates a new decoder or encoder instance. If the application wants
to give a command to a specific instance, the corresponding handle is used in every API function call for that instance.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 43
API Features
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
44 NXP Semiconductors
API Features
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 45
API Features
3.3.2.1 vpu_Init()
Prototype
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
46 NXP Semiconductors
API Features
RetCode vpu_Init(void *);
Parameter
Not used, just defined for extension. The user can set it with null.
Return Value
RETCODE_SUCCESS means VPU initialized successfully.
Description
This function initializes the VPU hardware and proper data structures/resources. The application must call this function
before using VPU. If the VPU hardware is initialized after boot at first usage, VPU library does not need to initialize the
hardware again. For example, there is no need to load the firmware again. This is transparent to the application.
3.3.2.2 vpu_UnInit()
Prototype
void vpu_UnInit();
Parameter
None
Description
This function deinitializes the VPU hardware and releases the resources that are allocated in the vpu_Init() function. The
application must call this function before exiting.
3.3.2.3 vpu_IsBusy()
Prototype
int vpu_IsBusy();
Parameter
None
Return Value
0 VPU hardware is idle.
1 VPU hardware is busy processing a frame.
Description
This function tells the application if decoder or encoder frame processing is completed or not.
3.3.2.4 jpu_IsBusy()
Prototype
int jpu_IsBusy();
Parameter
None
Return Value
0 JPU hardware is idle.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 47
API Features
3.3.2.5 vpu_WaitForInt()
Prototype
Parameter
timeout_in_ms [input] is wait time in milliseconds.
Return Value
RETCODE_SUCCESS means that the operation is successful.
RETCODE_FAILURE means that the operation failed.
Description
The application waits for the decoder or encoder to complete the interrupt. This function returns immediately if the interrupt
has been received. Otherwise, it returns after timeout_in_ms.
3.3.2.6 vpu_GetVersionInfo()
Prototype
Parameter
verinfo [output] is the pointer to vpu_versionInfo data.
Return Value
RETCODE_SUCCESS means that the version information is acquired successfully.
RETCODE_FAILURE means that the current firmware does not contain any version information.
RETCODE_NOT_INITIALIZED means that VPU is not initialized before calling this function. The application should
initialize VPU by calling vpu_Init() before calling this function.
Description
This function provides the version information running on the system to the application.
3.3.2.7 IOGetPhyMem()
Prototype
Parameter
buff [input] is a pointer to memory information stored in allocated memory. The user needs to input buff > size, then
buff >. phy_addr is output after return success.
Return Value
RETCODE_SUCCESS means that the operation is successful.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
48 NXP Semiconductors
API Features
3.3.2.8 IOFreePhyMem()
Prototype
Parameter
buff [input] is a pointer to memory information stored in allocated memory. The user needs to input buff > size, then
buff > phy_addr is output after return success.
Return Value
RETCODE_SUCCESS means that the operation is successful.
RETCODE_FAILURE means that the operation failed.
Description
This function frees the physical memory allocated by IOGetPhyMem back to the system.
3.3.2.9 IOGetVirtMem()
Prototype
Parameter
buff [input] is a pointer to memory information stored in allocated memory. The user needs to input buff > size, then
buff > phy_addr is output after return success.
Return Value
RETCODE_SUCCESS means that the operation is successful.
RETCODE_FAILURE means that the operation failed.
Description
This function gets the virtual address of the given physical address. If the allocated physical continuous memory needs to be
accessed in user space, this function is used to map physical memory.
3.3.2.10 IOFreeVirtMem()
Prototype
Parameter
buff [input] is a pointer to memory information stored in allocated memory. The user needs to input buff > size, then
buff > phy_addr is output after return success.
Return Value
RETCODE_SUCCESS means that the operation is successful.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 49
API Features
3.3.2.11 IOGetIramBase()
Prototype
Parameter
iram [input] is a pointer to memory information that stores the internal memory.
Return Value
RETCODE_SUCCESS means that the operation is successful.
RETCODE_FAILURE means that the operation failed.
Description
This function is not used in i.MX 6.
3.3.2.12 vpu_SWReset()
Prototype
Parameter
handle [input] is an encoder/decoder handle obtained from vpu_EncOpen()/vpu_DecOpen().
Return Value
RETCODE_SUCCESS means that the operation is successful.
RETCODE_FAILURE means that the operation failed.
Description
This function resets the instance specified by the handle or index. Host application can use this function with two methods:
1) Calling with handle parameter. If handle is given, the index parameter will be ignored automatically.
2) Calling with index parameter. This method is for special use cases in which the application exists without instance closed,
the resources need to be released, and the host knows the exact index of instance.
In normal situations, you should reset VPU with a specified handle. You should be confident in what you are doing if
resetting VPU with an index parameter not a handle.
3.3.3.1 vpu_EncOpen()
Prototype
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
50 NXP Semiconductors
API Features
RetCode vpu_EncOpen(EncHandle * pHandle, EncOpenParam * pop);
Parameter
pHandle [output] is a pointer to EncHandle type variable which specifies instance for an application. If no instance is
available, a null handle is returned.
pop [input] is a pointer to a EncOpenParam type structure which describes the parameters for the new encoder instance.
Return Value
RETCODE_SUCCESS means that the new encoder instance opened successfully.
RETCODE_FAILURE means that the new encoder instance not opened successfully. If there is no free instance available,
this value is returned in the function call.
RETCODE_INVALID_PARAM means that a given argument parameter, pop, is invalid-it has a null pointer or contains
improper values for some member variables.
RETCODE_NOT_INITIALIZED means that VPU is not initialized before calling this function. The application must
initialize VPU by calling vpu_Init() before calling this function.
Description
To start a new encoder operation, the application must open a new instance. By calling this function, the application gets a
handle specifying a new encoder instance. Because i.MX 6 VPU supports multiple instances of codec operations, the
application needs this kind of handle for the all running codec instances. Once the application receives a handle, the
application uses this handle to represent the target instances for all subsequent encoder-related operations.
3.3.3.2 vpu_EncClose()
Prototype
Parameter
handle [input] is an encoder handle obtained from vpu_EncOpen().
Return Value
RETCODE_SUCCESS means that the encoder instance closed successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This code might be
returned if handle has not been obtained by vpu_EncOpen(), for example a decoder handle, or if handle is from an instance
which has been closed.
RETCODE_FRAME_NOT_COMPLETE means that the frame decoding or encoding operation is not completed yet and the
API function call cannot be performed at this time. A frame encoding or decoding operation should be completed by calling
vpu_EncGetOutputInfo() or vpu_DecGetOutputInfo(). Even though the result of the current frame operation is not
necessary, the application should call vpu_EncGetOutputInfo() or vpu_DecGetOutputInfo() to proceed with this function
call.
RETCODE_FAILURE_TIMEOUT means that the hardware is already busy with other operation and unavailable for current
API calling.
Description
This function is called by the application to close an instance when the application completes the encoding operations and
wants to release this instance for other processing. After completion of this function call, the instance referred to by the
handle is free. Once the application closes an instance, the application cannot call any further encoder-specific function with
this handle before re-opening a new instance with the same handle.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 51
API Features
3.3.3.3 vpu_EncGetInitialInfo()
Prototype
Parameter
handle [input] is an encoder handle obtained from vpu_EncOpen().
info [output] is a pointer to a EncInitialInfo type structure which describes the parameters required before starting
encoder operations.
Return Value
RETCODE_SUCCESS means that receiving the initial parameters completed successfully.
RETCODE_FAILURE means that there is an error getting the configuration information for the encoder.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This code might be
returned if handle has not been obtained by vpu_EncOpen(), for example a decoder handle, or if handle is of an instance
which has been closed.
RETCODE_INVALID_PARAM means that the given argument parameter, info, is invalid. This means that it has a null
pointer or contains improper values for some member variables.
RETCODE_CALLED_BEFORE means that the function call is invalid because multiple calls of the current API function for
a given instance are not allowed. The encoder initial information has already been received, so this function call is
meaningless and not allowed.
RETCODE_FAILURE_TIMEOUT means that the hardware is already busy with other operation and unavailable for current
API calling.
Description
Before starting the encoder operation, the application must allocate the frame buffers according to the information obtained
from this function. This function returns the required parameters for vpu_EncRegisterFrameBuffer(), which is followed by
this function call.
3.3.3.4 vpu_EncGetBitstreamBuffer()
Prototype
PhysicalAddress * prdPrt,
Parameter
handle [input] is an encoder handle obtained from vpu_EncOpen().
prdPrt [output] is a stream buffer read pointer for the current encoder instance.
pwrPtr [output] is a stream buffer write pointer for the current encoder instance.
size [output] is a variable specifying the available space in the bitstream buffer for the current encoder instance.
Return Value
RETCODE_SUCCESS means that the required information for encoder stream buffer is received successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This code might be
returned if handle has not been obtained by vpu_EncOpen(), for example a decoder handle, or if handle is of an instance
which has been closed.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
52 NXP Semiconductors
API Features
RETCODE_INVALID_PARAM means that given argument parameters, prdPrt, pwrPtr, or size, are invalid. This means that
they have a null pointer or contain improper values for some member variables.
Description
After encoding a frame, the application must get the bitstream from the encoder by using the stream location and the
maximum size. The application gets the information by calling this function.
3.3.3.5 vpu_EncUpdateBitstreamBuffer()
Prototype
Parameter
handle [input] Encoder handle obtained from vpu_EncOpen()
size [input] Variable specifying the amount of bits retrieved from the bitstream buffer for the current encoder instance
Return Value
RETCODE_SUCCESS Putting new stream data completed successfully
RETCODE_INVALID_HANDLE Given handle for current API function call, handle, is invalid. This return code might be
returned if handle has not been obtained by vpu_EncOpen(), for example a decoder handle, or if handle is of an instance
which has been closed.
RETCODE_INVALID_PARAM Given argument parameter, size, is invalid-it is larger than the value obtained from
vpu_EncGetBitstreamBuffer()
Description
The application must let the encoder know how much bitstream has been transferred from the address obtained from
vpu_EncGetBitstreamBuffer(). By giving the size as an argument, the API automatically handles pointer wrap-around and
updates the read pointer.
3.3.3.6 vpu_EncRegisterFrameBuffer()
Prototype
Parameter
handle [input] is an encoder handle obtained from vpu_EncOpen().
bufArray [input] is a pointer to the first element of an array of FrameBuffer data structure.
frameBufStride [input] is a stride value of the given frame buffers for encoder.
sourceBufStride [input] is a stride value of the source frame buffer for encoder.
pBufInfo [input] is a buffer address for saving extension buffer info. See EncExtBufInfo for details.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 53
API Features
The distance between a pixel in a row and the corresponding pixel in the next row is called a stride. The value of a stride
must be a multiple of 8. The address of the first pixel in the second row does not necessarily coincide with the value next to
the last pixel in the first row. In other words, a stride can have values greater than the picture width in pixels.
The application should not set a stride value smaller than the picture width. For the Y component, the application must
allocate at least a space of size (frame height x stride), and for Cb or Cr components, (frame height/2 x stride/2).
For MJPEG encoding, the address of the frame buffer is not necessary. Only the frameBufStride and frameBufStride values
are necessary.
Return Value
RETCODE_SUCCESS means that registering the frame buffers completed successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This code might be
returned if handle has not been obtained by vpu_EncOpen(), for example a decoder handle, or if handle is of an instance
which has been closed.
RETCODE_WRONG_CALL_SEQUENCE means that the current API function call is invalid considering the allowed
sequences between API functions. In this situation, the application may have called this function before successfully calling
vpu_EncGetInitialInfo(). This function should be called after successfully calling vpu_EncGetInitialInfo().
RETCODE_INVALID_FRAME_BUFFER means that the argument bufArray is invalid or not initialized.
RETCODE_INSUFFICIENT_FRAME_BUFFERS means that the given number of frame buffers, num, is not enough for the
encoder operations of the given handle. num should be greater than or equal to the value of minFrameBufferCount obtained
from vpu_EncGetInitialInfo().
RETCODE_INVALID_STRIDE means that the given argument stride is invalid. This means that it is 0, or is not a multiple
of 8.
RETCODE_CALLED_BEFORE means that the function call is invalid because multiple calls of the current API function for
a given instance are not allowed. The encoder initial information has already been received, so this function call is
meaningless and not allowed.
Description
This function registers frame buffers requested by vpu_EncGetInitialInfo(). The frame buffers pointed to by bufArray are
managed internally within VPU. These include reference frames, reconstructed frames, and so on. The application must not
change the contents of the array of frame buffers during the life time of the instance. num must not be less than
minFrameBufferCount obtained by vpu_EncGetInitialInfo().
3.3.3.7 vpu_EncStartOneFrame()
Prototype
Parameter
handle [input] is an encoder handle obtained from vpu_EncOpen().
param [input] is a pointer to a EncParam type structure which describes the picture encoding parameters for the current
encoder instance.
Return Value
RETCODE_SUCCESS means that encoding a new frame started successfully. This return value does not mean that encoding
a frame completed successfully.
RETCODE_FAILURE means that there is an error in starting one frame encoding operation.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
54 NXP Semiconductors
API Features
RETCODE_INVALID_HANDLE means that a given handle for current API function call is invalid. This code might be
returned if handle has not been obtained by vpu_EncOpen(), for example a decoder handle, or if handle is of an instance
which has been closed.
RETCODE_WRONG_CALL_SEQUENCE means that the current API function call is invalid considering the allowed
sequences between API functions. In this situation, the application may have called this function before successfully calling
vpu_EncRegisterFrameBuffer(). This function should be called after successfully calling
vpu_EncRegisterFrameBuffer().
RETCODE_INVALID_PARAM means that the given argument parameter, param, is invalid. This means that it has a null
pointer, or contains improper values for some member variables.
RETCODE_INVALID_FRAME_BUFFER means that the sourceFrame in the input structure, EncParam, is invalid. This
means that the sourceFrame is not valid even though picture-skip is disabled.
RETCODE_FAILURE_TIMEOUT means that the hardware is already busy with other operation and unavailable for current
API calling.
Description
This function starts by encoding one frame. Returning from this function does not mean the completion of encoding one
frame, only that encoding of one frame successfully initiated. This function should be followed by
vpu_EncGetOutputInfo() with the same encoder handle. Before vpu_EncGetOutputInfo() is called, the application can't
call other API functions except for vpu_IsBusy(), vpu_EncGetBitstreamBuffer(), or vpu_EncUpdateBitstreamBuffer().
3.3.3.8 vpu_EncGetOutputInfo()
Prototype
Parameter
handle [input] is an encoder handle obtained from vpu_EncOpen().
info [output] is a pointer to an EncOutputInfo type structure which describes picture encoding results for the current
encoder instance.
Return Value
RETCODE_SUCCESS means that the output information of current frame encoding received successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This code might be
returned if handle has not been obtained by vpu_EncOpen(), for example a decoder handle, or if handle is of an instance
which has been closed.
RETCODE_WRONG_CALL_SEQUENCE means that the current API function call is invalid considering the allowed
sequences between API functions. In this situation, the application may have called this function before successfully calling
vpu_EncStartOneFrame(). This function should be called after successfully calling vpu_EncStartOneFrame().
RETCODE_INVALID_PARAM means that the given argument parameter, info, is invalid. This means that it has a null
pointer, or contains improper values for some member variables.
Description
This function gives the information about the encoding output such as the picture type, the address and size of the generated
bitstream, the number of generated slices, the end addresses of the slices, and the macroblock bit position information. The
host application should call this function after frame encoding is complete and before starting further processing.
3.3.3.9 vpu_EncGiveCommand()
Prototype
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 55
API Features
RetCode vpu_EncGiveCommand(EncHandle handle, CodecCommand cmd, void *param);
Parameter
handle [input] is an encoder handle obtained from vpu_EncOpen().
param [intput/output] is a pointer to a command-specific data structure which describes picture I/O parameters for the
current encoder instance.
Return Value
RETCODE_INVALID_COMMAND means that the given argument, cmd, is invalid. It is undefined or not allowed in the
current instance.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This code might be
returned if handle has not been obtained by vpu_EncOpen(), for example a decoder handle, or if handle is of an instance
which has been closed.
RETCODE_FRAME_NOT_COMPLETE means that frame encoding operation is not complete, so the given API function
call cannot be performed this time. A frame encoding or decoding operation should be completed by calling
vpu_EncGetOutputInfo() or vpu_DecGetOutputInfo(). Even though the result of the current frame operation is not
necessary, the application should call vpu_EncGetOutputInfo() or vpu_DecGetOutputInfo() to proceed with this function
call.
Description
This function is provided to give the application a certain level of freedom for reconfiguring the encoder operation after
creating an encoder instance. The options which can be changed dynamically while encoding a video sequence as well as
some command-specific return codes are shown in table below.
Table 3. Encoder Commands
Command Description
ENABLE_ROTATION handle is ignored. This command returns RETCODE_SUCCESS.
DISABLE_ROTATION handle is ignored. This command returns RETCODE_SUCCESS.
ENABLE_MIRRORING handle is ignored. This command returns RETCODE_SUCCESS.
DISABLE_MIRRORING handle is ignored. This command returns RETCODE_SUCCESS.
SET_MIRROR_DIRECTION handle is a pointer to MirrorDirection. *param should be one of the following:
• MIRDIR_NONE means no mirroring.
• MIRDIR_VER means vertical mirroring.
• MIRDIR_HOR means horizontal mirroring.
• MIRDIR_HOR_VER means both directions mirroring.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
56 NXP Semiconductors
API Features
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 57
API Features
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
58 NXP Semiconductors
API Features
3.3.4.1 vpu_DecOpen()
Prototype
Parameter
pHandle [output] is a pointer to a DecHandle type variable which specifies each instance for an application.
pop [input] is a pointer to a DecOpenParam type structure which describes the required parameters for creating a new
decoder instance.
Return values:
RETCODE_SUCCESS means that the new decoder instance created successfully.
RETCODE_FAILURE means that the new decoder instance did not open successfully. If there is no free instance available,
this value is returned in the function call.
RETCODE_INVALID_PARAM means that the given argument parameter, pop, is invalid. It has a null pointer or contains
improper values for some member variables.
RETCODE_NOT_INITIALIZED means that VPU is not initialized before calling this function. The application must
initialize the VPU by calling vpu_Init() before calling this function.
Description
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 59
API Features
To decode, the application must open the decoder. By calling this function, the application receives a handle by which the
application can refer to a decoder instance. Since VPU is a multiple instance codec, the application requires this kind of
handle. Once the application receives a handle, the application must pass the handle to all subsequent decoder-related
functions.
3.3.4.2 vpu_DecClose()
Prototype
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
Return Value
RETCODE_SUCCESS means that the current decoder instance closed successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This return code
might be caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
RETCODE_FAILURE_TIMEOUT means that VPU is busy with another task, or there is something wrong with VPU. In
normal operation, the API call should not return a RETCODE_FAILURE_TIMEOUT value. If the application receives this
value, VPU internal function may be corrupted.
RETCODE_FAILURE_TIMEOUT means that hardware is already busy with other operation and unavailable for current API
calling.
Description
When the application is finished decoding a sequence and wants to release this instance for other processing, the application
should close the instance. After completion of this function call, the instance referred to by handle is free. Once the
application closes an instance, the application cannot call any further decoder-specific function with this handle before re-
opening a new decoder instance with the same handle.
3.3.4.3 vpu_DecGetInitialInfo()
Prototype
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
Return Value
RETCODE_SUCCESS means that the required information of the stream data to be decoded is received successfully.
RETCODE_FAILURE means that there is an error in getting the configuration information for the decoder.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This code might be
caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
RETCODE_INVALID_PARAM means that the given argument parameter, info, is invalid. It has a null pointer or contains
improper values for some member variables.
RETCODE_FAILURE_TIMEOUT means that VPU is busy with another task, or there is something wrong with the VPU. In
normal operation, the API call should not return a RETCODE_FAILURE_TIMEOUT value. If the application receives this
value, the VPU internal function may be corrupted.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
60 NXP Semiconductors
API Features
RETCODE_WRONG_CALL_SEQUENCE means that current API function call is invalid considering the allowed sequence
between API functions. In this case, the application might call this function before successfully putting the bitstream into the
buffer data by calling vpu_DecUpdateBitstreamBuffer(). In order to perform this functions call, the bitstream data
including the sequence level header should be transferred into the bitstream buffer before calling vpu_DecGetInitialInfo().
RETCODE_CALLED_BEFORE means that the function call is invalid because multiple calls of the current API function for
a given instance are not allowed. The decoder initial information has been already received, so this function call is
meaningless and not allowed.
RETCODE_FAILURE_TIMEOUT means that the hardware is already busy with other operation and unavailable for current
API calling.
Description
The application must pass the address of a DecInitialInfo structure, where the decoder stores the information such as picture
size, number of necessary frame buffers, and so on. For details, see the definition of the DecInitialInfo data structure in
DecInitialInfo. This function should be called after creating a decoder instance and before starting frame decoding. The
application must provide sufficient amount of bitstream to the decoder by calling vpu_DecUpdateBitstreamBuffer() to
avoid bitstream buffer emptying before this function returns.
If the application cannot ensure to feed enough data for the stream, the application can use the forced escape option using
vpu_DecSetEscSeqInit().
3.3.4.4 vpu_DecSetEscSeqInit()
Prototype
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
Return Value
RETCODE_SUCCESS means that the force escape flag successfully provided to the BIT processor.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This return code
might be caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
Description
This is a special function to provide a way of escaping the VPU hanging during DEQ_SEQ_INIT. When this flag is set to 1
and the stream buffer becomes empty, the VPU automatically terminates the DEC_SEQ_INIT operation. If the target
application ensures that a high layer header syntax is periodically sent through the channel, the application does not need this
option. However, if the target application cannot ensure that a high layer header syntax is periodically sent through the
channel (such as file-play mode). This function is useful to avoid VPU hanging because of crucial errors in the header syntax.
NOTE
This flag is applied to all decoder instances together. Therefore, it is recommended to
reset this flag to 0 after successfully finishing the sequence initialization.
3.3.4.5 vpu_DecGetBitstreamBuffer()
Prototype
PhysicalAddress * paRdPtr,
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 61
API Features
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
paRdPtr [output] is a stream buffer read pointer for the current decoder instance.
paWrPtr [output] is a stream buffer write pointer for the current decoder instance.
size [output] is a variable specifying the available space in the bitstream buffer for the current decoder instance.
Return Value
RETCODE_SUCCESS means that the required information for the decoder stream buffer received successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This return code
might be caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
RETCODE_INVALID_PARAM means that the given argument parameter, paRdPtr, paWrPtr, or size, is invalid. It has a null
pointer or given values for some member variables have improper values.
Description
Before decoding a bitstream, the application must give the bitstream data to the decoder. First, the application must know
where bitstream can be placed and the maximum size. The application receives this information from this function. For VPU,
using the data from this function is more efficient than providing an arbitrary bitstream buffer to the decoder.
NOTE
The given size is the total sum of the free space in the ring buffer. Therefore, when the
application downloads a bitstream of this given size, Wrptr can reach the end of the
stream buffer. In this case, the application should wrap-around Wrptr to the beginning of
the stream buffer and download the remaining bits. If not, the decoder operation can fail.
3.3.4.6 vpu_DecUpdateBitstreamBuffer()
Prototype
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
size [input] is a variable specifying the amount of bits transferred into the bitstream buffer for the current decoder
instance.
Return Value
RETCODE_SUCCESS means that putting new stream data completed successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This code might be
returned if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
RETCODE_INVALID_PARAM means that the given argument parameter, size, is invalid. This means that it is larger than
the value obtained from vpu_DecGetBitstreamBuffer(), or larger than the available space in the bitstream buffer.
RETCODE_FAILURE_TIMEOUT means that VPU is busy with another task, or there is something wrong with VPU. In
normal operation, the API call should not return a RETCODE_FAILURE_TIMEOUT value. If the application receives this
value, the VPU internal function may be corrupted.
Description
The application must let the decoder know how much bitstream has been transferred to the address obtained from
vpu_DecGetBitstreamBuffer(). By giving the size as argument, the API automatically handles pointer wrap-around and
write pointer update.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
62 NXP Semiconductors
API Features
3.3.4.7 vpu_DecRegisterFrameBuffer()
Prototype
DecBufInfo * pBufInfo);
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
bufArray [input] is a pointer to the first element of an array of FrameBuffer for the current decoder instance.
pBufInfo [input] is a pointer to a DecBufInfo type structure which describes the additional work buffers. Only
sliceSaveBuffer is declared by this structure.
Return Value
RETCODE_SUCCESS means that registering the frame buffer information completed successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This return code
might be caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
RETCODE_FAILURE_TIMEOUT means that VPU is busy with another task, or there is something wrong with VPU. In
normal operation, the API call should not return a RETCODE_FAILURE_TIMEOUT value. If the application receives this
value, the VPU internal function may be corrupted.
RETCODE_WRONG_CALL_SEQUENCE means that the current API function call is invalid considering the allowed
sequence between API functions. In this case, the application might have called this function before successfully calling
vpu_DecGetInitialInfo().
RETCODE_INVALID_FRAME_BUFFER means that bufArray is invalid. It is not initialized, or is not valid anymore.
RETCODE_INSUFFICIENT_FRAME_BUFFERS means that the given number of frame buffers, num, is not enough for the
decoder operations of the given handle. num should be greater than or equal to the value requested by
vpu_DecGetInitialInfo().
RETCODE_INVALID_STRIDE means that the given argument stride is invalid. It is smaller than the decoded picture width,
or is not a multiple of 8.
RETCODE_CALLED_BEFORE means that the function call is invalid because multiple calls of the current API function for
a given instance are not allowed. The decoder initial information has been already received, so this function call is
meaningless and not allowed.
Description
This function is used for registering frame buffers with the information from vpu_DecGetInitialInfo(). The frame buffers
pointed to by bufArray are managed internally within VPU. These include reference frames, reconstructed frame, and so on.
The application must not change the contents of the array of frame buffers during the life time of the instance, and num must
not be less than minFrameBufferCount obtained from vpu_DecGetInitialInfo().
3.3.4.8 vpu_DecStartOneFrame()
Prototype
Parameter
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 63
API Features
param [input] is a pointer to a DecParam type structure which describes the decoder options.
Return value
RETCODE_SUCCESS means that decoding a new frame started successfully. This return value does not mean that decoding
a frame completed successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This code might be
caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
RETCODE_WRONG_CALL_SEQUENCE means that the current API function call is invalid considering the allowed
sequence between API functions. The application might have called this function before successfully calling
vpu_DecRegisterFrameBuffer(). This function should be called after successfully calling
vpu_DecRegisterFrameBuffer().
RETCODE_DEBLOCKING_OUTPUT_NOT_SET means that the de-blocking filter option is activated but required de-
blocking output information is not available. If de-blocking filter is enabled for MPEG-4, the application should register the
frame buffer information of de-blocking filtered output using vpu_DecGiveCommand().
RETCODE_FAILURE_TIMEOUT means that hardware is already busy with other operation and unavailable for current API
calling.
Description
This function starts by decoding one frame. Returning from this function does not mean the completion of decoding one
frame, only that encoding of one frame successfully initiated. If this event is signaled, then vpu_DecGetOutputInfo() is
called to get the decoded output information. Every call of this function should be matched with vpu_DecGetOutputInfo()
with the same handle. Before vpu_DecGetOutputInfo() is called, the application cannot call another API function except for
vpu_IsBusy(), vpu_DecGetBitstreamBuffer(), or vpu_DecUpdateBitstreamBuffer().
When the application uses pre-scan mode, there is only a very small chance that the decoder may hang. For the VC-1 SP/MP
decoder, pre-scan mode is not supported.
3.3.4.9 vpu_DecGetOutputInfo()
Prototype
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
info [output] is a pointer to a DecOutputInfo type structure which describes the picture decoding results for the current
decoder instance.
Return Value
RETCODE_SUCCESS means that receiving the output information of current frame completed successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This return code
might be caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
Also, this value is returned when vpu_DecStartOneFrame() is matched with vpu_DecGetOutputInfo() with different
handles.
RETCODE_WRONG_CALL_SEQUENCE means that the current API function call is invalid considering the allowed
sequence between API functions. vpu_DecStartOneFrame() with the same handle might not have been called before calling
this function
RETCODE_INVALID_PARAM means that the given argument parameter, pInfo, is invalid. It has a null pointer or contains
improper values for some member variables.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
64 NXP Semiconductors
API Features
Description
The application received the output information of the decoder by calling this function after the
VPU_INT_PIC_RUN_NAME event is signaled. The output information includes the frame buffer information containing the
reconstructed image. The host application calls this function after the frame decoding is finished and before starting further
processing.
NOTE
If pre-scan mode is enabled, the application should check prescanResult. If the value of
prescanResult = 0, the other output information is meaningless.
vpu_DecStartOneFrame() and vpu_DecGetOutputInfo() must be matched.
3.3.4.10 vpu_DecBitBufferFlush()
Prototype
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
Return Value
RETCODE_SUCCESS means that receiving the output information of the current frame completed successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This return code
might be caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
Also, this value is returned when vpu_DecStartOneFrame() is matched with vpu_DecGetOutputInfo() with different
handles.
RETCODE_WRONG_CALL_SEQUENCE means that the current API function call is invalid considering the allowed
sequence between API functions. vpu_DecRegisterFrameBuffer() with the same handle might not have been called before
calling this function.
Description
The application flushes the bitstream in the decoder bitstream buffer without decoding by calling this function. If the
bitstream buffer is flushed, the read and write pointers of the bitstream buffer of each instance are set to the bitstream buffer
start address.
3.3.4.11 vpu_DecClrDispFlag()
Prototype
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
Return Value
RETCODE_SUCCESS means that receiving the output information of the current frame completed successfully.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This return code
might be caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
Also, this value is returned when vpu_DecStartOneFrame() is matched with vpu_DecGetOutputInfo() with different
handles.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 65
API Features
RETCODE_WRONG_CALL_SEQUENCE means that the current API function call is invalid considering the allowed
sequence between API functions. vpu_DecRegisterFrameBuffer() with the same handle might not have been called before
calling this function.
RETCODE_INVALID_PARAM means that the given argument parameter, index, is invalid. It has improper values.
Description
The application clears the display flag of each frame buffer by calling this function after creating a decoder instance. If the
display flag of the frame buffer is cleared, the frame buffer can be used in the decoding process. Therefore, the application
controls displaying a buffer by clearing the display flag which is set by VPU at every display index output process. This API
is not needed for the STD_MJPG codec.
3.3.4.12 vpu_DecGiveCommand()
Prototype
Parameter
handle [input] is a decoder handle obtained from vpu_DecOpen().
param [input/output] is a pointer to a command-specific data structure which describes picture I/O parameters for the
current decoder instance.
Return Value
RETCODE_INVALID_COMMAND means that the given argument, cmd, is invalid. It is undefined or not allowed in the
current instance.
RETCODE_INVALID_HANDLE means that the given handle for current API function call is invalid. This return code
might be caused if handle has not been obtained by vpu_DecOpen(), or if handle is of an instance which has been closed.
RETCODE_FAILURE_TIMEOUT means that hardware is already busy with other operation and unavailable for current API
calling.
Description
This function is provided to give applications a certain level of freedom for reconfiguring decoder operations after creating a
decoder instance. The options which can be changed dynamically while decoding a video sequence are shown in the table
below.
Table 4. Decoder Commands
Command Description
ENABLE_ROTATION Enables rotation of the post-rotator. param is ignored. Returns RETCODE_SUCCESS.
DISABLE_ROTATION Disables rotation of the post-rotator. param is ignored. Returns RETCODE_SUCCESS.
ENABLE_MIRRORING Enables mirroring of the post-rotator. param is ignored. Returns RETCODE_SUCCESS.
DISABLE_MIRRORING Disables mirroring of the post-rotator. param is ignored. Returns RETCODE_SUCCESS.
SET_MIRROR_DIRECTION Sets the mirror direction of the post-rotator. param is a pointer to MirrorDirection. *param
should be one of the following:
• MIRDIR_NONE-No mirroring
• MIRDIR_VER-Vertical mirroring
• MIRDIR_HOR-Horizontal mirroring
• MIRDIR_HOR_VER-Both directions
Table continues on the next page...
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
66 NXP Semiconductors
API Features
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 67
VPU Control
4 VPU Control
This section explains how VPU works, and provides few example applications that can be used with i.MX 6 VPU API.
This section describes the VPU control scheme based on the API functions and includes some practical programming issues.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
68 NXP Semiconductors
VPU Control
Detailed information about each of these initialization steps and some programming tips are presented in the following
sections.
This version number can have a value from 0.0.0 to 15.15.255. A dedicated command, vpu_GetVersionInfo(), is used for
this version check and is supported after initialization.
In VPU API, the initialization function only receives the start address of this internal buffer as an argument. Therefore, the
total sum of the VPU processing buffer space, starting from the start address, should be dedicated memory space for VPU
and no other process should access this memory space while VPU is enabled. It is highly recommended for the host processor
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 69
VPU Control
to reserve the specified size of the dedicated buffer for the BIT processor and call vpu_Init() with the start address of the
reserved memory. The start addresses of internal buffer partitions, code buffer, work buffer, and parameter buffer are
calculated inside vpu_Init() function and the calculated start addresses are set in the host interface.
In addition to the above sub-buffers, VPU requires buffers for saving SPS/PPS and SLICE RBSP when decoding a H.264
stream. In general, 5 Kbytes is sufficient for the SPS/PPS save buffer and a quarter of the raw YUV image size is sufficient
for the SLICE save buffer. If VPU requires more buffer space to decode a H.264 stream, VPU reports a buffer overflow.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
70 NXP Semiconductors
VPU Control
DEC_SEQ_INIT and DEC_PIC_RUN can cause VPU to stall when the input bitstream is not large enough. Therefore,
enabling the bitstream buffer-empty interrupt with these two interrupts, avoids unnecessary cycle consumptions in the host
application. Each interrupt is easily enabled or disabled by writing 0 or 1 to the corresponding bit field of interrupt enable
register. When an interrupt is signaled, the application checks the source of the interrupt by checking the value of interrupt
reason register. When interrupt signaling is not easily applicable, these interrupts can be replaced by a polling scheme by
reading the BIT processor busy-flag.
NOTE
Only the DEC_PIC_RUN interrupt is used by applications. The other interrupts are used
internally by the API or not supported.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 71
VPU Control
• Intra quantization step-Intra Qstep value is configurable by specifying this value greater than 0. Even if rate control is
enabled, the VPU encoder uses this fixed quantization step for all I-frames. This intra quantization step is re-
configurable after creating an instance dynamically.
• Video standard-specific parameters-Specify standard-specific parameters for each video codec standard such as error
resilience tools in MPEG-4, Annexes in H.263, deblocking, and FMO parameters in H.264, source chroma format and
thumbnail parameters and table coefficients in MJPEG and so on.
Using these options, the application receives a well optimized output for the requirements of the target application. Some
output information options such as sliceReport, mbReport, qpReport, and so on, help application developers satisfy the
constraints for target applications.
For example, for a fixed packet size, an application might need to insert one slice to a certain amount of bits. If the slice size
is given by the number of bits, it does not ensure that the output slice size is smaller than the given size because of the
variable length characteristics of the encoding process. Therefore, the application divides the slice into two packets which
causes an inefficiency in the packetization. To achieve an easy packetization, the application sets the slice size to
(packet_size - N) with a certain margin of N, which allows the output slice size to be less than the packet size. Then the
application easily adds a slice into a packet by referring to the slice boundary information provided by the VPU as encoder
output.
MJPEG can be encoded with various YUV format such as 4:4:4 by setting source format variable. 4:0:0, 4:2:0, 4:2:2
horizontal/vertical and 4:4:4 formats are supported in i.MX 6 MJPEG encoder. i.MX 6 VPU also supports encoding by using
a user-defined Huffman Table and Q matrix. To encode by using a user-defined Huffman Table and Q matrix, the host must
save the coefficients in a pre-defined format and set the pointer to the area.
After creating an encoder instance with these parameters, the application cannot change these parameters. If the application
wants to change any of these basic parameters, it should close this instance and re-create another encoder instance with new
initial parameters. However, the application may need to change some of these initial parameters depending on the target
application environment. Using the dynamic configuration command, the VPU API enables the application to configure part
of these initial parameters dynamically. For details, refer to vpu_EncGiveCommand().
The API function, vpu_EncOpen(), does not require any operations on the VPU side. Instead, it declares all of the internal
parameters used in later stages as well as the bitstream buffer information.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
72 NXP Semiconductors
VPU Control
After providing this information to the VPU, the host processor initiates a picture encoding operation by sending a
ENC_PIC_RUN command to the VPU.
These processes can be performed by calling a single API function, vpu_EncStartOneFrame() with the EncParam structure.
This API function initiates a picture encoding operation. Return from this API does not mean that picture encoding is
completed, only that the encoding operation began successfully.
The quantization step size given to the VPU with ENC_PIC_RUN is only meaningful when the rate control option is
disabled. This additional feature is provided to support application-specific VBR encoder operations.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 73
VPU Control
The forced frame skip option is used when encoding a new picture is not allowed temporarily. Automatic frame skipping in
the VPU rate control is used for limiting the output amount of the bitstream under the given target bit-rate. Also, the forced
frame skip can be used by the application when encoding a picture is problematic under certain external situations, for
example, if the channel condition is temporarily unacceptable and transmitting the encoded stream is impossible. Then the
application can suspend the encoder operation for a while using this forced frame skip option.
The forced I-frame option is used when the remote receiver side reports an error during decoder operation. Even though a
certain error concealment or error robustness scheme might be implemented on the decoder side, the best way to recover
from a decoder error is to send an I-frame. Using this forced I-frame option, the application can achieve error-recovery of the
remote receiver side very effectively.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
74 NXP Semiconductors
VPU Control
Therefore, the application can read out this information directly from the parameter buffer using the base address of each data
structure.
VPU API provides a function for retrieving the output results of the picture encoder, VPU_EncGetOutputInfo(), which has
a output data structure that includes the following information:
• Start address of encoded picture and its size
• Number of slices in the encoded picture
• Slice boundary information in the encoded bitstream
• MB boundary information in the encoded bitstream
• Application-specific information for packetization such as MB Qstep information
Some packetization schemes, such as Real-time Transfer Protocol (RTP), require some internal information of encoded
picture depending on the codec standard.
The slice information is useful for packet-based applications which have limitations of the slice start in the video packet. The
slice information is also useful for implementing slice re-ordering on the application side such as Arbitrary Slice Ordering
(ASO) in the H.264 standard.
VPU API includes a constraint on using the encoder initiation function and the encoder result acquisition. When using VPU
API, the application should always use these two functions as a pair. This means that without calling the result acquisition
function, vpu_EncGetOutputInfo(), the next picture encoding operation is not initiated by calling
vpu_EncStartOneFrame(). Most VPU commands are not allowed unless the application calls VPU_EncGetOutputInfo()
after completion of the picture encoding operation. This constraint is used to protect the encoded results from being
overwritten from another thread by mistake in a multi-instance environment. Therefore, the application should regard the
vpu_EncGetOutputInfo() function as a releasing command of the VPU from the current picture encoding operation.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 75
VPU Control
For decoding, most information is acquired from the input stream, so there are few required parameters for creating a decoder
instance. VPU API function, VPU_DecOpen(), does not require any operations on VPU side but declares all the internal
parameters to be used in later stage as well as the bitstream buffer information.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
76 NXP Semiconductors
VPU Control
The picture size acquired from the bitstream might not be a multiple of 16x16. However, to perform the decoder operation
properly, frame buffer size should be a multiple of 16x16. Therefore, the returned size is modified to be a multiple of 16x16
after a ceiling operation. Using the picture size and the minimum number of frame buffers, the application reserves frame
buffers and provides them to the VPU before starting the picture decoding operation.
The frame buffer delay is an H.264-specific parameter for supporting display reordering. If the application supports display
reordering and reordering requires five additional frame buffers, for example, then the first display output comes out from
decoder after decoding the 6th frame. Theoretically, the maximum delay for display reordering is a 16-frames.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 77
VPU Control
The VPU API provides a function to handle the DEC_SEQ_INIT operations, vpu_DecGetInitialInfo(). Completion of this
function is signaled by a dedicated interrupt or by polling the BusyFlag.
An important issue in SEQ_INIT operation is error-handling because any errors in the high layer header syntaxes cause
serious problems in decoding operations. Generally, many marker bits are added to the header syntaxes to assist error
detection. When header syntaxes included in the stream have crucial errors, or when header syntaxes are not received for a
long time, the VPU can be stuck on this task and no other instances can run on the VPU. Therefore, the VPU API provides a
special function which is used in this situation, called vpu_SetSeqInitEsc(). When this function is called and the stream
buffer is empty, the VPU automatically terminates the SEQ_INIT operation. Then the host application decides whether to
close this instance or retry SEQ_INIT after running a different codec instance. After escaping from this situation, it is highly
recommend to reset the internal ESCAPE flag by calling the vpu_SetSeqInitEsc() function again. This flag affects all the
decoder instances performing a DEC_SEQ_INIT operation.
After providing these parameters to VPU, the application starts the picture decoding operation by sending a DEC_PIC_RUN
command.
The pre-scan option is a special option for scanning the bitstream buffer to check if a full picture stream exists in the stream
buffer. This option allows the application to determine whether the bitstream empty and decoder stalls or not before running
the actual decoder operation. When this option is enabled and there is not a full picture stream in the decoder buffer, the
DEC_PIC_RUN command does not initiate the picture decoding operation and returns immediately. Then, the application
decides whether to retry the picture decoding after feeding more bitstream data or to handle other tasks for a while.
The pre-scan mode is also given as an option for general usage of the pre-scan operation. When this flag is set to 0 and there
is at least one full picture stream in the stream buffer, the decoder operation is automatically initiated. On the contrary, when
this flag is set to 1, the DEC_PIC_RUN command returns immediately with a return code representing whether a full picture
stream exists or not. In this case, no picture decoding is initiated. To run picture decoding in this case, the application resets
this flag to 0 and re-sends the DEC_PIC_RUN command.
When display reordering in H.264 is enabled, the first decoded output is only available after decoding many frames. To avoid
this, a constraint is added to the H.264 decoder that requires the decoder to fill all the reordering display buffers at the first
time of picture decoding. That means, if the frame buffer delay received from the stream header is five, the H.264 decoder
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
78 NXP Semiconductors
VPU Control
should decode six frames at once at the first DEC_PIC_RUN operation. Then, the picture decoding always provides a picture
output to be displayed. In this scenario, the pre-scan might cause problems, because it is designed for the case of one picture
decoding. When display reordering is enabled, it is recommend that the first DEC_PIC_RUN be performed with pre-scan
disabled.
To support display reordering in H.264 mode, a special parameter is used to flush the stored decoder output from the display
reorder buffer without picture decoding. This option is designed for flushing out the decoded picture not yet displayed at the
end of the decoding video sequence. When the display reordering option is enabled and the reordering frame buffer stores
five decoded pictures, the first display output is available after the 6th frame decoding. Therefore, at the end of the stream
decoding, there are five decoded pictures which are not displayed yet even though there is no more available bitstream data to
decode. In this case, the application may ignore these five non-displayed pictures or display them by setting the
dispReorderBuf parameter to 1 and sending the DEC_PIC_RUN command until the VPU returns the decoded picture index
of -1.
VPU API provides an API for handling all these complex operations, vpu_DecStartOneFrame(), which initiates the picture
decoding operation and returns as soon as picture decoding has started on the VPU. Completion of picture decoding is
checked using a different method.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 79
VPU Control
Random access is generally supported with a form of slide-bar in a graphic user interface of a player. For supporting this
random access, an I-(or IDR in H.264) frame search operation is needed because decoding intermediate inter-frames causes
visual artifacts on displayed pictures. As well as I-frame search functionality, random access also requires a buffer-reset
scheme that does not cause unexpected artifacts in the decoded output. The steps of random access for the video decoder are
as follows:
1. Freeze the display and reset the decoder bit-stream buffer
2. Read the bitstream from the new file read pointer and transfer it into the decoder
3. Enable I-Search and run the picture decoding operation
4. If the buffer empty interrupt is signaled, feed more bitstream and wait for decoding completion
5. If decoding completion is detected, read the decoder results and resume display
Resetting the bitstream buffer in Step 1 can be accomplished by calling vpu_DecBitBufferFlush(). Starting the decoder
operation with I-frame search can also be accomplished by calling vpu_DecStartOneFrame() with iframeSearchEnable of
DecParam set to 1. The number of skipped frames specified by skipframeNum of DecParam is given by 1 in random access
operation. When an interrupt of decoder completion or non-busy state of the BIT processor is detected, the I-frame is
searched and decoded.
When the application uses the I-frame search option, the decoder should skip many bits in the decoder stream buffer.
Therefore, the pre-scan option can be meaningless when used simultaneously with the I-search. In the VPU firmware;
therefore, the pre-scan option is automatically disabled and settings for the pre-scan option are ignored. The application
should handle stream buffer filling until the end of the I-search operation. Larger stream units are recommended in this case;
otherwise, too many stream buffer empty interrupts might occur from the VPU side.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
80 NXP Semiconductors
VPU Control
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 81
VPU Control
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
82 NXP Semiconductors
VPU Control
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 83
VPU Control
NOTE
Only packet-based streaming mode with ring-buffer is included in this example
application.
Refer to the readme file for details about the usage of the application example. Decode Stream to Display on LCD, and
Encode Stream from Camera Captured Data, describe the example applications usage for decoding streams to display on a
LCD and encoding streams from camera captured data. These two examples are described in detail to illustrate how proper
frame buffer management between VPU and V4L interface improves performance and avoids memory copy, especially
memory for decoded YUV or captured YUV data.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
84 NXP Semiconductors
VPU Control
• If dering is enabled, the ENABLE_DERING command needs to be given before starting decoding.
• If mirror is enabled, the SET_MIRROR_DIRECTION and ENABLE_MIRRORING commands need to be
given.
• Since there are two extra buffers used for rotation or dering, the SET_ROTATOR_OUTPUT commands need to
be set before each picture decoder.
• Start the picture decoder operation by calling vpu_DecStartOneFrame().
8. Wait for the completion of the picture decoder operation interrupt event by calling vpu_WaitforInt(). vpu_IsBusy() is
used to check if the VPU is busy. If the VPU is not busy, go to the next step. Otherwise, wait again and more bitstream
can be filled to the bitstreamBuffer while waiting.
9. Check the results of the decoder operation using vpu_DecGetOutputInfo(). Go to different case as defined by
outputinfo. For example, -1 in outinfo.indexFrameDisplay indicates that the decoder completed. Values of -2 or -3 in
outinfo.indexFrameDisplay indicates that no picture needs to be displayed. A positive value in
outinfo.indexFrameDisplay indicates the displayed buffer index, and v4l_put_data() can be called to display the image
on the LCD.
In the v4l_put_data() function, IOCTL VIDIOC_QBUF is set to queue the buffer to the v4l module for display. Also,
IOCTL VIDIOC_DQBUF is used to get one buffer that image has been displayed and can be used again for the
decoder. Here, one frame buffer dequeue from the IPU is delayed, then the VPU and IPU operate in an asynchronous
method for performance improvement.
10. After displaying the nth frame buffer, clear the buffer display flag using vpu_DecClrDispFlag(). This function does not
need to be called for the STD_MJPG codec. One frame buffer is delayed for display flag clear, that means, previous
dequeued framebuffer index was cleared by the VIDIOC_DQBUF IOCTL.
11. If there is more bitstream to decode, go to step 7, otherwise go to the next step
12. Terminate the sequence operation by closing the instance using vpu_DecClose(). Make sure
vpu_DecGetOutputInfo() is called for each corresponding vpu_DecStartOneFrame() call before closing the instance
although the last output information may be not useful.
13. Free all memory that was allocate by calling IOFreePhyMem() and IOFreeVirtMem(). v4l_display_close() needs to
be called to free all v4l related resource, including v4l buffers.
14. Call vpu_UnInit() to release the system resources before exit. If there are multi-instances supported in this application,
this function only needs to be called once.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
NXP Semiconductors 85
Revision History
7. Start picture encoder operation picture-by-picture using vpu_EncStartOneFrame(). Pass dequeued v4l buffer address
by calling v4l_get_capture_data() as the encoder source frame before each picture encoder is started.
8. Wait for the completion of picture decoder operation interrupt event calling vpu_WaitforInt(). Use vpu_IsBusy() to
check if the VPU is busy. If the VPU is not busy, go to the next step; otherwise, wait again.
9. After encoding a frame is complete, check the results of encoder operation using vpu_EncGetOutputInfo(). After the
output information is received, call v4l_put_capture_data() to the VIDIOC_QBUF v4l buffer for the next capture
usage.
10. If there are more frames to encode, go to Step 7; otherwise, go to the next step.
11. Terminate the sequence operation by closing the instance using vpu_DecClose(). Make sure
vpu_DecGetOutputInfo() is called for each corresponding vpu_DecStartOneFrame() call before closing the instance
although the last output information may be not useful.
12. Free all allocated memory and v4l resource using IOFreePhyMem() and IOFreeVirtMem(). Call
v4l_stop_capturing() to stop capture.
13. Call vpu_UnInit() to release the system resources. If there are multi-instances supported in this application, this
function only needs to be called once.
5 Revision History
This table provides the revision history.
i.MX VPU Application Programming Interface Linux® Reference Manual, Rev. L4.9.88_2.0.0-ga, 05/2018
86 NXP Semiconductors
How to Reach Us: Information in this document is provided solely to enable system and software implementers to
use NXP products. There are no express or implied copyright licenses granted hereunder to
Home Page:
nxp.com design or fabricate any integrated circuits based on the information in this document. NXP
Web Support: reserves the right to make changes without further notice to any products herein.
nxp.com/support NXP makes no warranty, representation, or guarantee regarding the suitability of its products for
any particular purpose, nor does NXP assume any liability arising out of the application or use
of any product or circuit, and specifically disclaims any and all liability, including without
limitation consequential or incidental damages. “Typical” parameters that may be provided in
NXP data sheets and/or specifications can and do vary in different applications, and actual
performance may vary over time. All operating parameters, including “typicals”, must be
validated for each customer application by customer’s technical experts. NXP does not convey
any license under its patent rights nor the rights of others. NXP sells products pursuant to
standard terms and conditions of sale, which can be found at the following address:
nxp.com/SalesTermsandConditions.
NXP, the NXP logo, Freescale, and the Freescale logo are trademarks of NXP B.V. All other
product or service names are the property of their respective owners.