1# Core 2 3 4## Overview 5 6Provides 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:** 119 12 13 14## Summary 15 16 17### Files 18 19| Name | Description | 20| -------- | -------- | 21| [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> | 22| [native_avformat.h](native__avformat_8h.md) | Declares the format-related functions and enums. <br>File to Include: <multimedia/player_framework/native_avformat.h> | 23| [native_avmemory.h](native__avmemory_8h.md) | Declares the memory-related functions. <br>File to Include: <multimedia/player_framework/native_avmemory.h> | 24 25 26### Types 27 28| Name | Description | 29| -------- | -------- | 30| [OH_AVErrCode](#oh_averrcode) | Enumerates the audio and video error codes. | 31| [OH_AVPixelFormat](#oh_avpixelformat) | Enumerates the audio and video pixel formats. | 32 33 34### Enums 35 36| Name | Description | 37| -------- | -------- | 38| [OH_AVErrCode](#oh_averrcode) {<br/>AV_ERR_OK = 0, AV_ERR_NO_MEMORY = 1, AV_ERR_OPERATE_NOT_PERMIT = 2, AV_ERR_INVALID_VAL = 3,<br/>AV_ERR_IO = 4, AV_ERR_TIMEOUT = 5, AV_ERR_UNKNOWN = 6, AV_ERR_SERVICE_DIED = 7,<br/>AV_ERR_INVALID_STATE = 8, AV_ERR_UNSUPPORT = 9, AV_ERR_EXTEND_START = 100<br/>} | Enumerates the audio and video error codes. | 39| [OH_AVPixelFormat](#oh_avpixelformat) {<br/>AV_PIXEL_FORMAT_YUVI420 = 1, AV_PIXEL_FORMAT_NV12 = 2, AV_PIXEL_FORMAT_NV21 = 3, AV_PIXEL_FORMAT_SURFACE_FORMAT = 4,<br/>AV_PIXEL_FORMAT_RGBA = 5<br/>} | Enumerates the audio and video pixel formats. | 40 41 42### Functions 43 44| Name | Description | 45| -------- | -------- | 46| [OH_AVFormat_Create](#oh_avformat_create) (void) | Creates an **OH_AVFormat** instance for reading and writing data. | 47| [OH_AVFormat_Destroy](#oh_avformat_destroy) (struct OH_AVFormat \*format) | Destroys an **OH_AVFormat** instance. | 48| [OH_AVFormat_Copy](#oh_avformat_copy) (struct OH_AVFormat \*to, struct OH_AVFormat \*from) | Copies the resources from an **OH_AVFormat** instance to another. | 49| [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. | 50| [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. | 51| [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. | 52| [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. | 53| [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. | 54| [OH_AVFormat_SetBuffer](#oh_avformat_setbuffer) (struct OH_AVFormat \*format, const char \*key, const uint8_t \*addr, size_t size) | Writes data with a specified size to an **OH_AVFormat** instance. | 55| [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. | 56| [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. | 57| [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. | 58| [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. | 59| [OH_AVFormat_GetStringValue](#oh_avformat_getstringvalue) (struct OH_AVFormat \*format, const char \*key, const char \*\*out) | Reads data of the double type from an **OH_AVFormat** instance. | 60| [OH_AVFormat_GetBuffer](#oh_avformat_getbuffer) (struct OH_AVFormat \*format, const char \*key, uint8_t \*\*addr, size_t \*size) | Reads data with a specified size from an **OH_AVFormat** instance. | 61| [OH_AVFormat_DumpInfo](#oh_avformat_dumpinfo) (struct OH_AVFormat \*format) | Dumps the information contained in an**OH_AVFormat** instance as a string. | 62| [OH_AVMemory_GetAddr](#oh_avmemory_getaddr) (struct OH_AVMemory \*mem) | Obtains the virtual memory address of an **OH_AVMemory** instance. | 63| [OH_AVMemory_GetSize](#oh_avmemory_getsize) (struct OH_AVMemory \*mem) | Obtains the memory size of an **OH_AVMemory** instance. | 64 65 66## Type Description 67 68 69### OH_AVErrCode 70 71 72``` 73typedef enum OH_AVErrCodeOH_AVErrCode 74``` 75**Description**<br> 76Enumerates the audio and video error codes. 77 78\@syscap SystemCapability.Multimedia.Media.Core 79 80 81### OH_AVPixelFormat 82 83 84``` 85typedef enum OH_AVPixelFormatOH_AVPixelFormat 86``` 87**Description**<br> 88Enumerates the audio and video pixel formats. 89 90\@syscap SystemCapability.Multimedia.Media.Core 91 92 93## Enum Description 94 95 96### OH_AVErrCode 97 98 99``` 100enum OH_AVErrCode 101``` 102**Description**<br> 103Enumerates the audio and video error codes. 104 105\@syscap SystemCapability.Multimedia.Media.Core 106 107| Name | Description | 108| -------- | -------- | 109| AV_ERR_OK | Operation successful. | 110| AV_ERR_NO_MEMORY | No memory. | 111| AV_ERR_OPERATE_NOT_PERMIT | Invalid parameter. | 112| AV_ERR_INVALID_VAL | Invalid value. | 113| AV_ERR_IO | I/O error. | 114| AV_ERR_TIMEOUT | Timeout. | 115| AV_ERR_UNKNOWN | Unknown error. | 116| AV_ERR_SERVICE_DIED | Unavailable media service. | 117| AV_ERR_INVALID_STATE | Unsupported operation in this state. | 118| AV_ERR_UNSUPPORT | Unsupported API. | 119| AV_ERR_EXTEND_START | Initial value for extended error codes. | 120 121 122### OH_AVPixelFormat 123 124 125``` 126enum OH_AVPixelFormat 127``` 128**Description**<br> 129Enumerates the audio and video pixel formats. 130 131\@syscap SystemCapability.Multimedia.Media.Core 132 133| Name | Description | 134| -------- | -------- | 135| AV_PIXEL_FORMAT_YUVI420 | YUV 420 Planar. | 136| AV_PIXEL_FORMAT_NV12 | NV12. YUV 420 Semi-planar. | 137| AV_PIXEL_FORMAT_NV21 | NV21. YVU 420 Semi-planar. | 138| AV_PIXEL_FORMAT_SURFACE_FORMAT | Surface. | 139| AV_PIXEL_FORMAT_RGBA | RGBA8888. | 140 141 142## Function Description 143 144 145### OH_AVFormat_Copy() 146 147 148``` 149bool OH_AVFormat_Copy (struct OH_AVFormat * to, struct OH_AVFormat * from ) 150``` 151**Description**<br> 152Copies the resources from an **OH_AVFormat** instance to another. 153 154\@syscap SystemCapability.Multimedia.Media.Core 155 156 **Parameters** 157 158| Name | Description | 159| -------- | -------- | 160| to | Indicates the handle to the **OH_AVFormat** instance to which the data will be copied. | 161| from | Indicates the handle to the **OH_AVFormat** instance from which the data will be copied. | 162 163**Returns** 164 165Returns **TRUE** if the operation is successful. 166 167Returns **FALSE** if the operation fails. 168 169 170### OH_AVFormat_Create() 171 172 173``` 174struct OH_AVFormat* OH_AVFormat_Create (void ) 175``` 176**Description**<br> 177Creates an **OH_AVFormat** instance for reading and writing data. 178 179\@syscap SystemCapability.Multimedia.Media.Core 180 181**Returns** 182 183Returns the handle to an **OH_AVFormat** instance. 184 185 186### OH_AVFormat_Destroy() 187 188 189``` 190void OH_AVFormat_Destroy (struct OH_AVFormat * format) 191``` 192**Description**<br> 193Destroys an **OH_AVFormat** instance. 194 195\@syscap SystemCapability.Multimedia.Media.Core 196 197 **Parameters** 198 199| Name | Description | 200| -------- | -------- | 201| format | Indicates the handle to an **OH_AVFormat** instance. | 202 203**Returns** 204 205void 206 207 208### OH_AVFormat_DumpInfo() 209 210 211``` 212const char* OH_AVFormat_DumpInfo (struct OH_AVFormat * format) 213``` 214**Description**<br> 215Dumps the information contained in an**OH_AVFormat** instance as a string. 216 217\@syscap SystemCapability.Multimedia.Media.Core 218 219 **Parameters** 220 221| Name | Description | 222| -------- | -------- | 223| format | Indicates the handle to an **OH_AVFormat** instance. | 224 225**Returns** 226 227Returns the pointer to a collect of strings, each of which consists of a key and value. 228 229 230### OH_AVFormat_GetBuffer() 231 232 233``` 234bool OH_AVFormat_GetBuffer (struct OH_AVFormat * format, const char * key, uint8_t ** addr, size_t * size ) 235``` 236**Description**<br> 237Reads data with a specified size from an **OH_AVFormat** instance. 238 239\@syscap SystemCapability.Multimedia.Media.Core 240 241 **Parameters** 242 243| Name | Description | 244| -------- | -------- | 245| format | Indicates the handle to an **OH_AVFormat** instance. | 246| key | Indicates the pointer to the key of the data to read. | 247| addr | Indicates the 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. | 248| size | Indicates the pointer to the size of the data read. | 249 250**Returns** 251 252Returns **TRUE** if the operation is successful. 253 254Returns **FALSE** if the operation fails. 255 256 257### OH_AVFormat_GetDoubleValue() 258 259 260``` 261bool OH_AVFormat_GetDoubleValue (struct OH_AVFormat * format, const char * key, double * out ) 262``` 263**Description**<br> 264Reads data of the double type from an **OH_AVFormat** instance. 265 266\@syscap SystemCapability.Multimedia.Media.Core 267 268 **Parameters** 269 270| Name | Description | 271| -------- | -------- | 272| format | Indicates the handle to an **OH_AVFormat** instance. | 273| key | Indicates the pointer to the key of the data to read. | 274| out | Indicates the pointer to the data read. | 275 276**Returns** 277 278Returns **TRUE** if the operation is successful. 279 280Returns **FALSE** if the operation fails. 281 282 283### OH_AVFormat_GetFloatValue() 284 285 286``` 287bool OH_AVFormat_GetFloatValue (struct OH_AVFormat * format, const char * key, float * out ) 288``` 289**Description**<br> 290Reads data of the float type from an **OH_AVFormat** instance. 291 292\@syscap SystemCapability.Multimedia.Media.Core 293 294 **Parameters** 295 296| Name | Description | 297| -------- | -------- | 298| format | Indicates the handle to an **OH_AVFormat** instance. | 299| key | Indicates the pointer to the key of the data to read. | 300| out | Indicates the pointer to the data read. | 301 302**Returns** 303 304Returns **TRUE** if the operation is successful. 305 306Returns **FALSE** if the operation fails. 307 308 309### OH_AVFormat_GetIntValue() 310 311 312``` 313bool OH_AVFormat_GetIntValue (struct OH_AVFormat * format, const char * key, int32_t * out ) 314``` 315**Description**<br> 316Reads data of the int type from an **OH_AVFormat** instance. 317 318\@syscap SystemCapability.Multimedia.Media.Core 319 320 **Parameters** 321 322| Name | Description | 323| -------- | -------- | 324| format | Indicates the handle to an **OH_AVFormat** instance. | 325| key | Indicates the pointer to the key of the data to read. | 326| out | Indicates the pointer to the data read. | 327 328**Returns** 329 330Returns **TRUE** if the operation is successful. 331 332Returns **FALSE** if the operation fails. 333 334 335### OH_AVFormat_GetLongValue() 336 337 338``` 339bool OH_AVFormat_GetLongValue (struct OH_AVFormat * format, const char * key, int64_t * out ) 340``` 341**Description**<br> 342Reads data of the long type from an **OH_AVFormat** instance. 343 344\@syscap SystemCapability.Multimedia.Media.Core 345 346 **Parameters** 347 348| Name | Description | 349| -------- | -------- | 350| format | Indicates the handle to an **OH_AVFormat** instance. | 351| key | Indicates the pointer to the key of the data to read. | 352| out | Indicates the pointer to the data read. | 353 354**Returns** 355 356Returns **TRUE** if the operation is successful. 357 358Returns **FALSE** if the operation fails. 359 360 361### OH_AVFormat_GetStringValue() 362 363 364``` 365bool OH_AVFormat_GetStringValue (struct OH_AVFormat * format, const char * key, const char ** out ) 366``` 367**Description**<br> 368Reads data of the double type from an **OH_AVFormat** instance. 369 370\@syscap SystemCapability.Multimedia.Media.Core 371 372 **Parameters** 373 374| Name | Description | 375| -------- | -------- | 376| format | Indicates the handle to an **OH_AVFormat** instance. | 377| key | Indicates the pointer to the key of the data to read. | 378| out | Indicates the double pointer to the data read. The data read is updated when **GetString** is called and destroyed when the **OH_AVFormat** instance is destroyed. To hold the data for an extended period of time, copy it to the memory. | 379 380**Returns** 381 382Returns **TRUE** if the operation is successful. 383 384Returns **FALSE** if the operation fails. 385 386 387### OH_AVFormat_SetBuffer() 388 389 390``` 391bool OH_AVFormat_SetBuffer (struct OH_AVFormat * format, const char * key, const uint8_t * addr, size_t size ) 392``` 393**Description**<br> 394Writes data with a specified size to an **OH_AVFormat** instance. 395 396\@syscap SystemCapability.Multimedia.Media.Core 397 398 **Parameters** 399 400| Name | Description | 401| -------- | -------- | 402| format | Indicates the handle to an **OH_AVFormat** instance. | 403| key | Indicates the pointer to the key of the data to write. | 404| addr | Indicates the pointer to the address where the data is written. | 405| size | Indicates the size of the data written. | 406 407**Returns** 408 409Returns **TRUE** if the operation is successful. 410 411Returns **FALSE** if the operation fails. 412 413 414### OH_AVFormat_SetDoubleValue() 415 416 417``` 418bool OH_AVFormat_SetDoubleValue (struct OH_AVFormat * format, const char * key, double value ) 419``` 420**Description**<br> 421Writes data of the double type to an **OH_AVFormat** instance. 422 423\@syscap SystemCapability.Multimedia.Media.Core 424 425 **Parameters** 426 427| Name | Description | 428| -------- | -------- | 429| format | Indicates the handle to an **OH_AVFormat** instance. | 430| key | Indicates the pointer to the key of the data to write. | 431| value | Indicates the value of the data to write. | 432 433**Returns** 434 435Returns **TRUE** if the operation is successful. 436 437Returns **FALSE** if the operation fails. 438 439 440### OH_AVFormat_SetFloatValue() 441 442 443``` 444bool OH_AVFormat_SetFloatValue (struct OH_AVFormat * format, const char * key, float value ) 445``` 446**Description**<br> 447Writes data of the float type to an **OH_AVFormat** instance. 448 449\@syscap SystemCapability.Multimedia.Media.Core 450 451 **Parameters** 452 453| Name | Description | 454| -------- | -------- | 455| format | Indicates the handle to an **OH_AVFormat** instance. | 456| key | Indicates the pointer to the key of the data to write. | 457| value | Indicates the value of the data to write. | 458 459**Returns** 460 461Returns **TRUE** if the operation is successful. 462 463Returns **FALSE** if the operation fails. 464 465 466### OH_AVFormat_SetIntValue() 467 468 469``` 470bool OH_AVFormat_SetIntValue (struct OH_AVFormat * format, const char * key, int32_t value ) 471``` 472**Description**<br> 473Writes data of the int type to an **OH_AVFormat** instance. 474 475\@syscap SystemCapability.Multimedia.Media.Core 476 477 **Parameters** 478 479| Name | Description | 480| -------- | -------- | 481| format | Indicates the handle to an **OH_AVFormat** instance. | 482| key | Indicates the pointer to the key of the data to write. | 483| value | Indicates the value of the data to write. | 484 485**Returns** 486 487Returns **TRUE** if the operation is successful. 488 489Returns **FALSE** if the operation fails. 490 491 492### OH_AVFormat_SetLongValue() 493 494 495``` 496bool OH_AVFormat_SetLongValue (struct OH_AVFormat * format, const char * key, int64_t value ) 497``` 498**Description**<br> 499Writes data of the long type to an **OH_AVFormat** instance. 500 501\@syscap SystemCapability.Multimedia.Media.Core 502 503 **Parameters** 504 505| Name | Description | 506| -------- | -------- | 507| format | Indicates the handle to an **OH_AVFormat** instance. | 508| key | Indicates the pointer to the key of the data to write. | 509| value | Indicates the value of the data to write. | 510 511**Returns** 512 513Returns **TRUE** if the operation is successful. 514 515Returns **FALSE** if the operation fails. 516 517 518### OH_AVFormat_SetStringValue() 519 520 521``` 522bool OH_AVFormat_SetStringValue (struct OH_AVFormat * format, const char * key, const char * value ) 523``` 524**Description**<br> 525Writes data of the string type to an **OH_AVFormat** instance. 526 527\@syscap SystemCapability.Multimedia.Media.Core 528 529 **Parameters** 530 531| Name | Description | 532| -------- | -------- | 533| format | Indicates the handle to an **OH_AVFormat** instance. | 534| key | Indicates the pointer to the key of the data to write. | 535| value | Indicates the pointer to the value of the data to write. | 536 537**Returns** 538 539Returns **TRUE** if the operation is successful. 540 541Returns **FALSE** if the operation fails. 542 543 544### OH_AVMemory_GetAddr() 545 546 547``` 548uint8_t* OH_AVMemory_GetAddr (struct OH_AVMemory * mem) 549``` 550**Description**<br> 551Obtains the virtual memory address of an **OH_AVMemory** instance. 552 553\@syscap SystemCapability.Multimedia.Media.Core 554 555 **Parameters** 556 557| Name | Description | 558| -------- | -------- | 559| mem | Indicates the pointer to an **OH_AVMemory** instance. | 560 561**Returns** 562 563Returns the virtual address if the memory is valid. 564 565Returns a null pointer if the memory is invalid. 566 567 568### OH_AVMemory_GetSize() 569 570 571``` 572int32_t OH_AVMemory_GetSize (struct OH_AVMemory * mem) 573``` 574**Description**<br> 575Obtains the memory size of an **OH_AVMemory** instance. 576 577\@syscap SystemCapability.Multimedia.Media.Core 578 579 **Parameters** 580 581| Name | Description | 582| -------- | -------- | 583| mem | Indicates the pointer to an **OH_AVMemory** instance. | 584 585**Returns** 586 587Returns the size if the memory is valid. 588 589Returns **-1** if the memory is invalid. 590