# VideoDecoder ## Overview The VideoDecoder module provides the functions for video decoding. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 ## Summary ### Files | Name| Description| | -------- | -------- | | [native_avcodec_videodecoder.h](native__avcodec__videodecoder_8h.md) | Declares the native APIs used for video decoding.| ### Functions | Name| Description| | -------- | -------- | | OH_AVCodec \* [OH_VideoDecoder_CreateByMime](#oh_videodecoder_createbymime) (const char \*mime) | Creates a video decoder instance based on an MIME type.| | OH_AVCodec \* [OH_VideoDecoder_CreateByName](#oh_videodecoder_createbyname) (const char \*name) | Creates a video decoder instance based on a decoder name.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_Destroy](#oh_videodecoder_destroy) (OH_AVCodec \*codec) | Clears the internal resources of a video decoder and destroys the decoder instance.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_SetCallback](#oh_videodecoder_setcallback) (OH_AVCodec \*codec, [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md) callback, void \*userData) | Sets an asynchronous callback so that your application can respond to events generated by a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_RegisterCallback](#oh_videodecoder_registercallback) (OH_AVCodec \*codec, [OH_AVCodecCallback](_o_h___a_v_codec_callback.md) callback, void \*userData) | Registers an asynchronous callback so that your application can respond to events generated by a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_SetSurface](#oh_videodecoder_setsurface) (OH_AVCodec \*codec, OHNativeWindow \*window) | Sets an output surface for a video decoder. This function must be called prior to **Prepare**.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_Configure](#oh_videodecoder_configure) (OH_AVCodec \*codec, OH_AVFormat \*format) | Configures a video decoder. Typically, you need to configure the video track description information that can be extracted from **OH_AVSource**.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_Prepare](#oh_videodecoder_prepare) (OH_AVCodec \*codec) | Prepares internal resources for a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_Start](#oh_videodecoder_start) (OH_AVCodec \*codec) | Starts a video decoder. This function can be called only after the decoder is prepared.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_Stop](#oh_videodecoder_stop) (OH_AVCodec \*codec) | Stops a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_Flush](#oh_videodecoder_flush) (OH_AVCodec \*codec) | Clears the input and output data in the internal buffer of a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_Reset](#oh_videodecoder_reset) (OH_AVCodec \*codec) | Resets a video decoder.| | OH_AVFormat \* [OH_VideoDecoder_GetOutputDescription](#oh_videodecoder_getoutputdescription) (OH_AVCodec \*codec) | Obtains the description information about the output data of a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_SetParameter](#oh_videodecoder_setparameter) (OH_AVCodec \*codec, OH_AVFormat \*format) | Sets dynamic parameters for a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_PushInputData](#oh_videodecoder_pushinputdata) (OH_AVCodec \*codec, uint32_t index, [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md) attr) | Pushes the input buffer filled with data to a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_RenderOutputData](#oh_videodecoder_renderoutputdata) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of a video decoder and instructs the decoder to render the decoded data in the buffer on the output surface.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_FreeOutputData](#oh_videodecoder_freeoutputdata) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_PushInputBuffer](#oh_videodecoder_pushinputbuffer) (OH_AVCodec \*codec, uint32_t index) | Pushes the input buffer filled with data to a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_RenderOutputBuffer](#oh_videodecoder_renderoutputbuffer) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of a video decoder and instructs the decoder to render the decoded data in the buffer on the output surface.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_FreeOutputBuffer](#oh_videodecoder_freeoutputbuffer) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of a video decoder.| | [OH_AVErrCode](_core.md#oh_averrcode)[OH_VideoDecoder_IsValid](#oh_videodecoder_isvalid) (OH_AVCodec \*codec, bool \*isValid) | Checks whether a video decoder instance is valid.| ## Function Description ### OH_VideoDecoder_Configure() ``` OH_AVErrCode OH_VideoDecoder_Configure (OH_AVCodec *codec, OH_AVFormat *format ) ``` **Description** Configures a video decoder. Typically, you need to configure the video track description information that can be extracted from **OH_AVSource**. This function must be called prior to **Prepare**. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | format | Pointer to an **OH_AVFormat** instance, which provides the description information about the video track to be decoded.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_CreateByMime() ``` OH_AVCodec* OH_VideoDecoder_CreateByMime (const char *mime) ``` **Description** Creates a video decoder instance based on a MIME type. This function is recommended in most cases. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | mime | Pointer to a string that describes the MIME type. For details, see [AVCODEC_MIMETYPE](_codec_base.md#variables).| **Returns** Pointer to the video decoder instance. ### OH_VideoDecoder_CreateByName() ``` OH_AVCodec* OH_VideoDecoder_CreateByName (const char *name) ``` **Description** Creates a video decoder instance based on a decoder name. To use this function, you must know the exact name of the decoder. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | name | Pointer to a video decoder name.| **Returns** Pointer to the video decoder instance. ### OH_VideoDecoder_Destroy() ``` OH_AVErrCode OH_VideoDecoder_Destroy (OH_AVCodec *codec) ``` **Description** Clears the internal resources of a video decoder and destroys the decoder instance. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_Flush() ``` OH_AVErrCode OH_VideoDecoder_Flush (OH_AVCodec *codec) ``` **Description** Clears the input and output data in the internal buffer of a video decoder. This function invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this function, ensure that the buffers with the specified indexes are no longer required. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_FreeOutputBuffer() ``` OH_AVErrCode OH_VideoDecoder_FreeOutputBuffer (OH_AVCodec *codec, uint32_t index ) ``` **Description** Frees an output buffer of a video decoder. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 11 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | index | Index of an output buffer.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_FreeOutputData() ``` OH_AVErrCode OH_VideoDecoder_FreeOutputData (OH_AVCodec *codec, uint32_t index ) ``` **Description** Frees an output buffer of a video decoder. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Deprecated version**: 11 **Substitute**: [OH_VideoDecoder_FreeOutputBuffer](#oh_videodecoder_freeoutputbuffer) **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | index | Index of an output buffer.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_GetOutputDescription() ``` OH_AVFormat* OH_VideoDecoder_GetOutputDescription (OH_AVCodec *codec) ``` **Description** Obtains the description information about the output data of a video decoder. The caller must manually release the **OH_AVFormat** instance in the return value. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| **Returns** Returns the pointer to an **OH_AVFormat** instance. ### OH_VideoDecoder_IsValid() ``` OH_AVErrCode OH_VideoDecoder_IsValid (OH_AVCodec *codec, bool *isValid ) ``` **Description** Checks whether a video decoder instance is valid. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 10 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | isValid | Output parameter. Pointer to an instance of the Boolean type. The value **true** means that the decoder instance is valid and **false** means the opposite.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_Prepare() ``` OH_AVErrCode OH_VideoDecoder_Prepare (OH_AVCodec *codec) ``` **Description** Prepares internal resources for a video decoder. This function must be called after **Configure**. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_PushInputBuffer() ``` OH_AVErrCode OH_VideoDecoder_PushInputBuffer (OH_AVCodec *codec, uint32_t index ) ``` **Description** Pushes the input buffer filled with data to a video decoder. The input callback reports the available input buffer and the index. For details, see [OH_AVCodecOnNeedInputBuffer](_codec_base.md#oh_avcodeconneedinputbuffer). After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the input callback. In addition, some decoders require the input of codec-specific data, such as PPS/SPS data in H.264 format, to initialize the decoding process. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 11 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | index | Index of an input buffer.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_PushInputData() ``` OH_AVErrCode OH_VideoDecoder_PushInputData (OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr ) ``` **Description** Pushes the input buffer filled with data to a video decoder. The input callback reports the available input buffer and the index. For details, see [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata). After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the input callback. In addition, some decoders require the input of codec-specific data, such as PPS/SPS data in H.264 format, to initialize the decoding process. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Deprecated version**: 11 **Substitute**: [OH_VideoDecoder_PushInputBuffer](#oh_videodecoder_pushinputbuffer) **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | index | Index of an input buffer.| | attr | Description information about the data in the buffer.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_RegisterCallback() ``` OH_AVErrCode OH_VideoDecoder_RegisterCallback (OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData ) ``` **Description** Registers an asynchronous callback so that your application can respond to events generated by a video decoder. This function must be called prior to **Prepare**. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 11 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | callback | Callback function to set. For details, see [OH_AVCodecCallback](_o_h___a_v_codec_callback.md).| | userData | User-specific data.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_RenderOutputBuffer() ``` OH_AVErrCode OH_VideoDecoder_RenderOutputBuffer (OH_AVCodec *codec, uint32_t index ) ``` **Description** Frees an output buffer of a video decoder and instructs the decoder to render the decoded data in the buffer on the output surface. If no output surface is configured, calling this function only frees the output buffer. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 11 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | index | Index of an output buffer.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_RenderOutputData() ``` OH_AVErrCode OH_VideoDecoder_RenderOutputData (OH_AVCodec *codec, uint32_t index ) ``` **Description** Frees an output buffer of a video decoder and instructs the decoder to render the decoded data in the buffer on the output surface. If no output surface is configured, calling this function only frees the output buffer. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Deprecated version**: 11 **Substitute**: [OH_VideoDecoder_RenderOutputBuffer](#oh_videodecoder_renderoutputbuffer) **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | index | Index of an output buffer.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_Reset() ``` OH_AVErrCode OH_VideoDecoder_Reset (OH_AVCodec *codec) ``` **Description** Resets a video decoder. To continue decoding, you must call **Configure** to configure the decoder again. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_SetCallback() ``` OH_AVErrCode OH_VideoDecoder_SetCallback (OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData ) ``` **Description** Sets an asynchronous callback so that your application can respond to events generated by a video decoder. This function must be called prior to **Prepare**. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Deprecated version**: 11 **Substitute**: [OH_VideoDecoder_RegisterCallback](#oh_videodecoder_registercallback) **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | callback | Callback function to set. For details, see [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md).| | userData | User-specific data.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_SetParameter() ``` OH_AVErrCode OH_VideoDecoder_SetParameter (OH_AVCodec *codec, OH_AVFormat *format ) ``` **Description** Sets dynamic parameters for a video decoder. This function can be called only after the decoder is started. Incorrect parameter settings may cause decoding failure. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | format | Pointer to an **OH_AVFormat** instance.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_SetSurface() ``` OH_AVErrCode OH_VideoDecoder_SetSurface (OH_AVCodec *codec, OHNativeWindow *window ) ``` **Description** Sets an output surface for a video decoder. This function must be called prior to **Prepare**. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| | window | Pointer to an **OHNativeWindow** instance.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_Start() ``` OH_AVErrCode OH_VideoDecoder_Start (OH_AVCodec *codec) ``` **Description** Starts a video decoder. This function can be called only after the decoder is prepared. After being started, the decoder starts to report the registered event. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. ### OH_VideoDecoder_Stop() ``` OH_AVErrCode OH_VideoDecoder_Stop (OH_AVCodec *codec) ``` **Description** Stops a video decoder. After the encoder is stopped, you can call **Start** to start it again. If you have passed codec-specific data in the previous **Start** for the decoder, you must pass it again. **System capability**: SystemCapability.Multimedia.Media.VideoDecoder **Since**: 9 **Parameters** | Name| Description| | -------- | -------- | | codec | Pointer to the video decorder instance.| **Returns** Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise.