xref: /aosp_15_r20/frameworks/av/media/libaaudio/include/aaudio/AAudio.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
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 /**
18  * @addtogroup Audio
19  * @{
20  */
21 
22 /**
23  * @file aaudio/AAudio.h
24  */
25 
26 /**
27  * This is the 'C' API for AAudio.
28  */
29 #ifndef AAUDIO_AAUDIO_H
30 #define AAUDIO_AAUDIO_H
31 
32 #include <stdbool.h>
33 #include <stdint.h>
34 #include <time.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /**
41  * This is used to represent a value that has not been specified.
42  * For example, an application could use {@link #AAUDIO_UNSPECIFIED} to indicate
43  * that it did not care what the specific value of a parameter was
44  * and would accept whatever it was given.
45  */
46 #define AAUDIO_UNSPECIFIED           0
47 
48 enum {
49     /**
50      * Audio data will travel out of the device, for example through a speaker.
51      */
52     AAUDIO_DIRECTION_OUTPUT,
53 
54 
55     /**
56      * Audio data will travel into the device, for example from a microphone.
57      */
58     AAUDIO_DIRECTION_INPUT
59 };
60 typedef int32_t aaudio_direction_t;
61 
62 enum {
63     AAUDIO_FORMAT_INVALID = -1,
64     AAUDIO_FORMAT_UNSPECIFIED = 0,
65 
66     /**
67      * This format uses the int16_t data type.
68      * The maximum range of the data is -32768 (0x8000) to 32767 (0x7FFF).
69      */
70     AAUDIO_FORMAT_PCM_I16,
71 
72     /**
73      * This format uses the float data type.
74      * The nominal range of the data is [-1.0f, 1.0f).
75      * Values outside that range may be clipped.
76      *
77      * See also the float Data in
78      * <a href="/reference/android/media/AudioTrack#write(float[],%20int,%20int,%20int)">
79      *   write(float[], int, int, int)</a>.
80      */
81     AAUDIO_FORMAT_PCM_FLOAT,
82 
83     /**
84      * This format uses 24-bit samples packed into 3 bytes.
85      * The bytes are in little-endian order, so the least significant byte
86      * comes first in the byte array.
87      *
88      * The maximum range of the data is -8388608 (0x800000)
89      * to 8388607 (0x7FFFFF).
90      *
91      * Note that the lower precision bits may be ignored by the device.
92      *
93      * Available since API level 31.
94      */
95     AAUDIO_FORMAT_PCM_I24_PACKED,
96 
97     /**
98      * This format uses 32-bit samples stored in an int32_t data type.
99      * The maximum range of the data is -2147483648 (0x80000000)
100      * to 2147483647 (0x7FFFFFFF).
101      *
102      * Note that the lower precision bits may be ignored by the device.
103      *
104      * Available since API level 31.
105      */
106     AAUDIO_FORMAT_PCM_I32,
107 
108     /**
109      * This format is used for compressed audio wrapped in IEC61937 for HDMI
110      * or S/PDIF passthrough.
111      *
112      * Unlike PCM playback, the Android framework is not able to do format
113      * conversion for IEC61937. In that case, when IEC61937 is requested, sampling
114      * rate and channel count or channel mask must be specified. Otherwise, it may
115      * fail when opening the stream. Apps are able to get the correct configuration
116      * for the playback by calling
117      * <a href="/reference/android/media/AudioManager#getDevices(int)">
118      *   AudioManager#getDevices(int)</a>.
119      *
120      * Available since API level 34.
121      */
122     AAUDIO_FORMAT_IEC61937,
123 
124     /**
125      * This format is used for audio compressed in MP3 format.
126      */
127     AAUDIO_FORMAT_MP3,
128 
129     /**
130      * This format is used for audio compressed in AAC LC format.
131      */
132     AAUDIO_FORMAT_AAC_LC,
133 
134     /**
135      * This format is used for audio compressed in AAC HE V1 format.
136      */
137     AAUDIO_FORMAT_AAC_HE_V1,
138 
139     /**
140      * This format is used for audio compressed in AAC HE V2 format.
141      */
142     AAUDIO_FORMAT_AAC_HE_V2,
143 
144     /**
145      * This format is used for audio compressed in AAC ELD format.
146      */
147     AAUDIO_FORMAT_AAC_ELD,
148 
149     /**
150      * This format is used for audio compressed in AAC XHE format.
151      */
152     AAUDIO_FORMAT_AAC_XHE,
153 
154     /**
155      * This format is used for audio compressed in OPUS.
156      */
157     AAUDIO_FORMAT_OPUS
158 };
159 typedef int32_t aaudio_format_t;
160 
161 /**
162  * These result codes are returned from AAudio functions to indicate success or failure.
163  * Note that error return codes may change in the future so applications should generally
164  * not rely on specific return codes.
165  */
166 enum {
167     /**
168      * The call was successful.
169      */
170     AAUDIO_OK,
171 
172     /**
173      * Reserved. This should not be returned.
174      */
175     AAUDIO_ERROR_BASE = -900,
176 
177     /**
178      * The audio device was disconnected. This could occur, for example, when headphones
179      * are plugged in or unplugged. The stream cannot be used after the device is disconnected.
180      * Applications should stop and close the stream.
181      * If this error is received in an error callback then another thread should be
182      * used to stop and close the stream.
183      */
184     AAUDIO_ERROR_DISCONNECTED,
185 
186     /**
187      * An invalid parameter was passed to AAudio.
188      */
189     AAUDIO_ERROR_ILLEGAL_ARGUMENT,
190     // reserved
191 
192     /**
193      * An internal error occurred.
194      */
195     AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2,
196 
197     /**
198      * The requested operation is not appropriate for the current state of AAudio.
199      */
200     AAUDIO_ERROR_INVALID_STATE,
201     // reserved
202     // reserved
203 
204     /**
205      * The server rejected the handle used to identify the stream.
206      */
207     AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3,
208     // reserved
209 
210     /**
211      * The function is not implemented for this stream.
212      */
213     AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2,
214 
215     /**
216      * A resource or information is unavailable.
217      * This could occur when an application tries to open too many streams,
218      * or a timestamp is not available.
219      */
220     AAUDIO_ERROR_UNAVAILABLE,
221 
222     /**
223      * Reserved. This should not be returned.
224      */
225     AAUDIO_ERROR_NO_FREE_HANDLES,
226 
227     /**
228      * Memory could not be allocated.
229      */
230     AAUDIO_ERROR_NO_MEMORY,
231 
232     /**
233      * A NULL pointer was passed to AAudio.
234      * Or a NULL pointer was detected internally.
235      */
236     AAUDIO_ERROR_NULL,
237 
238     /**
239      * An operation took longer than expected.
240      */
241     AAUDIO_ERROR_TIMEOUT,
242 
243     /**
244      * A queue is full. This queue would be blocked.
245      */
246     AAUDIO_ERROR_WOULD_BLOCK,
247 
248     /**
249      * The requested data format is not supported.
250      */
251     AAUDIO_ERROR_INVALID_FORMAT,
252 
253     /**
254      * A requested was out of range.
255      */
256     AAUDIO_ERROR_OUT_OF_RANGE,
257 
258     /**
259      * The audio service was not available.
260      */
261     AAUDIO_ERROR_NO_SERVICE,
262 
263     /**
264      * The requested sample rate was not supported.
265      */
266     AAUDIO_ERROR_INVALID_RATE
267 };
268 typedef int32_t  aaudio_result_t;
269 
270 /**
271  * AAudio Stream states, for details, refer to
272  * <a href="/ndk/guides/audio/aaudio/aaudio#using-streams">Using an Audio Stream</a>
273  */
274 enum
275 {
276 
277     /**
278      * The stream is created but not initialized yet.
279      */
280     AAUDIO_STREAM_STATE_UNINITIALIZED = 0,
281     /**
282      * The stream is in an unrecognized state.
283      */
284     AAUDIO_STREAM_STATE_UNKNOWN,
285 
286     /**
287      * The stream is open and ready to use.
288      */
289     AAUDIO_STREAM_STATE_OPEN,
290     /**
291      * The stream is just starting up.
292      */
293     AAUDIO_STREAM_STATE_STARTING,
294     /**
295      * The stream has started.
296      */
297     AAUDIO_STREAM_STATE_STARTED,
298     /**
299      * The stream is pausing.
300      */
301     AAUDIO_STREAM_STATE_PAUSING,
302     /**
303      * The stream has paused, could be restarted or flushed.
304      */
305     AAUDIO_STREAM_STATE_PAUSED,
306     /**
307      * The stream is being flushed.
308      */
309     AAUDIO_STREAM_STATE_FLUSHING,
310     /**
311      * The stream is flushed, ready to be restarted.
312      */
313     AAUDIO_STREAM_STATE_FLUSHED,
314     /**
315      * The stream is stopping.
316      */
317     AAUDIO_STREAM_STATE_STOPPING,
318     /**
319      * The stream has been stopped.
320      */
321     AAUDIO_STREAM_STATE_STOPPED,
322     /**
323      * The stream is closing.
324      */
325     AAUDIO_STREAM_STATE_CLOSING,
326     /**
327      * The stream has been closed.
328      */
329     AAUDIO_STREAM_STATE_CLOSED,
330     /**
331      * The stream is disconnected from audio device.
332      * @deprecated
333      */
334     AAUDIO_STREAM_STATE_DISCONNECTED
335 };
336 typedef int32_t aaudio_stream_state_t;
337 
338 
339 enum {
340     /**
341      * This will be the only stream using a particular source or sink.
342      * This mode will provide the lowest possible latency.
343      * You should close EXCLUSIVE streams immediately when you are not using them.
344      */
345             AAUDIO_SHARING_MODE_EXCLUSIVE,
346     /**
347      * Multiple applications will be mixed by the AAudio Server.
348      * This will have higher latency than the EXCLUSIVE mode.
349      */
350             AAUDIO_SHARING_MODE_SHARED
351 };
352 typedef int32_t aaudio_sharing_mode_t;
353 
354 
355 enum {
356     /**
357      * No particular performance needs. Default.
358      */
359     AAUDIO_PERFORMANCE_MODE_NONE = 10,
360 
361     /**
362      * Extending battery life is more important than low latency.
363      *
364      * This mode is not supported in input streams.
365      * For input, mode NONE will be used if this is requested.
366      */
367     AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
368 
369     /**
370      * Reducing latency is more important than battery life.
371      */
372     AAUDIO_PERFORMANCE_MODE_LOW_LATENCY,
373 
374     /**
375      * Extending battery life is more important than low latency.
376      *
377      * This mode is not supported in input streams.
378      * This mode will play through the offloaded audio path to save battery life.
379      *
380      * Comparing to mode {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING}, the stream at
381      * this mode will be able to write a large amount(several seconds) of data within a
382      * short time. The written data will be queued in a hardware buffer. After that, the
383      * app can suspend its thread/process that playing audio, the audio framework's data
384      * pipe will be suspended automatically and the CPU will be allowed to sleep for
385      * power saving. When all queued data are played, the apps will be able to get callback
386      * to feed more data.
387      */
388     AAUDIO_PERFORMANCE_MODE_POWER_SAVING_OFFLOADED
389 };
390 typedef int32_t aaudio_performance_mode_t;
391 
392 #define AAUDIO_SYSTEM_USAGE_OFFSET 1000
393 
394 /**
395  * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for.
396  * This information is used by certain platforms or routing policies
397  * to make more refined volume or routing decisions.
398  *
399  * Note that these match the equivalent values in
400  * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>
401  * in the Android Java API.
402  *
403  * Added in API level 28.
404  */
405 enum {
406     /**
407      * Use this for streaming media, music performance, video, podcasts, etcetera.
408      */
409     AAUDIO_USAGE_MEDIA = 1,
410 
411     /**
412      * Use this for voice over IP, telephony, etcetera.
413      */
414     AAUDIO_USAGE_VOICE_COMMUNICATION = 2,
415 
416     /**
417      * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.
418      */
419     AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
420 
421     /**
422      * Use this to demand the users attention.
423      */
424     AAUDIO_USAGE_ALARM = 4,
425 
426     /**
427      * Use this for notifying the user when a message has arrived or some
428      * other background event has occured.
429      */
430     AAUDIO_USAGE_NOTIFICATION = 5,
431 
432     /**
433      * Use this when the phone rings.
434      */
435     AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6,
436 
437     /**
438      * Use this to attract the users attention when, for example, the battery is low.
439      */
440     AAUDIO_USAGE_NOTIFICATION_EVENT = 10,
441 
442     /**
443      * Use this for screen readers, etcetera.
444      */
445     AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
446 
447     /**
448      * Use this for driving or navigation directions.
449      */
450     AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
451 
452     /**
453      * Use this for user interface sounds, beeps, etcetera.
454      */
455     AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
456 
457     /**
458      * Use this for game audio and sound effects.
459      */
460     AAUDIO_USAGE_GAME = 14,
461 
462     /**
463      * Use this for audio responses to user queries, audio instructions or help utterances.
464      */
465     AAUDIO_USAGE_ASSISTANT = 16,
466 
467     /**
468      * Use this in case of playing sounds in an emergency.
469      * Privileged MODIFY_AUDIO_ROUTING permission required.
470      */
471     AAUDIO_SYSTEM_USAGE_EMERGENCY = AAUDIO_SYSTEM_USAGE_OFFSET,
472 
473     /**
474      * Use this for safety sounds and alerts, for example backup camera obstacle detection.
475      * Privileged MODIFY_AUDIO_ROUTING permission required.
476      */
477     AAUDIO_SYSTEM_USAGE_SAFETY = AAUDIO_SYSTEM_USAGE_OFFSET + 1,
478 
479     /**
480      * Use this for vehicle status alerts and information, for example the check engine light.
481      * Privileged MODIFY_AUDIO_ROUTING permission required.
482      */
483     AAUDIO_SYSTEM_USAGE_VEHICLE_STATUS = AAUDIO_SYSTEM_USAGE_OFFSET + 2,
484 
485     /**
486      * Use this for traffic announcements, etc.
487      * Privileged MODIFY_AUDIO_ROUTING permission required.
488      */
489     AAUDIO_SYSTEM_USAGE_ANNOUNCEMENT = AAUDIO_SYSTEM_USAGE_OFFSET + 3,
490 };
491 typedef int32_t aaudio_usage_t;
492 
493 /**
494  * The CONTENT_TYPE attribute describes "what" you are playing.
495  * It expresses the general category of the content. This information is optional.
496  * But in case it is known (for instance AAUDIO_CONTENT_TYPE_MOVIE for a
497  * movie streaming service or AAUDIO_CONTENT_TYPE_SPEECH for
498  * an audio book application) this information might be used by the audio framework to
499  * enforce audio focus.
500  *
501  * Note that these match the equivalent values in
502  * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>
503  * in the Android Java API.
504  *
505  * Added in API level 28.
506  */
507 enum {
508 
509     /**
510      * Use this for spoken voice, audio books, etcetera.
511      */
512     AAUDIO_CONTENT_TYPE_SPEECH = 1,
513 
514     /**
515      * Use this for pre-recorded or live music.
516      */
517     AAUDIO_CONTENT_TYPE_MUSIC = 2,
518 
519     /**
520      * Use this for a movie or video soundtrack.
521      */
522     AAUDIO_CONTENT_TYPE_MOVIE = 3,
523 
524     /**
525      * Use this for sound is designed to accompany a user action,
526      * such as a click or beep sound made when the user presses a button.
527      */
528     AAUDIO_CONTENT_TYPE_SONIFICATION = 4
529 };
530 typedef int32_t aaudio_content_type_t;
531 
532 enum {
533 
534     /**
535      * Constant indicating the audio content associated with these attributes will follow the
536      * default platform behavior with regards to which content will be spatialized or not.
537      */
538     AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO = 1,
539 
540     /**
541      * Constant indicating the audio content associated with these attributes should never
542      * be spatialized.
543      */
544     AAUDIO_SPATIALIZATION_BEHAVIOR_NEVER = 2,
545 };
546 typedef int32_t aaudio_spatialization_behavior_t;
547 
548 /**
549  * Defines the audio source.
550  * An audio source defines both a default physical source of audio signal, and a recording
551  * configuration.
552  *
553  * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
554  *
555  * Added in API level 28.
556  */
557 enum {
558     /**
559      * Use this preset when other presets do not apply.
560      */
561     AAUDIO_INPUT_PRESET_GENERIC = 1,
562 
563     /**
564      * Use this preset when recording video.
565      */
566     AAUDIO_INPUT_PRESET_CAMCORDER = 5,
567 
568     /**
569      * Use this preset when doing speech recognition.
570      */
571     AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6,
572 
573     /**
574      * Use this preset when doing telephony or voice messaging.
575      */
576     AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7,
577 
578     /**
579      * Use this preset to obtain an input with no effects.
580      * Note that this input will not have automatic gain control
581      * so the recorded volume may be very low.
582      */
583     AAUDIO_INPUT_PRESET_UNPROCESSED = 9,
584 
585     /**
586      * Use this preset for capturing audio meant to be processed in real time
587      * and played back for live performance (e.g karaoke).
588      * The capture path will minimize latency and coupling with playback path.
589      * Available since API level 29.
590      */
591     AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE = 10,
592 
593     /**
594      * Use this preset for an echo canceller to capture the reference signal.
595      * Reserved for system components.
596      * Requires CAPTURE_AUDIO_OUTPUT permission
597      * Available since API level 35.
598      */
599     AAUDIO_INPUT_PRESET_SYSTEM_ECHO_REFERENCE = 1997,
600 
601     /**
602      * Use this preset for preemptible, low-priority software hotword detection.
603      * Reserved for system components.
604      * Requires CAPTURE_AUDIO_HOTWORD permission.
605      * Available since API level 35.
606      */
607     AAUDIO_INPUT_PRESET_SYSTEM_HOTWORD = 1999,
608 };
609 typedef int32_t aaudio_input_preset_t;
610 
611 /**
612  * Specifying if audio may or may not be captured by other apps or the system.
613  *
614  * Note that these match the equivalent values in
615  * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>
616  * in the Android Java API.
617  *
618  * Added in API level 29.
619  */
620 enum {
621     /**
622      * Indicates that the audio may be captured by any app.
623      *
624      * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*,
625      * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and {@link #AAUDIO_USAGE_ASSISTANT}.
626      *
627      * On <a href="/reference/android/os/Build.VERSION_CODES#Q">Q</a>,
628      * this means only {@link #AAUDIO_USAGE_MEDIA} and {@link #AAUDIO_USAGE_GAME} may be captured.
629      *
630      * See <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_ALL">
631      * ALLOW_CAPTURE_BY_ALL</a>.
632      */
633     AAUDIO_ALLOW_CAPTURE_BY_ALL = 1,
634     /**
635      * Indicates that the audio may only be captured by system apps.
636      *
637      * System apps can capture for many purposes like accessibility, user guidance...
638      * but have strong restriction. See
639      * <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_SYSTEM">
640      * ALLOW_CAPTURE_BY_SYSTEM</a>
641      * for what the system apps can do with the capture audio.
642      */
643     AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2,
644     /**
645      * Indicates that the audio may not be recorded by any app, even if it is a system app.
646      *
647      * It is encouraged to use {@link #AAUDIO_ALLOW_CAPTURE_BY_SYSTEM} instead of this value as system apps
648      * provide significant and useful features for the user (eg. accessibility).
649      * See <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_NONE">
650      * ALLOW_CAPTURE_BY_NONE</a>.
651      */
652     AAUDIO_ALLOW_CAPTURE_BY_NONE = 3,
653 };
654 
655 typedef int32_t aaudio_allowed_capture_policy_t;
656 
657 /**
658  * These may be used with AAudioStreamBuilder_setSessionId().
659  *
660  * Added in API level 28.
661  */
662 enum {
663     /**
664      * Do not allocate a session ID.
665      * Effects cannot be used with this stream.
666      * Default.
667      *
668      * Added in API level 28.
669      */
670     AAUDIO_SESSION_ID_NONE = -1,
671 
672     /**
673      * Allocate a session ID that can be used to attach and control
674      * effects using the Java AudioEffects API.
675      * Note that using this may result in higher latency.
676      *
677      * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.
678      *
679      * Added in API level 28.
680      */
681     AAUDIO_SESSION_ID_ALLOCATE = 0,
682 };
683 typedef int32_t aaudio_session_id_t;
684 
685 /**
686  * Defines the audio channel mask.
687  * Channel masks are used to describe the samples and their
688  * arrangement in the audio frame. They are also used in the endpoint
689  * (e.g. a USB audio interface, a DAC connected to headphones) to
690  * specify allowable configurations of a particular device.
691  *
692  * Channel masks are for input only, output only, or both input and output.
693  * These channel masks are different than those defined in AudioFormat.java.
694  * If an app gets a channel mask from Java API and wants to use it in AAudio,
695  * conversion should be done by the app.
696  *
697  * Added in API level 32.
698  */
699 enum {
700     /**
701      * Invalid channel mask
702      */
703     AAUDIO_CHANNEL_INVALID = -1,
704     AAUDIO_CHANNEL_FRONT_LEFT = 1 << 0,
705     AAUDIO_CHANNEL_FRONT_RIGHT = 1 << 1,
706     AAUDIO_CHANNEL_FRONT_CENTER = 1 << 2,
707     AAUDIO_CHANNEL_LOW_FREQUENCY = 1 << 3,
708     AAUDIO_CHANNEL_BACK_LEFT = 1 << 4,
709     AAUDIO_CHANNEL_BACK_RIGHT = 1 << 5,
710     AAUDIO_CHANNEL_FRONT_LEFT_OF_CENTER = 1 << 6,
711     AAUDIO_CHANNEL_FRONT_RIGHT_OF_CENTER = 1 << 7,
712     AAUDIO_CHANNEL_BACK_CENTER = 1 << 8,
713     AAUDIO_CHANNEL_SIDE_LEFT = 1 << 9,
714     AAUDIO_CHANNEL_SIDE_RIGHT = 1 << 10,
715     AAUDIO_CHANNEL_TOP_CENTER = 1 << 11,
716     AAUDIO_CHANNEL_TOP_FRONT_LEFT = 1 << 12,
717     AAUDIO_CHANNEL_TOP_FRONT_CENTER = 1 << 13,
718     AAUDIO_CHANNEL_TOP_FRONT_RIGHT = 1 << 14,
719     AAUDIO_CHANNEL_TOP_BACK_LEFT = 1 << 15,
720     AAUDIO_CHANNEL_TOP_BACK_CENTER = 1 << 16,
721     AAUDIO_CHANNEL_TOP_BACK_RIGHT = 1 << 17,
722     AAUDIO_CHANNEL_TOP_SIDE_LEFT = 1 << 18,
723     AAUDIO_CHANNEL_TOP_SIDE_RIGHT = 1 << 19,
724     AAUDIO_CHANNEL_BOTTOM_FRONT_LEFT = 1 << 20,
725     AAUDIO_CHANNEL_BOTTOM_FRONT_CENTER = 1 << 21,
726     AAUDIO_CHANNEL_BOTTOM_FRONT_RIGHT = 1 << 22,
727     AAUDIO_CHANNEL_LOW_FREQUENCY_2 = 1 << 23,
728     AAUDIO_CHANNEL_FRONT_WIDE_LEFT = 1 << 24,
729     AAUDIO_CHANNEL_FRONT_WIDE_RIGHT = 1 << 25,
730 
731     /**
732      * Supported for Input and Output
733      */
734     AAUDIO_CHANNEL_MONO = AAUDIO_CHANNEL_FRONT_LEFT,
735     /**
736      * Supported for Input and Output
737      */
738     AAUDIO_CHANNEL_STEREO = AAUDIO_CHANNEL_FRONT_LEFT |
739                             AAUDIO_CHANNEL_FRONT_RIGHT,
740     /**
741      * Supported for only Output
742      */
743     AAUDIO_CHANNEL_2POINT1 = AAUDIO_CHANNEL_FRONT_LEFT |
744                              AAUDIO_CHANNEL_FRONT_RIGHT |
745                              AAUDIO_CHANNEL_LOW_FREQUENCY,
746     /**
747      * Supported for only Output
748      */
749     AAUDIO_CHANNEL_TRI = AAUDIO_CHANNEL_FRONT_LEFT |
750                          AAUDIO_CHANNEL_FRONT_RIGHT |
751                          AAUDIO_CHANNEL_FRONT_CENTER,
752     /**
753      * Supported for only Output
754      */
755     AAUDIO_CHANNEL_TRI_BACK = AAUDIO_CHANNEL_FRONT_LEFT |
756                               AAUDIO_CHANNEL_FRONT_RIGHT |
757                               AAUDIO_CHANNEL_BACK_CENTER,
758     /**
759      * Supported for only Output
760      */
761     AAUDIO_CHANNEL_3POINT1 = AAUDIO_CHANNEL_FRONT_LEFT |
762                              AAUDIO_CHANNEL_FRONT_RIGHT |
763                              AAUDIO_CHANNEL_FRONT_CENTER |
764                              AAUDIO_CHANNEL_LOW_FREQUENCY,
765     /**
766      * Supported for Input and Output
767      */
768     AAUDIO_CHANNEL_2POINT0POINT2 = AAUDIO_CHANNEL_FRONT_LEFT |
769                                    AAUDIO_CHANNEL_FRONT_RIGHT |
770                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
771                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
772     /**
773      * Supported for Input and Output
774      */
775     AAUDIO_CHANNEL_2POINT1POINT2 = AAUDIO_CHANNEL_2POINT0POINT2 |
776                                    AAUDIO_CHANNEL_LOW_FREQUENCY,
777     /**
778      * Supported for Input and Output
779      */
780     AAUDIO_CHANNEL_3POINT0POINT2 = AAUDIO_CHANNEL_FRONT_LEFT |
781                                    AAUDIO_CHANNEL_FRONT_RIGHT |
782                                    AAUDIO_CHANNEL_FRONT_CENTER |
783                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
784                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
785     /**
786      * Supported for Input and Output
787      */
788     AAUDIO_CHANNEL_3POINT1POINT2 = AAUDIO_CHANNEL_3POINT0POINT2 |
789                                    AAUDIO_CHANNEL_LOW_FREQUENCY,
790     /**
791      * Supported for only Output
792      */
793     AAUDIO_CHANNEL_QUAD = AAUDIO_CHANNEL_FRONT_LEFT |
794                           AAUDIO_CHANNEL_FRONT_RIGHT |
795                           AAUDIO_CHANNEL_BACK_LEFT |
796                           AAUDIO_CHANNEL_BACK_RIGHT,
797     /**
798      * Supported for only Output
799      */
800     AAUDIO_CHANNEL_QUAD_SIDE = AAUDIO_CHANNEL_FRONT_LEFT |
801                                AAUDIO_CHANNEL_FRONT_RIGHT |
802                                AAUDIO_CHANNEL_SIDE_LEFT |
803                                AAUDIO_CHANNEL_SIDE_RIGHT,
804     /**
805      * Supported for only Output
806      */
807     AAUDIO_CHANNEL_SURROUND = AAUDIO_CHANNEL_FRONT_LEFT |
808                               AAUDIO_CHANNEL_FRONT_RIGHT |
809                               AAUDIO_CHANNEL_FRONT_CENTER |
810                               AAUDIO_CHANNEL_BACK_CENTER,
811     /**
812      * Supported for only Output
813      */
814     AAUDIO_CHANNEL_PENTA = AAUDIO_CHANNEL_QUAD |
815                            AAUDIO_CHANNEL_FRONT_CENTER,
816     /**
817      * Supported for Input and Output. aka 5POINT1_BACK
818      */
819     AAUDIO_CHANNEL_5POINT1 = AAUDIO_CHANNEL_FRONT_LEFT |
820                              AAUDIO_CHANNEL_FRONT_RIGHT |
821                              AAUDIO_CHANNEL_FRONT_CENTER |
822                              AAUDIO_CHANNEL_LOW_FREQUENCY |
823                              AAUDIO_CHANNEL_BACK_LEFT |
824                              AAUDIO_CHANNEL_BACK_RIGHT,
825     /**
826      * Supported for only Output
827      */
828     AAUDIO_CHANNEL_5POINT1_SIDE = AAUDIO_CHANNEL_FRONT_LEFT |
829                                   AAUDIO_CHANNEL_FRONT_RIGHT |
830                                   AAUDIO_CHANNEL_FRONT_CENTER |
831                                   AAUDIO_CHANNEL_LOW_FREQUENCY |
832                                   AAUDIO_CHANNEL_SIDE_LEFT |
833                                   AAUDIO_CHANNEL_SIDE_RIGHT,
834     /**
835      * Supported for only Output
836      */
837     AAUDIO_CHANNEL_6POINT1 = AAUDIO_CHANNEL_FRONT_LEFT |
838                              AAUDIO_CHANNEL_FRONT_RIGHT |
839                              AAUDIO_CHANNEL_FRONT_CENTER |
840                              AAUDIO_CHANNEL_LOW_FREQUENCY |
841                              AAUDIO_CHANNEL_BACK_LEFT |
842                              AAUDIO_CHANNEL_BACK_RIGHT |
843                              AAUDIO_CHANNEL_BACK_CENTER,
844     /**
845      * Supported for only Output
846      */
847     AAUDIO_CHANNEL_7POINT1 = AAUDIO_CHANNEL_5POINT1 |
848                              AAUDIO_CHANNEL_SIDE_LEFT |
849                              AAUDIO_CHANNEL_SIDE_RIGHT,
850     /**
851      * Supported for only Output
852      */
853     AAUDIO_CHANNEL_5POINT1POINT2 = AAUDIO_CHANNEL_5POINT1 |
854                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
855                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
856     /**
857      * Supported for only Output
858      */
859     AAUDIO_CHANNEL_5POINT1POINT4 = AAUDIO_CHANNEL_5POINT1 |
860                                    AAUDIO_CHANNEL_TOP_FRONT_LEFT |
861                                    AAUDIO_CHANNEL_TOP_FRONT_RIGHT |
862                                    AAUDIO_CHANNEL_TOP_BACK_LEFT |
863                                    AAUDIO_CHANNEL_TOP_BACK_RIGHT,
864     /**
865      * Supported for only Output
866      */
867     AAUDIO_CHANNEL_7POINT1POINT2 = AAUDIO_CHANNEL_7POINT1 |
868                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
869                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
870     /**
871      * Supported for only Output
872      */
873     AAUDIO_CHANNEL_7POINT1POINT4 = AAUDIO_CHANNEL_7POINT1 |
874                                    AAUDIO_CHANNEL_TOP_FRONT_LEFT |
875                                    AAUDIO_CHANNEL_TOP_FRONT_RIGHT |
876                                    AAUDIO_CHANNEL_TOP_BACK_LEFT |
877                                    AAUDIO_CHANNEL_TOP_BACK_RIGHT,
878     /**
879      * Supported for only Output
880      */
881     AAUDIO_CHANNEL_9POINT1POINT4 = AAUDIO_CHANNEL_7POINT1POINT4 |
882                                    AAUDIO_CHANNEL_FRONT_WIDE_LEFT |
883                                    AAUDIO_CHANNEL_FRONT_WIDE_RIGHT,
884     /**
885      * Supported for only Output
886      */
887     AAUDIO_CHANNEL_9POINT1POINT6 = AAUDIO_CHANNEL_9POINT1POINT4 |
888                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
889                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
890     /**
891      * Supported for only Input
892      */
893     AAUDIO_CHANNEL_FRONT_BACK = AAUDIO_CHANNEL_FRONT_CENTER |
894                                 AAUDIO_CHANNEL_BACK_CENTER,
895 };
896 typedef uint32_t aaudio_channel_mask_t;
897 
898 // The values are copied from JAVA SDK device types defined in android/media/AudioDeviceInfo.java
899 // When a new value is added, it should be added here and handled by the conversion at
900 // AAudioConvert_aaudioToAndroidDeviceType.
901 typedef enum AAudio_DeviceType : int32_t {
902     /**
903      * A device type describing the attached earphone speaker.
904      */
905     AAUDIO_DEVICE_BUILTIN_EARPIECE = 1,
906 
907     /**
908      * A device type describing the speaker system (i.e. a mono speaker or stereo speakers) built
909      * in a device.
910      */
911     AAUDIO_DEVICE_BUILTIN_SPEAKER = 2,
912 
913     /**
914      * A device type describing a headset, which is the combination of a headphones and microphone.
915      */
916     AAUDIO_DEVICE_WIRED_HEADSET = 3,
917 
918     /**
919      * A device type describing a pair of wired headphones.
920      */
921     AAUDIO_DEVICE_WIRED_HEADPHONES = 4,
922 
923     /**
924      * A device type describing an analog line-level connection.
925      */
926     AAUDIO_DEVICE_LINE_ANALOG = 5,
927 
928     /**
929      * A device type describing a digital line connection (e.g. SPDIF).
930      */
931     AAUDIO_DEVICE_LINE_DIGITAL = 6,
932 
933     /**
934      * A device type describing a Bluetooth device typically used for telephony.
935      */
936     AAUDIO_DEVICE_BLUETOOTH_SCO = 7,
937 
938     /**
939      * A device type describing a Bluetooth device supporting the A2DP profile.
940      */
941     AAUDIO_DEVICE_BLUETOOTH_A2DP = 8,
942 
943     /**
944      * A device type describing an HDMI connection .
945      */
946     AAUDIO_DEVICE_HDMI = 9,
947 
948     /**
949      * A device type describing the Audio Return Channel of an HDMI connection.
950      */
951     AAUDIO_DEVICE_HDMI_ARC = 10,
952 
953     /**
954      * A device type describing a USB audio device.
955      */
956     AAUDIO_DEVICE_USB_DEVICE = 11,
957 
958     /**
959      * A device type describing a USB audio device in accessory mode.
960      */
961     AAUDIO_DEVICE_USB_ACCESSORY = 12,
962 
963     /**
964      * A device type describing the audio device associated with a dock.
965      * Starting at API 34, this device type only represents digital docks, while docks with an
966      * analog connection are represented with {@link #AAUDIO_DEVICE_DOCK_ANALOG}.
967      */
968     AAUDIO_DEVICE_DOCK = 13,
969 
970     /**
971      * A device type associated with the transmission of audio signals over FM.
972      */
973     AAUDIO_DEVICE_FM = 14,
974 
975     /**
976      * A device type describing the microphone(s) built in a device.
977      */
978     AAUDIO_DEVICE_BUILTIN_MIC = 15,
979 
980     /**
981      * A device type for accessing the audio content transmitted over FM.
982      */
983     AAUDIO_DEVICE_FM_TUNER = 16,
984 
985     /**
986      * A device type for accessing the audio content transmitted over the TV tuner system.
987      */
988     AAUDIO_DEVICE_TV_TUNER = 17,
989 
990     /**
991      * A device type describing the transmission of audio signals over the telephony network.
992      */
993     AAUDIO_DEVICE_TELEPHONY = 18,
994 
995     /**
996      * A device type describing the auxiliary line-level connectors.
997      */
998     AAUDIO_DEVICE_AUX_LINE = 19,
999 
1000     /**
1001      * A device type connected over IP.
1002      */
1003     AAUDIO_DEVICE_IP = 20,
1004 
1005     /**
1006      * A type-agnostic device used for communication with external audio systems.
1007      */
1008     AAUDIO_DEVICE_BUS = 21,
1009 
1010     /**
1011      * A device type describing a USB audio headset.
1012      */
1013     AAUDIO_DEVICE_USB_HEADSET = 22,
1014 
1015     /**
1016      * A device type describing a Hearing Aid.
1017      */
1018     AAUDIO_DEVICE_HEARING_AID = 23,
1019 
1020     /**
1021      * A device type describing the speaker system (i.e. a mono speaker or stereo speakers) built
1022      * in a device, that is specifically tuned for outputting sounds like notifications and alarms
1023      * (i.e. sounds the user couldn't necessarily anticipate).
1024      * <p>Note that this physical audio device may be the same as {@link #TYPE_BUILTIN_SPEAKER}
1025      * but is driven differently to safely accommodate the different use case.</p>
1026      */
1027     AAUDIO_DEVICE_BUILTIN_SPEAKER_SAFE = 24,
1028 
1029     /**
1030      * A device type for rerouting audio within the Android framework between mixes and
1031      * system applications.
1032      */
1033     AAUDIO_DEVICE_REMOTE_SUBMIX = 25,
1034     /**
1035      * A device type describing a Bluetooth Low Energy (BLE) audio headset or headphones.
1036      * Headphones are grouped with headsets when the device is a sink:
1037      * the features of headsets and headphones with regard to playback are the same.
1038      */
1039     AAUDIO_DEVICE_BLE_HEADSET = 26,
1040 
1041     /**
1042      * A device type describing a Bluetooth Low Energy (BLE) audio speaker.
1043      */
1044     AAUDIO_DEVICE_BLE_SPEAKER = 27,
1045 
1046     /**
1047      * A device type describing an Echo Canceller loopback Reference.
1048      * This device is only used when capturing with MediaRecorder.AudioSource.ECHO_REFERENCE,
1049      * which requires privileged permission
1050      * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT}.
1051      *
1052      * Note that this is not exposed as it is a system API that requires privileged permission.
1053      */
1054     // AAUDIO_DEVICE_ECHO_REFERENCE = 28,
1055 
1056     /**
1057      * A device type describing the Enhanced Audio Return Channel of an HDMI connection.
1058      */
1059     AAUDIO_DEVICE_HDMI_EARC = 29,
1060 
1061     /**
1062      * A device type describing a Bluetooth Low Energy (BLE) broadcast group.
1063      */
1064     AAUDIO_DEVICE_BLE_BROADCAST = 30,
1065 
1066     /**
1067      * A device type describing the audio device associated with a dock using an analog connection.
1068      */
1069     AAUDIO_DEVICE_DOCK_ANALOG = 31
1070 } AAudio_DeviceType;
1071 
1072 typedef struct AAudioStreamStruct         AAudioStream;
1073 typedef struct AAudioStreamBuilderStruct  AAudioStreamBuilder;
1074 
1075 #ifndef AAUDIO_API
1076 #define AAUDIO_API /* export this symbol */
1077 #endif
1078 
1079 // ============================================================
1080 // Audio System
1081 // ============================================================
1082 
1083 /**
1084  * The text is the ASCII symbol corresponding to the returnCode,
1085  * or an English message saying the returnCode is unrecognized.
1086  * This is intended for developers to use when debugging.
1087  * It is not for display to users.
1088  *
1089  * Available since API level 26.
1090  *
1091  * @return pointer to a text representation of an AAudio result code.
1092  */
1093 AAUDIO_API const char * _Nonnull AAudio_convertResultToText(aaudio_result_t returnCode)
1094         __INTRODUCED_IN(26);
1095 
1096 /**
1097  * The text is the ASCII symbol corresponding to the stream state,
1098  * or an English message saying the state is unrecognized.
1099  * This is intended for developers to use when debugging.
1100  * It is not for display to users.
1101  *
1102  * Available since API level 26.
1103  *
1104  * @return pointer to a text representation of an AAudio state.
1105  */
1106 AAUDIO_API const char * _Nonnull AAudio_convertStreamStateToText(aaudio_stream_state_t state)
1107         __INTRODUCED_IN(26);
1108 
1109 // ============================================================
1110 // StreamBuilder
1111 // ============================================================
1112 
1113 /**
1114  * Create a StreamBuilder that can be used to open a Stream.
1115  *
1116  * The deviceId is initially unspecified, meaning that the current default device will be used.
1117  *
1118  * The default direction is {@link #AAUDIO_DIRECTION_OUTPUT}.
1119  * The default sharing mode is {@link #AAUDIO_SHARING_MODE_SHARED}.
1120  * The data format, samplesPerFrames and sampleRate are unspecified and will be
1121  * chosen by the device when it is opened.
1122  *
1123  * AAudioStreamBuilder_delete() must be called when you are done using the builder.
1124  *
1125  * Available since API level 26.
1126  */
1127 AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder* _Nullable* _Nonnull
1128                                                       builder) __INTRODUCED_IN(26);
1129 
1130 /**
1131  * Request an audio device identified by an ID.
1132  *
1133  * The ID could be obtained from the Java AudioManager.
1134  * AudioManager.getDevices() returns an array of {@link AudioDeviceInfo},
1135  * which contains a getId() method. That ID can be passed to this function.
1136  *
1137  * It is possible that you may not get the device that you requested.
1138  * So if it is important to you, you should call
1139  * AAudioStream_getDeviceId() after the stream is opened to
1140  * verify the actual ID.
1141  *
1142  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED},
1143  * in which case the primary device will be used.
1144  *
1145  * Available since API level 26.
1146  *
1147  * @param builder reference provided by AAudio_createStreamBuilder()
1148  * @param deviceId device identifier or {@link #AAUDIO_UNSPECIFIED}
1149  */
1150 AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* _Nonnull builder,
1151                                                 int32_t deviceId) __INTRODUCED_IN(26);
1152 
1153 /**
1154  * Declare the name of the package creating the stream.
1155  *
1156  * This is usually {@code Context#getPackageName()}.
1157  *
1158  * The default, if you do not call this function, is a random package in the calling uid.
1159  * The vast majority of apps have only one package per calling UID.
1160  * If an invalid package name is set, input streams may not be given permission to
1161  * record when started.
1162  *
1163  * The package name is usually the applicationId in your app's build.gradle file.
1164  *
1165  * Available since API level 31.
1166  *
1167  * @param builder reference provided by AAudio_createStreamBuilder()
1168  * @param packageName packageName of the calling app.
1169  */
1170 AAUDIO_API void AAudioStreamBuilder_setPackageName(AAudioStreamBuilder* _Nonnull builder,
1171         const char * _Nonnull packageName) __INTRODUCED_IN(31);
1172 
1173 /**
1174  * Declare the attribution tag of the context creating the stream.
1175  *
1176  * This is usually {@code Context#getAttributionTag()}.
1177  *
1178  * The default, if you do not call this function, is null.
1179  *
1180  * Available since API level 31.
1181  *
1182  * @param builder reference provided by AAudio_createStreamBuilder()
1183  * @param attributionTag attributionTag of the calling context.
1184  */
1185 AAUDIO_API void AAudioStreamBuilder_setAttributionTag(AAudioStreamBuilder* _Nonnull builder,
1186         const char * _Nonnull attributionTag) __INTRODUCED_IN(31);
1187 
1188 /**
1189  * Request a sample rate in Hertz.
1190  *
1191  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
1192  * An optimal value will then be chosen when the stream is opened.
1193  * After opening a stream with an unspecified value, the application must
1194  * query for the actual value, which may vary by device.
1195  *
1196  * If an exact value is specified then an opened stream will use that value.
1197  * If a stream cannot be opened with the specified value then the open will fail.
1198  *
1199  * Available since API level 26.
1200  *
1201  * @param builder reference provided by AAudio_createStreamBuilder()
1202  * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
1203  */
1204 AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* _Nonnull builder,
1205                                                   int32_t sampleRate) __INTRODUCED_IN(26);
1206 
1207 /**
1208  * Request a number of channels for the stream.
1209  *
1210  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
1211  * An optimal value will then be chosen when the stream is opened.
1212  * After opening a stream with an unspecified value, the application must
1213  * query for the actual value, which may vary by device.
1214  *
1215  * If an exact value is specified then an opened stream will use that value.
1216  * If a stream cannot be opened with the specified value then the open will fail.
1217  *
1218  * As the channel count provided here may be different from the corresponding channel count
1219  * of channel mask used in {@link AAudioStreamBuilder_setChannelMask}, the last called function
1220  * will be respected if both this function and {@link AAudioStreamBuilder_setChannelMask} are
1221  * called.
1222  *
1223  * Note that if the channel count is two then it may get mixed to mono when the device only supports
1224  * one channel. If the channel count is greater than two but the device's supported channel count is
1225  * less than the requested value, the channels higher than the device channel will be dropped. If
1226  * higher channels should be mixed or spatialized, use {@link AAudioStreamBuilder_setChannelMask}
1227  * instead.
1228  *
1229  * Available since API level 26.
1230  *
1231  * @param builder reference provided by AAudio_createStreamBuilder()
1232  * @param channelCount Number of channels desired.
1233  */
1234 AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* _Nonnull builder,
1235                                                     int32_t channelCount) __INTRODUCED_IN(26);
1236 
1237 /**
1238  * Identical to AAudioStreamBuilder_setChannelCount().
1239  *
1240  * Available since API level 26.
1241  *
1242  * @param builder reference provided by AAudio_createStreamBuilder()
1243  * @param samplesPerFrame Number of samples in a frame.
1244  *
1245  * @deprecated use {@link AAudioStreamBuilder_setChannelCount}
1246  */
1247 AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* _Nonnull builder,
1248                                                        int32_t samplesPerFrame) __INTRODUCED_IN(26);
1249 
1250 /**
1251  * Request a sample data format, for example {@link #AAUDIO_FORMAT_PCM_I16}.
1252  *
1253  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
1254  * An optimal value will then be chosen when the stream is opened.
1255  * After opening a stream with an unspecified value, the application must
1256  * query for the actual value, which may vary by device.
1257  *
1258  * If an exact value is specified then an opened stream will use that value.
1259  * If a stream cannot be opened with the specified value then the open will fail.
1260  *
1261  * Available since API level 26.
1262  *
1263  * @param builder reference provided by AAudio_createStreamBuilder()
1264  * @param format common formats are {@link #AAUDIO_FORMAT_PCM_FLOAT} and
1265  *               {@link #AAUDIO_FORMAT_PCM_I16}.
1266  */
1267 AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* _Nonnull builder,
1268                                               aaudio_format_t format) __INTRODUCED_IN(26);
1269 
1270 /**
1271  * Request a mode for sharing the device.
1272  *
1273  * The default, if you do not call this function, is {@link #AAUDIO_SHARING_MODE_SHARED}.
1274  *
1275  * The requested sharing mode may not be available.
1276  * The application can query for the actual mode after the stream is opened.
1277  *
1278  * Available since API level 26.
1279  *
1280  * @param builder reference provided by AAudio_createStreamBuilder()
1281  * @param sharingMode {@link #AAUDIO_SHARING_MODE_SHARED} or {@link #AAUDIO_SHARING_MODE_EXCLUSIVE}
1282  */
1283 AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* _Nonnull builder,
1284         aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26);
1285 
1286 /**
1287  * Request the direction for a stream.
1288  *
1289  * The default, if you do not call this function, is {@link #AAUDIO_DIRECTION_OUTPUT}.
1290  *
1291  * Available since API level 26.
1292  *
1293  * @param builder reference provided by AAudio_createStreamBuilder()
1294  * @param direction {@link #AAUDIO_DIRECTION_OUTPUT} or {@link #AAUDIO_DIRECTION_INPUT}
1295  */
1296 AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* _Nonnull builder,
1297         aaudio_direction_t direction) __INTRODUCED_IN(26);
1298 
1299 /**
1300  * Set the requested buffer capacity in frames.
1301  * The final AAudioStream capacity may differ, but will probably be at least this big.
1302  *
1303  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
1304  *
1305  * Available since API level 26.
1306  *
1307  * @param builder reference provided by AAudio_createStreamBuilder()
1308  * @param numFrames the desired buffer capacity in frames or {@link #AAUDIO_UNSPECIFIED}
1309  */
1310 AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(
1311         AAudioStreamBuilder* _Nonnull builder, int32_t numFrames) __INTRODUCED_IN(26);
1312 
1313 /**
1314  * Set the requested performance mode.
1315  *
1316  * Supported modes are {@link #AAUDIO_PERFORMANCE_MODE_NONE},
1317  * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING}, {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY} and
1318  * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING_OFFLOADED}.
1319  *
1320  * The default, if you do not call this function, is {@link #AAUDIO_PERFORMANCE_MODE_NONE}.
1321  *
1322  * You may not get the mode you requested.
1323  * You can call AAudioStream_getPerformanceMode()
1324  * to find out the final mode for the stream.
1325  *
1326  * Available since API level 26.
1327  *
1328  * @param builder reference provided by AAudio_createStreamBuilder()
1329  * @param mode the desired performance mode, eg. {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}
1330  */
1331 AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* _Nonnull builder,
1332         aaudio_performance_mode_t mode) __INTRODUCED_IN(26);
1333 
1334 /**
1335  * Set the intended use case for the output stream.
1336  *
1337  * The AAudio system will use this information to optimize the
1338  * behavior of the stream.
1339  * This could, for example, affect how volume and focus is handled for the stream.
1340  *
1341  * The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}.
1342  *
1343  * If you set Usage then you will need to associate the volume keys with the resulting stream.
1344  * Otherwise the volume keys may not work correctly.
1345  * This is done in Java with the following code block.
1346  *
1347  * <pre><code>if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
1348  *     AudioAttributes attributes = new AudioAttributes.Builder().setUsage(usage)
1349  *             .setContentType(contentType).build();
1350  *     setVolumeControlStream(attributes.getVolumeControlStream());
1351  * }
1352  * </code></pre>
1353  *
1354  * Available since API level 28.
1355  *
1356  * @param builder reference provided by AAudio_createStreamBuilder()
1357  * @param usage the desired usage, eg. {@link #AAUDIO_USAGE_GAME}
1358  */
1359 AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* _Nonnull builder,
1360         aaudio_usage_t usage) __INTRODUCED_IN(28);
1361 
1362 /**
1363  * Set the type of audio data that the output stream will carry.
1364  *
1365  * The AAudio system will use this information to optimize the
1366  * behavior of the stream.
1367  * This could, for example, affect whether a stream is paused when a notification occurs.
1368  *
1369  * The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}.
1370  *
1371  * If you set ContentType then you will need to associate the volume keys with the resulting stream.
1372  * Otherwise the volume keys may not work correctly.
1373  * This is done in Java with the following code block.
1374  *
1375  * <pre><code>if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
1376  *     AudioAttributes attributes = new AudioAttributes.Builder().setUsage(usage)
1377  *             .setContentType(contentType).build();
1378  *     setVolumeControlStream(attributes.getVolumeControlStream());
1379  * }
1380  * </code></pre>
1381  *
1382  * Available since API level 28.
1383  *
1384  * @param builder reference provided by AAudio_createStreamBuilder()
1385  * @param contentType the type of audio data, eg. {@link #AAUDIO_CONTENT_TYPE_SPEECH}
1386  */
1387 AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* _Nonnull builder,
1388         aaudio_content_type_t contentType) __INTRODUCED_IN(28);
1389 
1390 /**
1391  * Sets the behavior affecting whether spatialization will be used.
1392  *
1393  * The AAudio system will use this information to select whether the stream will go
1394  * through a spatializer effect or not when the effect is supported and enabled.
1395  *
1396  * Available since API level 32.
1397  *
1398  * @param builder reference provided by AAudio_createStreamBuilder()
1399  * @param spatializationBehavior the desired behavior with regards to spatialization, eg.
1400  *     {@link #AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO}
1401  */
1402 AAUDIO_API void AAudioStreamBuilder_setSpatializationBehavior(
1403         AAudioStreamBuilder* _Nonnull builder,
1404         aaudio_spatialization_behavior_t spatializationBehavior) __INTRODUCED_IN(32);
1405 
1406 /**
1407  * Specifies whether the audio data of this output stream has already been processed for
1408  * spatialization.
1409  *
1410  * If the stream has been processed for spatialization, setting this to true will prevent
1411  * issues such as double-processing on platforms that will spatialize audio data.
1412  *
1413  * Available since API level 32.
1414  *
1415  * @param builder reference provided by AAudio_createStreamBuilder()
1416  * @param isSpatialized true if the content is already processed for binaural or transaural spatial
1417  *     rendering, false otherwise.
1418  */
1419 AAUDIO_API void AAudioStreamBuilder_setIsContentSpatialized(AAudioStreamBuilder* _Nonnull builder,
1420         bool isSpatialized) __INTRODUCED_IN(32);
1421 
1422 /**
1423  * Set the input (capture) preset for the stream.
1424  *
1425  * The AAudio system will use this information to optimize the
1426  * behavior of the stream.
1427  * This could, for example, affect which microphones are used and how the
1428  * recorded data is processed.
1429  *
1430  * The default, if you do not call this function, is {@link #AAUDIO_INPUT_PRESET_VOICE_RECOGNITION}.
1431  * That is because VOICE_RECOGNITION is the preset with the lowest latency
1432  * on many platforms.
1433  *
1434  * Available since API level 28.
1435  *
1436  * @param builder reference provided by AAudio_createStreamBuilder()
1437  * @param inputPreset the desired configuration for recording
1438  */
1439 AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* _Nonnull builder,
1440         aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28);
1441 
1442 /**
1443  * Specify whether this stream audio may or may not be captured by other apps or the system.
1444  *
1445  * The default is {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}.
1446  *
1447  * Note that an application can also set its global policy, in which case the most restrictive
1448  * policy is always applied. See
1449  * <a href="/reference/android/media/AudioManager#setAllowedCapturePolicy(int)">
1450  * setAllowedCapturePolicy(int)</a>
1451  *
1452  * Available since API level 29.
1453  *
1454  * @param builder reference provided by AAudio_createStreamBuilder()
1455  * @param capturePolicy the desired level of opt-out from being captured.
1456  */
1457 AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* _Nonnull builder,
1458         aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29);
1459 
1460 /** Set the requested session ID.
1461  *
1462  * The session ID can be used to associate a stream with effects processors.
1463  * The effects are controlled using the Android AudioEffect Java API.
1464  *
1465  * The default, if you do not call this function, is {@link #AAUDIO_SESSION_ID_NONE}.
1466  *
1467  * If set to {@link #AAUDIO_SESSION_ID_ALLOCATE} then a session ID will be allocated
1468  * when the stream is opened.
1469  *
1470  * The allocated session ID can be obtained by calling AAudioStream_getSessionId()
1471  * and then used with this function when opening another stream.
1472  * This allows effects to be shared between streams.
1473  *
1474  * Session IDs from AAudio can be used with the Android Java APIs and vice versa.
1475  * So a session ID from an AAudio stream can be passed to Java
1476  * and effects applied using the Java AudioEffect API.
1477  *
1478  * Note that allocating or setting a session ID may result in a stream with higher latency.
1479  *
1480  * Allocated session IDs will always be positive and nonzero.
1481  *
1482  * Available since API level 28.
1483  *
1484  * @param builder reference provided by AAudio_createStreamBuilder()
1485  * @param sessionId an allocated sessionID or {@link #AAUDIO_SESSION_ID_ALLOCATE}
1486  */
1487 AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* _Nonnull builder,
1488         aaudio_session_id_t sessionId) __INTRODUCED_IN(28);
1489 
1490 
1491 /** Indicates whether this input stream must be marked as privacy sensitive or not.
1492  *
1493  * When true, this input stream is privacy sensitive and any concurrent capture
1494  * is not permitted.
1495  *
1496  * This is off (false) by default except when the input preset is {@link #AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION}
1497  * or {@link #AAUDIO_INPUT_PRESET_CAMCORDER}.
1498  *
1499  * Always takes precedence over default from input preset when set explicitly.
1500  *
1501  * Only relevant if the stream direction is {@link #AAUDIO_DIRECTION_INPUT}.
1502  *
1503  * Added in API level 30.
1504  *
1505  * @param builder reference provided by AAudio_createStreamBuilder()
1506  * @param privacySensitive true if capture from this stream must be marked as privacy sensitive,
1507  * false otherwise.
1508  */
1509 AAUDIO_API void AAudioStreamBuilder_setPrivacySensitive(AAudioStreamBuilder* _Nonnull builder,
1510         bool privacySensitive) __INTRODUCED_IN(30);
1511 
1512 /**
1513  * Return one of these values from the data callback function.
1514  */
1515 enum {
1516 
1517     /**
1518      * Continue calling the callback.
1519      */
1520     AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
1521 
1522     /**
1523      * Stop calling the callback.
1524      *
1525      * The application will still need to call AAudioStream_requestPause()
1526      * or AAudioStream_requestStop().
1527      */
1528     AAUDIO_CALLBACK_RESULT_STOP,
1529 
1530 };
1531 typedef int32_t aaudio_data_callback_result_t;
1532 
1533 /**
1534  * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
1535  *
1536  * For an output stream, this function should render and write numFrames of data
1537  * in the streams current data format to the audioData buffer.
1538  *
1539  * For an input stream, this function should read and process numFrames of data
1540  * from the audioData buffer. The data in the audioData buffer must not be modified
1541  * directly. Instead, it should be copied to another buffer before doing any modification.
1542  * In many cases, writing to the audioData buffer of an input stream will result in a
1543  * native exception.
1544  *
1545  * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or
1546  * AAudioStream_write() on the stream that is making the callback.
1547  *
1548  * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback()
1549  * is called.
1550  *
1551  * Also note that this callback function should be considered a "real-time" function.
1552  * It must not do anything that could cause an unbounded delay because that can cause the
1553  * audio to glitch or pop.
1554  *
1555  * These are things the function should NOT do:
1556  * <ul>
1557  * <li>allocate memory using, for example, malloc() or new</li>
1558  * <li>any file operations such as opening, closing, reading or writing</li>
1559  * <li>any network operations such as streaming</li>
1560  * <li>use any mutexes or other synchronization primitives</li>
1561  * <li>sleep</li>
1562  * <li>stop or close the stream</li>
1563  * <li>AAudioStream_read()</li>
1564  * <li>AAudioStream_write()</li>
1565  * </ul>
1566  *
1567  * The following are OK to call from the data callback:
1568  * <ul>
1569  * <li>AAudioStream_get*()</li>
1570  * <li>AAudio_convertResultToText()</li>
1571  * </ul>
1572  *
1573  * If you need to move data, eg. MIDI commands, in or out of the callback function then
1574  * we recommend the use of non-blocking techniques such as an atomic FIFO.
1575  *
1576  * @param stream reference provided by AAudioStreamBuilder_openStream()
1577  * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
1578  * @param audioData a pointer to the audio data
1579  * @param numFrames the number of frames to be processed, which can vary
1580  * @return AAUDIO_CALLBACK_RESULT_*
1581  */
1582 typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
1583         AAudioStream* _Nonnull stream,
1584         void* _Nullable userData,
1585         void* _Nonnull audioData,
1586         int32_t numFrames);
1587 
1588 /**
1589  * Request that AAudio call this functions when the stream is running.
1590  *
1591  * Note that when using this callback, the audio data will be passed in or out
1592  * of the function as an argument.
1593  * So you cannot call AAudioStream_write() or AAudioStream_read()
1594  * on the same stream that has an active data callback.
1595  *
1596  * The callback function will start being called after AAudioStream_requestStart()
1597  * is called.
1598  * It will stop being called after AAudioStream_requestPause() or
1599  * AAudioStream_requestStop() is called.
1600  *
1601  * This callback function will be called on a real-time thread owned by AAudio.
1602  * The low latency streams may have callback threads with higher priority than normal streams.
1603  * See {@link #AAudioStream_dataCallback} for more information.
1604  *
1605  * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
1606  *
1607  * Available since API level 26.
1608  *
1609  * @param builder reference provided by AAudio_createStreamBuilder()
1610  * @param callback pointer to a function that will process audio data.
1611  * @param userData pointer to an application data structure that will be passed
1612  *          to the callback functions.
1613  */
1614 AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* _Nonnull builder,
1615         AAudioStream_dataCallback _Nullable callback, void* _Nullable userData)
1616         __INTRODUCED_IN(26);
1617 
1618 /**
1619  * Set the requested data callback buffer size in frames.
1620  * See {@link #AAudioStream_dataCallback}.
1621  *
1622  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
1623  *
1624  * For the lowest possible latency, do not call this function. AAudio will then
1625  * call the dataProc callback function with whatever size is optimal.
1626  * That size may vary from one callback to another.
1627  *
1628  * Only use this function if the application requires a specific number of frames for processing.
1629  * The application might, for example, be using an FFT that requires
1630  * a specific power-of-two sized buffer.
1631  *
1632  * AAudio may need to add additional buffering in order to adapt between the internal
1633  * buffer size and the requested buffer size.
1634  *
1635  * If you do call this function then the requested size should be less than
1636  * half the buffer capacity, to allow double buffering.
1637  *
1638  * Available since API level 26.
1639  *
1640  * @param builder reference provided by AAudio_createStreamBuilder()
1641  * @param numFrames the desired buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
1642  */
1643 AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* _Nonnull builder,
1644         int32_t numFrames) __INTRODUCED_IN(26);
1645 
1646 /**
1647  * Prototype for the callback function that is passed to
1648  * AAudioStreamBuilder_setErrorCallback().
1649  *
1650  * The following may NOT be called from the error callback:
1651  * <ul>
1652  * <li>AAudioStream_requestStop()</li>
1653  * <li>AAudioStream_requestPause()</li>
1654  * <li>AAudioStream_close()</li>
1655  * <li>AAudioStream_waitForStateChange()</li>
1656  * <li>AAudioStream_read()</li>
1657  * <li>AAudioStream_write()</li>
1658  * </ul>
1659  *
1660  * The following are OK to call from the error callback:
1661  * <ul>
1662  * <li>AAudioStream_get*()</li>
1663  * <li>AAudio_convertResultToText()</li>
1664  * </ul>
1665  *
1666  * @param stream reference provided by AAudioStreamBuilder_openStream()
1667  * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
1668  * @param error an AAUDIO_ERROR_* value.
1669  */
1670 typedef void (*AAudioStream_errorCallback)(
1671         AAudioStream* _Nonnull stream,
1672         void* _Nullable userData,
1673         aaudio_result_t error);
1674 
1675 /**
1676  * Request that AAudio call this function if any error occurs or the stream is disconnected.
1677  *
1678  * It will be called, for example, if a headset or a USB device is unplugged causing the stream's
1679  * device to be unavailable or "disconnected".
1680  * Another possible cause of error would be a timeout or an unanticipated internal error.
1681  *
1682  * In response, this function should signal or create another thread to stop
1683  * and close this stream. The other thread could then reopen a stream on another device.
1684  * Do not stop or close the stream, or reopen the new stream, directly from this callback.
1685  *
1686  * This callback will not be called because of actions by the application, such as stopping
1687  * or closing a stream.
1688  *
1689  * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
1690  *
1691  * Available since API level 26.
1692  *
1693  * @param builder reference provided by AAudio_createStreamBuilder()
1694  * @param callback pointer to a function that will be called if an error occurs.
1695  * @param userData pointer to an application data structure that will be passed
1696  *          to the callback functions.
1697  */
1698 AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* _Nonnull builder,
1699         AAudioStream_errorCallback _Nullable callback, void* _Nullable userData)
1700         __INTRODUCED_IN(26);
1701 
1702 /**
1703  * Prototype for the callback function that is passed to
1704  * AAudioStreamBuilder_setPresentationEndCallback().
1705  *
1706  * This will be called when all the buffers of an offloaded stream that were queued in the audio
1707  * system (e.g. the combination of the Android audio framework and the device's audio hardware)
1708  * have been played after AudioStream_requestStop() has been called.
1709  *
1710  * @param stream reference provided by AAudioStreamBuilder_openStream(), which must be an
1711  *               output stream as the offloaded mode is only supported for output stream
1712  * @param userData the same address that was passed to
1713  *                 AAudioStreamBuilder_setPresentationEndCallback().
1714  */
1715 typedef void (*AAudioStream_presentationEndCallback)(AAudioStream* _Nonnull stream,
1716                                                      void* _Null_unspecified userData);
1717 
1718 /**
1719  * Request that AAudio call this function when all the buffers of an offloaded stream that were
1720  * queued in the audio system (e.g. the combination of the Android audio framework and the device's
1721  * audio hardware) have been played.
1722  *
1723  * The presentation end callback must be used together with the data callback.
1724  * The presentation end callback won't be called if the stream is closed before all the data
1725  * is played.
1726  *
1727  * The callback function will be called from the same thread as the data callback thread,
1728  * which is a real-time thread owned by audio framework.
1729  * The callback function will not be called after AAudioStream_close() is called.
1730  *
1731  * Available since API level 36.
1732  *
1733  * @param builder reference provided by AAudio_createStreamBuilder()
1734  * @param callback pointer to a function that will be called when all the buffers of an offloaded
1735  *                 stream that were queued have been played.
1736  * @param userData pointer to an application data structure that will be passed
1737  *                 to the callback functions.
1738  */
1739 AAUDIO_API void AAudioStreamBuilder_setPresentationEndCallback(
1740         AAudioStreamBuilder* _Nonnull builder,
1741         AAudioStream_presentationEndCallback _Nonnull callback,
1742         void* _Nullable userData) __INTRODUCED_IN(36);
1743 
1744 /**
1745  * Open a stream based on the options in the StreamBuilder.
1746  *
1747  * AAudioStream_close() must be called when finished with the stream to recover
1748  * the memory and to free the associated resources.
1749  *
1750  * Available since API level 26.
1751  *
1752  * @param builder reference provided by AAudio_createStreamBuilder()
1753  * @param stream pointer to a variable to receive the new stream reference
1754  * @return {@link #AAUDIO_OK} or a negative error.
1755  */
1756 AAUDIO_API aaudio_result_t  AAudioStreamBuilder_openStream(AAudioStreamBuilder* _Nonnull builder,
1757         AAudioStream* _Nullable* _Nonnull stream) __INTRODUCED_IN(26);
1758 
1759 /**
1760  * Delete the resources associated with the StreamBuilder.
1761  *
1762  * Available since API level 26.
1763  *
1764  * @param builder reference provided by AAudio_createStreamBuilder()
1765  * @return {@link #AAUDIO_OK} or a negative error.
1766  */
1767 AAUDIO_API aaudio_result_t  AAudioStreamBuilder_delete(AAudioStreamBuilder* _Nonnull builder)
1768     __INTRODUCED_IN(26);
1769 
1770 /**
1771  * Set audio channel mask for the stream.
1772  *
1773  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
1774  * If both channel mask and count are not set, then stereo will then be chosen when the
1775  * stream is opened.
1776  * After opening a stream with an unspecified value, the application must query for the
1777  * actual value, which may vary by device.
1778  *
1779  * If an exact value is specified then an opened stream will use that value.
1780  * If a stream cannot be opened with the specified value then the open will fail.
1781  *
1782  * As the corresponding channel count of provided channel mask here may be different
1783  * from the channel count used in {@link AAudioStreamBuilder_setChannelCount} or
1784  * {@link AAudioStreamBuilder_setSamplesPerFrame}, the last called function will be
1785  * respected if this function and {@link AAudioStreamBuilder_setChannelCount} or
1786  * {@link AAudioStreamBuilder_setSamplesPerFrame} are called.
1787  *
1788  * Available since API level 32.
1789  *
1790  * @param builder reference provided by AAudio_createStreamBuilder()
1791  * @param channelMask Audio channel mask desired.
1792  */
1793 AAUDIO_API void AAudioStreamBuilder_setChannelMask(AAudioStreamBuilder* _Nonnull builder,
1794         aaudio_channel_mask_t channelMask) __INTRODUCED_IN(32);
1795 
1796 // ============================================================
1797 // Stream Control
1798 // ============================================================
1799 
1800 /**
1801  * Free the audio resources associated with a stream created by
1802  * AAudioStreamBuilder_openStream().
1803  * AAudioStream_close() should be called at some point after calling
1804  * this function.
1805  *
1806  * After this call, the stream will be in {@link #AAUDIO_STREAM_STATE_CLOSING}
1807  *
1808  * This function is useful if you want to release the audio resources immediately,
1809  * but still allow queries to the stream to occur from other threads. This often
1810  * happens if you are monitoring stream progress from a UI thread.
1811  *
1812  * NOTE: This function is only fully implemented for MMAP streams,
1813  * which are low latency streams supported by some devices.
1814  * On other "Legacy" streams some audio resources will still be in use
1815  * and some callbacks may still be in process after this call.
1816  *
1817  * Available since API level 30.
1818  *
1819  * @param stream reference provided by AAudioStreamBuilder_openStream()
1820  * @return {@link #AAUDIO_OK} or a negative error.
1821  */
1822 AAUDIO_API aaudio_result_t  AAudioStream_release(AAudioStream* _Nonnull stream)
1823         __INTRODUCED_IN(30);
1824 
1825 /**
1826  * Delete the internal data structures associated with the stream created
1827  * by AAudioStreamBuilder_openStream().
1828  *
1829  * If AAudioStream_release() has not been called then it will be called automatically.
1830  *
1831  * Available since API level 26.
1832  *
1833  * @param stream reference provided by AAudioStreamBuilder_openStream()
1834  * @return {@link #AAUDIO_OK} or a negative error.
1835  */
1836 AAUDIO_API aaudio_result_t  AAudioStream_close(AAudioStream* _Nonnull stream) __INTRODUCED_IN(26);
1837 
1838 /**
1839  * Asynchronously request to start playing the stream. For output streams, one should
1840  * write to the stream to fill the buffer before starting.
1841  * Otherwise it will underflow.
1842  * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STARTING} or
1843  * {@link #AAUDIO_STREAM_STATE_STARTED}.
1844  *
1845  * Available since API level 26.
1846  *
1847  * @param stream reference provided by AAudioStreamBuilder_openStream()
1848  * @return {@link #AAUDIO_OK} or a negative error.
1849  */
1850 AAUDIO_API aaudio_result_t  AAudioStream_requestStart(AAudioStream* _Nonnull stream)
1851         __INTRODUCED_IN(26);
1852 
1853 /**
1854  * Asynchronous request for the stream to pause.
1855  * Pausing a stream will freeze the data flow but not flush any buffers.
1856  * Use AAudioStream_requestStart() to resume playback after a pause.
1857  * After this call the state will be in {@link #AAUDIO_STREAM_STATE_PAUSING} or
1858  * {@link #AAUDIO_STREAM_STATE_PAUSED}.
1859  *
1860  * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
1861  * For input streams use AAudioStream_requestStop().
1862  *
1863  * Available since API level 26.
1864  *
1865  * @param stream reference provided by AAudioStreamBuilder_openStream()
1866  * @return {@link #AAUDIO_OK} or a negative error.
1867  */
1868 AAUDIO_API aaudio_result_t  AAudioStream_requestPause(AAudioStream* _Nonnull stream)
1869         __INTRODUCED_IN(26);
1870 
1871 /**
1872  * Asynchronous request for the stream to flush.
1873  * Flushing will discard any pending data.
1874  * This call only works if the stream is OPEN, PAUSED, STOPPED, or FLUSHED.
1875  * Calling this function when in other states,
1876  * or calling from an AAudio callback function,
1877  * will have no effect and an error will be returned.
1878  * Frame counters are not reset by a flush. They may be advanced.
1879  * After this call the state will be in {@link #AAUDIO_STREAM_STATE_FLUSHING} or
1880  * {@link #AAUDIO_STREAM_STATE_FLUSHED}.
1881  *
1882  * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
1883  *
1884  * Available since API level 26.
1885  *
1886  * @param stream reference provided by AAudioStreamBuilder_openStream()
1887  * @return {@link #AAUDIO_OK} or a negative error.
1888  */
1889 AAUDIO_API aaudio_result_t  AAudioStream_requestFlush(AAudioStream* _Nonnull stream)
1890         __INTRODUCED_IN(26);
1891 
1892 /**
1893  * Asynchronous request for the stream to stop.
1894  * The stream will stop after all of the data currently buffered has been played.
1895  * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STOPPING} or
1896  * {@link #AAUDIO_STREAM_STATE_STOPPED}.
1897  *
1898  * Available since API level 26.
1899  *
1900  * @param stream reference provided by AAudioStreamBuilder_openStream()
1901  * @return {@link #AAUDIO_OK} or a negative error.
1902  */
1903 AAUDIO_API aaudio_result_t  AAudioStream_requestStop(AAudioStream* _Nonnull stream)
1904         __INTRODUCED_IN(26);
1905 
1906 /**
1907  * Query the current state of the client, eg. {@link #AAUDIO_STREAM_STATE_PAUSING}
1908  *
1909  * This function will immediately return the state without updating the state.
1910  * If you want to update the client state based on the server state then
1911  * call AAudioStream_waitForStateChange() with currentState
1912  * set to {@link #AAUDIO_STREAM_STATE_UNKNOWN} and a zero timeout.
1913  *
1914  * Available since API level 26.
1915  *
1916  * @param stream reference provided by AAudioStreamBuilder_openStream()
1917  */
1918 AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* _Nonnull stream)
1919         __INTRODUCED_IN(26);
1920 
1921 /**
1922  * Wait until the current state no longer matches the input state.
1923  *
1924  * This will update the current client state.
1925  *
1926  * <pre><code>
1927  * aaudio_result_t result = AAUDIO_OK;
1928  * aaudio_stream_state_t currentState = AAudioStream_getState(stream);
1929  * aaudio_stream_state_t inputState = currentState;
1930  * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) {
1931  *     result = AAudioStream_waitForStateChange(
1932  *                                   stream, inputState, &currentState, MY_TIMEOUT_NANOS);
1933  *     inputState = currentState;
1934  * }
1935  * </code></pre>
1936  *
1937  * Available since API level 26.
1938  *
1939  * @param stream A reference provided by AAudioStreamBuilder_openStream()
1940  * @param inputState The state we want to avoid.
1941  * @param nextState Pointer to a variable that will be set to the new state.
1942  * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1943  * @return {@link #AAUDIO_OK} or a negative error.
1944  */
1945 AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* _Nonnull stream,
1946         aaudio_stream_state_t inputState, aaudio_stream_state_t* _Nullable nextState,
1947         int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
1948 
1949 // ============================================================
1950 // Stream I/O
1951 // ============================================================
1952 
1953 /**
1954  * Read data from the stream.
1955  *
1956  * The call will wait until the read is complete or until it runs out of time.
1957  * If timeoutNanos is zero then this call will not wait.
1958  *
1959  * Note that timeoutNanoseconds is a relative duration in wall clock time.
1960  * Time will not stop if the thread is asleep.
1961  * So it will be implemented using CLOCK_BOOTTIME.
1962  *
1963  * This call is "strong non-blocking" unless it has to wait for data.
1964  *
1965  * If the call times out then zero or a partial frame count will be returned.
1966  *
1967  * Available since API level 26.
1968  *
1969  * @param stream A stream created using AAudioStreamBuilder_openStream().
1970  * @param buffer The address of the first sample.
1971  * @param numFrames Number of frames to read. Only complete frames will be written.
1972  * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1973  * @return The number of frames actually read or a negative error.
1974  */
1975 AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* _Nonnull stream,
1976         void* _Nonnull buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
1977 
1978 /**
1979  * Write data to the stream.
1980  *
1981  * The call will wait until the write is complete or until it runs out of time.
1982  * If timeoutNanos is zero then this call will not wait.
1983  *
1984  * Note that timeoutNanoseconds is a relative duration in wall clock time.
1985  * Time will not stop if the thread is asleep.
1986  * So it will be implemented using CLOCK_BOOTTIME.
1987  *
1988  * This call is "strong non-blocking" unless it has to wait for room in the buffer.
1989  *
1990  * If the call times out then zero or a partial frame count will be returned.
1991  *
1992  * Available since API level 26.
1993  *
1994  * @param stream A stream created using AAudioStreamBuilder_openStream().
1995  * @param buffer The address of the first sample.
1996  * @param numFrames Number of frames to write. Only complete frames will be written.
1997  * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1998  * @return The number of frames actually written or a negative error.
1999  */
2000 AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* _Nonnull stream,
2001         const void* _Nonnull buffer, int32_t numFrames, int64_t timeoutNanoseconds)
2002         __INTRODUCED_IN(26);
2003 
2004 // ============================================================
2005 // Stream - queries
2006 // ============================================================
2007 
2008 /**
2009  * This can be used to adjust the latency of the buffer by changing
2010  * the threshold where blocking will occur.
2011  * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
2012  * at run-time for each device.
2013  *
2014  * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
2015  *
2016  * Note that you will probably not get the exact size you request.
2017  * You can check the return value or call AAudioStream_getBufferSizeInFrames()
2018  * to see what the actual final size is.
2019  *
2020  * Available since API level 26.
2021  *
2022  * @param stream reference provided by AAudioStreamBuilder_openStream()
2023  * @param numFrames requested number of frames that can be filled without blocking
2024  * @return actual buffer size in frames or a negative error
2025  */
2026 AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* _Nonnull stream,
2027         int32_t numFrames) __INTRODUCED_IN(26);
2028 
2029 /**
2030  * Query the maximum number of frames that can be filled without blocking.
2031  *
2032  * Available since API level 26.
2033  *
2034  * @param stream reference provided by AAudioStreamBuilder_openStream()
2035  * @return buffer size in frames.
2036  */
2037 AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* _Nonnull stream)
2038         __INTRODUCED_IN(26);
2039 
2040 /**
2041  * Query the number of frames that the application should read or write at
2042  * one time for optimal performance. It is OK if an application writes
2043  * a different number of frames. But the buffer size may need to be larger
2044  * in order to avoid underruns or overruns.
2045  *
2046  * Note that this may or may not match the actual device burst size.
2047  * For some endpoints, the burst size can vary dynamically.
2048  * But these tend to be devices with high latency.
2049  *
2050  * Available since API level 26.
2051  *
2052  * @param stream reference provided by AAudioStreamBuilder_openStream()
2053  * @return burst size
2054  */
2055 AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* _Nonnull stream)
2056         __INTRODUCED_IN(26);
2057 
2058 /**
2059  * Query maximum buffer capacity in frames.
2060  *
2061  * Available since API level 26.
2062  *
2063  * @param stream reference provided by AAudioStreamBuilder_openStream()
2064  * @return  buffer capacity in frames
2065  */
2066 AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* _Nonnull stream)
2067         __INTRODUCED_IN(26);
2068 
2069 /**
2070  * Query the size of the buffer that will be passed to the dataProc callback
2071  * in the numFrames parameter.
2072  *
2073  * This call can be used if the application needs to know the value of numFrames before
2074  * the stream is started. This is not normally necessary.
2075  *
2076  * If a specific size was requested by calling
2077  * AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size.
2078  *
2079  * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will
2080  * return the size chosen by AAudio, or {@link #AAUDIO_UNSPECIFIED}.
2081  *
2082  * {@link #AAUDIO_UNSPECIFIED} indicates that the callback buffer size for this stream
2083  * may vary from one dataProc callback to the next.
2084  *
2085  * Available since API level 26.
2086  *
2087  * @param stream reference provided by AAudioStreamBuilder_openStream()
2088  * @return callback buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
2089  */
2090 AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* _Nonnull stream)
2091         __INTRODUCED_IN(26);
2092 
2093 /**
2094  * An XRun is an Underrun or an Overrun.
2095  * During playing, an underrun will occur if the stream is not written in time
2096  * and the system runs out of valid data.
2097  * During recording, an overrun will occur if the stream is not read in time
2098  * and there is no place to put the incoming data so it is discarded.
2099  *
2100  * An underrun or overrun can cause an audible "pop" or "glitch".
2101  *
2102  * Note that some INPUT devices may not support this function.
2103  * In that case a 0 will always be returned.
2104  *
2105  * Available since API level 26.
2106  *
2107  * @param stream reference provided by AAudioStreamBuilder_openStream()
2108  * @return the underrun or overrun count
2109  */
2110 AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* _Nonnull stream) __INTRODUCED_IN(26);
2111 
2112 /**
2113  * Available since API level 26.
2114  *
2115  * @param stream reference provided by AAudioStreamBuilder_openStream()
2116  * @return actual sample rate of the stream
2117  */
2118 AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* _Nonnull stream) __INTRODUCED_IN(26);
2119 
2120 /**
2121  * There may be sample rate conversions in the Audio framework.
2122  * The sample rate set in the stream builder may not be actual sample rate used in the hardware.
2123  *
2124  * This returns the sample rate used by the hardware in Hertz.
2125  *
2126  * If AAudioStreamBuilder_openStream() returned AAUDIO_OK, the result should always be valid.
2127  *
2128  * Available since API level 34.
2129  *
2130  * @param stream reference provided by AAudioStreamBuilder_openStream()
2131  * @return actual sample rate of the underlying hardware
2132  */
2133 AAUDIO_API int32_t AAudioStream_getHardwareSampleRate(AAudioStream* _Nonnull stream)
2134         __INTRODUCED_IN(__ANDROID_API_U__);
2135 
2136 /**
2137  * A stream has one or more channels of data.
2138  * A frame will contain one sample for each channel.
2139  *
2140  * Available since API level 26.
2141  *
2142  * @param stream reference provided by AAudioStreamBuilder_openStream()
2143  * @return actual number of channels of the stream
2144  */
2145 AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* _Nonnull stream) __INTRODUCED_IN(26);
2146 
2147 /**
2148  * There may be channel conversions in the Audio framework.
2149  * The channel count or channel mask set in the stream builder may not be actual number of
2150  * channels used in the hardware.
2151  *
2152  * This returns the channel count used by the hardware.
2153  *
2154  * If AAudioStreamBuilder_openStream() returned AAUDIO_OK, the result should always be valid.
2155  *
2156  * Available since API level 34.
2157  *
2158  * @param stream reference provided by AAudioStreamBuilder_openStream()
2159  * @return actual number of channels of the underlying hardware
2160  */
2161 AAUDIO_API int32_t AAudioStream_getHardwareChannelCount(AAudioStream* _Nonnull stream)
2162         __INTRODUCED_IN(__ANDROID_API_U__);
2163 
2164 /**
2165  * Identical to AAudioStream_getChannelCount().
2166  *
2167  * Available since API level 26.
2168  *
2169  * @param stream reference provided by AAudioStreamBuilder_openStream()
2170  * @return actual number of samples frame
2171  */
2172 AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* _Nonnull stream)
2173         __INTRODUCED_IN(26);
2174 
2175 /**
2176  * Available since API level 26.
2177  *
2178  * @param stream reference provided by AAudioStreamBuilder_openStream()
2179  * @return actual device id. If there are multiple device ids used,
2180  *         this will return the first device id from AAudioStream_getDeviceIds().
2181  */
2182 AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* _Nonnull stream) __INTRODUCED_IN(26);
2183 
2184 /**
2185  * Call this function after AAudioStreamBuilder_openStream().
2186  * An array of size 16 should generally be large enough to fit all device identifiers.
2187  *
2188  * Available since API level 36.
2189  *
2190  * @param stream reference provided by AAudioStreamBuilder_openStream().
2191  * @param ids reference to an array of ids.
2192  * @params numIds size allocated to the array of ids.
2193  *         The input should be the size of the ids array.
2194  *         The output will be the actual number of device ids.
2195  * @return {@link #AAUDIO_OK} or an error code.
2196  *         If numIds is null, return {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT}.
2197  *         If numIds is smaller than the number of device ids, return
2198  *         {@link #AAUDIO_ERROR_OUT_OF_RANGE}. The value of numIds will still be updated.
2199  *         Otherwise, if ids is null, return {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT}.
2200  */
2201 AAUDIO_API aaudio_result_t AAudioStream_getDeviceIds(AAudioStream* _Nonnull stream,
2202         int32_t* _Nullable ids, int32_t* _Nullable numIds) __INTRODUCED_IN(36);
2203 
2204 /**
2205  * Available since API level 26.
2206  *
2207  * @param stream reference provided by AAudioStreamBuilder_openStream()
2208  * @return actual data format of the stream
2209  */
2210 AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* _Nonnull stream)
2211         __INTRODUCED_IN(26);
2212 
2213 /**
2214  * There may be data format conversions in the Audio framework.
2215  * The data format set in the stream builder may not be actual format used in the hardware.
2216  *
2217  * This returns the audio format used by the hardware.
2218  *
2219  * If AAudioStreamBuilder_openStream() returned AAUDIO_OK, this should always return an
2220  * aaudio_format_t.
2221  *
2222  * AUDIO_FORMAT_PCM_8_24_BIT is currently not supported in AAudio, but the hardware may use it.
2223  * If AUDIO_FORMAT_PCM_8_24_BIT is used by the hardware, return AAUDIO_FORMAT_PCM_I24_PACKED.
2224  *
2225  * If any other format used by the hardware is not supported by AAudio, this will return
2226  * AAUDIO_FORMAT_INVALID.
2227  *
2228  * Available since API level 34.
2229  *
2230  * @param stream reference provided by AAudioStreamBuilder_openStream()
2231  * @return actual data format of the underlying hardware.
2232  */
2233 AAUDIO_API aaudio_format_t AAudioStream_getHardwareFormat(AAudioStream* _Nonnull stream)
2234         __INTRODUCED_IN(__ANDROID_API_U__);
2235 
2236 /**
2237  * Provide actual sharing mode.
2238  *
2239  * Available since API level 26.
2240  *
2241  * @param stream reference provided by AAudioStreamBuilder_openStream()
2242  * @return  actual sharing mode
2243  */
2244 AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* _Nonnull stream)
2245         __INTRODUCED_IN(26);
2246 
2247 /**
2248  * Get the performance mode used by the stream.
2249  *
2250  * Available since API level 26.
2251  *
2252  * @param stream reference provided by AAudioStreamBuilder_openStream()
2253  */
2254 AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* _Nonnull stream)
2255         __INTRODUCED_IN(26);
2256 
2257 /**
2258  * Available since API level 26.
2259  *
2260  * @param stream reference provided by AAudioStreamBuilder_openStream()
2261  * @return direction
2262  */
2263 AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* _Nonnull stream)
2264         __INTRODUCED_IN(26);
2265 
2266 /**
2267  * Passes back the number of frames that have been written since the stream was created.
2268  * For an output stream, this will be advanced by the application calling write()
2269  * or by a data callback.
2270  * For an input stream, this will be advanced by the endpoint.
2271  *
2272  * The frame position is monotonically increasing.
2273  *
2274  * Available since API level 26.
2275  *
2276  * @param stream reference provided by AAudioStreamBuilder_openStream()
2277  * @return frames written
2278  */
2279 AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* _Nonnull stream)
2280         __INTRODUCED_IN(26);
2281 
2282 /**
2283  * Passes back the number of frames that have been read since the stream was created.
2284  * For an output stream, this will be advanced by the endpoint.
2285  * For an input stream, this will be advanced by the application calling read()
2286  * or by a data callback.
2287  *
2288  * The frame position is monotonically increasing.
2289  *
2290  * Available since API level 26.
2291  *
2292  * @param stream reference provided by AAudioStreamBuilder_openStream()
2293  * @return frames read
2294  */
2295 AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* _Nonnull stream) __INTRODUCED_IN(26);
2296 
2297 /**
2298  * Passes back the session ID associated with this stream.
2299  *
2300  * The session ID can be used to associate a stream with effects processors.
2301  * The effects are controlled using the Android AudioEffect Java API.
2302  *
2303  * If AAudioStreamBuilder_setSessionId() was
2304  * called with {@link #AAUDIO_SESSION_ID_ALLOCATE}
2305  * then a new session ID should be allocated once when the stream is opened.
2306  *
2307  * If AAudioStreamBuilder_setSessionId() was called with a previously allocated
2308  * session ID then that value should be returned.
2309  *
2310  * If AAudioStreamBuilder_setSessionId() was not called then this function should
2311  * return {@link #AAUDIO_SESSION_ID_NONE}.
2312  *
2313  * The sessionID for a stream should not change once the stream has been opened.
2314  *
2315  * Available since API level 28.
2316  *
2317  * @param stream reference provided by AAudioStreamBuilder_openStream()
2318  * @return session ID or {@link #AAUDIO_SESSION_ID_NONE}
2319  */
2320 AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* _Nonnull stream)
2321         __INTRODUCED_IN(28);
2322 
2323 /**
2324  * Returns the time at which a particular frame was played on a speaker or headset,
2325  * or was recorded on a microphone.
2326  *
2327  * This can be used to synchronize audio with video or MIDI.
2328  * It can also be used to align a recorded stream with a playback stream.
2329  *
2330  * The framePosition is an index into the stream of audio data.
2331  * The first frame played or recorded is at framePosition 0.
2332  *
2333  * These framePositions are the same units that you get from AAudioStream_getFramesRead()
2334  * or AAudioStream_getFramesWritten().
2335  * A "frame" is a set of audio sample values that are played simultaneously.
2336  * For example, a stereo stream has two samples in a frame, left and right.
2337  *
2338  * Timestamps are only valid when the stream is in {@link #AAUDIO_STREAM_STATE_STARTED}.
2339  * {@link #AAUDIO_ERROR_INVALID_STATE} will be returned if the stream is not started.
2340  * Note that because requestStart() is asynchronous, timestamps will not be valid until
2341  * a short time after calling requestStart().
2342  * So {@link #AAUDIO_ERROR_INVALID_STATE} should not be considered a fatal error.
2343  * Just try calling again later.
2344  *
2345  * If an error occurs, then the position and time will not be modified.
2346  *
2347  * The position and time passed back are monotonically increasing.
2348  *
2349  * Available since API level 26.
2350  *
2351  * @param stream reference provided by AAudioStreamBuilder_openStream()
2352  * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
2353  * @param[out] framePosition pointer to a variable to receive the position
2354  * @param[out] timeNanoseconds pointer to a variable to receive the time
2355  * @return {@link #AAUDIO_OK} or a negative error
2356  */
2357 AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* _Nonnull stream,
2358         clockid_t clockid, int64_t* _Nonnull framePosition, int64_t* _Nonnull timeNanoseconds)
2359         __INTRODUCED_IN(26);
2360 
2361 /**
2362  * Return the use case for the stream.
2363  *
2364  * Available since API level 28.
2365  *
2366  * @param stream reference provided by AAudioStreamBuilder_openStream()
2367  * @return frames read
2368  */
2369 AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* _Nonnull stream) __INTRODUCED_IN(28);
2370 
2371 /**
2372  * Return the content type for the stream.
2373  *
2374  * Available since API level 28.
2375  *
2376  * @param stream reference provided by AAudioStreamBuilder_openStream()
2377  * @return content type, for example {@link #AAUDIO_CONTENT_TYPE_MUSIC}
2378  */
2379 AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* _Nonnull stream)
2380         __INTRODUCED_IN(28);
2381 
2382 /**
2383  * Return the spatialization behavior for the stream.
2384  *
2385  * If none was explicitly set, it will return the default
2386  * {@link #AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO} behavior.
2387  *
2388  * Available since API level 32.
2389  *
2390  * @param stream reference provided by AAudioStreamBuilder_openStream()
2391  * @return spatialization behavior, for example {@link #AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO}
2392  */
2393 AAUDIO_API aaudio_spatialization_behavior_t AAudioStream_getSpatializationBehavior(
2394         AAudioStream* _Nonnull stream) __INTRODUCED_IN(32);
2395 
2396 /**
2397  * Return whether the content of the stream is spatialized.
2398  *
2399  * Available since API level 32.
2400  *
2401  * @param stream reference provided by AAudioStreamBuilder_openStream()
2402  * @return true if the content is spatialized
2403  */
2404 AAUDIO_API bool AAudioStream_isContentSpatialized(AAudioStream* _Nonnull stream)
2405         __INTRODUCED_IN(32);
2406 
2407 
2408 /**
2409  * Return the input preset for the stream.
2410  *
2411  * Available since API level 28.
2412  *
2413  * @param stream reference provided by AAudioStreamBuilder_openStream()
2414  * @return input preset, for example {@link #AAUDIO_INPUT_PRESET_CAMCORDER}
2415  */
2416 AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* _Nonnull stream)
2417         __INTRODUCED_IN(28);
2418 
2419 /**
2420  * Return the policy that determines whether the audio may or may not be captured
2421  * by other apps or the system.
2422  *
2423  * Available since API level 29.
2424  *
2425  * @param stream reference provided by AAudioStreamBuilder_openStream()
2426  * @return the allowed capture policy, for example {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}
2427  */
2428 AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
2429         AAudioStream* _Nonnull stream) __INTRODUCED_IN(29);
2430 
2431 
2432 /**
2433  * Return whether this input stream is marked as privacy sensitive or not.
2434  *
2435  * See {@link #AAudioStreamBuilder_setPrivacySensitive()}.
2436  *
2437  * Added in API level 30.
2438  *
2439  * @param stream reference provided by AAudioStreamBuilder_openStream()
2440  * @return true if privacy sensitive, false otherwise
2441  */
2442 AAUDIO_API bool AAudioStream_isPrivacySensitive(AAudioStream* _Nonnull stream)
2443         __INTRODUCED_IN(30);
2444 
2445 /**
2446  * Return the channel mask for the stream. This will be the mask set using
2447  * {@link #AAudioStreamBuilder_setChannelMask}, or {@link #AAUDIO_UNSPECIFIED} otherwise.
2448  *
2449  * Available since API level 32.
2450  *
2451  * @param stream reference provided by AAudioStreamBuilder_openStream()
2452  * @return actual channel mask
2453  */
2454 AAUDIO_API aaudio_channel_mask_t AAudioStream_getChannelMask(AAudioStream* _Nonnull stream)
2455         __INTRODUCED_IN(32);
2456 
2457 /**
2458  * Configures the delay and padding values for the current stream playing in offload mode.
2459  * This should only be used on a stream whose performance mode is
2460  * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING_OFFLOADED} and the format is compressed format.
2461  * The unit is frames, where a frame includes samples for all audio channels, e.g. 100 frames
2462  * for a stereo stream corresponds to 200 interleaved PCM samples.
2463  *
2464  * @param stream reference provided by AAudioStreamBuilder_openStream()
2465  * @param delayInFrames number of frames to be ignored at the beginning of the stream. A value
2466  *                      of 0 indicates no delay is to be applied.
2467  * @param paddingInFrames number of frames to be ignored at the end of the stream. A value of 0
2468  *                        of 0 indicates no padding is to be applied.
2469  * @return {@link #AAUDIO_OK} if the delay and padding values are set successfully,
2470  *         or {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT} if delayInFrames or paddingInFrames
2471  *         is less than 0,
2472  *         or {@link #AAUDIO_ERROR_UNIMPLEMENTED} if the stream is not an output stream whose
2473  *         performance mode is {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING_OFFLOADED},
2474  *         or {@link #AAUDIO_ERROR_INVALID_STATE} if the stream is not yet initialized.
2475  */
2476 AAUDIO_API aaudio_result_t AAudioStream_setOffloadDelayPadding(
2477         AAudioStream* _Nonnull stream, int32_t delayInFrames, int32_t paddingInFrames)
2478         __INTRODUCED_IN(36);
2479 
2480 /**
2481  * Return the decoder delay of an offloaded stream in frames.
2482  *
2483  * @param stream reference provided by AAudioStreamBuilder_openStream()
2484  * @return the offload delay in frames that previously set with
2485  *         {@link #AAudioStream_setOffloadDelayPadding},
2486  *         or 0 if it was never modified,
2487  *         or {@link #AAUDIO_ERROR_UNIMPLEMENTED} if the stream is not an output stream whose
2488  *         performance mode is {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING_OFFLOADED},
2489  *         or {@link #AAUDIO_ERROR_INVALID_STATE} if the stream is not yet initialized.
2490  */
2491 AAUDIO_API int32_t AAudioStream_getOffloadDelay(AAudioStream* _Nonnull stream) __INTRODUCED_IN(36);
2492 
2493 /**
2494  * Return the decoder padding of an offloaded stream in frames.
2495  *
2496  * @param stream reference provided by AAudioStreamBuilder_openStream()
2497  * @return the offload padding in frames that previously set with
2498  *         {@link #AAudioStream_setOffloadDelayPadding},
2499  *         or 0 if it was never modified,
2500  *         or {@link #AAUDIO_ERROR_UNIMPLEMENTED} if the stream is not an output stream whose
2501  *         performance mode is {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING_OFFLOADED},
2502  *         or {@link #AAUDIO_ERROR_INVALID_STATE} if the stream is not yet initialized.
2503  */
2504 AAUDIO_API int32_t AAudioStream_getOffloadPadding(AAudioStream* _Nonnull stream)
2505         __INTRODUCED_IN(36);
2506 
2507 /**
2508  * Declares that the last data writing operation on this stream provided the last buffer of this
2509  * stream.
2510  * After the end of stream, previously set padding and delay values are ignored. That indicates
2511  * all written data will be played.
2512  * Use this method in the same thread as any data writing operation.
2513  *
2514  * @param stream reference provided by AAudioStreamBuilder_openStream()
2515  * @return {@link #AAUDIO_OK} on success,
2516  *         or {@link #AAUDIO_ERROR_UNIMPLEMENTED} if the stream is not an output stream whose
2517  *         performance mode is {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING_OFFLOADED},
2518  *         or {@link #AAUDIO_ERROR_INVALID_STATE} if the stream is not yet initialized.
2519  */
2520 AAUDIO_API aaudio_result_t AAudioStream_setOffloadEndOfStream(AAudioStream* _Nonnull stream)
2521         __INTRODUCED_IN(36);
2522 
2523 /************************************************************************************
2524  * Helper functions for AAudio MMAP.
2525  * AAudio MMAP data path uses a memory region that is shared between the hardware and
2526  * the audio software. The shared memory is referenced using a file descriptor that is
2527  * generated by the ALSA driver. Apps can read/write directly from/to the shared
2528  * memory, which helps improve the audio latency.
2529  ************************************************************************************/
2530 
2531 /**
2532  * When the audio is played/recorded via AAudio MMAP data path, the apps can write to/read from
2533  * a shared memory that will also be accessed directly by hardware. That reduces the audio latency.
2534  * The following values are used to describe how AAudio MMAP is supported.
2535  */
2536 enum {
2537     /**
2538      * AAudio MMAP is disabled and never used.
2539      */
2540     AAUDIO_POLICY_NEVER = 1,
2541 
2542     /**
2543      * AAudio MMAP support depends on device's availability. It will be used
2544      * when it is possible or fallback to the normal path, where the audio data
2545      * will be delivered via audio framework data pipeline.
2546      */
2547     AAUDIO_POLICY_AUTO,
2548 
2549     /**
2550      * AAudio MMAP must be used or fail.
2551      */
2552     AAUDIO_POLICY_ALWAYS
2553 };
2554 typedef int32_t aaudio_policy_t;
2555 
2556 /**
2557  * Query how aaudio mmap is supported for the given device type.
2558  *
2559  * @param device device type
2560  * @param direction {@link AAUDIO_DIRECTION_OUTPUT} or {@link AAUDIO_DIRECTION_INPUT}
2561  * @return the mmap policy or {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT} if the device or direction
2562  *         is invalid or {@link #AAUDIO_ERROR_INTERNAL} if the audio HAL returns error.
2563  */
2564 AAUDIO_API aaudio_policy_t AAudio_getPlatformMMapPolicy(
2565         AAudio_DeviceType device, aaudio_direction_t direction) __INTRODUCED_IN(36);
2566 
2567 /**
2568  * Query how aaudio exclusive mmap is supported for the given device type.
2569  *
2570  * @param device device type
2571  * @param direction {@link AAUDIO_DIRECTION_OUTPUT} or {@link AAUDIO_DIRECTION_INPUT}
2572  * @return the mmap exclusive policy or or {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT} if the device
2573  *         or direction is invalid or {@link #AAUDIO_ERROR_INTERNAL} if the audio HAL returns error.
2574  */
2575 AAUDIO_API aaudio_policy_t AAudio_getPlatformMMapExclusivePolicy(
2576         AAudio_DeviceType device, aaudio_direction_t direction) __INTRODUCED_IN(36);
2577 
2578 /**
2579  * Control whether AAudioStreamBuilder_openStream() will use the new MMAP data path
2580  * or the older "Legacy" data path.
2581  *
2582  * This will only affect the current process.
2583  *
2584  * If unspecified then the policy will be based on system properties or configuration.
2585  *
2586  * @param policy {@link #AAUDIO_UNSPECIFIED}, {@link #AAUDIO_POLICY_NEVER},
2587  *               {@link #AAUDIO_POLICY_AUTO}, or {@link #AAUDIO_POLICY_ALWAYS}
2588  * @return AAUDIO_OK or a negative error
2589  */
2590 AAUDIO_API aaudio_result_t AAudio_setMMapPolicy(aaudio_policy_t policy) __INTRODUCED_IN(36);
2591 
2592 /**
2593  * Get the current MMAP policy set by AAudio_setMMapPolicy().
2594  *
2595  * @return current policy or {@link #AAUDIO_UNSPECIFIED} if it is never set.
2596  */
2597 AAUDIO_API aaudio_policy_t AAudio_getMMapPolicy() __INTRODUCED_IN(36);
2598 
2599 /**
2600  * Return true if the stream uses the MMAP data path versus the legacy path.
2601  *
2602  * @return true if the stream uses the MMAP data path
2603  */
2604 AAUDIO_API bool AAudioStream_isMMapUsed(AAudioStream* _Nonnull stream) __INTRODUCED_IN(36);
2605 
2606 #ifdef __cplusplus
2607 }
2608 #endif
2609 
2610 #endif //AAUDIO_AAUDIO_H
2611 
2612 /** @} */
2613