/*
 * 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 AudioEncoder
 * @{
 *
 * @brief The AudioEncoder module provides functions for audio encoding.
 *
 * @syscap SystemCapability.Multimedia.Media.AudioEncoder
 * @deprecated since 11
 * @since 9
 */

/**
 * @file native_avcodec_audioencoder.h
 *
 * @brief The file declares the native APIs used for audio encoding.
 *
 * @kit AVCodecKit
 * @library libnative_media_aenc.so
 * @syscap SystemCapability.Multimedia.Media.AudioEncoder
 * @deprecated since 11
 * @since 9
 */

#ifndef NATIVE_AVCODEC_AUDIOENCODER_H
#define NATIVE_AVCODEC_AUDIOENCODER_H

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

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Creates an audio encoder 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
 * @version 1.0
 */
OH_AVCodec *OH_AudioEncoder_CreateByMime(const char *mime);

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

/**
 * @brief Clears the internal resources of an audio encoder and destroys the encoder 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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_Destroy(OH_AVCodec *codec);

/**
 * @brief Sets an asynchronous callback so that your application can respond to events generated by an audio encoder.
 * 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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData);

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

/**
 * @brief Prepares internal resources for an audio encoder. 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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_Prepare(OH_AVCodec *codec);

/**
 * @brief Starts an audio encoder after it is prepared successfully. After being started, the encoder 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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_Start(OH_AVCodec *codec);

/**
 * @brief Stops an audio encoder. After the encoder is stopped, you can call **Start** to start 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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_Stop(OH_AVCodec *codec);

/**
 * @brief Clears the input and output data in the internal buffer of an audio encoder.
 *
 * 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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_Flush(OH_AVCodec *codec);

/**
 * @brief Resets an audio encoder. To continue encoding, you must call **Configure** to configure the encoder 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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_Reset(OH_AVCodec *codec);

/**
 * @brief Obtains the description information about the output data of an audio encoder. 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
 * @version 1.0
 */
OH_AVFormat *OH_AudioEncoder_GetOutputDescription(OH_AVCodec *codec);

/**
 * @brief Sets dynamic parameters for an audio encoder.
 *
 * This function can be called only after the encoder is started. Incorrect parameter settings may cause encoding
 * 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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format);

/**
 * @brief Notifies the audio encoder 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 encoder, a buffer is not accessible until the buffer with the same index is reported again through the
 * {@link OH_AVCodecOnNeedInputData} callback.
 *
 * In addition, some encoders require the input of specific data to initialize the encoding 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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr);

/**
 * @brief Frees an output buffer of an audio encoder.
 *
 * @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
 * @version 1.0
 */
OH_AVErrCode OH_AudioEncoder_FreeOutputData(OH_AVCodec *codec, uint32_t index);

/**
 * @brief Checks whether an audio encoder instance is valid. This function is used to check the encoder 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 of the Boolean type. The value **true** means that the encoder 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_AudioEncoder_IsValid(OH_AVCodec *codec, bool *isValid);

#ifdef __cplusplus
}
#endif
#endif // NATIVE_AVCODEC_AUDIOENCODER_H
/** @} */