1# VideoDecoder 2 3 4## Overview 5 6The VideoDecoder module provides the functions for video decoding. 7 8\@syscap SystemCapability.Multimedia.Media.VideoDecoder 9 10**Since** 11 129 13 14 15## Summary 16 17 18### Files 19 20| Name| Description| 21| -------- | -------- | 22| [native_avcodec_videodecoder.h](native__avcodec__videodecoder_8h.md) | Declares the native APIs used for video decoding.<br>**File to include**: <multimedia/player_framework/native_avcodec_videodecoder.h><br>**Library**: libnative_media_vdec.so | 23 24 25### Functions 26 27| Name| Description| 28| -------- | -------- | 29| \*[OH_VideoDecoder_CreateByMime](#oh_videodecoder_createbymime) (const char \*mime) | Creates a video decoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This function is recommended in most cases.| 30| \*[OH_VideoDecoder_CreateByName](#oh_videodecoder_createbyname) (const char \*name) | Creates a video decoder instance based on a decoder name. To use this function, you must know the exact name of the decoder.| 31| [OH_VideoDecoder_Destroy](#oh_videodecoder_destroy) (OH_AVCodec \*codec) | Clears the internal resources of a video decoder and destroys the decoder instance.| 32| [OH_VideoDecoder_SetCallback](#oh_videodecoder_setcallback) (OH_AVCodec \*codec, OH_AVCodecAsyncCallback callback, void \*userData) | Sets an asynchronous callback so that your application can respond to events generated by a video decoder.| 33| [OH_VideoDecoder_SetSurface](#oh_videodecoder_setsurface) (OH_AVCodec \*codec, OHNativeWindow \*window) | Sets an output surface for a video decoder. This function must be called prior to **Prepare**.| 34| [OH_VideoDecoder_Configure](#oh_videodecoder_configure) (OH_AVCodec \*codec, OH_AVFormat \*format) | Configures a video decoder. Typically, you need to configure the video track description information that can be extracted from the container.| 35| [OH_VideoDecoder_Prepare](#oh_videodecoder_prepare) (OH_AVCodec \*codec) | Prepares internal resources for a video decoder. This function must be called after **Configure**.| 36| [OH_VideoDecoder_Start](#oh_videodecoder_start) (OH_AVCodec \*codec) | Starts a video decoder. This function can be called only after the decoder is prepared successfully.| 37| [OH_VideoDecoder_Stop](#oh_videodecoder_stop) (OH_AVCodec \*codec) | Stops a video decoder.| 38| [OH_VideoDecoder_Flush](#oh_videodecoder_flush) (OH_AVCodec \*codec) | Clears the input and output data in the internal buffer of a video decoder.| 39| [OH_VideoDecoder_Reset](#oh_videodecoder_reset) (OH_AVCodec \*codec) | Resets a video decoder.| 40| \*[OH_VideoDecoder_GetOutputDescription](#oh_videodecoder_getoutputdescription) (OH_AVCodec \*codec) | Obtains the description information about the output data of a video decoder.| 41| [OH_VideoDecoder_SetParameter](#oh_videodecoder_setparameter) (OH_AVCodec \*codec, OH_AVFormat \*format) | Sets dynamic parameters for a video decoder.| 42| [OH_VideoDecoder_PushInputData](#oh_videodecoder_pushinputdata) (OH_AVCodec \*codec, uint32_t index, OH_AVCodecBufferAttr attr) | Pushes the input buffer filled with data to a video decoder.| 43| [OH_VideoDecoder_RenderOutputData](#oh_videodecoder_renderoutputdata) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of a video decoder and instructs the decoder to render the decoded data in the buffer on the output surface.| 44| [OH_VideoDecoder_FreeOutputData](#oh_videodecoder_freeoutputdata) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of a video decoder.| 45| [OH_VideoDecoder_IsValid](#oh_videodecoder_isvalid) (OH_AVCodec \*codec, bool \*isValid) | Checks whether a video codec instance is valid.| 46 47 48## Function Description 49 50 51### OH_VideoDecoder_Configure() 52 53 54``` 55OH_AVErrCode OH_VideoDecoder_Configure (OH_AVCodec *codec, OH_AVFormat *format) 56``` 57 58**Description** 59 60Configures a video decoder. Typically, you need to configure the video track description information that can be extracted from the container. 61 62This function must be called prior to **Prepare**. 63 64\@syscap SystemCapability.Multimedia.Media.VideoDecoder 65 66**Parameters** 67 68| Name| Description| 69| -------- | -------- | 70| codec | Pointer to an **OH_AVCodec** instance.| 71| format | Pointer to an **OH_AVFormat** instance, which provides the description information about the video track to be decoded.| 72 73**Returns** 74 75Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 76 77**Since** 78 799 80 81 82### OH_VideoDecoder_CreateByMime() 83 84 85``` 86OH_AVCodec* OH_VideoDecoder_CreateByMime (const char *mime) 87``` 88 89**Description** 90 91Creates a video decoder instance based on a MIME type. This function is recommended in most cases. 92 93\@syscap SystemCapability.Multimedia.Media.VideoDecoder 94 95**Parameters** 96 97| Name| Description| 98| -------- | -------- | 99| mime | Pointer to a string that describes the MIME type. For details, see [AVCODEC_MIMETYPE](_codec_base.md#variables).| 100 101**Returns** 102 103Returns the pointer to an **OH_AVCodec** instance. 104 105**Since** 106 1079 108 109 110### OH_VideoDecoder_CreateByName() 111 112 113``` 114OH_AVCodec* OH_VideoDecoder_CreateByName (const char *name) 115``` 116 117**Description** 118 119Creates a video decoder instance based on a decoder name. To use this function, you must know the exact name of the decoder. 120 121\@syscap SystemCapability.Multimedia.Media.VideoDecoder 122 123**Parameters** 124 125| Name| Description| 126| -------- | -------- | 127| name | Pointer to a video decoder name.| 128 129**Returns** 130 131Returns the pointer to an **OH_AVCodec** instance. 132 133**Since** 134 1359 136 137 138### OH_VideoDecoder_Destroy() 139 140 141``` 142OH_AVErrCode OH_VideoDecoder_Destroy (OH_AVCodec *codec) 143``` 144 145**Description** 146 147Clears the internal resources of a video decoder and destroys the decoder instance. 148 149\@syscap SystemCapability.Multimedia.Media.VideoDecoder 150 151**Parameters** 152 153| Name| Description| 154| -------- | -------- | 155| codec | Pointer to an **OH_AVCodec** instance.| 156 157**Returns** 158 159Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 160 161**Since** 162 1639 164 165 166### OH_VideoDecoder_Flush() 167 168 169``` 170OH_AVErrCode OH_VideoDecoder_Flush (OH_AVCodec *codec) 171``` 172 173**Description** 174 175Clears the input and output data in the internal buffer of a video decoder. 176 177This 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. 178 179\@syscap SystemCapability.Multimedia.Media.VideoDecoder 180 181**Parameters** 182 183| Name| Description| 184| -------- | -------- | 185| codec | Pointer to an **OH_AVCodec** instance.| 186 187**Returns** 188 189Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 190 191**Since** 192 1939 194 195 196### OH_VideoDecoder_FreeOutputData() 197 198 199``` 200OH_AVErrCode OH_VideoDecoder_FreeOutputData (OH_AVCodec *codec, uint32_t index) 201``` 202 203**Description** 204 205Frees an output buffer of a video decoder. 206 207\@syscap SystemCapability.Multimedia.Media.VideoDecoder 208 209**Parameters** 210 211| Name| Description| 212| -------- | -------- | 213| codec | Pointer to an **OH_AVCodec** instance.| 214| index | Index of an output buffer.| 215 216**Returns** 217 218Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 219 220**Since** 221 2229 223 224 225### OH_VideoDecoder_GetOutputDescription() 226 227 228``` 229OH_AVFormat* OH_VideoDecoder_GetOutputDescription (OH_AVCodec *codec) 230``` 231 232**Description** 233 234Obtains the description information about the output data of a video decoder. For details, see **OH_AVFormat**. 235 236The caller must manually release the **OH_AVFormat** instance in the return value. 237 238\@syscap SystemCapability.Multimedia.Media.VideoDecoder 239 240**Parameters** 241 242| Name| Description| 243| -------- | -------- | 244| codec | Pointer to an **OH_AVCodec** instance.| 245 246**Returns** 247 248Returns the pointer to an **OH_AVFormat** instance. 249 250**Since** 251 2529 253 254 255### OH_VideoDecoder_IsValid() 256 257 258``` 259OH_AVErrCode OH_VideoDecoder_IsValid (OH_AVCodec *codec, bool *isValid) 260``` 261 262**Description** 263 264Checks whether a video codec instance is valid. 265 266\@syscap SystemCapability.Multimedia.Media.VideoDecoder 267 268**Parameters** 269 270| Name| Description| 271| -------- | -------- | 272| codec | Pointer to an **OH_AVCodec** instance.| 273| isVaild | Output parameter. Pointer to an instance of the Boolean type. The value **true** means that the decoder instance is valid and **false** means the opposite.| 274 275**Returns** 276 277Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 278 279**Since** 280 28110 282 283 284### OH_VideoDecoder_Prepare() 285 286 287``` 288OH_AVErrCode OH_VideoDecoder_Prepare (OH_AVCodec *codec) 289``` 290 291**Description** 292 293Prepares internal resources for a video decoder. This function must be called after **Configure**. 294 295\@syscap SystemCapability.Multimedia.Media.VideoDecoder 296 297**Parameters** 298 299| Name| Description| 300| -------- | -------- | 301| codec | Pointer to an **OH_AVCodec** instance.| 302 303**Returns** 304 305Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 306 307**Since** 308 3099 310 311 312### OH_VideoDecoder_PushInputData() 313 314 315``` 316OH_AVErrCode OH_VideoDecoder_PushInputData (OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr) 317``` 318 319**Description** 320 321Pushes the input buffer filled with data to a video decoder. 322 323The **OH_AVCodecOnNeedInputData** callback reports the available input buffer and the index. 324 325After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the **OH_AVCodecOnNeedInputData** callback. 326 327In addition, some decoders require the input of codec-specific data, such as PPS/SPS data in H.264 format, to initialize the decoding process. 328 329\@syscap SystemCapability.Multimedia.Media.VideoDecoder 330 331**Parameters** 332 333| Name| Description| 334| -------- | -------- | 335| codec | Pointer to an **OH_AVCodec** instance.| 336| index | Index of an input buffer.| 337| attr | Description information about the data in the buffer.| 338 339**Returns** 340 341Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 342 343**Since** 344 3459 346 347 348### OH_VideoDecoder_RenderOutputData() 349 350 351``` 352OH_AVErrCode OH_VideoDecoder_RenderOutputData (OH_AVCodec *codec, uint32_t index) 353``` 354 355**Description** 356 357Frees an output buffer of a video decoder and instructs the decoder to render the decoded data in the buffer on the output surface. 358 359If no output surface is configured, calling this function only frees the output buffer. 360 361\@syscap SystemCapability.Multimedia.Media.VideoDecoder 362 363**Parameters** 364 365| Name| Description| 366| -------- | -------- | 367| codec | Pointer to an **OH_AVCodec** instance.| 368| index | Index of an output buffer.| 369 370**Returns** 371 372Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 373 374**Since** 375 3769 377 378 379### OH_VideoDecoder_Reset() 380 381 382``` 383OH_AVErrCode OH_VideoDecoder_Reset (OH_AVCodec *codec) 384``` 385 386**Description** 387 388Resets a video decoder. To continue decoding, you must call **Configure** to configure the decoder again. 389 390\@syscap SystemCapability.Multimedia.Media.VideoDecoder 391 392**Parameters** 393 394| Name| Description| 395| -------- | -------- | 396| codec | Pointer to an **OH_AVCodec** instance.| 397 398**Returns** 399 400Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 401 402**Since** 403 4049 405 406 407### OH_VideoDecoder_SetCallback() 408 409 410``` 411OH_AVErrCode OH_VideoDecoder_SetCallback (OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData) 412``` 413 414**Description** 415 416Sets an asynchronous callback so that your application can respond to events generated by a video decoder. 417 418This function must be called prior to **Prepare**. 419 420\@syscap SystemCapability.Multimedia.Media.VideoDecoder 421 422**Parameters** 423 424| Name| Description| 425| -------- | -------- | 426| codec | Pointer to an **OH_AVCodec** instance.| 427| callback | Callback function to set. For details, see [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md).| 428| userData | User-specific data.| 429 430**Returns** 431 432Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 433 434**Since** 435 4369 437 438 439### OH_VideoDecoder_SetParameter() 440 441 442``` 443OH_AVErrCode OH_VideoDecoder_SetParameter (OH_AVCodec *codec, OH_AVFormat *format) 444``` 445 446**Description** 447 448Sets dynamic parameters for a video decoder. 449 450This function can be called only after the decoder is started. Incorrect parameter settings may cause decoding failure. 451 452\@syscap SystemCapability.Multimedia.Media.VideoDecoder 453 454**Parameters** 455 456| Name| Description| 457| -------- | -------- | 458| codec | Pointer to an **OH_AVCodec** instance.| 459| format | Pointer to an **OH_AVFormat** instance.| 460 461**Returns** 462 463Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 464 465**Since** 466 4679 468 469 470### OH_VideoDecoder_SetSurface() 471 472 473``` 474OH_AVErrCode OH_VideoDecoder_SetSurface (OH_AVCodec *codec, OHNativeWindow *window) 475``` 476 477**Description** 478 479Sets an output surface for a video decoder. This function must be called prior to **Prepare**. 480 481\@syscap SystemCapability.Multimedia.Media.VideoDecoder 482 483**Parameters** 484 485| Name| Description| 486| -------- | -------- | 487| codec | Pointer to an **OH_AVCodec** instance.| 488| window | Pointer to an **OHNativeWindow** instance. For details, see **OHNativeWindow**.| 489 490**Returns** 491 492Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 493 494**Since** 495 4969 497 498 499### OH_VideoDecoder_Start() 500 501 502``` 503OH_AVErrCode OH_VideoDecoder_Start (OH_AVCodec *codec) 504``` 505 506**Description** 507 508Starts a video decoder. This function can be called only after the decoder is prepared successfully. 509 510After being started, the decoder starts to report the **NeedInputData** event. 511 512\@syscap SystemCapability.Multimedia.Media.VideoDecoder 513 514**Parameters** 515 516| Name| Description| 517| -------- | -------- | 518| codec | Pointer to an **OH_AVCodec** instance.| 519 520**Returns** 521 522Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 523 524**Since** 525 5269 527 528 529### OH_VideoDecoder_Stop() 530 531 532``` 533OH_AVErrCode OH_VideoDecoder_Stop (OH_AVCodec *codec) 534``` 535 536**Description** 537 538Stops a video decoder. After the encoder is stopped, you can call **Start** to start it again. 539 540If you have passed codec-specific data in the previous **Start** for the decoder, you must pass it again. 541 542\@syscap SystemCapability.Multimedia.Media.VideoDecoder 543 544**Parameters** 545 546| Name| Description| 547| -------- | -------- | 548| codec | Pointer to an **OH_AVCodec** instance.| 549 550**Returns** 551 552Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) otherwise. 553 554**Since** 555 5569 557