Intel Media SDK is a framework for developing media applications. It provides the hardware implementations for some of the founding algorithms for Media - encode, decode, video processing; and also exposes a numbers of relevant parameters that can be used to tune the application to one's need. The hardware implementation is the recommended implementation to use, but sometimes, the implementation can default to software due to the lack of underlying hardware. To leverage the full potential of the SDK, the developer has to ensure the features he wants (achieved by specifying the parameters) are supported by the underlying hardware.
If you would the application to be portable and easily deployable across many platform, it is not practical to check the compatibility of each system and customize the media application accordingly. This where the QUERY functionality of Media SDK comes into picture. The developer can use thus functionality to not only check the capabilities of the underlying system, it can also suggest the best possible configuration one can achieve using the underlying system. In the following table, I will list some of the commonly used Query functions and their usage.
All the above-mentioned query functions greatly aid in portability and programmability. The first two (QueryImpl and QueryVersion) can help you choose the best possible implementation for the underlying hardware. The other query functions (Query and QueryIOSurf) are focused on the pipeline being used, and help with feature-check and ensuring enough resources are allocated for the requested features.
MFXQueryIMPL(session, &impl); // returns the actual implementation of the session MFXQueryVersion(session, &version); //returns the version of the SDK implementation sts = mfxVPP.Query(&Params_in, &Params_out); //*Params_in points to the requested out features, *Param_out points to the features that can be best achieved. If sts is MFX_ERR_NONE, it means requested features can be met. If the status returns warnings for incompatible video parameters, the *param_out is filled with best achievable parameters.
Query for Surfaces
mfxFrameAllocRequest Request; memset(&Request, 0, sizeof(Request)); sts = QueryIOSurf(session, &Params, &Request); //Returns number of (minimum,maximum and suggested) surfaces needed for the specified pipeline and parameters. mfxU16 numSurfaces = Request.NumFrameSuggested;
Some optimization tips:
The hardware implementation is always faster than the software counterpart. You can achieve the best performance with hardware by using the video memory which is local to the hardware (GPU or fixed-function logic). When defaulting to software implementation, make sure you use the system memory and not the video memory. You can do this by adding a simple check to the output of the QueryIMPL function, and conditionally allocating the surfaces based on the output. For example,
MFXQueryIMPL(session, &impl); // returns the actual implementation of the session if (impl == MFX_IMPL_SOFTWARE) m_mfxEncParams.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY; else m_mfxEncParams.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
For surface allocation, refer to the tutorials such as simple_3_encode_vmem and surface_3_encode. The former uses video memory, while the latter uses system memory.