• 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 /**
17  * @addtogroup VideoDecoder
18  * @{
19  *
20  * @brief The VideoDecoder module provides interfaces for video decoding.
21  *
22  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
23  * @since 9
24  * @version 1.0
25  */
26 
27 /**
28  * @file native_avcodec_videodecoder.h
29  *
30  * @brief Declare the Native API used for video decoding.
31  *
32  * @kit AVCodecKit
33  * @library libnative_media_vdec.so
34  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
35  * @since 9
36  */
37 
38 #ifndef NATIVE_AVCODEC_VIDEODECODER_H
39 #define NATIVE_AVCODEC_VIDEODECODER_H
40 
41 #include <stdint.h>
42 #include <stdio.h>
43 #include "native_avcodec_base.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /**
50  * @brief Forward declaration of MediaKeySession.
51  *
52  * @since 11
53  */
54 typedef struct MediaKeySession MediaKeySession;
55 
56 /**
57  * @brief Creates a video decoder instance from the mime type, which is recommended in most cases.
58  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
59  * @param mime mime type description string, refer to {@link AVCODEC_MIME_TYPE}
60  * @return Returns a Pointer to an OH_AVCodec instance.
61  * Return nullptr if memory ran out or the mime type is not supported.
62  * @since 9
63  */
64 OH_AVCodec *OH_VideoDecoder_CreateByMime(const char *mime);
65 
66 /**
67  * @brief Create a video decoder instance through the video decoder name.
68  * The premise of using this interface is to know the exact name of the decoder.
69  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
70  * @param name video codec name
71  * @return Returns a Pointer to an OH_AVCodec instance.
72  * Return nullptr if memory ran out or the decoder name is not supported.
73  * @since 9
74  */
75 OH_AVCodec *OH_VideoDecoder_CreateByName(const char *name);
76 
77 /**
78  * @brief Clear the internal resources of the decoder and destroy the decoder instance
79  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
80  * @param codec Pointer to an OH_AVCodec instance
81  * @return Returns AV_ERR_OK if succeed,
82  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
83  * {@link AV_ERR_NO_MEMORY}, inner resource has already released.
84  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
85  * {@link AV_ERR_UNKNOWN}, unknown error.
86  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
87  * @since 9
88  */
89 OH_AVErrCode OH_VideoDecoder_Destroy(OH_AVCodec *codec);
90 
91 /**
92  * @brief Set the asynchronous callback function so that your application can respond to the events
93  * generated by the video decoder. This interface must be called before Prepare is called.
94  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
95  * @param codec Pointer to an OH_AVCodec instance
96  * @param callback A collection of all callback functions, see {@link OH_AVCodecAsyncCallback}
97  * @param userData User specific data
98  * @return Returns AV_ERR_OK if the execution is successful,
99  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
100  * {@link AV_ERR_NO_MEMORY}, inner resource has already released.
101  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
102  * {@link AV_ERR_UNKNOWN}, unknown error.
103  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
104  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state, must be called before Prepare.
105  * @deprecated since 11
106  * @useinstead OH_VideoDecoder_RegisterCallback
107  * @since 9
108  */
109 OH_AVErrCode OH_VideoDecoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData);
110 
111 /**
112  * @brief Set the asynchronous callback function so that your application can respond to the events
113  * generated by the video decoder. This interface must be called before Prepare is called.
114  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
115  * @param codec Pointer to an OH_AVCodec instance
116  * @param callback A collection of all callback functions, see {@link OH_AVCodecCallback}
117  * @param userData User specific data
118  * @return Returns AV_ERR_OK if the execution is successful,
119  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
120  * {@link AV_ERR_NO_MEMORY}, inner resource has already released.
121  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
122  * {@link AV_ERR_UNKNOWN}, unknown error.
123  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
124  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state, must be called before Prepare.
125  * @since 11
126  */
127 OH_AVErrCode OH_VideoDecoder_RegisterCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData);
128 
129 /**
130  * @brief Specify the output Surface to provide video decoding output,
131  * this interface must be called before Prepare is called
132  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
133  * @param codec Pointer to an OH_AVCodec instance
134  * @param window A pointer to a OHNativeWindow instance, see {@link OHNativeWindow}
135  * @return Returns AV_ERR_OK if the execution is successful,
136  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
137  * {@link AV_ERR_NO_MEMORY}, inner resource has already released.
138  * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permit to call the interface in buffer mode.
139  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
140  * {@link AV_ERR_UNKNOWN}, unknown error.
141  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
142  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
143  * @since 9
144  */
145 OH_AVErrCode OH_VideoDecoder_SetSurface(OH_AVCodec *codec, OHNativeWindow *window);
146 
147 /**
148  * @brief To configure the video decoder, typically, you need to configure the description information of the decoded
149  * video track, which can be extracted from the OH_AVSource. This interface must be called before Prepare is called.
150  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
151  * @param codec Pointer to an OH_AVCodec instance
152  * @param format A pointer to an OH_AVFormat to give the description of the video track to be decoded
153  * @return Returns AV_ERR_OK if the execution is successful,
154  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
155  * {@link AV_ERR_NO_MEMORY}, instance has already released.
156  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid. Invalid param in format.
157  * {@link AV_ERR_UNKNOWN}, unknown error.
158  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
159  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state, must be called before Prepare.
160  * {@link AV_ERR_UNSUPPORT}, unsupported features.
161  * {@link AV_ERR_VIDEO_UNSUPPORTED_COLOR_SPACE_CONVERSION}, video unsupported color space conversion.
162  * @since 9
163  */
164 OH_AVErrCode OH_VideoDecoder_Configure(OH_AVCodec *codec, OH_AVFormat *format);
165 
166 /**
167  * @brief To prepare the internal resources of the decoder, the Configure interface must be called before
168  * calling this interface.
169  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
170  * @param codec Pointer to an OH_AVCodec instance
171  * @return Returns AV_ERR_OK if the execution is successful,
172  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
173  * {@link AV_ERR_NO_MEMORY}, instance has already released.
174  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
175  * {@link AV_ERR_UNKNOWN}, unknown error.
176  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
177  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
178  * {@link AV_ERR_OPERATE_NOT_PERMIT}, decoder is in buffer mode and color space conversion is configured.
179  * @since 9
180  */
181 OH_AVErrCode OH_VideoDecoder_Prepare(OH_AVCodec *codec);
182 
183 /**
184  * @brief Start the decoder, this interface must be called after the Prepare is successful.
185  * After being successfully started, the decoder will start reporting NeedInputData events.
186  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
187  * @param codec Pointer to an OH_AVCodec instance
188  * @return Returns AV_ERR_OK if the execution is successful,
189  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
190  * {@link AV_ERR_NO_MEMORY}, instance has already released.
191  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
192  * {@link AV_ERR_UNKNOWN}, unknown error.
193  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
194  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
195  * {@link AV_ERR_OPERATE_NOT_PERMIT}, video color space conversion is configured but decoder is not prepared.
196  * @since 9
197  */
198 OH_AVErrCode OH_VideoDecoder_Start(OH_AVCodec *codec);
199 
200 /**
201  * @brief Stop the decoder. After stopping, you can re-enter the Started state through Start,
202  * but it should be noted that if Codec-Specific-Data has been input to the decoder before, it needs to be input again.
203  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
204  * @param codec Pointer to an OH_AVCodec instance
205  * @return Returns AV_ERR_OK if the execution is successful,
206  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
207  * {@link AV_ERR_NO_MEMORY}, instance has already released.
208  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
209  * {@link AV_ERR_UNKNOWN}, unknown error.
210  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
211  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
212  * @since 9
213  */
214 OH_AVErrCode OH_VideoDecoder_Stop(OH_AVCodec *codec);
215 
216 /**
217  * @brief Clear the input and output data buffered in the decoder. After this interface is called, all the Buffer
218  * indexes previously reported through the asynchronous callback will be invalidated, make sure not to access
219  * the Buffers corresponding to these indexes.
220  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
221  * @param codec Pointer to an OH_AVCodec instance
222  * @return Returns AV_ERR_OK if the execution is successful,
223  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
224  * {@link AV_ERR_NO_MEMORY}, instance has already released.
225  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
226  * {@link AV_ERR_UNKNOWN}, unknown error.
227  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
228  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
229  * @since 9
230  */
231 OH_AVErrCode OH_VideoDecoder_Flush(OH_AVCodec *codec);
232 
233 /**
234  * @brief Reset the decoder. To continue decoding, you need to call the Configure interface again
235  * to configure the decoder instance.
236  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
237  * @param codec Pointer to an OH_AVCodec instance
238  * @return Returns AV_ERR_OK if the execution is successful,
239  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
240  * {@link AV_ERR_NO_MEMORY}, instance has already released.
241  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
242  * {@link AV_ERR_UNKNOWN}, unknown error.
243  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
244  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
245  * @since 9
246  */
247 OH_AVErrCode OH_VideoDecoder_Reset(OH_AVCodec *codec);
248 
249 /**
250  * @brief Get the description information of the output data of the decoder, refer to {@link OH_AVFormat}
251  * It should be noted that the life cycle of the OH_AVFormat instance pointed to by the return value * needs
252  * to be manually released by the caller.
253  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
254  * @param codec Pointer to an OH_AVCodec instance
255  * @return Returns a pointer to an OH_AVFormat instance.
256  * Return nullptr if the decoder is nullptr or invaild.
257  * @since 9
258  */
259 OH_AVFormat *OH_VideoDecoder_GetOutputDescription(OH_AVCodec *codec);
260 
261 /**
262  * @brief Set dynamic parameters to the decoder. Note: This interface can only be called after the decoder is started.
263  * At the same time, incorrect parameter settings may cause decoding failure.
264  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
265  * @param codec Pointer to an OH_AVCodec instance
266  * @param format pointer to an OH_AVFormat instance
267  * @return Returns AV_ERR_OK if the execution is successful,
268  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
269  * {@link AV_ERR_NO_MEMORY}, instance has already released.
270  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid. Invalid param in format.
271  * {@link AV_ERR_UNKNOWN}, unknown error.
272  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
273  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
274  * @since 9
275  */
276 OH_AVErrCode OH_VideoDecoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format);
277 
278 /**
279  * @brief Submit the input buffer filled with data to the video decoder. The {@link OH_AVCodecOnNeedInputData} callback
280  * will report the available input buffer and the corresponding index value. Once the buffer with the specified index
281  * is submitted to the video decoder, the buffer cannot be accessed again until the {@link OH_AVCodecOnNeedInputData}
282  * callback is received again reporting that the buffer with the same index is available. In addition, for some
283  * decoders, it is required to input Codec-Specific-Data to the decoder at the beginning to initialize the decoding
284  * process of the decoder, such as PPS/SPS data in H264 format.
285  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
286  * @param codec Pointer to an OH_AVCodec instance
287  * @param index Enter the index value corresponding to the Buffer
288  * @param attr Information describing the data contained in the Buffer
289  * @return Returns AV_ERR_OK if the execution is successful,
290  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
291  * {@link AV_ERR_NO_MEMORY}, instance has already released.
292  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
293  * Buffer index should be given by {@link OH_AVCodecOnNeedInputData}.
294  * {@link AV_ERR_UNKNOWN}, unknown error.
295  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
296  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
297  * @deprecated since 11
298  * @useinstead OH_VideoDecoder_PushInputBuffer
299  * @since 9
300  */
301 OH_AVErrCode OH_VideoDecoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr);
302 
303 /**
304  * @brief Return the processed output Buffer to the decoder, and notify the decoder to finish rendering the
305  * decoded data contained in the Buffer on the output Surface. If the output surface is not configured before,
306  * calling this interface only returns the output buffer corresponding to the specified index to the decoder.
307  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
308  * @param codec Pointer to an OH_AVCodec instance
309  * @param index The index value corresponding to the output Buffer
310  * @return Returns AV_ERR_OK if the execution is successful,
311  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
312  * {@link AV_ERR_NO_MEMORY}, instance has already released.
313  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
314  * Buffer index should be given by {@link OH_AVCodecOnNewOutputData}.
315  * {@link AV_ERR_UNKNOWN}, unknown error.
316  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
317  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
318  * @deprecated since 11
319  * @useinstead OH_VideoDecoder_RenderOutputBuffer
320  * @since 9
321  */
322 OH_AVErrCode OH_VideoDecoder_RenderOutputData(OH_AVCodec *codec, uint32_t index);
323 
324 /**
325  * @brief Return the processed output Buffer to the decoder.
326  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
327  * @param codec Pointer to an OH_AVCodec instance
328  * @param index The index value corresponding to the output Buffer
329  * @return Returns AV_ERR_OK if the execution is successful,
330  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
331  * {@link AV_ERR_NO_MEMORY}, instance has already released.
332  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
333  * Buffer index should be given by {@link OH_AVCodecOnNewOutputData}.
334  * {@link AV_ERR_UNKNOWN}, unknown error.
335  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
336  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
337  * @deprecated since 11
338  * @useinstead OH_VideoDecoder_FreeOutputBuffer
339  * @since 9
340  */
341 OH_AVErrCode OH_VideoDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index);
342 
343 /**
344  * @brief Submit the input buffer filled with data to the video decoder. The {@link OH_AVCodecOnNeedInputBuffer}
345  * callback will report the available input buffer and the corresponding index value. Once the buffer with the
346  * specified index is submitted to the video decoder, the buffer cannot be accessed again until the
347  * {@link OH_AVCodecOnNeedInputBuffer} callback is received again reporting that the buffer with the same index is
348  * available. In addition, for some decoders, it is required to input Codec-Specific-Data to the decoder at the
349  * beginning to initialize the decoding process of the decoder, such as PPS/SPS data in H264 format.
350  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
351  * @param codec Pointer to an OH_AVCodec instance
352  * @param index The index of the input buffer.
353  * @return Returns AV_ERR_OK if the execution is successful,
354  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
355  * {@link AV_ERR_NO_MEMORY}, instance has already released.
356  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
357  * Buffer index should be given by {@link OH_AVCodecOnNeedInputBuffer}.
358  * {@link AV_ERR_UNKNOWN}, unknown error.
359  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
360  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
361  * {@link AV_ERR_DRM_DECRYPT_FAILED}, the drm-protected video buffer is decrypted failed,
362  * it is recommended to check the logs.
363  * @since 11
364  */
365 OH_AVErrCode OH_VideoDecoder_PushInputBuffer(OH_AVCodec *codec, uint32_t index);
366 
367 /**
368  * @brief Return the processed output Buffer to the decoder, and notify the decoder to finish rendering the
369  * decoded data contained in the Buffer on the output Surface. If the output surface is not configured before,
370  * calling this interface only returns the output buffer corresponding to the specified index to the decoder.
371  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
372  * @param codec Pointer to an OH_AVCodec instance
373  * @param index The index value corresponding to the output Buffer
374  * @return Returns AV_ERR_OK if the execution is successful,
375  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
376  * {@link AV_ERR_NO_MEMORY}, instance has already released.
377  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
378  * Buffer index should be given by {@link OH_AVCodecOnNewOutputBuffer}.
379  * {@link AV_ERR_UNKNOWN}, unknown error.
380  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
381  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
382  * @since 11
383  */
384 OH_AVErrCode OH_VideoDecoder_RenderOutputBuffer(OH_AVCodec *codec, uint32_t index);
385 
386 /**
387  * @brief Return the processed output buffer with render timestamp to the decoder, and notify the decoder to finish
388  * rendering the decoded data contained in the buffer on the output surface. If the output surface is not configured
389  * before, calling this interface only returns the output buffer corresponding to the specified index to the decoder.
390  * The timestamp may have special meaning depending on the destination surface.
391  * Invoker can use the timestamp to render the buffer at a specific time (at the VSYNC at or after the buffer
392  * timestamp). For this to work, the timestamp needs to be reasonably close to the current SystemNanoTime. A few notes:
393  * 1. The buffer will not be returned to the codec until the timestamp has passed and the buffer is no longer used by
394  *    the surface.
395  * 2. Buffers are processed sequentially, so you may block subsequent buffers to be displayed on the surface.
396  *    This is important if you want to react to user action, e.g. stop the video or seek.
397  * 3. If multiple buffers are sent to the surface to be rendered at the same VSYNC, the last one will be shown, and the
398  *    other ones will be dropped.
399  * 4. If the timestamp is not "reasonably close" to the current system time, the Surface will
400  *    ignore the timestamp, and display the buffer at the earliest feasible time. In this mode it will not drop frames.
401  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
402  * @param codec Pointer to an OH_AVCodec instance
403  * @param index The index value corresponding to the output buffer, should be given by {@link
404  * OH_AVCodecOnNewOutputBuffer}
405  * @param renderTimestampNs The timestamp is associated with the output buffer when it is sent to the surface. The unit
406  * is nanosecond
407  * @return Returns AV_ERR_OK if the execution is successful,
408  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
409  * {@link AV_ERR_NO_MEMORY}, the codec has already released.
410  * {@link AV_ERR_INVALID_VAL}, the parameter is invalid.
411  * {@link AV_ERR_UNKNOWN}, unknown error.
412  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
413  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
414  * @since 12
415  */
416 OH_AVErrCode OH_VideoDecoder_RenderOutputBufferAtTime(OH_AVCodec *codec, uint32_t index, int64_t renderTimestampNs);
417 
418 /**
419  * @brief Return the processed output Buffer to the decoder.
420  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
421  * @param codec Pointer to an OH_AVCodec instance
422  * @param index The index value corresponding to the output Buffer
423  * @return Returns AV_ERR_OK if the execution is successful,
424  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
425  * {@link AV_ERR_NO_MEMORY}, instance has already released.
426  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
427  * Buffer index should be given by {@link OH_AVCodecOnNewOutputBuffer}.
428  * {@link AV_ERR_UNKNOWN}, unknown error.
429  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
430  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
431  * @since 11
432  */
433 OH_AVErrCode OH_VideoDecoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index);
434 
435 /**
436  * @brief Queries the index of the next available input buffer.
437  *
438  * This API must be followed by calling {@link OH_VideoDecoder_GetInputBuffer} to obtain the buffer handle,
439  * which should then be passed to the decoder via {@link OH_VideoDecoder_PushInputBuffer}.\n
440  * Note: This operation is only supported in synchronous mode.\n
441  *
442  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
443  * @param codec Pointer to an OH_AVCodec instance.
444  * @param index The index of the input buffer.
445  * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait.
446  * @return Returns AV_ERR_OK if the execution is successful,
447  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
448  * {@link AV_ERR_NO_MEMORY}, internal errors in the input decode instance, such as an abnormal NULL.
449  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
450  * {@link AV_ERR_UNKNOWN}, unknown error.
451  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
452  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
453 
454  * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode.
455  * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay.
456  * @since 20
457  */
458 OH_AVErrCode OH_VideoDecoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs);
459 
460 /**
461  * @brief Acquires the handle of an available input buffer.
462  *
463  * Note: It's only applicable in synchronous mode.\n
464  *
465  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
466  * @param codec Pointer to an OH_AVCodec instance
467  * @param index Buffer index obtained via {@link OH_VideoDecoder_QueryInputBuffer}.
468  * @return Returns a Pointer to an OH_AVBuffer instance.
469  * Return nullptr if no buffer available.
470  * @since 20
471  */
472 OH_AVBuffer *OH_VideoDecoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index);
473 
474 /**
475  * @brief Queries the index of the next available output buffer.
476  *
477  * The obtained buffer handle through {@link OH_VideoDecoder_GetOutputBuffer} must be:
478  *          - Return to the decoder via {@link OH_VideoDecoder_FreeOutputBuffer}, or
479  *          - Rendered using {@link OH_VideoDecoder_RenderOutputBuffer}, or
480  *          - Scheduled for rendering with {@link OH_VideoDecoder_RenderOutputBufferAtTime}\n
481  * Note: This operation is only supported in synchronous mode.\n
482  *
483  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
484  * @param codec Pointer to an OH_AVCodec instance
485  * @param index The index of the output buffer
486  * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait.
487  * @return Returns AV_ERR_OK if the execution is successful,
488  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
489  * {@link AV_ERR_NO_MEMORY}, internal errors in the input decode instance, such as an abnormal NULL.
490  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
491  * {@link AV_ERR_UNKNOWN}, unknown error.
492  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
493  * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state.
494  * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode.
495  * {@link AV_ERR_STREAM_CHANGED}, stream format changed, call {@link OH_VideoDecoder_GetOutputDescription} to
496  * retrieve new steam information.
497  * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay.
498  * @since 20
499  */
500 OH_AVErrCode OH_VideoDecoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs);
501 
502 /**
503  * @brief Acquires the handle of an available output buffer.
504  *
505  * Note: It's only applicable in synchronous mode.\n
506  *
507  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
508  * @param codec Pointer to an OH_AVCodec instance
509  * @param index Buffer index obtained via {@link OH_VideoDecoder_QueryOutputBuffer}.
510  * @return Returns a Pointer to an OH_AVBuffer instance.
511  * Return nullptr if no buffer available.
512  * @since 20
513  */
514 OH_AVBuffer *OH_VideoDecoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index);
515 
516 /**
517  * @brief Check whether the current codec instance is valid. It can be used fault recovery or app
518  * switchback from the background.
519  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
520  * @param codec Pointer to an OH_AVCodec instance
521  * @param isValid Output parameter. A pointer to a boolean instance, it is true if the codec instance is valid,
522  * false if the codec instance is invalid
523  * @return Returns AV_ERR_OK if the execution is successful,
524  * otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
525  * {@link AV_ERR_NO_MEMORY}, instance has already released.
526  * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid.
527  * {@link AV_ERR_UNKNOWN}, unknown error.
528  * {@link AV_ERR_SERVICE_DIED}, avcodec service is died.
529  * @since 10
530  */
531 OH_AVErrCode OH_VideoDecoder_IsValid(OH_AVCodec *codec, bool *isValid);
532 
533 /**
534  * @brief Set decryption info.
535  *
536  * @syscap SystemCapability.Multimedia.Media.VideoDecoder
537  * @param codec Pointer to an OH_AVCodec instance
538  * @param mediaKeySession A media key session instance with decryption function.
539  * @param secureVideoPath Require secure decoder or not.
540  * @return {@link AV_ERR_OK} 0 - Success
541  *         {@link AV_ERR_OPERATE_NOT_PERMIT} 2 - If the codec service or the media key session
542  *         service is in wrong status.
543  *         {@link AV_ERR_NO_MEMORY}, instance has already released or no memory.
544  *         {@link AV_ERR_INVALID_VAL} 3 - If the codec instance is nullptr or invalid,
545  *         the mediaKeySession is nullptr or invalid.
546  * @since 11
547 */
548 OH_AVErrCode OH_VideoDecoder_SetDecryptionConfig(OH_AVCodec *codec, MediaKeySession *mediaKeySession,
549     bool secureVideoPath);
550 
551 #ifdef __cplusplus
552 }
553 #endif
554 
555 #endif // NATIVE_AVCODEC_VIDEODECODER_H
556 /** @} */