blob: 5bebd61c541c3914112e535672eb9649d4ab1731 [file] [log] [blame]
Phil Burk5ed503c2017-02-01 09:38:15 -08001/*
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/**
Phil Burka45be8b2017-04-05 14:45:48 -070018 * @addtogroup Audio
19 * @{
20 */
21
22/**
23 * @file AAudio.h
24 */
25
26/**
27 * This is the 'C' API for AAudio.
Phil Burk5ed503c2017-02-01 09:38:15 -080028 */
29#ifndef AAUDIO_AAUDIO_H
30#define AAUDIO_AAUDIO_H
31
Phil Burk3316d5e2017-02-15 11:23:01 -080032#include <time.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080033
34#ifdef __cplusplus
35extern "C" {
36#endif
37
Phil Burka4eb0d82017-04-12 15:44:06 -070038/**
39 * This is used to represent a value that has not been specified.
Kevin Rocardfb7e8462019-03-20 13:26:49 -070040 * For example, an application could use {@link #AAUDIO_UNSPECIFIED} to indicate
Phil Burka4eb0d82017-04-12 15:44:06 -070041 * that is did not not care what the specific value of a parameter was
42 * and would accept whatever it was given.
43 */
44#define AAUDIO_UNSPECIFIED 0
Phil Burka4eb0d82017-04-12 15:44:06 -070045
46enum {
Phil Burk8149eed2018-05-24 14:09:46 -070047 /**
48 * Audio data will travel out of the device, for example through a speaker.
49 */
Phil Burka4eb0d82017-04-12 15:44:06 -070050 AAUDIO_DIRECTION_OUTPUT,
Phil Burk8149eed2018-05-24 14:09:46 -070051
52
53 /**
54 * Audio data will travel into the device, for example from a microphone.
55 */
Phil Burka4eb0d82017-04-12 15:44:06 -070056 AAUDIO_DIRECTION_INPUT
57};
58typedef int32_t aaudio_direction_t;
59
60enum {
61 AAUDIO_FORMAT_INVALID = -1,
62 AAUDIO_FORMAT_UNSPECIFIED = 0,
Phil Burk8149eed2018-05-24 14:09:46 -070063
64 /**
65 * This format uses the int16_t data type.
66 * The maximum range of the data is -32768 to 32767.
67 */
Phil Burka4eb0d82017-04-12 15:44:06 -070068 AAUDIO_FORMAT_PCM_I16,
Phil Burk8149eed2018-05-24 14:09:46 -070069
70 /**
71 * This format uses the float data type.
72 * The nominal range of the data is [-1.0f, 1.0f).
73 * Values outside that range may be clipped.
74 *
75 * See also 'floatData' at
76 * https://developer.android.com/reference/android/media/AudioTrack#write(float[],%20int,%20int,%20int)
77 */
Phil Burk74733452017-04-18 19:50:28 -070078 AAUDIO_FORMAT_PCM_FLOAT
Phil Burka4eb0d82017-04-12 15:44:06 -070079};
80typedef int32_t aaudio_format_t;
81
Phil Burk8149eed2018-05-24 14:09:46 -070082/**
83 * These result codes are returned from AAudio functions to indicate success or failure.
84 * Note that error return codes may change in the future so applications should generally
85 * not rely on specific return codes.
86 */
Phil Burka4eb0d82017-04-12 15:44:06 -070087enum {
Phil Burk8149eed2018-05-24 14:09:46 -070088 /**
89 * The call was successful.
90 */
Phil Burka4eb0d82017-04-12 15:44:06 -070091 AAUDIO_OK,
92 AAUDIO_ERROR_BASE = -900, // TODO review
Phil Burk8149eed2018-05-24 14:09:46 -070093
94 /**
95 * The audio device was disconnected. This could occur, for example, when headphones
96 * are plugged in or unplugged. The stream cannot be used after the device is disconnected.
97 * Applications should stop and close the stream.
98 * If this error is received in an error callback then another thread should be
99 * used to stop and close the stream.
100 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700101 AAUDIO_ERROR_DISCONNECTED,
Phil Burk8149eed2018-05-24 14:09:46 -0700102
103 /**
104 * An invalid parameter was passed to AAudio.
105 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700106 AAUDIO_ERROR_ILLEGAL_ARGUMENT,
Phil Burk17fff382017-05-16 14:06:45 -0700107 // reserved
108 AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2,
Phil Burk8149eed2018-05-24 14:09:46 -0700109
110 /**
111 * The requested operation is not appropriate for the current state of AAudio.
112 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700113 AAUDIO_ERROR_INVALID_STATE,
Phil Burk17fff382017-05-16 14:06:45 -0700114 // reserved
115 // reserved
Phil Burk8149eed2018-05-24 14:09:46 -0700116 /* The server rejected the handle used to identify the stream.
117 */
Phil Burk17fff382017-05-16 14:06:45 -0700118 AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3,
119 // reserved
Phil Burk8149eed2018-05-24 14:09:46 -0700120
121 /**
122 * The function is not implemented for this stream.
123 */
Phil Burk17fff382017-05-16 14:06:45 -0700124 AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2,
Phil Burk8149eed2018-05-24 14:09:46 -0700125
126 /**
127 * A resource or information is unavailable.
128 * This could occur when an application tries to open too many streams,
129 * or a timestamp is not available.
130 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700131 AAUDIO_ERROR_UNAVAILABLE,
132 AAUDIO_ERROR_NO_FREE_HANDLES,
Phil Burk8149eed2018-05-24 14:09:46 -0700133
134 /**
135 * Memory could not be allocated.
136 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700137 AAUDIO_ERROR_NO_MEMORY,
Phil Burk8149eed2018-05-24 14:09:46 -0700138
139 /**
140 * A NULL pointer was passed to AAudio.
141 * Or a NULL pointer was detected internally.
142 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700143 AAUDIO_ERROR_NULL,
Phil Burk8149eed2018-05-24 14:09:46 -0700144
145 /**
146 * An operation took longer than expected.
147 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700148 AAUDIO_ERROR_TIMEOUT,
149 AAUDIO_ERROR_WOULD_BLOCK,
Phil Burk8149eed2018-05-24 14:09:46 -0700150
151 /**
152 * The requested data format is not supported.
153 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700154 AAUDIO_ERROR_INVALID_FORMAT,
Phil Burk8149eed2018-05-24 14:09:46 -0700155
156 /**
157 * A requested was out of range.
158 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700159 AAUDIO_ERROR_OUT_OF_RANGE,
Phil Burk8149eed2018-05-24 14:09:46 -0700160
161 /**
162 * The audio service was not available.
163 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700164 AAUDIO_ERROR_NO_SERVICE,
Phil Burk8149eed2018-05-24 14:09:46 -0700165
166 /**
167 * The requested sample rate was not supported.
168 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700169 AAUDIO_ERROR_INVALID_RATE
170};
171typedef int32_t aaudio_result_t;
172
173enum
174{
175 AAUDIO_STREAM_STATE_UNINITIALIZED = 0,
176 AAUDIO_STREAM_STATE_UNKNOWN,
177 AAUDIO_STREAM_STATE_OPEN,
178 AAUDIO_STREAM_STATE_STARTING,
179 AAUDIO_STREAM_STATE_STARTED,
180 AAUDIO_STREAM_STATE_PAUSING,
181 AAUDIO_STREAM_STATE_PAUSED,
182 AAUDIO_STREAM_STATE_FLUSHING,
183 AAUDIO_STREAM_STATE_FLUSHED,
184 AAUDIO_STREAM_STATE_STOPPING,
185 AAUDIO_STREAM_STATE_STOPPED,
186 AAUDIO_STREAM_STATE_CLOSING,
187 AAUDIO_STREAM_STATE_CLOSED,
188 AAUDIO_STREAM_STATE_DISCONNECTED
189};
190typedef int32_t aaudio_stream_state_t;
191
192
193enum {
194 /**
195 * This will be the only stream using a particular source or sink.
196 * This mode will provide the lowest possible latency.
197 * You should close EXCLUSIVE streams immediately when you are not using them.
198 */
199 AAUDIO_SHARING_MODE_EXCLUSIVE,
200 /**
201 * Multiple applications will be mixed by the AAudio Server.
202 * This will have higher latency than the EXCLUSIVE mode.
203 */
204 AAUDIO_SHARING_MODE_SHARED
205};
206typedef int32_t aaudio_sharing_mode_t;
207
Phil Burke2fbb592017-05-01 15:05:52 -0700208
209enum {
210 /**
211 * No particular performance needs. Default.
212 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800213 AAUDIO_PERFORMANCE_MODE_NONE = 10,
Phil Burke2fbb592017-05-01 15:05:52 -0700214
215 /**
Phil Burk8149eed2018-05-24 14:09:46 -0700216 * Extending battery life is more important than low latency.
Phil Burked0a3fe2017-12-05 14:27:43 -0800217 *
218 * This mode is not supported in input streams.
Phil Burk8149eed2018-05-24 14:09:46 -0700219 * For input, mode NONE will be used if this is requested.
Phil Burke2fbb592017-05-01 15:05:52 -0700220 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800221 AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
Phil Burke2fbb592017-05-01 15:05:52 -0700222
223 /**
Phil Burk8149eed2018-05-24 14:09:46 -0700224 * Reducing latency is more important than battery life.
Phil Burke2fbb592017-05-01 15:05:52 -0700225 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800226 AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
Phil Burke2fbb592017-05-01 15:05:52 -0700227};
228typedef int32_t aaudio_performance_mode_t;
229
Phil Burk361b1422017-12-20 14:24:16 -0800230/**
231 * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for.
232 * This information is used by certain platforms or routing policies
233 * to make more refined volume or routing decisions.
234 *
Kevin Rocard68646ba2019-03-20 13:26:49 -0700235 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
236 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700237 *
238 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800239 */
240enum {
241 /**
242 * Use this for streaming media, music performance, video, podcasts, etcetera.
243 */
244 AAUDIO_USAGE_MEDIA = 1,
245
246 /**
247 * Use this for voice over IP, telephony, etcetera.
248 */
249 AAUDIO_USAGE_VOICE_COMMUNICATION = 2,
250
251 /**
252 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.
253 */
254 AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
255
256 /**
257 * Use this to demand the users attention.
258 */
259 AAUDIO_USAGE_ALARM = 4,
260
261 /**
262 * Use this for notifying the user when a message has arrived or some
263 * other background event has occured.
264 */
265 AAUDIO_USAGE_NOTIFICATION = 5,
266
267 /**
268 * Use this when the phone rings.
269 */
270 AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6,
271
272 /**
273 * Use this to attract the users attention when, for example, the battery is low.
274 */
275 AAUDIO_USAGE_NOTIFICATION_EVENT = 10,
276
277 /**
278 * Use this for screen readers, etcetera.
279 */
280 AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
281
282 /**
283 * Use this for driving or navigation directions.
284 */
285 AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
286
287 /**
288 * Use this for user interface sounds, beeps, etcetera.
289 */
290 AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
291
292 /**
293 * Use this for game audio and sound effects.
294 */
295 AAUDIO_USAGE_GAME = 14,
296
297 /**
298 * Use this for audio responses to user queries, audio instructions or help utterances.
299 */
300 AAUDIO_USAGE_ASSISTANT = 16
301};
302typedef int32_t aaudio_usage_t;
303
304/**
305 * The CONTENT_TYPE attribute describes "what" you are playing.
306 * It expresses the general category of the content. This information is optional.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700307 * But in case it is known (for instance AAUDIO_CONTENT_TYPE_MOVIE for a
308 * movie streaming service or AAUDIO_CONTENT_TYPE_SPEECH for
Phil Burk361b1422017-12-20 14:24:16 -0800309 * an audio book application) this information might be used by the audio framework to
310 * enforce audio focus.
311 *
Kevin Rocard68646ba2019-03-20 13:26:49 -0700312 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
313 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700314 *
315 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800316 */
317enum {
318
319 /**
320 * Use this for spoken voice, audio books, etcetera.
321 */
322 AAUDIO_CONTENT_TYPE_SPEECH = 1,
323
324 /**
325 * Use this for pre-recorded or live music.
326 */
327 AAUDIO_CONTENT_TYPE_MUSIC = 2,
328
329 /**
330 * Use this for a movie or video soundtrack.
331 */
332 AAUDIO_CONTENT_TYPE_MOVIE = 3,
333
334 /**
335 * Use this for sound is designed to accompany a user action,
336 * such as a click or beep sound made when the user presses a button.
337 */
338 AAUDIO_CONTENT_TYPE_SONIFICATION = 4
339};
340typedef int32_t aaudio_content_type_t;
341
342/**
343 * Defines the audio source.
344 * An audio source defines both a default physical source of audio signal, and a recording
345 * configuration.
346 *
347 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700348 *
349 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800350 */
351enum {
352 /**
353 * Use this preset when other presets do not apply.
354 */
355 AAUDIO_INPUT_PRESET_GENERIC = 1,
356
357 /**
358 * Use this preset when recording video.
359 */
360 AAUDIO_INPUT_PRESET_CAMCORDER = 5,
361
362 /**
363 * Use this preset when doing speech recognition.
364 */
365 AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6,
366
367 /**
368 * Use this preset when doing telephony or voice messaging.
369 */
370 AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7,
371
372 /**
373 * Use this preset to obtain an input with no effects.
374 * Note that this input will not have automatic gain control
375 * so the recorded volume may be very low.
376 */
377 AAUDIO_INPUT_PRESET_UNPROCESSED = 9,
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800378
379 /**
380 * Use this preset for capturing audio meant to be processed in real time
381 * and played back for live performance (e.g karaoke).
382 * The capture path will minimize latency and coupling with playback path.
383 */
384 AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE = 10,
Phil Burk361b1422017-12-20 14:24:16 -0800385};
386typedef int32_t aaudio_input_preset_t;
387
Phil Burk8149eed2018-05-24 14:09:46 -0700388/**
Kevin Rocard68646ba2019-03-20 13:26:49 -0700389 * Specifying if audio may or may not be captured by other apps or the system.
390 *
391 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
392 * in the Android Java API.
393 *
394 * Added in API level 29.
395 */
396enum {
397 /**
398 * Indicates that the audio may be captured by any app.
399 *
400 * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*,
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700401 * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and {@link #AAUDIO_USAGE_ASSISTANT}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700402 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700403 * On {@link android.os.Build.VERSION_CODES#Q}, this means only {@link #AAUDIO_USAGE_MEDIA}
404 * and {@link #AAUDIO_USAGE_GAME} may be captured.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700405 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700406 * See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_ALL}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700407 */
408 AAUDIO_ALLOW_CAPTURE_BY_ALL = 1,
409 /**
410 * Indicates that the audio may only be captured by system apps.
411 *
412 * System apps can capture for many purposes like accessibility, user guidance...
413 * but have strong restriction. See
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700414 * {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_SYSTEM} for what the system apps
Kevin Rocard68646ba2019-03-20 13:26:49 -0700415 * can do with the capture audio.
416 */
417 AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2,
418 /**
419 * Indicates that the audio may not be recorded by any app, even if it is a system app.
420 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700421 * It is encouraged to use {@link #AAUDIO_ALLOW_CAPTURE_BY_SYSTEM} instead of this value as system apps
Kevin Rocard68646ba2019-03-20 13:26:49 -0700422 * provide significant and useful features for the user (eg. accessibility).
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700423 * See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_NONE}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700424 */
425 AAUDIO_ALLOW_CAPTURE_BY_NONE = 3,
426};
427
428typedef int32_t aaudio_allowed_capture_policy_t;
429
430/**
Phil Burk8149eed2018-05-24 14:09:46 -0700431 * These may be used with AAudioStreamBuilder_setSessionId().
432 *
433 * Added in API level 28.
434 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800435enum {
436 /**
437 * Do not allocate a session ID.
438 * Effects cannot be used with this stream.
439 * Default.
Phil Burk42452c02018-04-10 12:43:33 -0700440 *
441 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800442 */
443 AAUDIO_SESSION_ID_NONE = -1,
444
445 /**
446 * Allocate a session ID that can be used to attach and control
447 * effects using the Java AudioEffects API.
Phil Burk8149eed2018-05-24 14:09:46 -0700448 * Note that using this may result in higher latency.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800449 *
450 * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.
Phil Burk42452c02018-04-10 12:43:33 -0700451 *
452 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800453 */
454 AAUDIO_SESSION_ID_ALLOCATE = 0,
455};
456typedef int32_t aaudio_session_id_t;
457
Phil Burke2155ef2017-02-24 13:50:29 -0800458typedef struct AAudioStreamStruct AAudioStream;
459typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder;
Phil Burk5ed503c2017-02-01 09:38:15 -0800460
Phil Burk5ed503c2017-02-01 09:38:15 -0800461#ifndef AAUDIO_API
Phil Burk3316d5e2017-02-15 11:23:01 -0800462#define AAUDIO_API /* export this symbol */
Phil Burk5ed503c2017-02-01 09:38:15 -0800463#endif
464
465// ============================================================
466// Audio System
467// ============================================================
468
469/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800470 * The text is the ASCII symbol corresponding to the returnCode,
471 * or an English message saying the returnCode is unrecognized.
472 * This is intended for developers to use when debugging.
473 * It is not for display to users.
474 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700475 * Available since API level 26.
476 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800477 * @return pointer to a text representation of an AAudio result code.
478 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700479AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800480
481/**
482 * The text is the ASCII symbol corresponding to the stream state,
483 * or an English message saying the state is unrecognized.
484 * This is intended for developers to use when debugging.
485 * It is not for display to users.
486 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700487 * Available since API level 26.
488 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800489 * @return pointer to a text representation of an AAudio state.
490 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700491AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state)
492 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800493
494// ============================================================
495// StreamBuilder
496// ============================================================
497
498/**
499 * Create a StreamBuilder that can be used to open a Stream.
500 *
501 * The deviceId is initially unspecified, meaning that the current default device will be used.
502 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700503 * The default direction is {@link #AAUDIO_DIRECTION_OUTPUT}.
504 * The default sharing mode is {@link #AAUDIO_SHARING_MODE_SHARED}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800505 * The data format, samplesPerFrames and sampleRate are unspecified and will be
506 * chosen by the device when it is opened.
507 *
508 * AAudioStreamBuilder_delete() must be called when you are done using the builder.
Elliott Hughes64a3b062019-10-29 10:09:30 -0700509 *
510 * Available since API level 26.
Phil Burk5ed503c2017-02-01 09:38:15 -0800511 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700512AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder)
513 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800514
515/**
516 * Request an audio device identified device using an ID.
Phil Burk5ed503c2017-02-01 09:38:15 -0800517 * On Android, for example, the ID could be obtained from the Java AudioManager.
518 *
Kevin Rocard6309d882019-03-20 13:26:49 -0700519 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED},
Phil Burke057ca92017-03-28 11:31:34 -0700520 * in which case the primary device will be used.
Phil Burk5ed503c2017-02-01 09:38:15 -0800521 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700522 * Available since API level 26.
523 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800524 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocard6309d882019-03-20 13:26:49 -0700525 * @param deviceId device identifier or {@link #AAUDIO_UNSPECIFIED}
Phil Burk5ed503c2017-02-01 09:38:15 -0800526 */
Phil Burke2155ef2017-02-24 13:50:29 -0800527AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700528 int32_t deviceId) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800529
530/**
Phil Burke057ca92017-03-28 11:31:34 -0700531 * Request a sample rate in Hertz.
532 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700533 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700534 * An optimal value will then be chosen when the stream is opened.
535 * After opening a stream with an unspecified value, the application must
536 * query for the actual value, which may vary by device.
537 *
538 * If an exact value is specified then an opened stream will use that value.
539 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700540 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700541 * Available since API level 26.
542 *
Phil Burke057ca92017-03-28 11:31:34 -0700543 * @param builder reference provided by AAudio_createStreamBuilder()
544 * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
Phil Burk5ed503c2017-02-01 09:38:15 -0800545 */
Phil Burke2155ef2017-02-24 13:50:29 -0800546AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700547 int32_t sampleRate) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800548
549/**
Phil Burk20523ed2017-04-24 17:04:01 -0700550 * Request a number of channels for the stream.
Phil Burke057ca92017-03-28 11:31:34 -0700551 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700552 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700553 * An optimal value will then be chosen when the stream is opened.
554 * After opening a stream with an unspecified value, the application must
555 * query for the actual value, which may vary by device.
Phil Burk5ed503c2017-02-01 09:38:15 -0800556 *
Phil Burk8f624892017-05-11 11:44:20 -0700557 * If an exact value is specified then an opened stream will use that value.
558 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700559 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700560 * Available since API level 26.
561 *
Phil Burke057ca92017-03-28 11:31:34 -0700562 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk20523ed2017-04-24 17:04:01 -0700563 * @param channelCount Number of channels desired.
Phil Burk5ed503c2017-02-01 09:38:15 -0800564 */
Phil Burk20523ed2017-04-24 17:04:01 -0700565AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700566 int32_t channelCount) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -0700567
568/**
Phil Burke74240d2017-08-03 15:25:43 -0700569 * Identical to AAudioStreamBuilder_setChannelCount().
570 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700571 * Available since API level 26.
572 *
Phil Burke74240d2017-08-03 15:25:43 -0700573 * @param builder reference provided by AAudio_createStreamBuilder()
574 * @param samplesPerFrame Number of samples in a frame.
575 */
576AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700577 int32_t samplesPerFrame) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -0700578
579/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700580 * Request a sample data format, for example {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burke057ca92017-03-28 11:31:34 -0700581 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700582 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700583 * An optimal value will then be chosen when the stream is opened.
584 * After opening a stream with an unspecified value, the application must
585 * query for the actual value, which may vary by device.
Phil Burke057ca92017-03-28 11:31:34 -0700586 *
Phil Burk8f624892017-05-11 11:44:20 -0700587 * If an exact value is specified then an opened stream will use that value.
588 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700589 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700590 * Available since API level 26.
591 *
Phil Burke057ca92017-03-28 11:31:34 -0700592 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700593 * @param format common formats are {@link #AAUDIO_FORMAT_PCM_FLOAT} and
594 * {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800595 */
Phil Burke2155ef2017-02-24 13:50:29 -0800596AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700597 aaudio_format_t format) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800598
599/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800600 * Request a mode for sharing the device.
Phil Burke057ca92017-03-28 11:31:34 -0700601 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700602 * The default, if you do not call this function, is {@link #AAUDIO_SHARING_MODE_SHARED}.
Phil Burke057ca92017-03-28 11:31:34 -0700603 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800604 * The requested sharing mode may not be available.
Phil Burke057ca92017-03-28 11:31:34 -0700605 * The application can query for the actual mode after the stream is opened.
Phil Burk5ed503c2017-02-01 09:38:15 -0800606 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700607 * Available since API level 26.
608 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800609 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700610 * @param sharingMode {@link #AAUDIO_SHARING_MODE_SHARED} or {@link #AAUDIO_SHARING_MODE_EXCLUSIVE}
Phil Burk5ed503c2017-02-01 09:38:15 -0800611 */
Phil Burke2155ef2017-02-24 13:50:29 -0800612AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700613 aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800614
615/**
Phil Burke057ca92017-03-28 11:31:34 -0700616 * Request the direction for a stream.
617 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700618 * The default, if you do not call this function, is {@link #AAUDIO_DIRECTION_OUTPUT}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800619 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700620 * Available since API level 26.
621 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800622 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700623 * @param direction {@link #AAUDIO_DIRECTION_OUTPUT} or {@link #AAUDIO_DIRECTION_INPUT}
Phil Burk5ed503c2017-02-01 09:38:15 -0800624 */
Phil Burke2155ef2017-02-24 13:50:29 -0800625AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700626 aaudio_direction_t direction) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800627
628/**
Phil Burke057ca92017-03-28 11:31:34 -0700629 * Set the requested buffer capacity in frames.
Phil Burk3df348f2017-02-08 11:41:55 -0800630 * The final AAudioStream capacity may differ, but will probably be at least this big.
631 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700632 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk3df348f2017-02-08 11:41:55 -0800633 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700634 * Available since API level 26.
635 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800636 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700637 * @param numFrames the desired buffer capacity in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burk3df348f2017-02-08 11:41:55 -0800638 */
Phil Burke2155ef2017-02-24 13:50:29 -0800639AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700640 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700641
642/**
643 * Set the requested performance mode.
644 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700645 * Supported modes are {@link #AAUDIO_PERFORMANCE_MODE_NONE},
646 * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING} * and {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}.
Phil Burk8149eed2018-05-24 14:09:46 -0700647 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700648 * The default, if you do not call this function, is {@link #AAUDIO_PERFORMANCE_MODE_NONE}.
Phil Burke2fbb592017-05-01 15:05:52 -0700649 *
Phil Burk8149eed2018-05-24 14:09:46 -0700650 * You may not get the mode you requested.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700651 * You can call AAudioStream_getPerformanceMode()
652 * to find out the final mode for the stream.
Phil Burk8149eed2018-05-24 14:09:46 -0700653 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700654 * Available since API level 26.
655 *
Phil Burke2fbb592017-05-01 15:05:52 -0700656 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700657 * @param mode the desired performance mode, eg. {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}
Phil Burke2fbb592017-05-01 15:05:52 -0700658 */
659AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700660 aaudio_performance_mode_t mode) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700661
Phil Burke057ca92017-03-28 11:31:34 -0700662/**
Phil Burk361b1422017-12-20 14:24:16 -0800663 * Set the intended use case for the stream.
664 *
665 * The AAudio system will use this information to optimize the
666 * behavior of the stream.
667 * This could, for example, affect how volume and focus is handled for the stream.
668 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700669 * The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}.
Phil Burk361b1422017-12-20 14:24:16 -0800670 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700671 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700672 *
Phil Burk361b1422017-12-20 14:24:16 -0800673 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700674 * @param usage the desired usage, eg. {@link #AAUDIO_USAGE_GAME}
Phil Burk361b1422017-12-20 14:24:16 -0800675 */
676AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700677 aaudio_usage_t usage) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800678
679/**
680 * Set the type of audio data that the stream will carry.
681 *
682 * The AAudio system will use this information to optimize the
683 * behavior of the stream.
684 * This could, for example, affect whether a stream is paused when a notification occurs.
685 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700686 * The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}.
Phil Burk361b1422017-12-20 14:24:16 -0800687 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700688 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700689 *
Phil Burk361b1422017-12-20 14:24:16 -0800690 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700691 * @param contentType the type of audio data, eg. {@link #AAUDIO_CONTENT_TYPE_SPEECH}
Phil Burk361b1422017-12-20 14:24:16 -0800692 */
693AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700694 aaudio_content_type_t contentType) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800695
696/**
697 * Set the input (capture) preset for the stream.
698 *
699 * The AAudio system will use this information to optimize the
700 * behavior of the stream.
701 * This could, for example, affect which microphones are used and how the
702 * recorded data is processed.
703 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700704 * The default, if you do not call this function, is {@link #AAUDIO_INPUT_PRESET_VOICE_RECOGNITION}.
Phil Burkeaef9b92018-01-18 09:09:42 -0800705 * That is because VOICE_RECOGNITION is the preset with the lowest latency
706 * on many platforms.
Phil Burk361b1422017-12-20 14:24:16 -0800707 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700708 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700709 *
Phil Burk361b1422017-12-20 14:24:16 -0800710 * @param builder reference provided by AAudio_createStreamBuilder()
711 * @param inputPreset the desired configuration for recording
712 */
713AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700714 aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800715
Kevin Rocard68646ba2019-03-20 13:26:49 -0700716/**
717 * Specify whether this stream audio may or may not be captured by other apps or the system.
718 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700719 * The default is {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700720 *
721 * Note that an application can also set its global policy, in which case the most restrictive
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700722 * policy is always applied. See {@link android.media.AudioAttributes#setAllowedCapturePolicy(int)}
Kevin Rocard68646ba2019-03-20 13:26:49 -0700723 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700724 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700725 *
726 * @param builder reference provided by AAudio_createStreamBuilder()
Glenn Kastend3080c32019-10-24 09:54:56 -0700727 * @param capturePolicy the desired level of opt-out from being captured.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700728 */
729AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder,
730 aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29);
731
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800732/** Set the requested session ID.
733 *
734 * The session ID can be used to associate a stream with effects processors.
735 * The effects are controlled using the Android AudioEffect Java API.
736 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700737 * The default, if you do not call this function, is {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800738 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700739 * If set to {@link #AAUDIO_SESSION_ID_ALLOCATE} then a session ID will be allocated
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800740 * when the stream is opened.
741 *
742 * The allocated session ID can be obtained by calling AAudioStream_getSessionId()
743 * and then used with this function when opening another stream.
744 * This allows effects to be shared between streams.
745 *
Phil Burk8149eed2018-05-24 14:09:46 -0700746 * Session IDs from AAudio can be used with the Android Java APIs and vice versa.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800747 * So a session ID from an AAudio stream can be passed to Java
748 * and effects applied using the Java AudioEffect API.
749 *
Phil Burk8149eed2018-05-24 14:09:46 -0700750 * Note that allocating or setting a session ID may result in a stream with higher latency.
751 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800752 * Allocated session IDs will always be positive and nonzero.
753 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700754 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700755 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800756 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700757 * @param sessionId an allocated sessionID or {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800758 */
759AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700760 aaudio_session_id_t sessionId) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800761
Eric Laurentd17c8502019-10-24 15:58:35 -0700762
763/** Indicates whether this input stream must be marked as privacy sensitive or not.
764 *
765 * When true, this input stream is privacy sensitive and any concurrent capture
766 * is not permitted.
767 *
768 * This is off (false) by default except when the input preset is {@link #AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION}
769 * or {@link #AAUDIO_INPUT_PRESET_CAMCORDER}.
770 *
771 * Always takes precedence over default from input preset when set explicitly.
772 *
773 * Only relevant if the stream direction is {@link #AAUDIO_DIRECTION_INPUT}.
774 *
775 * Added in API level 30.
776 *
777 * @param builder reference provided by AAudio_createStreamBuilder()
778 * @param privacySensitive true if capture from this stream must be marked as privacy sensitive,
779 * false otherwise.
780 */
781AAUDIO_API void AAudioStreamBuilder_setPrivacySensitive(AAudioStreamBuilder* builder,
782 bool privacySensitive) __INTRODUCED_IN(30);
783
Phil Burk361b1422017-12-20 14:24:16 -0800784/**
Phil Burke057ca92017-03-28 11:31:34 -0700785 * Return one of these values from the data callback function.
786 */
787enum {
788
789 /**
790 * Continue calling the callback.
791 */
792 AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
793
794 /**
795 * Stop calling the callback.
796 *
797 * The application will still need to call AAudioStream_requestPause()
798 * or AAudioStream_requestStop().
799 */
800 AAUDIO_CALLBACK_RESULT_STOP,
801
802};
803typedef int32_t aaudio_data_callback_result_t;
804
805/**
806 * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
807 *
808 * For an output stream, this function should render and write numFrames of data
809 * in the streams current data format to the audioData buffer.
810 *
811 * For an input stream, this function should read and process numFrames of data
812 * from the audioData buffer.
813 *
Phil Burked0a3fe2017-12-05 14:27:43 -0800814 * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or
815 * AAudioStream_write() on the stream that is making the callback.
816 *
817 * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback()
818 * is called.
819 *
820 * Also note that this callback function should be considered a "real-time" function.
Phil Burke057ca92017-03-28 11:31:34 -0700821 * It must not do anything that could cause an unbounded delay because that can cause the
822 * audio to glitch or pop.
823 *
824 * These are things the function should NOT do:
825 * <ul>
826 * <li>allocate memory using, for example, malloc() or new</li>
827 * <li>any file operations such as opening, closing, reading or writing</li>
828 * <li>any network operations such as streaming</li>
829 * <li>use any mutexes or other synchronization primitives</li>
830 * <li>sleep</li>
Phil Burked0a3fe2017-12-05 14:27:43 -0800831 * <li>stop or close the stream</li>
Phil Burk8149eed2018-05-24 14:09:46 -0700832 * <li>AAudioStream_read()</li>
833 * <li>AAudioStream_write()</li>
834 * </ul>
835 *
836 * The following are OK to call from the data callback:
837 * <ul>
838 * <li>AAudioStream_get*()</li>
839 * <li>AAudio_convertResultToText()</li>
Phil Burke057ca92017-03-28 11:31:34 -0700840 * </ul>
841 *
842 * If you need to move data, eg. MIDI commands, in or out of the callback function then
843 * we recommend the use of non-blocking techniques such as an atomic FIFO.
844 *
845 * @param stream reference provided by AAudioStreamBuilder_openStream()
846 * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
847 * @param audioData a pointer to the audio data
Phil Burked0a3fe2017-12-05 14:27:43 -0800848 * @param numFrames the number of frames to be processed, which can vary
Phil Burke057ca92017-03-28 11:31:34 -0700849 * @return AAUDIO_CALLBACK_RESULT_*
850 */
851typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
852 AAudioStream *stream,
853 void *userData,
854 void *audioData,
855 int32_t numFrames);
856
857/**
858 * Request that AAudio call this functions when the stream is running.
859 *
860 * Note that when using this callback, the audio data will be passed in or out
861 * of the function as an argument.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700862 * So you cannot call AAudioStream_write() or AAudioStream_read()
863 * on the same stream that has an active data callback.
Phil Burke057ca92017-03-28 11:31:34 -0700864 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700865 * The callback function will start being called after AAudioStream_requestStart()
866 * is called.
Phil Burke057ca92017-03-28 11:31:34 -0700867 * It will stop being called after AAudioStream_requestPause() or
868 * AAudioStream_requestStop() is called.
869 *
870 * This callback function will be called on a real-time thread owned by AAudio. See
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700871 * {@link #AAudioStream_dataCallback} for more information.
Phil Burke057ca92017-03-28 11:31:34 -0700872 *
873 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
874 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700875 * Available since API level 26.
876 *
Phil Burke057ca92017-03-28 11:31:34 -0700877 * @param builder reference provided by AAudio_createStreamBuilder()
878 * @param callback pointer to a function that will process audio data.
879 * @param userData pointer to an application data structure that will be passed
880 * to the callback functions.
881 */
882AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700883 AAudioStream_dataCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -0700884
885/**
886 * Set the requested data callback buffer size in frames.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700887 * See {@link #AAudioStream_dataCallback}.
Phil Burke057ca92017-03-28 11:31:34 -0700888 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700889 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -0700890 *
891 * For the lowest possible latency, do not call this function. AAudio will then
892 * call the dataProc callback function with whatever size is optimal.
893 * That size may vary from one callback to another.
894 *
895 * Only use this function if the application requires a specific number of frames for processing.
896 * The application might, for example, be using an FFT that requires
897 * a specific power-of-two sized buffer.
898 *
899 * AAudio may need to add additional buffering in order to adapt between the internal
900 * buffer size and the requested buffer size.
901 *
902 * If you do call this function then the requested size should be less than
903 * half the buffer capacity, to allow double buffering.
904 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700905 * Available since API level 26.
906 *
Phil Burke057ca92017-03-28 11:31:34 -0700907 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700908 * @param numFrames the desired buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -0700909 */
910AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700911 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -0700912
913/**
914 * Prototype for the callback function that is passed to
915 * AAudioStreamBuilder_setErrorCallback().
916 *
Phil Burk8149eed2018-05-24 14:09:46 -0700917 * The following may NOT be called from the error callback:
918 * <ul>
919 * <li>AAudioStream_requestStop()</li>
920 * <li>AAudioStream_requestPause()</li>
921 * <li>AAudioStream_close()</li>
922 * <li>AAudioStream_waitForStateChange()</li>
923 * <li>AAudioStream_read()</li>
924 * <li>AAudioStream_write()</li>
925 * </ul>
926 *
927 * The following are OK to call from the error callback:
928 * <ul>
929 * <li>AAudioStream_get*()</li>
930 * <li>AAudio_convertResultToText()</li>
931 * </ul>
932 *
Phil Burke057ca92017-03-28 11:31:34 -0700933 * @param stream reference provided by AAudioStreamBuilder_openStream()
934 * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
935 * @param error an AAUDIO_ERROR_* value.
936 */
937typedef void (*AAudioStream_errorCallback)(
938 AAudioStream *stream,
939 void *userData,
940 aaudio_result_t error);
941
942/**
Phil Burked0a3fe2017-12-05 14:27:43 -0800943 * Request that AAudio call this function if any error occurs or the stream is disconnected.
Phil Burke057ca92017-03-28 11:31:34 -0700944 *
945 * It will be called, for example, if a headset or a USB device is unplugged causing the stream's
Phil Burked0a3fe2017-12-05 14:27:43 -0800946 * device to be unavailable or "disconnected".
Phil Burke057ca92017-03-28 11:31:34 -0700947 * Another possible cause of error would be a timeout or an unanticipated internal error.
948 *
Phil Burked0a3fe2017-12-05 14:27:43 -0800949 * In response, this function should signal or create another thread to stop
950 * and close this stream. The other thread could then reopen a stream on another device.
951 * Do not stop or close the stream, or reopen the new stream, directly from this callback.
952 *
953 * This callback will not be called because of actions by the application, such as stopping
954 * or closing a stream.
955 *
Phil Burke057ca92017-03-28 11:31:34 -0700956 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
957 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700958 * Available since API level 26.
959 *
Phil Burke057ca92017-03-28 11:31:34 -0700960 * @param builder reference provided by AAudio_createStreamBuilder()
961 * @param callback pointer to a function that will be called if an error occurs.
962 * @param userData pointer to an application data structure that will be passed
963 * to the callback functions.
964 */
965AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700966 AAudioStream_errorCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800967
968/**
969 * Open a stream based on the options in the StreamBuilder.
970 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700971 * AAudioStream_close() must be called when finished with the stream to recover
Phil Burk5ed503c2017-02-01 09:38:15 -0800972 * the memory and to free the associated resources.
973 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700974 * Available since API level 26.
975 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800976 * @param builder reference provided by AAudio_createStreamBuilder()
977 * @param stream pointer to a variable to receive the new stream reference
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700978 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -0800979 */
Phil Burke2155ef2017-02-24 13:50:29 -0800980AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700981 AAudioStream** stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800982
983/**
984 * Delete the resources associated with the StreamBuilder.
985 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700986 * Available since API level 26.
987 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800988 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700989 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -0800990 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700991AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder)
992 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800993
994// ============================================================
995// Stream Control
996// ============================================================
997
998/**
999 * Free the resources associated with a stream created by AAudioStreamBuilder_openStream()
1000 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001001 * Available since API level 26.
1002 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001003 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001004 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001005 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001006AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001007
1008/**
1009 * Asynchronously request to start playing the stream. For output streams, one should
1010 * write to the stream to fill the buffer before starting.
1011 * Otherwise it will underflow.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001012 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STARTING} or
1013 * {@link #AAUDIO_STREAM_STATE_STARTED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001014 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001015 * Available since API level 26.
1016 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001017 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001018 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001019 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001020AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001021
1022/**
1023 * Asynchronous request for the stream to pause.
1024 * Pausing a stream will freeze the data flow but not flush any buffers.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001025 * Use AAudioStream_requestStart() to resume playback after a pause.
1026 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_PAUSING} or
1027 * {@link #AAUDIO_STREAM_STATE_PAUSED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001028 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001029 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001030 * For input streams use AAudioStream_requestStop().
1031 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001032 * Available since API level 26.
1033 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001034 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001035 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001036 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001037AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001038
1039/**
1040 * Asynchronous request for the stream to flush.
1041 * Flushing will discard any pending data.
1042 * This call only works if the stream is pausing or paused. TODO review
1043 * Frame counters are not reset by a flush. They may be advanced.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001044 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_FLUSHING} or
1045 * {@link #AAUDIO_STREAM_STATE_FLUSHED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001046 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001047 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001048 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001049 * Available since API level 26.
1050 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001051 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001052 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001053 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001054AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001055
1056/**
1057 * Asynchronous request for the stream to stop.
1058 * The stream will stop after all of the data currently buffered has been played.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001059 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STOPPING} or
1060 * {@link #AAUDIO_STREAM_STATE_STOPPED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001061 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001062 * Available since API level 26.
1063 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001064 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001065 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001066 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001067AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001068
1069/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001070 * Query the current state of the client, eg. {@link #AAUDIO_STREAM_STATE_PAUSING}
Phil Burk5ed503c2017-02-01 09:38:15 -08001071 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001072 * This function will immediately return the state without updating the state.
1073 * If you want to update the client state based on the server state then
1074 * call AAudioStream_waitForStateChange() with currentState
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001075 * set to {@link #AAUDIO_STREAM_STATE_UNKNOWN} and a zero timeout.
Phil Burk3316d5e2017-02-15 11:23:01 -08001076 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001077 * Available since API level 26.
1078 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001079 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001080 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001081AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001082
1083/**
1084 * Wait until the current state no longer matches the input state.
1085 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001086 * This will update the current client state.
1087 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001088 * <pre><code>
Phil Burked0a3fe2017-12-05 14:27:43 -08001089 * aaudio_result_t result = AAUDIO_OK;
1090 * aaudio_stream_state_t currentState = AAudioStream_getState(stream);
1091 * aaudio_stream_state_t inputState = currentState;
1092 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) {
Phil Burk5ed503c2017-02-01 09:38:15 -08001093 * result = AAudioStream_waitForStateChange(
Phil Burked0a3fe2017-12-05 14:27:43 -08001094 * stream, inputState, &currentState, MY_TIMEOUT_NANOS);
1095 * inputState = currentState;
Phil Burk5ed503c2017-02-01 09:38:15 -08001096 * }
1097 * </code></pre>
1098 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001099 * Available since API level 26.
1100 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001101 * @param stream A reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001102 * @param inputState The state we want to avoid.
1103 * @param nextState Pointer to a variable that will be set to the new state.
1104 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001105 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001106 */
Phil Burke2155ef2017-02-24 13:50:29 -08001107AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001108 aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState,
1109 int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001110
1111// ============================================================
1112// Stream I/O
1113// ============================================================
1114
1115/**
1116 * Read data from the stream.
1117 *
1118 * The call will wait until the read is complete or until it runs out of time.
1119 * If timeoutNanos is zero then this call will not wait.
1120 *
1121 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1122 * Time will not stop if the thread is asleep.
1123 * So it will be implemented using CLOCK_BOOTTIME.
1124 *
1125 * This call is "strong non-blocking" unless it has to wait for data.
1126 *
Phil Burk8149eed2018-05-24 14:09:46 -07001127 * If the call times out then zero or a partial frame count will be returned.
1128 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001129 * Available since API level 26.
1130 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001131 * @param stream A stream created using AAudioStreamBuilder_openStream().
1132 * @param buffer The address of the first sample.
1133 * @param numFrames Number of frames to read. Only complete frames will be written.
1134 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Phil Burk3316d5e2017-02-15 11:23:01 -08001135 * @return The number of frames actually read or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001136 */
Phil Burke2155ef2017-02-24 13:50:29 -08001137AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001138 void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001139
1140/**
1141 * Write data to the stream.
1142 *
1143 * The call will wait until the write is complete or until it runs out of time.
1144 * If timeoutNanos is zero then this call will not wait.
1145 *
1146 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1147 * Time will not stop if the thread is asleep.
1148 * So it will be implemented using CLOCK_BOOTTIME.
1149 *
1150 * This call is "strong non-blocking" unless it has to wait for room in the buffer.
1151 *
Phil Burk8149eed2018-05-24 14:09:46 -07001152 * If the call times out then zero or a partial frame count will be returned.
1153 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001154 * Available since API level 26.
1155 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001156 * @param stream A stream created using AAudioStreamBuilder_openStream().
1157 * @param buffer The address of the first sample.
1158 * @param numFrames Number of frames to write. Only complete frames will be written.
1159 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1160 * @return The number of frames actually written or a negative error.
1161 */
Phil Burke2155ef2017-02-24 13:50:29 -08001162AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001163 const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001164
Phil Burk5ed503c2017-02-01 09:38:15 -08001165// ============================================================
1166// Stream - queries
1167// ============================================================
1168
Phil Burk5ed503c2017-02-01 09:38:15 -08001169/**
1170 * This can be used to adjust the latency of the buffer by changing
1171 * the threshold where blocking will occur.
Phil Burk3316d5e2017-02-15 11:23:01 -08001172 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
Phil Burk5ed503c2017-02-01 09:38:15 -08001173 * at run-time for each device.
1174 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001175 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
Phil Burk5ed503c2017-02-01 09:38:15 -08001176 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001177 * Note that you will probably not get the exact size you request.
Phil Burk8149eed2018-05-24 14:09:46 -07001178 * You can check the return value or call AAudioStream_getBufferSizeInFrames()
1179 * to see what the actual final size is.
Phil Burk3316d5e2017-02-15 11:23:01 -08001180 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001181 * Available since API level 26.
1182 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001183 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001184 * @param numFrames requested number of frames that can be filled without blocking
Phil Burk3316d5e2017-02-15 11:23:01 -08001185 * @return actual buffer size in frames or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001186 */
Phil Burke2155ef2017-02-24 13:50:29 -08001187AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001188 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001189
1190/**
1191 * Query the maximum number of frames that can be filled without blocking.
1192 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001193 * Available since API level 26.
1194 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001195 * @param stream reference provided by AAudioStreamBuilder_openStream()
1196 * @return buffer size in frames.
Phil Burk5ed503c2017-02-01 09:38:15 -08001197 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001198AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001199
1200/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001201 * Query the number of frames that the application should read or write at
1202 * one time for optimal performance. It is OK if an application writes
1203 * a different number of frames. But the buffer size may need to be larger
1204 * in order to avoid underruns or overruns.
Phil Burk5ed503c2017-02-01 09:38:15 -08001205 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001206 * Note that this may or may not match the actual device burst size.
1207 * For some endpoints, the burst size can vary dynamically.
1208 * But these tend to be devices with high latency.
1209 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001210 * Available since API level 26.
1211 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001212 * @param stream reference provided by AAudioStreamBuilder_openStream()
1213 * @return burst size
Phil Burk5ed503c2017-02-01 09:38:15 -08001214 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001215AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001216
1217/**
1218 * Query maximum buffer capacity in frames.
1219 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001220 * Available since API level 26.
1221 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001222 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001223 * @return buffer capacity in frames
Phil Burk5ed503c2017-02-01 09:38:15 -08001224 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001225AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001226
1227/**
Phil Burke057ca92017-03-28 11:31:34 -07001228 * Query the size of the buffer that will be passed to the dataProc callback
1229 * in the numFrames parameter.
1230 *
1231 * This call can be used if the application needs to know the value of numFrames before
1232 * the stream is started. This is not normally necessary.
1233 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001234 * If a specific size was requested by calling
1235 * AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size.
Phil Burke057ca92017-03-28 11:31:34 -07001236 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001237 * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001238 * return the size chosen by AAudio, or {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -07001239 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001240 * {@link #AAUDIO_UNSPECIFIED} indicates that the callback buffer size for this stream
Phil Burke057ca92017-03-28 11:31:34 -07001241 * may vary from one dataProc callback to the next.
1242 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001243 * Available since API level 26.
1244 *
Phil Burke057ca92017-03-28 11:31:34 -07001245 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001246 * @return callback buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -07001247 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001248AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001249
1250/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001251 * An XRun is an Underrun or an Overrun.
1252 * During playing, an underrun will occur if the stream is not written in time
1253 * and the system runs out of valid data.
1254 * During recording, an overrun will occur if the stream is not read in time
1255 * and there is no place to put the incoming data so it is discarded.
1256 *
1257 * An underrun or overrun can cause an audible "pop" or "glitch".
1258 *
Phil Burk068c10f2017-05-08 16:36:41 -07001259 * Note that some INPUT devices may not support this function.
1260 * In that case a 0 will always be returned.
1261 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001262 * Available since API level 26.
1263 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001264 * @param stream reference provided by AAudioStreamBuilder_openStream()
1265 * @return the underrun or overrun count
Phil Burk5ed503c2017-02-01 09:38:15 -08001266 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001267AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001268
1269/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001270 * Available since API level 26.
1271 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001272 * @param stream reference provided by AAudioStreamBuilder_openStream()
1273 * @return actual sample rate
Phil Burk5ed503c2017-02-01 09:38:15 -08001274 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001275AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001276
1277/**
Phil Burk20523ed2017-04-24 17:04:01 -07001278 * A stream has one or more channels of data.
1279 * A frame will contain one sample for each channel.
1280 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001281 * Available since API level 26.
1282 *
Phil Burk20523ed2017-04-24 17:04:01 -07001283 * @param stream reference provided by AAudioStreamBuilder_openStream()
1284 * @return actual number of channels
1285 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001286AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -07001287
1288/**
Phil Burke74240d2017-08-03 15:25:43 -07001289 * Identical to AAudioStream_getChannelCount().
1290 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001291 * Available since API level 26.
1292 *
Phil Burke74240d2017-08-03 15:25:43 -07001293 * @param stream reference provided by AAudioStreamBuilder_openStream()
1294 * @return actual number of samples frame
1295 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001296AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -07001297
1298/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001299 * Available since API level 26.
1300 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001301 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke2155ef2017-02-24 13:50:29 -08001302 * @return actual device ID
Phil Burk5ed503c2017-02-01 09:38:15 -08001303 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001304AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001305
1306/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001307 * Available since API level 26.
1308 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001309 * @param stream reference provided by AAudioStreamBuilder_openStream()
1310 * @return actual data format
Phil Burk5ed503c2017-02-01 09:38:15 -08001311 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001312AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001313
1314/**
1315 * Provide actual sharing mode.
Elliott Hughes64a3b062019-10-29 10:09:30 -07001316 *
1317 * Available since API level 26.
1318 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001319 * @param stream reference provided by AAudioStreamBuilder_openStream()
1320 * @return actual sharing mode
Phil Burk5ed503c2017-02-01 09:38:15 -08001321 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001322AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream)
1323 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001324
1325/**
Phil Burke2fbb592017-05-01 15:05:52 -07001326 * Get the performance mode used by the stream.
1327 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001328 * Available since API level 26.
1329 *
Phil Burke2fbb592017-05-01 15:05:52 -07001330 * @param stream reference provided by AAudioStreamBuilder_openStream()
1331 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001332AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream)
1333 __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -07001334
1335/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001336 * Available since API level 26.
1337 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001338 * @param stream reference provided by AAudioStreamBuilder_openStream()
1339 * @return direction
Phil Burk5ed503c2017-02-01 09:38:15 -08001340 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001341AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001342
1343/**
1344 * Passes back the number of frames that have been written since the stream was created.
Phil Burk8149eed2018-05-24 14:09:46 -07001345 * For an output stream, this will be advanced by the application calling write()
1346 * or by a data callback.
Phil Burk3316d5e2017-02-15 11:23:01 -08001347 * For an input stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -08001348 *
1349 * The frame position is monotonically increasing.
1350 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001351 * Available since API level 26.
1352 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001353 * @param stream reference provided by AAudioStreamBuilder_openStream()
1354 * @return frames written
Phil Burk5ed503c2017-02-01 09:38:15 -08001355 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001356AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001357
1358/**
1359 * Passes back the number of frames that have been read since the stream was created.
Phil Burk3316d5e2017-02-15 11:23:01 -08001360 * For an output stream, this will be advanced by the endpoint.
Phil Burk8149eed2018-05-24 14:09:46 -07001361 * For an input stream, this will be advanced by the application calling read()
1362 * or by a data callback.
Phil Burk5ed503c2017-02-01 09:38:15 -08001363 *
1364 * The frame position is monotonically increasing.
1365 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001366 * Available since API level 26.
1367 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001368 * @param stream reference provided by AAudioStreamBuilder_openStream()
1369 * @return frames read
Phil Burk5ed503c2017-02-01 09:38:15 -08001370 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001371AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001372
1373/**
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001374 * Passes back the session ID associated with this stream.
1375 *
1376 * The session ID can be used to associate a stream with effects processors.
1377 * The effects are controlled using the Android AudioEffect Java API.
1378 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001379 * If AAudioStreamBuilder_setSessionId() was
1380 * called with {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001381 * then a new session ID should be allocated once when the stream is opened.
1382 *
1383 * If AAudioStreamBuilder_setSessionId() was called with a previously allocated
1384 * session ID then that value should be returned.
1385 *
1386 * If AAudioStreamBuilder_setSessionId() was not called then this function should
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001387 * return {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001388 *
1389 * The sessionID for a stream should not change once the stream has been opened.
1390 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001391 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001392 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001393 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001394 * @return session ID or {@link #AAUDIO_SESSION_ID_NONE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001395 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001396AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001397
1398/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001399 * Passes back the time at which a particular frame was presented.
1400 * This can be used to synchronize audio with video or MIDI.
1401 * It can also be used to align a recorded stream with a playback stream.
1402 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001403 * Timestamps are only valid when the stream is in {@link #AAUDIO_STREAM_STATE_STARTED}.
1404 * {@link #AAUDIO_ERROR_INVALID_STATE} will be returned if the stream is not started.
Phil Burk5ed503c2017-02-01 09:38:15 -08001405 * Note that because requestStart() is asynchronous, timestamps will not be valid until
1406 * a short time after calling requestStart().
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001407 * So {@link #AAUDIO_ERROR_INVALID_STATE} should not be considered a fatal error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001408 * Just try calling again later.
1409 *
1410 * If an error occurs, then the position and time will not be modified.
1411 *
1412 * The position and time passed back are monotonically increasing.
1413 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001414 * Available since API level 26.
1415 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001416 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burkec159502017-07-25 17:33:47 -07001417 * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
Phil Burk5ed503c2017-02-01 09:38:15 -08001418 * @param framePosition pointer to a variable to receive the position
1419 * @param timeNanoseconds pointer to a variable to receive the time
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001420 * @return {@link #AAUDIO_OK} or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001421 */
Phil Burke2155ef2017-02-24 13:50:29 -08001422AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001423 clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001424
Phil Burk361b1422017-12-20 14:24:16 -08001425/**
1426 * Return the use case for the stream.
1427 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001428 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001429 *
Phil Burk361b1422017-12-20 14:24:16 -08001430 * @param stream reference provided by AAudioStreamBuilder_openStream()
1431 * @return frames read
1432 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001433AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001434
1435/**
1436 * Return the content type for the stream.
1437 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001438 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001439 *
Phil Burk361b1422017-12-20 14:24:16 -08001440 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001441 * @return content type, for example {@link #AAUDIO_CONTENT_TYPE_MUSIC}
Phil Burk361b1422017-12-20 14:24:16 -08001442 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001443AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream)
1444 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001445
1446/**
1447 * Return the input preset for the stream.
1448 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001449 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001450 *
Phil Burk361b1422017-12-20 14:24:16 -08001451 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001452 * @return input preset, for example {@link #AAUDIO_INPUT_PRESET_CAMCORDER}
Phil Burk361b1422017-12-20 14:24:16 -08001453 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001454AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream)
1455 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001456
Kevin Rocard68646ba2019-03-20 13:26:49 -07001457/**
1458 * Return the policy that determines whether the audio may or may not be captured
1459 * by other apps or the system.
1460 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001461 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -07001462 *
1463 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001464 * @return the allowed capture policy, for example {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}
Kevin Rocard68646ba2019-03-20 13:26:49 -07001465 */
1466AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
1467 AAudioStream* stream) __INTRODUCED_IN(29);
1468
Eric Laurentd17c8502019-10-24 15:58:35 -07001469
1470/**
1471 * Return whether this input stream is marked as privacy sensitive or not.
1472 *
1473 * See {@link #AAudioStreamBuilder_setPrivacySensitive()}.
1474 *
1475 * Added in API level 30.
1476 *
1477 * @param stream reference provided by AAudioStreamBuilder_openStream()
1478 * @return true if privacy sensitive, false otherwise
1479 */
1480AAUDIO_API bool AAudioStream_isPrivacySensitive(AAudioStream* stream)
1481 __INTRODUCED_IN(30);
1482
Phil Burk5ed503c2017-02-01 09:38:15 -08001483#ifdef __cplusplus
1484}
1485#endif
1486
1487#endif //AAUDIO_AAUDIO_H
Phil Burka45be8b2017-04-05 14:45:48 -07001488
1489/** @} */