1# CodecBase 2 3 4## Overview 5 6Provides the common structs, character constants, and enums for running **OH_AVCodec** instances. 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. 7 8@syscap SystemCapability.Multimedia.Media.CodecBase 9 10**Since** 119 12 13## Summary 14 15 16### Files 17 18 | Name| Description| 19| -------- | -------- | 20| [native_avcodec_base.h](native__avcodec__base_8h.md) | Declares the common structs, character constants, and enums for running <b>OH_AVCodec</b> instances.<br>File to include: <multimedia/player_framework/native_avcodec_base.h> | 21 22 23### Structs 24 25 | Name| Description| 26| -------- | -------- | 27| [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md) | Defines the buffer attributes of an **OH_AVCodec** instance. | 28| [OH_AVCodecAsyncCallback](_o_h___a_v_codec_async_callback.md) | Defines a collection of asynchronous callback functions for an **OH_AVCodec** instance. You must register this struct instance for an **OH_AVCodec** instance and process the information reported through these callbacks to ensure the normal running of the instance. | 29 30 31### Types 32 33 | Name| Description| 34| -------- | -------- | 35| [OH_AVCodecBufferFlags](#oh_avcodecbufferflags) | Enumerates the buffer flags of an **OH_AVCodec** instance. | 36| [OH_AVCodecBufferAttr](#oh_avcodecbufferattr) | Defines the buffer attributes of an **OH_AVCodec** instance. | 37| (\*[OH_AVCodecOnError](#oh_avcodeconerror)) (OH_AVCodec \*codec, int32_t errorCode, void \*userData) | Defines the function pointer that is called to report error information when an error occurs during the running of an **OH_AVCodec** instance. | 38| (\*[OH_AVCodecOnStreamChanged](#oh_avcodeconstreamchanged)) (OH_AVCodec \*codec, OH_AVFormat \*format, void \*userData) | Defines the function pointer that is called to report the attributes of the new stream when the output stream changes. Note that the lifecycle of the pointer to the **OH_AVFormat** instance is valid only when the function pointer is being called. Do not access the pointer to the instance after the function pointer is called. | 39| (\*[OH_AVCodecOnNeedInputData](#oh_avcodeconneedinputdata)) (OH_AVCodec \*codec, uint32_t index, OH_AVMemory \*data, void \*userData) | Defines the function pointer that is called, with a new buffer to fill in new input data, when new input data is required during the running of an **OH_AVCodec** instance. | 40| (\*[OH_AVCodecOnNewOutputData](#oh_avcodeconnewoutputdata)) (OH_AVCodec \*codec, uint32_t index, OH_AVMemory \*data, [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md) \*attr, void \*userData) | Defines the function pointer that is called, with a buffer containing new output data, when the new output data is generated during the running of an **OH_AVCodec** instance. Note that the lifecycle of the pointer to the **OH_AVCodecBufferAttr** instance is valid only when the function pointer is being called. Do not access the pointer to the instance after the function pointer is called. | 41| [OH_AVCodecAsyncCallback](#oh_avcodecasynccallback) | Defines a collection of asynchronous callback functions for an **OH_AVCodec** instance. You must register this struct instance for an **OH_AVCodec** instance and process the information reported through these callbacks to ensure the normal running of the instance. | 42| [OH_MediaType](#oh_mediatype) | Enumerates the media types. | 43| [OH_AVCProfile](#oh_avcprofile) | Enumerates the AVC profiles. | 44| [OH_AACProfile](#oh_aacprofile) | Enumerates the AAC profiles. | 45 46 47### Enums 48 49 | Name| Description| 50| -------- | -------- | 51| [OH_AVCodecBufferFlags](#oh_avcodecbufferflags) {<br>**AVCODEC_BUFFER_FLAGS_NONE** = 0, **AVCODEC_BUFFER_FLAGS_EOS** = 1 << 0, **AVCODEC_BUFFER_FLAGS_SYNC_FRAME** = 1 << 1, **AVCODEC_BUFFER_FLAGS_INCOMPLETE_FRAME** = 1 << 2, **AVCODEC_BUFFER_FLAGS_CODEC_DATA**= 1 << 3<br>} | Enumerates the buffer flags of an **OH_AVCodec** instance. | 52| [OH_MediaType](#oh_mediatype) { **MEDIA_TYPE_AUD** = 0, **MEDIA_TYPE_VID** = 1 } | Enumerates the media types. | 53| [OH_AVCProfile](#oh_avcprofile) { **AVC_PROFILE_BASELINE** = 0, **AVC_PROFILE_HIGH** = 4, **AVC_PROFILE_MAIN** = 8 } | Enumerates the Advanced Video Coding (AVC) profiles. | 54| [OH_AACProfile](#oh_aacprofile) { **AAC_PROFILE_LC** = 0 } | Enumerates the Advanced Audio Coding (AAC) profiles. | 55 56 57### Variables 58 59 | Name| Description| 60| -------- | -------- | 61| [OH_AVCodecBufferAttr::pts](#pts) | Defines the presentation timestamp of the buffer, in microseconds. | 62| [OH_AVCodecBufferAttr::size](#size) | Defines the size of the data contained in the buffer, in bytes. | 63| [OH_AVCodecBufferAttr::offset](#offset) | Defines the start offset of valid data in the buffer. | 64| [OH_AVCodecBufferAttr::flags](#flags) | Defines a buffer flag, which is a combination of multiple [OH_AVCodecBufferFlags](#oh_avcodecbufferflags). | 65| [OH_AVCODEC_MIMETYPE_VIDEO_AVC](#oh_avcodec_mimetype_video_avc) | Defines the Multipurpose Internet Mail Extension (MIME) type for AVC. | 66| [OH_AVCODEC_MIMETYPE_AUDIO_AAC](#oh_avcodec_mimetype_audio_aac) | Defines the MIME type for AAC. | 67| [OH_ED_KEY_TIME_STAMP](#oh_ed_key_time_stamp) | Defines the unified character descriptors for the auxiliary data of the surface buffer. | 68| [OH_ED_KEY_EOS](#oh_ed_key_eos) | Defines the character descriptor of the end-of-stream in the surface auxiliary data. The value type is bool. | 69| [OH_MD_KEY_TRACK_TYPE](#oh_md_key_track_type) | Defines the unified character descriptors for the media playback framework. | 70| [OH_MD_KEY_CODEC_MIME](#oh_md_key_codec_mime) | Defines the character descriptor of the MIME type. The value type is string. | 71| [OH_MD_KEY_DURATION](#oh_md_key_duration) | Defines the character descriptor of duration. The value type is int64_t. | 72| [OH_MD_KEY_BITRATE](#oh_md_key_bitrate) | Defines the character descriptor of the bit rate. The value type is uint32_t. | 73| [OH_MD_KEY_MAX_INPUT_SIZE](#oh_md_key_max_input_size) | Defines the character descriptor of the maximum input size. The value type is uint32_t. | 74| [OH_MD_KEY_WIDTH](#oh_md_key_width) | Defines the character descriptor of the video width. The value type is uint32_t. | 75| [OH_MD_KEY_HEIGHT](#oh_md_key_height) | Defines the character descriptor of the video height. The value type is uint32_t. | 76| [OH_MD_KEY_PIXEL_FORMAT](#oh_md_key_pixel_format) | Defines the character descriptor of the video pixel format. The value type is int32_t. For details, see [OH_AVPixelFormat](_core.md#oh_avpixelformat).| 77| [OH_MD_KEY_AUDIO_SAMPLE_FORMAT](#oh_md_key_audio_sample_format) | Defines the character descriptor of the audio sample format. The value type is uint32_t. | 78| [OH_MD_KEY_FRAME_RATE](#oh_md_key_frame_rate) | Defines the character descriptor of the video frame rate. The value type is double. | 79| [OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE](#oh_md_key_video_encode_bitrate_mode) | Defines the character descriptor of the video encoding bit rate mode. The value type is int32_t. For details, see [OH_VideoEncodeBitrateMode](_video_encoder.md#oh_videoencodebitratemode).| 80| [OH_MD_KEY_PROFILE](#oh_md_key_profile) | Defines the character descriptor of the audio/video encoding capability. The value type is int32_t. For details, see [OH_AVCProfile](#oh_avcprofile) or [OH_AACProfile](#oh_aacprofile).| 81| [OH_MD_KEY_AUD_CHANNEL_COUNT](#oh_md_key_aud_channel_count) | Defines the character descriptor of the number of audio channels. The value type is uint32_t. | 82| [OH_MD_KEY_AUD_SAMPLE_RATE](#oh_md_key_aud_sample_rate) | Defines the character descriptor of the audio sampling rate. The value type is uint32_t. | 83| [OH_MD_KEY_I_FRAME_INTERVAL](#oh_md_key_i_frame_interval) | Defines the character descriptor of the I-frame interval. The value type is int32_t, and the unit is ms. | 84| [OH_MD_KEY_ROTATION](#oh_md_key_rotation) | Defines the character descriptor of the surface rotation angle. The value type is int32_t. The value range is {0, 90, 180, 270}. The default value is 0. | 85 86 87## Type Description 88 89 90### OH_AACProfile 91 92 93``` 94typedef enum OH_AACProfileOH_AACProfile 95``` 96**Description**<br> 97Enumerates the AAC profiles. 98 99@syscap SystemCapability.Multimedia.Media.CodecBase 100 101 102### OH_AVCodecAsyncCallback 103 104 105``` 106typedef struct OH_AVCodecAsyncCallbackOH_AVCodecAsyncCallback 107``` 108**Description**<br> 109Defines a collection of asynchronous callback functions for an **OH_AVCodec** instance. You must register this struct instance for an **OH_AVCodec** instance and process the information reported through these callbacks to ensure the normal running of the instance. 110 111@syscap SystemCapability.Multimedia.Media.CodecBase 112 113**Parameters** 114 115 | Name| Description| 116| -------- | -------- | 117| onError | Indicates the callback used to report errors occurred during the running of the instance. For details, see [OH_AVCodecOnError](#oh_avcodeconerror).| 118| onStreamChanged | Indicates the callback used to report stream information. For details, see [OH_AVCodecOnStreamChanged](#oh_avcodeconstreamchanged).| 119| onNeedInputData | Indicates the callback used to report input data needed. For details, see [OH_AVCodecOnNeedInputData](#oh_avcodeconneedinputdata).| 120| onNeedInputData | Indicates the callback used to report output data needed. For details, see [OH_AVCodecOnNewOutputData](#oh_avcodeconnewoutputdata).| 121 122 123### OH_AVCodecBufferAttr 124 125 126``` 127typedef struct OH_AVCodecBufferAttrOH_AVCodecBufferAttr 128``` 129**Description**<br> 130Defines the buffer attributes of an **OH_AVCodec** instance. 131 132@syscap SystemCapability.Multimedia.Media.CodecBase 133 134 135### OH_AVCodecBufferFlags 136 137 138``` 139typedef enum OH_AVCodecBufferFlagsOH_AVCodecBufferFlags 140``` 141**Description**<br> 142Enumerates the buffer flags of an **OH_AVCodec** instance. 143 144@syscap SystemCapability.Multimedia.Media.CodecBase 145 146 147### OH_AVCodecOnError 148 149 150``` 151typedef void(* OH_AVCodecOnError) (OH_AVCodec *codec, int32_t errorCode, void *userData) 152``` 153**Description**<br> 154Defines the function pointer that is called to report error information when an error occurs during the running of an **OH_AVCodec** instance. 155 156@syscap SystemCapability.Multimedia.Media.CodecBase 157 158**Parameters** 159 160 | Name| Description| 161| -------- | -------- | 162| codec | Indicates the pointer to an **OH_AVCodec** instance. | 163| errorCode | Indicates an error code. | 164| userData | Indicates the pointer to user-specific data. | 165 166 167### OH_AVCodecOnNeedInputData 168 169 170``` 171typedef void(* OH_AVCodecOnNeedInputData) (OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData) 172``` 173**Description**<br> 174Defines the function pointer that is called, with a new buffer to fill in new input data, when new input data is required during the running of an **OH_AVCodec** instance. 175 176@syscap SystemCapability.Multimedia.Media.CodecBase 177 178**Parameters** 179 180 | Name| Description| 181| -------- | -------- | 182| codec | Indicates the pointer to an **OH_AVCodec** instance. | 183| index | Indicates the index of an input buffer. | 184| data | Indicates the pointer to the new input data. | 185| userData | Indicates the pointer to user-specific data. | 186 187 188### OH_AVCodecOnNewOutputData 189 190 191``` 192typedef void(* OH_AVCodecOnNewOutputData) (OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr, void *userData) 193``` 194**Description**<br> 195Defines the function pointer that is called, with a buffer containing new output data, when the new output data is generated during the running of an **OH_AVCodec** instance. Note that the lifecycle of the pointer to the **OH_AVCodecBufferAttr** instance is valid only when the function pointer is being called. Do not access the pointer to the instance after the function pointer is called. 196 197@syscap SystemCapability.Multimedia.Media.CodecBase 198 199**Parameters** 200 201 | Name| Description| 202| -------- | -------- | 203| codec | Indicates the pointer to an **OH_AVCodec** instance. | 204| index | Indicates the index of a new output buffer. | 205| data | Indicates the pointer to the new output data. | 206| attr | Indicates the pointer to the attributes of the new output buffer. For details, see [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md).| 207| userData | Indicates the pointer to user-specific data. | 208 209 210### OH_AVCodecOnStreamChanged 211 212 213``` 214typedef void(* OH_AVCodecOnStreamChanged) (OH_AVCodec *codec, OH_AVFormat *format, void *userData) 215``` 216**Description**<br> 217Defines the function pointer that is called to report the attributes of the new stream when the output stream changes. Note that the lifecycle of the pointer to the **OH_AVFormat** instance is valid only when the function pointer is being called. Do not access the pointer to the instance after the function pointer is called. 218 219@syscap SystemCapability.Multimedia.Media.CodecBase 220 221**Parameters** 222 223 | Name| Description| 224| -------- | -------- | 225| codec | Indicates the pointer to an **OH_AVCodec** instance. | 226| format | Indicates the handle to the attributes of the new output stream. | 227| userData | Indicates the pointer to user-specific data. | 228 229 230### OH_AVCProfile 231 232 233``` 234typedef enum OH_AVCProfileOH_AVCProfile 235``` 236**Description**<br> 237Enumerates the AVC profiles. 238 239@syscap SystemCapability.Multimedia.Media.CodecBase 240 241 242### OH_MediaType 243 244 245``` 246typedef enum OH_MediaTypeOH_MediaType 247``` 248**Description**<br> 249Enumerates the media types. 250 251@syscap SystemCapability.Multimedia.Media.CodecBase 252 253 254## Enum Description 255 256 257### OH_AACProfile 258 259 260``` 261enum OH_AACProfile 262``` 263**Description**<br> 264Enumerates the AAC profiles. 265 266@syscap SystemCapability.Multimedia.Media.CodecBase 267 268 269### OH_AVCodecBufferFlags 270 271 272``` 273enum OH_AVCodecBufferFlags 274``` 275**Description**<br> 276Enumerates the buffer flags of an **OH_AVCodec** instance. 277 278@syscap SystemCapability.Multimedia.Media.CodecBase 279 280 | Value| Description| 281| -------- | -------- | 282| AVCODEC_BUFFER_FLAGS_EOS | The buffer contains an end-of-stream frame.| 283| AVCODEC_BUFFER_FLAGS_SYNC_FRAME | The buffer contains a sync frame.| 284| AVCODEC_BUFFER_FLAGS_INCOMPLETE_FRAME | The buffer contains part of a frame.| 285| AVCODEC_BUFFER_FLAGS_CODEC_DATA | The buffer contains codec-specific data.| 286 287 288### OH_AVCProfile 289 290 291``` 292enum OH_AVCProfile 293``` 294**Description**<br> 295Enumerates the AVC profiles. 296 297@syscap SystemCapability.Multimedia.Media.CodecBase 298 299 300### OH_MediaType 301 302 303``` 304enum OH_MediaType 305``` 306**Description**<br> 307Enumerates the media types. 308 309@syscap SystemCapability.Multimedia.Media.CodecBase 310 311 | Value| Description| 312| -------- | -------- | 313| MEDIA_TYPE_AUD | Audio track.| 314| MEDIA_TYPE_VID | Video track.| 315 316 317## Variable Description 318 319 320### flags 321 322 323``` 324uint32_t OH_AVCodecBufferAttr::flags 325``` 326**Description**<br> 327Defines a buffer flag, which is a combination of multiple [OH_AVCodecBufferFlags](#oh_avcodecbufferflags). 328 329 330### offset 331 332 333``` 334int32_t OH_AVCodecBufferAttr::offset 335``` 336**Description**<br> 337Start offset of valid data in the buffer. 338 339 340### OH_AVCODEC_MIMETYPE_AUDIO_AAC 341 342 343``` 344const char* OH_AVCODEC_MIMETYPE_AUDIO_AAC 345``` 346**Description**<br> 347Defines the MIME type for AAC. 348 349@syscap SystemCapability.Multimedia.Media.CodecBase 350 351 352### OH_AVCODEC_MIMETYPE_VIDEO_AVC 353 354 355``` 356const char* OH_AVCODEC_MIMETYPE_VIDEO_AVC 357``` 358**Description**<br> 359Defines the MIME type for AVC. 360 361@syscap SystemCapability.Multimedia.Media.CodecBase 362 363 364### OH_ED_KEY_EOS 365 366 367``` 368const char* OH_ED_KEY_EOS 369``` 370**Description**<br> 371Defines the character descriptor of the end-of-stream in the surface auxiliary data. The value type is bool. 372 373 374### OH_ED_KEY_TIME_STAMP 375 376 377``` 378const char* OH_ED_KEY_TIME_STAMP 379``` 380**Description**<br> 381Defines the unified character descriptors for the auxiliary data of the surface buffer. 382 383@syscap SystemCapability.Multimedia.Media.CodecBase 384 385 386### OH_MD_KEY_AUD_CHANNEL_COUNT 387 388 389``` 390const char* OH_MD_KEY_AUD_CHANNEL_COUNT 391``` 392**Description**<br> 393Defines the character descriptor of the number of audio channels. The value type is uint32_t. 394 395 396### OH_MD_KEY_AUD_SAMPLE_RATE 397 398 399``` 400const char* OH_MD_KEY_AUD_SAMPLE_RATE 401``` 402**Description**<br> 403Defines the character descriptor of the audio sampling rate. The value type is uint32_t. 404 405 406### OH_MD_KEY_AUDIO_SAMPLE_FORMAT 407 408 409``` 410const char* OH_MD_KEY_AUDIO_SAMPLE_FORMAT 411``` 412**Description**<br> 413Defines the character descriptor of the audio sample format. The value type is uint32_t. 414 415 416### OH_MD_KEY_BITRATE 417 418 419``` 420const char* OH_MD_KEY_BITRATE 421``` 422**Description**<br> 423Defines the character descriptor of the bit rate. The value type is uint32_t. 424 425 426### OH_MD_KEY_CODEC_MIME 427 428 429``` 430const char* OH_MD_KEY_CODEC_MIME 431``` 432**Description**<br> 433Defines the character descriptor of the MIME type. The value type is string. 434 435 436### OH_MD_KEY_DURATION 437 438 439``` 440const char* OH_MD_KEY_DURATION 441``` 442**Description**<br> 443Defines the character descriptor of duration. The value type is int64_t. 444 445 446### OH_MD_KEY_FRAME_RATE 447 448 449``` 450const char* OH_MD_KEY_FRAME_RATE 451``` 452**Description**<br> 453Defines the character descriptor of the video frame rate. The value type is double. 454 455 456### OH_MD_KEY_HEIGHT 457 458 459``` 460const char* OH_MD_KEY_HEIGHT 461``` 462**Description**<br> 463Defines the character descriptor of the video height. The value type is uint32_t. 464 465 466### OH_MD_KEY_I_FRAME_INTERVAL 467 468 469``` 470const char* OH_MD_KEY_I_FRAME_INTERVAL 471``` 472**Description**<br> 473Defines the character descriptor of the I-frame interval. The value type is int32_t, and the unit is ms. 474 475 476### OH_MD_KEY_MAX_INPUT_SIZE 477 478 479``` 480const char* OH_MD_KEY_MAX_INPUT_SIZE 481``` 482**Description**<br> 483Defines the character descriptor of the maximum input size. The value type is uint32_t. 484 485 486### OH_MD_KEY_PIXEL_FORMAT 487 488 489``` 490const char* OH_MD_KEY_PIXEL_FORMAT 491``` 492**Description**<br> 493Defines the character descriptor of the video pixel format. The value type is int32_t. For details, see [OH_AVPixelFormat](_core.md#oh_avpixelformat). 494 495 496### OH_MD_KEY_PROFILE 497 498 499``` 500const char* OH_MD_KEY_PROFILE 501``` 502**Description**<br> 503Defines the character descriptor of the audio/video encoding capability. The value type is int32_t. For details, see [OH_AVCProfile](#oh_avcprofile) or [OH_AACProfile](#oh_aacprofile). 504 505 506### OH_MD_KEY_ROTATION 507 508 509``` 510const char* OH_MD_KEY_ROTATION 511``` 512**Description**<br> 513Defines the character descriptor of the surface rotation angle. The value type is int32_t. The value range is {0, 90, 180, 270}. The default value is 0. 514 515 516### OH_MD_KEY_TRACK_TYPE 517 518 519``` 520const char* OH_MD_KEY_TRACK_TYPE 521``` 522**Description**<br> 523Defines the unified character descriptors for the media playback framework. 524 525@syscap SystemCapability.Multimedia.Media.CodecBase 526 527 528### OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE 529 530 531``` 532const char* OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE 533``` 534**Description**<br> 535Defines the character descriptor of the video encoding bit rate mode. The value type is int32_t. For details, see [OH_VideoEncodeBitrateMode](_video_encoder.md#oh_videoencodebitratemode). 536 537 538### OH_MD_KEY_WIDTH 539 540 541``` 542const char* OH_MD_KEY_WIDTH 543``` 544**Description**<br> 545Defines the character descriptor of the video width. The value type is uint32_t. 546 547 548### pts 549 550 551``` 552int64_t OH_AVCodecBufferAttr::pts 553``` 554**Description**<br> 555Defines the presentation timestamp of the buffer, in microseconds. 556 557 558### size 559 560 561``` 562int32_t OH_AVCodecBufferAttr::size 563``` 564**Description**<br> 565Defines the size of the data contained in the buffer, in bytes. 566