blob: 22cf2547533dd1350410cda957e5f723b1abb2ba [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
Elliott Hughes9c1fca22020-06-12 09:53:12 -070032#include <stdbool.h>
33#include <stdint.h>
Phil Burk3316d5e2017-02-15 11:23:01 -080034#include <time.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080035
36#ifdef __cplusplus
37extern "C" {
38#endif
39
Phil Burka4eb0d82017-04-12 15:44:06 -070040/**
41 * This is used to represent a value that has not been specified.
Kevin Rocardfb7e8462019-03-20 13:26:49 -070042 * For example, an application could use {@link #AAUDIO_UNSPECIFIED} to indicate
Phil Burka4eb0d82017-04-12 15:44:06 -070043 * that is did not not care what the specific value of a parameter was
44 * and would accept whatever it was given.
45 */
46#define AAUDIO_UNSPECIFIED 0
Phil Burka4eb0d82017-04-12 15:44:06 -070047
48enum {
Phil Burk8149eed2018-05-24 14:09:46 -070049 /**
50 * Audio data will travel out of the device, for example through a speaker.
51 */
Phil Burka4eb0d82017-04-12 15:44:06 -070052 AAUDIO_DIRECTION_OUTPUT,
Phil Burk8149eed2018-05-24 14:09:46 -070053
54
55 /**
56 * Audio data will travel into the device, for example from a microphone.
57 */
Phil Burka4eb0d82017-04-12 15:44:06 -070058 AAUDIO_DIRECTION_INPUT
59};
60typedef int32_t aaudio_direction_t;
61
62enum {
63 AAUDIO_FORMAT_INVALID = -1,
64 AAUDIO_FORMAT_UNSPECIFIED = 0,
Phil Burk8149eed2018-05-24 14:09:46 -070065
66 /**
67 * This format uses the int16_t data type.
Phil Burk04e805b2018-03-27 09:13:53 -070068 * The maximum range of the data is -32768 (0x8000) to 32767 (0x7FFF).
Phil Burk8149eed2018-05-24 14:09:46 -070069 */
Phil Burka4eb0d82017-04-12 15:44:06 -070070 AAUDIO_FORMAT_PCM_I16,
Phil Burk8149eed2018-05-24 14:09:46 -070071
72 /**
73 * This format uses the float data type.
74 * The nominal range of the data is [-1.0f, 1.0f).
75 * Values outside that range may be clipped.
76 *
77 * See also 'floatData' at
78 * https://developer.android.com/reference/android/media/AudioTrack#write(float[],%20int,%20int,%20int)
79 */
Phil Burk04e805b2018-03-27 09:13:53 -070080 AAUDIO_FORMAT_PCM_FLOAT,
81
82 /**
83 * This format uses 24-bit samples packed into 3 bytes.
84 * The bytes are in the native endian order.
85 * The maximum range of the data is -8388608 (0x800000)
86 * to 8388607 (0x7FFFFF).
87 *
88 * Note that the lower precision bits may be ignored by the device.
89 *
90 * Available since API level 31.
91 */
92 AAUDIO_FORMAT_PCM_I24_PACKED,
93
94 /**
95 * This format uses 32-bit samples stored in an int32_t data type.
96 * The maximum range of the data is -2147483648 (0x80000000)
97 * to 2147483647 (0x7FFFFFFF).
98 *
99 * Note that the lower precision bits may be ignored by the device.
100 *
101 * Available since API level 31.
102 */
103 AAUDIO_FORMAT_PCM_I32
104
Phil Burka4eb0d82017-04-12 15:44:06 -0700105};
106typedef int32_t aaudio_format_t;
107
Phil Burk8149eed2018-05-24 14:09:46 -0700108/**
109 * These result codes are returned from AAudio functions to indicate success or failure.
110 * Note that error return codes may change in the future so applications should generally
111 * not rely on specific return codes.
112 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700113enum {
Phil Burk8149eed2018-05-24 14:09:46 -0700114 /**
115 * The call was successful.
116 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700117 AAUDIO_OK,
118 AAUDIO_ERROR_BASE = -900, // TODO review
Phil Burk8149eed2018-05-24 14:09:46 -0700119
120 /**
121 * The audio device was disconnected. This could occur, for example, when headphones
122 * are plugged in or unplugged. The stream cannot be used after the device is disconnected.
123 * Applications should stop and close the stream.
124 * If this error is received in an error callback then another thread should be
125 * used to stop and close the stream.
126 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700127 AAUDIO_ERROR_DISCONNECTED,
Phil Burk8149eed2018-05-24 14:09:46 -0700128
129 /**
130 * An invalid parameter was passed to AAudio.
131 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700132 AAUDIO_ERROR_ILLEGAL_ARGUMENT,
Phil Burk17fff382017-05-16 14:06:45 -0700133 // reserved
134 AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2,
Phil Burk8149eed2018-05-24 14:09:46 -0700135
136 /**
137 * The requested operation is not appropriate for the current state of AAudio.
138 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700139 AAUDIO_ERROR_INVALID_STATE,
Phil Burk17fff382017-05-16 14:06:45 -0700140 // reserved
141 // reserved
Phil Burk8149eed2018-05-24 14:09:46 -0700142 /* The server rejected the handle used to identify the stream.
143 */
Phil Burk17fff382017-05-16 14:06:45 -0700144 AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3,
145 // reserved
Phil Burk8149eed2018-05-24 14:09:46 -0700146
147 /**
148 * The function is not implemented for this stream.
149 */
Phil Burk17fff382017-05-16 14:06:45 -0700150 AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2,
Phil Burk8149eed2018-05-24 14:09:46 -0700151
152 /**
153 * A resource or information is unavailable.
154 * This could occur when an application tries to open too many streams,
155 * or a timestamp is not available.
156 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700157 AAUDIO_ERROR_UNAVAILABLE,
158 AAUDIO_ERROR_NO_FREE_HANDLES,
Phil Burk8149eed2018-05-24 14:09:46 -0700159
160 /**
161 * Memory could not be allocated.
162 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700163 AAUDIO_ERROR_NO_MEMORY,
Phil Burk8149eed2018-05-24 14:09:46 -0700164
165 /**
166 * A NULL pointer was passed to AAudio.
167 * Or a NULL pointer was detected internally.
168 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700169 AAUDIO_ERROR_NULL,
Phil Burk8149eed2018-05-24 14:09:46 -0700170
171 /**
172 * An operation took longer than expected.
173 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700174 AAUDIO_ERROR_TIMEOUT,
175 AAUDIO_ERROR_WOULD_BLOCK,
Phil Burk8149eed2018-05-24 14:09:46 -0700176
177 /**
178 * The requested data format is not supported.
179 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700180 AAUDIO_ERROR_INVALID_FORMAT,
Phil Burk8149eed2018-05-24 14:09:46 -0700181
182 /**
183 * A requested was out of range.
184 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700185 AAUDIO_ERROR_OUT_OF_RANGE,
Phil Burk8149eed2018-05-24 14:09:46 -0700186
187 /**
188 * The audio service was not available.
189 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700190 AAUDIO_ERROR_NO_SERVICE,
Phil Burk8149eed2018-05-24 14:09:46 -0700191
192 /**
193 * The requested sample rate was not supported.
194 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700195 AAUDIO_ERROR_INVALID_RATE
196};
197typedef int32_t aaudio_result_t;
198
199enum
200{
201 AAUDIO_STREAM_STATE_UNINITIALIZED = 0,
202 AAUDIO_STREAM_STATE_UNKNOWN,
203 AAUDIO_STREAM_STATE_OPEN,
204 AAUDIO_STREAM_STATE_STARTING,
205 AAUDIO_STREAM_STATE_STARTED,
206 AAUDIO_STREAM_STATE_PAUSING,
207 AAUDIO_STREAM_STATE_PAUSED,
208 AAUDIO_STREAM_STATE_FLUSHING,
209 AAUDIO_STREAM_STATE_FLUSHED,
210 AAUDIO_STREAM_STATE_STOPPING,
211 AAUDIO_STREAM_STATE_STOPPED,
212 AAUDIO_STREAM_STATE_CLOSING,
213 AAUDIO_STREAM_STATE_CLOSED,
214 AAUDIO_STREAM_STATE_DISCONNECTED
215};
216typedef int32_t aaudio_stream_state_t;
217
218
219enum {
220 /**
221 * This will be the only stream using a particular source or sink.
222 * This mode will provide the lowest possible latency.
223 * You should close EXCLUSIVE streams immediately when you are not using them.
224 */
225 AAUDIO_SHARING_MODE_EXCLUSIVE,
226 /**
227 * Multiple applications will be mixed by the AAudio Server.
228 * This will have higher latency than the EXCLUSIVE mode.
229 */
230 AAUDIO_SHARING_MODE_SHARED
231};
232typedef int32_t aaudio_sharing_mode_t;
233
Phil Burke2fbb592017-05-01 15:05:52 -0700234
235enum {
236 /**
237 * No particular performance needs. Default.
238 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800239 AAUDIO_PERFORMANCE_MODE_NONE = 10,
Phil Burke2fbb592017-05-01 15:05:52 -0700240
241 /**
Phil Burk8149eed2018-05-24 14:09:46 -0700242 * Extending battery life is more important than low latency.
Phil Burked0a3fe2017-12-05 14:27:43 -0800243 *
244 * This mode is not supported in input streams.
Phil Burk8149eed2018-05-24 14:09:46 -0700245 * For input, mode NONE will be used if this is requested.
Phil Burke2fbb592017-05-01 15:05:52 -0700246 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800247 AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
Phil Burke2fbb592017-05-01 15:05:52 -0700248
249 /**
Phil Burk8149eed2018-05-24 14:09:46 -0700250 * Reducing latency is more important than battery life.
Phil Burke2fbb592017-05-01 15:05:52 -0700251 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800252 AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
Phil Burke2fbb592017-05-01 15:05:52 -0700253};
254typedef int32_t aaudio_performance_mode_t;
255
Hayden Gomes3e8bbb92020-01-10 13:37:05 -0800256#define AAUDIO_SYSTEM_USAGE_OFFSET 1000
257
Phil Burk361b1422017-12-20 14:24:16 -0800258/**
259 * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for.
260 * This information is used by certain platforms or routing policies
261 * to make more refined volume or routing decisions.
262 *
Kevin Rocard68646ba2019-03-20 13:26:49 -0700263 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
264 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700265 *
266 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800267 */
268enum {
269 /**
270 * Use this for streaming media, music performance, video, podcasts, etcetera.
271 */
272 AAUDIO_USAGE_MEDIA = 1,
273
274 /**
275 * Use this for voice over IP, telephony, etcetera.
276 */
277 AAUDIO_USAGE_VOICE_COMMUNICATION = 2,
278
279 /**
280 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.
281 */
282 AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
283
284 /**
285 * Use this to demand the users attention.
286 */
287 AAUDIO_USAGE_ALARM = 4,
288
289 /**
290 * Use this for notifying the user when a message has arrived or some
291 * other background event has occured.
292 */
293 AAUDIO_USAGE_NOTIFICATION = 5,
294
295 /**
296 * Use this when the phone rings.
297 */
298 AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6,
299
300 /**
301 * Use this to attract the users attention when, for example, the battery is low.
302 */
303 AAUDIO_USAGE_NOTIFICATION_EVENT = 10,
304
305 /**
306 * Use this for screen readers, etcetera.
307 */
308 AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
309
310 /**
311 * Use this for driving or navigation directions.
312 */
313 AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
314
315 /**
316 * Use this for user interface sounds, beeps, etcetera.
317 */
318 AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
319
320 /**
321 * Use this for game audio and sound effects.
322 */
323 AAUDIO_USAGE_GAME = 14,
324
325 /**
326 * Use this for audio responses to user queries, audio instructions or help utterances.
327 */
Hayden Gomes3e8bbb92020-01-10 13:37:05 -0800328 AAUDIO_USAGE_ASSISTANT = 16,
329
330 /**
331 * Use this in case of playing sounds in an emergency.
332 * Privileged MODIFY_AUDIO_ROUTING permission required.
333 */
334 AAUDIO_SYSTEM_USAGE_EMERGENCY = AAUDIO_SYSTEM_USAGE_OFFSET,
335
336 /**
337 * Use this for safety sounds and alerts, for example backup camera obstacle detection.
338 * Privileged MODIFY_AUDIO_ROUTING permission required.
339 */
340 AAUDIO_SYSTEM_USAGE_SAFETY = AAUDIO_SYSTEM_USAGE_OFFSET + 1,
341
342 /**
343 * Use this for vehicle status alerts and information, for example the check engine light.
344 * Privileged MODIFY_AUDIO_ROUTING permission required.
345 */
346 AAUDIO_SYSTEM_USAGE_VEHICLE_STATUS = AAUDIO_SYSTEM_USAGE_OFFSET + 2,
347
348 /**
349 * Use this for traffic announcements, etc.
350 * Privileged MODIFY_AUDIO_ROUTING permission required.
351 */
352 AAUDIO_SYSTEM_USAGE_ANNOUNCEMENT = AAUDIO_SYSTEM_USAGE_OFFSET + 3,
Phil Burk361b1422017-12-20 14:24:16 -0800353};
354typedef int32_t aaudio_usage_t;
355
356/**
357 * The CONTENT_TYPE attribute describes "what" you are playing.
358 * It expresses the general category of the content. This information is optional.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700359 * But in case it is known (for instance AAUDIO_CONTENT_TYPE_MOVIE for a
360 * movie streaming service or AAUDIO_CONTENT_TYPE_SPEECH for
Phil Burk361b1422017-12-20 14:24:16 -0800361 * an audio book application) this information might be used by the audio framework to
362 * enforce audio focus.
363 *
Kevin Rocard68646ba2019-03-20 13:26:49 -0700364 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
365 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700366 *
367 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800368 */
369enum {
370
371 /**
372 * Use this for spoken voice, audio books, etcetera.
373 */
374 AAUDIO_CONTENT_TYPE_SPEECH = 1,
375
376 /**
377 * Use this for pre-recorded or live music.
378 */
379 AAUDIO_CONTENT_TYPE_MUSIC = 2,
380
381 /**
382 * Use this for a movie or video soundtrack.
383 */
384 AAUDIO_CONTENT_TYPE_MOVIE = 3,
385
386 /**
387 * Use this for sound is designed to accompany a user action,
388 * such as a click or beep sound made when the user presses a button.
389 */
390 AAUDIO_CONTENT_TYPE_SONIFICATION = 4
391};
392typedef int32_t aaudio_content_type_t;
393
394/**
395 * Defines the audio source.
396 * An audio source defines both a default physical source of audio signal, and a recording
397 * configuration.
398 *
399 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700400 *
401 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800402 */
403enum {
404 /**
405 * Use this preset when other presets do not apply.
406 */
407 AAUDIO_INPUT_PRESET_GENERIC = 1,
408
409 /**
410 * Use this preset when recording video.
411 */
412 AAUDIO_INPUT_PRESET_CAMCORDER = 5,
413
414 /**
415 * Use this preset when doing speech recognition.
416 */
417 AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6,
418
419 /**
420 * Use this preset when doing telephony or voice messaging.
421 */
422 AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7,
423
424 /**
425 * Use this preset to obtain an input with no effects.
426 * Note that this input will not have automatic gain control
427 * so the recorded volume may be very low.
428 */
429 AAUDIO_INPUT_PRESET_UNPROCESSED = 9,
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800430
431 /**
432 * Use this preset for capturing audio meant to be processed in real time
433 * and played back for live performance (e.g karaoke).
434 * The capture path will minimize latency and coupling with playback path.
Eric Laurentb51e3ab2020-04-28 18:29:25 -0700435 * Available since API level 29.
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800436 */
437 AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE = 10,
Phil Burk361b1422017-12-20 14:24:16 -0800438};
439typedef int32_t aaudio_input_preset_t;
440
Phil Burk8149eed2018-05-24 14:09:46 -0700441/**
Kevin Rocard68646ba2019-03-20 13:26:49 -0700442 * Specifying if audio may or may not be captured by other apps or the system.
443 *
444 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
445 * in the Android Java API.
446 *
447 * Added in API level 29.
448 */
449enum {
450 /**
451 * Indicates that the audio may be captured by any app.
452 *
453 * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*,
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700454 * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and {@link #AAUDIO_USAGE_ASSISTANT}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700455 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700456 * On {@link android.os.Build.VERSION_CODES#Q}, this means only {@link #AAUDIO_USAGE_MEDIA}
457 * and {@link #AAUDIO_USAGE_GAME} may be captured.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700458 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700459 * See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_ALL}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700460 */
461 AAUDIO_ALLOW_CAPTURE_BY_ALL = 1,
462 /**
463 * Indicates that the audio may only be captured by system apps.
464 *
465 * System apps can capture for many purposes like accessibility, user guidance...
466 * but have strong restriction. See
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700467 * {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_SYSTEM} for what the system apps
Kevin Rocard68646ba2019-03-20 13:26:49 -0700468 * can do with the capture audio.
469 */
470 AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2,
471 /**
472 * Indicates that the audio may not be recorded by any app, even if it is a system app.
473 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700474 * 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 -0700475 * provide significant and useful features for the user (eg. accessibility).
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700476 * See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_NONE}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700477 */
478 AAUDIO_ALLOW_CAPTURE_BY_NONE = 3,
479};
480
481typedef int32_t aaudio_allowed_capture_policy_t;
482
483/**
Phil Burk8149eed2018-05-24 14:09:46 -0700484 * These may be used with AAudioStreamBuilder_setSessionId().
485 *
486 * Added in API level 28.
487 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800488enum {
489 /**
490 * Do not allocate a session ID.
491 * Effects cannot be used with this stream.
492 * Default.
Phil Burk42452c02018-04-10 12:43:33 -0700493 *
494 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800495 */
496 AAUDIO_SESSION_ID_NONE = -1,
497
498 /**
499 * Allocate a session ID that can be used to attach and control
500 * effects using the Java AudioEffects API.
Phil Burk8149eed2018-05-24 14:09:46 -0700501 * Note that using this may result in higher latency.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800502 *
503 * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.
Phil Burk42452c02018-04-10 12:43:33 -0700504 *
505 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800506 */
507 AAUDIO_SESSION_ID_ALLOCATE = 0,
508};
509typedef int32_t aaudio_session_id_t;
510
Phil Burke2155ef2017-02-24 13:50:29 -0800511typedef struct AAudioStreamStruct AAudioStream;
512typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder;
Phil Burk5ed503c2017-02-01 09:38:15 -0800513
Phil Burk5ed503c2017-02-01 09:38:15 -0800514#ifndef AAUDIO_API
Phil Burk3316d5e2017-02-15 11:23:01 -0800515#define AAUDIO_API /* export this symbol */
Phil Burk5ed503c2017-02-01 09:38:15 -0800516#endif
517
518// ============================================================
519// Audio System
520// ============================================================
521
522/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800523 * The text is the ASCII symbol corresponding to the returnCode,
524 * or an English message saying the returnCode is unrecognized.
525 * This is intended for developers to use when debugging.
526 * It is not for display to users.
527 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700528 * Available since API level 26.
529 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800530 * @return pointer to a text representation of an AAudio result code.
531 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700532AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800533
534/**
535 * The text is the ASCII symbol corresponding to the stream state,
536 * or an English message saying the state is unrecognized.
537 * This is intended for developers to use when debugging.
538 * It is not for display to users.
539 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700540 * Available since API level 26.
541 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800542 * @return pointer to a text representation of an AAudio state.
543 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700544AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state)
545 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800546
547// ============================================================
548// StreamBuilder
549// ============================================================
550
551/**
552 * Create a StreamBuilder that can be used to open a Stream.
553 *
554 * The deviceId is initially unspecified, meaning that the current default device will be used.
555 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700556 * The default direction is {@link #AAUDIO_DIRECTION_OUTPUT}.
557 * The default sharing mode is {@link #AAUDIO_SHARING_MODE_SHARED}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800558 * The data format, samplesPerFrames and sampleRate are unspecified and will be
559 * chosen by the device when it is opened.
560 *
561 * AAudioStreamBuilder_delete() must be called when you are done using the builder.
Elliott Hughes64a3b062019-10-29 10:09:30 -0700562 *
563 * Available since API level 26.
Phil Burk5ed503c2017-02-01 09:38:15 -0800564 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700565AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder)
566 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800567
568/**
569 * Request an audio device identified device using an ID.
Phil Burk5ed503c2017-02-01 09:38:15 -0800570 * On Android, for example, the ID could be obtained from the Java AudioManager.
571 *
Kevin Rocard6309d882019-03-20 13:26:49 -0700572 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED},
Phil Burke057ca92017-03-28 11:31:34 -0700573 * in which case the primary device will be used.
Phil Burk5ed503c2017-02-01 09:38:15 -0800574 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700575 * Available since API level 26.
576 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800577 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocard6309d882019-03-20 13:26:49 -0700578 * @param deviceId device identifier or {@link #AAUDIO_UNSPECIFIED}
Phil Burk5ed503c2017-02-01 09:38:15 -0800579 */
Phil Burke2155ef2017-02-24 13:50:29 -0800580AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700581 int32_t deviceId) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800582
Philip P. Moltmannbda45752020-07-17 16:41:18 -0700583// TODO b/182392769: reexamine if Identity can be used
584/**
585 * Declare the name of the package creating the stream.
586 *
587 * This is usually {@code Context#getPackageName()}.
588 *
589 * The default, if you do not call this function, is a random package in the calling uid.
590 *
591 * Available since API level 31.
592 *
593 * @param builder reference provided by AAudio_createStreamBuilder()
594 * @param packageName packageName of the calling app.
595 */
596AAUDIO_API void AAudioStreamBuilder_setPackageName(AAudioStreamBuilder* builder,
597 const char * packageName) __INTRODUCED_IN(31);
598
599/**
600 * Declare the attribution tag of the context creating the stream.
601 *
602 * This is usually {@code Context#getAttributionTag()}.
603 *
604 * The default, if you do not call this function, is the default attribution tag.
605 *
606 * Available since API level 31.
607 *
608 * @param builder reference provided by AAudio_createStreamBuilder()
609 * @param attributionTag attributionTag of the calling context.
610 */
611AAUDIO_API void AAudioStreamBuilder_setAttributionTag(AAudioStreamBuilder* builder,
612 const char * attributionTag) __INTRODUCED_IN(31);
613
Phil Burk5ed503c2017-02-01 09:38:15 -0800614/**
Phil Burke057ca92017-03-28 11:31:34 -0700615 * Request a sample rate in Hertz.
616 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700617 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700618 * An optimal value will then be chosen when the stream is opened.
619 * After opening a stream with an unspecified value, the application must
620 * query for the actual value, which may vary by device.
621 *
622 * If an exact value is specified then an opened stream will use that value.
623 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700624 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700625 * Available since API level 26.
626 *
Phil Burke057ca92017-03-28 11:31:34 -0700627 * @param builder reference provided by AAudio_createStreamBuilder()
628 * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
Phil Burk5ed503c2017-02-01 09:38:15 -0800629 */
Phil Burke2155ef2017-02-24 13:50:29 -0800630AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700631 int32_t sampleRate) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800632
633/**
Phil Burk20523ed2017-04-24 17:04:01 -0700634 * Request a number of channels for the stream.
Phil Burke057ca92017-03-28 11:31:34 -0700635 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700636 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700637 * An optimal value will then be chosen when the stream is opened.
638 * After opening a stream with an unspecified value, the application must
639 * query for the actual value, which may vary by device.
Phil Burk5ed503c2017-02-01 09:38:15 -0800640 *
Phil Burk8f624892017-05-11 11:44:20 -0700641 * If an exact value is specified then an opened stream will use that value.
642 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700643 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700644 * Available since API level 26.
645 *
Phil Burke057ca92017-03-28 11:31:34 -0700646 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk20523ed2017-04-24 17:04:01 -0700647 * @param channelCount Number of channels desired.
Phil Burk5ed503c2017-02-01 09:38:15 -0800648 */
Phil Burk20523ed2017-04-24 17:04:01 -0700649AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700650 int32_t channelCount) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -0700651
652/**
Phil Burke74240d2017-08-03 15:25:43 -0700653 * Identical to AAudioStreamBuilder_setChannelCount().
654 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700655 * Available since API level 26.
656 *
Phil Burke74240d2017-08-03 15:25:43 -0700657 * @param builder reference provided by AAudio_createStreamBuilder()
658 * @param samplesPerFrame Number of samples in a frame.
659 */
660AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700661 int32_t samplesPerFrame) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -0700662
663/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700664 * Request a sample data format, for example {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burke057ca92017-03-28 11:31:34 -0700665 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700666 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700667 * An optimal value will then be chosen when the stream is opened.
668 * After opening a stream with an unspecified value, the application must
669 * query for the actual value, which may vary by device.
Phil Burke057ca92017-03-28 11:31:34 -0700670 *
Phil Burk8f624892017-05-11 11:44:20 -0700671 * If an exact value is specified then an opened stream will use that value.
672 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700673 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700674 * Available since API level 26.
675 *
Phil Burke057ca92017-03-28 11:31:34 -0700676 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700677 * @param format common formats are {@link #AAUDIO_FORMAT_PCM_FLOAT} and
678 * {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800679 */
Phil Burke2155ef2017-02-24 13:50:29 -0800680AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700681 aaudio_format_t format) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800682
683/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800684 * Request a mode for sharing the device.
Phil Burke057ca92017-03-28 11:31:34 -0700685 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700686 * The default, if you do not call this function, is {@link #AAUDIO_SHARING_MODE_SHARED}.
Phil Burke057ca92017-03-28 11:31:34 -0700687 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800688 * The requested sharing mode may not be available.
Phil Burke057ca92017-03-28 11:31:34 -0700689 * The application can query for the actual mode after the stream is opened.
Phil Burk5ed503c2017-02-01 09:38:15 -0800690 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700691 * Available since API level 26.
692 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800693 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700694 * @param sharingMode {@link #AAUDIO_SHARING_MODE_SHARED} or {@link #AAUDIO_SHARING_MODE_EXCLUSIVE}
Phil Burk5ed503c2017-02-01 09:38:15 -0800695 */
Phil Burke2155ef2017-02-24 13:50:29 -0800696AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700697 aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800698
699/**
Phil Burke057ca92017-03-28 11:31:34 -0700700 * Request the direction for a stream.
701 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700702 * The default, if you do not call this function, is {@link #AAUDIO_DIRECTION_OUTPUT}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800703 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700704 * Available since API level 26.
705 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800706 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700707 * @param direction {@link #AAUDIO_DIRECTION_OUTPUT} or {@link #AAUDIO_DIRECTION_INPUT}
Phil Burk5ed503c2017-02-01 09:38:15 -0800708 */
Phil Burke2155ef2017-02-24 13:50:29 -0800709AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700710 aaudio_direction_t direction) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800711
712/**
Phil Burke057ca92017-03-28 11:31:34 -0700713 * Set the requested buffer capacity in frames.
Phil Burk3df348f2017-02-08 11:41:55 -0800714 * The final AAudioStream capacity may differ, but will probably be at least this big.
715 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700716 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk3df348f2017-02-08 11:41:55 -0800717 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700718 * Available since API level 26.
719 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800720 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700721 * @param numFrames the desired buffer capacity in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burk3df348f2017-02-08 11:41:55 -0800722 */
Phil Burke2155ef2017-02-24 13:50:29 -0800723AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700724 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700725
726/**
727 * Set the requested performance mode.
728 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700729 * Supported modes are {@link #AAUDIO_PERFORMANCE_MODE_NONE},
730 * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING} * and {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}.
Phil Burk8149eed2018-05-24 14:09:46 -0700731 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700732 * The default, if you do not call this function, is {@link #AAUDIO_PERFORMANCE_MODE_NONE}.
Phil Burke2fbb592017-05-01 15:05:52 -0700733 *
Phil Burk8149eed2018-05-24 14:09:46 -0700734 * You may not get the mode you requested.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700735 * You can call AAudioStream_getPerformanceMode()
736 * to find out the final mode for the stream.
Phil Burk8149eed2018-05-24 14:09:46 -0700737 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700738 * Available since API level 26.
739 *
Phil Burke2fbb592017-05-01 15:05:52 -0700740 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700741 * @param mode the desired performance mode, eg. {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}
Phil Burke2fbb592017-05-01 15:05:52 -0700742 */
743AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700744 aaudio_performance_mode_t mode) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700745
Phil Burke057ca92017-03-28 11:31:34 -0700746/**
jiabinec3fa352020-08-11 16:29:26 -0700747 * Set the intended use case for the output stream.
Phil Burk361b1422017-12-20 14:24:16 -0800748 *
749 * The AAudio system will use this information to optimize the
750 * behavior of the stream.
751 * This could, for example, affect how volume and focus is handled for the stream.
752 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700753 * The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}.
Phil Burk361b1422017-12-20 14:24:16 -0800754 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700755 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700756 *
Phil Burk361b1422017-12-20 14:24:16 -0800757 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700758 * @param usage the desired usage, eg. {@link #AAUDIO_USAGE_GAME}
Phil Burk361b1422017-12-20 14:24:16 -0800759 */
760AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700761 aaudio_usage_t usage) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800762
763/**
jiabinec3fa352020-08-11 16:29:26 -0700764 * Set the type of audio data that the output stream will carry.
Phil Burk361b1422017-12-20 14:24:16 -0800765 *
766 * The AAudio system will use this information to optimize the
767 * behavior of the stream.
768 * This could, for example, affect whether a stream is paused when a notification occurs.
769 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700770 * The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}.
Phil Burk361b1422017-12-20 14:24:16 -0800771 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700772 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700773 *
Phil Burk361b1422017-12-20 14:24:16 -0800774 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700775 * @param contentType the type of audio data, eg. {@link #AAUDIO_CONTENT_TYPE_SPEECH}
Phil Burk361b1422017-12-20 14:24:16 -0800776 */
777AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700778 aaudio_content_type_t contentType) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800779
780/**
781 * Set the input (capture) preset for the stream.
782 *
783 * The AAudio system will use this information to optimize the
784 * behavior of the stream.
785 * This could, for example, affect which microphones are used and how the
786 * recorded data is processed.
787 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700788 * The default, if you do not call this function, is {@link #AAUDIO_INPUT_PRESET_VOICE_RECOGNITION}.
Phil Burkeaef9b92018-01-18 09:09:42 -0800789 * That is because VOICE_RECOGNITION is the preset with the lowest latency
790 * on many platforms.
Phil Burk361b1422017-12-20 14:24:16 -0800791 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700792 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700793 *
Phil Burk361b1422017-12-20 14:24:16 -0800794 * @param builder reference provided by AAudio_createStreamBuilder()
795 * @param inputPreset the desired configuration for recording
796 */
797AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700798 aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800799
Kevin Rocard68646ba2019-03-20 13:26:49 -0700800/**
801 * Specify whether this stream audio may or may not be captured by other apps or the system.
802 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700803 * The default is {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700804 *
805 * Note that an application can also set its global policy, in which case the most restrictive
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700806 * policy is always applied. See {@link android.media.AudioAttributes#setAllowedCapturePolicy(int)}
Kevin Rocard68646ba2019-03-20 13:26:49 -0700807 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700808 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700809 *
810 * @param builder reference provided by AAudio_createStreamBuilder()
Glenn Kastend3080c32019-10-24 09:54:56 -0700811 * @param capturePolicy the desired level of opt-out from being captured.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700812 */
813AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder,
814 aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29);
815
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800816/** Set the requested session ID.
817 *
818 * The session ID can be used to associate a stream with effects processors.
819 * The effects are controlled using the Android AudioEffect Java API.
820 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700821 * The default, if you do not call this function, is {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800822 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700823 * If set to {@link #AAUDIO_SESSION_ID_ALLOCATE} then a session ID will be allocated
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800824 * when the stream is opened.
825 *
826 * The allocated session ID can be obtained by calling AAudioStream_getSessionId()
827 * and then used with this function when opening another stream.
828 * This allows effects to be shared between streams.
829 *
Phil Burk8149eed2018-05-24 14:09:46 -0700830 * Session IDs from AAudio can be used with the Android Java APIs and vice versa.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800831 * So a session ID from an AAudio stream can be passed to Java
832 * and effects applied using the Java AudioEffect API.
833 *
Phil Burk8149eed2018-05-24 14:09:46 -0700834 * Note that allocating or setting a session ID may result in a stream with higher latency.
835 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800836 * Allocated session IDs will always be positive and nonzero.
837 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700838 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700839 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800840 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700841 * @param sessionId an allocated sessionID or {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800842 */
843AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700844 aaudio_session_id_t sessionId) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800845
Eric Laurentd17c8502019-10-24 15:58:35 -0700846
847/** Indicates whether this input stream must be marked as privacy sensitive or not.
848 *
849 * When true, this input stream is privacy sensitive and any concurrent capture
850 * is not permitted.
851 *
852 * This is off (false) by default except when the input preset is {@link #AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION}
853 * or {@link #AAUDIO_INPUT_PRESET_CAMCORDER}.
854 *
855 * Always takes precedence over default from input preset when set explicitly.
856 *
857 * Only relevant if the stream direction is {@link #AAUDIO_DIRECTION_INPUT}.
858 *
859 * Added in API level 30.
860 *
861 * @param builder reference provided by AAudio_createStreamBuilder()
862 * @param privacySensitive true if capture from this stream must be marked as privacy sensitive,
863 * false otherwise.
864 */
865AAUDIO_API void AAudioStreamBuilder_setPrivacySensitive(AAudioStreamBuilder* builder,
866 bool privacySensitive) __INTRODUCED_IN(30);
867
Phil Burk361b1422017-12-20 14:24:16 -0800868/**
Phil Burke057ca92017-03-28 11:31:34 -0700869 * Return one of these values from the data callback function.
870 */
871enum {
872
873 /**
874 * Continue calling the callback.
875 */
876 AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
877
878 /**
879 * Stop calling the callback.
880 *
881 * The application will still need to call AAudioStream_requestPause()
882 * or AAudioStream_requestStop().
883 */
884 AAUDIO_CALLBACK_RESULT_STOP,
885
886};
887typedef int32_t aaudio_data_callback_result_t;
888
889/**
890 * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
891 *
892 * For an output stream, this function should render and write numFrames of data
893 * in the streams current data format to the audioData buffer.
894 *
895 * For an input stream, this function should read and process numFrames of data
896 * from the audioData buffer.
897 *
Phil Burked0a3fe2017-12-05 14:27:43 -0800898 * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or
899 * AAudioStream_write() on the stream that is making the callback.
900 *
901 * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback()
902 * is called.
903 *
904 * Also note that this callback function should be considered a "real-time" function.
Phil Burke057ca92017-03-28 11:31:34 -0700905 * It must not do anything that could cause an unbounded delay because that can cause the
906 * audio to glitch or pop.
907 *
908 * These are things the function should NOT do:
909 * <ul>
910 * <li>allocate memory using, for example, malloc() or new</li>
911 * <li>any file operations such as opening, closing, reading or writing</li>
912 * <li>any network operations such as streaming</li>
913 * <li>use any mutexes or other synchronization primitives</li>
914 * <li>sleep</li>
Phil Burked0a3fe2017-12-05 14:27:43 -0800915 * <li>stop or close the stream</li>
Phil Burk8149eed2018-05-24 14:09:46 -0700916 * <li>AAudioStream_read()</li>
917 * <li>AAudioStream_write()</li>
918 * </ul>
919 *
920 * The following are OK to call from the data callback:
921 * <ul>
922 * <li>AAudioStream_get*()</li>
923 * <li>AAudio_convertResultToText()</li>
Phil Burke057ca92017-03-28 11:31:34 -0700924 * </ul>
925 *
926 * If you need to move data, eg. MIDI commands, in or out of the callback function then
927 * we recommend the use of non-blocking techniques such as an atomic FIFO.
928 *
929 * @param stream reference provided by AAudioStreamBuilder_openStream()
930 * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
931 * @param audioData a pointer to the audio data
Phil Burked0a3fe2017-12-05 14:27:43 -0800932 * @param numFrames the number of frames to be processed, which can vary
Phil Burke057ca92017-03-28 11:31:34 -0700933 * @return AAUDIO_CALLBACK_RESULT_*
934 */
935typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
936 AAudioStream *stream,
937 void *userData,
938 void *audioData,
939 int32_t numFrames);
940
941/**
942 * Request that AAudio call this functions when the stream is running.
943 *
944 * Note that when using this callback, the audio data will be passed in or out
945 * of the function as an argument.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700946 * So you cannot call AAudioStream_write() or AAudioStream_read()
947 * on the same stream that has an active data callback.
Phil Burke057ca92017-03-28 11:31:34 -0700948 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700949 * The callback function will start being called after AAudioStream_requestStart()
950 * is called.
Phil Burke057ca92017-03-28 11:31:34 -0700951 * It will stop being called after AAudioStream_requestPause() or
952 * AAudioStream_requestStop() is called.
953 *
Phil Burk0cb1b542020-11-25 01:01:18 +0000954 * This callback function will be called on a real-time thread owned by AAudio.
955 * The low latency streams may have callback threads with higher priority than normal streams.
956 * See {@link #AAudioStream_dataCallback} for more information.
Phil Burke057ca92017-03-28 11:31:34 -0700957 *
958 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
959 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700960 * Available since API level 26.
961 *
Phil Burke057ca92017-03-28 11:31:34 -0700962 * @param builder reference provided by AAudio_createStreamBuilder()
963 * @param callback pointer to a function that will process audio data.
964 * @param userData pointer to an application data structure that will be passed
965 * to the callback functions.
966 */
967AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700968 AAudioStream_dataCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -0700969
970/**
971 * Set the requested data callback buffer size in frames.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700972 * See {@link #AAudioStream_dataCallback}.
Phil Burke057ca92017-03-28 11:31:34 -0700973 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700974 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -0700975 *
976 * For the lowest possible latency, do not call this function. AAudio will then
977 * call the dataProc callback function with whatever size is optimal.
978 * That size may vary from one callback to another.
979 *
980 * Only use this function if the application requires a specific number of frames for processing.
981 * The application might, for example, be using an FFT that requires
982 * a specific power-of-two sized buffer.
983 *
984 * AAudio may need to add additional buffering in order to adapt between the internal
985 * buffer size and the requested buffer size.
986 *
987 * If you do call this function then the requested size should be less than
988 * half the buffer capacity, to allow double buffering.
989 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700990 * Available since API level 26.
991 *
Phil Burke057ca92017-03-28 11:31:34 -0700992 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700993 * @param numFrames the desired buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -0700994 */
995AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700996 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -0700997
998/**
999 * Prototype for the callback function that is passed to
1000 * AAudioStreamBuilder_setErrorCallback().
1001 *
Phil Burk8149eed2018-05-24 14:09:46 -07001002 * The following may NOT be called from the error callback:
1003 * <ul>
1004 * <li>AAudioStream_requestStop()</li>
1005 * <li>AAudioStream_requestPause()</li>
1006 * <li>AAudioStream_close()</li>
1007 * <li>AAudioStream_waitForStateChange()</li>
1008 * <li>AAudioStream_read()</li>
1009 * <li>AAudioStream_write()</li>
1010 * </ul>
1011 *
1012 * The following are OK to call from the error callback:
1013 * <ul>
1014 * <li>AAudioStream_get*()</li>
1015 * <li>AAudio_convertResultToText()</li>
1016 * </ul>
1017 *
Phil Burke057ca92017-03-28 11:31:34 -07001018 * @param stream reference provided by AAudioStreamBuilder_openStream()
1019 * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
1020 * @param error an AAUDIO_ERROR_* value.
1021 */
1022typedef void (*AAudioStream_errorCallback)(
1023 AAudioStream *stream,
1024 void *userData,
1025 aaudio_result_t error);
1026
1027/**
Phil Burked0a3fe2017-12-05 14:27:43 -08001028 * Request that AAudio call this function if any error occurs or the stream is disconnected.
Phil Burke057ca92017-03-28 11:31:34 -07001029 *
1030 * 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 -08001031 * device to be unavailable or "disconnected".
Phil Burke057ca92017-03-28 11:31:34 -07001032 * Another possible cause of error would be a timeout or an unanticipated internal error.
1033 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001034 * In response, this function should signal or create another thread to stop
1035 * and close this stream. The other thread could then reopen a stream on another device.
1036 * Do not stop or close the stream, or reopen the new stream, directly from this callback.
1037 *
1038 * This callback will not be called because of actions by the application, such as stopping
1039 * or closing a stream.
1040 *
Phil Burke057ca92017-03-28 11:31:34 -07001041 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
1042 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001043 * Available since API level 26.
1044 *
Phil Burke057ca92017-03-28 11:31:34 -07001045 * @param builder reference provided by AAudio_createStreamBuilder()
1046 * @param callback pointer to a function that will be called if an error occurs.
1047 * @param userData pointer to an application data structure that will be passed
1048 * to the callback functions.
1049 */
1050AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001051 AAudioStream_errorCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001052
1053/**
1054 * Open a stream based on the options in the StreamBuilder.
1055 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001056 * AAudioStream_close() must be called when finished with the stream to recover
Phil Burk5ed503c2017-02-01 09:38:15 -08001057 * the memory and to free the associated resources.
1058 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001059 * Available since API level 26.
1060 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001061 * @param builder reference provided by AAudio_createStreamBuilder()
1062 * @param stream pointer to a variable to receive the new stream reference
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001063 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001064 */
Phil Burke2155ef2017-02-24 13:50:29 -08001065AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001066 AAudioStream** stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001067
1068/**
1069 * Delete the resources associated with the StreamBuilder.
1070 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001071 * Available since API level 26.
1072 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001073 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001074 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001075 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001076AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder)
1077 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001078
1079// ============================================================
1080// Stream Control
1081// ============================================================
1082
1083/**
Phil Burk8b4e05e2019-12-17 12:12:09 -08001084 * Free the audio resources associated with a stream created by
1085 * AAudioStreamBuilder_openStream().
1086 * AAudioStream_close() should be called at some point after calling
1087 * this function.
Phil Burk5ed503c2017-02-01 09:38:15 -08001088 *
Phil Burk8b4e05e2019-12-17 12:12:09 -08001089 * After this call, the stream will be in {@link #AAUDIO_STREAM_STATE_CLOSING}
1090 *
Phil Burk41561762020-02-05 14:20:33 -08001091 * This function is useful if you want to release the audio resources immediately,
1092 * but still allow queries to the stream to occur from other threads. This often
1093 * happens if you are monitoring stream progress from a UI thread.
1094 *
Phil Burk320910f2020-08-12 14:29:10 +00001095 * NOTE: This function is only fully implemented for MMAP streams,
1096 * which are low latency streams supported by some devices.
1097 * On other "Legacy" streams some audio resources will still be in use
1098 * and some callbacks may still be in process after this call.
1099 *
Elliott Hughes81fc8592021-01-26 16:45:07 -08001100 * Available since API level 30.
1101 *
Phil Burk8b4e05e2019-12-17 12:12:09 -08001102 * @param stream reference provided by AAudioStreamBuilder_openStream()
1103 * @return {@link #AAUDIO_OK} or a negative error.
1104 */
1105AAUDIO_API aaudio_result_t AAudioStream_release(AAudioStream* stream) __INTRODUCED_IN(30);
Phil Burk8b4e05e2019-12-17 12:12:09 -08001106
1107/**
1108 * Delete the internal data structures associated with the stream created
1109 * by AAudioStreamBuilder_openStream().
1110 *
1111 * If AAudioStream_release() has not been called then it will be called automatically.
Elliott Hughes64a3b062019-10-29 10:09:30 -07001112 *
Elliott Hughes81fc8592021-01-26 16:45:07 -08001113 * Available since API level 26.
1114 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001115 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001116 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001117 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001118AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001119
1120/**
1121 * Asynchronously request to start playing the stream. For output streams, one should
1122 * write to the stream to fill the buffer before starting.
1123 * Otherwise it will underflow.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001124 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STARTING} or
1125 * {@link #AAUDIO_STREAM_STATE_STARTED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001126 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001127 * Available since API level 26.
1128 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001129 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001130 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001131 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001132AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001133
1134/**
1135 * Asynchronous request for the stream to pause.
1136 * Pausing a stream will freeze the data flow but not flush any buffers.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001137 * Use AAudioStream_requestStart() to resume playback after a pause.
1138 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_PAUSING} or
1139 * {@link #AAUDIO_STREAM_STATE_PAUSED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001140 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001141 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001142 * For input streams use AAudioStream_requestStop().
1143 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001144 * Available since API level 26.
1145 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001146 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001147 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001148 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001149AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001150
1151/**
1152 * Asynchronous request for the stream to flush.
1153 * Flushing will discard any pending data.
1154 * This call only works if the stream is pausing or paused. TODO review
1155 * Frame counters are not reset by a flush. They may be advanced.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001156 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_FLUSHING} or
1157 * {@link #AAUDIO_STREAM_STATE_FLUSHED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001158 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001159 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001160 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001161 * Available since API level 26.
1162 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001163 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001164 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001165 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001166AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001167
1168/**
1169 * Asynchronous request for the stream to stop.
1170 * The stream will stop after all of the data currently buffered has been played.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001171 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STOPPING} or
1172 * {@link #AAUDIO_STREAM_STATE_STOPPED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001173 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001174 * Available since API level 26.
1175 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001176 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001177 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001178 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001179AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001180
1181/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001182 * Query the current state of the client, eg. {@link #AAUDIO_STREAM_STATE_PAUSING}
Phil Burk5ed503c2017-02-01 09:38:15 -08001183 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001184 * This function will immediately return the state without updating the state.
1185 * If you want to update the client state based on the server state then
1186 * call AAudioStream_waitForStateChange() with currentState
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001187 * set to {@link #AAUDIO_STREAM_STATE_UNKNOWN} and a zero timeout.
Phil Burk3316d5e2017-02-15 11:23:01 -08001188 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001189 * Available since API level 26.
1190 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001191 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001192 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001193AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001194
1195/**
1196 * Wait until the current state no longer matches the input state.
1197 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001198 * This will update the current client state.
1199 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001200 * <pre><code>
Phil Burked0a3fe2017-12-05 14:27:43 -08001201 * aaudio_result_t result = AAUDIO_OK;
1202 * aaudio_stream_state_t currentState = AAudioStream_getState(stream);
1203 * aaudio_stream_state_t inputState = currentState;
1204 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) {
Phil Burk5ed503c2017-02-01 09:38:15 -08001205 * result = AAudioStream_waitForStateChange(
Phil Burked0a3fe2017-12-05 14:27:43 -08001206 * stream, inputState, &currentState, MY_TIMEOUT_NANOS);
1207 * inputState = currentState;
Phil Burk5ed503c2017-02-01 09:38:15 -08001208 * }
1209 * </code></pre>
1210 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001211 * Available since API level 26.
1212 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001213 * @param stream A reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001214 * @param inputState The state we want to avoid.
1215 * @param nextState Pointer to a variable that will be set to the new state.
1216 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001217 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001218 */
Phil Burke2155ef2017-02-24 13:50:29 -08001219AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001220 aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState,
1221 int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001222
1223// ============================================================
1224// Stream I/O
1225// ============================================================
1226
1227/**
1228 * Read data from the stream.
1229 *
1230 * The call will wait until the read is complete or until it runs out of time.
1231 * If timeoutNanos is zero then this call will not wait.
1232 *
1233 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1234 * Time will not stop if the thread is asleep.
1235 * So it will be implemented using CLOCK_BOOTTIME.
1236 *
1237 * This call is "strong non-blocking" unless it has to wait for data.
1238 *
Phil Burk8149eed2018-05-24 14:09:46 -07001239 * If the call times out then zero or a partial frame count will be returned.
1240 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001241 * Available since API level 26.
1242 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001243 * @param stream A stream created using AAudioStreamBuilder_openStream().
1244 * @param buffer The address of the first sample.
1245 * @param numFrames Number of frames to read. Only complete frames will be written.
1246 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Phil Burk3316d5e2017-02-15 11:23:01 -08001247 * @return The number of frames actually read or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001248 */
Phil Burke2155ef2017-02-24 13:50:29 -08001249AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001250 void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001251
1252/**
1253 * Write data to the stream.
1254 *
1255 * The call will wait until the write is complete or until it runs out of time.
1256 * If timeoutNanos is zero then this call will not wait.
1257 *
1258 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1259 * Time will not stop if the thread is asleep.
1260 * So it will be implemented using CLOCK_BOOTTIME.
1261 *
1262 * This call is "strong non-blocking" unless it has to wait for room in the buffer.
1263 *
Phil Burk8149eed2018-05-24 14:09:46 -07001264 * If the call times out then zero or a partial frame count will be returned.
1265 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001266 * Available since API level 26.
1267 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001268 * @param stream A stream created using AAudioStreamBuilder_openStream().
1269 * @param buffer The address of the first sample.
1270 * @param numFrames Number of frames to write. Only complete frames will be written.
1271 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1272 * @return The number of frames actually written or a negative error.
1273 */
Phil Burke2155ef2017-02-24 13:50:29 -08001274AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001275 const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001276
Phil Burk5ed503c2017-02-01 09:38:15 -08001277// ============================================================
1278// Stream - queries
1279// ============================================================
1280
Phil Burk5ed503c2017-02-01 09:38:15 -08001281/**
1282 * This can be used to adjust the latency of the buffer by changing
1283 * the threshold where blocking will occur.
Phil Burk3316d5e2017-02-15 11:23:01 -08001284 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
Phil Burk5ed503c2017-02-01 09:38:15 -08001285 * at run-time for each device.
1286 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001287 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
Phil Burk5ed503c2017-02-01 09:38:15 -08001288 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001289 * Note that you will probably not get the exact size you request.
Phil Burk8149eed2018-05-24 14:09:46 -07001290 * You can check the return value or call AAudioStream_getBufferSizeInFrames()
1291 * to see what the actual final size is.
Phil Burk3316d5e2017-02-15 11:23:01 -08001292 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001293 * Available since API level 26.
1294 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001295 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001296 * @param numFrames requested number of frames that can be filled without blocking
Phil Burk3316d5e2017-02-15 11:23:01 -08001297 * @return actual buffer size in frames or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001298 */
Phil Burke2155ef2017-02-24 13:50:29 -08001299AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001300 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001301
1302/**
1303 * Query the maximum number of frames that can be filled without blocking.
1304 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001305 * Available since API level 26.
1306 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001307 * @param stream reference provided by AAudioStreamBuilder_openStream()
1308 * @return buffer size in frames.
Phil Burk5ed503c2017-02-01 09:38:15 -08001309 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001310AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001311
1312/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001313 * Query the number of frames that the application should read or write at
1314 * one time for optimal performance. It is OK if an application writes
1315 * a different number of frames. But the buffer size may need to be larger
1316 * in order to avoid underruns or overruns.
Phil Burk5ed503c2017-02-01 09:38:15 -08001317 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001318 * Note that this may or may not match the actual device burst size.
1319 * For some endpoints, the burst size can vary dynamically.
1320 * But these tend to be devices with high latency.
1321 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001322 * Available since API level 26.
1323 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001324 * @param stream reference provided by AAudioStreamBuilder_openStream()
1325 * @return burst size
Phil Burk5ed503c2017-02-01 09:38:15 -08001326 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001327AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001328
1329/**
1330 * Query maximum buffer capacity in frames.
1331 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001332 * Available since API level 26.
1333 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001334 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001335 * @return buffer capacity in frames
Phil Burk5ed503c2017-02-01 09:38:15 -08001336 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001337AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001338
1339/**
Phil Burke057ca92017-03-28 11:31:34 -07001340 * Query the size of the buffer that will be passed to the dataProc callback
1341 * in the numFrames parameter.
1342 *
1343 * This call can be used if the application needs to know the value of numFrames before
1344 * the stream is started. This is not normally necessary.
1345 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001346 * If a specific size was requested by calling
1347 * AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size.
Phil Burke057ca92017-03-28 11:31:34 -07001348 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001349 * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001350 * return the size chosen by AAudio, or {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -07001351 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001352 * {@link #AAUDIO_UNSPECIFIED} indicates that the callback buffer size for this stream
Phil Burke057ca92017-03-28 11:31:34 -07001353 * may vary from one dataProc callback to the next.
1354 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001355 * Available since API level 26.
1356 *
Phil Burke057ca92017-03-28 11:31:34 -07001357 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001358 * @return callback buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -07001359 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001360AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001361
1362/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001363 * An XRun is an Underrun or an Overrun.
1364 * During playing, an underrun will occur if the stream is not written in time
1365 * and the system runs out of valid data.
1366 * During recording, an overrun will occur if the stream is not read in time
1367 * and there is no place to put the incoming data so it is discarded.
1368 *
1369 * An underrun or overrun can cause an audible "pop" or "glitch".
1370 *
Phil Burk068c10f2017-05-08 16:36:41 -07001371 * Note that some INPUT devices may not support this function.
1372 * In that case a 0 will always be returned.
1373 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001374 * Available since API level 26.
1375 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001376 * @param stream reference provided by AAudioStreamBuilder_openStream()
1377 * @return the underrun or overrun count
Phil Burk5ed503c2017-02-01 09:38:15 -08001378 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001379AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001380
1381/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001382 * Available since API level 26.
1383 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001384 * @param stream reference provided by AAudioStreamBuilder_openStream()
1385 * @return actual sample rate
Phil Burk5ed503c2017-02-01 09:38:15 -08001386 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001387AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001388
1389/**
Phil Burk20523ed2017-04-24 17:04:01 -07001390 * A stream has one or more channels of data.
1391 * A frame will contain one sample for each channel.
1392 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001393 * Available since API level 26.
1394 *
Phil Burk20523ed2017-04-24 17:04:01 -07001395 * @param stream reference provided by AAudioStreamBuilder_openStream()
1396 * @return actual number of channels
1397 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001398AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -07001399
1400/**
Phil Burke74240d2017-08-03 15:25:43 -07001401 * Identical to AAudioStream_getChannelCount().
1402 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001403 * Available since API level 26.
1404 *
Phil Burke74240d2017-08-03 15:25:43 -07001405 * @param stream reference provided by AAudioStreamBuilder_openStream()
1406 * @return actual number of samples frame
1407 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001408AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -07001409
1410/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001411 * Available since API level 26.
1412 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001413 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke2155ef2017-02-24 13:50:29 -08001414 * @return actual device ID
Phil Burk5ed503c2017-02-01 09:38:15 -08001415 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001416AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001417
1418/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001419 * Available since API level 26.
1420 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001421 * @param stream reference provided by AAudioStreamBuilder_openStream()
1422 * @return actual data format
Phil Burk5ed503c2017-02-01 09:38:15 -08001423 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001424AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001425
1426/**
1427 * Provide actual sharing mode.
Elliott Hughes64a3b062019-10-29 10:09:30 -07001428 *
1429 * Available since API level 26.
1430 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001431 * @param stream reference provided by AAudioStreamBuilder_openStream()
1432 * @return actual sharing mode
Phil Burk5ed503c2017-02-01 09:38:15 -08001433 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001434AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream)
1435 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001436
1437/**
Phil Burke2fbb592017-05-01 15:05:52 -07001438 * Get the performance mode used by the stream.
1439 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001440 * Available since API level 26.
1441 *
Phil Burke2fbb592017-05-01 15:05:52 -07001442 * @param stream reference provided by AAudioStreamBuilder_openStream()
1443 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001444AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream)
1445 __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -07001446
1447/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001448 * Available since API level 26.
1449 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001450 * @param stream reference provided by AAudioStreamBuilder_openStream()
1451 * @return direction
Phil Burk5ed503c2017-02-01 09:38:15 -08001452 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001453AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001454
1455/**
1456 * Passes back the number of frames that have been written since the stream was created.
Phil Burk8149eed2018-05-24 14:09:46 -07001457 * For an output stream, this will be advanced by the application calling write()
1458 * or by a data callback.
Phil Burk3316d5e2017-02-15 11:23:01 -08001459 * For an input stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -08001460 *
1461 * The frame position is monotonically increasing.
1462 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001463 * Available since API level 26.
1464 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001465 * @param stream reference provided by AAudioStreamBuilder_openStream()
1466 * @return frames written
Phil Burk5ed503c2017-02-01 09:38:15 -08001467 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001468AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001469
1470/**
1471 * Passes back the number of frames that have been read since the stream was created.
Phil Burk3316d5e2017-02-15 11:23:01 -08001472 * For an output stream, this will be advanced by the endpoint.
Phil Burk8149eed2018-05-24 14:09:46 -07001473 * For an input stream, this will be advanced by the application calling read()
1474 * or by a data callback.
Phil Burk5ed503c2017-02-01 09:38:15 -08001475 *
1476 * The frame position is monotonically increasing.
1477 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001478 * Available since API level 26.
1479 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001480 * @param stream reference provided by AAudioStreamBuilder_openStream()
1481 * @return frames read
Phil Burk5ed503c2017-02-01 09:38:15 -08001482 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001483AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001484
1485/**
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001486 * Passes back the session ID associated with this stream.
1487 *
1488 * The session ID can be used to associate a stream with effects processors.
1489 * The effects are controlled using the Android AudioEffect Java API.
1490 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001491 * If AAudioStreamBuilder_setSessionId() was
1492 * called with {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001493 * then a new session ID should be allocated once when the stream is opened.
1494 *
1495 * If AAudioStreamBuilder_setSessionId() was called with a previously allocated
1496 * session ID then that value should be returned.
1497 *
1498 * If AAudioStreamBuilder_setSessionId() was not called then this function should
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001499 * return {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001500 *
1501 * The sessionID for a stream should not change once the stream has been opened.
1502 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001503 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001504 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001505 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001506 * @return session ID or {@link #AAUDIO_SESSION_ID_NONE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001507 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001508AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001509
1510/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001511 * Passes back the time at which a particular frame was presented.
1512 * This can be used to synchronize audio with video or MIDI.
1513 * It can also be used to align a recorded stream with a playback stream.
1514 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001515 * Timestamps are only valid when the stream is in {@link #AAUDIO_STREAM_STATE_STARTED}.
1516 * {@link #AAUDIO_ERROR_INVALID_STATE} will be returned if the stream is not started.
Phil Burk5ed503c2017-02-01 09:38:15 -08001517 * Note that because requestStart() is asynchronous, timestamps will not be valid until
1518 * a short time after calling requestStart().
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001519 * So {@link #AAUDIO_ERROR_INVALID_STATE} should not be considered a fatal error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001520 * Just try calling again later.
1521 *
1522 * If an error occurs, then the position and time will not be modified.
1523 *
1524 * The position and time passed back are monotonically increasing.
1525 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001526 * Available since API level 26.
1527 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001528 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burkec159502017-07-25 17:33:47 -07001529 * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
Phil Burk5ed503c2017-02-01 09:38:15 -08001530 * @param framePosition pointer to a variable to receive the position
1531 * @param timeNanoseconds pointer to a variable to receive the time
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001532 * @return {@link #AAUDIO_OK} or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001533 */
Phil Burke2155ef2017-02-24 13:50:29 -08001534AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001535 clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001536
Phil Burk361b1422017-12-20 14:24:16 -08001537/**
1538 * Return the use case for the stream.
1539 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001540 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001541 *
Phil Burk361b1422017-12-20 14:24:16 -08001542 * @param stream reference provided by AAudioStreamBuilder_openStream()
1543 * @return frames read
1544 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001545AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001546
1547/**
1548 * Return the content type for the stream.
1549 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001550 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001551 *
Phil Burk361b1422017-12-20 14:24:16 -08001552 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001553 * @return content type, for example {@link #AAUDIO_CONTENT_TYPE_MUSIC}
Phil Burk361b1422017-12-20 14:24:16 -08001554 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001555AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream)
1556 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001557
1558/**
1559 * Return the input preset for the stream.
1560 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001561 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001562 *
Phil Burk361b1422017-12-20 14:24:16 -08001563 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001564 * @return input preset, for example {@link #AAUDIO_INPUT_PRESET_CAMCORDER}
Phil Burk361b1422017-12-20 14:24:16 -08001565 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001566AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream)
1567 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001568
Kevin Rocard68646ba2019-03-20 13:26:49 -07001569/**
1570 * Return the policy that determines whether the audio may or may not be captured
1571 * by other apps or the system.
1572 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001573 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -07001574 *
1575 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001576 * @return the allowed capture policy, for example {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}
Kevin Rocard68646ba2019-03-20 13:26:49 -07001577 */
1578AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
1579 AAudioStream* stream) __INTRODUCED_IN(29);
1580
Eric Laurentd17c8502019-10-24 15:58:35 -07001581
1582/**
1583 * Return whether this input stream is marked as privacy sensitive or not.
1584 *
1585 * See {@link #AAudioStreamBuilder_setPrivacySensitive()}.
1586 *
1587 * Added in API level 30.
1588 *
1589 * @param stream reference provided by AAudioStreamBuilder_openStream()
1590 * @return true if privacy sensitive, false otherwise
1591 */
1592AAUDIO_API bool AAudioStream_isPrivacySensitive(AAudioStream* stream)
1593 __INTRODUCED_IN(30);
1594
Phil Burk5ed503c2017-02-01 09:38:15 -08001595#ifdef __cplusplus
1596}
1597#endif
1598
1599#endif //AAUDIO_AAUDIO_H
Phil Burka45be8b2017-04-05 14:45:48 -07001600
1601/** @} */