_video_decoder.md 16.1 KB
Newer Older
Z
zengyawen 已提交
1
# VideoDecoder
Z
zengyawen 已提交
2 3 4 5


## Overview

G
Gloria 已提交
6
Provides the functions for video decoding. This module may not be supported on some devices. You can call [CanIUse](../syscap.md) to check whether this module is supported on your device.
Z
zengyawen 已提交
7

G
Gloria 已提交
8
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
9

G
Gloria 已提交
10
**Since**
Z
zengyawen 已提交
11 12 13 14 15 16 17 18
9


## Summary


### Files

G
Gloria 已提交
19
  | Name| Description| 
Z
zengyawen 已提交
20
| -------- | -------- |
G
Gloria 已提交
21
| [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> | 
Z
zengyawen 已提交
22 23 24 25


### Functions

G
Gloria 已提交
26
  | Name| Description| 
Z
zengyawen 已提交
27
| -------- | -------- |
G
Gloria 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| [OH_VideoDecoder_CreateByMime](#oh_videodecoder_createbymime) (const char \*mime) | Creates a video decoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases. | 
| [OH_VideoDecoder_CreateByName](#oh_videodecoder_createbyname) (const char \*name) | Creates a video decoder instance based on a video decoder name. To use this API, you must know the exact name of the video decoder. | 
| [OH_VideoDecoder_Destroy](#oh_videodecoder_destroy) (OH_AVCodec \*codec) | Clears the internal resources of a video decoder and destroys the video decoder instance. | 
| [OH_VideoDecoder_SetCallback](#oh_videodecoder_setcallback) (OH_AVCodec \*codec, [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md) callback, void \*userData) | Sets an asynchronous callback so that your application can respond to events generated by a video decoder. This API must be called prior to **Prepare**. | 
| [OH_VideoDecoder_SetSurface](#oh_videodecoder_setsurface) (OH_AVCodec \*codec, OHNativeWindow \*window) | Sets an output surface for a video decoder. This API must be called prior to **Prepare**. | 
| [OH_VideoDecoder_Configure](#oh_videodecoder_configure) (OH_AVCodec \*codec, OH_AVFormat \*format) | Configures a video decoder. Typically, you need to configure the attributes, which can be extracted from the container, of the video track that can be decoded. This API must be called prior to **Prepare**. | 
| [OH_VideoDecoder_Prepare](#oh_videodecoder_prepare) (OH_AVCodec \*codec) | Prepares internal resources for a video decoder. This API must be called after **Configure**. | 
| [OH_VideoDecoder_Start](#oh_videodecoder_start) (OH_AVCodec \*codec) | Starts a video decoder. This API can be called only after the decoder is prepared successfully. After being started, the decoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event. | 
| [OH_VideoDecoder_Stop](#oh_videodecoder_stop) (OH_AVCodec \*codec) | Stops a video decoder. After the decoder is stopped, you can call **Start** to start it again. If you have passed codec-specific data in the previous **Start** for the decoder, you must pass it again. | 
| [OH_VideoDecoder_Flush](#oh_videodecoder_flush) (OH_AVCodec \*codec) | Clears the input and output data in the internal buffer of a video decoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required. | 
| [OH_VideoDecoder_Reset](#oh_videodecoder_reset) (OH_AVCodec \*codec) | Resets a video decoder. To continue decoding, you must call **Configure** and **Start** to configure and start the decoder again. | 
| [OH_VideoDecoder_GetOutputDescription](#oh_videodecoder_getoutputdescription) (OH_AVCodec \*codec) | Obtains the attributes of the output data of a video decoder. The **OH_AVFormat** instance in the return value will become invalid when this API is called again or when the **OH_AVCodec** instance is destroyed. | 
| [OH_VideoDecoder_SetParameter](#oh_videodecoder_setparameter) (OH_AVCodec \*codec, OH_AVFormat \*format) | Sets dynamic parameters for a video decoder. This API can be called only after the decoder is started. Incorrect parameter settings may cause decoding failure. | 
| [OH_VideoDecoder_PushInputData](#oh_videodecoder_pushinputdata) (OH_AVCodec \*codec, uint32_t index, [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md) attr) | Pushes the input buffer filled with data to a video decoder. The [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback reports available input buffers and their indexes. After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) 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. | 
| [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. If no output surface is configured, calling this API only frees the output buffer. | 
| [OH_VideoDecoder_FreeOutputData](#oh_videodecoder_freeoutputdata) (OH_AVCodec \*codec, uint32_t index) | Frees an output buffer of a video decoder. | 
Z
zengyawen 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57


## Function Description


### OH_VideoDecoder_Configure()

  
```
OH_AVErrCode OH_VideoDecoder_Configure (OH_AVCodec * codec, OH_AVFormat * format )
```
**Description**<br>
Configures a video decoder. Typically, you need to configure the attributes, which can be extracted from the container, of the video track that can be decoded. This API must be called prior to **Prepare**.

G
Gloria 已提交
58
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
59

G
Gloria 已提交
60
**Parameters**
Z
zengyawen 已提交
61

G
Gloria 已提交
62
  | Name| Description| 
Z
zengyawen 已提交
63
| -------- | -------- |
G
Gloria 已提交
64 65
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
| format | Indicates the handle to an **OH_AVFormat** instance, which provides the attributes of the video track to be decoded. | 
Z
zengyawen 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_CreateByMime()

  
```
OH_AVCodec* OH_VideoDecoder_CreateByMime (const char * mime)
```
**Description**<br>
Creates a video decoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This API is recommended in most cases.

G
Gloria 已提交
83
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
84

G
Gloria 已提交
85
**Parameters**
Z
zengyawen 已提交
86

G
Gloria 已提交
87
  | Name| Description| 
Z
zengyawen 已提交
88
| -------- | -------- |
G
Gloria 已提交
89
| mime | Indicates the pointer to a MIME type. For details, see [OH_AVCODEC_MIMETYPE_VIDEO_AVC](_codec_base.md#oh_avcodec_mimetype_video_avc).| 
Z
zengyawen 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

**Returns**

Returns the pointer to an **OH_AVCodec** instance.


### OH_VideoDecoder_CreateByName()

  
```
OH_AVCodec* OH_VideoDecoder_CreateByName (const char * name)
```
**Description**<br>
Creates a video decoder instance based on a video decoder name. To use this API, you must know the exact name of the video decoder.

G
Gloria 已提交
105
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
106

G
Gloria 已提交
107
**Parameters**
Z
zengyawen 已提交
108

G
Gloria 已提交
109
  | Name| Description| 
Z
zengyawen 已提交
110
| -------- | -------- |
G
Gloria 已提交
111
| name | Indicates the pointer to a video decoder name. | 
Z
zengyawen 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

**Returns**

Returns the pointer to an **OH_AVCodec** instance.


### OH_VideoDecoder_Destroy()

  
```
OH_AVErrCode OH_VideoDecoder_Destroy (OH_AVCodec * codec)
```
**Description**<br>
Clears the internal resources of a video decoder and destroys the video decoder instance.

G
Gloria 已提交
127
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
128

G
Gloria 已提交
129
**Parameters**
Z
zengyawen 已提交
130

G
Gloria 已提交
131
  | Name| Description| 
Z
zengyawen 已提交
132
| -------- | -------- |
G
Gloria 已提交
133
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
Z
zengyawen 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_Flush()

  
```
OH_AVErrCode OH_VideoDecoder_Flush (OH_AVCodec * codec)
```
**Description**<br>
Clears the input and output data in the internal buffer of a video decoder. This API invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this API, ensure that the buffers corresponding to the indexes are no longer required.

G
Gloria 已提交
151
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
152

G
Gloria 已提交
153
**Parameters**
Z
zengyawen 已提交
154

G
Gloria 已提交
155
  | Name| Description| 
Z
zengyawen 已提交
156
| -------- | -------- |
G
Gloria 已提交
157
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
Z
zengyawen 已提交
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_FreeOutputData()

  
```
OH_AVErrCode OH_VideoDecoder_FreeOutputData (OH_AVCodec * codec, uint32_t index )
```
**Description**<br>
Frees an output buffer of a video decoder.

G
Gloria 已提交
175
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
176

G
Gloria 已提交
177
**Parameters**
Z
zengyawen 已提交
178

G
Gloria 已提交
179
  | Name| Description| 
Z
zengyawen 已提交
180
| -------- | -------- |
G
Gloria 已提交
181 182
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
| index | Indicates the index of an output buffer. | 
Z
zengyawen 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_GetOutputDescription()

  
```
OH_AVFormat* OH_VideoDecoder_GetOutputDescription (OH_AVCodec * codec)
```
**Description**<br>
Obtains the attributes of the output data of a video decoder. The **OH_AVFormat** instance in the return value will become invalid when this API is called again or when the **OH_AVCodec** instance is destroyed.

G
Gloria 已提交
200
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
201

G
Gloria 已提交
202
**Parameters**
Z
zengyawen 已提交
203

G
Gloria 已提交
204
  | Name| Description| 
Z
zengyawen 已提交
205
| -------- | -------- |
G
Gloria 已提交
206
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
Z
zengyawen 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

**Returns**

Returns the pointer to an **OH_AVFormat** instance.


### OH_VideoDecoder_Prepare()

  
```
OH_AVErrCode OH_VideoDecoder_Prepare (OH_AVCodec * codec)
```
**Description**<br>
Prepares internal resources for a video decoder. This API must be called after **Configure**.

G
Gloria 已提交
222
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
223

G
Gloria 已提交
224
**Parameters**
Z
zengyawen 已提交
225

G
Gloria 已提交
226
  | Name| Description| 
Z
zengyawen 已提交
227
| -------- | -------- |
G
Gloria 已提交
228
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
Z
zengyawen 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_PushInputData()

  
```
OH_AVErrCode OH_VideoDecoder_PushInputData (OH_AVCodec * codec, uint32_t index, OH_AVCodecBufferAttr attr )
```
**Description**<br>
Pushes the input buffer filled with data to a video decoder. The [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) callback reports available input buffers and their indexes. After being pushed to the decoder, a buffer is not accessible until the buffer with the same index is reported again through the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) 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.

G
Gloria 已提交
246
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
247

G
Gloria 已提交
248
**Parameters**
Z
zengyawen 已提交
249

G
Gloria 已提交
250
  | Name| Description| 
Z
zengyawen 已提交
251
| -------- | -------- |
G
Gloria 已提交
252 253 254
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
| index | Indicates the index of an input buffer. | 
| attr | Indicates the attributes of the data contained in the buffer. | 
Z
zengyawen 已提交
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_RenderOutputData()

  
```
OH_AVErrCode OH_VideoDecoder_RenderOutputData (OH_AVCodec * codec, uint32_t index )
```
**Description**<br>
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 API only frees the output buffer.

G
Gloria 已提交
272
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
273

G
Gloria 已提交
274
**Parameters**
Z
zengyawen 已提交
275

G
Gloria 已提交
276
  | Name| Description| 
Z
zengyawen 已提交
277
| -------- | -------- |
G
Gloria 已提交
278 279
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
| index | Indicates the index of an output buffer. | 
Z
zengyawen 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_Reset()

  
```
OH_AVErrCode OH_VideoDecoder_Reset (OH_AVCodec * codec)
```
**Description**<br>
Resets a video decoder. To continue decoding, you must call **Configure** and **Start** to configure and start the decoder again.

G
Gloria 已提交
297
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
298

G
Gloria 已提交
299
**Parameters**
Z
zengyawen 已提交
300

G
Gloria 已提交
301
  | Name| Description| 
Z
zengyawen 已提交
302
| -------- | -------- |
G
Gloria 已提交
303
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
Z
zengyawen 已提交
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_SetCallback()

  
```
OH_AVErrCode OH_VideoDecoder_SetCallback (OH_AVCodec * codec, OH_AVCodecAsyncCallback callback, void * userData )
```
**Description**<br>
Sets an asynchronous callback so that your application can respond to events generated by a video decoder. This API must be called prior to **Prepare**.

G
Gloria 已提交
321
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
322

G
Gloria 已提交
323
**Parameters**
Z
zengyawen 已提交
324

G
Gloria 已提交
325
  | Name| Description| 
Z
zengyawen 已提交
326
| -------- | -------- |
G
Gloria 已提交
327 328 329
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
| callback | Indicates a collection of all callback functions. For details, see [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md).| 
| userData | Indicates the pointer to user-specific data. | 
Z
zengyawen 已提交
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_SetParameter()

  
```
OH_AVErrCode OH_VideoDecoder_SetParameter (OH_AVCodec * codec, OH_AVFormat * format )
```
**Description**<br>
Sets dynamic parameters for a video decoder. This API can be called only after the decoder is started. Incorrect parameter settings may cause decoding failure.

G
Gloria 已提交
347
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
348

G
Gloria 已提交
349
**Parameters**
Z
zengyawen 已提交
350

G
Gloria 已提交
351
  | Name| Description| 
Z
zengyawen 已提交
352
| -------- | -------- |
G
Gloria 已提交
353 354
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
| format | Indicates the pointer to an **OH_AVFormat** instance. | 
Z
zengyawen 已提交
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_SetSurface()

  
```
OH_AVErrCode OH_VideoDecoder_SetSurface (OH_AVCodec * codec, OHNativeWindow * window )
```
**Description**<br>
Sets an output surface for a video decoder. This API must be called prior to **Prepare**.

G
Gloria 已提交
372
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
373

G
Gloria 已提交
374
**Parameters**
Z
zengyawen 已提交
375

G
Gloria 已提交
376
  | Name| Description| 
Z
zengyawen 已提交
377
| -------- | -------- |
G
Gloria 已提交
378 379
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
| window | Indicates the pointer to an **OHNativeWindow** instance. | 
Z
zengyawen 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_Start()

  
```
OH_AVErrCode OH_VideoDecoder_Start (OH_AVCodec * codec)
```
**Description**<br>
Starts a video decoder. This API can be called only after the decoder is prepared successfully. After being started, the decoder starts to report the [OH_AVCodecOnNeedInputData](_codec_base.md#oh_avcodeconneedinputdata) event.

G
Gloria 已提交
397
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
398

G
Gloria 已提交
399
**Parameters**
Z
zengyawen 已提交
400

G
Gloria 已提交
401
  | Name| Description| 
Z
zengyawen 已提交
402
| -------- | -------- |
G
Gloria 已提交
403
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
Z
zengyawen 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.


### OH_VideoDecoder_Stop()

  
```
OH_AVErrCode OH_VideoDecoder_Stop (OH_AVCodec * codec)
```
**Description**<br>
Stops a video decoder. After the decoder is stopped, you can call **Start** to start it again. If you have passed codec-specific data in the previous **Start** for the decoder, you must pass it again.

G
Gloria 已提交
421
@syscap SystemCapability.Multimedia.Media.VideoDecoder
Z
zengyawen 已提交
422

G
Gloria 已提交
423
**Parameters**
Z
zengyawen 已提交
424

G
Gloria 已提交
425
  | Name| Description| 
Z
zengyawen 已提交
426
| -------- | -------- |
G
Gloria 已提交
427
| codec | Indicates the pointer to an **OH_AVCodec** instance. | 
Z
zengyawen 已提交
428 429 430 431 432 433

**Returns**

Returns **AV_ERR_OK** if the operation is successful.

Returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode) if the operation fails.