Visible to Intel only — GUID: GUID-6690924E-D246-47A3-8FC6-D1F0E95F0656
Visible to Intel only — GUID: GUID-6690924E-D246-47A3-8FC6-D1F0E95F0656
oneVPL Code Sample
oneVPL provides rich code samples to show how to use the oneVPL API. The code samples are included in the release package and are also available from the oneAPI-samples repository on GitHub*.
For example, the hello-decode sample shows a simple decode operation of HEVC input streams and demonstrates the basic steps in the oneVPL programming model.
The sample can be broken down into the following key steps in the code:
Initialize oneVPL session with dispatcher:
mfxLoader loader = NULL; mfxConfig cfg = NULL; loader = MFXLoad(); cfg = MFXCreateConfig(loader); ImplValue.Type = MFX_VARIANT_TYPE_U32; ImplValue.Data.U32 = MFX_CODEC_HEVC; sts = MFXSetConfigFilterProperty(cfg, (mfxU8*)"mfxImplDescription.mfxDecoderDescription.decoder.CodecID", ImplValue); sts = MFXCreateSession(loader, 0, &session);
Here, MFXCreateConfig() creates the dispatcher internal configuration. Once the dispatcher is configured, the application uses MFXSetConfigFilterProperty() to set its requirements including codec ID and accelerator preference. After the application sets the desired requirements, the session is created.
Start the decoding loop:
while(is_stillgoing) { sts = MFXVideoDECODE_DecodeFrameAsync(session, (isdraining) ? NULL : &bitstream, NULL, &pmfxOutSurface, &syncp); ...... }
After preparing the input stream, the stream has the required context and the decoding loop is started immediately.
MFXVideoDECODE_DecodeFrameAsync() takes the bit stream as the second parameter. When the bit stream becomes NULL, oneVPL drains the remaining frames from the input and completes the operation. The third parameter is the working memory; the NULL input shown in the example means the application wants oneVPL to manage working memory.
Evaluate results of a decoding call:
while(is_stillgoing) { sts = MFXVideoDECODE_DecodeFrameAsync(...); switch(sts) { case MFX_ERR_MORE_DATA: ...... ReadEncodedStream(bitstream, codec_id, source); ...... } break; case MFX_ERR_NONE: do { sts = pmfxOutSurface->FrameInterface->Synchronize(pmfxOutSurface, WAIT_100_MILLSECONDS); if( MFX_ERR_NONE == sts ) { sts = pmfxOutSurface->FrameInterface->Map(pmfxOutSurface, MFX_MAP_READ); WriteRawFrame(pmfxOutSurface, sink); sts = pmfxOutSurface->FrameInterface->Unmap(pmfxOutSurface); sts = pmfxOutSurface->FrameInterface->Release(pmfxOutSurface); framenum++; } } while( sts == MFX_WRN_IN_EXECUTION ); break; default: break; }
For each MFXVideoDECODE_DecodeFrameAsync() call, the application continues to read the input bit stream until oneVPL completes a new frame with MFX_ERR_NONE, indicating the function successfully completed its operation. For each new frame, the application waits until the output memory (surface) is ready and then outputs and releases the output frame.
The Map() call is used to map the memory from the discrete graphic memory space to the host memory space.
Exit and do cleanup:
MFXUnload(loader); free(bitstream.Data); fclose(sink); fclose(source);
Finally, MFXUnload() is called to reclaim the resources from oneVPL. This is the only call that the application must execute to reclaim the oneVPL library resources.