The SDK takes care of all memory and synchronization related operations in VA API. However, in some cases the application may need to extend the SDK functionality by working directly with VA API for Linux*. For example, to implement customized external allocator or USER functions (also known as “plug-in”). This chapter describes some basic memory management and synchronization techniques.
To create VA surface pool the application should call vaCreateSurfaces as it is shown in Example 16.
Example 16: Creation of VA surfaces
To destroy surface pool the application should call vaDestroySurfaces as it is shown in Example 17.
Example 17: Destroying of VA surfaces
If the application works with hardware acceleration through the SDK then it can access surface data immediately after successful completion of MFXVideoCORE_SyncOperation call. If the application works with hardware acceleration directly then it has to check surface status before accessing data in video memory. This check can be done asynchronously by calling vaQuerySurfaceStatus function or synchronously by vaSyncSurface function.
After successful synchronization the application can access surface data. It is performed in two steps. At the first step VAImage is created from surface and at the second step image buffer is mapped to system memory. After mapping VAImage.offsets array holds offsets to each color plain in mapped buffer and VAImage.pitches array holds color plain pitches, in bytes. For packed data formats, only first entries in these arrays are valid. Example 18 shows how to access data in NV12 surface.
Example 18: Accessing data in VA surface
After processing data in VA surface the application should release resources allocated for mapped buffer and VAImage object. Example 19 shows how to do it.
Example 19: unmapping buffer and destroying VAImage
In some cases, for example, to retrieve encoded bitstream from video memory, the application has to use VABuffer to store data. Example 20 shows how to create, use and then destroy VA buffer. Note, that vaMapBuffer function returns pointers to different objects depending on mapped buffer type. It is plain data buffer for VAImage and VACodedBufferSegment structure for encoded bitstream. The application cannot use VABuffer for synchronization and in case of encoding it is recommended to synchronize by input VA surface as described above.
Example 20: Working with encoded bitstream buffer