1da853ecaSopenharmony_ci/*
2da853ecaSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3da853ecaSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4da853ecaSopenharmony_ci * you may not use this file except in compliance with the License.
5da853ecaSopenharmony_ci * You may obtain a copy of the License at
6da853ecaSopenharmony_ci *
7da853ecaSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8da853ecaSopenharmony_ci *
9da853ecaSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10da853ecaSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11da853ecaSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12da853ecaSopenharmony_ci * See the License for the specific language governing permissions and
13da853ecaSopenharmony_ci * limitations under the License.
14da853ecaSopenharmony_ci */
15da853ecaSopenharmony_ci
16da853ecaSopenharmony_ci#ifndef NATIVE_AVCODEC_AUDIODECODER_H
17da853ecaSopenharmony_ci#define NATIVE_AVCODEC_AUDIODECODER_H
18da853ecaSopenharmony_ci
19da853ecaSopenharmony_ci#include <stdint.h>
20da853ecaSopenharmony_ci#include <stdio.h>
21da853ecaSopenharmony_ci#include "native_avcodec_base.h"
22da853ecaSopenharmony_ci
23da853ecaSopenharmony_ci#ifdef __cplusplus
24da853ecaSopenharmony_ciextern "C" {
25da853ecaSopenharmony_ci#endif
26da853ecaSopenharmony_ci
27da853ecaSopenharmony_ci/**
28da853ecaSopenharmony_ci * @brief Creates an audio decoder instance from the mime type, which is recommended in most cases.
29da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
30da853ecaSopenharmony_ci * @param mime mime type description string, refer to {@link AVCODEC_MIME_TYPE}
31da853ecaSopenharmony_ci * @return Returns a Pointer to an OH_AVCodec instance
32da853ecaSopenharmony_ci * @deprecated since 11
33da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_CreateByMime
34da853ecaSopenharmony_ci * @since 9
35da853ecaSopenharmony_ci * @version 1.0
36da853ecaSopenharmony_ci */
37da853ecaSopenharmony_ciOH_AVCodec *OH_AudioDecoder_CreateByMime(const char *mime);
38da853ecaSopenharmony_ci
39da853ecaSopenharmony_ci/**
40da853ecaSopenharmony_ci * @brief Create an audio decoder instance through the audio decoder name.
41da853ecaSopenharmony_ci * The premise of using this interface is to know the exact name of the decoder.
42da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
43da853ecaSopenharmony_ci * @param name Audio codec name
44da853ecaSopenharmony_ci * @return Returns a Pointer to an OH_AVCodec instance
45da853ecaSopenharmony_ci * @deprecated since 11
46da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_CreateByName
47da853ecaSopenharmony_ci * @since 9
48da853ecaSopenharmony_ci * @version 1.0
49da853ecaSopenharmony_ci */
50da853ecaSopenharmony_ciOH_AVCodec *OH_AudioDecoder_CreateByName(const char *name);
51da853ecaSopenharmony_ci
52da853ecaSopenharmony_ci/**
53da853ecaSopenharmony_ci * @brief Clear the internal resources of the decoder and destroy the decoder instance
54da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
55da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
56da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
57da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
58da853ecaSopenharmony_ci * @deprecated since 11
59da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_Destroy
60da853ecaSopenharmony_ci * @since 9
61da853ecaSopenharmony_ci * @version 1.0
62da853ecaSopenharmony_ci */
63da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_Destroy(OH_AVCodec *codec);
64da853ecaSopenharmony_ci
65da853ecaSopenharmony_ci/**
66da853ecaSopenharmony_ci * @brief Set the asynchronous callback function so that your application
67da853ecaSopenharmony_ci * can respond to the events generated by the audio decoder. This interface must be called before Prepare is called.
68da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
69da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
70da853ecaSopenharmony_ci * @param callback A collection of all callback functions, see {@link OH_AVCodecAsyncCallback}
71da853ecaSopenharmony_ci * @param userData User specific data
72da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
73da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
74da853ecaSopenharmony_ci * @deprecated since 11
75da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_RegisterCallback
76da853ecaSopenharmony_ci * @since 9
77da853ecaSopenharmony_ci * @version 1.0
78da853ecaSopenharmony_ci */
79da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData);
80da853ecaSopenharmony_ci
81da853ecaSopenharmony_ci/**
82da853ecaSopenharmony_ci * @brief To configure the audio decoder, typically, you need to configure the description information of the decoded
83da853ecaSopenharmony_ci * audio track, which can be extracted from the OH_AVSource. This interface must be called before Prepare is called.
84da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
85da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
86da853ecaSopenharmony_ci * @param format A pointer to an OH_AVFormat giving a description of the audio track to be decoded
87da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
88da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
89da853ecaSopenharmony_ci * @deprecated since 11
90da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_Configure
91da853ecaSopenharmony_ci * @since 9
92da853ecaSopenharmony_ci * @version 1.0
93da853ecaSopenharmony_ci */
94da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_Configure(OH_AVCodec *codec, OH_AVFormat *format);
95da853ecaSopenharmony_ci
96da853ecaSopenharmony_ci/**
97da853ecaSopenharmony_ci * @brief To prepare the internal resources of the decoder, the Configure interface must be called
98da853ecaSopenharmony_ci * before calling this interface.
99da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
100da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
101da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
102da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
103da853ecaSopenharmony_ci * @deprecated since 11
104da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_Prepare
105da853ecaSopenharmony_ci * @since 9
106da853ecaSopenharmony_ci * @version 1.0
107da853ecaSopenharmony_ci */
108da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_Prepare(OH_AVCodec *codec);
109da853ecaSopenharmony_ci
110da853ecaSopenharmony_ci/**
111da853ecaSopenharmony_ci * @brief Start the decoder, this interface must be called after the Prepare is successful.
112da853ecaSopenharmony_ci * After being successfully started, the decoder will start reporting NeedInputData events.
113da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
114da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
115da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
116da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
117da853ecaSopenharmony_ci * @deprecated since 11
118da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_Start
119da853ecaSopenharmony_ci * @since 9
120da853ecaSopenharmony_ci * @version 1.0
121da853ecaSopenharmony_ci */
122da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_Start(OH_AVCodec *codec);
123da853ecaSopenharmony_ci
124da853ecaSopenharmony_ci/**
125da853ecaSopenharmony_ci * @brief Stop the decoder. After stopping, you can re-enter the Started state through Start,
126da853ecaSopenharmony_ci * but it should be noted that need to re-enter if the decoder has been input before
127da853ecaSopenharmony_ci * Codec-Specific-Data.
128da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
129da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
130da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
131da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
132da853ecaSopenharmony_ci * @deprecated since 11
133da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_Stop
134da853ecaSopenharmony_ci * @since 9
135da853ecaSopenharmony_ci * @version 1.0
136da853ecaSopenharmony_ci */
137da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_Stop(OH_AVCodec *codec);
138da853ecaSopenharmony_ci
139da853ecaSopenharmony_ci/**
140da853ecaSopenharmony_ci * @brief Clear the input and output data buffered in the decoder. After this interface is called, all the Buffer
141da853ecaSopenharmony_ci * indexes previously reported through the asynchronous callback will be invalidated, make sure not to access
142da853ecaSopenharmony_ci * the Buffers corresponding to these indexes.
143da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
144da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
145da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
146da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
147da853ecaSopenharmony_ci * @deprecated since 11
148da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_Flush
149da853ecaSopenharmony_ci * @since 9
150da853ecaSopenharmony_ci * @version 1.0
151da853ecaSopenharmony_ci */
152da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_Flush(OH_AVCodec *codec);
153da853ecaSopenharmony_ci
154da853ecaSopenharmony_ci/**
155da853ecaSopenharmony_ci * @brief Reset the decoder. To continue decoding, you need to call the Configure interface again to
156da853ecaSopenharmony_ci * configure the decoder instance.
157da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
158da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
159da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
160da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
161da853ecaSopenharmony_ci * @deprecated since 11
162da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_Reset
163da853ecaSopenharmony_ci * @since 9
164da853ecaSopenharmony_ci * @version 1.0
165da853ecaSopenharmony_ci */
166da853ecaSopenharmony_ci
167da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_Reset(OH_AVCodec *codec);
168da853ecaSopenharmony_ci
169da853ecaSopenharmony_ci/**
170da853ecaSopenharmony_ci * @brief Get the description information of the output data of the decoder, refer to {@link OH_AVFormat} for details.
171da853ecaSopenharmony_ci * It should be noted that the life cycle of the OH_AVFormat instance pointed to by the return value * needs to
172da853ecaSopenharmony_ci * be manually released by the caller
173da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
174da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
175da853ecaSopenharmony_ci * @return Returns the OH_AVFormat handle pointer, the life cycle is refreshed with the next GetOutputMediaDescription,
176da853ecaSopenharmony_ci * or destroyed with OH_AVCodec;
177da853ecaSopenharmony_ci * @deprecated since 11
178da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_GetOutputDescription
179da853ecaSopenharmony_ci * @since 9
180da853ecaSopenharmony_ci * @version 1.0
181da853ecaSopenharmony_ci */
182da853ecaSopenharmony_ciOH_AVFormat *OH_AudioDecoder_GetOutputDescription(OH_AVCodec *codec);
183da853ecaSopenharmony_ci
184da853ecaSopenharmony_ci/**
185da853ecaSopenharmony_ci * @brief Set dynamic parameters to the decoder. Note: This interface can only be called after the decoder is started.
186da853ecaSopenharmony_ci * At the same time, incorrect parameter settings may cause decoding failure.
187da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
188da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
189da853ecaSopenharmony_ci * @param format OH_AVFormat handle pointer
190da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
191da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
192da853ecaSopenharmony_ci * @deprecated since 11
193da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_SetParameter
194da853ecaSopenharmony_ci * @since 9
195da853ecaSopenharmony_ci * @version 1.0
196da853ecaSopenharmony_ci */
197da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format);
198da853ecaSopenharmony_ci
199da853ecaSopenharmony_ci/**
200da853ecaSopenharmony_ci * @brief Submit the input buffer filled with data to the audio decoder. The {@link OH_AVCodecOnNeedInputData} callback
201da853ecaSopenharmony_ci * will report the available input buffer and the corresponding index value. Once the buffer with the specified index
202da853ecaSopenharmony_ci * is submitted to the audio decoder, the buffer cannot be accessed again until the {@link OH_AVCodecOnNeedInputData}
203da853ecaSopenharmony_ci * callback is received again reporting that the buffer with the same index is available. In addition, for some
204da853ecaSopenharmony_ci * decoders, it is required to input Codec-Specific-Data to the decoder at the beginning to initialize the decoding
205da853ecaSopenharmony_ci * process of the decoder.
206da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
207da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
208da853ecaSopenharmony_ci * @param index Enter the index value corresponding to the Buffer
209da853ecaSopenharmony_ci * @param attr Information describing the data contained in the Buffer
210da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
211da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
212da853ecaSopenharmony_ci * @deprecated since 11
213da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_PushInputBuffer
214da853ecaSopenharmony_ci * @since 9
215da853ecaSopenharmony_ci * @version 1.0
216da853ecaSopenharmony_ci */
217da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr);
218da853ecaSopenharmony_ci
219da853ecaSopenharmony_ci/**
220da853ecaSopenharmony_ci * @brief Return the processed output Buffer to the decoder.
221da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
222da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
223da853ecaSopenharmony_ci * @param index The index value corresponding to the output Buffer
224da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
225da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
226da853ecaSopenharmony_ci * @deprecated since 11
227da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_FreeOutputBuffer
228da853ecaSopenharmony_ci * @since 9
229da853ecaSopenharmony_ci * @version 1.0
230da853ecaSopenharmony_ci */
231da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index);
232da853ecaSopenharmony_ci
233da853ecaSopenharmony_ci/**
234da853ecaSopenharmony_ci * @brief Check whether the current codec instance is valid. It can be used fault recovery or app
235da853ecaSopenharmony_ci * switchback from the background
236da853ecaSopenharmony_ci * @syscap SystemCapability.Multimedia.Media.AudioDecoder
237da853ecaSopenharmony_ci * @param codec Pointer to an OH_AVCodec instance
238da853ecaSopenharmony_ci * @param isValid Output Parameter. A pointer to a boolean instance, it is true if the codec instance is valid,
239da853ecaSopenharmony_ci * false if the codec instance is invalid
240da853ecaSopenharmony_ci * @return Returns AV_ERR_OK if the execution is successful,
241da853ecaSopenharmony_ci * otherwise returns a specific error code, refer to {@link OH_AVErrCode}
242da853ecaSopenharmony_ci * @deprecated since 11
243da853ecaSopenharmony_ci * @useinstead OH_AudioCodec_IsValid
244da853ecaSopenharmony_ci * @since 10
245da853ecaSopenharmony_ci */
246da853ecaSopenharmony_ciOH_AVErrCode OH_AudioDecoder_IsValid(OH_AVCodec *codec, bool *isValid);
247da853ecaSopenharmony_ci
248da853ecaSopenharmony_ci#ifdef __cplusplus
249da853ecaSopenharmony_ci}
250da853ecaSopenharmony_ci#endif
251da853ecaSopenharmony_ci#endif // NATIVE_AVCODEC_AUDIODECODER_H