/*
 * Copyright (C) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @addtogroup AudioDecoder
 * @{
 *
 * @brief The AudioDecoder module provides functions for audio decoding.
 *
 * @syscap SystemCapability.Multimedia.Media.AudioDecoder
 * @deprecated since 11
 * @since 9
 */

/**
 * @file native_avcodec_audiodecoder.h
 *
 * @brief The file declares the native APIs used for audio decoding.
 *
 * @kit AVCodecKit
 * @library libnative_media_adec.so
 * @syscap SystemCapability.Multimedia.Media.AudioDecoder
 * @deprecated since 11
 * @since 9
 */

#ifndef NATIVE_AVCODEC_AUDIODECODER_H
#define NATIVE_AVCODEC_AUDIODECODER_H

#include <stdint.h>
#include <stdio.h>
#include "native_avcodec_base.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Creates an audio decoder instance based on a MIME type. This function is recommended in most cases.
 *
 * @param mime Pointer to a string that describes the MIME type. For details, see {@link AVCODEC_MIMETYPE}.
 * @return Pointer to an OH_AVCodec instance.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_CreateByMime
 * @since 9
 */
OH_AVCodec *OH_AudioDecoder_CreateByMime(const char *mime);

/**
 * @brief Creates an audio decoder instance based on a decoder name. To use this function, you must know the exact name
 * of the decoder.
 *
 * @param name Pointer to an audio decoder name.
 * @return Pointer to an OH_AVCodec instance.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_CreateByName
 * @since 9
 */
OH_AVCodec *OH_AudioDecoder_CreateByName(const char *name);

/**
 * @brief Clears the internal resources of an audio decoder and destroys the decoder instance.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_Destroy
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_Destroy(OH_AVCodec *codec);

/**
 * @brief Sets an asynchronous callback so that your application can respond to events generated by an audio decoder.
 * This function must be called prior to **Prepare**.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @param callback Callback function.
 * @param userData User-specific data.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_RegisterCallback
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData);

/**
 * @brief Configures an audio decoder. Typically, you need to configure the audio description information that can be
 * extracted from the container. This function must be called prior to **Prepare**.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @param format Pointer to the OH_AVFormat instance, which provides the description information about the audio track
 *     to be decoded.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_Configure
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_Configure(OH_AVCodec *codec, OH_AVFormat *format);

/**
 * @brief Prepares internal resources for an audio decoder. This function must be called after **Configure**.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_Prepare
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_Prepare(OH_AVCodec *codec);

/**
 * @brief Starts an audio decoder after it is prepared successfully. After being started, the decoder starts to report
 * the **OH_AVCodecOnNeedInputData** event.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_Start
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_Start(OH_AVCodec *codec);

/**
 * @brief Stops an audio decoder.
 *
 * After the decoder is stopped, you can call **Start** to start it again. If you have passed specific data in the
 * previous **Start** for the decoder, you must pass it again.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_Stop
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_Stop(OH_AVCodec *codec);

/**
 * @brief Clears the input and output data in the internal buffer of an audio 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.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_Flush
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_Flush(OH_AVCodec *codec);

/**
 * @brief Resets an audio decoder. To continue decoding, you must call **Configure** to configure the decoder again.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_Reset
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_Reset(OH_AVCodec *codec);

/**
 * @brief Obtains the description information about the output data of an audio decoder.
 *
 * The caller must manually release the OH_AVFormat instance in the return value.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @return Handle to an OH_AVFormat instance. The lifecycle of this instance is refreshed when **GetOutputDescription**
 *     is called again and destroyed when the OH_AVCodec instance is destroyed.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_GetOutputDescription
 * @since 9
 */
OH_AVFormat *OH_AudioDecoder_GetOutputDescription(OH_AVCodec *codec);

/**
 * @brief Sets dynamic parameters for an audio decoder.
 *
 * This function can be called only after the decoder is started. Incorrect parameter settings may cause decoding
 * failure.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @param format Handle to an OH_AVFormat instance.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_SetParameter
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format);

/**
 * @brief Notifies the audio decoder that the input data has been written to the buffer identified by **index**.
 *
 * The {@link OH_AVCodecOnNeedInputData} callback reports the available input buffer and the index. After being
 * pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the
 * {@link OH_AVCodecOnNeedInputData} callback.
 *
 * In addition, some decoders require the input of specific data to initialize the decoding process.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @param index Index of the input buffer.
 * @param attr Description information about the data in the buffer.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_PushInputBuffer
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr);

/**
 * @brief Frees an output buffer of an audio decoder.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @param index Index of the output buffer.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_FreeOutputBuffer
 * @since 9
 */
OH_AVErrCode OH_AudioDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index);

/**
 * @brief Checks whether an audio decoder instance is valid. This function is used to check the decoder validity when
 * the background recovers from a fault or an application is switched from the background.
 *
 * @param codec Pointer to an OH_AVCodec instance.
 * @param isValid Pointer to an instance of the Boolean type. The value **true** means that the decoder instance is
 *     valid and **false** means the opposite.
 * @return {@link AV_ERR_OK} if the operation is successful; a specific error code otherwise.
 * @deprecated since 11
 * @useinstead OH_AudioCodec_IsValid
 * @since 10
 */
OH_AVErrCode OH_AudioDecoder_IsValid(OH_AVCodec *codec, bool *isValid);
#ifdef __cplusplus
}
#endif
#endif // NATIVE_AVCODEC_AUDIODECODER_H
/** @} */