1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef OBOE_DEFINITIONS_H 18 #define OBOE_DEFINITIONS_H 19 20 #include <cstdint> 21 #include <type_traits> 22 23 // Oboe needs to be able to build on old NDKs so we use hard coded constants. 24 // The correctness of these constants is verified in "aaudio/AAudioLoader.cpp". 25 26 namespace oboe { 27 28 /** 29 * Represents any attribute, property or value which hasn't been specified. 30 */ 31 constexpr int32_t kUnspecified = 0; 32 33 // TODO: Investigate using std::chrono 34 /** 35 * The number of nanoseconds in a microsecond. 1,000. 36 */ 37 constexpr int64_t kNanosPerMicrosecond = 1000; 38 39 /** 40 * The number of nanoseconds in a millisecond. 1,000,000. 41 */ 42 constexpr int64_t kNanosPerMillisecond = kNanosPerMicrosecond * 1000; 43 44 /** 45 * The number of milliseconds in a second. 1,000. 46 */ 47 constexpr int64_t kMillisPerSecond = 1000; 48 49 /** 50 * The number of nanoseconds in a second. 1,000,000,000. 51 */ 52 constexpr int64_t kNanosPerSecond = kNanosPerMillisecond * kMillisPerSecond; 53 54 /** 55 * The state of the audio stream. 56 */ 57 enum class StreamState : int32_t { // aaudio_stream_state_t 58 Uninitialized = 0, // AAUDIO_STREAM_STATE_UNINITIALIZED, 59 Unknown = 1, // AAUDIO_STREAM_STATE_UNKNOWN, 60 Open = 2, // AAUDIO_STREAM_STATE_OPEN, 61 Starting = 3, // AAUDIO_STREAM_STATE_STARTING, 62 Started = 4, // AAUDIO_STREAM_STATE_STARTED, 63 Pausing = 5, // AAUDIO_STREAM_STATE_PAUSING, 64 Paused = 6, // AAUDIO_STREAM_STATE_PAUSED, 65 Flushing = 7, // AAUDIO_STREAM_STATE_FLUSHING, 66 Flushed = 8, // AAUDIO_STREAM_STATE_FLUSHED, 67 Stopping = 9, // AAUDIO_STREAM_STATE_STOPPING, 68 Stopped = 10, // AAUDIO_STREAM_STATE_STOPPED, 69 Closing = 11, // AAUDIO_STREAM_STATE_CLOSING, 70 Closed = 12, // AAUDIO_STREAM_STATE_CLOSED, 71 Disconnected = 13, // AAUDIO_STREAM_STATE_DISCONNECTED, 72 }; 73 74 /** 75 * The direction of the stream. 76 */ 77 enum class Direction : int32_t { // aaudio_direction_t 78 79 /** 80 * Used for playback. 81 */ 82 Output = 0, // AAUDIO_DIRECTION_OUTPUT, 83 84 /** 85 * Used for recording. 86 */ 87 Input = 1, // AAUDIO_DIRECTION_INPUT, 88 }; 89 90 /** 91 * The format of audio samples. 92 */ 93 enum class AudioFormat : int32_t { // aaudio_format_t 94 /** 95 * Invalid format. 96 */ 97 Invalid = -1, // AAUDIO_FORMAT_INVALID, 98 99 /** 100 * Unspecified format. Format will be decided by Oboe. 101 * When calling getHardwareFormat(), this will be returned if 102 * the API is not supported. 103 */ 104 Unspecified = 0, // AAUDIO_FORMAT_UNSPECIFIED, 105 106 /** 107 * Signed 16-bit integers. 108 */ 109 I16 = 1, // AAUDIO_FORMAT_PCM_I16, 110 111 /** 112 * Single precision floating point. 113 * 114 * This is the recommended format for most applications. 115 * But note that the use of Float may prevent the opening of 116 * a low-latency input path on OpenSL ES or Legacy AAudio streams. 117 */ 118 Float = 2, // AAUDIO_FORMAT_PCM_FLOAT, 119 120 /** 121 * Signed 24-bit integers, packed into 3 bytes. 122 * 123 * Note that the use of this format does not guarantee that 124 * the full precision will be provided. The underlying device may 125 * be using I16 format. 126 * 127 * Added in API 31 (S). 128 */ 129 I24 = 3, // AAUDIO_FORMAT_PCM_I24_PACKED 130 131 /** 132 * Signed 32-bit integers. 133 * 134 * Note that the use of this format does not guarantee that 135 * the full precision will be provided. The underlying device may 136 * be using I16 format. 137 * 138 * Added in API 31 (S). 139 */ 140 I32 = 4, // AAUDIO_FORMAT_PCM_I32 141 142 /** 143 * This format is used for compressed audio wrapped in IEC61937 for HDMI 144 * or S/PDIF passthrough. 145 * 146 * Unlike PCM playback, the Android framework is not able to do format 147 * conversion for IEC61937. In that case, when IEC61937 is requested, sampling 148 * rate and channel count or channel mask must be specified. Otherwise, it may 149 * fail when opening the stream. Apps are able to get the correct configuration 150 * for the playback by calling AudioManager#getDevices(int). 151 * 152 * Available since API 34 (U). 153 */ 154 IEC61937 = 5, // AAUDIO_FORMAT_IEC61937 155 }; 156 157 /** 158 * The result of an audio callback. 159 */ 160 enum class DataCallbackResult : int32_t { // aaudio_data_callback_result_t 161 // Indicates to the caller that the callbacks should continue. 162 Continue = 0, // AAUDIO_CALLBACK_RESULT_CONTINUE, 163 164 // Indicates to the caller that the callbacks should stop immediately. 165 Stop = 1, // AAUDIO_CALLBACK_RESULT_STOP, 166 }; 167 168 /** 169 * The result of an operation. All except the `OK` result indicates that an error occurred. 170 * The `Result` can be converted into a human readable string using `convertToText`. 171 */ 172 enum class Result : int32_t { // aaudio_result_t 173 OK = 0, // AAUDIO_OK 174 ErrorBase = -900, // AAUDIO_ERROR_BASE, 175 ErrorDisconnected = -899, // AAUDIO_ERROR_DISCONNECTED, 176 ErrorIllegalArgument = -898, // AAUDIO_ERROR_ILLEGAL_ARGUMENT, 177 ErrorInternal = -896, // AAUDIO_ERROR_INTERNAL, 178 ErrorInvalidState = -895, // AAUDIO_ERROR_INVALID_STATE, 179 ErrorInvalidHandle = -892, // AAUDIO_ERROR_INVALID_HANDLE, 180 ErrorUnimplemented = -890, // AAUDIO_ERROR_UNIMPLEMENTED, 181 ErrorUnavailable = -889, // AAUDIO_ERROR_UNAVAILABLE, 182 ErrorNoFreeHandles = -888, // AAUDIO_ERROR_NO_FREE_HANDLES, 183 ErrorNoMemory = -887, // AAUDIO_ERROR_NO_MEMORY, 184 ErrorNull = -886, // AAUDIO_ERROR_NULL, 185 ErrorTimeout = -885, // AAUDIO_ERROR_TIMEOUT, 186 ErrorWouldBlock = -884, // AAUDIO_ERROR_WOULD_BLOCK, 187 ErrorInvalidFormat = -883, // AAUDIO_ERROR_INVALID_FORMAT, 188 ErrorOutOfRange = -882, // AAUDIO_ERROR_OUT_OF_RANGE, 189 ErrorNoService = -881, // AAUDIO_ERROR_NO_SERVICE, 190 ErrorInvalidRate = -880, // AAUDIO_ERROR_INVALID_RATE, 191 // Reserved for future AAudio result types 192 Reserved1, 193 Reserved2, 194 Reserved3, 195 Reserved4, 196 Reserved5, 197 Reserved6, 198 Reserved7, 199 Reserved8, 200 Reserved9, 201 Reserved10, 202 ErrorClosed = -869, 203 }; 204 205 /** 206 * The sharing mode of the audio stream. 207 */ 208 enum class SharingMode : int32_t { // aaudio_sharing_mode_t 209 210 /** 211 * This will be the only stream using a particular source or sink. 212 * This mode will provide the lowest possible latency. 213 * You should close EXCLUSIVE streams immediately when you are not using them. 214 * 215 * If you do not need the lowest possible latency then we recommend using Shared, 216 * which is the default. 217 */ 218 Exclusive = 0, // AAUDIO_SHARING_MODE_EXCLUSIVE, 219 220 /** 221 * Multiple applications can share the same device. 222 * The data from output streams will be mixed by the audio service. 223 * The data for input streams will be distributed by the audio service. 224 * 225 * This will have higher latency than the EXCLUSIVE mode. 226 */ 227 Shared = 1, // AAUDIO_SHARING_MODE_SHARED, 228 }; 229 230 /** 231 * The performance mode of the audio stream. 232 */ 233 enum class PerformanceMode : int32_t { // aaudio_performance_mode_t 234 235 /** 236 * No particular performance needs. Default. 237 */ 238 None = 10, // AAUDIO_PERFORMANCE_MODE_NONE, 239 240 /** 241 * Extending battery life is most important. 242 */ 243 PowerSaving = 11, // AAUDIO_PERFORMANCE_MODE_POWER_SAVING, 244 245 /** 246 * Reducing latency is most important. 247 */ 248 LowLatency = 12, // AAUDIO_PERFORMANCE_MODE_LOW_LATENCY 249 }; 250 251 /** 252 * The underlying audio API used by the audio stream. 253 */ 254 enum class AudioApi : int32_t { 255 /** 256 * Try to use AAudio. If not available then use OpenSL ES. 257 */ 258 Unspecified = kUnspecified, 259 260 /** 261 * Use OpenSL ES. 262 * Note that OpenSL ES is deprecated in Android 13, API 30 and above. 263 */ 264 OpenSLES, 265 266 /** 267 * Try to use AAudio. Fail if unavailable. 268 * AAudio was first supported in Android 8, API 26 and above. 269 * It is only recommended for API 27 and above. 270 */ 271 AAudio 272 }; 273 274 /** 275 * Specifies the quality of the sample rate conversion performed by Oboe. 276 * Higher quality will require more CPU load. 277 * Higher quality conversion will probably be implemented using a sinc based resampler. 278 */ 279 enum class SampleRateConversionQuality : int32_t { 280 /** 281 * No conversion by Oboe. Underlying APIs may still do conversion. 282 */ 283 None, 284 /** 285 * Fastest conversion but may not sound great. 286 * This may be implemented using bilinear interpolation. 287 */ 288 Fastest, 289 /** 290 * Low quality conversion with 8 taps. 291 */ 292 Low, 293 /** 294 * Medium quality conversion with 16 taps. 295 */ 296 Medium, 297 /** 298 * High quality conversion with 32 taps. 299 */ 300 High, 301 /** 302 * Highest quality conversion, which may be expensive in terms of CPU. 303 */ 304 Best, 305 }; 306 307 /** 308 * The Usage attribute expresses *why* you are playing a sound, what is this sound used for. 309 * This information is used by certain platforms or routing policies 310 * to make more refined volume or routing decisions. 311 * 312 * Note that these match the equivalent values in AudioAttributes in the Android Java API. 313 * 314 * This attribute only has an effect on Android API 28+. 315 */ 316 enum class Usage : int32_t { // aaudio_usage_t 317 /** 318 * Use this for streaming media, music performance, video, podcasts, etcetera. 319 */ 320 Media = 1, // AAUDIO_USAGE_MEDIA 321 322 /** 323 * Use this for voice over IP, telephony, etcetera. 324 */ 325 VoiceCommunication = 2, // AAUDIO_USAGE_VOICE_COMMUNICATION 326 327 /** 328 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera. 329 */ 330 VoiceCommunicationSignalling = 3, // AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING 331 332 /** 333 * Use this to demand the users attention. 334 */ 335 Alarm = 4, // AAUDIO_USAGE_ALARM 336 337 /** 338 * Use this for notifying the user when a message has arrived or some 339 * other background event has occured. 340 */ 341 Notification = 5, // AAUDIO_USAGE_NOTIFICATION 342 343 /** 344 * Use this when the phone rings. 345 */ 346 NotificationRingtone = 6, // AAUDIO_USAGE_NOTIFICATION_RINGTONE 347 348 /** 349 * Use this to attract the users attention when, for example, the battery is low. 350 */ 351 NotificationEvent = 10, // AAUDIO_USAGE_NOTIFICATION_EVENT 352 353 /** 354 * Use this for screen readers, etcetera. 355 */ 356 AssistanceAccessibility = 11, // AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY 357 358 /** 359 * Use this for driving or navigation directions. 360 */ 361 AssistanceNavigationGuidance = 12, // AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE 362 363 /** 364 * Use this for user interface sounds, beeps, etcetera. 365 */ 366 AssistanceSonification = 13, // AAUDIO_USAGE_ASSISTANCE_SONIFICATION 367 368 /** 369 * Use this for game audio and sound effects. 370 */ 371 Game = 14, // AAUDIO_USAGE_GAME 372 373 /** 374 * Use this for audio responses to user queries, audio instructions or help utterances. 375 */ 376 Assistant = 16, // AAUDIO_USAGE_ASSISTANT 377 }; 378 379 380 /** 381 * The ContentType attribute describes *what* you are playing. 382 * It expresses the general category of the content. This information is optional. 383 * But in case it is known (for instance {@link Movie} for a 384 * movie streaming service or {@link Speech} for 385 * an audio book application) this information might be used by the audio framework to 386 * enforce audio focus. 387 * 388 * Note that these match the equivalent values in AudioAttributes in the Android Java API. 389 * 390 * This attribute only has an effect on Android API 28+. 391 */ 392 enum ContentType : int32_t { // aaudio_content_type_t 393 394 /** 395 * Use this for spoken voice, audio books, etcetera. 396 */ 397 Speech = 1, // AAUDIO_CONTENT_TYPE_SPEECH 398 399 /** 400 * Use this for pre-recorded or live music. 401 */ 402 Music = 2, // AAUDIO_CONTENT_TYPE_MUSIC 403 404 /** 405 * Use this for a movie or video soundtrack. 406 */ 407 Movie = 3, // AAUDIO_CONTENT_TYPE_MOVIE 408 409 /** 410 * Use this for sound is designed to accompany a user action, 411 * such as a click or beep sound made when the user presses a button. 412 */ 413 Sonification = 4, // AAUDIO_CONTENT_TYPE_SONIFICATION 414 }; 415 416 /** 417 * Defines the audio source. 418 * An audio source defines both a default physical source of audio signal, and a recording 419 * configuration. 420 * 421 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API. 422 * 423 * This attribute only has an effect on Android API 28+. 424 */ 425 enum InputPreset : int32_t { // aaudio_input_preset_t 426 /** 427 * Use this preset when other presets do not apply. 428 */ 429 Generic = 1, // AAUDIO_INPUT_PRESET_GENERIC 430 431 /** 432 * Use this preset when recording video. 433 */ 434 Camcorder = 5, // AAUDIO_INPUT_PRESET_CAMCORDER 435 436 /** 437 * Use this preset when doing speech recognition. 438 */ 439 VoiceRecognition = 6, // AAUDIO_INPUT_PRESET_VOICE_RECOGNITION 440 441 /** 442 * Use this preset when doing telephony or voice messaging. 443 */ 444 VoiceCommunication = 7, // AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION 445 446 /** 447 * Use this preset to obtain an input with no effects. 448 * Note that this input will not have automatic gain control 449 * so the recorded volume may be very low. 450 */ 451 Unprocessed = 9, // AAUDIO_INPUT_PRESET_UNPROCESSED 452 453 /** 454 * Use this preset for capturing audio meant to be processed in real time 455 * and played back for live performance (e.g karaoke). 456 * The capture path will minimize latency and coupling with playback path. 457 */ 458 VoicePerformance = 10, // AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE 459 460 }; 461 462 /** 463 * This attribute can be used to allocate a session ID to the audio stream. 464 * 465 * This attribute only has an effect on Android API 28+. 466 */ 467 enum SessionId { 468 /** 469 * Do not allocate a session ID. 470 * Effects cannot be used with this stream. 471 * Default. 472 */ 473 None = -1, // AAUDIO_SESSION_ID_NONE 474 475 /** 476 * Allocate a session ID that can be used to attach and control 477 * effects using the Java AudioEffects API. 478 * Note that the use of this flag may result in higher latency. 479 * 480 * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE. 481 */ 482 Allocate = 0, // AAUDIO_SESSION_ID_ALLOCATE 483 }; 484 485 /** 486 * The channel count of the audio stream. The underlying type is `int32_t`. 487 * Use of this enum is convenient to avoid "magic" 488 * numbers when specifying the channel count. 489 * 490 * For example, you can write 491 * `builder.setChannelCount(ChannelCount::Stereo)` 492 * rather than `builder.setChannelCount(2)` 493 * 494 */ 495 enum ChannelCount : int32_t { 496 /** 497 * Audio channel count definition, use Mono or Stereo 498 */ 499 Unspecified = kUnspecified, 500 501 /** 502 * Use this for mono audio 503 */ 504 Mono = 1, 505 506 /** 507 * Use this for stereo audio. 508 */ 509 Stereo = 2, 510 }; 511 512 /** 513 * The channel mask of the audio stream. The underlying type is `uint32_t`. 514 * Use of this enum is convenient. 515 * 516 * ChannelMask::Unspecified means this is not specified. 517 * The rest of the enums are channel position masks. 518 * Use the combinations of the channel position masks defined below instead of 519 * using those values directly. 520 * 521 * Channel masks are for input only, output only, or both input and output. 522 * These channel masks are different than those defined in AudioFormat.java. 523 * If an app gets a channel mask from Java API and wants to use it in Oboe, 524 * conversion should be done by the app. 525 */ 526 enum class ChannelMask : uint32_t { // aaudio_channel_mask_t 527 Unspecified = kUnspecified, 528 FrontLeft = 1 << 0, 529 FrontRight = 1 << 1, 530 FrontCenter = 1 << 2, 531 LowFrequency = 1 << 3, 532 BackLeft = 1 << 4, 533 BackRight = 1 << 5, 534 FrontLeftOfCenter = 1 << 6, 535 FrontRightOfCenter = 1 << 7, 536 BackCenter = 1 << 8, 537 SideLeft = 1 << 9, 538 SideRight = 1 << 10, 539 TopCenter = 1 << 11, 540 TopFrontLeft = 1 << 12, 541 TopFrontCenter = 1 << 13, 542 TopFrontRight = 1 << 14, 543 TopBackLeft = 1 << 15, 544 TopBackCenter = 1 << 16, 545 TopBackRight = 1 << 17, 546 TopSideLeft = 1 << 18, 547 TopSideRight = 1 << 19, 548 BottomFrontLeft = 1 << 20, 549 BottomFrontCenter = 1 << 21, 550 BottomFrontRight = 1 << 22, 551 LowFrequency2 = 1 << 23, 552 FrontWideLeft = 1 << 24, 553 FrontWideRight = 1 << 25, 554 555 /** 556 * Supported for Input and Output 557 */ 558 Mono = FrontLeft, 559 560 /** 561 * Supported for Input and Output 562 */ 563 Stereo = FrontLeft | 564 FrontRight, 565 566 /** 567 * Supported for only Output 568 */ 569 CM2Point1 = FrontLeft | 570 FrontRight | 571 LowFrequency, 572 573 /** 574 * Supported for only Output 575 */ 576 Tri = FrontLeft | 577 FrontRight | 578 FrontCenter, 579 580 /** 581 * Supported for only Output 582 */ 583 TriBack = FrontLeft | 584 FrontRight | 585 BackCenter, 586 587 /** 588 * Supported for only Output 589 */ 590 CM3Point1 = FrontLeft | 591 FrontRight | 592 FrontCenter | 593 LowFrequency, 594 595 /** 596 * Supported for Input and Output 597 */ 598 CM2Point0Point2 = FrontLeft | 599 FrontRight | 600 TopSideLeft | 601 TopSideRight, 602 603 /** 604 * Supported for Input and Output 605 */ 606 CM2Point1Point2 = CM2Point0Point2 | 607 LowFrequency, 608 609 /** 610 * Supported for Input and Output 611 */ 612 CM3Point0Point2 = FrontLeft | 613 FrontRight | 614 FrontCenter | 615 TopSideLeft | 616 TopSideRight, 617 618 /** 619 * Supported for Input and Output 620 */ 621 CM3Point1Point2 = CM3Point0Point2 | 622 LowFrequency, 623 624 /** 625 * Supported for only Output 626 */ 627 Quad = FrontLeft | 628 FrontRight | 629 BackLeft | 630 BackRight, 631 632 /** 633 * Supported for only Output 634 */ 635 QuadSide = FrontLeft | 636 FrontRight | 637 SideLeft | 638 SideRight, 639 640 /** 641 * Supported for only Output 642 */ 643 Surround = FrontLeft | 644 FrontRight | 645 FrontCenter | 646 BackCenter, 647 648 /** 649 * Supported for only Output 650 */ 651 Penta = Quad | 652 FrontCenter, 653 654 /** 655 * Supported for Input and Output. aka 5Point1Back 656 */ 657 CM5Point1 = FrontLeft | 658 FrontRight | 659 FrontCenter | 660 LowFrequency | 661 BackLeft | 662 BackRight, 663 664 /** 665 * Supported for only Output 666 */ 667 CM5Point1Side = FrontLeft | 668 FrontRight | 669 FrontCenter | 670 LowFrequency | 671 SideLeft | 672 SideRight, 673 674 /** 675 * Supported for only Output 676 */ 677 CM6Point1 = FrontLeft | 678 FrontRight | 679 FrontCenter | 680 LowFrequency | 681 BackLeft | 682 BackRight | 683 BackCenter, 684 685 /** 686 * Supported for only Output 687 */ 688 CM7Point1 = CM5Point1 | 689 SideLeft | 690 SideRight, 691 692 /** 693 * Supported for only Output 694 */ 695 CM5Point1Point2 = CM5Point1 | 696 TopSideLeft | 697 TopSideRight, 698 699 /** 700 * Supported for only Output 701 */ 702 CM5Point1Point4 = CM5Point1 | 703 TopFrontLeft | 704 TopFrontRight | 705 TopBackLeft | 706 TopBackRight, 707 708 /** 709 * Supported for only Output 710 */ 711 CM7Point1Point2 = CM7Point1 | 712 TopSideLeft | 713 TopSideRight, 714 715 /** 716 * Supported for only Output 717 */ 718 CM7Point1Point4 = CM7Point1 | 719 TopFrontLeft | 720 TopFrontRight | 721 TopBackLeft | 722 TopBackRight, 723 724 /** 725 * Supported for only Output 726 */ 727 CM9Point1Point4 = CM7Point1Point4 | 728 FrontWideLeft | 729 FrontWideRight, 730 731 /** 732 * Supported for only Output 733 */ 734 CM9Point1Point6 = CM9Point1Point4 | 735 TopSideLeft | 736 TopSideRight, 737 738 /** 739 * Supported for only Input 740 */ 741 FrontBack = FrontCenter | 742 BackCenter, 743 }; 744 745 /** 746 * The spatialization behavior of the audio stream. 747 */ 748 enum class SpatializationBehavior : int32_t { 749 750 /** 751 * Constant indicating that the spatialization behavior is not specified. 752 */ 753 Unspecified = kUnspecified, 754 755 /** 756 * Constant indicating the audio content associated with these attributes will follow the 757 * default platform behavior with regards to which content will be spatialized or not. 758 */ 759 Auto = 1, 760 761 /** 762 * Constant indicating the audio content associated with these attributes should never 763 * be spatialized. 764 */ 765 Never = 2, 766 }; 767 768 /** 769 * The PrivacySensitiveMode attribute determines whether an input stream can be shared 770 * with another privileged app, for example the Assistant. 771 * 772 * This allows to override the default behavior tied to the audio source (e.g 773 * InputPreset::VoiceCommunication is private by default but InputPreset::Unprocessed is not). 774 */ 775 enum class PrivacySensitiveMode : int32_t { 776 777 /** 778 * When not explicitly requested, set privacy sensitive mode according to input preset: 779 * communication and camcorder captures are considered privacy sensitive by default. 780 */ 781 Unspecified = kUnspecified, 782 783 /** 784 * Privacy sensitive mode disabled. 785 */ 786 Disabled = 1, 787 788 /** 789 * Privacy sensitive mode enabled. 790 */ 791 Enabled = 2, 792 }; 793 794 /** 795 * Specifies whether audio may or may not be captured by other apps or the system for an 796 * output stream. 797 * 798 * Note that these match the equivalent values in AudioAttributes in the Android Java API. 799 * 800 * Added in API level 29 for AAudio. 801 */ 802 enum class AllowedCapturePolicy : int32_t { 803 /** 804 * When not explicitly requested, set privacy sensitive mode according to the Usage. 805 * This should behave similarly to setting AllowedCapturePolicy::All. 806 */ 807 Unspecified = kUnspecified, 808 /** 809 * Indicates that the audio may be captured by any app. 810 * 811 * For privacy, the following Usages can not be recorded: VoiceCommunication*, 812 * Notification*, Assistance* and Assistant. 813 * 814 * On Android Q, only Usage::Game and Usage::Media may be captured. 815 * 816 * See ALLOW_CAPTURE_BY_ALL in the AudioAttributes Java API. 817 */ 818 All = 1, 819 /** 820 * Indicates that the audio may only be captured by system apps. 821 * 822 * System apps can capture for many purposes like accessibility, user guidance... 823 * but have strong restriction. See ALLOW_CAPTURE_BY_SYSTEM in the AudioAttributes Java API 824 * for what the system apps can do with the capture audio. 825 */ 826 System = 2, 827 /** 828 * Indicates that the audio may not be recorded by any app, even if it is a system app. 829 * 830 * It is encouraged to use AllowedCapturePolicy::System instead of this value as system apps 831 * provide significant and useful features for the user (eg. accessibility). 832 * See ALLOW_CAPTURE_BY_NONE in the AudioAttributes Java API 833 */ 834 None = 3, 835 }; 836 837 /** 838 * On API 16 to 26 OpenSL ES will be used. When using OpenSL ES the optimal values for sampleRate and 839 * framesPerBurst are not known by the native code. 840 * On API 17+ these values should be obtained from the AudioManager using this code: 841 * 842 * <pre><code> 843 * // Note that this technique only works for built-in speakers and headphones. 844 * AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 845 * String sampleRateStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); 846 * int defaultSampleRate = Integer.parseInt(sampleRateStr); 847 * String framesPerBurstStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER); 848 * int defaultFramesPerBurst = Integer.parseInt(framesPerBurstStr); 849 * </code></pre> 850 * 851 * It can then be passed down to Oboe through JNI. 852 * 853 * AAudio will get the optimal framesPerBurst from the HAL and will ignore this value. 854 */ 855 class DefaultStreamValues { 856 857 public: 858 859 /** The default sample rate to use when opening new audio streams */ 860 static int32_t SampleRate; 861 /** The default frames per burst to use when opening new audio streams */ 862 static int32_t FramesPerBurst; 863 /** The default channel count to use when opening new audio streams */ 864 static int32_t ChannelCount; 865 866 }; 867 868 /** 869 * The time at which the frame at `position` was presented 870 */ 871 struct FrameTimestamp { 872 int64_t position; // in frames 873 int64_t timestamp; // in nanoseconds 874 }; 875 876 class OboeGlobals { 877 public: 878 areWorkaroundsEnabled()879 static bool areWorkaroundsEnabled() { 880 return mWorkaroundsEnabled; 881 } 882 883 /** 884 * Disable this when writing tests to reproduce bugs in AAudio or OpenSL ES 885 * that have workarounds in Oboe. 886 * @param enabled 887 */ setWorkaroundsEnabled(bool enabled)888 static void setWorkaroundsEnabled(bool enabled) { 889 mWorkaroundsEnabled = enabled; 890 } 891 892 private: 893 static bool mWorkaroundsEnabled; 894 }; 895 } // namespace oboe 896 897 #endif // OBOE_DEFINITIONS_H 898