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