Decoding Procedures

Example 1 shows the pseudo code of the decoding procedure. The following describes a few key points:

·        The application can use the MFXVideoDECODE_DecodeHeader function to retrieve decoding initialization parameters from the bitstream. This step is optional if such parameters are retrievable from other sources such as an audio/video splitter.

·        The application uses the MFXVideoDECODE_QueryIOSurf function to obtain the number of working frame surfaces required to reorder output frames.

·        The application calls the MFXVideoDECODE_DecodeFrameAsync function for a decoding operation, with the bitstream buffer (bits), and an unlocked working frame surface (work) as input parameters. If decoding output is not available, the function returns a status code requesting additional bitstream input or working frame surfaces as follows:

MFX_ERR_MORE_DATA: The function needs additional bitstream input. The existing buffer contains less than a frame worth of bitstream data.

MFX_ERR_MORE_SURFACE: The function needs one more frame surface to produce any output.

MFX_ERR_REALLOC_SURFACE: Dynamic resolution change case - the function needs bigger working frame surface (work).

·        Upon successful decoding, the MFXVideoDECODE_DecodeFrameAsync function returns MFX_ERR_NONE. However, the decoded frame data (identified by the disp pointer) is not yet available because the MFXVideoDECODE_DecodeFrameAsync function is asynchronous. The application must use the MFXVideoCORE_SyncOperation function to synchronize the decoding operation before retrieving the decoded frame data.

·        At the end of the bitstream, the application continuously calls the MFXVideoDECODE_DecodeFrameAsync function with a NULL bitstream pointer to drain any remaining frames cached within the SDK decoder, until the function returns MFX_ERR_MORE_DATA.

 

The application can use the following procedure for bitstream reposition during decoding:

1.    Use the MFXVideoDECODE_Reset function to reset the SDK decoder.

2.    Optionally, if the application maintains a sequence header that decodes correctly the bitstream at the new position, the application may insert the sequence header to the bitstream buffer.

3.    Append the bitstream from the new location to the bitstream buffer.

4.    Resume the decoding procedure. If the sequence header is not inserted in the above steps, the SDK decoder searches for a new sequence header before starting decoding.

 

 

Text Box: MFXVideoDECODE_DecodeHeader(session, bitstream, &init_param); MFXVideoDECODE_QueryIOSurf(session, &init_param, &request); allocate_pool_of_frame_surfaces(request.NumFrameSuggested); MFXVideoDECODE_Init(session, &init_param); sts=MFX_ERR_MORE_DATA; for (;;) { if (sts==MFX_ERR_MORE_DATA && !end_of_stream()) append_more_bitstream(bitstream); find_unlocked_surface_from_the_pool(&work); bits=(end_of_stream())?NULL:bitstream; sts=MFXVideoDECODE_DecodeFrameAsync(session,bits,work,&disp,&syncp); if (sts==MFX_ERR_MORE_SURFACE) continue; if (end_of_bitstream() && sts==MFX_ERR_MORE_DATA) break; if (sts==MFX_ERR_REALLOC_SURFACE) { MFXVideoDECODE_GetVideoParam(session, &param); realloc_surface(work, param.mfx.FrameInfo); continue; } … // other error handling if (sts==MFX_ERR_NONE) { MFXVideoCORE_SyncOperation(session, syncp, INFINITE); do_something_with_decoded_frame(disp); } } MFXVideoDECODE_Close(); free_pool_of_frame_surfaces();

Example 1: Decoding Pseudo Code

The bitstream can contain multiple sequence headers. The SDK function returns a status code to indicate when a new sequence header is parsed.

The MFXVideoDECODE_DecodeFrameAsync function returns MFX_WRN_VIDEO_PARAM_CHANGED if the SDK decoder parsed a new sequence header in the bitstream and decoding can continue with existing frame buffers. The application can optionally retrieve new video parameters by calling MFXVideoDECODE_GetVideoParam.

The MFXVideoDECODE_DecodeFrameAsync function returns MFX_ERR_INCOMPATIBLE_VIDEO_PARAM if the decoder parsed a new sequence header in the bitstream and decoding cannot continue without reallocating frame buffers. The bitstream pointer moves to the first bit of the new sequence header. The application must do the following:

1.    Retrieve any remaining frames by calling MFXVideoDECODE_DecodeFrameAsync with a NULL input bitstream pointer until the function returns MFX_ERR_MORE_DATA. This step is not necessary if the application plans to discard any remaining frames.

2.    De-initialize the decoder by calling the MFXVideoDECODE_Close function, and restart the decoding procedure from the new bitstream position.

 

For more complete information about compiler optimizations, see our Optimization Notice.