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 * @syscap SystemCapability.Multimedia.Audio.Core 34 * @since 10 35 * @version 1.0 36 */ 37 38 #ifndef NATIVE_AUDIOSTREAM_BASE_H 39 #define NATIVE_AUDIOSTREAM_BASE_H 40 41 #include <stdint.h> 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /** 48 * Define the result of the function execution. 49 * 50 * @since 10 51 */ 52 typedef enum { 53 /** 54 * The call was successful. 55 * 56 * @since 10 57 */ 58 AUDIOSTREAM_SUCCESS = 0, 59 60 /** 61 * This means that the function was executed with an invalid input parameter. 62 * 63 * @since 10 64 */ 65 AUDIOSTREAM_ERROR_INVALID_PARAM = 1, 66 67 /** 68 * Execution status exception. 69 * 70 * @since 10 71 */ 72 AUDIOSTREAM_ERROR_ILLEGAL_STATE = 2, 73 74 /** 75 * An system error has occurred. 76 * 77 * @since 10 78 */ 79 AUDIOSTREAM_ERROR_SYSTEM = 3 80 } OH_AudioStream_Result; 81 82 /** 83 * Define the audio stream type. 84 * 85 * @since 10 86 */ 87 typedef enum { 88 /** 89 * The type for audio stream is renderer. 90 * 91 * @since 10 92 */ 93 AUDIOSTREAM_TYPE_RENDERER = 1, 94 95 /** 96 * The type for audio stream is capturer. 97 * 98 * @since 10 99 */ 100 AUDIOSTREAM_TYPE_CAPTURER = 2 101 } OH_AudioStream_Type; 102 103 /** 104 * Define the audio stream sample format. 105 * 106 * @since 10 107 */ 108 typedef enum { 109 /** 110 * Unsigned 8 format. 111 * 112 * @since 10 113 */ 114 AUDIOSTREAM_SAMPLE_U8 = 0, 115 /** 116 * Signed 16 bit integer, little endian. 117 * 118 * @since 10 119 */ 120 AUDIOSTREAM_SAMPLE_S16LE = 1, 121 /** 122 * Signed 24 bit integer, little endian. 123 * 124 * @since 10 125 */ 126 AUDIOSTREAM_SAMPLE_S24LE = 2, 127 /** 128 * Signed 32 bit integer, little endian. 129 * 130 * @since 10 131 */ 132 AUDIOSTREAM_SAMPLE_S32LE = 3, 133 } OH_AudioStream_SampleFormat; 134 135 /** 136 * Define the audio encoding type. 137 * 138 * @since 10 139 */ 140 typedef enum { 141 /** 142 * PCM encoding type. 143 * 144 * @since 10 145 */ 146 AUDIOSTREAM_ENCODING_TYPE_RAW = 0, 147 } OH_AudioStream_EncodingType; 148 149 /** 150 * Define the audio stream usage. 151 * Audio stream usage is used to describe what work scenario 152 * the current stream is used for. 153 * 154 * @since 10 155 */ 156 typedef enum { 157 /** 158 * Unknown usage. 159 * 160 * @since 10 161 */ 162 AUDIOSTREAM_USAGE_UNKNOWN = 0, 163 /** 164 * Music usage. 165 * 166 * @since 10 167 */ 168 AUDIOSTREAM_USAGE_MUSIC = 1, 169 /** 170 * Voice communication usage. 171 * 172 * @since 10 173 */ 174 AUDIOSTREAM_USAGE_VOICE_COMMUNICATION = 2, 175 /** 176 * Voice assistant usage. 177 * 178 * @since 10 179 */ 180 AUDIOSTREAM_USAGE_VOICE_ASSISTANT = 3, 181 /** 182 * Alarm usage. 183 * 184 * @since 10 185 */ 186 AUDIOSTREAM_USAGE_ALARM = 4, 187 /** 188 * Voice message usage. 189 * 190 * @since 10 191 */ 192 AUDIOSTREAM_USAGE_VOICE_MESSAGE = 5, 193 /** 194 * Ringtone usage. 195 * 196 * @since 10 197 */ 198 AUDIOSTREAM_USAGE_RINGTONE = 6, 199 /** 200 * Notification usage. 201 * 202 * @since 10 203 */ 204 AUDIOSTREAM_USAGE_NOTIFICATION = 7, 205 /** 206 * Accessibility usage, such as screen reader. 207 * 208 * @since 10 209 */ 210 AUDIOSTREAM_USAGE_ACCESSIBILITY = 8, 211 /** 212 * Movie or video usage. 213 * 214 * @since 10 215 */ 216 AUDIOSTREAM_USAGE_MOVIE = 10, 217 /** 218 * Game sound effect usage. 219 * 220 * @since 10 221 */ 222 AUDIOSTREAM_USAGE_GAME = 11, 223 /** 224 * Audiobook usage. 225 * 226 * @since 10 227 */ 228 AUDIOSTREAM_USAGE_AUDIOBOOK = 12, 229 /** 230 * Navigation usage. 231 * 232 * @since 10 233 */ 234 AUDIOSTREAM_USAGE_NAVIGATION = 13, 235 } OH_AudioStream_Usage; 236 237 /** 238 * Define the audio latency mode. 239 * 240 * @since 10 241 */ 242 typedef enum { 243 /** 244 * This is a normal audio scene. 245 * 246 * @since 10 247 */ 248 AUDIOSTREAM_LATENCY_MODE_NORMAL = 0, 249 /** 250 * This is a low latency audio scene. 251 * 252 * @since 10 253 */ 254 AUDIOSTREAM_LATENCY_MODE_FAST = 1 255 } OH_AudioStream_LatencyMode; 256 257 /** 258 * Define the audio event. 259 * 260 * @since 10 261 */ 262 typedef enum { 263 /** 264 * The routing of the audio has changed. 265 * 266 * @since 10 267 */ 268 AUDIOSTREAM_EVENT_ROUTING_CHANGED = 0 269 } OH_AudioStream_Event; 270 271 /** 272 * The audio stream states 273 * 274 * @since 10 275 */ 276 typedef enum { 277 /** 278 * The invalid state. 279 * 280 * @since 10 281 */ 282 AUDIOSTREAM_STATE_INVALID = -1, 283 /** 284 * Create new instance state. 285 * 286 * @since 10 287 */ 288 AUDIOSTREAM_STATE_NEW = 0, 289 /** 290 * The prepared state. 291 * 292 * @since 10 293 */ 294 AUDIOSTREAM_STATE_PREPARED = 1, 295 /** 296 * The stream is running. 297 * 298 * @since 10 299 */ 300 AUDIOSTREAM_STATE_RUNNING = 2, 301 /** 302 * The stream is stopped. 303 * 304 * @since 10 305 */ 306 AUDIOSTREAM_STATE_STOPPED = 3, 307 /** 308 * The stream is released. 309 * 310 * @since 10 311 */ 312 AUDIOSTREAM_STATE_RELEASED = 4, 313 /** 314 * The stream is paused. 315 * 316 * @since 10 317 */ 318 AUDIOSTREAM_STATE_PAUSED = 5, 319 } OH_AudioStream_State; 320 321 /** 322 * Defines the audio interrupt type. 323 * 324 * @since 10 325 */ 326 typedef enum { 327 /** 328 * Force type, system change audio state. 329 * 330 * @since 10 331 */ 332 AUDIOSTREAM_INTERRUPT_FORCE = 0, 333 /** 334 * Share type, application change audio state. 335 * 336 * @since 10 337 */ 338 AUDIOSTREAM_INTERRUPT_SHARE = 1 339 } OH_AudioInterrupt_ForceType; 340 341 /** 342 * Defines the audio interrupt hint type. 343 * 344 * @since 10 345 */ 346 typedef enum { 347 /** 348 * None. 349 * 350 * @since 10 351 */ 352 AUDIOSTREAM_INTERRUPT_HINT_NONE = 0, 353 /** 354 * Resume the stream. 355 * 356 * @since 10 357 */ 358 AUDIOSTREAM_INTERRUPT_HINT_RESUME = 1, 359 /** 360 * Pause the stream. 361 * 362 * @since 10 363 */ 364 AUDIOSTREAM_INTERRUPT_HINT_PAUSE = 2, 365 /** 366 * Stop the stream. 367 * 368 * @since 10 369 */ 370 AUDIOSTREAM_INTERRUPT_HINT_STOP = 3, 371 /** 372 * Ducked the stream. 373 * 374 * @since 10 375 */ 376 AUDIOSTREAM_INTERRUPT_HINT_DUCK = 4, 377 /** 378 * Unducked the stream. 379 * 380 * @since 10 381 */ 382 AUDIOSTREAM_INTERRUPT_HINT_UNDUCK = 5 383 } OH_AudioInterrupt_Hint; 384 385 /** 386 * Defines the audio source type. 387 * 388 * @since 10 389 */ 390 typedef enum { 391 /** 392 * Invalid type. 393 * 394 * @since 10 395 */ 396 AUDIOSTREAM_SOURCE_TYPE_INVALID = -1, 397 /** 398 * Mic source type. 399 * 400 * @since 10 401 */ 402 AUDIOSTREAM_SOURCE_TYPE_MIC = 0, 403 /** 404 * Voice recognition source type. 405 * 406 * @since 10 407 */ 408 AUDIOSTREAM_SOURCE_TYPE_VOICE_RECOGNITION = 1, 409 /** 410 * Playback capture source type. 411 * 412 * @since 10 413 */ 414 AUDIOSTREAM_SOURCE_TYPE_PLAYBACK_CAPTURE = 2, 415 /** 416 * Voice communication source type. 417 * 418 * @since 10 419 */ 420 AUDIOSTREAM_SOURCE_TYPE_VOICE_COMMUNICATION = 7 421 } OH_AudioStream_SourceType; 422 423 /** 424 * Declaring the audio stream builder. 425 * The instance of builder is used for creating audio stream. 426 * 427 * @since 10 428 */ 429 typedef struct OH_AudioStreamBuilderStruct OH_AudioStreamBuilder; 430 431 /** 432 * Declaring the audio renderer stream. 433 * The instance of renderer stream is used for playing audio data. 434 * 435 * @since 10 436 */ 437 typedef struct OH_AudioRendererStruct OH_AudioRenderer; 438 439 /** 440 * Declaring the audio capturer stream. 441 * The instance of renderer stream is used for capturing audio data. 442 * 443 * @since 10 444 */ 445 typedef struct OH_AudioCapturerStruct OH_AudioCapturer; 446 447 /** 448 * Declaring the callback struct for renderer stream. 449 * 450 * @since 10 451 */ 452 typedef struct OH_AudioRenderer_Callbacks_Struct { 453 /** 454 * This function pointer will point to the callback function that 455 * is used to write audio data 456 * 457 * @since 10 458 */ 459 int32_t (*OH_AudioRenderer_OnWriteData)( 460 OH_AudioRenderer* renderer, 461 void* userData, 462 void* buffer, 463 int32_t lenth); 464 465 /** 466 * This function pointer will point to the callback function that 467 * is used to handle audio renderer stream events. 468 * 469 * @since 10 470 */ 471 int32_t (*OH_AudioRenderer_OnStreamEvent)( 472 OH_AudioRenderer* renderer, 473 void* userData, 474 OH_AudioStream_Event event); 475 476 /** 477 * This function pointer will point to the callback function that 478 * is used to handle audio interrupt events. 479 * 480 * @since 10 481 */ 482 int32_t (*OH_AudioRenderer_OnInterruptEvent)( 483 OH_AudioRenderer* renderer, 484 void* userData, 485 OH_AudioInterrupt_ForceType type, 486 OH_AudioInterrupt_Hint hint); 487 488 /** 489 * This function pointer will point to the callback function that 490 * is used to handle audio error result. 491 * 492 * @since 10 493 */ 494 int32_t (*OH_AudioRenderer_OnError)( 495 OH_AudioRenderer* renderer, 496 void* userData, 497 OH_AudioStream_Result error); 498 } OH_AudioRenderer_Callbacks; 499 500 /** 501 * Declaring the callback struct for capturer stream. 502 * 503 * @since 10 504 */ 505 typedef struct OH_AudioCapturer_Callbacks_Struct { 506 /** 507 * This function pointer will point to the callback function that 508 * is used to read audio data. 509 * 510 * @since 10 511 */ 512 int32_t (*OH_AudioCapturer_OnReadData)( 513 OH_AudioCapturer* capturer, 514 void* userData, 515 void* buffer, 516 int32_t lenth); 517 518 /** 519 * This function pointer will point to the callback function that 520 * is used to handle audio capturer stream events. 521 * 522 * @since 10 523 */ 524 int32_t (*OH_AudioCapturer_OnStreamEvent)( 525 OH_AudioCapturer* capturer, 526 void* userData, 527 OH_AudioStream_Event event); 528 529 /** 530 * This function pointer will point to the callback function that 531 * is used to handle audio interrupt events. 532 * 533 * @since 10 534 */ 535 int32_t (*OH_AudioCapturer_OnInterruptEvent)( 536 OH_AudioCapturer* capturer, 537 void* userData, 538 OH_AudioInterrupt_ForceType type, 539 OH_AudioInterrupt_Hint hint); 540 541 /** 542 * This function pointer will point to the callback function that 543 * is used to handle audio error result. 544 * 545 * @since 10 546 */ 547 int32_t (*OH_AudioCapturer_OnError)( 548 OH_AudioCapturer* capturer, 549 void* userData, 550 OH_AudioStream_Result error); 551 } OH_AudioCapturer_Callbacks; 552 553 /** 554 * @brief Defines reason for device changes of one audio stream. 555 * 556 * @since 11 557 */ 558 typedef enum { 559 /* Unknown. */ 560 REASON_UNKNOWN = 0, 561 /* New Device available. */ 562 REASON_NEW_DEVICE_AVAILABLE = 1, 563 /* Old Device unavailable. Applications should consider to pause the audio playback when this reason is 564 reported. */ 565 REASON_OLD_DEVICE_UNAVAILABLE = 2, 566 /* Device is overrode by user or system. */ 567 REASON_OVERRODE = 3, 568 } OH_AudioStream_DeviceChangeReason; 569 570 /** 571 * @brief Callback when the output device of an audio renderer changed. 572 * 573 * @param renderer AudioRenderer where this event occurs. 574 * @param userData User data which is passed by user. 575 * @param reason Indicates that why does the output device changes. 576 * @since 11 577 */ 578 typedef void (*OH_AudioRenderer_OutputDeviceChangeCallback)(OH_AudioRenderer* renderer, void* userData, 579 OH_AudioStream_DeviceChangeReason reason); 580 #ifdef __cplusplus 581 } 582 #endif 583 584 #endif // NATIVE_AUDIOSTREAM_BASE_H 585