1# Core 2 3 4## 概述 5 6Core模块提供用于播放框架的基础骨干能力,包含内存、错误码、格式载体等相关函数。 7 8\@syscap SystemCapability.Multimedia.Media.Core 9 10**起始版本:** 11 129 13 14 15## 汇总 16 17 18### 文件 19 20| 名称 | 描述 | 21| -------- | -------- | 22| [native_averrors.h](native__averrors_8h.md) | 声明了媒体播放框架的错误码。<br>**引用文件**:<multimedia/player_framework/native_averrors.h> <br>**库**:libnative_media_core.so | 23| [native_avformat.h](native__avformat_8h.md) | 声明了格式相关的函数和枚举。<br>**引用文件**:<multimedia/player_framework/native_avformat.h> <br>**库**:libnative_media_core.so | 24| [native_avmemory.h](native__avmemory_8h.md) | 声明了AVMemory的函数接口。<br>**引用文件**:<multimedia/player_framework/native_avmemory.h> <br>**库**:libnative_media_core.so | 25 26 27### 类型定义 28 29| 名称 | 描述 | 30| -------- | -------- | 31| [OH_AVErrCode](#oh_averrcode) | 音视频错误码。 | 32| [OH_AVPixelFormat](#oh_avpixelformat) | AVPixel 格式的枚举类。 | 33 34 35### 枚举 36 37| 名称 | 描述 | 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/>} | 音视频错误码。 | 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/>} | AVPixel 格式的枚举类。 | 41 42 43### 函数 44 45| 名称 | 描述 | 46| -------- | -------- | 47| \*[OH_AVFormat_Create](#oh_avformat_create) (void) | 创建OH_AVFormat句柄,用于读取数据。 | 48| \*[OH_AVFormat_CreateAudioFormat](#oh_avformat_createaudioformat) (const char \*mimeType, int32_t sampleRate, int32_t channelCount) | 创建音频OH_AVFormat句柄指针,用于读写数据。 | 49| \*[OH_AVFormat_CreateVideoFormat](#oh_avformat_createvideoformat) (const char \*mimeType, int32_t width, int32_t height) | 创建视频OH_AVFormat句柄指针,用于读写数据。 | 50| [OH_AVFormat_Destroy](#oh_avformat_destroy) (struct OH_AVFormat \*format) | 销毁OH_AVFormat句柄。 | 51| [OH_AVFormat_Copy](#oh_avformat_copy) (struct OH_AVFormat \*to, struct OH_AVFormat \*from) | 复制OH_AVFormat句柄。 | 52| [OH_AVFormat_SetIntValue](#oh_avformat_setintvalue) (struct OH_AVFormat \*format, const char \*key, int32_t value) | 将int数据写入OH_AVFormat。 | 53| [OH_AVFormat_SetLongValue](#oh_avformat_setlongvalue) (struct OH_AVFormat \*format, const char \*key, int64_t value) | 将long数据写入OH_AVFormat。 | 54| [OH_AVFormat_SetFloatValue](#oh_avformat_setfloatvalue) (struct OH_AVFormat \*format, const char \*key, float value) | 将float数据写入OH_AVFormat。 | 55| [OH_AVFormat_SetDoubleValue](#oh_avformat_setdoublevalue) (struct OH_AVFormat \*format, const char \*key, double value) | 将double数据写入OH_AVFormat。 | 56| [OH_AVFormat_SetStringValue](#oh_avformat_setstringvalue) (struct OH_AVFormat \*format, const char \*key, const char \*value) | 将string数据写入OH_AVFormat。 | 57| [OH_AVFormat_SetBuffer](#oh_avformat_setbuffer) (struct OH_AVFormat \*format, const char \*key, const uint8_t \*addr, size_t size) | 将指定长度的数据块写入OH_AVFormat。 | 58| [OH_AVFormat_GetIntValue](#oh_avformat_getintvalue) (struct OH_AVFormat \*format, const char \*key, int32_t \*out) | 从OH_AVFormat读取int数据。 | 59| [OH_AVFormat_GetLongValue](#oh_avformat_getlongvalue) (struct OH_AVFormat \*format, const char \*key, int64_t \*out) | 从OH_AVFormat读取long数据。 | 60| [OH_AVFormat_GetFloatValue](#oh_avformat_getfloatvalue) (struct OH_AVFormat \*format, const char \*key, float \*out) | 从OH_AVFormat读取float数据。 | 61| [OH_AVFormat_GetDoubleValue](#oh_avformat_getdoublevalue) (struct OH_AVFormat \*format, const char \*key, double \*out) | 从OH_AVFormat读取double数据。 | 62| [OH_AVFormat_GetStringValue](#oh_avformat_getstringvalue) (struct OH_AVFormat \*format, const char \*key, const char \*\*out) | 从OH_AVFormat读取string数据。 | 63| [OH_AVFormat_GetBuffer](#oh_avformat_getbuffer) (struct OH_AVFormat \*format, const char \*key, uint8_t \*\*addr, size_t \*size) | 从OH_AVFormat中读取指定长度的数据块。 | 64| \*[OH_AVFormat_DumpInfo](#oh_avformat_dumpinfo) (struct OH_AVFormat \*format) | 输出OH_AVFormat中包含的字符串。 | 65| \*[OH_AVMemory_Create](#oh_avmemory_create) (int32_t size) | 创建OH_AVMemory实例的指针。 | 66| \*[OH_AVMemory_GetAddr](#oh_avmemory_getaddr) (struct OH_AVMemory \*mem) | 获取入参的内存虚拟地址。 | 67| [OH_AVMemory_GetSize](#oh_avmemory_getsize) (struct OH_AVMemory \*mem) | 获取入参的内存长度。 | 68| [OH_AVMemory_Destroy](#oh_avmemory_destroy) (struct OH_AVMemory \*mem) | 释放OH_AVMemory实例指针的资源。 | 69 70 71## 类型定义说明 72 73 74### OH_AVErrCode 75 76 77``` 78typedef enum OH_AVErrCode OH_AVErrCode 79``` 80 81**描述:** 82 83音视频错误码。 84 85\@syscap SystemCapability.Multimedia.Media.Core 86 87**起始版本:** 88 899 90 91 92### OH_AVPixelFormat 93 94 95``` 96typedef enum OH_AVPixelFormat OH_AVPixelFormat 97``` 98 99**描述:** 100 101视频像素格式的枚举类。 102 103\@syscap SystemCapability.Multimedia.Media.Core 104 105**起始版本:** 106 1079 108 109 110## 枚举类型说明 111 112 113### OH_AVErrCode 114 115 116``` 117enum OH_AVErrCode 118``` 119 120**描述:** 121 122音视频错误码。 123 124\@syscap SystemCapability.Multimedia.Media.Core 125 126**起始版本:** 127 1289 129 130| 枚举值 | 描述 | 131| -------- | -------- | 132| AV_ERR_OK | 操作成功 | 133| AV_ERR_NO_MEMORY | 无内存 | 134| AV_ERR_OPERATE_NOT_PERMIT | 操作不允许 | 135| AV_ERR_INVALID_VAL | 无效值 | 136| AV_ERR_IO | IO错误 | 137| AV_ERR_TIMEOUT | 超时错误 | 138| AV_ERR_UNKNOWN | 未知错误 | 139| AV_ERR_SERVICE_DIED | 服务死亡 | 140| AV_ERR_INVALID_STATE | 当前状态不支持此操作 | 141| AV_ERR_UNSUPPORT | 未支持的接口 | 142| AV_ERR_EXTEND_START | 扩展错误码初始值 | 143 144 145### OH_AVPixelFormat 146 147 148``` 149enum OH_AVPixelFormat 150``` 151 152**描述:** 153 154视频像素格式的枚举类。 155 156\@syscap SystemCapability.Multimedia.Media.Core 157 158**起始版本:** 159 1609 161 162| 枚举值 | 描述 | 163| -------- | -------- | 164| AV_PIXEL_FORMAT_YUVI420 | yuv 420 planar | 165| AV_PIXEL_FORMAT_NV12 | NV12. yuv 420 semiplanar | 166| AV_PIXEL_FORMAT_NV21 | NV21. yvu 420 semiplanar | 167| AV_PIXEL_FORMAT_SURFACE_FORMAT | surface格式 | 168| AV_PIXEL_FORMAT_RGBA | RGBA8888 | 169 170 171## 函数说明 172 173 174### OH_AVFormat_Copy() 175 176 177``` 178bool OH_AVFormat_Copy (struct OH_AVFormat *to, struct OH_AVFormat *from) 179``` 180 181**描述:** 182 183复制OH_AVFormat句柄。 184 185\@syscap SystemCapability.Multimedia.Media.Core 186 187**参数:** 188 189| 名称 | 描述 | 190| -------- | -------- | 191| to | OH_AVFormat句柄,用于接收数据 | 192| from | 指向复制数据的OH_AVFormat句柄的指针 | 193 194**返回:** 195 196返回值为true表示成功,为false表示失败 197 198**起始版本:** 199 2009 201 202 203### OH_AVFormat_Create() 204 205 206``` 207struct OH_AVFormat* OH_AVFormat_Create (void) 208``` 209 210**描述:** 211 212创建OH_AVFormat句柄,用于读取数据。 213 214\@syscap SystemCapability.Multimedia.Media.Core 215 216**返回:** 217 218返回指向OH_AVFormat实例的指针 219 220**起始版本:** 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**描述:** 233 234创建音频OH_AVFormat句柄指针,用于读写数据。 235 236\@syscap SystemCapability.Multimedia.Media.Core 237 238**参数:** 239 240| 名称 | 描述 | 241| -------- | -------- | 242| mimeType | MIME类型描述字符串,请参阅[AVCODEC_MIMETYPE](_codec_base.md#变量) | 243| sampleRate | 采样率,单位Hz。 | 244| channelCount | 声道个数,如1为单声道,2为双声道。 | 245 246**返回:** 247 248返回指向OH_AVFormat实例的指针。 249 250**起始版本:** 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**描述:** 263 264创建视频OH_AVFormat句柄指针,用于读写数据。 265 266\@syscap SystemCapability.Multimedia.Media.Core 267 268**参数:** 269 270| 名称 | 描述 | 271| -------- | -------- | 272| mimeType | MIME类型描述字符串,请参阅[AVCODEC_MIMETYPE](_codec_base.md#变量) | 273| width | 宽度,单位为px。 | 274| height | 高度,单位为px。 | 275 276**返回:** 277 278返回指向OH_AVFormat实例的指针。 279 280**起始版本:** 281 28210 283 284 285### OH_AVFormat_Destroy() 286 287 288``` 289void OH_AVFormat_Destroy (struct OH_AVFormat *format) 290``` 291 292**描述:** 293 294销毁OH_AVFormat句柄。 295 296\@syscap SystemCapability.Multimedia.Media.Core 297 298**参数:** 299 300| 名称 | 描述 | 301| -------- | -------- | 302| format | 指向OH_AVFormat实例的指针。 | 303 304**起始版本:** 305 3069 307 308 309### OH_AVFormat_DumpInfo() 310 311 312``` 313const char* OH_AVFormat_DumpInfo (struct OH_AVFormat *format) 314``` 315 316**描述:** 317 318输出OH_AVFormat中包含的字符串。 319 320\@syscap SystemCapability.Multimedia.Media.Core 321 322**参数:** 323 324| 名称 | 描述 | 325| -------- | -------- | 326| format | 指向OH_AVFormat实例的指针 | 327 328**返回:** 329 330返回一个由key和data组成的字符串。 331 332**起始版本:** 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**描述:** 345 346从OH_AVFormat中读取指定长度的数据块。 347 348\@syscap SystemCapability.Multimedia.Media.Core 349 350**参数:** 351 352| 名称 | 描述 | 353| -------- | -------- | 354| format | 指向OH_AVFormat实例的指针。 | 355| key | 读写数据的键。 | 356| addr | 生命周期与format相同,与format一同销毁。 如果调用者需要长时间保持它,必须进行内存拷贝。 | 357| size | 读写数据的长度。 | 358 359**返回:** 360 361返回值为true表示成功,为false表示失败。 362 363**起始版本:** 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**描述:** 376 377从OH_AVFormat读取double数据。 378 379\@syscap SystemCapability.Multimedia.Media.Core 380 381**参数:** 382 383| 名称 | 描述 | 384| -------- | -------- | 385| format | 指向OH_AVFormat实例的指针 | 386| key | 读取数据的键 | 387| out | 读取数据的值 | 388 389**返回:** 390 391返回值为true表示成功,为false表示失败 392 393**起始版本:** 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**描述:** 406 407从OH_AVFormat读取Float数据。 408 409\@syscap SystemCapability.Multimedia.Media.Core 410 411**参数:** 412 413| 名称 | 描述 | 414| -------- | -------- | 415| format | 指向OH_AVFormat实例的指针 | 416| key | 读取数据的键 | 417| out | 读取数据的值 | 418 419**返回:** 420 421返回值为true表示成功,为false表示失败 422 423**起始版本:** 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**描述:** 436 437从OH_AVFormat读取int数据。 438 439\@syscap SystemCapability.Multimedia.Media.Core 440 441**参数:** 442 443| 名称 | 描述 | 444| -------- | -------- | 445| format | 指向OH_AVFormat实例的指针 | 446| key | 读取数据的键 | 447| out | 读取数据的值 | 448 449**返回:** 450 451返回值为true表示成功,为false表示失败 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**描述:** 462 463从OH_AVFormat读取long数据。 464 465\@syscap SystemCapability.Multimedia.Media.Core 466 467**参数:** 468 469| 名称 | 描述 | 470| -------- | -------- | 471| format | 指向OH_AVFormat实例的指针 | 472| key | 读取数据的键 | 473| out | 读取数据的值 | 474 475**返回:** 476 477返回值为true表示成功,为false表示失败 478 479**起始版本:** 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**描述:** 492 493从OH_AVFormat读取string数据。 494 495\@syscap SystemCapability.Multimedia.Media.Core 496 497**参数:** 498 499| 名称 | 描述 | 500| -------- | -------- | 501| format | 指向OH_AVFormat实例的指针 | 502| key | 读取数据的键 | 503| out | 读取string指针,out数据的生命周期与format内string对应。 如果调用者需要长时间保持它,必须内存拷贝 | 504 505**返回:** 506 507返回值为true表示成功,为false表示失败 508 509**起始版本:** 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**描述:** 522 523将指定长度的数据块写入OH_AVFormat。 524 525\@syscap SystemCapability.Multimedia.Media.Core 526 527**参数:** 528 529| 名称 | 描述 | 530| -------- | -------- | 531| format | 指向OH_AVFormat实例的指针 | 532| key | 写入数据的键 | 533| addr | 写入数据的地址 | 534| size | 写入数据的长度 | 535 536**返回:** 537 538返回值为true表示成功,为false表示失败 539 540**起始版本:** 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**描述:** 553 554将double数据写入OH_AVFormat。 555 556\@syscap SystemCapability.Multimedia.Media.Core 557 558**参数:** 559 560| 名称 | 描述 | 561| -------- | -------- | 562| format | 指向OH_AVFormat实例的指针 | 563| key | 写入数据的键 | 564| value | 写入数据的值 | 565 566**返回:** 567 568返回值为true表示成功,为false表示失败 569 570**起始版本:** 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**描述:** 583 584将float数据写入OH_AVFormat。 585 586\@syscap SystemCapability.Multimedia.Media.Core 587 588**参数:** 589 590| 名称 | 描述 | 591| -------- | -------- | 592| format | 指向OH_AVFormat实例的指针 | 593| key | 写入数据的键 | 594| value | 写入数据的值 | 595 596**返回:** 597 598返回值为true表示成功,为false表示失败 599 600**起始版本:** 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**描述:** 613 614将int数据写入OH_AVFormat。 615 616\@syscap SystemCapability.Multimedia.Media.Core 617 618**参数:** 619 620| 名称 | 描述 | 621| -------- | -------- | 622| format | 指向OH_AVFormat实例的指针 | 623| key | 写入数据的键 | 624| value | 写入数据的值 | 625 626**返回:** 627 628返回值为true表示成功,为false表示失败 629 630**起始版本:** 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**描述:** 643 644将long数据写入OH_AVFormat。 645 646\@syscap SystemCapability.Multimedia.Media.Core 647 648**参数:** 649 650| 名称 | 描述 | 651| -------- | -------- | 652| format | 指向OH_AVFormat实例的指针 | 653| key | 写入数据的键 | 654| value | 写入数据的值 | 655 656**返回:** 657 658返回值为true表示成功,为false表示失败 659 660**起始版本:** 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**描述:** 673 674将string数据写入OH_AVFormat。 675 676\@syscap SystemCapability.Multimedia.Media.Core 677 678**参数:** 679 680| 名称 | 描述 | 681| -------- | -------- | 682| format | 指向OH_AVFormat实例的指针 | 683| key | 写入数据的键 | 684| value | 写入数据的值 | 685 686**返回:** 687 688返回值为true表示成功,为false表示失败 689 690**起始版本:** 691 6929 693 694 695### OH_AVMemory_Create() 696 697 698``` 699OH_AVMemory* OH_AVMemory_Create (int32_t size) 700``` 701 702**描述:** 703 704创建OH_AVMemory实例的指针 705 706\@syscap SystemCapability.Multimedia.Media.Core 707 708**参数:** 709 710| 名称 | 描述 | 711| -------- | -------- | 712| size | 创建内存的大小,单位字节 | 713 714**返回:** 715 716如果创建成功返回OH_AVMemory实例的指针,如果失败,返回nullptr, 使用结束后需要通过OH_AVMemory_Destroy释放内存 717 718**起始版本:** 719 72010 721 722 723### OH_AVMemory_Destroy() 724 725 726``` 727OH_AVErrCode OH_AVMemory_Destroy (struct OH_AVMemory *mem) 728``` 729 730**描述:** 731 732释放OH_AVMemory实例指针的资源 733 734\@syscap SystemCapability.Multimedia.Media.Core 735 736**参数:** 737 738| 名称 | 描述 | 739| -------- | -------- | 740| mem | 指向OH_AVMemory实例的指针 | 741 742**返回:** 743 744如果释放成功返回AV_ERR_OK, 如果失败返回具体错误码, 参考[OH_AVErrCode](#oh_averrcode) 745 746**起始版本:** 747 74810 749 750 751### OH_AVMemory_GetAddr() 752 753 754``` 755uint8_t* OH_AVMemory_GetAddr (struct OH_AVMemory *mem) 756``` 757 758**描述:** 759 760获取入参的内存虚拟地址 761 762\@syscap SystemCapability.Multimedia.Media.Core 763 764**参数:** 765 766| 名称 | 描述 | 767| -------- | -------- | 768| mem | 指向OH_AVMemory实例的指针 | 769 770**返回:** 771 772如果内存有效,返回内存的虚拟地址,如果内存无效,返回nullptr 773 774**起始版本:** 775 7769 777 778 779### OH_AVMemory_GetSize() 780 781 782``` 783int32_t OH_AVMemory_GetSize (struct OH_AVMemory *mem) 784``` 785 786**描述:** 787 788获取入参的内存长度 789 790\@syscap SystemCapability.Multimedia.Media.Core 791 792**参数:** 793 794| 名称 | 描述 | 795| -------- | -------- | 796| mem | 指向OH_AVMemory实例的指针 | 797 798**返回:** 799 800如果内存有效,返回内存长度,如果内存无效,返回-1 801 802**起始版本:** 803 8049 805