1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup OHAudio 18 * @{ 19 * 20 * @brief Provide the definition of the C interface for the audio module. 21 * 22 * @syscap SystemCapability.Multimedia.Audio.Core 23 * 24 * @since 10 25 * @version 1.0 26 */ 27 28 /** 29 * @file native_audiostream_base.h 30 * 31 * @brief Declare the underlying data structure. 32 * 33 * @library libohaudio.so 34 * @syscap SystemCapability.Multimedia.Audio.Core 35 * @kit AudioKit 36 * @since 10 37 * @version 1.0 38 */ 39 40 #ifndef NATIVE_AUDIOSTREAM_BASE_H 41 #define NATIVE_AUDIOSTREAM_BASE_H 42 43 #include <stdint.h> 44 #include "multimedia/native_audio_channel_layout.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 struct OH_AudioDeviceDescriptorArray; 51 52 /** 53 * @brief Define the result of the function execution. 54 * 55 * @since 10 56 */ 57 typedef enum { 58 /** 59 * @error The call was successful. 60 * 61 * @since 10 62 */ 63 AUDIOSTREAM_SUCCESS = 0, 64 65 /** 66 * @error This means that the function was executed with an invalid input parameter. 67 * 68 * @since 10 69 */ 70 AUDIOSTREAM_ERROR_INVALID_PARAM = 1, 71 72 /** 73 * @error Execution status exception. 74 * 75 * @since 10 76 */ 77 AUDIOSTREAM_ERROR_ILLEGAL_STATE = 2, 78 79 /** 80 * @error An system error has occurred. 81 * 82 * @since 10 83 */ 84 AUDIOSTREAM_ERROR_SYSTEM = 3, 85 86 /** 87 * @error Unsupported audio format, such as unsupported encoding type, sample format etc. 88 * 89 * @since 19 90 */ 91 AUDIOSTREAM_ERROR_UNSUPPORTED_FORMAT = 4 92 } OH_AudioStream_Result; 93 94 /** 95 * @brief Define the audio stream type. 96 * 97 * @since 10 98 */ 99 typedef enum { 100 /** 101 * The type for audio stream is renderer. 102 * 103 * @since 10 104 */ 105 AUDIOSTREAM_TYPE_RENDERER = 1, 106 107 /** 108 * The type for audio stream is capturer. 109 * 110 * @since 10 111 */ 112 AUDIOSTREAM_TYPE_CAPTURER = 2 113 } OH_AudioStream_Type; 114 115 /** 116 * @brief Define the audio stream sample format. 117 * 118 * @since 10 119 */ 120 typedef enum { 121 /** 122 * Unsigned 8 format. 123 * 124 * @since 10 125 */ 126 AUDIOSTREAM_SAMPLE_U8 = 0, 127 /** 128 * Signed 16 bit integer, little endian. 129 * 130 * @since 10 131 */ 132 AUDIOSTREAM_SAMPLE_S16LE = 1, 133 /** 134 * Signed 24 bit integer, little endian. 135 * 136 * @since 10 137 */ 138 AUDIOSTREAM_SAMPLE_S24LE = 2, 139 /** 140 * Signed 32 bit integer, little endian. 141 * 142 * @since 10 143 */ 144 AUDIOSTREAM_SAMPLE_S32LE = 3, 145 /** 146 * 32 bit IEEE floating point, little endian. 147 * 148 * @since 16 149 */ 150 AUDIOSTREAM_SAMPLE_F32LE = 4, 151 } OH_AudioStream_SampleFormat; 152 153 /** 154 * @brief Define the audio encoding type. 155 * 156 * @since 10 157 */ 158 typedef enum { 159 /** 160 * PCM encoding type. 161 * 162 * @since 10 163 */ 164 AUDIOSTREAM_ENCODING_TYPE_RAW = 0, 165 /** 166 * AudioVivid encoding type. 167 * 168 * @since 12 169 */ 170 AUDIOSTREAM_ENCODING_TYPE_AUDIOVIVID = 1, 171 /** 172 * E_AC3 encoding type. 173 * 174 * @since 19 175 */ 176 AUDIOSTREAM_ENCODING_TYPE_E_AC3 = 2, 177 } OH_AudioStream_EncodingType; 178 179 /** 180 * @brief Define the audio stream info structure, used to describe basic audio format. 181 * 182 * @since 19 183 */ 184 typedef struct OH_AudioStreamInfo { 185 /** 186 * @brief Audio sampling rate. 187 * 188 * @since 19 189 */ 190 int32_t samplingRate; 191 /** 192 * @brief Audio channel layout. 193 * 194 * @since 19 195 */ 196 OH_AudioChannelLayout channelLayout; 197 /** 198 * @brief Audio encoding format type. 199 * 200 * @since 19 201 */ 202 OH_AudioStream_EncodingType encodingType; 203 /** 204 * @brief Audio sample format. 205 * 206 * @since 19 207 */ 208 OH_AudioStream_SampleFormat sampleFormat; 209 } OH_AudioStreamInfo; 210 211 /** 212 * @brief Define the audio stream usage. 213 * Audio stream usage is used to describe what work scenario 214 * the current stream is used for. 215 * 216 * @since 10 217 */ 218 typedef enum { 219 /** 220 * Unknown usage. 221 * 222 * @since 10 223 */ 224 AUDIOSTREAM_USAGE_UNKNOWN = 0, 225 /** 226 * Music usage. 227 * 228 * @since 10 229 */ 230 AUDIOSTREAM_USAGE_MUSIC = 1, 231 /** 232 * Voice communication usage. 233 * 234 * @since 10 235 */ 236 AUDIOSTREAM_USAGE_VOICE_COMMUNICATION = 2, 237 /** 238 * Voice assistant usage. 239 * 240 * @since 10 241 */ 242 AUDIOSTREAM_USAGE_VOICE_ASSISTANT = 3, 243 /** 244 * Alarm usage. 245 * 246 * @since 10 247 */ 248 AUDIOSTREAM_USAGE_ALARM = 4, 249 /** 250 * Voice message usage. 251 * 252 * @since 10 253 */ 254 AUDIOSTREAM_USAGE_VOICE_MESSAGE = 5, 255 /** 256 * Ringtone usage. 257 * 258 * @since 10 259 */ 260 AUDIOSTREAM_USAGE_RINGTONE = 6, 261 /** 262 * Notification usage. 263 * 264 * @since 10 265 */ 266 AUDIOSTREAM_USAGE_NOTIFICATION = 7, 267 /** 268 * Accessibility usage, such as screen reader. 269 * 270 * @since 10 271 */ 272 AUDIOSTREAM_USAGE_ACCESSIBILITY = 8, 273 /** 274 * Movie or video usage. 275 * 276 * @since 10 277 */ 278 AUDIOSTREAM_USAGE_MOVIE = 10, 279 /** 280 * Game sound effect usage. 281 * 282 * @since 10 283 */ 284 AUDIOSTREAM_USAGE_GAME = 11, 285 /** 286 * Audiobook usage. 287 * 288 * @since 10 289 */ 290 AUDIOSTREAM_USAGE_AUDIOBOOK = 12, 291 /** 292 * Navigation usage. 293 * 294 * @since 10 295 */ 296 AUDIOSTREAM_USAGE_NAVIGATION = 13, 297 /** 298 * Video call usage. 299 * 300 * @since 12 301 */ 302 AUDIOSTREAM_USAGE_VIDEO_COMMUNICATION = 17, 303 } OH_AudioStream_Usage; 304 305 /** 306 * @brief Define the audio latency mode. 307 * 308 * @since 10 309 */ 310 typedef enum { 311 /** 312 * This is a normal audio scene. 313 * 314 * @since 10 315 */ 316 AUDIOSTREAM_LATENCY_MODE_NORMAL = 0, 317 /** 318 * This is a low latency audio scene. 319 * 320 * @since 10 321 */ 322 AUDIOSTREAM_LATENCY_MODE_FAST = 1 323 } OH_AudioStream_LatencyMode; 324 325 /** 326 * @brief Enumerates audio direct playback modes. 327 * 328 * @since 19 329 */ 330 typedef enum { 331 /** 332 * Direct playback is not supported. 333 * 334 * @since 19 335 */ 336 AUDIOSTREAM_DIRECT_PLAYBACK_NOT_SUPPORTED = 0, 337 /** 338 * Direct playback mode which is bitstream pass-through such as compressed pass-through. 339 * 340 * @since 19 341 */ 342 AUDIOSTREAM_DIRECT_PLAYBACK_BITSTREAM_SUPPORTED = 1, 343 /** 344 * Direct playback mode of pcm. 345 * 346 * @since 19 347 */ 348 AUDIOSTREAM_DIRECT_PLAYBACK_PCM_SUPPORTED = 2 349 } OH_AudioStream_DirectPlaybackMode; 350 351 /** 352 * @brief Define the audio stream volume mode. 353 * 354 * @since 18 355 */ 356 typedef enum { 357 /** 358 * Indicates this audio stream volume will be affected by system volume, also the default behavior. 359 * 360 * @since 18 361 */ 362 AUDIOSTREAM_VOLUMEMODE_SYSTEM_GLOBAL = 0, 363 /** 364 * Indicates this audio stream volume will be affected by app's individual volume percentage which set by yourself 365 * using the app volume api. 366 * 367 * @since 18 368 */ 369 AUDIOSTREAM_VOLUMEMODE_APP_INDIVIDUAL = 1 370 } OH_AudioStream_VolumeMode; 371 372 /** 373 * @brief Define the audio event. 374 * 375 * @deprecated since 18 376 * @useinstead OH_AudioRenderer_OutputDeviceChangeCallback. 377 * @since 10 378 */ 379 typedef enum { 380 /** 381 * The routing of the audio has changed. 382 * 383 * @deprecated since 18 384 * @useinstead OH_AudioRenderer_OutputDeviceChangeCallback. 385 * @since 10 386 */ 387 AUDIOSTREAM_EVENT_ROUTING_CHANGED = 0 388 } OH_AudioStream_Event; 389 390 /** 391 * @brief The audio stream states 392 * 393 * @since 10 394 */ 395 typedef enum { 396 /** 397 * The invalid state. 398 * 399 * @since 10 400 */ 401 AUDIOSTREAM_STATE_INVALID = -1, 402 /** 403 * Create new instance state. 404 * 405 * @since 10 406 */ 407 AUDIOSTREAM_STATE_NEW = 0, 408 /** 409 * The prepared state. 410 * 411 * @since 10 412 */ 413 AUDIOSTREAM_STATE_PREPARED = 1, 414 /** 415 * The stream is running. 416 * 417 * @since 10 418 */ 419 AUDIOSTREAM_STATE_RUNNING = 2, 420 /** 421 * The stream is stopped. 422 * 423 * @since 10 424 */ 425 AUDIOSTREAM_STATE_STOPPED = 3, 426 /** 427 * The stream is released. 428 * 429 * @since 10 430 */ 431 AUDIOSTREAM_STATE_RELEASED = 4, 432 /** 433 * The stream is paused. 434 * 435 * @since 10 436 */ 437 AUDIOSTREAM_STATE_PAUSED = 5, 438 } OH_AudioStream_State; 439 440 /** 441 * @brief Defines the audio interrupt type. 442 * 443 * @since 10 444 */ 445 typedef enum { 446 /** 447 * Force type, system change audio state. 448 * 449 * @since 10 450 */ 451 AUDIOSTREAM_INTERRUPT_FORCE = 0, 452 /** 453 * Share type, application change audio state. 454 * 455 * @since 10 456 */ 457 AUDIOSTREAM_INTERRUPT_SHARE = 1 458 } OH_AudioInterrupt_ForceType; 459 460 /** 461 * @brief Defines the audio interrupt hint type. 462 * 463 * @since 10 464 */ 465 typedef enum { 466 /** 467 * None. 468 * 469 * @since 10 470 */ 471 AUDIOSTREAM_INTERRUPT_HINT_NONE = 0, 472 /** 473 * Resume the stream. 474 * 475 * @since 10 476 */ 477 AUDIOSTREAM_INTERRUPT_HINT_RESUME = 1, 478 /** 479 * Pause the stream. 480 * 481 * @since 10 482 */ 483 AUDIOSTREAM_INTERRUPT_HINT_PAUSE = 2, 484 /** 485 * Stop the stream. 486 * 487 * @since 10 488 */ 489 AUDIOSTREAM_INTERRUPT_HINT_STOP = 3, 490 /** 491 * Ducked the stream. 492 * 493 * @since 10 494 */ 495 AUDIOSTREAM_INTERRUPT_HINT_DUCK = 4, 496 /** 497 * Unducked the stream. 498 * 499 * @since 10 500 */ 501 AUDIOSTREAM_INTERRUPT_HINT_UNDUCK = 5, 502 /** 503 * Mute the stream. 504 * 505 * @since 20 506 */ 507 AUDIOSTREAM_INTERRUPT_HINT_MUTE = 6, 508 /** 509 * Unmute the stream. 510 * 511 * @since 20 512 */ 513 AUDIOSTREAM_INTERRUPT_HINT_UNMUTE = 7 514 } OH_AudioInterrupt_Hint; 515 516 /** 517 * @brief Defines the audio source type. 518 * 519 * @since 10 520 */ 521 typedef enum { 522 /** 523 * Invalid type. 524 * 525 * @since 10 526 */ 527 AUDIOSTREAM_SOURCE_TYPE_INVALID = -1, 528 /** 529 * Mic source type. 530 * 531 * @since 10 532 */ 533 AUDIOSTREAM_SOURCE_TYPE_MIC = 0, 534 /** 535 * Voice recognition source type. 536 * 537 * @since 10 538 */ 539 AUDIOSTREAM_SOURCE_TYPE_VOICE_RECOGNITION = 1, 540 /** 541 * Playback capture source type. 542 * 543 * @deprecated since 12 544 * @useinstead OH_AVScreenCapture in native interface. 545 * @since 10 546 */ 547 AUDIOSTREAM_SOURCE_TYPE_PLAYBACK_CAPTURE = 2, 548 /** 549 * Voice call source type. 550 * 551 * @permission ohos.permission.RECORD_VOICE_CALL 552 * @systemapi 553 * @since 11 554 */ 555 AUDIOSTREAM_SOURCE_TYPE_VOICE_CALL = 4, 556 /** 557 * Voice communication source type. 558 * 559 * @since 10 560 */ 561 AUDIOSTREAM_SOURCE_TYPE_VOICE_COMMUNICATION = 7, 562 /** 563 * Voice message source type. 564 * 565 * @since 12 566 */ 567 AUDIOSTREAM_SOURCE_TYPE_VOICE_MESSAGE = 10, 568 /** 569 * Camcorder source type. 570 * 571 * @since 13 572 */ 573 AUDIOSTREAM_SOURCE_TYPE_CAMCORDER = 13, 574 /** 575 * Unprocessed source type. 576 * 577 * @since 15 578 */ 579 AUDIOSTREAM_SOURCE_TYPE_UNPROCESSED = 14, 580 /** 581 * live broadcast source type. 582 * 583 * @since 20 584 */ 585 AUDIOSTREAM_SOURCE_TYPE_LIVE = 17 586 } OH_AudioStream_SourceType; 587 588 /** 589 * Defines the audio interrupt mode. 590 * 591 * @since 12 592 */ 593 typedef enum { 594 /** 595 * Share mode 596 */ 597 AUDIOSTREAM_INTERRUPT_MODE_SHARE = 0, 598 /** 599 * Independent mode 600 */ 601 AUDIOSTREAM_INTERRUPT_MODE_INDEPENDENT = 1 602 } OH_AudioInterrupt_Mode; 603 604 /** 605 * @brief Defines the audio effect mode. 606 * 607 * @since 12 608 */ 609 typedef enum { 610 /** 611 * Audio Effect Mode effect none. 612 * 613 * @since 12 614 */ 615 EFFECT_NONE = 0, 616 /** 617 * Audio Effect Mode effect default. 618 * 619 * @since 12 620 */ 621 EFFECT_DEFAULT = 1, 622 } OH_AudioStream_AudioEffectMode; 623 624 /** 625 * @brief Defines the fast status. 626 * 627 * @since 20 628 */ 629 typedef enum { 630 /** 631 * normal status 632 */ 633 AUDIOSTREAM_FASTSTATUS_NORMAL = 0, 634 /** 635 * fast status 636 */ 637 AUDIOSTREAM_FASTSTATUS_FAST = 1 638 } OH_AudioStream_FastStatus; 639 640 /** 641 * @brief Declaring the audio stream builder. 642 * The instance of builder is used for creating audio stream. 643 * 644 * @since 10 645 */ 646 typedef struct OH_AudioStreamBuilderStruct OH_AudioStreamBuilder; 647 648 /** 649 * @brief Declaring the audio renderer stream. 650 * The instance of renderer stream is used for playing audio data. 651 * 652 * @since 10 653 */ 654 typedef struct OH_AudioRendererStruct OH_AudioRenderer; 655 656 /** 657 * @brief Declaring the audio capturer stream. 658 * The instance of renderer stream is used for capturing audio data. 659 * 660 * @since 10 661 */ 662 typedef struct OH_AudioCapturerStruct OH_AudioCapturer; 663 664 /** 665 * @brief Declaring the callback struct for renderer stream. 666 * 667 * @deprecated since 18 668 * @useinstead Use the callback type: OH_AudioRenderer_OnWriteDataCallback, OH_AudioRenderer_OutputDeviceChangeCallback, 669 * OH_AudioRenderer_OnInterruptEvent, OH_AudioRenderer_OnErrorCallback separately. 670 * @since 10 671 */ 672 typedef struct OH_AudioRenderer_Callbacks_Struct { 673 /** 674 * This function pointer will point to the callback function that 675 * is used to write audio data 676 * 677 * @deprecated since 18 678 * @useinstead OH_AudioRenderer_OnWriteDataCallback. 679 * @since 10 680 */ 681 int32_t (*OH_AudioRenderer_OnWriteData)( 682 OH_AudioRenderer* renderer, 683 void* userData, 684 void* buffer, 685 int32_t length); 686 687 /** 688 * This function pointer will point to the callback function that 689 * is used to handle audio renderer stream events. 690 * 691 * @deprecated since 18 692 * @useinstead OH_AudioRenderer_OutputDeviceChangeCallback. 693 * @since 10 694 */ 695 int32_t (*OH_AudioRenderer_OnStreamEvent)( 696 OH_AudioRenderer* renderer, 697 void* userData, 698 OH_AudioStream_Event event); 699 700 /** 701 * This function pointer will point to the callback function that 702 * is used to handle audio interrupt events. 703 * 704 * @deprecated since 18 705 * @useinstead OH_AudioRenderer_OnInterruptCallback. 706 * @since 10 707 */ 708 int32_t (*OH_AudioRenderer_OnInterruptEvent)( 709 OH_AudioRenderer* renderer, 710 void* userData, 711 OH_AudioInterrupt_ForceType type, 712 OH_AudioInterrupt_Hint hint); 713 714 /** 715 * This function pointer will point to the callback function that 716 * is used to handle audio error result. 717 * 718 * @deprecated since 18 719 * @useinstead OH_AudioRenderer_OnErrorCallback. 720 * @since 10 721 */ 722 int32_t (*OH_AudioRenderer_OnError)( 723 OH_AudioRenderer* renderer, 724 void* userData, 725 OH_AudioStream_Result error); 726 } OH_AudioRenderer_Callbacks; 727 728 /** 729 * @brief Declaring the callback struct for capturer stream. 730 * 731 * @deprecated since 18 732 * @useinstead Use the callback type: OH_AudioCapturer_OnReadDataCallback, OH_AudioCapturer_OnDeviceChangeCallback, 733 * OH_AudioCapturer_OnInterruptCallback and OH_AudioCapturer_OnErrorCallback separately. 734 * @since 10 735 */ 736 typedef struct OH_AudioCapturer_Callbacks_Struct { 737 /** 738 * This function pointer will point to the callback function that 739 * is used to read audio data. 740 * 741 * @deprecated since 18 742 * @useinstead OH_AudioCapturer_OnReadDataCallback 743 * @since 10 744 */ 745 int32_t (*OH_AudioCapturer_OnReadData)( 746 OH_AudioCapturer* capturer, 747 void* userData, 748 void* buffer, 749 int32_t length); 750 751 /** 752 * This function pointer will point to the callback function that 753 * is used to handle audio capturer stream events. 754 * 755 * @deprecated since 18 756 * @useinstead OH_AudioRenderer_OutputDeviceChangeCallback 757 * @since 10 758 */ 759 int32_t (*OH_AudioCapturer_OnStreamEvent)( 760 OH_AudioCapturer* capturer, 761 void* userData, 762 OH_AudioStream_Event event); 763 764 /** 765 * This function pointer will point to the callback function that 766 * is used to handle audio interrupt events. 767 * 768 * @deprecated since 18 769 * @useinstead OH_AudioCapturer_OnInterruptCallback 770 * @since 10 771 */ 772 int32_t (*OH_AudioCapturer_OnInterruptEvent)( 773 OH_AudioCapturer* capturer, 774 void* userData, 775 OH_AudioInterrupt_ForceType type, 776 OH_AudioInterrupt_Hint hint); 777 778 /** 779 * This function pointer will point to the callback function that 780 * is used to handle audio error result. 781 * 782 * @deprecated since 18 783 * @useinstead OH_AudioCapturer_OnErrorCallback 784 * @since 10 785 */ 786 int32_t (*OH_AudioCapturer_OnError)( 787 OH_AudioCapturer* capturer, 788 void* userData, 789 OH_AudioStream_Result error); 790 } OH_AudioCapturer_Callbacks; 791 792 /** 793 * @brief Defines reason for device changes of one audio stream. 794 * 795 * @since 11 796 */ 797 typedef enum { 798 /* Unknown. */ 799 REASON_UNKNOWN = 0, 800 /* New Device available. */ 801 REASON_NEW_DEVICE_AVAILABLE = 1, 802 /* Old Device unavailable. Applications should consider to pause the audio playback when this reason is 803 reported. */ 804 REASON_OLD_DEVICE_UNAVAILABLE = 2, 805 /* Device is overrode by user or system. */ 806 REASON_OVERRODE = 3, 807 /** 808 * @brief Device information when the audio session is activated. 809 * 810 * @since 20 811 */ 812 REASON_SESSION_ACTIVATED = 4, 813 /** 814 * @brief The priority of the stream has changed. 815 * 816 * @since 20 817 */ 818 REASON_STREAM_PRIORITY_CHANGED = 5, 819 } OH_AudioStream_DeviceChangeReason; 820 821 /** 822 * @brief Callback when the output device of an audio renderer changed. 823 * 824 * @param renderer AudioRenderer where this event occurs. 825 * @param userData User data which is passed by user. 826 * @param reason Indicates that why does the output device changes. 827 * @since 11 828 */ 829 typedef void (*OH_AudioRenderer_OutputDeviceChangeCallback)(OH_AudioRenderer* renderer, void* userData, 830 OH_AudioStream_DeviceChangeReason reason); 831 832 /** 833 * @brief Callback when the mark position reached. 834 * 835 * @param renderer AudioRenderer where this event occurs. 836 * @param samplePos Mark position in samples. 837 * @param userData User data which is passed by user. 838 * @since 12 839 */ 840 typedef void (*OH_AudioRenderer_OnMarkReachedCallback)(OH_AudioRenderer* renderer, uint32_t samplePos, void* userData); 841 842 /** 843 * @brief This function pointer will point to the callback function that 844 * is used to write audio data with metadata 845 * 846 * @param renderer AudioRenderer where this event occurs. 847 * @param userData User data which is passed by user. 848 * @param audioData Audio data which is written by user. 849 * @param audioDataSize Audio data size which is the size of audio data written by user. 850 * @param metadata Metadata which is written by user. 851 * @param metadataSize Metadata size which is the size of metadata written by user. 852 * @return Error code of the callback function returned by user. 853 * @since 12 854 */ 855 typedef int32_t (*OH_AudioRenderer_WriteDataWithMetadataCallback)(OH_AudioRenderer* renderer, 856 void* userData, void* audioData, int32_t audioDataSize, void* metadata, int32_t metadataSize); 857 858 /** 859 * @brief Defines Enumeration of audio stream privacy type for playback capture. 860 * 861 * @since 12 862 */ 863 typedef enum { 864 /** Privacy type that stream can be captured by third party applications. 865 * @since 12 866 */ 867 AUDIO_STREAM_PRIVACY_TYPE_PUBLIC = 0, 868 /** Privacy type that stream can not be captured. 869 * @since 12 870 */ 871 AUDIO_STREAM_PRIVACY_TYPE_PRIVATE = 1, 872 } OH_AudioStream_PrivacyType; 873 874 /** 875 * @brief Defines enumeration of audio data callback result. 876 * 877 * @since 12 878 */ 879 typedef enum { 880 /** Result of audio data callabck is invalid. */ 881 AUDIO_DATA_CALLBACK_RESULT_INVALID = -1, 882 /** Result of audio data callabck is valid. */ 883 AUDIO_DATA_CALLBACK_RESULT_VALID = 0, 884 } OH_AudioData_Callback_Result; 885 886 /** 887 * @brief Callback function of write data. 888 * 889 * This function is similar with OH_AudioRenderer_Callbacks_Struct.OH_AudioRenderer_OnWriteData instead of the return 890 * value. The return result of this function indicates whether the data filled in the buffer is valid or invalid. If 891 * result is invalid, the data filled by user will not be played. 892 * 893 * @param renderer AudioRenderer where this callback occurs. 894 * @param userData User data which is passed by user. 895 * @param audioData Audio data pointer, where user should fill in audio data. 896 * @param audioDataSize Size of audio data that user should fill in. 897 * @return Audio Data callback result. 898 * @see OH_AudioRenderer_Callbacks_Struct.OH_AudioRenderer_OnWriteData 899 * @since 12 900 */ 901 typedef OH_AudioData_Callback_Result (*OH_AudioRenderer_OnWriteDataCallback)(OH_AudioRenderer* renderer, void* userData, 902 void* audioData, int32_t audioDataSize); 903 904 /** 905 * @brief Callback function of write data on Render. 906 * 907 * Different with OH_AudioRenderer_OnWriteDataCallback, this function allows the caller to write partial data which 908 * ranges from 0 to the callback buffer size. If 0 is returned, the callback thread will sleep for a while. Otherwise, 909 * the system may callback again immediately. 910 * 911 * @param renderer AudioRenderer where this callback occurs. 912 * @param userData User data which is passed by user. 913 * @param audioData Audio data pointer, where user should fill in audio data. 914 * @param audioDataSize Size of audio data that user should fill in. 915 * @return Length of the valid data that has written into audioData buffer. The return value must be in range of 916 * [0, audioDataSize]. If the return value is less than 0, the system changes it to 0. And, if the return value is 917 * greater than audioDataSize, the system changes it to audioDataSize. 918 * @see OH_AudioRenderer_OnWriteDataCallback 919 * @since 20 920 */ 921 typedef int32_t (*OH_AudioRenderer_OnWriteDataCallbackAdvanced)(OH_AudioRenderer* renderer, void* userData, 922 void* audioData, int32_t audioDataSize); 923 924 #ifdef __cplusplus 925 } 926 #endif 927 928 #endif // NATIVE_AUDIOSTREAM_BASE_H 929