目录

native_avcodec_audiodecoder.h

Overview

Declaration of the audio decoding Native API.

File to include: <multimedia/player_framework/native_avcodec_audiodecoder.h>

Library: libnative_media_adec.so

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitute recommendation The APIs in this module are all deprecated. You can use native_avcodec_audiocodec.h to implement the corresponding functions. For the substitute API of each individual API, refer to the specific API description.

Related module: AudioDecoder

Summary

[h2]Function

Name Description
OH_AVCodec *OH_AudioDecoder_CreateByMime(const char *mime) Creates an audio decoder instance based on the MIME type. This method is recommended in most scenarios. (Deprecated since API 11)
OH_AVCodec *OH_AudioDecoder_CreateByName(const char *name) Creates an audio decoder instance by the decoder name. This API can be used only when the exact decoder name is known. (Deprecated since API 11)
OH_AVErrCode OH_AudioDecoder_Destroy(OH_AVCodec *codec) Clears the internal resources of the decoder and destroys the decoder instance. (Deprecated since API 11)
OH_AVErrCode OH_AudioDecoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData) Sets an asynchronous callback function so that the app can respond to events generated by the audio decoder. This API must be called before Prepare. (Deprecated since API 11)
OH_AVErrCode OH_AudioDecoder_Configure(OH_AVCodec *codec, OH_AVFormat *format) Configures the audio decoder. Typically, the audio description information extracted from the container needs to be configured. This API must be called before Prepare. (Deprecated since API 11)
OH_AVErrCode OH_AudioDecoder_Prepare(OH_AVCodec *codec) Prepares the internal resources of the decoder. The Configure API must be called before this API. (Deprecated since API 11)
OH_AVErrCode OH_AudioDecoder_Start(OH_AVCodec *codec) Starts the decoder. This API is called after Prepare succeeds. After the decoder is started, it will begin reporting OH_AVCodecOnNeedInputData events. (Deprecated since API 11)
OH_AVErrCode OH_AudioDecoder_Stop(OH_AVCodec *codec)

Stops the decoder.

After stopping, you can re-enter the started state by calling Start. However, note that if data has been previously input to the decoder, you need to re-input the decoder data. (Deprecated since API 11)

OH_AVErrCode OH_AudioDecoder_Flush(OH_AVCodec *codec)

Clears the input and output data buffered in the decoder.

After this API is called, all buffer indices previously reported through asynchronous callbacks become invalid. Ensure that you do not access the buffers corresponding to these indices. (Deprecated since API 11)

OH_AVErrCode OH_AudioDecoder_Reset(OH_AVCodec *codec) Resets the decoder. To continue decoding, you need to call the Configure API again to configure the decoder instance. (Deprecated since API 11)
OH_AVFormat *OH_AudioDecoder_GetOutputDescription(OH_AVCodec *codec)

Obtains the description of the decoder output data.

Note that the lifecycle of the OH_AVFormat instance pointed to by the return value must be manually released by the caller. (Deprecated since API 11)

OH_AVErrCode OH_AudioDecoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format)

Sets dynamic parameters for the decoder.

Note: This API can be called only after the decoder is started. In addition, incorrect parameter configuration may cause decoding failures. (Deprecated since API 11)

OH_AVErrCode OH_AudioDecoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr)

Notifies the audio decoder that the input data has been filled into the buffer corresponding to the index.

The OH_AVCodecOnNeedInputData callback reports available input buffers and the corresponding index values. Once a buffer with a specified index is submitted to the audio decoder, this buffer cannot be accessed again until the OH_AVCodecOnNeedInputData callback is received again with the same index.

In addition, for some decoders, specific configuration parameters need to be input to the decoder at the beginning to initialize the decoding process. (Deprecated since API 11)

OH_AVErrCode OH_AudioDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index) Returns the processed output buffer to the decoder. (Deprecated since API 11)
OH_AVErrCode OH_AudioDecoder_IsValid(OH_AVCodec *codec, bool *isValid) Checks whether the current decoder instance is valid. This API can be used for background fault recovery or for detecting the decoder validity when the app recovers from the background. (Deprecated since API 11)

Function Description

[h2]OH_AudioDecoder_CreateByMime()

OH_AVCodec *OH_AudioDecoder_CreateByMime(const char *mime)

Description

Creates an audio decoder instance based on the MIME type. This method is recommended for most scenarios.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_CreateByMime

Parameters

Name Description
const char *mime MIME type description string. See AVCODEC_MIMETYPE.

Returns

Type Description
OH_AVCodec * Pointer to the OH_AVCodec instance.

[h2]OH_AudioDecoder_CreateByName()

OH_AVCodec *OH_AudioDecoder_CreateByName(const char *name)

Description

Creates an audio decoder instance by the audio decoder name. This API can be called only when the exact decoder name is known.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_CreateByName

Parameters

Name Description
const char *name Audio decoder name.

Returns

Type Description
OH_AVCodec * Returns a pointer to an OH_AVCodec instance.

[h2]OH_AudioDecoder_Destroy()

OH_AVErrCode OH_AudioDecoder_Destroy(OH_AVCodec *codec)

Description

Clears the internal resources of the decoder and destroys the decoder instance.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_Destroy

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.

Returns

Type Description
OH_AVErrCode AV_ERR_OK if the operation is successful; otherwise, a specific error code.

[h2]OH_AudioDecoder_SetCallback()

OH_AVErrCode OH_AudioDecoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData)

Description

Sets an asynchronous callback function so that the app can respond to events generated by the audio decoder. This API must be called before Prepare.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_RegisterCallback

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.
OH_AVCodecAsyncCallback callback Set of all callback functions.
void *userData User-specific data.

Returns

Type Description
OH_AVErrCode If the operation is successful, AV_ERR_OK is returned; otherwise, a specific error code is returned.

[h2]OH_AudioDecoder_Configure()

OH_AVErrCode OH_AudioDecoder_Configure(OH_AVCodec *codec, OH_AVFormat *format)

Description

To configure the audio decoder, you usually need to configure the audio description information extracted from the container. This API must be called before calling Prepare.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_Configure

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.
OH_AVFormat *format Pointer to OH_AVFormat, which describes the audio track to decode.

Returns

Type Description
OH_AVErrCode If the operation is successful, AV_ERR_OK is returned; otherwise, a specific error code is returned.

[h2]OH_AudioDecoder_Prepare()

OH_AVErrCode OH_AudioDecoder_Prepare(OH_AVCodec *codec)

Description

Prepares internal resources of the decoder. The Configure API must be called before this API.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_Prepare

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.

Returns

Type Description
OH_AVErrCode AV_ERR_OK is returned if the operation is successful; otherwise, a specific error code is returned.

[h2]OH_AudioDecoder_Start()

OH_AVErrCode OH_AudioDecoder_Start(OH_AVCodec *codec)

Description

Starts the decoder. This API can be called only after Prepare is successful. After being started, the decoder begins to report the OH_AVCodecOnNeedInputData event.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_Start

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.

Returns

Type Description
OH_AVErrCode AV_ERR_OK if the operation is successful; otherwise, a specific error code.

[h2]OH_AudioDecoder_Stop()

OH_AVErrCode OH_AudioDecoder_Stop(OH_AVCodec *codec)

Description

Stops the decoder.

After stopping, you can re-enter the started state by calling Start. However, note that if the decoder has previously received input data, you need to input the decoder data again.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_Stop

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.

Returns

Type Description
OH_AVErrCode AV_ERR_OK is returned if the operation is successful; otherwise, a specific error code is returned.

[h2]OH_AudioDecoder_Flush()

OH_AVErrCode OH_AudioDecoder_Flush(OH_AVCodec *codec)

Description

Clears the input and output data cached in the decoder.

After this API is called, all buffer indices previously reported through asynchronous callbacks become invalid. Ensure that you do not access the buffers corresponding to these indices.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_Flush

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.

Returns

Type Description
OH_AVErrCode Returns AV_ERR_OK if the operation is successful; returns a specific error code otherwise.

[h2]OH_AudioDecoder_Reset()

OH_AVErrCode OH_AudioDecoder_Reset(OH_AVCodec *codec)

Description

Resets the decoder. To continue decoding, you need to call the Configure API again to configure the decoder instance.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_Reset

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.

Returns

Type Description
OH_AVErrCode If the operation is successful, AV_ERR_OK is returned; otherwise, a specific error code is returned.

[h2]OH_AudioDecoder_GetOutputDescription()

OH_AVFormat *OH_AudioDecoder_GetOutputDescription(OH_AVCodec *codec)

Description

Obtains the description of the decoder output data.

Note: The lifecycle of the OH_AVFormat instance pointed to by the return value must be manually released by the caller.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_GetOutputDescription

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.

Returns

Type Description
OH_AVFormat * Pointer to the OH_AVFormat handle.

[h2]OH_AudioDecoder_SetParameter()

OH_AVErrCode OH_AudioDecoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format)

Description

Configures dynamic parameters of the decoder.

Note: This API can be called only after the decoder is started. In addition, incorrect parameter configuration may cause decoding failures.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_SetParameter

Parameters

Name Description
OH_AVCodec *codec Pointer to an OH_AVCodec instance.
OH_AVFormat *format Pointer to an OH_AVFormat handle.

Returns

Type Description
OH_AVErrCode If the operation is successful, AV_ERR_OK is returned; otherwise, a specific error code is returned.

[h2]OH_AudioDecoder_PushInputData()

OH_AVErrCode OH_AudioDecoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr)

Description

Notifies the audio decoder that the input data has been filled into the buffer corresponding to the specified index.

The OH_AVCodecOnNeedInputData callback reports the available input buffers and the corresponding index values. Once a buffer with the specified index is submitted to the audio decoder, this buffer cannot be accessed again until the OH_AVCodecOnNeedInputData callback is received again with the same index.

In addition, for some decoders, specific configuration parameters need to be input to the decoder at the beginning to initialize the decoding process.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_PushInputBuffer

Parameters

Name Description
OH_AVCodec *codec Pointer to the OH_AVCodec instance.
uint32_t index Index of the input buffer.
OH_AVCodecBufferAttr attr Describes the information about the data contained in the buffer.

Returns

Type Description
OH_AVErrCode If the execution is successful, AV_ERR_OK is returned; otherwise, a specific error code is returned.

[h2]OH_AudioDecoder_FreeOutputData()

OH_AVErrCode OH_AudioDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index)

Description

Frees a processed output buffer and returns it to the decoder.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 9

Deprecated from: 11

Substitutes: OH_AudioCodec_FreeOutputBuffer

Parameters

Name Description
OH_AVCodec *codec Pointer to an OH_AVCodec instance.
uint32_t index Index of the output buffer.

Returns

Type Description
OH_AVErrCode If the execution is successful, AV_ERR_OK is returned; otherwise, a specific error code is returned.

[h2]OH_AudioDecoder_IsValid()

OH_AVErrCode OH_AudioDecoder_IsValid(OH_AVCodec *codec, bool *isValid)

Description

Checks whether the current decoder instance is valid. It can be used for background fault recovery or for detecting the validity of the decoder when the app recovers from the background.

System capability: SystemCapability.Multimedia.Media.AudioDecoder

Since: 10

Deprecated from: 11

Substitutes: OH_AudioCodec_IsValid

Parameters

Name Description
OH_AVCodec *codec Pointer to an OH_AVCodec instance.
bool *isValid Pointer to a boolean value. The value true indicates that the decoder instance is valid, and false indicates that the decoder instance is invalid.

Returns

Type Description
OH_AVErrCode If the operation is successful, AV_ERR_OK is returned; otherwise, a specific error code is returned.