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 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /** 50 * @brief Define the result of the function execution. 51 * 52 * @since 10 53 */ 54 typedef enum { 55 /** 56 * @error The call was successful. 57 * 58 * @since 10 59 */ 60 AUDIOSTREAM_SUCCESS = 0, 61 62 /** 63 * @error This means that the function was executed with an invalid input parameter. 64 * 65 * @since 10 66 */ 67 AUDIOSTREAM_ERROR_INVALID_PARAM = 1, 68 69 /** 70 * @error Execution status exception. 71 * 72 * @since 10 73 */ 74 AUDIOSTREAM_ERROR_ILLEGAL_STATE = 2, 75 76 /** 77 * @error An system error has occurred. 78 * 79 * @since 10 80 */ 81 AUDIOSTREAM_ERROR_SYSTEM = 3 82 } OH_AudioStream_Result; 83 84 /** 85 * @brief Define the audio stream type. 86 * 87 * @since 10 88 */ 89 typedef enum { 90 /** 91 * The type for audio stream is renderer. 92 * 93 * @since 10 94 */ 95 AUDIOSTREAM_TYPE_RENDERER = 1, 96 97 /** 98 * The type for audio stream is capturer. 99 * 100 * @since 10 101 */ 102 AUDIOSTREAM_TYPE_CAPTURER = 2 103 } OH_AudioStream_Type; 104 105 /** 106 * @brief Define the audio stream sample format. 107 * 108 * @since 10 109 */ 110 typedef enum { 111 /** 112 * Unsigned 8 format. 113 * 114 * @since 10 115 */ 116 AUDIOSTREAM_SAMPLE_U8 = 0, 117 /** 118 * Signed 16 bit integer, little endian. 119 * 120 * @since 10 121 */ 122 AUDIOSTREAM_SAMPLE_S16LE = 1, 123 /** 124 * Signed 24 bit integer, little endian. 125 * 126 * @since 10 127 */ 128 AUDIOSTREAM_SAMPLE_S24LE = 2, 129 /** 130 * Signed 32 bit integer, little endian. 131 * 132 * @since 10 133 */ 134 AUDIOSTREAM_SAMPLE_S32LE = 3, 135 } OH_AudioStream_SampleFormat; 136 137 /** 138 * @brief Define the audio encoding type. 139 * 140 * @since 10 141 */ 142 typedef enum { 143 /** 144 * PCM encoding type. 145 * 146 * @since 10 147 */ 148 AUDIOSTREAM_ENCODING_TYPE_RAW = 0, 149 /** 150 * AudioVivid encoding type. 151 * 152 * @since 12 153 */ 154 AUDIOSTREAM_ENCODING_TYPE_AUDIOVIVID = 1, 155 } OH_AudioStream_EncodingType; 156 157 /** 158 * @brief Define the audio stream usage. 159 * Audio stream usage is used to describe what work scenario 160 * the current stream is used for. 161 * 162 * @since 10 163 */ 164 typedef enum { 165 /** 166 * Unknown usage. 167 * 168 * @since 10 169 */ 170 AUDIOSTREAM_USAGE_UNKNOWN = 0, 171 /** 172 * Music usage. 173 * 174 * @since 10 175 */ 176 AUDIOSTREAM_USAGE_MUSIC = 1, 177 /** 178 * Voice communication usage. 179 * 180 * @since 10 181 */ 182 AUDIOSTREAM_USAGE_VOICE_COMMUNICATION = 2, 183 /** 184 * Voice assistant usage. 185 * 186 * @since 10 187 */ 188 AUDIOSTREAM_USAGE_VOICE_ASSISTANT = 3, 189 /** 190 * Alarm usage. 191 * 192 * @since 10 193 */ 194 AUDIOSTREAM_USAGE_ALARM = 4, 195 /** 196 * Voice message usage. 197 * 198 * @since 10 199 */ 200 AUDIOSTREAM_USAGE_VOICE_MESSAGE = 5, 201 /** 202 * Ringtone usage. 203 * 204 * @since 10 205 */ 206 AUDIOSTREAM_USAGE_RINGTONE = 6, 207 /** 208 * Notification usage. 209 * 210 * @since 10 211 */ 212 AUDIOSTREAM_USAGE_NOTIFICATION = 7, 213 /** 214 * Accessibility usage, such as screen reader. 215 * 216 * @since 10 217 */ 218 AUDIOSTREAM_USAGE_ACCESSIBILITY = 8, 219 /** 220 * Movie or video usage. 221 * 222 * @since 10 223 */ 224 AUDIOSTREAM_USAGE_MOVIE = 10, 225 /** 226 * Game sound effect usage. 227 * 228 * @since 10 229 */ 230 AUDIOSTREAM_USAGE_GAME = 11, 231 /** 232 * Audiobook usage. 233 * 234 * @since 10 235 */ 236 AUDIOSTREAM_USAGE_AUDIOBOOK = 12, 237 /** 238 * Navigation usage. 239 * 240 * @since 10 241 */ 242 AUDIOSTREAM_USAGE_NAVIGATION = 13, 243 /** 244 * Video call usage. 245 * 246 * @since 12 247 */ 248 AUDIOSTREAM_USAGE_VIDEO_COMMUNICATION = 17, 249 } OH_AudioStream_Usage; 250 251 /** 252 * @brief Define the audio latency mode. 253 * 254 * @since 10 255 */ 256 typedef enum { 257 /** 258 * This is a normal audio scene. 259 * 260 * @since 10 261 */ 262 AUDIOSTREAM_LATENCY_MODE_NORMAL = 0, 263 /** 264 * This is a low latency audio scene. 265 * 266 * @since 10 267 */ 268 AUDIOSTREAM_LATENCY_MODE_FAST = 1 269 } OH_AudioStream_LatencyMode; 270 271 /** 272 * @brief Define the audio event. 273 * 274 * @since 10 275 */ 276 typedef enum { 277 /** 278 * The routing of the audio has changed. 279 * 280 * @since 10 281 */ 282 AUDIOSTREAM_EVENT_ROUTING_CHANGED = 0 283 } OH_AudioStream_Event; 284 285 /** 286 * @brief The audio stream states 287 * 288 * @since 10 289 */ 290 typedef enum { 291 /** 292 * The invalid state. 293 * 294 * @since 10 295 */ 296 AUDIOSTREAM_STATE_INVALID = -1, 297 /** 298 * Create new instance state. 299 * 300 * @since 10 301 */ 302 AUDIOSTREAM_STATE_NEW = 0, 303 /** 304 * The prepared state. 305 * 306 * @since 10 307 */ 308 AUDIOSTREAM_STATE_PREPARED = 1, 309 /** 310 * The stream is running. 311 * 312 * @since 10 313 */ 314 AUDIOSTREAM_STATE_RUNNING = 2, 315 /** 316 * The stream is stopped. 317 * 318 * @since 10 319 */ 320 AUDIOSTREAM_STATE_STOPPED = 3, 321 /** 322 * The stream is released. 323 * 324 * @since 10 325 */ 326 AUDIOSTREAM_STATE_RELEASED = 4, 327 /** 328 * The stream is paused. 329 * 330 * @since 10 331 */ 332 AUDIOSTREAM_STATE_PAUSED = 5, 333 } OH_AudioStream_State; 334 335 /** 336 * @brief Defines the audio interrupt type. 337 * 338 * @since 10 339 */ 340 typedef enum { 341 /** 342 * Force type, system change audio state. 343 * 344 * @since 10 345 */ 346 AUDIOSTREAM_INTERRUPT_FORCE = 0, 347 /** 348 * Share type, application change audio state. 349 * 350 * @since 10 351 */ 352 AUDIOSTREAM_INTERRUPT_SHARE = 1 353 } OH_AudioInterrupt_ForceType; 354 355 /** 356 * @brief Defines the audio interrupt hint type. 357 * 358 * @since 10 359 */ 360 typedef enum { 361 /** 362 * None. 363 * 364 * @since 10 365 */ 366 AUDIOSTREAM_INTERRUPT_HINT_NONE = 0, 367 /** 368 * Resume the stream. 369 * 370 * @since 10 371 */ 372 AUDIOSTREAM_INTERRUPT_HINT_RESUME = 1, 373 /** 374 * Pause the stream. 375 * 376 * @since 10 377 */ 378 AUDIOSTREAM_INTERRUPT_HINT_PAUSE = 2, 379 /** 380 * Stop the stream. 381 * 382 * @since 10 383 */ 384 AUDIOSTREAM_INTERRUPT_HINT_STOP = 3, 385 /** 386 * Ducked the stream. 387 * 388 * @since 10 389 */ 390 AUDIOSTREAM_INTERRUPT_HINT_DUCK = 4, 391 /** 392 * Unducked the stream. 393 * 394 * @since 10 395 */ 396 AUDIOSTREAM_INTERRUPT_HINT_UNDUCK = 5 397 } OH_AudioInterrupt_Hint; 398 399 /** 400 * @brief Defines the audio source type. 401 * 402 * @since 10 403 */ 404 typedef enum { 405 /** 406 * Invalid type. 407 * 408 * @since 10 409 */ 410 AUDIOSTREAM_SOURCE_TYPE_INVALID = -1, 411 /** 412 * Mic source type. 413 * 414 * @since 10 415 */ 416 AUDIOSTREAM_SOURCE_TYPE_MIC = 0, 417 /** 418 * Voice recognition source type. 419 * 420 * @since 10 421 */ 422 AUDIOSTREAM_SOURCE_TYPE_VOICE_RECOGNITION = 1, 423 /** 424 * Playback capture source type. 425 * 426 * @deprecated since 12 427 * @useinstead OH_AVScreenCapture in native interface. 428 * @since 10 429 */ 430 AUDIOSTREAM_SOURCE_TYPE_PLAYBACK_CAPTURE = 2, 431 /** 432 * Voice communication source type. 433 * 434 * @since 10 435 */ 436 AUDIOSTREAM_SOURCE_TYPE_VOICE_COMMUNICATION = 7, 437 /** 438 * Voice message source type. 439 * 440 * @since 12 441 */ 442 AUDIOSTREAM_SOURCE_TYPE_VOICE_MESSAGE = 10, 443 /** 444 * Camcorder source type. 445 * 446 * @since 13 447 */ 448 AUDIOSTREAM_SOURCE_TYPE_CAMCORDER = 13 449 } OH_AudioStream_SourceType; 450 451 /** 452 * @brief Defines the audio interrupt mode. 453 * 454 * @since 12 455 */ 456 typedef enum { 457 /** 458 * Share mode 459 */ 460 AUDIOSTREAM_INTERRUPT_MODE_SHARE = 0, 461 /** 462 * Independent mode 463 */ 464 AUDIOSTREAM_INTERRUPT_MODE_INDEPENDENT = 1 465 } OH_AudioInterrupt_Mode; 466 467 /** 468 * @brief Defines the audio effect mode. 469 * 470 * @since 12 471 */ 472 typedef enum { 473 /** 474 * Audio Effect Mode effect none. 475 * 476 * @since 12 477 */ 478 EFFECT_NONE = 0, 479 /** 480 * Audio Effect Mode effect default. 481 * 482 * @since 12 483 */ 484 EFFECT_DEFAULT = 1, 485 } OH_AudioStream_AudioEffectMode; 486 487 /** 488 * @brief Declaring the audio stream builder. 489 * The instance of builder is used for creating audio stream. 490 * 491 * @since 10 492 */ 493 typedef struct OH_AudioStreamBuilderStruct OH_AudioStreamBuilder; 494 495 /** 496 * @brief Declaring the audio renderer stream. 497 * The instance of renderer stream is used for playing audio data. 498 * 499 * @since 10 500 */ 501 typedef struct OH_AudioRendererStruct OH_AudioRenderer; 502 503 /** 504 * @brief Declaring the audio capturer stream. 505 * The instance of renderer stream is used for capturing audio data. 506 * 507 * @since 10 508 */ 509 typedef struct OH_AudioCapturerStruct OH_AudioCapturer; 510 511 /** 512 * @brief Declaring the callback struct for renderer stream. 513 * 514 * @since 10 515 */ 516 typedef struct OH_AudioRenderer_Callbacks_Struct { 517 /** 518 * This function pointer will point to the callback function that 519 * is used to write audio data 520 * 521 * @since 10 522 */ 523 int32_t (*OH_AudioRenderer_OnWriteData)( 524 OH_AudioRenderer* renderer, 525 void* userData, 526 void* buffer, 527 int32_t length); 528 529 /** 530 * This function pointer will point to the callback function that 531 * is used to handle audio renderer stream events. 532 * 533 * @since 10 534 */ 535 int32_t (*OH_AudioRenderer_OnStreamEvent)( 536 OH_AudioRenderer* renderer, 537 void* userData, 538 OH_AudioStream_Event event); 539 540 /** 541 * This function pointer will point to the callback function that 542 * is used to handle audio interrupt events. 543 * 544 * @since 10 545 */ 546 int32_t (*OH_AudioRenderer_OnInterruptEvent)( 547 OH_AudioRenderer* renderer, 548 void* userData, 549 OH_AudioInterrupt_ForceType type, 550 OH_AudioInterrupt_Hint hint); 551 552 /** 553 * This function pointer will point to the callback function that 554 * is used to handle audio error result. 555 * 556 * @since 10 557 */ 558 int32_t (*OH_AudioRenderer_OnError)( 559 OH_AudioRenderer* renderer, 560 void* userData, 561 OH_AudioStream_Result error); 562 } OH_AudioRenderer_Callbacks; 563 564 /** 565 * @brief Declaring the callback struct for capturer stream. 566 * 567 * @since 10 568 */ 569 typedef struct OH_AudioCapturer_Callbacks_Struct { 570 /** 571 * This function pointer will point to the callback function that 572 * is used to read audio data. 573 * 574 * @since 10 575 */ 576 int32_t (*OH_AudioCapturer_OnReadData)( 577 OH_AudioCapturer* capturer, 578 void* userData, 579 void* buffer, 580 int32_t length); 581 582 /** 583 * This function pointer will point to the callback function that 584 * is used to handle audio capturer stream events. 585 * 586 * @since 10 587 */ 588 int32_t (*OH_AudioCapturer_OnStreamEvent)( 589 OH_AudioCapturer* capturer, 590 void* userData, 591 OH_AudioStream_Event event); 592 593 /** 594 * This function pointer will point to the callback function that 595 * is used to handle audio interrupt events. 596 * 597 * @since 10 598 */ 599 int32_t (*OH_AudioCapturer_OnInterruptEvent)( 600 OH_AudioCapturer* capturer, 601 void* userData, 602 OH_AudioInterrupt_ForceType type, 603 OH_AudioInterrupt_Hint hint); 604 605 /** 606 * This function pointer will point to the callback function that 607 * is used to handle audio error result. 608 * 609 * @since 10 610 */ 611 int32_t (*OH_AudioCapturer_OnError)( 612 OH_AudioCapturer* capturer, 613 void* userData, 614 OH_AudioStream_Result error); 615 } OH_AudioCapturer_Callbacks; 616 617 /** 618 * @brief Defines reason for device changes of one audio stream. 619 * 620 * @since 11 621 */ 622 typedef enum { 623 /* Unknown. */ 624 REASON_UNKNOWN = 0, 625 /* New Device available. */ 626 REASON_NEW_DEVICE_AVAILABLE = 1, 627 /* Old Device unavailable. Applications should consider to pause the audio playback when this reason is 628 reported. */ 629 REASON_OLD_DEVICE_UNAVAILABLE = 2, 630 /* Device is overrode by user or system. */ 631 REASON_OVERRODE = 3, 632 } OH_AudioStream_DeviceChangeReason; 633 634 /** 635 * @brief Callback when the output device of an audio renderer changed. 636 * 637 * @param renderer AudioRenderer where this event occurs. 638 * @param userData User data which is passed by user. 639 * @param reason Indicates that why does the output device changes. 640 * @since 11 641 */ 642 typedef void (*OH_AudioRenderer_OutputDeviceChangeCallback)(OH_AudioRenderer* renderer, void* userData, 643 OH_AudioStream_DeviceChangeReason reason); 644 645 /** 646 * @brief Callback when the mark position reached. 647 * 648 * @param renderer AudioRenderer where this event occurs. 649 * @param samplePos Mark position in samples. 650 * @param userData User data which is passed by user. 651 * @since 12 652 */ 653 typedef void (*OH_AudioRenderer_OnMarkReachedCallback)(OH_AudioRenderer* renderer, uint32_t samplePos, void* userData); 654 655 /** 656 * @brief This function pointer will point to the callback function that 657 * is used to write audio data with metadata 658 * 659 * @param renderer AudioRenderer where this event occurs. 660 * @param userData User data which is passed by user. 661 * @param audioData Audio data which is written by user. 662 * @param audioDataSize Audio data size which is the size of audio data written by user. 663 * @param metadata Metadata which is written by user. 664 * @param metadataSize Metadata size which is the size of metadata written by user. 665 * @return Error code of the callback function returned by user. 666 * @since 12 667 */ 668 typedef int32_t (*OH_AudioRenderer_WriteDataWithMetadataCallback)(OH_AudioRenderer* renderer, 669 void* userData, void* audioData, int32_t audioDataSize, void* metadata, int32_t metadataSize); 670 671 /** 672 * @brief Defines Enumeration of audio stream privacy type for playback capture. 673 * 674 * @since 12 675 */ 676 typedef enum { 677 /** Privacy type that stream can be captured by third party applications. 678 * @since 12 679 */ 680 AUDIO_STREAM_PRIVACY_TYPE_PUBLIC = 0, 681 /** Privacy type that stream can not be captured. 682 * @since 12 683 */ 684 AUDIO_STREAM_PRIVACY_TYPE_PRIVATE = 1, 685 } OH_AudioStream_PrivacyType; 686 687 /** 688 * @brief Defines enumeration of audio data callback result. 689 * 690 * @since 12 691 */ 692 typedef enum { 693 /** Result of audio data callabck is invalid. */ 694 AUDIO_DATA_CALLBACK_RESULT_INVALID = -1, 695 /** Result of audio data callabck is valid. */ 696 AUDIO_DATA_CALLBACK_RESULT_VALID = 0, 697 } OH_AudioData_Callback_Result; 698 699 /** 700 * @brief Callback function of write data. 701 * 702 * This function is similar with OH_AudioRenderer_Callbacks_Struct.OH_AudioRenderer_OnWriteData instead of the return 703 * value. The return result of this function indicates whether the data filled in the buffer is valid or invalid. If 704 * result is invalid, the data filled by user will not be played. 705 * 706 * @param renderer AudioRenderer where this callback occurs. 707 * @param userData User data which is passed by user. 708 * @param audioData Audio data pointer, where user should fill in audio data. 709 * @param audioDataSize Size of audio data that user should fill in. 710 * @return Audio Data callback result. 711 * @see OH_AudioRenderer_Callbacks_Struct.OH_AudioRenderer_OnWriteData 712 * @since 12 713 */ 714 typedef OH_AudioData_Callback_Result (*OH_AudioRenderer_OnWriteDataCallback)(OH_AudioRenderer* renderer, void* userData, 715 void* audioData, int32_t audioDataSize); 716 #ifdef __cplusplus 717 } 718 #endif 719 720 #endif // NATIVE_AUDIOSTREAM_BASE_H 721