• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 is did not 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 typedef int32_t aaudio_format_t;
110 
111 /**
112  * These result codes are returned from AAudio functions to indicate success or failure.
113  * Note that error return codes may change in the future so applications should generally
114  * not rely on specific return codes.
115  */
116 enum {
117     /**
118      * The call was successful.
119      */
120     AAUDIO_OK,
121     AAUDIO_ERROR_BASE = -900, // TODO review
122 
123     /**
124      * The audio device was disconnected. This could occur, for example, when headphones
125      * are plugged in or unplugged. The stream cannot be used after the device is disconnected.
126      * Applications should stop and close the stream.
127      * If this error is received in an error callback then another thread should be
128      * used to stop and close the stream.
129      */
130     AAUDIO_ERROR_DISCONNECTED,
131 
132     /**
133      * An invalid parameter was passed to AAudio.
134      */
135     AAUDIO_ERROR_ILLEGAL_ARGUMENT,
136     // reserved
137     AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2,
138 
139     /**
140      * The requested operation is not appropriate for the current state of AAudio.
141      */
142     AAUDIO_ERROR_INVALID_STATE,
143     // reserved
144     // reserved
145     /* The server rejected the handle used to identify the stream.
146      */
147     AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3,
148     // reserved
149 
150     /**
151      * The function is not implemented for this stream.
152      */
153     AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2,
154 
155     /**
156      * A resource or information is unavailable.
157      * This could occur when an application tries to open too many streams,
158      * or a timestamp is not available.
159      */
160     AAUDIO_ERROR_UNAVAILABLE,
161     AAUDIO_ERROR_NO_FREE_HANDLES,
162 
163     /**
164      * Memory could not be allocated.
165      */
166     AAUDIO_ERROR_NO_MEMORY,
167 
168     /**
169      * A NULL pointer was passed to AAudio.
170      * Or a NULL pointer was detected internally.
171      */
172     AAUDIO_ERROR_NULL,
173 
174     /**
175      * An operation took longer than expected.
176      */
177     AAUDIO_ERROR_TIMEOUT,
178     AAUDIO_ERROR_WOULD_BLOCK,
179 
180     /**
181      * The requested data format is not supported.
182      */
183     AAUDIO_ERROR_INVALID_FORMAT,
184 
185     /**
186      * A requested was out of range.
187      */
188     AAUDIO_ERROR_OUT_OF_RANGE,
189 
190     /**
191      * The audio service was not available.
192      */
193     AAUDIO_ERROR_NO_SERVICE,
194 
195     /**
196      * The requested sample rate was not supported.
197      */
198     AAUDIO_ERROR_INVALID_RATE
199 };
200 typedef int32_t  aaudio_result_t;
201 
202 /**
203  * AAudio Stream states, for details, refer to
204  * <a href="/ndk/guides/audio/aaudio/aaudio#using-streams">Using an Audio Stream</a>
205  */
206 enum
207 {
208 
209     /**
210      * The stream is created but not initialized yet.
211      */
212     AAUDIO_STREAM_STATE_UNINITIALIZED = 0,
213     /**
214      * The stream is in an unrecognized state.
215      */
216     AAUDIO_STREAM_STATE_UNKNOWN,
217 
218     /**
219      * The stream is open and ready to use.
220      */
221     AAUDIO_STREAM_STATE_OPEN,
222     /**
223      * The stream is just starting up.
224      */
225     AAUDIO_STREAM_STATE_STARTING,
226     /**
227      * The stream has started.
228      */
229     AAUDIO_STREAM_STATE_STARTED,
230     /**
231      * The stream is pausing.
232      */
233     AAUDIO_STREAM_STATE_PAUSING,
234     /**
235      * The stream has paused, could be restarted or flushed.
236      */
237     AAUDIO_STREAM_STATE_PAUSED,
238     /**
239      * The stream is being flushed.
240      */
241     AAUDIO_STREAM_STATE_FLUSHING,
242     /**
243      * The stream is flushed, ready to be restarted.
244      */
245     AAUDIO_STREAM_STATE_FLUSHED,
246     /**
247      * The stream is stopping.
248      */
249     AAUDIO_STREAM_STATE_STOPPING,
250     /**
251      * The stream has been stopped.
252      */
253     AAUDIO_STREAM_STATE_STOPPED,
254     /**
255      * The stream is closing.
256      */
257     AAUDIO_STREAM_STATE_CLOSING,
258     /**
259      * The stream has been closed.
260      */
261     AAUDIO_STREAM_STATE_CLOSED,
262     /**
263      * The stream is disconnected from audio device.
264      */
265     AAUDIO_STREAM_STATE_DISCONNECTED
266 };
267 typedef int32_t aaudio_stream_state_t;
268 
269 
270 enum {
271     /**
272      * This will be the only stream using a particular source or sink.
273      * This mode will provide the lowest possible latency.
274      * You should close EXCLUSIVE streams immediately when you are not using them.
275      */
276             AAUDIO_SHARING_MODE_EXCLUSIVE,
277     /**
278      * Multiple applications will be mixed by the AAudio Server.
279      * This will have higher latency than the EXCLUSIVE mode.
280      */
281             AAUDIO_SHARING_MODE_SHARED
282 };
283 typedef int32_t aaudio_sharing_mode_t;
284 
285 
286 enum {
287     /**
288      * No particular performance needs. Default.
289      */
290     AAUDIO_PERFORMANCE_MODE_NONE = 10,
291 
292     /**
293      * Extending battery life is more important than low latency.
294      *
295      * This mode is not supported in input streams.
296      * For input, mode NONE will be used if this is requested.
297      */
298     AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
299 
300     /**
301      * Reducing latency is more important than battery life.
302      */
303     AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
304 };
305 typedef int32_t aaudio_performance_mode_t;
306 
307 #define AAUDIO_SYSTEM_USAGE_OFFSET 1000
308 
309 /**
310  * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for.
311  * This information is used by certain platforms or routing policies
312  * to make more refined volume or routing decisions.
313  *
314  * Note that these match the equivalent values in
315  * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>
316  * in the Android Java API.
317  *
318  * Added in API level 28.
319  */
320 enum {
321     /**
322      * Use this for streaming media, music performance, video, podcasts, etcetera.
323      */
324     AAUDIO_USAGE_MEDIA = 1,
325 
326     /**
327      * Use this for voice over IP, telephony, etcetera.
328      */
329     AAUDIO_USAGE_VOICE_COMMUNICATION = 2,
330 
331     /**
332      * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.
333      */
334     AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
335 
336     /**
337      * Use this to demand the users attention.
338      */
339     AAUDIO_USAGE_ALARM = 4,
340 
341     /**
342      * Use this for notifying the user when a message has arrived or some
343      * other background event has occured.
344      */
345     AAUDIO_USAGE_NOTIFICATION = 5,
346 
347     /**
348      * Use this when the phone rings.
349      */
350     AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6,
351 
352     /**
353      * Use this to attract the users attention when, for example, the battery is low.
354      */
355     AAUDIO_USAGE_NOTIFICATION_EVENT = 10,
356 
357     /**
358      * Use this for screen readers, etcetera.
359      */
360     AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
361 
362     /**
363      * Use this for driving or navigation directions.
364      */
365     AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
366 
367     /**
368      * Use this for user interface sounds, beeps, etcetera.
369      */
370     AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
371 
372     /**
373      * Use this for game audio and sound effects.
374      */
375     AAUDIO_USAGE_GAME = 14,
376 
377     /**
378      * Use this for audio responses to user queries, audio instructions or help utterances.
379      */
380     AAUDIO_USAGE_ASSISTANT = 16,
381 
382     /**
383      * Use this in case of playing sounds in an emergency.
384      * Privileged MODIFY_AUDIO_ROUTING permission required.
385      */
386     AAUDIO_SYSTEM_USAGE_EMERGENCY = AAUDIO_SYSTEM_USAGE_OFFSET,
387 
388     /**
389      * Use this for safety sounds and alerts, for example backup camera obstacle detection.
390      * Privileged MODIFY_AUDIO_ROUTING permission required.
391      */
392     AAUDIO_SYSTEM_USAGE_SAFETY = AAUDIO_SYSTEM_USAGE_OFFSET + 1,
393 
394     /**
395      * Use this for vehicle status alerts and information, for example the check engine light.
396      * Privileged MODIFY_AUDIO_ROUTING permission required.
397      */
398     AAUDIO_SYSTEM_USAGE_VEHICLE_STATUS = AAUDIO_SYSTEM_USAGE_OFFSET + 2,
399 
400     /**
401      * Use this for traffic announcements, etc.
402      * Privileged MODIFY_AUDIO_ROUTING permission required.
403      */
404     AAUDIO_SYSTEM_USAGE_ANNOUNCEMENT = AAUDIO_SYSTEM_USAGE_OFFSET + 3,
405 };
406 typedef int32_t aaudio_usage_t;
407 
408 /**
409  * The CONTENT_TYPE attribute describes "what" you are playing.
410  * It expresses the general category of the content. This information is optional.
411  * But in case it is known (for instance AAUDIO_CONTENT_TYPE_MOVIE for a
412  * movie streaming service or AAUDIO_CONTENT_TYPE_SPEECH for
413  * an audio book application) this information might be used by the audio framework to
414  * enforce audio focus.
415  *
416  * Note that these match the equivalent values in
417  * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>
418  * in the Android Java API.
419  *
420  * Added in API level 28.
421  */
422 enum {
423 
424     /**
425      * Use this for spoken voice, audio books, etcetera.
426      */
427     AAUDIO_CONTENT_TYPE_SPEECH = 1,
428 
429     /**
430      * Use this for pre-recorded or live music.
431      */
432     AAUDIO_CONTENT_TYPE_MUSIC = 2,
433 
434     /**
435      * Use this for a movie or video soundtrack.
436      */
437     AAUDIO_CONTENT_TYPE_MOVIE = 3,
438 
439     /**
440      * Use this for sound is designed to accompany a user action,
441      * such as a click or beep sound made when the user presses a button.
442      */
443     AAUDIO_CONTENT_TYPE_SONIFICATION = 4
444 };
445 typedef int32_t aaudio_content_type_t;
446 
447 enum {
448 
449     /**
450      * Constant indicating the audio content associated with these attributes will follow the
451      * default platform behavior with regards to which content will be spatialized or not.
452      */
453     AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO = 1,
454 
455     /**
456      * Constant indicating the audio content associated with these attributes should never
457      * be spatialized.
458      */
459     AAUDIO_SPATIALIZATION_BEHAVIOR_NEVER = 2,
460 };
461 typedef int32_t aaudio_spatialization_behavior_t;
462 
463 /**
464  * Defines the audio source.
465  * An audio source defines both a default physical source of audio signal, and a recording
466  * configuration.
467  *
468  * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
469  *
470  * Added in API level 28.
471  */
472 enum {
473     /**
474      * Use this preset when other presets do not apply.
475      */
476     AAUDIO_INPUT_PRESET_GENERIC = 1,
477 
478     /**
479      * Use this preset when recording video.
480      */
481     AAUDIO_INPUT_PRESET_CAMCORDER = 5,
482 
483     /**
484      * Use this preset when doing speech recognition.
485      */
486     AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6,
487 
488     /**
489      * Use this preset when doing telephony or voice messaging.
490      */
491     AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7,
492 
493     /**
494      * Use this preset to obtain an input with no effects.
495      * Note that this input will not have automatic gain control
496      * so the recorded volume may be very low.
497      */
498     AAUDIO_INPUT_PRESET_UNPROCESSED = 9,
499 
500     /**
501      * Use this preset for capturing audio meant to be processed in real time
502      * and played back for live performance (e.g karaoke).
503      * The capture path will minimize latency and coupling with playback path.
504      * Available since API level 29.
505      */
506     AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE = 10,
507 };
508 typedef int32_t aaudio_input_preset_t;
509 
510 /**
511  * Specifying if audio may or may not be captured by other apps or the system.
512  *
513  * Note that these match the equivalent values in
514  * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>
515  * in the Android Java API.
516  *
517  * Added in API level 29.
518  */
519 enum {
520     /**
521      * Indicates that the audio may be captured by any app.
522      *
523      * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*,
524      * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and {@link #AAUDIO_USAGE_ASSISTANT}.
525      *
526      * On <a href="/reference/android/os/Build.VERSION_CODES#Q">Build.VERSION_CODES</a>,
527      * this means only {@link #AAUDIO_USAGE_MEDIA} and {@link #AAUDIO_USAGE_GAME} may be captured.
528      *
529      * See <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_ALL">
530      * ALLOW_CAPTURE_BY_ALL</a>.
531      */
532     AAUDIO_ALLOW_CAPTURE_BY_ALL = 1,
533     /**
534      * Indicates that the audio may only be captured by system apps.
535      *
536      * System apps can capture for many purposes like accessibility, user guidance...
537      * but have strong restriction. See
538      * <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_SYSTEM">
539      * ALLOW_CAPTURE_BY_SYSTEM</a>
540      * for what the system apps can do with the capture audio.
541      */
542     AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2,
543     /**
544      * Indicates that the audio may not be recorded by any app, even if it is a system app.
545      *
546      * It is encouraged to use {@link #AAUDIO_ALLOW_CAPTURE_BY_SYSTEM} instead of this value as system apps
547      * provide significant and useful features for the user (eg. accessibility).
548      * See <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_NONE">
549      * ALLOW_CAPTURE_BY_NONE</a>.
550      */
551     AAUDIO_ALLOW_CAPTURE_BY_NONE = 3,
552 };
553 
554 typedef int32_t aaudio_allowed_capture_policy_t;
555 
556 /**
557  * These may be used with AAudioStreamBuilder_setSessionId().
558  *
559  * Added in API level 28.
560  */
561 enum {
562     /**
563      * Do not allocate a session ID.
564      * Effects cannot be used with this stream.
565      * Default.
566      *
567      * Added in API level 28.
568      */
569     AAUDIO_SESSION_ID_NONE = -1,
570 
571     /**
572      * Allocate a session ID that can be used to attach and control
573      * effects using the Java AudioEffects API.
574      * Note that using this may result in higher latency.
575      *
576      * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.
577      *
578      * Added in API level 28.
579      */
580     AAUDIO_SESSION_ID_ALLOCATE = 0,
581 };
582 typedef int32_t aaudio_session_id_t;
583 
584 /**
585  * Defines the audio channel mask.
586  * Channel masks are used to describe the samples and their
587  * arrangement in the audio frame. They are also used in the endpoint
588  * (e.g. a USB audio interface, a DAC connected to headphones) to
589  * specify allowable configurations of a particular device.
590  *
591  * Added in API level 32.
592  */
593 enum {
594     /**
595      * Invalid channel mask
596      */
597     AAUDIO_CHANNEL_INVALID = -1,
598 
599     /**
600      * Output audio channel mask
601      */
602     AAUDIO_CHANNEL_FRONT_LEFT = 1 << 0,
603     AAUDIO_CHANNEL_FRONT_RIGHT = 1 << 1,
604     AAUDIO_CHANNEL_FRONT_CENTER = 1 << 2,
605     AAUDIO_CHANNEL_LOW_FREQUENCY = 1 << 3,
606     AAUDIO_CHANNEL_BACK_LEFT = 1 << 4,
607     AAUDIO_CHANNEL_BACK_RIGHT = 1 << 5,
608     AAUDIO_CHANNEL_FRONT_LEFT_OF_CENTER = 1 << 6,
609     AAUDIO_CHANNEL_FRONT_RIGHT_OF_CENTER = 1 << 7,
610     AAUDIO_CHANNEL_BACK_CENTER = 1 << 8,
611     AAUDIO_CHANNEL_SIDE_LEFT = 1 << 9,
612     AAUDIO_CHANNEL_SIDE_RIGHT = 1 << 10,
613     AAUDIO_CHANNEL_TOP_CENTER = 1 << 11,
614     AAUDIO_CHANNEL_TOP_FRONT_LEFT = 1 << 12,
615     AAUDIO_CHANNEL_TOP_FRONT_CENTER = 1 << 13,
616     AAUDIO_CHANNEL_TOP_FRONT_RIGHT = 1 << 14,
617     AAUDIO_CHANNEL_TOP_BACK_LEFT = 1 << 15,
618     AAUDIO_CHANNEL_TOP_BACK_CENTER = 1 << 16,
619     AAUDIO_CHANNEL_TOP_BACK_RIGHT = 1 << 17,
620     AAUDIO_CHANNEL_TOP_SIDE_LEFT = 1 << 18,
621     AAUDIO_CHANNEL_TOP_SIDE_RIGHT = 1 << 19,
622     AAUDIO_CHANNEL_BOTTOM_FRONT_LEFT = 1 << 20,
623     AAUDIO_CHANNEL_BOTTOM_FRONT_CENTER = 1 << 21,
624     AAUDIO_CHANNEL_BOTTOM_FRONT_RIGHT = 1 << 22,
625     AAUDIO_CHANNEL_LOW_FREQUENCY_2 = 1 << 23,
626     AAUDIO_CHANNEL_FRONT_WIDE_LEFT = 1 << 24,
627     AAUDIO_CHANNEL_FRONT_WIDE_RIGHT = 1 << 25,
628 
629     AAUDIO_CHANNEL_MONO = AAUDIO_CHANNEL_FRONT_LEFT,
630     AAUDIO_CHANNEL_STEREO = AAUDIO_CHANNEL_FRONT_LEFT |
631                             AAUDIO_CHANNEL_FRONT_RIGHT,
632     AAUDIO_CHANNEL_2POINT1 = AAUDIO_CHANNEL_FRONT_LEFT |
633                              AAUDIO_CHANNEL_FRONT_RIGHT |
634                              AAUDIO_CHANNEL_LOW_FREQUENCY,
635     AAUDIO_CHANNEL_TRI = AAUDIO_CHANNEL_FRONT_LEFT |
636                          AAUDIO_CHANNEL_FRONT_RIGHT |
637                          AAUDIO_CHANNEL_FRONT_CENTER,
638     AAUDIO_CHANNEL_TRI_BACK = AAUDIO_CHANNEL_FRONT_LEFT |
639                               AAUDIO_CHANNEL_FRONT_RIGHT |
640                               AAUDIO_CHANNEL_BACK_CENTER,
641     AAUDIO_CHANNEL_3POINT1 = AAUDIO_CHANNEL_FRONT_LEFT |
642                              AAUDIO_CHANNEL_FRONT_RIGHT |
643                              AAUDIO_CHANNEL_FRONT_CENTER |
644                              AAUDIO_CHANNEL_LOW_FREQUENCY,
645     AAUDIO_CHANNEL_2POINT0POINT2 = AAUDIO_CHANNEL_FRONT_LEFT |
646                                    AAUDIO_CHANNEL_FRONT_RIGHT |
647                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
648                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
649     AAUDIO_CHANNEL_2POINT1POINT2 = AAUDIO_CHANNEL_2POINT0POINT2 |
650                                    AAUDIO_CHANNEL_LOW_FREQUENCY,
651     AAUDIO_CHANNEL_3POINT0POINT2 = AAUDIO_CHANNEL_FRONT_LEFT |
652                                    AAUDIO_CHANNEL_FRONT_RIGHT |
653                                    AAUDIO_CHANNEL_FRONT_CENTER |
654                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
655                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
656     AAUDIO_CHANNEL_3POINT1POINT2 = AAUDIO_CHANNEL_3POINT0POINT2 |
657                                    AAUDIO_CHANNEL_LOW_FREQUENCY,
658     AAUDIO_CHANNEL_QUAD = AAUDIO_CHANNEL_FRONT_LEFT |
659                           AAUDIO_CHANNEL_FRONT_RIGHT |
660                           AAUDIO_CHANNEL_BACK_LEFT |
661                           AAUDIO_CHANNEL_BACK_RIGHT,
662     AAUDIO_CHANNEL_QUAD_SIDE = AAUDIO_CHANNEL_FRONT_LEFT |
663                                AAUDIO_CHANNEL_FRONT_RIGHT |
664                                AAUDIO_CHANNEL_SIDE_LEFT |
665                                AAUDIO_CHANNEL_SIDE_RIGHT,
666     AAUDIO_CHANNEL_SURROUND = AAUDIO_CHANNEL_FRONT_LEFT |
667                               AAUDIO_CHANNEL_FRONT_RIGHT |
668                               AAUDIO_CHANNEL_FRONT_CENTER |
669                               AAUDIO_CHANNEL_BACK_CENTER,
670     AAUDIO_CHANNEL_PENTA = AAUDIO_CHANNEL_QUAD |
671                            AAUDIO_CHANNEL_FRONT_CENTER,
672     // aka 5POINT1_BACK
673     AAUDIO_CHANNEL_5POINT1 = AAUDIO_CHANNEL_FRONT_LEFT |
674                              AAUDIO_CHANNEL_FRONT_RIGHT |
675                              AAUDIO_CHANNEL_FRONT_CENTER |
676                              AAUDIO_CHANNEL_LOW_FREQUENCY |
677                              AAUDIO_CHANNEL_BACK_LEFT |
678                              AAUDIO_CHANNEL_BACK_RIGHT,
679     AAUDIO_CHANNEL_5POINT1_SIDE = AAUDIO_CHANNEL_FRONT_LEFT |
680                                   AAUDIO_CHANNEL_FRONT_RIGHT |
681                                   AAUDIO_CHANNEL_FRONT_CENTER |
682                                   AAUDIO_CHANNEL_LOW_FREQUENCY |
683                                   AAUDIO_CHANNEL_SIDE_LEFT |
684                                   AAUDIO_CHANNEL_SIDE_RIGHT,
685     AAUDIO_CHANNEL_6POINT1 = AAUDIO_CHANNEL_FRONT_LEFT |
686                              AAUDIO_CHANNEL_FRONT_RIGHT |
687                              AAUDIO_CHANNEL_FRONT_CENTER |
688                              AAUDIO_CHANNEL_LOW_FREQUENCY |
689                              AAUDIO_CHANNEL_BACK_LEFT |
690                              AAUDIO_CHANNEL_BACK_RIGHT |
691                              AAUDIO_CHANNEL_BACK_CENTER,
692     AAUDIO_CHANNEL_7POINT1 = AAUDIO_CHANNEL_5POINT1 |
693                              AAUDIO_CHANNEL_SIDE_LEFT |
694                              AAUDIO_CHANNEL_SIDE_RIGHT,
695     AAUDIO_CHANNEL_5POINT1POINT2 = AAUDIO_CHANNEL_5POINT1 |
696                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
697                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
698     AAUDIO_CHANNEL_5POINT1POINT4 = AAUDIO_CHANNEL_5POINT1 |
699                                    AAUDIO_CHANNEL_TOP_FRONT_LEFT |
700                                    AAUDIO_CHANNEL_TOP_FRONT_RIGHT |
701                                    AAUDIO_CHANNEL_TOP_BACK_LEFT |
702                                    AAUDIO_CHANNEL_TOP_BACK_RIGHT,
703     AAUDIO_CHANNEL_7POINT1POINT2 = AAUDIO_CHANNEL_7POINT1 |
704                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
705                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
706     AAUDIO_CHANNEL_7POINT1POINT4 = AAUDIO_CHANNEL_7POINT1 |
707                                    AAUDIO_CHANNEL_TOP_FRONT_LEFT |
708                                    AAUDIO_CHANNEL_TOP_FRONT_RIGHT |
709                                    AAUDIO_CHANNEL_TOP_BACK_LEFT |
710                                    AAUDIO_CHANNEL_TOP_BACK_RIGHT,
711     AAUDIO_CHANNEL_9POINT1POINT4 = AAUDIO_CHANNEL_7POINT1POINT4 |
712                                    AAUDIO_CHANNEL_FRONT_WIDE_LEFT |
713                                    AAUDIO_CHANNEL_FRONT_WIDE_RIGHT,
714     AAUDIO_CHANNEL_9POINT1POINT6 = AAUDIO_CHANNEL_9POINT1POINT4 |
715                                    AAUDIO_CHANNEL_TOP_SIDE_LEFT |
716                                    AAUDIO_CHANNEL_TOP_SIDE_RIGHT,
717 
718     AAUDIO_CHANNEL_FRONT_BACK = AAUDIO_CHANNEL_FRONT_CENTER |
719                                 AAUDIO_CHANNEL_BACK_CENTER,
720 };
721 typedef uint32_t aaudio_channel_mask_t;
722 
723 typedef struct AAudioStreamStruct         AAudioStream;
724 typedef struct AAudioStreamBuilderStruct  AAudioStreamBuilder;
725 
726 #ifndef AAUDIO_API
727 #define AAUDIO_API /* export this symbol */
728 #endif
729 
730 // ============================================================
731 // Audio System
732 // ============================================================
733 
734 /**
735  * The text is the ASCII symbol corresponding to the returnCode,
736  * or an English message saying the returnCode is unrecognized.
737  * This is intended for developers to use when debugging.
738  * It is not for display to users.
739  *
740  * Available since API level 26.
741  *
742  * @return pointer to a text representation of an AAudio result code.
743  */
744 AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode) __INTRODUCED_IN(26);
745 
746 /**
747  * The text is the ASCII symbol corresponding to the stream state,
748  * or an English message saying the state is unrecognized.
749  * This is intended for developers to use when debugging.
750  * It is not for display to users.
751  *
752  * Available since API level 26.
753  *
754  * @return pointer to a text representation of an AAudio state.
755  */
756 AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state)
757         __INTRODUCED_IN(26);
758 
759 // ============================================================
760 // StreamBuilder
761 // ============================================================
762 
763 /**
764  * Create a StreamBuilder that can be used to open a Stream.
765  *
766  * The deviceId is initially unspecified, meaning that the current default device will be used.
767  *
768  * The default direction is {@link #AAUDIO_DIRECTION_OUTPUT}.
769  * The default sharing mode is {@link #AAUDIO_SHARING_MODE_SHARED}.
770  * The data format, samplesPerFrames and sampleRate are unspecified and will be
771  * chosen by the device when it is opened.
772  *
773  * AAudioStreamBuilder_delete() must be called when you are done using the builder.
774  *
775  * Available since API level 26.
776  */
777 AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder)
778         __INTRODUCED_IN(26);
779 
780 /**
781  * Request an audio device identified by an ID.
782  *
783  * The ID could be obtained from the Java AudioManager.
784  * AudioManager.getDevices() returns an array of {@link AudioDeviceInfo},
785  * which contains a getId() method. That ID can be passed to this function.
786  *
787  * It is possible that you may not get the device that you requested.
788  * So if it is important to you, you should call
789  * AAudioStream_getDeviceId() after the stream is opened to
790  * verify the actual ID.
791  *
792  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED},
793  * in which case the primary device will be used.
794  *
795  * Available since API level 26.
796  *
797  * @param builder reference provided by AAudio_createStreamBuilder()
798  * @param deviceId device identifier or {@link #AAUDIO_UNSPECIFIED}
799  */
800 AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder,
801                                                 int32_t deviceId) __INTRODUCED_IN(26);
802 
803 /**
804  * Declare the name of the package creating the stream.
805  *
806  * This is usually {@code Context#getPackageName()}.
807  *
808  * The default, if you do not call this function, is a random package in the calling uid.
809  * The vast majority of apps have only one package per calling UID.
810  * If an invalid package name is set, input streams may not be given permission to
811  * record when started.
812  *
813  * The package name is usually the applicationId in your app's build.gradle file.
814  *
815  * Available since API level 31.
816  *
817  * @param builder reference provided by AAudio_createStreamBuilder()
818  * @param packageName packageName of the calling app.
819  */
820 AAUDIO_API void AAudioStreamBuilder_setPackageName(AAudioStreamBuilder* builder,
821                                                    const char * packageName) __INTRODUCED_IN(31);
822 
823 /**
824  * Declare the attribution tag of the context creating the stream.
825  *
826  * This is usually {@code Context#getAttributionTag()}.
827  *
828  * The default, if you do not call this function, is null.
829  *
830  * Available since API level 31.
831  *
832  * @param builder reference provided by AAudio_createStreamBuilder()
833  * @param attributionTag attributionTag of the calling context.
834  */
835 AAUDIO_API void AAudioStreamBuilder_setAttributionTag(AAudioStreamBuilder* builder,
836         const char * attributionTag) __INTRODUCED_IN(31);
837 
838 /**
839  * Request a sample rate in Hertz.
840  *
841  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
842  * An optimal value will then be chosen when the stream is opened.
843  * After opening a stream with an unspecified value, the application must
844  * query for the actual value, which may vary by device.
845  *
846  * If an exact value is specified then an opened stream will use that value.
847  * If a stream cannot be opened with the specified value then the open will fail.
848  *
849  * Available since API level 26.
850  *
851  * @param builder reference provided by AAudio_createStreamBuilder()
852  * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
853  */
854 AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder,
855                                                   int32_t sampleRate) __INTRODUCED_IN(26);
856 
857 /**
858  * Request a number of channels for the stream.
859  *
860  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
861  * An optimal value will then be chosen when the stream is opened.
862  * After opening a stream with an unspecified value, the application must
863  * query for the actual value, which may vary by device.
864  *
865  * If an exact value is specified then an opened stream will use that value.
866  * If a stream cannot be opened with the specified value then the open will fail.
867  *
868  * As the channel count provided here may be different from the corresponding channel count
869  * of channel mask used in {@link AAudioStreamBuilder_setChannelMask}, the last called function
870  * will be respected if both this function and {@link AAudioStreamBuilder_setChannelMask} are
871  * called.
872  *
873  * Available since API level 26.
874  *
875  * @param builder reference provided by AAudio_createStreamBuilder()
876  * @param channelCount Number of channels desired.
877  */
878 AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder,
879                                                     int32_t channelCount) __INTRODUCED_IN(26);
880 
881 /**
882  * Identical to AAudioStreamBuilder_setChannelCount().
883  *
884  * Available since API level 26.
885  *
886  * @param builder reference provided by AAudio_createStreamBuilder()
887  * @param samplesPerFrame Number of samples in a frame.
888  *
889  * @deprecated use {@link AAudioStreamBuilder_setChannelCount}
890  */
891 AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder,
892                                                        int32_t samplesPerFrame) __INTRODUCED_IN(26);
893 
894 /**
895  * Request a sample data format, for example {@link #AAUDIO_FORMAT_PCM_I16}.
896  *
897  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
898  * An optimal value will then be chosen when the stream is opened.
899  * After opening a stream with an unspecified value, the application must
900  * query for the actual value, which may vary by device.
901  *
902  * If an exact value is specified then an opened stream will use that value.
903  * If a stream cannot be opened with the specified value then the open will fail.
904  *
905  * Available since API level 26.
906  *
907  * @param builder reference provided by AAudio_createStreamBuilder()
908  * @param format common formats are {@link #AAUDIO_FORMAT_PCM_FLOAT} and
909  *               {@link #AAUDIO_FORMAT_PCM_I16}.
910  */
911 AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder,
912                                               aaudio_format_t format) __INTRODUCED_IN(26);
913 
914 /**
915  * Request a mode for sharing the device.
916  *
917  * The default, if you do not call this function, is {@link #AAUDIO_SHARING_MODE_SHARED}.
918  *
919  * The requested sharing mode may not be available.
920  * The application can query for the actual mode after the stream is opened.
921  *
922  * Available since API level 26.
923  *
924  * @param builder reference provided by AAudio_createStreamBuilder()
925  * @param sharingMode {@link #AAUDIO_SHARING_MODE_SHARED} or {@link #AAUDIO_SHARING_MODE_EXCLUSIVE}
926  */
927 AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder,
928         aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26);
929 
930 /**
931  * Request the direction for a stream.
932  *
933  * The default, if you do not call this function, is {@link #AAUDIO_DIRECTION_OUTPUT}.
934  *
935  * Available since API level 26.
936  *
937  * @param builder reference provided by AAudio_createStreamBuilder()
938  * @param direction {@link #AAUDIO_DIRECTION_OUTPUT} or {@link #AAUDIO_DIRECTION_INPUT}
939  */
940 AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder,
941         aaudio_direction_t direction) __INTRODUCED_IN(26);
942 
943 /**
944  * Set the requested buffer capacity in frames.
945  * The final AAudioStream capacity may differ, but will probably be at least this big.
946  *
947  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
948  *
949  * Available since API level 26.
950  *
951  * @param builder reference provided by AAudio_createStreamBuilder()
952  * @param numFrames the desired buffer capacity in frames or {@link #AAUDIO_UNSPECIFIED}
953  */
954 AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder,
955         int32_t numFrames) __INTRODUCED_IN(26);
956 
957 /**
958  * Set the requested performance mode.
959  *
960  * Supported modes are {@link #AAUDIO_PERFORMANCE_MODE_NONE},
961  * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING} * and {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}.
962  *
963  * The default, if you do not call this function, is {@link #AAUDIO_PERFORMANCE_MODE_NONE}.
964  *
965  * You may not get the mode you requested.
966  * You can call AAudioStream_getPerformanceMode()
967  * to find out the final mode for the stream.
968  *
969  * Available since API level 26.
970  *
971  * @param builder reference provided by AAudio_createStreamBuilder()
972  * @param mode the desired performance mode, eg. {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}
973  */
974 AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder,
975         aaudio_performance_mode_t mode) __INTRODUCED_IN(26);
976 
977 /**
978  * Set the intended use case for the output stream.
979  *
980  * The AAudio system will use this information to optimize the
981  * behavior of the stream.
982  * This could, for example, affect how volume and focus is handled for the stream.
983  *
984  * The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}.
985  *
986  * Available since API level 28.
987  *
988  * @param builder reference provided by AAudio_createStreamBuilder()
989  * @param usage the desired usage, eg. {@link #AAUDIO_USAGE_GAME}
990  */
991 AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder,
992         aaudio_usage_t usage) __INTRODUCED_IN(28);
993 
994 /**
995  * Set the type of audio data that the output stream will carry.
996  *
997  * The AAudio system will use this information to optimize the
998  * behavior of the stream.
999  * This could, for example, affect whether a stream is paused when a notification occurs.
1000  *
1001  * The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}.
1002  *
1003  * Available since API level 28.
1004  *
1005  * @param builder reference provided by AAudio_createStreamBuilder()
1006  * @param contentType the type of audio data, eg. {@link #AAUDIO_CONTENT_TYPE_SPEECH}
1007  */
1008 AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder,
1009         aaudio_content_type_t contentType) __INTRODUCED_IN(28);
1010 
1011 /**
1012  * Sets the behavior affecting whether spatialization will be used.
1013  *
1014  * The AAudio system will use this information to select whether the stream will go
1015  * through a spatializer effect or not when the effect is supported and enabled.
1016  *
1017  * Available since API level 32.
1018  *
1019  * @param builder reference provided by AAudio_createStreamBuilder()
1020  * @param spatializationBehavior the desired behavior with regards to spatialization, eg.
1021  *     {@link #AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO}
1022  */
1023 AAUDIO_API void AAudioStreamBuilder_setSpatializationBehavior(AAudioStreamBuilder* builder,
1024         aaudio_spatialization_behavior_t spatializationBehavior) __INTRODUCED_IN(32);
1025 
1026 /**
1027  * Specifies whether the audio data of this output stream has already been processed for
1028  * spatialization.
1029  *
1030  * If the stream has been processed for spatialization, setting this to true will prevent
1031  * issues such as double-processing on platforms that will spatialize audio data.
1032  *
1033  * Available since API level 32.
1034  *
1035  * @param builder reference provided by AAudio_createStreamBuilder()
1036  * @param isSpatialized true if the content is already processed for binaural or transaural spatial
1037  *     rendering, false otherwise.
1038  */
1039 AAUDIO_API void AAudioStreamBuilder_setIsContentSpatialized(AAudioStreamBuilder* builder,
1040         bool isSpatialized) __INTRODUCED_IN(32);
1041 
1042 /**
1043  * Set the input (capture) preset for the stream.
1044  *
1045  * The AAudio system will use this information to optimize the
1046  * behavior of the stream.
1047  * This could, for example, affect which microphones are used and how the
1048  * recorded data is processed.
1049  *
1050  * The default, if you do not call this function, is {@link #AAUDIO_INPUT_PRESET_VOICE_RECOGNITION}.
1051  * That is because VOICE_RECOGNITION is the preset with the lowest latency
1052  * on many platforms.
1053  *
1054  * Available since API level 28.
1055  *
1056  * @param builder reference provided by AAudio_createStreamBuilder()
1057  * @param inputPreset the desired configuration for recording
1058  */
1059 AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
1060         aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28);
1061 
1062 /**
1063  * Specify whether this stream audio may or may not be captured by other apps or the system.
1064  *
1065  * The default is {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}.
1066  *
1067  * Note that an application can also set its global policy, in which case the most restrictive
1068  * policy is always applied. See
1069  * <a href="/reference/android/media/AudioManager#setAllowedCapturePolicy(int)">
1070  * setAllowedCapturePolicy(int)</a>
1071  *
1072  * Available since API level 29.
1073  *
1074  * @param builder reference provided by AAudio_createStreamBuilder()
1075  * @param capturePolicy the desired level of opt-out from being captured.
1076  */
1077 AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder,
1078         aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29);
1079 
1080 /** Set the requested session ID.
1081  *
1082  * The session ID can be used to associate a stream with effects processors.
1083  * The effects are controlled using the Android AudioEffect Java API.
1084  *
1085  * The default, if you do not call this function, is {@link #AAUDIO_SESSION_ID_NONE}.
1086  *
1087  * If set to {@link #AAUDIO_SESSION_ID_ALLOCATE} then a session ID will be allocated
1088  * when the stream is opened.
1089  *
1090  * The allocated session ID can be obtained by calling AAudioStream_getSessionId()
1091  * and then used with this function when opening another stream.
1092  * This allows effects to be shared between streams.
1093  *
1094  * Session IDs from AAudio can be used with the Android Java APIs and vice versa.
1095  * So a session ID from an AAudio stream can be passed to Java
1096  * and effects applied using the Java AudioEffect API.
1097  *
1098  * Note that allocating or setting a session ID may result in a stream with higher latency.
1099  *
1100  * Allocated session IDs will always be positive and nonzero.
1101  *
1102  * Available since API level 28.
1103  *
1104  * @param builder reference provided by AAudio_createStreamBuilder()
1105  * @param sessionId an allocated sessionID or {@link #AAUDIO_SESSION_ID_ALLOCATE}
1106  */
1107 AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder,
1108         aaudio_session_id_t sessionId) __INTRODUCED_IN(28);
1109 
1110 
1111 /** Indicates whether this input stream must be marked as privacy sensitive or not.
1112  *
1113  * When true, this input stream is privacy sensitive and any concurrent capture
1114  * is not permitted.
1115  *
1116  * This is off (false) by default except when the input preset is {@link #AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION}
1117  * or {@link #AAUDIO_INPUT_PRESET_CAMCORDER}.
1118  *
1119  * Always takes precedence over default from input preset when set explicitly.
1120  *
1121  * Only relevant if the stream direction is {@link #AAUDIO_DIRECTION_INPUT}.
1122  *
1123  * Added in API level 30.
1124  *
1125  * @param builder reference provided by AAudio_createStreamBuilder()
1126  * @param privacySensitive true if capture from this stream must be marked as privacy sensitive,
1127  * false otherwise.
1128  */
1129 AAUDIO_API void AAudioStreamBuilder_setPrivacySensitive(AAudioStreamBuilder* builder,
1130         bool privacySensitive) __INTRODUCED_IN(30);
1131 
1132 /**
1133  * Return one of these values from the data callback function.
1134  */
1135 enum {
1136 
1137     /**
1138      * Continue calling the callback.
1139      */
1140     AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
1141 
1142     /**
1143      * Stop calling the callback.
1144      *
1145      * The application will still need to call AAudioStream_requestPause()
1146      * or AAudioStream_requestStop().
1147      */
1148     AAUDIO_CALLBACK_RESULT_STOP,
1149 
1150 };
1151 typedef int32_t aaudio_data_callback_result_t;
1152 
1153 /**
1154  * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
1155  *
1156  * For an output stream, this function should render and write numFrames of data
1157  * in the streams current data format to the audioData buffer.
1158  *
1159  * For an input stream, this function should read and process numFrames of data
1160  * from the audioData buffer.
1161  *
1162  * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or
1163  * AAudioStream_write() on the stream that is making the callback.
1164  *
1165  * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback()
1166  * is called.
1167  *
1168  * Also note that this callback function should be considered a "real-time" function.
1169  * It must not do anything that could cause an unbounded delay because that can cause the
1170  * audio to glitch or pop.
1171  *
1172  * These are things the function should NOT do:
1173  * <ul>
1174  * <li>allocate memory using, for example, malloc() or new</li>
1175  * <li>any file operations such as opening, closing, reading or writing</li>
1176  * <li>any network operations such as streaming</li>
1177  * <li>use any mutexes or other synchronization primitives</li>
1178  * <li>sleep</li>
1179  * <li>stop or close the stream</li>
1180  * <li>AAudioStream_read()</li>
1181  * <li>AAudioStream_write()</li>
1182  * </ul>
1183  *
1184  * The following are OK to call from the data callback:
1185  * <ul>
1186  * <li>AAudioStream_get*()</li>
1187  * <li>AAudio_convertResultToText()</li>
1188  * </ul>
1189  *
1190  * If you need to move data, eg. MIDI commands, in or out of the callback function then
1191  * we recommend the use of non-blocking techniques such as an atomic FIFO.
1192  *
1193  * @param stream reference provided by AAudioStreamBuilder_openStream()
1194  * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
1195  * @param audioData a pointer to the audio data
1196  * @param numFrames the number of frames to be processed, which can vary
1197  * @return AAUDIO_CALLBACK_RESULT_*
1198  */
1199 typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
1200         AAudioStream *stream,
1201         void *userData,
1202         void *audioData,
1203         int32_t numFrames);
1204 
1205 /**
1206  * Request that AAudio call this functions when the stream is running.
1207  *
1208  * Note that when using this callback, the audio data will be passed in or out
1209  * of the function as an argument.
1210  * So you cannot call AAudioStream_write() or AAudioStream_read()
1211  * on the same stream that has an active data callback.
1212  *
1213  * The callback function will start being called after AAudioStream_requestStart()
1214  * is called.
1215  * It will stop being called after AAudioStream_requestPause() or
1216  * AAudioStream_requestStop() is called.
1217  *
1218  * This callback function will be called on a real-time thread owned by AAudio.
1219  * The low latency streams may have callback threads with higher priority than normal streams.
1220  * See {@link #AAudioStream_dataCallback} for more information.
1221  *
1222  * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
1223  *
1224  * Available since API level 26.
1225  *
1226  * @param builder reference provided by AAudio_createStreamBuilder()
1227  * @param callback pointer to a function that will process audio data.
1228  * @param userData pointer to an application data structure that will be passed
1229  *          to the callback functions.
1230  */
1231 AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder,
1232         AAudioStream_dataCallback callback, void *userData) __INTRODUCED_IN(26);
1233 
1234 /**
1235  * Set the requested data callback buffer size in frames.
1236  * See {@link #AAudioStream_dataCallback}.
1237  *
1238  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
1239  *
1240  * For the lowest possible latency, do not call this function. AAudio will then
1241  * call the dataProc callback function with whatever size is optimal.
1242  * That size may vary from one callback to another.
1243  *
1244  * Only use this function if the application requires a specific number of frames for processing.
1245  * The application might, for example, be using an FFT that requires
1246  * a specific power-of-two sized buffer.
1247  *
1248  * AAudio may need to add additional buffering in order to adapt between the internal
1249  * buffer size and the requested buffer size.
1250  *
1251  * If you do call this function then the requested size should be less than
1252  * half the buffer capacity, to allow double buffering.
1253  *
1254  * Available since API level 26.
1255  *
1256  * @param builder reference provided by AAudio_createStreamBuilder()
1257  * @param numFrames the desired buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
1258  */
1259 AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder,
1260                                                              int32_t numFrames) __INTRODUCED_IN(26);
1261 
1262 /**
1263  * Prototype for the callback function that is passed to
1264  * AAudioStreamBuilder_setErrorCallback().
1265  *
1266  * The following may NOT be called from the error callback:
1267  * <ul>
1268  * <li>AAudioStream_requestStop()</li>
1269  * <li>AAudioStream_requestPause()</li>
1270  * <li>AAudioStream_close()</li>
1271  * <li>AAudioStream_waitForStateChange()</li>
1272  * <li>AAudioStream_read()</li>
1273  * <li>AAudioStream_write()</li>
1274  * </ul>
1275  *
1276  * The following are OK to call from the error callback:
1277  * <ul>
1278  * <li>AAudioStream_get*()</li>
1279  * <li>AAudio_convertResultToText()</li>
1280  * </ul>
1281  *
1282  * @param stream reference provided by AAudioStreamBuilder_openStream()
1283  * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
1284  * @param error an AAUDIO_ERROR_* value.
1285  */
1286 typedef void (*AAudioStream_errorCallback)(
1287         AAudioStream *stream,
1288         void *userData,
1289         aaudio_result_t error);
1290 
1291 /**
1292  * Request that AAudio call this function if any error occurs or the stream is disconnected.
1293  *
1294  * It will be called, for example, if a headset or a USB device is unplugged causing the stream's
1295  * device to be unavailable or "disconnected".
1296  * Another possible cause of error would be a timeout or an unanticipated internal error.
1297  *
1298  * In response, this function should signal or create another thread to stop
1299  * and close this stream. The other thread could then reopen a stream on another device.
1300  * Do not stop or close the stream, or reopen the new stream, directly from this callback.
1301  *
1302  * This callback will not be called because of actions by the application, such as stopping
1303  * or closing a stream.
1304  *
1305  * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
1306  *
1307  * Available since API level 26.
1308  *
1309  * @param builder reference provided by AAudio_createStreamBuilder()
1310  * @param callback pointer to a function that will be called if an error occurs.
1311  * @param userData pointer to an application data structure that will be passed
1312  *          to the callback functions.
1313  */
1314 AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder,
1315         AAudioStream_errorCallback callback, void *userData) __INTRODUCED_IN(26);
1316 
1317 /**
1318  * Open a stream based on the options in the StreamBuilder.
1319  *
1320  * AAudioStream_close() must be called when finished with the stream to recover
1321  * the memory and to free the associated resources.
1322  *
1323  * Available since API level 26.
1324  *
1325  * @param builder reference provided by AAudio_createStreamBuilder()
1326  * @param stream pointer to a variable to receive the new stream reference
1327  * @return {@link #AAUDIO_OK} or a negative error.
1328  */
1329 AAUDIO_API aaudio_result_t  AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder,
1330         AAudioStream** stream) __INTRODUCED_IN(26);
1331 
1332 /**
1333  * Delete the resources associated with the StreamBuilder.
1334  *
1335  * Available since API level 26.
1336  *
1337  * @param builder reference provided by AAudio_createStreamBuilder()
1338  * @return {@link #AAUDIO_OK} or a negative error.
1339  */
1340 AAUDIO_API aaudio_result_t  AAudioStreamBuilder_delete(AAudioStreamBuilder* builder)
1341     __INTRODUCED_IN(26);
1342 
1343 /**
1344  * Set audio channel mask for the stream.
1345  *
1346  * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
1347  * If both channel mask and count are not set, then stereo will then be chosen when the
1348  * stream is opened.
1349  * After opening a stream with an unspecified value, the application must query for the
1350  * actual value, which may vary by device.
1351  *
1352  * If an exact value is specified then an opened stream will use that value.
1353  * If a stream cannot be opened with the specified value then the open will fail.
1354  *
1355  * As the corresponding channel count of provided channel mask here may be different
1356  * from the channel count used in {@link AAudioStreamBuilder_setChannelCount} or
1357  * {@link AAudioStreamBuilder_setSamplesPerFrame}, the last called function will be
1358  * respected if this function and {@link AAudioStreamBuilder_setChannelCount} or
1359  * {@link AAudioStreamBuilder_setSamplesPerFrame} are called.
1360  *
1361  * Available since API level 32.
1362  *
1363  * @param builder reference provided by AAudio_createStreamBuilder()
1364  * @param channelMask Audio channel mask desired.
1365  */
1366 AAUDIO_API void AAudioStreamBuilder_setChannelMask(AAudioStreamBuilder* builder,
1367         aaudio_channel_mask_t channelMask) __INTRODUCED_IN(32);
1368 
1369 // ============================================================
1370 // Stream Control
1371 // ============================================================
1372 
1373 /**
1374  * Free the audio resources associated with a stream created by
1375  * AAudioStreamBuilder_openStream().
1376  * AAudioStream_close() should be called at some point after calling
1377  * this function.
1378  *
1379  * After this call, the stream will be in {@link #AAUDIO_STREAM_STATE_CLOSING}
1380  *
1381  * This function is useful if you want to release the audio resources immediately,
1382  * but still allow queries to the stream to occur from other threads. This often
1383  * happens if you are monitoring stream progress from a UI thread.
1384  *
1385  * NOTE: This function is only fully implemented for MMAP streams,
1386  * which are low latency streams supported by some devices.
1387  * On other "Legacy" streams some audio resources will still be in use
1388  * and some callbacks may still be in process after this call.
1389  *
1390  * Available since API level 30.
1391  *
1392  * @param stream reference provided by AAudioStreamBuilder_openStream()
1393  * @return {@link #AAUDIO_OK} or a negative error.
1394  */
1395 AAUDIO_API aaudio_result_t  AAudioStream_release(AAudioStream* stream) __INTRODUCED_IN(30);
1396 
1397 /**
1398  * Delete the internal data structures associated with the stream created
1399  * by AAudioStreamBuilder_openStream().
1400  *
1401  * If AAudioStream_release() has not been called then it will be called automatically.
1402  *
1403  * Available since API level 26.
1404  *
1405  * @param stream reference provided by AAudioStreamBuilder_openStream()
1406  * @return {@link #AAUDIO_OK} or a negative error.
1407  */
1408 AAUDIO_API aaudio_result_t  AAudioStream_close(AAudioStream* stream) __INTRODUCED_IN(26);
1409 
1410 /**
1411  * Asynchronously request to start playing the stream. For output streams, one should
1412  * write to the stream to fill the buffer before starting.
1413  * Otherwise it will underflow.
1414  * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STARTING} or
1415  * {@link #AAUDIO_STREAM_STATE_STARTED}.
1416  *
1417  * Available since API level 26.
1418  *
1419  * @param stream reference provided by AAudioStreamBuilder_openStream()
1420  * @return {@link #AAUDIO_OK} or a negative error.
1421  */
1422 AAUDIO_API aaudio_result_t  AAudioStream_requestStart(AAudioStream* stream) __INTRODUCED_IN(26);
1423 
1424 /**
1425  * Asynchronous request for the stream to pause.
1426  * Pausing a stream will freeze the data flow but not flush any buffers.
1427  * Use AAudioStream_requestStart() to resume playback after a pause.
1428  * After this call the state will be in {@link #AAUDIO_STREAM_STATE_PAUSING} or
1429  * {@link #AAUDIO_STREAM_STATE_PAUSED}.
1430  *
1431  * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
1432  * For input streams use AAudioStream_requestStop().
1433  *
1434  * Available since API level 26.
1435  *
1436  * @param stream reference provided by AAudioStreamBuilder_openStream()
1437  * @return {@link #AAUDIO_OK} or a negative error.
1438  */
1439 AAUDIO_API aaudio_result_t  AAudioStream_requestPause(AAudioStream* stream) __INTRODUCED_IN(26);
1440 
1441 /**
1442  * Asynchronous request for the stream to flush.
1443  * Flushing will discard any pending data.
1444  * This call only works if the stream is pausing or paused. TODO review
1445  * Frame counters are not reset by a flush. They may be advanced.
1446  * After this call the state will be in {@link #AAUDIO_STREAM_STATE_FLUSHING} or
1447  * {@link #AAUDIO_STREAM_STATE_FLUSHED}.
1448  *
1449  * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
1450  *
1451  * Available since API level 26.
1452  *
1453  * @param stream reference provided by AAudioStreamBuilder_openStream()
1454  * @return {@link #AAUDIO_OK} or a negative error.
1455  */
1456 AAUDIO_API aaudio_result_t  AAudioStream_requestFlush(AAudioStream* stream) __INTRODUCED_IN(26);
1457 
1458 /**
1459  * Asynchronous request for the stream to stop.
1460  * The stream will stop after all of the data currently buffered has been played.
1461  * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STOPPING} or
1462  * {@link #AAUDIO_STREAM_STATE_STOPPED}.
1463  *
1464  * Available since API level 26.
1465  *
1466  * @param stream reference provided by AAudioStreamBuilder_openStream()
1467  * @return {@link #AAUDIO_OK} or a negative error.
1468  */
1469 AAUDIO_API aaudio_result_t  AAudioStream_requestStop(AAudioStream* stream) __INTRODUCED_IN(26);
1470 
1471 /**
1472  * Query the current state of the client, eg. {@link #AAUDIO_STREAM_STATE_PAUSING}
1473  *
1474  * This function will immediately return the state without updating the state.
1475  * If you want to update the client state based on the server state then
1476  * call AAudioStream_waitForStateChange() with currentState
1477  * set to {@link #AAUDIO_STREAM_STATE_UNKNOWN} and a zero timeout.
1478  *
1479  * Available since API level 26.
1480  *
1481  * @param stream reference provided by AAudioStreamBuilder_openStream()
1482  */
1483 AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream) __INTRODUCED_IN(26);
1484 
1485 /**
1486  * Wait until the current state no longer matches the input state.
1487  *
1488  * This will update the current client state.
1489  *
1490  * <pre><code>
1491  * aaudio_result_t result = AAUDIO_OK;
1492  * aaudio_stream_state_t currentState = AAudioStream_getState(stream);
1493  * aaudio_stream_state_t inputState = currentState;
1494  * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) {
1495  *     result = AAudioStream_waitForStateChange(
1496  *                                   stream, inputState, &currentState, MY_TIMEOUT_NANOS);
1497  *     inputState = currentState;
1498  * }
1499  * </code></pre>
1500  *
1501  * Available since API level 26.
1502  *
1503  * @param stream A reference provided by AAudioStreamBuilder_openStream()
1504  * @param inputState The state we want to avoid.
1505  * @param nextState Pointer to a variable that will be set to the new state.
1506  * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1507  * @return {@link #AAUDIO_OK} or a negative error.
1508  */
1509 AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
1510         aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState,
1511         int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
1512 
1513 // ============================================================
1514 // Stream I/O
1515 // ============================================================
1516 
1517 /**
1518  * Read data from the stream.
1519  *
1520  * The call will wait until the read is complete or until it runs out of time.
1521  * If timeoutNanos is zero then this call will not wait.
1522  *
1523  * Note that timeoutNanoseconds is a relative duration in wall clock time.
1524  * Time will not stop if the thread is asleep.
1525  * So it will be implemented using CLOCK_BOOTTIME.
1526  *
1527  * This call is "strong non-blocking" unless it has to wait for data.
1528  *
1529  * If the call times out then zero or a partial frame count will be returned.
1530  *
1531  * Available since API level 26.
1532  *
1533  * @param stream A stream created using AAudioStreamBuilder_openStream().
1534  * @param buffer The address of the first sample.
1535  * @param numFrames Number of frames to read. Only complete frames will be written.
1536  * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1537  * @return The number of frames actually read or a negative error.
1538  */
1539 AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream,
1540         void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
1541 
1542 /**
1543  * Write data to the stream.
1544  *
1545  * The call will wait until the write is complete or until it runs out of time.
1546  * If timeoutNanos is zero then this call will not wait.
1547  *
1548  * Note that timeoutNanoseconds is a relative duration in wall clock time.
1549  * Time will not stop if the thread is asleep.
1550  * So it will be implemented using CLOCK_BOOTTIME.
1551  *
1552  * This call is "strong non-blocking" unless it has to wait for room in the buffer.
1553  *
1554  * If the call times out then zero or a partial frame count will be returned.
1555  *
1556  * Available since API level 26.
1557  *
1558  * @param stream A stream created using AAudioStreamBuilder_openStream().
1559  * @param buffer The address of the first sample.
1560  * @param numFrames Number of frames to write. Only complete frames will be written.
1561  * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1562  * @return The number of frames actually written or a negative error.
1563  */
1564 AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream,
1565         const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
1566 
1567 // ============================================================
1568 // Stream - queries
1569 // ============================================================
1570 
1571 /**
1572  * This can be used to adjust the latency of the buffer by changing
1573  * the threshold where blocking will occur.
1574  * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
1575  * at run-time for each device.
1576  *
1577  * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
1578  *
1579  * Note that you will probably not get the exact size you request.
1580  * You can check the return value or call AAudioStream_getBufferSizeInFrames()
1581  * to see what the actual final size is.
1582  *
1583  * Available since API level 26.
1584  *
1585  * @param stream reference provided by AAudioStreamBuilder_openStream()
1586  * @param numFrames requested number of frames that can be filled without blocking
1587  * @return actual buffer size in frames or a negative error
1588  */
1589 AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream,
1590         int32_t numFrames) __INTRODUCED_IN(26);
1591 
1592 /**
1593  * Query the maximum number of frames that can be filled without blocking.
1594  *
1595  * Available since API level 26.
1596  *
1597  * @param stream reference provided by AAudioStreamBuilder_openStream()
1598  * @return buffer size in frames.
1599  */
1600 AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
1601 
1602 /**
1603  * Query the number of frames that the application should read or write at
1604  * one time for optimal performance. It is OK if an application writes
1605  * a different number of frames. But the buffer size may need to be larger
1606  * in order to avoid underruns or overruns.
1607  *
1608  * Note that this may or may not match the actual device burst size.
1609  * For some endpoints, the burst size can vary dynamically.
1610  * But these tend to be devices with high latency.
1611  *
1612  * Available since API level 26.
1613  *
1614  * @param stream reference provided by AAudioStreamBuilder_openStream()
1615  * @return burst size
1616  */
1617 AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream) __INTRODUCED_IN(26);
1618 
1619 /**
1620  * Query maximum buffer capacity in frames.
1621  *
1622  * Available since API level 26.
1623  *
1624  * @param stream reference provided by AAudioStreamBuilder_openStream()
1625  * @return  buffer capacity in frames
1626  */
1627 AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
1628 
1629 /**
1630  * Query the size of the buffer that will be passed to the dataProc callback
1631  * in the numFrames parameter.
1632  *
1633  * This call can be used if the application needs to know the value of numFrames before
1634  * the stream is started. This is not normally necessary.
1635  *
1636  * If a specific size was requested by calling
1637  * AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size.
1638  *
1639  * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will
1640  * return the size chosen by AAudio, or {@link #AAUDIO_UNSPECIFIED}.
1641  *
1642  * {@link #AAUDIO_UNSPECIFIED} indicates that the callback buffer size for this stream
1643  * may vary from one dataProc callback to the next.
1644  *
1645  * Available since API level 26.
1646  *
1647  * @param stream reference provided by AAudioStreamBuilder_openStream()
1648  * @return callback buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
1649  */
1650 AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream) __INTRODUCED_IN(26);
1651 
1652 /**
1653  * An XRun is an Underrun or an Overrun.
1654  * During playing, an underrun will occur if the stream is not written in time
1655  * and the system runs out of valid data.
1656  * During recording, an overrun will occur if the stream is not read in time
1657  * and there is no place to put the incoming data so it is discarded.
1658  *
1659  * An underrun or overrun can cause an audible "pop" or "glitch".
1660  *
1661  * Note that some INPUT devices may not support this function.
1662  * In that case a 0 will always be returned.
1663  *
1664  * Available since API level 26.
1665  *
1666  * @param stream reference provided by AAudioStreamBuilder_openStream()
1667  * @return the underrun or overrun count
1668  */
1669 AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream) __INTRODUCED_IN(26);
1670 
1671 /**
1672  * Available since API level 26.
1673  *
1674  * @param stream reference provided by AAudioStreamBuilder_openStream()
1675  * @return actual sample rate
1676  */
1677 AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) __INTRODUCED_IN(26);
1678 
1679 /**
1680  * A stream has one or more channels of data.
1681  * A frame will contain one sample for each channel.
1682  *
1683  * Available since API level 26.
1684  *
1685  * @param stream reference provided by AAudioStreamBuilder_openStream()
1686  * @return actual number of channels
1687  */
1688 AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) __INTRODUCED_IN(26);
1689 
1690 /**
1691  * Identical to AAudioStream_getChannelCount().
1692  *
1693  * Available since API level 26.
1694  *
1695  * @param stream reference provided by AAudioStreamBuilder_openStream()
1696  * @return actual number of samples frame
1697  */
1698 AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) __INTRODUCED_IN(26);
1699 
1700 /**
1701  * Available since API level 26.
1702  *
1703  * @param stream reference provided by AAudioStreamBuilder_openStream()
1704  * @return actual device ID
1705  */
1706 AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream) __INTRODUCED_IN(26);
1707 
1708 /**
1709  * Available since API level 26.
1710  *
1711  * @param stream reference provided by AAudioStreamBuilder_openStream()
1712  * @return actual data format
1713  */
1714 AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream) __INTRODUCED_IN(26);
1715 
1716 /**
1717  * Provide actual sharing mode.
1718  *
1719  * Available since API level 26.
1720  *
1721  * @param stream reference provided by AAudioStreamBuilder_openStream()
1722  * @return  actual sharing mode
1723  */
1724 AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream)
1725         __INTRODUCED_IN(26);
1726 
1727 /**
1728  * Get the performance mode used by the stream.
1729  *
1730  * Available since API level 26.
1731  *
1732  * @param stream reference provided by AAudioStreamBuilder_openStream()
1733  */
1734 AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream)
1735         __INTRODUCED_IN(26);
1736 
1737 /**
1738  * Available since API level 26.
1739  *
1740  * @param stream reference provided by AAudioStreamBuilder_openStream()
1741  * @return direction
1742  */
1743 AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream) __INTRODUCED_IN(26);
1744 
1745 /**
1746  * Passes back the number of frames that have been written since the stream was created.
1747  * For an output stream, this will be advanced by the application calling write()
1748  * or by a data callback.
1749  * For an input stream, this will be advanced by the endpoint.
1750  *
1751  * The frame position is monotonically increasing.
1752  *
1753  * Available since API level 26.
1754  *
1755  * @param stream reference provided by AAudioStreamBuilder_openStream()
1756  * @return frames written
1757  */
1758 AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream) __INTRODUCED_IN(26);
1759 
1760 /**
1761  * Passes back the number of frames that have been read since the stream was created.
1762  * For an output stream, this will be advanced by the endpoint.
1763  * For an input stream, this will be advanced by the application calling read()
1764  * or by a data callback.
1765  *
1766  * The frame position is monotonically increasing.
1767  *
1768  * Available since API level 26.
1769  *
1770  * @param stream reference provided by AAudioStreamBuilder_openStream()
1771  * @return frames read
1772  */
1773 AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream) __INTRODUCED_IN(26);
1774 
1775 /**
1776  * Passes back the session ID associated with this stream.
1777  *
1778  * The session ID can be used to associate a stream with effects processors.
1779  * The effects are controlled using the Android AudioEffect Java API.
1780  *
1781  * If AAudioStreamBuilder_setSessionId() was
1782  * called with {@link #AAUDIO_SESSION_ID_ALLOCATE}
1783  * then a new session ID should be allocated once when the stream is opened.
1784  *
1785  * If AAudioStreamBuilder_setSessionId() was called with a previously allocated
1786  * session ID then that value should be returned.
1787  *
1788  * If AAudioStreamBuilder_setSessionId() was not called then this function should
1789  * return {@link #AAUDIO_SESSION_ID_NONE}.
1790  *
1791  * The sessionID for a stream should not change once the stream has been opened.
1792  *
1793  * Available since API level 28.
1794  *
1795  * @param stream reference provided by AAudioStreamBuilder_openStream()
1796  * @return session ID or {@link #AAUDIO_SESSION_ID_NONE}
1797  */
1798 AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream) __INTRODUCED_IN(28);
1799 
1800 /**
1801  * Passes back the time at which a particular frame was presented.
1802  * This can be used to synchronize audio with video or MIDI.
1803  * It can also be used to align a recorded stream with a playback stream.
1804  *
1805  * Timestamps are only valid when the stream is in {@link #AAUDIO_STREAM_STATE_STARTED}.
1806  * {@link #AAUDIO_ERROR_INVALID_STATE} will be returned if the stream is not started.
1807  * Note that because requestStart() is asynchronous, timestamps will not be valid until
1808  * a short time after calling requestStart().
1809  * So {@link #AAUDIO_ERROR_INVALID_STATE} should not be considered a fatal error.
1810  * Just try calling again later.
1811  *
1812  * If an error occurs, then the position and time will not be modified.
1813  *
1814  * The position and time passed back are monotonically increasing.
1815  *
1816  * Available since API level 26.
1817  *
1818  * @param stream reference provided by AAudioStreamBuilder_openStream()
1819  * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
1820  * @param framePosition pointer to a variable to receive the position
1821  * @param timeNanoseconds pointer to a variable to receive the time
1822  * @return {@link #AAUDIO_OK} or a negative error
1823  */
1824 AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream,
1825         clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds) __INTRODUCED_IN(26);
1826 
1827 /**
1828  * Return the use case for the stream.
1829  *
1830  * Available since API level 28.
1831  *
1832  * @param stream reference provided by AAudioStreamBuilder_openStream()
1833  * @return frames read
1834  */
1835 AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream) __INTRODUCED_IN(28);
1836 
1837 /**
1838  * Return the content type for the stream.
1839  *
1840  * Available since API level 28.
1841  *
1842  * @param stream reference provided by AAudioStreamBuilder_openStream()
1843  * @return content type, for example {@link #AAUDIO_CONTENT_TYPE_MUSIC}
1844  */
1845 AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream)
1846         __INTRODUCED_IN(28);
1847 
1848 /**
1849  * Return the spatialization behavior for the stream.
1850  *
1851  * If none was explicitly set, it will return the default
1852  * {@link #AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO} behavior.
1853  *
1854  * Available since API level 32.
1855  *
1856  * @param stream reference provided by AAudioStreamBuilder_openStream()
1857  * @return spatialization behavior, for example {@link #AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO}
1858  */
1859 AAUDIO_API aaudio_spatialization_behavior_t AAudioStream_getSpatializationBehavior(
1860         AAudioStream* stream) __INTRODUCED_IN(32);
1861 
1862 /**
1863  * Return whether the content of the stream is spatialized.
1864  *
1865  * Available since API level 32.
1866  *
1867  * @param stream reference provided by AAudioStreamBuilder_openStream()
1868  * @return true if the content is spatialized
1869  */
1870 AAUDIO_API bool AAudioStream_isContentSpatialized(AAudioStream* stream) __INTRODUCED_IN(32);
1871 
1872 
1873 /**
1874  * Return the input preset for the stream.
1875  *
1876  * Available since API level 28.
1877  *
1878  * @param stream reference provided by AAudioStreamBuilder_openStream()
1879  * @return input preset, for example {@link #AAUDIO_INPUT_PRESET_CAMCORDER}
1880  */
1881 AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream)
1882         __INTRODUCED_IN(28);
1883 
1884 /**
1885  * Return the policy that determines whether the audio may or may not be captured
1886  * by other apps or the system.
1887  *
1888  * Available since API level 29.
1889  *
1890  * @param stream reference provided by AAudioStreamBuilder_openStream()
1891  * @return the allowed capture policy, for example {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}
1892  */
1893 AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
1894         AAudioStream* stream) __INTRODUCED_IN(29);
1895 
1896 
1897 /**
1898  * Return whether this input stream is marked as privacy sensitive or not.
1899  *
1900  * See {@link #AAudioStreamBuilder_setPrivacySensitive()}.
1901  *
1902  * Added in API level 30.
1903  *
1904  * @param stream reference provided by AAudioStreamBuilder_openStream()
1905  * @return true if privacy sensitive, false otherwise
1906  */
1907 AAUDIO_API bool AAudioStream_isPrivacySensitive(AAudioStream* stream)
1908         __INTRODUCED_IN(30);
1909 
1910 /**
1911  * Return the channel mask for the stream. This will be the mask set using
1912  * {@link #AAudioStreamBuilder_setChannelMask}, or {@link #AAUDIO_UNSPECIFIED} otherwise.
1913  *
1914  * Available since API level 32.
1915  *
1916  * @param stream reference provided by AAudioStreamBuilder_openStream()
1917  * @return actual channel mask
1918  */
1919 AAUDIO_API aaudio_channel_mask_t AAudioStream_getChannelMask(AAudioStream* stream)
1920         __INTRODUCED_IN(32);
1921 
1922 #ifdef __cplusplus
1923 }
1924 #endif
1925 
1926 #endif //AAUDIO_AAUDIO_H
1927 
1928 /** @} */
1929