1# Core 2 3 4## Overview 5 6The **Core** module provides the basic backbone capabilities for the media playback framework, including functions related to the memory, error code, and format carrier. 7 8\@syscap SystemCapability.Multimedia.Media.Core 9 10**Since** 11 129 13 14 15## Summary 16 17 18### Files 19 20| Name| Description| 21| -------- | -------- | 22| [native_averrors.h](native__averrors_8h.md) | Declares the error codes used by the media playback framework.<br>**File to include**: <multimedia/player_framework/native_averrors.h><br>**Library**: libnative_media_core.so| 23| [native_avformat.h](native__avformat_8h.md) | Declares the format-related functions and enums.<br>**File to include**: <multimedia/player_framework/native_avformat.h><br>**Library**: libnative_media_core.so| 24| [native_avmemory.h](native__avmemory_8h.md) | Declares the memory-related functions.<br>**File to include**: <multimedia/player_framework/native_avmemory.h><br>**Library**: libnative_media_core.so| 25 26 27### Types 28 29| Name| Description| 30| -------- | -------- | 31| [OH_AVErrCode](#oh_averrcode) | Defines an enum that enumerates the audio and video error codes.| 32| [OH_AVPixelFormat](#oh_avpixelformat) | Defines an enum that enumerates the audio and video pixel formats.| 33 34 35### Enums 36 37| Name| Description| 38| -------- | -------- | 39| [OH_AVErrCode](#oh_averrcode) {<br> AV_ERR_OK = 0,<br> AV_ERR_NO_MEMORY = 1,<br> AV_ERR_OPERATE_NOT_PERMIT = 2,<br> AV_ERR_INVALID_VAL = 3,<br> AV_ERR_IO = 4,<br> AV_ERR_TIMEOUT = 5,<br> AV_ERR_UNKNOWN = 6,<br> AV_ERR_SERVICE_DIED = 7,<br> AV_ERR_INVALID_STATE = 8,<br> AV_ERR_UNSUPPORT = 9,<br> AV_ERR_EXTEND_START = 100<br>} | Enumerates the audio and video error codes.| 40| [OH_AVPixelFormat](#oh_avpixelformat) {<br> AV_PIXEL_FORMAT_YUVI420 = 1,<br> AV_PIXEL_FORMAT_NV12 = 2,<br> AV_PIXEL_FORMAT_NV21 = 3,<br> AV_PIXEL_FORMAT_SURFACE_FORMAT = 4,<br> AV_PIXEL_FORMAT_RGBA = 5<br>} | Enumerates the audio and video pixel formats.| 41 42 43### Functions 44 45| Name| Description| 46| -------- | -------- | 47| \*[OH_AVFormat_Create](#oh_avformat_create) (void) | Creates an **OH_AVFormat** instance for reading data.| 48| \*[OH_AVFormat_CreateAudioFormat](#oh_avformat_createaudioformat) (const char \*mimeType, int32_t sampleRate, int32_t channelCount) | Creates an audio **OH_AVFormat** instance for reading and writing data.| 49| \*[OH_AVFormat_CreateVideoFormat](#oh_avformat_createvideoformat) (const char \*mimeType, int32_t width, int32_t height) | Creates a video **OH_AVFormat** instance for reading and writing data.| 50| [OH_AVFormat_Destroy](#oh_avformat_destroy) (struct OH_AVFormat \*format) | Destroys an **OH_AVFormat** instance.| 51| [OH_AVFormat_Copy](#oh_avformat_copy) (struct OH_AVFormat \*to, struct OH_AVFormat \*from) | Copies an **OH_AVFormat** instance.| 52| [OH_AVFormat_SetIntValue](#oh_avformat_setintvalue) (struct OH_AVFormat \*format, const char \*key, int32_t value) | Writes data of the int type to an **OH_AVFormat** instance.| 53| [OH_AVFormat_SetLongValue](#oh_avformat_setlongvalue) (struct OH_AVFormat \*format, const char \*key, int64_t value) | Writes data of the long type to an **OH_AVFormat** instance.| 54| [OH_AVFormat_SetFloatValue](#oh_avformat_setfloatvalue) (struct OH_AVFormat \*format, const char \*key, float value) | Writes data of the float type to an **OH_AVFormat** instance.| 55| [OH_AVFormat_SetDoubleValue](#oh_avformat_setdoublevalue) (struct OH_AVFormat \*format, const char \*key, double value) | Writes data of the double type to an **OH_AVFormat** instance.| 56| [OH_AVFormat_SetStringValue](#oh_avformat_setstringvalue) (struct OH_AVFormat \*format, const char \*key, const char \*value) | Writes data of the string type to an **OH_AVFormat** instance.| 57| [OH_AVFormat_SetBuffer](#oh_avformat_setbuffer) (struct OH_AVFormat \*format, const char \*key, const uint8_t \*addr, size_t size) | Writes data blocks of a specified length to an **OH_AVFormat** instance.| 58| [OH_AVFormat_GetIntValue](#oh_avformat_getintvalue) (struct OH_AVFormat \*format, const char \*key, int32_t \*out) | Reads data of the int type from an **OH_AVFormat** instance.| 59| [OH_AVFormat_GetLongValue](#oh_avformat_getlongvalue) (struct OH_AVFormat \*format, const char \*key, int64_t \*out) | Reads data of the long type from an **OH_AVFormat** instance.| 60| [OH_AVFormat_GetFloatValue](#oh_avformat_getfloatvalue) (struct OH_AVFormat \*format, const char \*key, float \*out) | Reads data of the float type from an **OH_AVFormat** instance.| 61| [OH_AVFormat_GetDoubleValue](#oh_avformat_getdoublevalue) (struct OH_AVFormat \*format, const char \*key, double \*out) | Reads data of the double type from an **OH_AVFormat** instance.| 62| [OH_AVFormat_GetStringValue](#oh_avformat_getstringvalue) (struct OH_AVFormat \*format, const char \*key, const char \*\*out) | Reads data of the string type from an **OH_AVFormat** instance.| 63| [OH_AVFormat_GetBuffer](#oh_avformat_getbuffer) (struct OH_AVFormat \*format, const char \*key, uint8_t \*\*addr, size_t \*size) | Reads data blocks of a specified length from an **OH_AVFormat** instance.| 64| \*[OH_AVFormat_DumpInfo](#oh_avformat_dumpinfo) (struct OH_AVFormat \*format) | Dumps the information contained in an **OH_AVFormat** instance as a string.| 65| \*[OH_AVMemory_Create](#oh_avmemory_create) (int32_t size) | Creates an **OH_AVMemory** instance.| 66| \*[OH_AVMemory_GetAddr](#oh_avmemory_getaddr) (struct OH_AVMemory \*mem) | Obtains the virtual memory address of an **OH_AVMemory** instance.| 67| [OH_AVMemory_GetSize](#oh_avmemory_getsize) (struct OH_AVMemory \*mem) | Obtains the memory size of an **OH_AVMemory** instance.| 68| [OH_AVMemory_Destroy](#oh_avmemory_destroy) (struct OH_AVMemory \*mem) | Releases an **OH_AVMemory** instance.| 69 70 71## Type Description 72 73 74### OH_AVErrCode 75 76 77``` 78typedef enum OH_AVErrCode OH_AVErrCode 79``` 80 81**Description** 82 83Defines an enum that enumerates the audio and video error codes. 84 85\@syscap SystemCapability.Multimedia.Media.Core 86 87**Since** 88 899 90 91 92### OH_AVPixelFormat 93 94 95``` 96typedef enum OH_AVPixelFormat OH_AVPixelFormat 97``` 98 99**Description** 100 101Defines an enum that enumerates the video pixel formats. 102 103\@syscap SystemCapability.Multimedia.Media.Core 104 105**Since** 106 1079 108 109 110## Enum Description 111 112 113### OH_AVErrCode 114 115 116``` 117enum OH_AVErrCode 118``` 119 120**Description** 121 122Enumerates the audio and video error codes. 123 124\@syscap SystemCapability.Multimedia.Media.Core 125 126**Since** 127 1289 129 130| Value| Description| 131| -------- | -------- | 132| AV_ERR_OK | Operation successful.| 133| AV_ERR_NO_MEMORY | No memory.| 134| AV_ERR_OPERATE_NOT_PERMIT | Operation not allowed.| 135| AV_ERR_INVALID_VAL | Invalid value.| 136| AV_ERR_IO | I/O error.| 137| AV_ERR_TIMEOUT | Timeout.| 138| AV_ERR_UNKNOWN | Unknown error.| 139| AV_ERR_SERVICE_DIED | Unavailable service.| 140| AV_ERR_INVALID_STATE | Unsupported operation in this state.| 141| AV_ERR_UNSUPPORT | Unsupported API.| 142| AV_ERR_EXTEND_START | Initial value for extended error codes.| 143 144 145### OH_AVPixelFormat 146 147 148``` 149enum OH_AVPixelFormat 150``` 151 152**Description** 153 154Enumerates the video pixel formats. 155 156\@syscap SystemCapability.Multimedia.Media.Core 157 158**Since** 159 1609 161 162| Value| Description| 163| -------- | -------- | 164| AV_PIXEL_FORMAT_YUVI420 | YUV 420 Planar.| 165| AV_PIXEL_FORMAT_NV12 | NV12. YUV 420 semi-planar.| 166| AV_PIXEL_FORMAT_NV21 | NV21. YVU 420 semi-planar.| 167| AV_PIXEL_FORMAT_SURFACE_FORMAT | Surface.| 168| AV_PIXEL_FORMAT_RGBA | RGBA8888.| 169 170 171## Function Description 172 173 174### OH_AVFormat_Copy() 175 176 177``` 178bool OH_AVFormat_Copy (struct OH_AVFormat *to, struct OH_AVFormat *from) 179``` 180 181**Description** 182 183Copies an **OH_AVFormat** instance. 184 185\@syscap SystemCapability.Multimedia.Media.Core 186 187**Parameters** 188 189| Name| Description| 190| -------- | -------- | 191| to | Handle to the **OH_AVFormat** instance to which the data will be copied.| 192| from | Handle to the **OH_AVFormat** instance from which the data will be copied.| 193 194**Returns** 195 196Returns **true** if the operation is successful; returns **false** otherwise. 197 198**Since** 199 2009 201 202 203### OH_AVFormat_Create() 204 205 206``` 207struct OH_AVFormat* OH_AVFormat_Create (void) 208``` 209 210**Description** 211 212Creates an **OH_AVFormat** instance for reading data. 213 214\@syscap SystemCapability.Multimedia.Media.Core 215 216**Returns** 217 218Returns the pointer to an **OH_AVFormat** instance. 219 220**Since** 221 2229 223 224 225### OH_AVFormat_CreateAudioFormat() 226 227 228``` 229struct OH_AVFormat* OH_AVFormat_CreateAudioFormat (const char *mimeType, int32_t sampleRate, int32_t channelCount) 230``` 231 232**Description** 233 234Creates an audio **OH_AVFormat** instance for reading and writing data. 235 236\@syscap SystemCapability.Multimedia.Media.Core 237 238**Parameters** 239 240| Name| Description| 241| -------- | -------- | 242| mimeType | Pointer to a string that describes the MIME type. For details, see [AVCODEC_MIMETYPE](_codec_base.md#variables).| 243| sampleRate | Sampling rate, in Hz.| 244| channelCount | Number of audio channels. For example, 1 indicates mono and 2 indicates stereo.| 245 246**Returns** 247 248Returns the pointer to an **OH_AVFormat** instance. 249 250**Since** 251 25210 253 254 255### OH_AVFormat_CreateVideoFormat() 256 257 258``` 259struct OH_AVFormat* OH_AVFormat_CreateVideoFormat (const char *mimeType, int32_t width, int32_t height) 260``` 261 262**Description** 263 264Creates a video **OH_AVFormat** instance for reading and writing data. 265 266\@syscap SystemCapability.Multimedia.Media.Core 267 268**Parameters** 269 270| Name| Description| 271| -------- | -------- | 272| mimeType | Pointer to a string that describes the MIME type. For details, see [AVCODEC_MIMETYPE](_codec_base.md#variables).| 273| width | Video width, in pixels.| 274| height | Video height, in pixels.| 275 276**Returns** 277 278Returns the pointer to an **OH_AVFormat** instance. 279 280**Since** 281 28210 283 284 285### OH_AVFormat_Destroy() 286 287 288``` 289void OH_AVFormat_Destroy (struct OH_AVFormat *format) 290``` 291 292**Description** 293 294Destroys an **OH_AVFormat** instance. 295 296\@syscap SystemCapability.Multimedia.Media.Core 297 298**Parameters** 299 300| Name| Description| 301| -------- | -------- | 302| format | Pointer to an **OH_AVFormat** instance.| 303 304**Since** 305 3069 307 308 309### OH_AVFormat_DumpInfo() 310 311 312``` 313const char* OH_AVFormat_DumpInfo (struct OH_AVFormat *format) 314``` 315 316**Description** 317 318Dumps the information contained in an **OH_AVFormat** instance as a string. 319 320\@syscap SystemCapability.Multimedia.Media.Core 321 322**Parameters** 323 324| Name| Description| 325| -------- | -------- | 326| format | Pointer to an **OH_AVFormat** instance.| 327 328**Returns** 329 330Returns the pointer to a collection of strings, each of which consists of a key and value. 331 332**Since** 333 3349 335 336 337### OH_AVFormat_GetBuffer() 338 339 340``` 341bool OH_AVFormat_GetBuffer (struct OH_AVFormat *format, const char *key, uint8_t **addr, size_t *size) 342``` 343 344**Description** 345 346Reads data blocks of a specified length from an **OH_AVFormat** instance. 347 348\@syscap SystemCapability.Multimedia.Media.Core 349 350**Parameters** 351 352| Name| Description| 353| -------- | -------- | 354| format | Pointer to an **OH_AVFormat** instance.| 355| key | Pointer to the key of the data to read.| 356| addr | Double pointer to the address where the data read is stored. The data read is destroyed when the **OH_AVFormat** instance is destroyed. To hold the data for an extended period of time, copy it to the memory.| 357| size | Pointer to the size of the data read.| 358 359**Returns** 360 361Returns **true** if the operation is successful; returns **false** otherwise. 362 363**Since** 364 3659 366 367 368### OH_AVFormat_GetDoubleValue() 369 370 371``` 372bool OH_AVFormat_GetDoubleValue (struct OH_AVFormat *format, const char *key, double *out) 373``` 374 375**Description** 376 377Reads data of the double type from an **OH_AVFormat** instance. 378 379\@syscap SystemCapability.Multimedia.Media.Core 380 381**Parameters** 382 383| Name| Description| 384| -------- | -------- | 385| format | Pointer to an **OH_AVFormat** instance.| 386| key | Pointer to the key of the data to read.| 387| out | Pointer to the value of the data read.| 388 389**Returns** 390 391Returns **true** if the operation is successful; returns **false** otherwise. 392 393**Since** 394 3959 396 397 398### OH_AVFormat_GetFloatValue() 399 400 401``` 402bool OH_AVFormat_GetFloatValue (struct OH_AVFormat *format, const char *key, float *out) 403``` 404 405**Description** 406 407Reads data of the float type from an **OH_AVFormat** instance. 408 409\@syscap SystemCapability.Multimedia.Media.Core 410 411**Parameters** 412 413| Name| Description| 414| -------- | -------- | 415| format | Pointer to an **OH_AVFormat** instance.| 416| key | Pointer to the key of the data to read.| 417| out | Pointer to the value of the data read.| 418 419**Returns** 420 421Returns **true** if the operation is successful; returns **false** otherwise. 422 423**Since** 424 4259 426 427 428### OH_AVFormat_GetIntValue() 429 430 431``` 432bool OH_AVFormat_GetIntValue (struct OH_AVFormat *format, const char *key, int32_t *out) 433``` 434 435**Description** 436 437Reads data of the int type from an **OH_AVFormat** instance. 438 439\@syscap SystemCapability.Multimedia.Media.Core 440 441**Parameters** 442 443| Name| Description| 444| -------- | -------- | 445| format | Pointer to an **OH_AVFormat** instance.| 446| key | Pointer to the key of the data to read.| 447| out | Pointer to the value of the data read.| 448 449**Returns** 450 451Returns **true** if the operation is successful; returns **false** otherwise. 452 453 454### OH_AVFormat_GetLongValue() 455 456 457``` 458bool OH_AVFormat_GetLongValue (struct OH_AVFormat *format, const char *key, int64_t *out) 459``` 460 461**Description** 462 463Reads data of the long type from an **OH_AVFormat** instance. 464 465\@syscap SystemCapability.Multimedia.Media.Core 466 467**Parameters** 468 469| Name| Description| 470| -------- | -------- | 471| format | Pointer to an **OH_AVFormat** instance.| 472| key | Pointer to the key of the data to read.| 473| out | Pointer to the value of the data read.| 474 475**Returns** 476 477Returns **true** if the operation is successful; returns **false** otherwise. 478 479**Since** 480 4819 482 483 484### OH_AVFormat_GetStringValue() 485 486 487``` 488bool OH_AVFormat_GetStringValue (struct OH_AVFormat *format, const char *key, const char **out) 489``` 490 491**Description** 492 493Reads data of the string type from an **OH_AVFormat** instance. 494 495\@syscap SystemCapability.Multimedia.Media.Core 496 497**Parameters** 498 499| Name| Description| 500| -------- | -------- | 501| format | Pointer to an **OH_AVFormat** instance.| 502| key | Pointer to the key of the data to read.| 503| out | Double pointer to the data read. The data read is destroyed when the **OH_AVFormat** instance is destroyed. To hold the data for an extended period of time, copy it to the memory.| 504 505**Returns** 506 507Returns **true** if the operation is successful; returns **false** otherwise. 508 509**Since** 510 5119 512 513 514### OH_AVFormat_SetBuffer() 515 516 517``` 518bool OH_AVFormat_SetBuffer (struct OH_AVFormat *format, const char *key, const uint8_t *addr, size_t size) 519``` 520 521**Description** 522 523Writes data blocks of a specified length to an **OH_AVFormat** instance. 524 525\@syscap SystemCapability.Multimedia.Media.Core 526 527**Parameters** 528 529| Name| Description| 530| -------- | -------- | 531| format | Pointer to an **OH_AVFormat** instance.| 532| key | Pointer to the key of the data to write.| 533| addr | Pointer to the address where the data is written.| 534| size | Size of the data written.| 535 536**Returns** 537 538Returns **true** if the operation is successful; returns **false** otherwise. 539 540**Since** 541 5429 543 544 545### OH_AVFormat_SetDoubleValue() 546 547 548``` 549bool OH_AVFormat_SetDoubleValue (struct OH_AVFormat *format, const char *key, double value) 550``` 551 552**Description** 553 554Writes data of the double type to an **OH_AVFormat** instance. 555 556\@syscap SystemCapability.Multimedia.Media.Core 557 558**Parameters** 559 560| Name| Description| 561| -------- | -------- | 562| format | Pointer to an **OH_AVFormat** instance.| 563| key | Pointer to the key of the data to write.| 564| value | Value of the data to write.| 565 566**Returns** 567 568Returns **true** if the operation is successful; returns **false** otherwise. 569 570**Since** 571 5729 573 574 575### OH_AVFormat_SetFloatValue() 576 577 578``` 579bool OH_AVFormat_SetFloatValue (struct OH_AVFormat *format, const char *key, float value) 580``` 581 582**Description** 583 584Writes data of the float type to an **OH_AVFormat** instance. 585 586\@syscap SystemCapability.Multimedia.Media.Core 587 588**Parameters** 589 590| Name| Description| 591| -------- | -------- | 592| format | Pointer to an **OH_AVFormat** instance.| 593| key | Pointer to the key of the data to write.| 594| value | Value of the data to write.| 595 596**Returns** 597 598Returns **true** if the operation is successful; returns **false** otherwise. 599 600**Since** 601 6029 603 604 605### OH_AVFormat_SetIntValue() 606 607 608``` 609bool OH_AVFormat_SetIntValue (struct OH_AVFormat *format, const char *key, int32_t value) 610``` 611 612**Description** 613 614Writes data of the int type to an **OH_AVFormat** instance. 615 616\@syscap SystemCapability.Multimedia.Media.Core 617 618**Parameters** 619 620| Name| Description| 621| -------- | -------- | 622| format | Pointer to an **OH_AVFormat** instance.| 623| key | Pointer to the key of the data to write.| 624| value | Value of the data to write.| 625 626**Returns** 627 628Returns **true** if the operation is successful; returns **false** otherwise. 629 630**Since** 631 6329 633 634 635### OH_AVFormat_SetLongValue() 636 637 638``` 639bool OH_AVFormat_SetLongValue (struct OH_AVFormat *format, const char *key, int64_t value) 640``` 641 642**Description** 643 644Writes data of the long type to an **OH_AVFormat** instance. 645 646\@syscap SystemCapability.Multimedia.Media.Core 647 648**Parameters** 649 650| Name| Description| 651| -------- | -------- | 652| format | Pointer to an **OH_AVFormat** instance.| 653| key | Pointer to the key of the data to write.| 654| value | Value of the data to write.| 655 656**Returns** 657 658Returns **true** if the operation is successful; returns **false** otherwise. 659 660**Since** 661 6629 663 664 665### OH_AVFormat_SetStringValue() 666 667 668``` 669bool OH_AVFormat_SetStringValue (struct OH_AVFormat *format, const char *key, const char *value) 670``` 671 672**Description** 673 674Writes data of the string type to an **OH_AVFormat** instance. 675 676\@syscap SystemCapability.Multimedia.Media.Core 677 678**Parameters** 679 680| Name| Description| 681| -------- | -------- | 682| format | Pointer to an **OH_AVFormat** instance.| 683| key | Pointer to the key of the data to write.| 684| value | Value of the data to write.| 685 686**Returns** 687 688Returns **true** if the operation is successful; returns **false** otherwise. 689 690**Since** 691 6929 693 694 695### OH_AVMemory_Create() 696 697 698``` 699OH_AVMemory* OH_AVMemory_Create (int32_t size) 700``` 701 702**Description** 703 704Creates an **OH_AVMemory** instance. 705 706\@syscap SystemCapability.Multimedia.Media.Core 707 708**Parameters** 709 710| Name| Description| 711| -------- | -------- | 712| size | Size of the created memory, in bytes.| 713 714**Returns** 715 716Returns the pointer to the **OH_AVMemory** instance created if the operation is successful; returns a null pointer otherwise. The instance must be released by calling **OH_AVMemory_Destroy** when it is no longer required. 717 718**Since** 719 72010 721 722 723### OH_AVMemory_Destroy() 724 725 726``` 727OH_AVErrCode OH_AVMemory_Destroy (struct OH_AVMemory *mem) 728``` 729 730**Description** 731 732Releases an **OH_AVMemory** instance. 733 734\@syscap SystemCapability.Multimedia.Media.Core 735 736**Parameters** 737 738| Name| Description| 739| -------- | -------- | 740| mem | Pointer to an **OH_AVMemory** instance.| 741 742**Returns** 743 744Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](#oh_averrcode) otherwise. 745 746**Since** 747 74810 749 750 751### OH_AVMemory_GetAddr() 752 753 754``` 755uint8_t* OH_AVMemory_GetAddr (struct OH_AVMemory *mem) 756``` 757 758**Description** 759 760Obtains the virtual memory address of an **OH_AVMemory** instance. 761 762\@syscap SystemCapability.Multimedia.Media.Core 763 764**Parameters** 765 766| Name| Description| 767| -------- | -------- | 768| mem | Pointer to an **OH_AVMemory** instance.| 769 770**Returns** 771 772Returns the pointer to the virtual memory address if the memory is valid; returns a null pointer otherwise. 773 774**Since** 775 7769 777 778 779### OH_AVMemory_GetSize() 780 781 782``` 783int32_t OH_AVMemory_GetSize (struct OH_AVMemory *mem) 784``` 785 786**Description** 787 788Obtains the memory size of an **OH_AVMemory** instance. 789 790\@syscap SystemCapability.Multimedia.Media.Core 791 792**Parameters** 793 794| Name| Description| 795| -------- | -------- | 796| mem | Pointer to an **OH_AVMemory** instance.| 797 798**Returns** 799 800Returns the memory size if the memory is valid; returns **-1** otherwise. 801 802**Since** 803 8049 805