1# native_avcodec_videodecoder.h 2<!--Kit: AVCodec Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @zhanghongran--> 5<!--Designer: @dpy2650---> 6<!--Tester: @cyakee--> 7<!--Adviser: @zengyawen--> 8 9## Overview 10 11The file declares the native APIs used for video decoding. 12 13**File to include**: <multimedia/player_framework/native_avcodec_videodecoder.h> 14 15**Library**: libnative_media_vdec.so 16 17**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 18 19**Since**: 9 20 21**Related module**: [VideoDecoder](capi-videodecoder.md) 22 23**Sample**: [AVCodec](https://gitcode.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/Media/AVCodec) 24 25The following figures show the APIs supported by each version and the APIs that can be called in different states. 26 27 28 29 30 31## Summary 32 33### Structs 34 35| Name| typedef Keyword| Description| 36| -- | -- | -- | 37| [MediaKeySession](capi-videodecoder-mediakeysession.md) | MediaKeySession | Describes a native object for MediaKeySession.| 38 39### Functions 40 41| Name| Description| 42| -- | -- | 43| [OH_AVCodec *OH_VideoDecoder_CreateByMime(const char *mime)](#oh_videodecoder_createbymime) | Creates a video decoder instance based on a MIME type. This function is recommended in most cases.| 44| [OH_AVCodec *OH_VideoDecoder_CreateByName(const char *name)](#oh_videodecoder_createbyname) | Creates a video decoder instance based on a decoder name. To use this function, you must know the exact name of the decoder. The decoder name can be obtained through capability query.| 45| [OH_AVErrCode OH_VideoDecoder_Destroy(OH_AVCodec *codec)](#oh_videodecoder_destroy) | Clears the internal resources of a video decoder and destroys the decoder instance. You only need to call the function once.| 46| [OH_AVErrCode OH_VideoDecoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData)](#oh_videodecoder_setcallback) | Sets an asynchronous callback so that your application can respond to events generated by a video decoder. This function must be called prior to **OH_VideoDecoder_Prepare**.| 47| [OH_AVErrCode OH_VideoDecoder_RegisterCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData)](#oh_videodecoder_registercallback) | Registers an asynchronous callback so that your application can respond to events generated by a video decoder. This function must be called prior to **OH_VideoDecoder_Prepare**.| 48| [OH_AVErrCode OH_VideoDecoder_SetSurface(OH_AVCodec *codec, OHNativeWindow *window)](#oh_videodecoder_setsurface) | Sets an output surface for a video decoder. In the initialization phase, this function must be called prior to **OH_VideoDecoder_Prepare**. In the running state, it can be called directly.| 49| [OH_AVErrCode OH_VideoDecoder_Configure(OH_AVCodec *codec, OH_AVFormat *format)](#oh_videodecoder_configure) | Configures a video decoder. Typically, you need to configure the video description information that can be extracted from OH_AVSource. This function must be called prior to **OH_VideoDecoder_Prepare**.| 50| [OH_AVErrCode OH_VideoDecoder_Prepare(OH_AVCodec *codec)](#oh_videodecoder_prepare) | Prepares internal resources for a video decoder. This function must be called after **OH_VideoDecoder_Configure**.| 51| [OH_AVErrCode OH_VideoDecoder_Start(OH_AVCodec *codec)](#oh_videodecoder_start) | Starts a video decoder. This function should be called after a successful call of [OH_VideoDecoder_Prepare](#oh_videodecoder_prepare). After being started, the decoder starts to report the registered event.| 52| [OH_AVErrCode OH_VideoDecoder_Stop(OH_AVCodec *codec)](#oh_videodecoder_stop) | Stops a video decoder and releases the input and output buffers. After the video decoder is stopped, you can call **OH_VideoDecoder_Start** to enter the executing state again. If you have passed codec-specific data in the previous **Start** for the decoder, you must pass it again.| 53| [OH_AVErrCode OH_VideoDecoder_Flush(OH_AVCodec *codec)](#oh_videodecoder_flush) | Clears the input and output data and parameters, for example, H.264 PPS/SPS, cached in a video 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.| 54| [OH_AVErrCode OH_VideoDecoder_Reset(OH_AVCodec *codec)](#oh_videodecoder_reset) | Resets a video decoder. The decoder returns to the initial state. To continue decoding, you must call **OH_VideoDecoder_Configure** to configure the decoder again.| 55| [OH_AVFormat *OH_VideoDecoder_GetOutputDescription(OH_AVCodec *codec)](#oh_videodecoder_getoutputdescription) | Obtains the OH_AVFormat information about the output data of a video decoder. For details, see [OH_AVFormat](capi-core-oh-avformat.md). You must call **OH_AVFormat_Destroy** to release the OH_AVFormat instance when its lifecycle ends.| 56| [OH_AVErrCode OH_VideoDecoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format)](#oh_videodecoder_setparameter) | Sets dynamic parameters for a video decoder. This function can be called only after the decoder is started. Incorrect parameter settings may cause decoding failure.| 57| [OH_AVErrCode OH_VideoDecoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr)](#oh_videodecoder_pushinputdata) | Pushes the input buffer filled with data to a video decoder. The input callback reports the available input buffer and the index. For details, see **OH_AVCodecOnNeedInputData**. After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the input callback. In addition, some decoders require the input of codec-specific data, such as PPS/SPS data in H.264 format, to initialize the decoding process.| 58| [OH_AVErrCode OH_VideoDecoder_RenderOutputData(OH_AVCodec *codec, uint32_t index)](#oh_videodecoder_renderoutputdata) | Frees an output buffer of a video decoder and instructs the decoder to render the decoded data in the buffer on the output surface. If no output surface is configured, calling this function only frees the output buffer.| 59| [OH_AVErrCode OH_VideoDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index)](#oh_videodecoder_freeoutputdata) | Frees an output buffer of a video decoder.| 60| [OH_AVErrCode OH_VideoDecoder_PushInputBuffer(OH_AVCodec *codec, uint32_t index)](#oh_videodecoder_pushinputbuffer) | Notifies a video decoder that the buffer corresponding to the index has been filled with input data. The input callback reports the available input buffer and the index. For details, see **OH_AVCodecOnNeedInputBuffer**. After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the input callback. In addition, some decoders require the input of codec-specific data, such as PPS/SPS data in H.264 format, to initialize the decoding process. This function is used to transfer the parameters (such as H.264 PPS/SPS) required for decoding to the decoder. The parameters can be transferred to the decoder separately or together with the data to be decoded.| 61| [OH_AVErrCode OH_VideoDecoder_RenderOutputBuffer(OH_AVCodec *codec, uint32_t index)](#oh_videodecoder_renderoutputbuffer) | Returns the output buffer corresponding to the index to a video decoder. The buffer carries the decoded data and is used to instruct the decoder to finish rendering on the output surface. If no output surface is configured, calling this function only frees the output buffer.| 62| [OH_AVErrCode OH_VideoDecoder_RenderOutputBufferAtTime(OH_AVCodec *codec, uint32_t index, int64_t renderTimestampNs)](#oh_videodecoder_renderoutputbufferattime) | Returns the output buffer corresponding to the index to a video decoder. The buffer carries the decoded data and is used to instruct the decoder to finish rendering within the specified duration on the output surface. If no output surface is configured, calling this function only frees the output buffer. You can request the system to render the buffer at a specific time (after the VSYNC or buffer timestamp) based on the timestamp. To render the buffer at the specified timestamp, that timestamp should approximate the current system time within an acceptable margin of error. Pay attention to the following: 1. Buffers are processed sequentially, which may result in the display of subsequent buffers on the surface being blocked. This is particularly important for interactive scenarios, such as responding to user actions like stopping, fast-forwarding, or rewinding a video.2. If multiple buffers are sent to the surface for rendering on a single VSYNC event, the last buffer is rendered and other buffers are discarded.3. If the difference between the timestamp and the current system time exceeds the acceptable margin of error, the surface ignores the timestamp and renders the buffer at the earliest feasible time. In this case, no frames are discarded.| 63| [OH_AVErrCode OH_VideoDecoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index)](#oh_videodecoder_freeoutputbuffer) | Frees an output buffer of a video decoder. You need to call this function to release the output buffer in a timely manner. Otherwise, the decoding process is blocked.| 64| [OH_AVErrCode OH_VideoDecoder_IsValid(OH_AVCodec *codec, bool *isValid)](#oh_videodecoder_isvalid) | Checks whether a video decoder instance is valid.| 65| [OH_AVErrCode OH_VideoDecoder_SetDecryptionConfig(OH_AVCodec *codec, MediaKeySession *mediaKeySession,bool secureVideoPath)](#oh_videodecoder_setdecryptionconfig) | Sets the decryption configuration. This function can be called prior to **OH_VideoDecoder_Prepare**.| 66| [OH_AVErrCode OH_VideoDecoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)](#oh_videodecoder_queryinputbuffer) | Obtains the index of the next available input buffer. After calling this function, you must call [OH_VideoDecoder_GetInputBuffer](#oh_videodecoder_getinputbuffer) to obtain the buffer instance and call [OH_VideoDecoder_PushInputBuffer](#oh_videodecoder_pushinputbuffer) to pass the buffer instance to the decoder.<br> Note that the preceding operations are supported only in synchronous mode.| 67| [OH_AVBuffer *OH_VideoDecoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index)](#oh_videodecoder_getinputbuffer) | Obtains the instance of the available input buffer. Note that this function works only in synchronous mode.| 68| [OH_AVErrCode OH_VideoDecoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs)](#oh_videodecoder_queryoutputbuffer) | Obtains the index of the next available output buffer. You can perform the following operations to display or release the decoded frame of the buffer instance obtained through [OH_VideoDecoder_GetOutputBuffer](#oh_videodecoder_getoutputbuffer):<br> 1. Return the processed output buffer to the decoder by calling [OH_VideoDecoder_FreeOutputBuffer](#oh_videodecoder_freeoutputbuffer).<br> 2. Render the output surface by calling [OH_VideoDecoder_RenderOutputBuffer](#oh_videodecoder_renderoutputbuffer).<br> 3. Render the output surface within the specified time by calling [OH_VideoDecoder_RenderOutputBufferAtTime](#oh_videodecoder_renderoutputbufferattime).<br> Note that the preceding operations are supported only in synchronous mode.| 69| [OH_AVBuffer *OH_VideoDecoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index)](#oh_videodecoder_getoutputbuffer) | Obtains the instance of the available output buffer. Note that this function works only in synchronous mode.| 70 71## Function Description 72 73### OH_VideoDecoder_CreateByMime() 74 75``` 76OH_AVCodec *OH_VideoDecoder_CreateByMime(const char *mime) 77``` 78 79**Description** 80 81Creates a video decoder instance based on a MIME type. This function is recommended in most cases. 82 83**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 84 85**Since**: 9 86 87 88**Parameters** 89 90| Name| Description| 91| -- | -- | 92| const char *mime | Pointer to a string that describes the MIME type. For details, see [AVCODEC_MIME_TYPE](capi-native-avcodec-base-h.md#variables).| 93 94**Returns** 95 96| Type| Description| 97| -- | -- | 98| [OH_AVCodec](capi-codecbase-oh-avcodec.md) * | Pointer to the video decoder instance.<br> If the decoder type is not supported or the memory is insufficient, NULL is returned.| 99 100### OH_VideoDecoder_CreateByName() 101 102``` 103OH_AVCodec *OH_VideoDecoder_CreateByName(const char *name) 104``` 105 106**Description** 107 108Creates a video decoder instance based on a decoder name. To use this function, you must know the exact name of the decoder. The decoder name can be obtained through capability query. 109 110For details, see [Obtaining Supported Codecs](../../media/avcodec/obtain-supported-codecs.md#creating-a-codec-with-the-specified-name). 111 112**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 113 114**Since**: 9 115 116 117**Parameters** 118 119| Name| Description| 120| -- | -- | 121| const char *name | Pointer to a video decoder name.| 122 123**Returns** 124 125| Type| Description| 126| -- | -- | 127| [OH_AVCodec](capi-codecbase-oh-avcodec.md) * | Pointer to the video decoder instance.<br> If the decoder name is not supported or the memory is insufficient, NULL is returned.| 128 129### OH_VideoDecoder_Destroy() 130 131``` 132OH_AVErrCode OH_VideoDecoder_Destroy(OH_AVCodec *codec) 133``` 134 135**Description** 136 137Clears the internal resources of a video decoder and destroys the decoder instance. You only need to call the function once. 138 139**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 140 141**Since**: 9 142 143 144**Parameters** 145 146| Name| Description| 147| -- | -- | 148| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 149 150**Returns** 151 152| Type| Description| 153| -- | -- | 154| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 155 156### OH_VideoDecoder_SetCallback() 157 158``` 159OH_AVErrCode OH_VideoDecoder_SetCallback(OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData) 160``` 161 162**Description** 163 164Sets an asynchronous callback so that your application can respond to events generated by a video decoder. This function must be called prior to **OH_VideoDecoder_Prepare**. 165 166**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 167 168**Since**: 9 169 170**Deprecated from**: 11 171 172**Substitute**: [OH_VideoDecoder_RegisterCallback](#oh_videodecoder_registercallback) 173 174 175**Parameters** 176 177| Name| Description| 178| -- | -- | 179| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 180| [OH_AVCodecAsyncCallback](capi-codecbase-oh-avcodecasynccallback.md) callback | All callback functions.| 181| void *userData | Pointer to the data on which the caller depends when executing the callback.| 182 183**Returns** 184 185| Type| Description| 186| -- | -- | 187| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br> **AV_ERR_INVALID_STATE**: The function is not called prior to **OH_VideoDecoder_Prepare**.| 188 189### OH_VideoDecoder_RegisterCallback() 190 191``` 192OH_AVErrCode OH_VideoDecoder_RegisterCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData) 193``` 194 195**Description** 196 197Registers an asynchronous callback so that your application can respond to events generated by a video decoder. This function must be called prior to **OH_VideoDecoder_Prepare**. 198 199**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 200 201**Since**: 11 202 203 204**Parameters** 205 206| Name| Description| 207| -- | -- | 208| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 209| [OH_AVCodecCallback](capi-codecbase-oh-avcodeccallback.md) callback | All callback functions.| 210| void *userData | Pointer to the data on which the caller depends when executing the callback.| 211 212**Returns** 213 214| Type| Description| 215| -- | -- | 216| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br> **AV_ERR_INVALID_STATE**: The function is not called prior to **OH_VideoDecoder_Prepare**.| 217 218### OH_VideoDecoder_SetSurface() 219 220``` 221OH_AVErrCode OH_VideoDecoder_SetSurface(OH_AVCodec *codec, OHNativeWindow *window) 222``` 223 224**Description** 225 226Sets an output surface for a video decoder.<br>In the initialization phase, this function must be called prior to **OH_VideoDecoder_Prepare**. In the executing state, it can be called directly. 227 228**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 229 230**Since**: 9 231 232 233**Parameters** 234 235| Name| Description| 236| -- | -- | 237| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 238| [OHNativeWindow](../apis-arkgraphics2d/capi-nativewindow-nativewindow.md) *window | Pointer to an OHNativeWindow instance.| 239 240**Returns** 241 242| Type| Description| 243| -- | -- | 244| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_OPERATE_NOT_PERMIT**: The function is called in the buffer mode. It can be called only in the surface mode.<br> **AV_ERR_INVALID_VAL**: 1. The value of **codec** is nullptr or does not point to a decoder instance. 2. The value of **window** is nullptr.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.| 245 246### OH_VideoDecoder_Configure() 247 248``` 249OH_AVErrCode OH_VideoDecoder_Configure(OH_AVCodec *codec, OH_AVFormat *format) 250``` 251 252**Description** 253 254Configures a video decoder. Typically, you need to configure the video description information that can be extracted from [OH_AVSource](capi-avsource-oh-avsource.md). This function must be called prior to **OH_VideoDecoder_Prepare**.<br>The value ranges of the following parameters can be obtained from [Capability Query](../../media/avcodec/obtain-supported-codecs.md). All the values of **OH_MD_KEY_ROTATION** are supported.<br>If the current platform does not support **OH_MD_KEY_VIDEO_ENABLE_LOW_LATENCY**, no error is reported and the normal decoding process is used.<br>Parameter verification rules are as follows: 255 256| Key | Value Within the Range| Value Out of Range| No Value Configured| 257| ----------| -------- | -------- | ------ | 258| OH_MD_KEY_WIDTH | AV_ERR_OK | AV_ERR_INVALID_VAL | AV_ERR_INVALID_VAL | 259| OH_MD_KEY_HEIGHT | AV_ERR_OK | AV_ERR_INVALID_VAL | AV_ERR_INVALID_VAL | 260| OH_MD_KEY_PIXEL_FORMAT<br>For details, see [OH_AVPixelFormat](capi-native-avformat-h.md#oh_avpixelformat). | AV_ERR_OK | AV_ERR_UNSUPPORT | AV_ERR_OK | 261| OH_MD_KEY_FRAME_RATE | AV_ERR_OK | AV_ERR_INVALID_VAL | AV_ERR_OK | 262| OH_MD_KEY_ROTATION<br>For details, see [OH_MD_KEY_ROTATION](capi-native-avcodec-base-h.md#variables).| AV_ERR_OK | AV_ERR_INVALID_VAL | AV_ERR_OK | 263 264> **NOTE** 265> 266> You are advised to set the parameters based on the maximum resolution supported by the instance. Otherwise, an exception may occur when streams with the resolution higher than the maximum resolution are to be decoded. This setting directly affects the memory usage of the application. 267 268**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 269 270**Since**: 9 271 272 273**Parameters** 274 275| Name| Description| 276| -- | -- | 277| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 278| [OH_AVFormat](capi-core-oh-avformat.md) *format | Pointer to an OH_AVFormat instance, which provides the description information about the video track to be decoded.| 279 280**Returns** 281 282| Type| Description| 283| -- | -- | 284| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: 1. The value of **codec** is nullptr or does not point to a decoder instance. 2. The format is not supported.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.<br> **AV_ERR_INVALID_STATE**: The function is not called prior to **OH_VideoDecoder_Prepare**.<br> **AV_ERR_VIDEO_UNSUPPORTED_COLOR_SPACE_CONVERSION**: CSC is not supported.| 285 286### OH_VideoDecoder_Prepare() 287 288``` 289OH_AVErrCode OH_VideoDecoder_Prepare(OH_AVCodec *codec) 290``` 291 292**Description** 293 294Prepares internal resources for a video decoder. This function must be called after **OH_VideoDecoder_Configure**. 295 296**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 297 298**Since**: 9 299 300 301**Parameters** 302 303| Name| Description| 304| -- | -- | 305| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 306 307**Returns** 308 309| Type| Description| 310| -- | -- | 311| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: 1. An internal execution error occurs. 2. CSC is configured, but the decoder is in buffer mode.| 312 313### OH_VideoDecoder_Start() 314 315``` 316OH_AVErrCode OH_VideoDecoder_Start(OH_AVCodec *codec) 317``` 318 319**Description** 320 321Starts a video decoder. This function should be called after a successful call of [OH_VideoDecoder_Prepare](#oh_videodecoder_prepare). After being started, the decoder starts to report the registered event. 322 323**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 324 325**Since**: 9 326 327 328**Parameters** 329 330| Name| Description| 331| -- | -- | 332| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 333 334**Returns** 335 336| Type| Description| 337| -- | -- | 338| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: 1. An internal execution error occurs. 2. CSC is configured, but **OH_VideoDecoder_Prepare** is not called.| 339 340### OH_VideoDecoder_Stop() 341 342``` 343OH_AVErrCode OH_VideoDecoder_Stop(OH_AVCodec *codec) 344``` 345 346**Description** 347 348Stops a video decoder and releases the input and output buffers. After the video decoder is stopped, you can call **OH_VideoDecoder_Start** to enter the running state again.<br>If you have passed codec-specific data in the previous **Start** for the decoder, you must pass it again. 349 350**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 351 352**Since**: 9 353 354 355**Parameters** 356 357| Name| Description| 358| -- | -- | 359| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 360 361**Returns** 362 363| Type| Description| 364| -- | -- | 365| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 366 367### OH_VideoDecoder_Flush() 368 369``` 370OH_AVErrCode OH_VideoDecoder_Flush(OH_AVCodec *codec) 371``` 372 373**Description** 374 375Clears the input and output data and parameters, for example, H.264 PPS/SPS, cached in a video decoder.<br>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. 376 377**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 378 379**Since**: 9 380 381 382**Parameters** 383 384| Name| Description| 385| -- | -- | 386| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 387 388**Returns** 389 390| Type| Description| 391| -- | -- | 392| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 393 394### OH_VideoDecoder_Reset() 395 396``` 397OH_AVErrCode OH_VideoDecoder_Reset(OH_AVCodec *codec) 398``` 399 400**Description** 401 402Resets a video decoder. The decoder returns to the initial state. To continue decoding, you must call **OH_VideoDecoder_Configure** to configure the decoder again. 403 404**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 405 406**Since**: 9 407 408 409**Parameters** 410 411| Name| Description| 412| -- | -- | 413| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 414 415**Returns** 416 417| Type| Description| 418| -- | -- | 419| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 420 421### OH_VideoDecoder_GetOutputDescription() 422 423``` 424OH_AVFormat *OH_VideoDecoder_GetOutputDescription(OH_AVCodec *codec) 425``` 426 427**Description** 428 429Obtains the OH_AVFormat information about the output data of a video decoder. For details, see [OH_AVFormat](capi-core-oh-avformat.md).<br>You must call [OH_AVFormat_Destroy](capi-native-avformat-h.md#oh_avformat_destroy) to release the OH_AVFormat instance when its lifecycle ends. 430 431**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 432 433**Since**: 9 434 435 436**Parameters** 437 438| Name| Description| 439| -- | -- | 440| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 441 442**Returns** 443 444| Type| Description| 445| -- | -- | 446| [OH_AVFormat](capi-core-oh-avformat.md) * | Pointer to an OH_AVFormat instance.<br> If the value of **codec** is nullptr or does not point to a decoder instance, NULL is returned.| 447 448### OH_VideoDecoder_SetParameter() 449 450``` 451OH_AVErrCode OH_VideoDecoder_SetParameter(OH_AVCodec *codec, OH_AVFormat *format) 452``` 453 454**Description** 455 456Sets dynamic parameters for a video decoder.<br>This function can be called only after the decoder is started. Incorrect parameter settings may cause decoding failure. 457 458**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 459 460**Since**: 9 461 462 463**Parameters** 464 465| Name| Description| 466| -- | -- | 467| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 468| [OH_AVFormat](capi-core-oh-avformat.md) *format | Pointer to an OH_AVFormat instance.| 469 470**Returns** 471 472| Type| Description| 473| -- | -- | 474| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: 1. The value of **codec** is nullptr or does not point to a decoder instance. 2. The format is not supported.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 475 476### OH_VideoDecoder_PushInputData() 477 478``` 479OH_AVErrCode OH_VideoDecoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr) 480``` 481 482**Description** 483 484Pushes the input buffer filled with data to a video decoder.<br>The input callback reports the available input buffer and the index. For details, see [OH_AVCodecOnNeedInputData](capi-native-avcodec-base-h.md#oh_avcodeconneedinputdata). After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the input callback.<br>In addition, some decoders require the input of codec-specific data, such as PPS/SPS data in H.264 format, to initialize the decoding process. 485 486**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 487 488**Since**: 9 489 490**Deprecated from**: 11 491 492**Substitute**: [OH_VideoDecoder_PushInputBuffer](#oh_videodecoder_pushinputbuffer) 493 494 495**Parameters** 496 497| Name| Description| 498| -- | -- | 499| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 500| uint32_t index | Index of an input buffer. The value is provided by [OH_AVCodecOnNeedInputData](capi-native-avcodec-base-h.md#oh_avcodeconneedinputdata).| 501| OH_AVCodecBufferAttr attr | Description information about the data in the buffer.| 502 503**Returns** 504 505| Type| Description| 506| -- | -- | 507| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 508 509### OH_VideoDecoder_RenderOutputData() 510 511``` 512OH_AVErrCode OH_VideoDecoder_RenderOutputData(OH_AVCodec *codec, uint32_t index) 513``` 514 515**Description** 516 517Frees an output buffer of a video decoder and instructs the decoder to render the decoded data in the buffer on the output surface.<br>If no output surface is configured, calling this function only frees the output buffer. 518 519**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 520 521**Since**: 9 522 523**Deprecated from**: 11 524 525**Substitute**: [OH_VideoDecoder_RenderOutputBuffer](#oh_videodecoder_renderoutputbuffer) 526 527 528**Parameters** 529 530| Name| Description| 531| -- | -- | 532| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 533| uint32_t index | Index of an output buffer. The value is provided by [OH_AVCodecOnNewOutputData](capi-native-avcodec-base-h.md#oh_avcodeconnewoutputdata).| 534 535**Returns** 536 537| Type| Description| 538| -- | -- | 539| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 540 541### OH_VideoDecoder_FreeOutputData() 542 543``` 544OH_AVErrCode OH_VideoDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index) 545``` 546 547**Description** 548 549Frees an output buffer of a video decoder. 550 551**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 552 553**Since**: 9 554 555**Deprecated from**: 11 556 557**Substitute**: [OH_VideoDecoder_FreeOutputBuffer](#oh_videodecoder_freeoutputbuffer) 558 559 560**Parameters** 561 562| Name| Description| 563| -- | -- | 564| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 565| uint32_t index | Index of an output buffer. The value is provided by [OH_AVCodecOnNewOutputData](capi-native-avcodec-base-h.md#oh_avcodeconnewoutputdata).| 566 567**Returns** 568 569| Type| Description| 570| -- | -- | 571| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 572 573### OH_VideoDecoder_PushInputBuffer() 574 575``` 576OH_AVErrCode OH_VideoDecoder_PushInputBuffer(OH_AVCodec *codec, uint32_t index) 577``` 578 579**Description** 580 581Notifies a video decoder that the buffer corresponding to the index has been filled with input data.<br>The input callback reports the available input buffer and the index. For details, see [OH_AVCodecOnNeedInputBuffer](capi-native-avcodec-base-h.md#oh_avcodeconneedinputbuffer). After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the input callback.<br>In addition, some decoders require the input of codec-specific data, such as PPS/SPS data in H.264 format, to initialize the decoding process.<br>This function is used to transfer the parameters (such as H.264 PPS/SPS) required for decoding to the decoder. The parameters can be transferred to the decoder separately or together with the data to be decoded. 582 583**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 584 585**Since**: 11 586 587 588**Parameters** 589 590| Name| Description| 591| -- | -- | 592| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 593| uint32_t index | Index of an input buffer. The value is provided by [OH_AVCodecOnNeedInputBuffer](capi-native-avcodec-base-h.md#oh_avcodeconneedinputbuffer).| 594 595**Returns** 596 597| Type| Description| 598| -- | -- | 599| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 600 601### OH_VideoDecoder_RenderOutputBuffer() 602 603``` 604OH_AVErrCode OH_VideoDecoder_RenderOutputBuffer(OH_AVCodec *codec, uint32_t index) 605``` 606 607**Description** 608 609Returns the output buffer corresponding to the index to a video decoder. The buffer carries the decoded data and is used to instruct the decoder to finish rendering on the output surface.<br>If no output surface is configured, calling this function only frees the output buffer. 610 611**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 612 613**Since**: 11 614 615 616**Parameters** 617 618| Name| Description| 619| -- | -- | 620| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 621| uint32_t index | Index of an output buffer. The value is provided by [OH_AVCodecOnNewOutputBuffer](capi-native-avcodec-base-h.md#oh_avcodeconnewoutputbuffer).| 622 623**Returns** 624 625| Type| Description| 626| -- | -- | 627| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 628 629### OH_VideoDecoder_RenderOutputBufferAtTime() 630 631``` 632OH_AVErrCode OH_VideoDecoder_RenderOutputBufferAtTime(OH_AVCodec *codec, uint32_t index, int64_t renderTimestampNs) 633``` 634 635**Description** 636 637Returns the output buffer corresponding to the index to a video decoder. The buffer carries the decoded data and is used to instruct the decoder to finish rendering within the specified duration on the output surface.<br>If no output surface is configured, calling this function only frees the output buffer.<br>You can request the system to render the buffer at a specific time (after the VSYNC or buffer timestamp) based on the timestamp. To render the buffer at the specified timestamp, that timestamp should approximate the current system time within an acceptable margin of error. Pay attention to the following:<br>1. Buffers are processed sequentially, which may result in the display of subsequent buffers on the surface being blocked. This is particularly important for interactive scenarios, such as responding to user actions like stopping, fast-forwarding, or rewinding a video.<br>2. If multiple buffers are sent to the surface for rendering on a single VSYNC event, the last buffer is rendered and other buffers are discarded.<br>3. If the difference between the timestamp and the current system time exceeds the acceptable margin of error, the surface ignores the timestamp and renders the buffer at the earliest feasible time. In this case, no frames are discarded. 638 639**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 640 641**Since**: 12 642 643 644**Parameters** 645 646| Name| Description| 647| -- | -- | 648| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 649| uint32_t index | Index of an output buffer. The value is provided by [OH_AVCodecOnNewOutputBuffer](capi-native-avcodec-base-h.md#oh_avcodeconnewoutputbuffer).| 650| int64_t renderTimestampNs | Timestamp (in nanoseconds) when the output buffer is sent to the surface. The value must be greater than 0 and should be generated by the clock of the std::chrono::steady_clock standard library.| 651 652**Returns** 653 654| Type| Description| 655| -- | -- | 656| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 657 658### OH_VideoDecoder_FreeOutputBuffer() 659 660``` 661OH_AVErrCode OH_VideoDecoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index) 662``` 663 664**Description** 665 666Frees an output buffer of a video decoder. You need to call this function to release the output buffer in a timely manner. Otherwise, the decoding process is blocked.<br>For details, see step 12 in surface mode or step 10 in buffer mode in [Video Decoding](../../media/avcodec/video-decoding.md). 667 668**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 669 670**Since**: 11 671 672 673**Parameters** 674 675| Name| Description| 676| -- | -- | 677| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 678| uint32_t index | Index of an output buffer. The value is provided by [OH_AVCodecOnNewOutputBuffer](capi-native-avcodec-base-h.md#oh_avcodeconnewoutputbuffer).| 679 680**Returns** 681 682| Type| Description| 683| -- | -- | 684| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: 1. The value of **codec** is nullptr or does not point to a decoder instance. 2. The index is invalid or the same index is used consecutively. This error does not affect the subsequent decoding process.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: An internal execution error occurs.| 685 686### OH_VideoDecoder_IsValid() 687 688``` 689OH_AVErrCode OH_VideoDecoder_IsValid(OH_AVCodec *codec, bool *isValid) 690``` 691 692**Description** 693 694Checks whether the decoder service is valid when a decoder instance exists. 695 696**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 697 698**Since**: 10 699 700 701**Parameters** 702 703| Name| Description| 704| -- | -- | 705| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 706| bool *isValid | Pointer of the Boolean type. The value indicates the validity of the decoder service only when the function returns **AV_ERR_OK**. The value **true** means that the decoder service is valid, and **false** means the opposite. It is recommended that you initialize **isValid** to **false**.| 707 708**Returns** 709 710| Type| Description| 711| -- | -- | 712| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.| 713 714### OH_VideoDecoder_SetDecryptionConfig() 715 716``` 717OH_AVErrCode OH_VideoDecoder_SetDecryptionConfig(OH_AVCodec *codec, MediaKeySession *mediaKeySession,bool secureVideoPath) 718``` 719 720**Description** 721 722Sets the decryption configuration. This function can be called prior to **OH_VideoDecoder_Prepare**. 723 724**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 725 726**Since**: 11 727 728 729**Parameters** 730 731| Name| Description| 732| -- | -- | 733| [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 734| [MediaKeySession](capi-videodecoder-mediakeysession.md) *mediaKeySession | Pointer to a media key session instance with decryption capabilities.| 735| bool secureVideoPath | Whether a secure video channel is used. The value **true** means a secure video channel, and **false** means a non-secure video channel. In [surface mode](../../media/avcodec/video-decoding.md#surface-mode), both secure and non-secure video channels are supported. In [buffer mode](../../media/avcodec/video-decoding.md#buffer-mode), only non-secure video channels are supported.| 736 737**Returns** 738 739| Type| Description| 740| -- | -- | 741| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_OPERATE_NOT_PERMIT**: 1. An internal execution error occurs. 2. The decoding service process is abnormal. 3. The media key session service is in an error state.<br> **AV_ERR_INVALID_VAL**: 1. The value of **codec** is nullptr or does not point to a decoder instance. 2. The value of **mediaKeySession** is nullptr or invalid.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.| 742 743### OH_VideoDecoder_QueryInputBuffer() 744 745``` 746OH_AVErrCode OH_VideoDecoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs) 747``` 748 749**Description** 750 751Obtains the index of the next available input buffer.<br>After calling this function, you must call [OH_VideoDecoder_GetInputBuffer](#oh_videodecoder_getinputbuffer) to obtain the buffer instance and call [OH_VideoDecoder_PushInputBuffer](#oh_videodecoder_pushinputbuffer) to pass the buffer instance to the decoder.<br> Note that the preceding operations are supported only in synchronous mode. 752 753**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 754 755**Since**: 20 756 757 758**Parameters** 759 760| Name| Description| 761| -- | -- | 762| struct [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 763| uint32_t *index | Index of an input buffer.| 764| int64_t timeoutUs | Timeout duration, in microseconds. A negative value means to wait infinitely. The value **0** means to return immediately. A positive value means to wait for the specified time before exiting.| 765 766**Returns** 767 768| Type| Description| 769| -- | -- | 770| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_SERVICE_DIED**: The codec service has been terminated.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: This function is called in asynchronous mode.<br> **AV_ERR_TRY_AGAIN_LATER**: The query fails. Try again after a short interval.| 771 772### OH_VideoDecoder_GetInputBuffer() 773 774``` 775OH_AVBuffer *OH_VideoDecoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index) 776``` 777 778**Description** 779 780Obtains the instance of the available input buffer.<br>Note that this function works only in synchronous mode. 781 782**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 783 784**Since**: 20 785 786 787**Parameters** 788 789| Name| Description| 790| -- | -- | 791| struct [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 792| uint32_t index | Index of the input buffer. It can be obtained by calling [OH_VideoDecoder_QueryInputBuffer](#oh_videodecoder_queryinputbuffer).| 793 794**Returns** 795 796| Type| Description| 797| -- | -- | 798| [OH_AVBuffer](capi-core-oh-avbuffer.md) * | Pointer to the OH_AVBuffer instance created. If the operation fails, NULL is returned.| 799 800### OH_VideoDecoder_QueryOutputBuffer() 801 802``` 803OH_AVErrCode OH_VideoDecoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs) 804``` 805 806**Description** 807 808Obtains the index of the next available output buffer.<br>You can perform the following operations to display or release the decoded frame of the buffer instance obtained through [OH_VideoDecoder_GetOutputBuffer](#oh_videodecoder_getoutputbuffer):<br> 1. Return the processed output buffer to the decoder by calling [OH_VideoDecoder_FreeOutputBuffer](#oh_videodecoder_freeoutputbuffer).<br> 2. Render the output surface by calling [OH_VideoDecoder_RenderOutputBuffer](#oh_videodecoder_renderoutputbuffer).<br> 3. Render the output surface within the specified time by calling [OH_VideoDecoder_RenderOutputBufferAtTime](#oh_videodecoder_renderoutputbufferattime).<br> Note that the preceding operations are supported only in synchronous mode. 809 810**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 811 812**Since**: 20 813 814 815**Parameters** 816 817| Name| Description| 818| -- | -- | 819| struct [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 820| uint32_t *index | Index of an output buffer.| 821| int64_t timeoutUs | Timeout duration, in microseconds. A negative value means to wait infinitely. The value **0** means to return immediately. A positive value means to wait for the specified time before exiting.| 822 823**Returns** 824 825| Type| Description| 826| -- | -- | 827| [OH_AVErrCode](capi-native-averrors-h.md#oh_averrcode) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_NO_MEMORY**: The decoder instance has been destroyed.<br> **AV_ERR_INVALID_VAL**: The value of **codec** is nullptr or does not point to a decoder instance.<br> **AV_ERR_UNKNOWN**: An unknown error occurs.<br> **AV_ERR_SERVICE_DIED**: The codec service has been terminated.<br> **AV_ERR_INVALID_STATE**: The function is called in an incorrect state.<br> **AV_ERR_OPERATE_NOT_PERMIT**: This function is called in asynchronous mode.<br> **AV_ERR_STREAM_CHANGED**: The stream format has changed. You can call [OH_VideoDecoder_GetOutputDescription](#oh_videodecoder_getoutputdescription) to obtain the new stream information.<br> **AV_ERR_TRY_AGAIN_LATER**: The query fails. Try again after a short interval.| 828 829### OH_VideoDecoder_GetOutputBuffer() 830 831``` 832OH_AVBuffer *OH_VideoDecoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index) 833``` 834 835**Description** 836 837Obtains the instance of the available output buffer.<br>Note that this function works only in synchronous mode. 838 839**System capability**: SystemCapability.Multimedia.Media.VideoDecoder 840 841**Since**: 20 842 843 844**Parameters** 845 846| Name| Description| 847| -- | -- | 848| struct [OH_AVCodec](capi-codecbase-oh-avcodec.md) *codec | Pointer to a video decoder instance.| 849| uint32_t index | Index of the output buffer. It can be obtained by calling [OH_VideoDecoder_QueryOutputBuffer](#oh_videodecoder_queryoutputbuffer).| 850 851**Returns** 852 853| Type| Description| 854| -- | -- | 855| [OH_AVBuffer](capi-core-oh-avbuffer.md) * | Pointer to the OH_AVBuffer instance created. If the operation fails, NULL is returned.| 856 857<!--no_check-->