blob: 2f43b2282d862bbc36313035f70384773feaeeac [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
Hayden Gomes3e8bbb92020-01-10 13:37:05 -0800230#define AAUDIO_SYSTEM_USAGE_OFFSET 1000
231
Phil Burk361b1422017-12-20 14:24:16 -0800232/**
233 * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for.
234 * This information is used by certain platforms or routing policies
235 * to make more refined volume or routing decisions.
236 *
Kevin Rocard68646ba2019-03-20 13:26:49 -0700237 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
238 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700239 *
240 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800241 */
242enum {
243 /**
244 * Use this for streaming media, music performance, video, podcasts, etcetera.
245 */
246 AAUDIO_USAGE_MEDIA = 1,
247
248 /**
249 * Use this for voice over IP, telephony, etcetera.
250 */
251 AAUDIO_USAGE_VOICE_COMMUNICATION = 2,
252
253 /**
254 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.
255 */
256 AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
257
258 /**
259 * Use this to demand the users attention.
260 */
261 AAUDIO_USAGE_ALARM = 4,
262
263 /**
264 * Use this for notifying the user when a message has arrived or some
265 * other background event has occured.
266 */
267 AAUDIO_USAGE_NOTIFICATION = 5,
268
269 /**
270 * Use this when the phone rings.
271 */
272 AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6,
273
274 /**
275 * Use this to attract the users attention when, for example, the battery is low.
276 */
277 AAUDIO_USAGE_NOTIFICATION_EVENT = 10,
278
279 /**
280 * Use this for screen readers, etcetera.
281 */
282 AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
283
284 /**
285 * Use this for driving or navigation directions.
286 */
287 AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
288
289 /**
290 * Use this for user interface sounds, beeps, etcetera.
291 */
292 AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
293
294 /**
295 * Use this for game audio and sound effects.
296 */
297 AAUDIO_USAGE_GAME = 14,
298
299 /**
300 * Use this for audio responses to user queries, audio instructions or help utterances.
301 */
Hayden Gomes3e8bbb92020-01-10 13:37:05 -0800302 AAUDIO_USAGE_ASSISTANT = 16,
303
304 /**
305 * Use this in case of playing sounds in an emergency.
306 * Privileged MODIFY_AUDIO_ROUTING permission required.
307 */
308 AAUDIO_SYSTEM_USAGE_EMERGENCY = AAUDIO_SYSTEM_USAGE_OFFSET,
309
310 /**
311 * Use this for safety sounds and alerts, for example backup camera obstacle detection.
312 * Privileged MODIFY_AUDIO_ROUTING permission required.
313 */
314 AAUDIO_SYSTEM_USAGE_SAFETY = AAUDIO_SYSTEM_USAGE_OFFSET + 1,
315
316 /**
317 * Use this for vehicle status alerts and information, for example the check engine light.
318 * Privileged MODIFY_AUDIO_ROUTING permission required.
319 */
320 AAUDIO_SYSTEM_USAGE_VEHICLE_STATUS = AAUDIO_SYSTEM_USAGE_OFFSET + 2,
321
322 /**
323 * Use this for traffic announcements, etc.
324 * Privileged MODIFY_AUDIO_ROUTING permission required.
325 */
326 AAUDIO_SYSTEM_USAGE_ANNOUNCEMENT = AAUDIO_SYSTEM_USAGE_OFFSET + 3,
Phil Burk361b1422017-12-20 14:24:16 -0800327};
328typedef int32_t aaudio_usage_t;
329
330/**
331 * The CONTENT_TYPE attribute describes "what" you are playing.
332 * It expresses the general category of the content. This information is optional.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700333 * But in case it is known (for instance AAUDIO_CONTENT_TYPE_MOVIE for a
334 * movie streaming service or AAUDIO_CONTENT_TYPE_SPEECH for
Phil Burk361b1422017-12-20 14:24:16 -0800335 * an audio book application) this information might be used by the audio framework to
336 * enforce audio focus.
337 *
Kevin Rocard68646ba2019-03-20 13:26:49 -0700338 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
339 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700340 *
341 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800342 */
343enum {
344
345 /**
346 * Use this for spoken voice, audio books, etcetera.
347 */
348 AAUDIO_CONTENT_TYPE_SPEECH = 1,
349
350 /**
351 * Use this for pre-recorded or live music.
352 */
353 AAUDIO_CONTENT_TYPE_MUSIC = 2,
354
355 /**
356 * Use this for a movie or video soundtrack.
357 */
358 AAUDIO_CONTENT_TYPE_MOVIE = 3,
359
360 /**
361 * Use this for sound is designed to accompany a user action,
362 * such as a click or beep sound made when the user presses a button.
363 */
364 AAUDIO_CONTENT_TYPE_SONIFICATION = 4
365};
366typedef int32_t aaudio_content_type_t;
367
368/**
369 * Defines the audio source.
370 * An audio source defines both a default physical source of audio signal, and a recording
371 * configuration.
372 *
373 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700374 *
375 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800376 */
377enum {
378 /**
379 * Use this preset when other presets do not apply.
380 */
381 AAUDIO_INPUT_PRESET_GENERIC = 1,
382
383 /**
384 * Use this preset when recording video.
385 */
386 AAUDIO_INPUT_PRESET_CAMCORDER = 5,
387
388 /**
389 * Use this preset when doing speech recognition.
390 */
391 AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6,
392
393 /**
394 * Use this preset when doing telephony or voice messaging.
395 */
396 AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7,
397
398 /**
399 * Use this preset to obtain an input with no effects.
400 * Note that this input will not have automatic gain control
401 * so the recorded volume may be very low.
402 */
403 AAUDIO_INPUT_PRESET_UNPROCESSED = 9,
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800404
405 /**
406 * Use this preset for capturing audio meant to be processed in real time
407 * and played back for live performance (e.g karaoke).
408 * The capture path will minimize latency and coupling with playback path.
409 */
410 AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE = 10,
Phil Burk361b1422017-12-20 14:24:16 -0800411};
412typedef int32_t aaudio_input_preset_t;
413
Phil Burk8149eed2018-05-24 14:09:46 -0700414/**
Kevin Rocard68646ba2019-03-20 13:26:49 -0700415 * Specifying if audio may or may not be captured by other apps or the system.
416 *
417 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
418 * in the Android Java API.
419 *
420 * Added in API level 29.
421 */
422enum {
423 /**
424 * Indicates that the audio may be captured by any app.
425 *
426 * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*,
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700427 * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and {@link #AAUDIO_USAGE_ASSISTANT}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700428 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700429 * On {@link android.os.Build.VERSION_CODES#Q}, this means only {@link #AAUDIO_USAGE_MEDIA}
430 * and {@link #AAUDIO_USAGE_GAME} may be captured.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700431 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700432 * See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_ALL}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700433 */
434 AAUDIO_ALLOW_CAPTURE_BY_ALL = 1,
435 /**
436 * Indicates that the audio may only be captured by system apps.
437 *
438 * System apps can capture for many purposes like accessibility, user guidance...
439 * but have strong restriction. See
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700440 * {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_SYSTEM} for what the system apps
Kevin Rocard68646ba2019-03-20 13:26:49 -0700441 * can do with the capture audio.
442 */
443 AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2,
444 /**
445 * Indicates that the audio may not be recorded by any app, even if it is a system app.
446 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700447 * 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 -0700448 * provide significant and useful features for the user (eg. accessibility).
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700449 * See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_NONE}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700450 */
451 AAUDIO_ALLOW_CAPTURE_BY_NONE = 3,
452};
453
454typedef int32_t aaudio_allowed_capture_policy_t;
455
456/**
Phil Burk8149eed2018-05-24 14:09:46 -0700457 * These may be used with AAudioStreamBuilder_setSessionId().
458 *
459 * Added in API level 28.
460 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800461enum {
462 /**
463 * Do not allocate a session ID.
464 * Effects cannot be used with this stream.
465 * Default.
Phil Burk42452c02018-04-10 12:43:33 -0700466 *
467 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800468 */
469 AAUDIO_SESSION_ID_NONE = -1,
470
471 /**
472 * Allocate a session ID that can be used to attach and control
473 * effects using the Java AudioEffects API.
Phil Burk8149eed2018-05-24 14:09:46 -0700474 * Note that using this may result in higher latency.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800475 *
476 * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.
Phil Burk42452c02018-04-10 12:43:33 -0700477 *
478 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800479 */
480 AAUDIO_SESSION_ID_ALLOCATE = 0,
481};
482typedef int32_t aaudio_session_id_t;
483
Phil Burke2155ef2017-02-24 13:50:29 -0800484typedef struct AAudioStreamStruct AAudioStream;
485typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder;
Phil Burk5ed503c2017-02-01 09:38:15 -0800486
Phil Burk5ed503c2017-02-01 09:38:15 -0800487#ifndef AAUDIO_API
Phil Burk3316d5e2017-02-15 11:23:01 -0800488#define AAUDIO_API /* export this symbol */
Phil Burk5ed503c2017-02-01 09:38:15 -0800489#endif
490
491// ============================================================
492// Audio System
493// ============================================================
494
495/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800496 * The text is the ASCII symbol corresponding to the returnCode,
497 * or an English message saying the returnCode is unrecognized.
498 * This is intended for developers to use when debugging.
499 * It is not for display to users.
500 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700501 * Available since API level 26.
502 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800503 * @return pointer to a text representation of an AAudio result code.
504 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700505AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800506
507/**
508 * The text is the ASCII symbol corresponding to the stream state,
509 * or an English message saying the state is unrecognized.
510 * This is intended for developers to use when debugging.
511 * It is not for display to users.
512 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700513 * Available since API level 26.
514 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800515 * @return pointer to a text representation of an AAudio state.
516 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700517AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state)
518 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800519
520// ============================================================
521// StreamBuilder
522// ============================================================
523
524/**
525 * Create a StreamBuilder that can be used to open a Stream.
526 *
527 * The deviceId is initially unspecified, meaning that the current default device will be used.
528 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700529 * The default direction is {@link #AAUDIO_DIRECTION_OUTPUT}.
530 * The default sharing mode is {@link #AAUDIO_SHARING_MODE_SHARED}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800531 * The data format, samplesPerFrames and sampleRate are unspecified and will be
532 * chosen by the device when it is opened.
533 *
534 * AAudioStreamBuilder_delete() must be called when you are done using the builder.
Elliott Hughes64a3b062019-10-29 10:09:30 -0700535 *
536 * Available since API level 26.
Phil Burk5ed503c2017-02-01 09:38:15 -0800537 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700538AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder)
539 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800540
541/**
542 * Request an audio device identified device using an ID.
Phil Burk5ed503c2017-02-01 09:38:15 -0800543 * On Android, for example, the ID could be obtained from the Java AudioManager.
544 *
Kevin Rocard6309d882019-03-20 13:26:49 -0700545 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED},
Phil Burke057ca92017-03-28 11:31:34 -0700546 * in which case the primary device will be used.
Phil Burk5ed503c2017-02-01 09:38:15 -0800547 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700548 * Available since API level 26.
549 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800550 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocard6309d882019-03-20 13:26:49 -0700551 * @param deviceId device identifier or {@link #AAUDIO_UNSPECIFIED}
Phil Burk5ed503c2017-02-01 09:38:15 -0800552 */
Phil Burke2155ef2017-02-24 13:50:29 -0800553AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700554 int32_t deviceId) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800555
556/**
Phil Burke057ca92017-03-28 11:31:34 -0700557 * Request a sample rate in Hertz.
558 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700559 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700560 * An optimal value will then be chosen when the stream is opened.
561 * After opening a stream with an unspecified value, the application must
562 * query for the actual value, which may vary by device.
563 *
564 * If an exact value is specified then an opened stream will use that value.
565 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700566 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700567 * Available since API level 26.
568 *
Phil Burke057ca92017-03-28 11:31:34 -0700569 * @param builder reference provided by AAudio_createStreamBuilder()
570 * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
Phil Burk5ed503c2017-02-01 09:38:15 -0800571 */
Phil Burke2155ef2017-02-24 13:50:29 -0800572AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700573 int32_t sampleRate) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800574
575/**
Phil Burk20523ed2017-04-24 17:04:01 -0700576 * Request a number of channels for the stream.
Phil Burke057ca92017-03-28 11:31:34 -0700577 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700578 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700579 * An optimal value will then be chosen when the stream is opened.
580 * After opening a stream with an unspecified value, the application must
581 * query for the actual value, which may vary by device.
Phil Burk5ed503c2017-02-01 09:38:15 -0800582 *
Phil Burk8f624892017-05-11 11:44:20 -0700583 * If an exact value is specified then an opened stream will use that value.
584 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700585 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700586 * Available since API level 26.
587 *
Phil Burke057ca92017-03-28 11:31:34 -0700588 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk20523ed2017-04-24 17:04:01 -0700589 * @param channelCount Number of channels desired.
Phil Burk5ed503c2017-02-01 09:38:15 -0800590 */
Phil Burk20523ed2017-04-24 17:04:01 -0700591AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700592 int32_t channelCount) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -0700593
594/**
Phil Burke74240d2017-08-03 15:25:43 -0700595 * Identical to AAudioStreamBuilder_setChannelCount().
596 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700597 * Available since API level 26.
598 *
Phil Burke74240d2017-08-03 15:25:43 -0700599 * @param builder reference provided by AAudio_createStreamBuilder()
600 * @param samplesPerFrame Number of samples in a frame.
601 */
602AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700603 int32_t samplesPerFrame) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -0700604
605/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700606 * Request a sample data format, for example {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burke057ca92017-03-28 11:31:34 -0700607 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700608 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700609 * An optimal value will then be chosen when the stream is opened.
610 * After opening a stream with an unspecified value, the application must
611 * query for the actual value, which may vary by device.
Phil Burke057ca92017-03-28 11:31:34 -0700612 *
Phil Burk8f624892017-05-11 11:44:20 -0700613 * If an exact value is specified then an opened stream will use that value.
614 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700615 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700616 * Available since API level 26.
617 *
Phil Burke057ca92017-03-28 11:31:34 -0700618 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700619 * @param format common formats are {@link #AAUDIO_FORMAT_PCM_FLOAT} and
620 * {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800621 */
Phil Burke2155ef2017-02-24 13:50:29 -0800622AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700623 aaudio_format_t format) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800624
625/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800626 * Request a mode for sharing the device.
Phil Burke057ca92017-03-28 11:31:34 -0700627 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700628 * The default, if you do not call this function, is {@link #AAUDIO_SHARING_MODE_SHARED}.
Phil Burke057ca92017-03-28 11:31:34 -0700629 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800630 * The requested sharing mode may not be available.
Phil Burke057ca92017-03-28 11:31:34 -0700631 * The application can query for the actual mode after the stream is opened.
Phil Burk5ed503c2017-02-01 09:38:15 -0800632 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700633 * Available since API level 26.
634 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800635 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700636 * @param sharingMode {@link #AAUDIO_SHARING_MODE_SHARED} or {@link #AAUDIO_SHARING_MODE_EXCLUSIVE}
Phil Burk5ed503c2017-02-01 09:38:15 -0800637 */
Phil Burke2155ef2017-02-24 13:50:29 -0800638AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700639 aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800640
641/**
Phil Burke057ca92017-03-28 11:31:34 -0700642 * Request the direction for a stream.
643 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700644 * The default, if you do not call this function, is {@link #AAUDIO_DIRECTION_OUTPUT}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800645 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700646 * Available since API level 26.
647 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800648 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700649 * @param direction {@link #AAUDIO_DIRECTION_OUTPUT} or {@link #AAUDIO_DIRECTION_INPUT}
Phil Burk5ed503c2017-02-01 09:38:15 -0800650 */
Phil Burke2155ef2017-02-24 13:50:29 -0800651AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700652 aaudio_direction_t direction) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800653
654/**
Phil Burke057ca92017-03-28 11:31:34 -0700655 * Set the requested buffer capacity in frames.
Phil Burk3df348f2017-02-08 11:41:55 -0800656 * The final AAudioStream capacity may differ, but will probably be at least this big.
657 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700658 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk3df348f2017-02-08 11:41:55 -0800659 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700660 * Available since API level 26.
661 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800662 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700663 * @param numFrames the desired buffer capacity in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burk3df348f2017-02-08 11:41:55 -0800664 */
Phil Burke2155ef2017-02-24 13:50:29 -0800665AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700666 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700667
668/**
669 * Set the requested performance mode.
670 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700671 * Supported modes are {@link #AAUDIO_PERFORMANCE_MODE_NONE},
672 * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING} * and {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}.
Phil Burk8149eed2018-05-24 14:09:46 -0700673 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700674 * The default, if you do not call this function, is {@link #AAUDIO_PERFORMANCE_MODE_NONE}.
Phil Burke2fbb592017-05-01 15:05:52 -0700675 *
Phil Burk8149eed2018-05-24 14:09:46 -0700676 * You may not get the mode you requested.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700677 * You can call AAudioStream_getPerformanceMode()
678 * to find out the final mode for the stream.
Phil Burk8149eed2018-05-24 14:09:46 -0700679 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700680 * Available since API level 26.
681 *
Phil Burke2fbb592017-05-01 15:05:52 -0700682 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700683 * @param mode the desired performance mode, eg. {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}
Phil Burke2fbb592017-05-01 15:05:52 -0700684 */
685AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700686 aaudio_performance_mode_t mode) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700687
Phil Burke057ca92017-03-28 11:31:34 -0700688/**
Phil Burk361b1422017-12-20 14:24:16 -0800689 * Set the intended use case for the stream.
690 *
691 * The AAudio system will use this information to optimize the
692 * behavior of the stream.
693 * This could, for example, affect how volume and focus is handled for the stream.
694 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700695 * The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}.
Phil Burk361b1422017-12-20 14:24:16 -0800696 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700697 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700698 *
Phil Burk361b1422017-12-20 14:24:16 -0800699 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700700 * @param usage the desired usage, eg. {@link #AAUDIO_USAGE_GAME}
Phil Burk361b1422017-12-20 14:24:16 -0800701 */
702AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700703 aaudio_usage_t usage) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800704
705/**
706 * Set the type of audio data that the stream will carry.
707 *
708 * The AAudio system will use this information to optimize the
709 * behavior of the stream.
710 * This could, for example, affect whether a stream is paused when a notification occurs.
711 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700712 * The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}.
Phil Burk361b1422017-12-20 14:24:16 -0800713 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700714 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700715 *
Phil Burk361b1422017-12-20 14:24:16 -0800716 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700717 * @param contentType the type of audio data, eg. {@link #AAUDIO_CONTENT_TYPE_SPEECH}
Phil Burk361b1422017-12-20 14:24:16 -0800718 */
719AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700720 aaudio_content_type_t contentType) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800721
722/**
723 * Set the input (capture) preset for the stream.
724 *
725 * The AAudio system will use this information to optimize the
726 * behavior of the stream.
727 * This could, for example, affect which microphones are used and how the
728 * recorded data is processed.
729 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700730 * The default, if you do not call this function, is {@link #AAUDIO_INPUT_PRESET_VOICE_RECOGNITION}.
Phil Burkeaef9b92018-01-18 09:09:42 -0800731 * That is because VOICE_RECOGNITION is the preset with the lowest latency
732 * on many platforms.
Phil Burk361b1422017-12-20 14:24:16 -0800733 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700734 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700735 *
Phil Burk361b1422017-12-20 14:24:16 -0800736 * @param builder reference provided by AAudio_createStreamBuilder()
737 * @param inputPreset the desired configuration for recording
738 */
739AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700740 aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800741
Kevin Rocard68646ba2019-03-20 13:26:49 -0700742/**
743 * Specify whether this stream audio may or may not be captured by other apps or the system.
744 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700745 * The default is {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700746 *
747 * Note that an application can also set its global policy, in which case the most restrictive
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700748 * policy is always applied. See {@link android.media.AudioAttributes#setAllowedCapturePolicy(int)}
Kevin Rocard68646ba2019-03-20 13:26:49 -0700749 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700750 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700751 *
752 * @param builder reference provided by AAudio_createStreamBuilder()
Glenn Kastend3080c32019-10-24 09:54:56 -0700753 * @param capturePolicy the desired level of opt-out from being captured.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700754 */
755AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder,
756 aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29);
757
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800758/** Set the requested session ID.
759 *
760 * The session ID can be used to associate a stream with effects processors.
761 * The effects are controlled using the Android AudioEffect Java API.
762 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700763 * The default, if you do not call this function, is {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800764 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700765 * If set to {@link #AAUDIO_SESSION_ID_ALLOCATE} then a session ID will be allocated
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800766 * when the stream is opened.
767 *
768 * The allocated session ID can be obtained by calling AAudioStream_getSessionId()
769 * and then used with this function when opening another stream.
770 * This allows effects to be shared between streams.
771 *
Phil Burk8149eed2018-05-24 14:09:46 -0700772 * Session IDs from AAudio can be used with the Android Java APIs and vice versa.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800773 * So a session ID from an AAudio stream can be passed to Java
774 * and effects applied using the Java AudioEffect API.
775 *
Phil Burk8149eed2018-05-24 14:09:46 -0700776 * Note that allocating or setting a session ID may result in a stream with higher latency.
777 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800778 * Allocated session IDs will always be positive and nonzero.
779 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700780 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700781 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800782 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700783 * @param sessionId an allocated sessionID or {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800784 */
785AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700786 aaudio_session_id_t sessionId) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800787
Eric Laurentd17c8502019-10-24 15:58:35 -0700788
789/** Indicates whether this input stream must be marked as privacy sensitive or not.
790 *
791 * When true, this input stream is privacy sensitive and any concurrent capture
792 * is not permitted.
793 *
794 * This is off (false) by default except when the input preset is {@link #AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION}
795 * or {@link #AAUDIO_INPUT_PRESET_CAMCORDER}.
796 *
797 * Always takes precedence over default from input preset when set explicitly.
798 *
799 * Only relevant if the stream direction is {@link #AAUDIO_DIRECTION_INPUT}.
800 *
801 * Added in API level 30.
802 *
803 * @param builder reference provided by AAudio_createStreamBuilder()
804 * @param privacySensitive true if capture from this stream must be marked as privacy sensitive,
805 * false otherwise.
806 */
807AAUDIO_API void AAudioStreamBuilder_setPrivacySensitive(AAudioStreamBuilder* builder,
808 bool privacySensitive) __INTRODUCED_IN(30);
809
Phil Burk361b1422017-12-20 14:24:16 -0800810/**
Phil Burke057ca92017-03-28 11:31:34 -0700811 * Return one of these values from the data callback function.
812 */
813enum {
814
815 /**
816 * Continue calling the callback.
817 */
818 AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
819
820 /**
821 * Stop calling the callback.
822 *
823 * The application will still need to call AAudioStream_requestPause()
824 * or AAudioStream_requestStop().
825 */
826 AAUDIO_CALLBACK_RESULT_STOP,
827
828};
829typedef int32_t aaudio_data_callback_result_t;
830
831/**
832 * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
833 *
834 * For an output stream, this function should render and write numFrames of data
835 * in the streams current data format to the audioData buffer.
836 *
837 * For an input stream, this function should read and process numFrames of data
838 * from the audioData buffer.
839 *
Phil Burked0a3fe2017-12-05 14:27:43 -0800840 * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or
841 * AAudioStream_write() on the stream that is making the callback.
842 *
843 * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback()
844 * is called.
845 *
846 * Also note that this callback function should be considered a "real-time" function.
Phil Burke057ca92017-03-28 11:31:34 -0700847 * It must not do anything that could cause an unbounded delay because that can cause the
848 * audio to glitch or pop.
849 *
850 * These are things the function should NOT do:
851 * <ul>
852 * <li>allocate memory using, for example, malloc() or new</li>
853 * <li>any file operations such as opening, closing, reading or writing</li>
854 * <li>any network operations such as streaming</li>
855 * <li>use any mutexes or other synchronization primitives</li>
856 * <li>sleep</li>
Phil Burked0a3fe2017-12-05 14:27:43 -0800857 * <li>stop or close the stream</li>
Phil Burk8149eed2018-05-24 14:09:46 -0700858 * <li>AAudioStream_read()</li>
859 * <li>AAudioStream_write()</li>
860 * </ul>
861 *
862 * The following are OK to call from the data callback:
863 * <ul>
864 * <li>AAudioStream_get*()</li>
865 * <li>AAudio_convertResultToText()</li>
Phil Burke057ca92017-03-28 11:31:34 -0700866 * </ul>
867 *
868 * If you need to move data, eg. MIDI commands, in or out of the callback function then
869 * we recommend the use of non-blocking techniques such as an atomic FIFO.
870 *
871 * @param stream reference provided by AAudioStreamBuilder_openStream()
872 * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
873 * @param audioData a pointer to the audio data
Phil Burked0a3fe2017-12-05 14:27:43 -0800874 * @param numFrames the number of frames to be processed, which can vary
Phil Burke057ca92017-03-28 11:31:34 -0700875 * @return AAUDIO_CALLBACK_RESULT_*
876 */
877typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
878 AAudioStream *stream,
879 void *userData,
880 void *audioData,
881 int32_t numFrames);
882
883/**
884 * Request that AAudio call this functions when the stream is running.
885 *
886 * Note that when using this callback, the audio data will be passed in or out
887 * of the function as an argument.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700888 * So you cannot call AAudioStream_write() or AAudioStream_read()
889 * on the same stream that has an active data callback.
Phil Burke057ca92017-03-28 11:31:34 -0700890 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700891 * The callback function will start being called after AAudioStream_requestStart()
892 * is called.
Phil Burke057ca92017-03-28 11:31:34 -0700893 * It will stop being called after AAudioStream_requestPause() or
894 * AAudioStream_requestStop() is called.
895 *
896 * This callback function will be called on a real-time thread owned by AAudio. See
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700897 * {@link #AAudioStream_dataCallback} for more information.
Phil Burke057ca92017-03-28 11:31:34 -0700898 *
899 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
900 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700901 * Available since API level 26.
902 *
Phil Burke057ca92017-03-28 11:31:34 -0700903 * @param builder reference provided by AAudio_createStreamBuilder()
904 * @param callback pointer to a function that will process audio data.
905 * @param userData pointer to an application data structure that will be passed
906 * to the callback functions.
907 */
908AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700909 AAudioStream_dataCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -0700910
911/**
912 * Set the requested data callback buffer size in frames.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700913 * See {@link #AAudioStream_dataCallback}.
Phil Burke057ca92017-03-28 11:31:34 -0700914 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700915 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -0700916 *
917 * For the lowest possible latency, do not call this function. AAudio will then
918 * call the dataProc callback function with whatever size is optimal.
919 * That size may vary from one callback to another.
920 *
921 * Only use this function if the application requires a specific number of frames for processing.
922 * The application might, for example, be using an FFT that requires
923 * a specific power-of-two sized buffer.
924 *
925 * AAudio may need to add additional buffering in order to adapt between the internal
926 * buffer size and the requested buffer size.
927 *
928 * If you do call this function then the requested size should be less than
929 * half the buffer capacity, to allow double buffering.
930 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700931 * Available since API level 26.
932 *
Phil Burke057ca92017-03-28 11:31:34 -0700933 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700934 * @param numFrames the desired buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -0700935 */
936AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700937 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -0700938
939/**
940 * Prototype for the callback function that is passed to
941 * AAudioStreamBuilder_setErrorCallback().
942 *
Phil Burk8149eed2018-05-24 14:09:46 -0700943 * The following may NOT be called from the error callback:
944 * <ul>
945 * <li>AAudioStream_requestStop()</li>
946 * <li>AAudioStream_requestPause()</li>
947 * <li>AAudioStream_close()</li>
948 * <li>AAudioStream_waitForStateChange()</li>
949 * <li>AAudioStream_read()</li>
950 * <li>AAudioStream_write()</li>
951 * </ul>
952 *
953 * The following are OK to call from the error callback:
954 * <ul>
955 * <li>AAudioStream_get*()</li>
956 * <li>AAudio_convertResultToText()</li>
957 * </ul>
958 *
Phil Burke057ca92017-03-28 11:31:34 -0700959 * @param stream reference provided by AAudioStreamBuilder_openStream()
960 * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
961 * @param error an AAUDIO_ERROR_* value.
962 */
963typedef void (*AAudioStream_errorCallback)(
964 AAudioStream *stream,
965 void *userData,
966 aaudio_result_t error);
967
968/**
Phil Burked0a3fe2017-12-05 14:27:43 -0800969 * Request that AAudio call this function if any error occurs or the stream is disconnected.
Phil Burke057ca92017-03-28 11:31:34 -0700970 *
971 * 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 -0800972 * device to be unavailable or "disconnected".
Phil Burke057ca92017-03-28 11:31:34 -0700973 * Another possible cause of error would be a timeout or an unanticipated internal error.
974 *
Phil Burked0a3fe2017-12-05 14:27:43 -0800975 * In response, this function should signal or create another thread to stop
976 * and close this stream. The other thread could then reopen a stream on another device.
977 * Do not stop or close the stream, or reopen the new stream, directly from this callback.
978 *
979 * This callback will not be called because of actions by the application, such as stopping
980 * or closing a stream.
981 *
Phil Burke057ca92017-03-28 11:31:34 -0700982 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
983 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700984 * Available since API level 26.
985 *
Phil Burke057ca92017-03-28 11:31:34 -0700986 * @param builder reference provided by AAudio_createStreamBuilder()
987 * @param callback pointer to a function that will be called if an error occurs.
988 * @param userData pointer to an application data structure that will be passed
989 * to the callback functions.
990 */
991AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700992 AAudioStream_errorCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800993
994/**
995 * Open a stream based on the options in the StreamBuilder.
996 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700997 * AAudioStream_close() must be called when finished with the stream to recover
Phil Burk5ed503c2017-02-01 09:38:15 -0800998 * the memory and to free the associated resources.
999 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001000 * Available since API level 26.
1001 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001002 * @param builder reference provided by AAudio_createStreamBuilder()
1003 * @param stream pointer to a variable to receive the new stream reference
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001004 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001005 */
Phil Burke2155ef2017-02-24 13:50:29 -08001006AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001007 AAudioStream** stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001008
1009/**
1010 * Delete the resources associated with the StreamBuilder.
1011 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001012 * Available since API level 26.
1013 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001014 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001015 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001016 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001017AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder)
1018 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001019
1020// ============================================================
1021// Stream Control
1022// ============================================================
1023
Phil Burk8b4e05e2019-12-17 12:12:09 -08001024#if __ANDROID_API__ >= 30
Phil Burk5ed503c2017-02-01 09:38:15 -08001025/**
Phil Burk8b4e05e2019-12-17 12:12:09 -08001026 * Free the audio resources associated with a stream created by
1027 * AAudioStreamBuilder_openStream().
1028 * AAudioStream_close() should be called at some point after calling
1029 * this function.
Phil Burk5ed503c2017-02-01 09:38:15 -08001030 *
Phil Burk8b4e05e2019-12-17 12:12:09 -08001031 * After this call, the stream will be in {@link #AAUDIO_STREAM_STATE_CLOSING}
1032 *
1033 * @param stream reference provided by AAudioStreamBuilder_openStream()
1034 * @return {@link #AAUDIO_OK} or a negative error.
1035 */
1036AAUDIO_API aaudio_result_t AAudioStream_release(AAudioStream* stream) __INTRODUCED_IN(30);
1037#endif // __ANDROID_API__
1038
1039/**
1040 * Delete the internal data structures associated with the stream created
1041 * by AAudioStreamBuilder_openStream().
1042 *
1043 * If AAudioStream_release() has not been called then it will be called automatically.
Elliott Hughes64a3b062019-10-29 10:09:30 -07001044 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001045 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001046 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001047 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001048AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001049
1050/**
1051 * Asynchronously request to start playing the stream. For output streams, one should
1052 * write to the stream to fill the buffer before starting.
1053 * Otherwise it will underflow.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001054 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STARTING} or
1055 * {@link #AAUDIO_STREAM_STATE_STARTED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001056 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001057 * Available since API level 26.
1058 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001059 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001060 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001061 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001062AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001063
1064/**
1065 * Asynchronous request for the stream to pause.
1066 * Pausing a stream will freeze the data flow but not flush any buffers.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001067 * Use AAudioStream_requestStart() to resume playback after a pause.
1068 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_PAUSING} or
1069 * {@link #AAUDIO_STREAM_STATE_PAUSED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001070 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001071 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001072 * For input streams use AAudioStream_requestStop().
1073 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001074 * Available since API level 26.
1075 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001076 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001077 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001078 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001079AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001080
1081/**
1082 * Asynchronous request for the stream to flush.
1083 * Flushing will discard any pending data.
1084 * This call only works if the stream is pausing or paused. TODO review
1085 * Frame counters are not reset by a flush. They may be advanced.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001086 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_FLUSHING} or
1087 * {@link #AAUDIO_STREAM_STATE_FLUSHED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001088 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001089 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001090 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001091 * Available since API level 26.
1092 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001093 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001094 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001095 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001096AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001097
1098/**
1099 * Asynchronous request for the stream to stop.
1100 * The stream will stop after all of the data currently buffered has been played.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001101 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STOPPING} or
1102 * {@link #AAUDIO_STREAM_STATE_STOPPED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001103 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001104 * Available since API level 26.
1105 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001106 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001107 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001108 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001109AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001110
1111/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001112 * Query the current state of the client, eg. {@link #AAUDIO_STREAM_STATE_PAUSING}
Phil Burk5ed503c2017-02-01 09:38:15 -08001113 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001114 * This function will immediately return the state without updating the state.
1115 * If you want to update the client state based on the server state then
1116 * call AAudioStream_waitForStateChange() with currentState
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001117 * set to {@link #AAUDIO_STREAM_STATE_UNKNOWN} and a zero timeout.
Phil Burk3316d5e2017-02-15 11:23:01 -08001118 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001119 * Available since API level 26.
1120 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001121 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001122 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001123AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001124
1125/**
1126 * Wait until the current state no longer matches the input state.
1127 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001128 * This will update the current client state.
1129 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001130 * <pre><code>
Phil Burked0a3fe2017-12-05 14:27:43 -08001131 * aaudio_result_t result = AAUDIO_OK;
1132 * aaudio_stream_state_t currentState = AAudioStream_getState(stream);
1133 * aaudio_stream_state_t inputState = currentState;
1134 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) {
Phil Burk5ed503c2017-02-01 09:38:15 -08001135 * result = AAudioStream_waitForStateChange(
Phil Burked0a3fe2017-12-05 14:27:43 -08001136 * stream, inputState, &currentState, MY_TIMEOUT_NANOS);
1137 * inputState = currentState;
Phil Burk5ed503c2017-02-01 09:38:15 -08001138 * }
1139 * </code></pre>
1140 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001141 * Available since API level 26.
1142 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001143 * @param stream A reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001144 * @param inputState The state we want to avoid.
1145 * @param nextState Pointer to a variable that will be set to the new state.
1146 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001147 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001148 */
Phil Burke2155ef2017-02-24 13:50:29 -08001149AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001150 aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState,
1151 int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001152
1153// ============================================================
1154// Stream I/O
1155// ============================================================
1156
1157/**
1158 * Read data from the stream.
1159 *
1160 * The call will wait until the read is complete or until it runs out of time.
1161 * If timeoutNanos is zero then this call will not wait.
1162 *
1163 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1164 * Time will not stop if the thread is asleep.
1165 * So it will be implemented using CLOCK_BOOTTIME.
1166 *
1167 * This call is "strong non-blocking" unless it has to wait for data.
1168 *
Phil Burk8149eed2018-05-24 14:09:46 -07001169 * If the call times out then zero or a partial frame count will be returned.
1170 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001171 * Available since API level 26.
1172 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001173 * @param stream A stream created using AAudioStreamBuilder_openStream().
1174 * @param buffer The address of the first sample.
1175 * @param numFrames Number of frames to read. Only complete frames will be written.
1176 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Phil Burk3316d5e2017-02-15 11:23:01 -08001177 * @return The number of frames actually read or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001178 */
Phil Burke2155ef2017-02-24 13:50:29 -08001179AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001180 void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001181
1182/**
1183 * Write data to the stream.
1184 *
1185 * The call will wait until the write is complete or until it runs out of time.
1186 * If timeoutNanos is zero then this call will not wait.
1187 *
1188 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1189 * Time will not stop if the thread is asleep.
1190 * So it will be implemented using CLOCK_BOOTTIME.
1191 *
1192 * This call is "strong non-blocking" unless it has to wait for room in the buffer.
1193 *
Phil Burk8149eed2018-05-24 14:09:46 -07001194 * If the call times out then zero or a partial frame count will be returned.
1195 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001196 * Available since API level 26.
1197 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001198 * @param stream A stream created using AAudioStreamBuilder_openStream().
1199 * @param buffer The address of the first sample.
1200 * @param numFrames Number of frames to write. Only complete frames will be written.
1201 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1202 * @return The number of frames actually written or a negative error.
1203 */
Phil Burke2155ef2017-02-24 13:50:29 -08001204AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001205 const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001206
Phil Burk5ed503c2017-02-01 09:38:15 -08001207// ============================================================
1208// Stream - queries
1209// ============================================================
1210
Phil Burk5ed503c2017-02-01 09:38:15 -08001211/**
1212 * This can be used to adjust the latency of the buffer by changing
1213 * the threshold where blocking will occur.
Phil Burk3316d5e2017-02-15 11:23:01 -08001214 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
Phil Burk5ed503c2017-02-01 09:38:15 -08001215 * at run-time for each device.
1216 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001217 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
Phil Burk5ed503c2017-02-01 09:38:15 -08001218 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001219 * Note that you will probably not get the exact size you request.
Phil Burk8149eed2018-05-24 14:09:46 -07001220 * You can check the return value or call AAudioStream_getBufferSizeInFrames()
1221 * to see what the actual final size is.
Phil Burk3316d5e2017-02-15 11:23:01 -08001222 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001223 * Available since API level 26.
1224 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001225 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001226 * @param numFrames requested number of frames that can be filled without blocking
Phil Burk3316d5e2017-02-15 11:23:01 -08001227 * @return actual buffer size in frames or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001228 */
Phil Burke2155ef2017-02-24 13:50:29 -08001229AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001230 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001231
1232/**
1233 * Query the maximum number of frames that can be filled without blocking.
1234 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001235 * Available since API level 26.
1236 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001237 * @param stream reference provided by AAudioStreamBuilder_openStream()
1238 * @return buffer size in frames.
Phil Burk5ed503c2017-02-01 09:38:15 -08001239 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001240AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001241
1242/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001243 * Query the number of frames that the application should read or write at
1244 * one time for optimal performance. It is OK if an application writes
1245 * a different number of frames. But the buffer size may need to be larger
1246 * in order to avoid underruns or overruns.
Phil Burk5ed503c2017-02-01 09:38:15 -08001247 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001248 * Note that this may or may not match the actual device burst size.
1249 * For some endpoints, the burst size can vary dynamically.
1250 * But these tend to be devices with high latency.
1251 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001252 * Available since API level 26.
1253 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001254 * @param stream reference provided by AAudioStreamBuilder_openStream()
1255 * @return burst size
Phil Burk5ed503c2017-02-01 09:38:15 -08001256 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001257AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001258
1259/**
1260 * Query maximum buffer capacity in frames.
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()
Phil Burke057ca92017-03-28 11:31:34 -07001265 * @return buffer capacity in frames
Phil Burk5ed503c2017-02-01 09:38:15 -08001266 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001267AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001268
1269/**
Phil Burke057ca92017-03-28 11:31:34 -07001270 * Query the size of the buffer that will be passed to the dataProc callback
1271 * in the numFrames parameter.
1272 *
1273 * This call can be used if the application needs to know the value of numFrames before
1274 * the stream is started. This is not normally necessary.
1275 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001276 * If a specific size was requested by calling
1277 * AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size.
Phil Burke057ca92017-03-28 11:31:34 -07001278 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001279 * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001280 * return the size chosen by AAudio, or {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -07001281 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001282 * {@link #AAUDIO_UNSPECIFIED} indicates that the callback buffer size for this stream
Phil Burke057ca92017-03-28 11:31:34 -07001283 * may vary from one dataProc callback to the next.
1284 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001285 * Available since API level 26.
1286 *
Phil Burke057ca92017-03-28 11:31:34 -07001287 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001288 * @return callback buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -07001289 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001290AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001291
1292/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001293 * An XRun is an Underrun or an Overrun.
1294 * During playing, an underrun will occur if the stream is not written in time
1295 * and the system runs out of valid data.
1296 * During recording, an overrun will occur if the stream is not read in time
1297 * and there is no place to put the incoming data so it is discarded.
1298 *
1299 * An underrun or overrun can cause an audible "pop" or "glitch".
1300 *
Phil Burk068c10f2017-05-08 16:36:41 -07001301 * Note that some INPUT devices may not support this function.
1302 * In that case a 0 will always be returned.
1303 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001304 * Available since API level 26.
1305 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001306 * @param stream reference provided by AAudioStreamBuilder_openStream()
1307 * @return the underrun or overrun count
Phil Burk5ed503c2017-02-01 09:38:15 -08001308 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001309AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001310
1311/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001312 * Available since API level 26.
1313 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001314 * @param stream reference provided by AAudioStreamBuilder_openStream()
1315 * @return actual sample rate
Phil Burk5ed503c2017-02-01 09:38:15 -08001316 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001317AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001318
1319/**
Phil Burk20523ed2017-04-24 17:04:01 -07001320 * A stream has one or more channels of data.
1321 * A frame will contain one sample for each channel.
1322 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001323 * Available since API level 26.
1324 *
Phil Burk20523ed2017-04-24 17:04:01 -07001325 * @param stream reference provided by AAudioStreamBuilder_openStream()
1326 * @return actual number of channels
1327 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001328AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -07001329
1330/**
Phil Burke74240d2017-08-03 15:25:43 -07001331 * Identical to AAudioStream_getChannelCount().
1332 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001333 * Available since API level 26.
1334 *
Phil Burke74240d2017-08-03 15:25:43 -07001335 * @param stream reference provided by AAudioStreamBuilder_openStream()
1336 * @return actual number of samples frame
1337 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001338AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -07001339
1340/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001341 * Available since API level 26.
1342 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001343 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke2155ef2017-02-24 13:50:29 -08001344 * @return actual device ID
Phil Burk5ed503c2017-02-01 09:38:15 -08001345 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001346AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001347
1348/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001349 * Available since API level 26.
1350 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001351 * @param stream reference provided by AAudioStreamBuilder_openStream()
1352 * @return actual data format
Phil Burk5ed503c2017-02-01 09:38:15 -08001353 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001354AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001355
1356/**
1357 * Provide actual sharing mode.
Elliott Hughes64a3b062019-10-29 10:09:30 -07001358 *
1359 * Available since API level 26.
1360 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001361 * @param stream reference provided by AAudioStreamBuilder_openStream()
1362 * @return actual sharing mode
Phil Burk5ed503c2017-02-01 09:38:15 -08001363 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001364AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream)
1365 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001366
1367/**
Phil Burke2fbb592017-05-01 15:05:52 -07001368 * Get the performance mode used by the stream.
1369 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001370 * Available since API level 26.
1371 *
Phil Burke2fbb592017-05-01 15:05:52 -07001372 * @param stream reference provided by AAudioStreamBuilder_openStream()
1373 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001374AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream)
1375 __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -07001376
1377/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001378 * Available since API level 26.
1379 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001380 * @param stream reference provided by AAudioStreamBuilder_openStream()
1381 * @return direction
Phil Burk5ed503c2017-02-01 09:38:15 -08001382 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001383AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001384
1385/**
1386 * Passes back the number of frames that have been written since the stream was created.
Phil Burk8149eed2018-05-24 14:09:46 -07001387 * For an output stream, this will be advanced by the application calling write()
1388 * or by a data callback.
Phil Burk3316d5e2017-02-15 11:23:01 -08001389 * For an input stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -08001390 *
1391 * The frame position is monotonically increasing.
1392 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001393 * Available since API level 26.
1394 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001395 * @param stream reference provided by AAudioStreamBuilder_openStream()
1396 * @return frames written
Phil Burk5ed503c2017-02-01 09:38:15 -08001397 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001398AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001399
1400/**
1401 * Passes back the number of frames that have been read since the stream was created.
Phil Burk3316d5e2017-02-15 11:23:01 -08001402 * For an output stream, this will be advanced by the endpoint.
Phil Burk8149eed2018-05-24 14:09:46 -07001403 * For an input stream, this will be advanced by the application calling read()
1404 * or by a data callback.
Phil Burk5ed503c2017-02-01 09:38:15 -08001405 *
1406 * The frame position is monotonically increasing.
1407 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001408 * Available since API level 26.
1409 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001410 * @param stream reference provided by AAudioStreamBuilder_openStream()
1411 * @return frames read
Phil Burk5ed503c2017-02-01 09:38:15 -08001412 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001413AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001414
1415/**
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001416 * Passes back the session ID associated with this stream.
1417 *
1418 * The session ID can be used to associate a stream with effects processors.
1419 * The effects are controlled using the Android AudioEffect Java API.
1420 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001421 * If AAudioStreamBuilder_setSessionId() was
1422 * called with {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001423 * then a new session ID should be allocated once when the stream is opened.
1424 *
1425 * If AAudioStreamBuilder_setSessionId() was called with a previously allocated
1426 * session ID then that value should be returned.
1427 *
1428 * If AAudioStreamBuilder_setSessionId() was not called then this function should
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001429 * return {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001430 *
1431 * The sessionID for a stream should not change once the stream has been opened.
1432 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001433 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001434 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001435 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001436 * @return session ID or {@link #AAUDIO_SESSION_ID_NONE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001437 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001438AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001439
1440/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001441 * Passes back the time at which a particular frame was presented.
1442 * This can be used to synchronize audio with video or MIDI.
1443 * It can also be used to align a recorded stream with a playback stream.
1444 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001445 * Timestamps are only valid when the stream is in {@link #AAUDIO_STREAM_STATE_STARTED}.
1446 * {@link #AAUDIO_ERROR_INVALID_STATE} will be returned if the stream is not started.
Phil Burk5ed503c2017-02-01 09:38:15 -08001447 * Note that because requestStart() is asynchronous, timestamps will not be valid until
1448 * a short time after calling requestStart().
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001449 * So {@link #AAUDIO_ERROR_INVALID_STATE} should not be considered a fatal error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001450 * Just try calling again later.
1451 *
1452 * If an error occurs, then the position and time will not be modified.
1453 *
1454 * The position and time passed back are monotonically increasing.
1455 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001456 * Available since API level 26.
1457 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001458 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burkec159502017-07-25 17:33:47 -07001459 * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
Phil Burk5ed503c2017-02-01 09:38:15 -08001460 * @param framePosition pointer to a variable to receive the position
1461 * @param timeNanoseconds pointer to a variable to receive the time
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001462 * @return {@link #AAUDIO_OK} or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001463 */
Phil Burke2155ef2017-02-24 13:50:29 -08001464AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001465 clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001466
Phil Burk361b1422017-12-20 14:24:16 -08001467/**
1468 * Return the use case for the stream.
1469 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001470 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001471 *
Phil Burk361b1422017-12-20 14:24:16 -08001472 * @param stream reference provided by AAudioStreamBuilder_openStream()
1473 * @return frames read
1474 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001475AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001476
1477/**
1478 * Return the content type for the stream.
1479 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001480 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001481 *
Phil Burk361b1422017-12-20 14:24:16 -08001482 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001483 * @return content type, for example {@link #AAUDIO_CONTENT_TYPE_MUSIC}
Phil Burk361b1422017-12-20 14:24:16 -08001484 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001485AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream)
1486 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001487
1488/**
1489 * Return the input preset for the stream.
1490 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001491 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001492 *
Phil Burk361b1422017-12-20 14:24:16 -08001493 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001494 * @return input preset, for example {@link #AAUDIO_INPUT_PRESET_CAMCORDER}
Phil Burk361b1422017-12-20 14:24:16 -08001495 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001496AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream)
1497 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001498
Kevin Rocard68646ba2019-03-20 13:26:49 -07001499/**
1500 * Return the policy that determines whether the audio may or may not be captured
1501 * by other apps or the system.
1502 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001503 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -07001504 *
1505 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001506 * @return the allowed capture policy, for example {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}
Kevin Rocard68646ba2019-03-20 13:26:49 -07001507 */
1508AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
1509 AAudioStream* stream) __INTRODUCED_IN(29);
1510
Eric Laurentd17c8502019-10-24 15:58:35 -07001511
1512/**
1513 * Return whether this input stream is marked as privacy sensitive or not.
1514 *
1515 * See {@link #AAudioStreamBuilder_setPrivacySensitive()}.
1516 *
1517 * Added in API level 30.
1518 *
1519 * @param stream reference provided by AAudioStreamBuilder_openStream()
1520 * @return true if privacy sensitive, false otherwise
1521 */
1522AAUDIO_API bool AAudioStream_isPrivacySensitive(AAudioStream* stream)
1523 __INTRODUCED_IN(30);
1524
Phil Burk5ed503c2017-02-01 09:38:15 -08001525#ifdef __cplusplus
1526}
1527#endif
1528
1529#endif //AAUDIO_AAUDIO_H
Phil Burka45be8b2017-04-05 14:45:48 -07001530
1531/** @} */