Freescale / libimxvpuapi

i.MX VPU API Library
GNU Lesser General Public License v2.1
88 stars 54 forks source link

libimxvpuapi - frontend for i.MX hardware video codecs

This library provides an API for using hardware video codecs on i.MX platforms. The API abstracts away platform specific details and allows for using the same code with different hardware video codecs on different i.MX platforms.

The hardware video codec is referred to as the VPU.

Currently, the following platforms are supported (listed with their VPUs):

Not yet supported:

This is the second version of this library. Differences to the older version are described below.

License

This library is licensed under the LGPL v2.1.

Dependencies

libimxvpuapi depends on libimxdmabuffer.

Additional dependencies are specific to the target platform:

Building and installing

This project uses the waf meta build system. To configure , first set the following environment variables to whatever is necessary for cross compilation for your platform:

Then, run:

./waf configure --prefix=PREFIX --imx-platform=IMX_PLATFORM --sysroot-path=SYSROOT

(The aforementioned environment variables are only necessary for this configure call.)

The arguments are as follows:

Valid IMX_PLATFORM values are:

Once configuration is complete, run:

./waf

This builds the library. Finally, to install, run:

./waf install

This will install the headers in $PREFIX/include/imxvpuapi2/, the libraries in $PREFIX/lib/, and generate a pkg-config .pc file, which is placed in $PREFIX/lib/pkgconfig/ .

API documentation

The API is documented in the imxvpuapi/imxvpuapi.h header.

Examples

libimxvpuapi comes with these examples in the example/ directory:

(Other source files in the example/ directory are common utility code used by all examples above.)

Raw frames are read/written as YUV4MPEG2 (y4m) data, and encoded to / decoded from h.264.

Known issues

i.MX6 VPU timeout

If errors like imx_vpu_api_dec_decode() failed: timeout or VPU blocking: timeout are observed, check if the following workarounds for known problems help:

VP6 frames decoded upside down by Hantro G1 decoder

This seems to be a bug in imx-vpu-hantro. A workaround is currently not known.

imx_vpu_api_dec_add_framebuffers_to_pool() fails on Hantro VPUs, logs show "CODEC_ERROR_UNSPECIFIED" This can happen when too many framebuffers are added. One common situation is when libimxvpuapi is used through gstreamer-imx, and downstream has a queue that soaks up too many buffers. Example:

gst-launch-1.0 filesrc location=test-vp8.mkv ! matroskademux ! imxvpudec_vp8 ! queue ! autovideosink

If the video sink takes a while to start, it is possible that the queue in this example keeps storing more and more buffers without releasing them. This causes the VPU to repeatedly request more framebuffers to decode more frames into. Newer versions of imx-vpu-hantro define upper limits to how many framebuffers can be added, and if these limits are exceeded, the error occurs.

It is recommended to not hold on to too many framebuffers at once. Keep it below 16 framebuffers. In the GStreamer case above, it is sufficient to set the max-size-buffers property of the queue there to 1, since a queue that is right before a video sink is meant for decoupling the upstream portion of that pipeline from the video sink. This helps with reducing the likelihood of lost frames. More than 1 buffer in the queue is not needed for this.

DWL and EWL errors

On machines with Hantro based VPUs, "DWL" and "EWL" errors may appear. DWL and EWL are low level layers used by the Hantro drivers. Errors typically happen when certain device nodes are not available. If such errors occur, check for the presence of:

If at least one of these are missing, check the kernel configuration. The ION and/or the dma-heap CMA allocator needs to be enabled. Also check that the Hantro VPU is enabled.

Differences to the older libimxvpuapi version

This is version 2 of libimxvpuapi. Major changes are:

To do