blob: 6ca5fc802efca2b0675f18fd46e623781a959736 [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 *
gfan4db8ba42021-04-06 15:05:30 -070077 * See also the float Data in
78 * <a href="/reference/android/media/AudioTrack#write(float[],%20int,%20int,%20int)">
79 * write(float[], int, int, int)</a>.
Phil Burk8149eed2018-05-24 14:09:46 -070080 */
Phil Burk04e805b2018-03-27 09:13:53 -070081 AAUDIO_FORMAT_PCM_FLOAT,
82
83 /**
84 * This format uses 24-bit samples packed into 3 bytes.
85 * The bytes are in the native endian order.
86 * The maximum range of the data is -8388608 (0x800000)
87 * to 8388607 (0x7FFFFF).
88 *
89 * Note that the lower precision bits may be ignored by the device.
90 *
91 * Available since API level 31.
92 */
93 AAUDIO_FORMAT_PCM_I24_PACKED,
94
95 /**
96 * This format uses 32-bit samples stored in an int32_t data type.
97 * The maximum range of the data is -2147483648 (0x80000000)
98 * to 2147483647 (0x7FFFFFFF).
99 *
100 * Note that the lower precision bits may be ignored by the device.
101 *
102 * Available since API level 31.
103 */
104 AAUDIO_FORMAT_PCM_I32
105
Phil Burka4eb0d82017-04-12 15:44:06 -0700106};
107typedef int32_t aaudio_format_t;
108
Phil Burk8149eed2018-05-24 14:09:46 -0700109/**
110 * These result codes are returned from AAudio functions to indicate success or failure.
111 * Note that error return codes may change in the future so applications should generally
112 * not rely on specific return codes.
113 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700114enum {
Phil Burk8149eed2018-05-24 14:09:46 -0700115 /**
116 * The call was successful.
117 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700118 AAUDIO_OK,
119 AAUDIO_ERROR_BASE = -900, // TODO review
Phil Burk8149eed2018-05-24 14:09:46 -0700120
121 /**
122 * The audio device was disconnected. This could occur, for example, when headphones
123 * are plugged in or unplugged. The stream cannot be used after the device is disconnected.
124 * Applications should stop and close the stream.
125 * If this error is received in an error callback then another thread should be
126 * used to stop and close the stream.
127 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700128 AAUDIO_ERROR_DISCONNECTED,
Phil Burk8149eed2018-05-24 14:09:46 -0700129
130 /**
131 * An invalid parameter was passed to AAudio.
132 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700133 AAUDIO_ERROR_ILLEGAL_ARGUMENT,
Phil Burk17fff382017-05-16 14:06:45 -0700134 // reserved
135 AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2,
Phil Burk8149eed2018-05-24 14:09:46 -0700136
137 /**
138 * The requested operation is not appropriate for the current state of AAudio.
139 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700140 AAUDIO_ERROR_INVALID_STATE,
Phil Burk17fff382017-05-16 14:06:45 -0700141 // reserved
142 // reserved
Phil Burk8149eed2018-05-24 14:09:46 -0700143 /* The server rejected the handle used to identify the stream.
144 */
Phil Burk17fff382017-05-16 14:06:45 -0700145 AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3,
146 // reserved
Phil Burk8149eed2018-05-24 14:09:46 -0700147
148 /**
149 * The function is not implemented for this stream.
150 */
Phil Burk17fff382017-05-16 14:06:45 -0700151 AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2,
Phil Burk8149eed2018-05-24 14:09:46 -0700152
153 /**
154 * A resource or information is unavailable.
155 * This could occur when an application tries to open too many streams,
156 * or a timestamp is not available.
157 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700158 AAUDIO_ERROR_UNAVAILABLE,
159 AAUDIO_ERROR_NO_FREE_HANDLES,
Phil Burk8149eed2018-05-24 14:09:46 -0700160
161 /**
162 * Memory could not be allocated.
163 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700164 AAUDIO_ERROR_NO_MEMORY,
Phil Burk8149eed2018-05-24 14:09:46 -0700165
166 /**
167 * A NULL pointer was passed to AAudio.
168 * Or a NULL pointer was detected internally.
169 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700170 AAUDIO_ERROR_NULL,
Phil Burk8149eed2018-05-24 14:09:46 -0700171
172 /**
173 * An operation took longer than expected.
174 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700175 AAUDIO_ERROR_TIMEOUT,
176 AAUDIO_ERROR_WOULD_BLOCK,
Phil Burk8149eed2018-05-24 14:09:46 -0700177
178 /**
179 * The requested data format is not supported.
180 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700181 AAUDIO_ERROR_INVALID_FORMAT,
Phil Burk8149eed2018-05-24 14:09:46 -0700182
183 /**
184 * A requested was out of range.
185 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700186 AAUDIO_ERROR_OUT_OF_RANGE,
Phil Burk8149eed2018-05-24 14:09:46 -0700187
188 /**
189 * The audio service was not available.
190 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700191 AAUDIO_ERROR_NO_SERVICE,
Phil Burk8149eed2018-05-24 14:09:46 -0700192
193 /**
194 * The requested sample rate was not supported.
195 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700196 AAUDIO_ERROR_INVALID_RATE
197};
198typedef int32_t aaudio_result_t;
199
gfan4db8ba42021-04-06 15:05:30 -0700200/**
201 * AAudio Stream states, for details, refer to
202 * <a href="/ndk/guides/audio/aaudio/aaudio#using-streams">Using an Audio Stream</a>
203 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700204enum
205{
gfan4db8ba42021-04-06 15:05:30 -0700206
207 /**
208 * The stream is created but not initialized yet.
209 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700210 AAUDIO_STREAM_STATE_UNINITIALIZED = 0,
gfan4db8ba42021-04-06 15:05:30 -0700211 /**
212 * The stream is in an unrecognized state.
213 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700214 AAUDIO_STREAM_STATE_UNKNOWN,
gfan4db8ba42021-04-06 15:05:30 -0700215
216 /**
217 * The stream is open and ready to use.
218 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700219 AAUDIO_STREAM_STATE_OPEN,
gfan4db8ba42021-04-06 15:05:30 -0700220 /**
221 * The stream is just starting up.
222 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700223 AAUDIO_STREAM_STATE_STARTING,
gfan4db8ba42021-04-06 15:05:30 -0700224 /**
225 * The stream has started.
226 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700227 AAUDIO_STREAM_STATE_STARTED,
gfan4db8ba42021-04-06 15:05:30 -0700228 /**
229 * The stream is pausing.
230 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700231 AAUDIO_STREAM_STATE_PAUSING,
gfan4db8ba42021-04-06 15:05:30 -0700232 /**
233 * The stream has paused, could be restarted or flushed.
234 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700235 AAUDIO_STREAM_STATE_PAUSED,
gfan4db8ba42021-04-06 15:05:30 -0700236 /**
237 * The stream is being flushed.
238 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700239 AAUDIO_STREAM_STATE_FLUSHING,
gfan4db8ba42021-04-06 15:05:30 -0700240 /**
241 * The stream is flushed, ready to be restarted.
242 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700243 AAUDIO_STREAM_STATE_FLUSHED,
gfan4db8ba42021-04-06 15:05:30 -0700244 /**
245 * The stream is stopping.
246 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700247 AAUDIO_STREAM_STATE_STOPPING,
gfan4db8ba42021-04-06 15:05:30 -0700248 /**
249 * The stream has been stopped.
250 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700251 AAUDIO_STREAM_STATE_STOPPED,
gfan4db8ba42021-04-06 15:05:30 -0700252 /**
253 * The stream is closing.
254 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700255 AAUDIO_STREAM_STATE_CLOSING,
gfan4db8ba42021-04-06 15:05:30 -0700256 /**
257 * The stream has been closed.
258 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700259 AAUDIO_STREAM_STATE_CLOSED,
gfan4db8ba42021-04-06 15:05:30 -0700260 /**
261 * The stream is disconnected from audio device.
262 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700263 AAUDIO_STREAM_STATE_DISCONNECTED
264};
265typedef int32_t aaudio_stream_state_t;
266
267
268enum {
269 /**
270 * This will be the only stream using a particular source or sink.
271 * This mode will provide the lowest possible latency.
272 * You should close EXCLUSIVE streams immediately when you are not using them.
273 */
274 AAUDIO_SHARING_MODE_EXCLUSIVE,
275 /**
276 * Multiple applications will be mixed by the AAudio Server.
277 * This will have higher latency than the EXCLUSIVE mode.
278 */
279 AAUDIO_SHARING_MODE_SHARED
280};
281typedef int32_t aaudio_sharing_mode_t;
282
Phil Burke2fbb592017-05-01 15:05:52 -0700283
284enum {
285 /**
286 * No particular performance needs. Default.
287 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800288 AAUDIO_PERFORMANCE_MODE_NONE = 10,
Phil Burke2fbb592017-05-01 15:05:52 -0700289
290 /**
Phil Burk8149eed2018-05-24 14:09:46 -0700291 * Extending battery life is more important than low latency.
Phil Burked0a3fe2017-12-05 14:27:43 -0800292 *
293 * This mode is not supported in input streams.
Phil Burk8149eed2018-05-24 14:09:46 -0700294 * For input, mode NONE will be used if this is requested.
Phil Burke2fbb592017-05-01 15:05:52 -0700295 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800296 AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
Phil Burke2fbb592017-05-01 15:05:52 -0700297
298 /**
Phil Burk8149eed2018-05-24 14:09:46 -0700299 * Reducing latency is more important than battery life.
Phil Burke2fbb592017-05-01 15:05:52 -0700300 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800301 AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
Phil Burke2fbb592017-05-01 15:05:52 -0700302};
303typedef int32_t aaudio_performance_mode_t;
304
Hayden Gomes3e8bbb92020-01-10 13:37:05 -0800305#define AAUDIO_SYSTEM_USAGE_OFFSET 1000
306
Phil Burk361b1422017-12-20 14:24:16 -0800307/**
308 * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for.
309 * This information is used by certain platforms or routing policies
310 * to make more refined volume or routing decisions.
311 *
gfan4db8ba42021-04-06 15:05:30 -0700312 * Note that these match the equivalent values in
313 * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>
Kevin Rocard68646ba2019-03-20 13:26:49 -0700314 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700315 *
316 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800317 */
318enum {
319 /**
320 * Use this for streaming media, music performance, video, podcasts, etcetera.
321 */
322 AAUDIO_USAGE_MEDIA = 1,
323
324 /**
325 * Use this for voice over IP, telephony, etcetera.
326 */
327 AAUDIO_USAGE_VOICE_COMMUNICATION = 2,
328
329 /**
330 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.
331 */
332 AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
333
334 /**
335 * Use this to demand the users attention.
336 */
337 AAUDIO_USAGE_ALARM = 4,
338
339 /**
340 * Use this for notifying the user when a message has arrived or some
341 * other background event has occured.
342 */
343 AAUDIO_USAGE_NOTIFICATION = 5,
344
345 /**
346 * Use this when the phone rings.
347 */
348 AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6,
349
350 /**
351 * Use this to attract the users attention when, for example, the battery is low.
352 */
353 AAUDIO_USAGE_NOTIFICATION_EVENT = 10,
354
355 /**
356 * Use this for screen readers, etcetera.
357 */
358 AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
359
360 /**
361 * Use this for driving or navigation directions.
362 */
363 AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
364
365 /**
366 * Use this for user interface sounds, beeps, etcetera.
367 */
368 AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
369
370 /**
371 * Use this for game audio and sound effects.
372 */
373 AAUDIO_USAGE_GAME = 14,
374
375 /**
376 * Use this for audio responses to user queries, audio instructions or help utterances.
377 */
Hayden Gomes3e8bbb92020-01-10 13:37:05 -0800378 AAUDIO_USAGE_ASSISTANT = 16,
379
380 /**
381 * Use this in case of playing sounds in an emergency.
382 * Privileged MODIFY_AUDIO_ROUTING permission required.
383 */
384 AAUDIO_SYSTEM_USAGE_EMERGENCY = AAUDIO_SYSTEM_USAGE_OFFSET,
385
386 /**
387 * Use this for safety sounds and alerts, for example backup camera obstacle detection.
388 * Privileged MODIFY_AUDIO_ROUTING permission required.
389 */
390 AAUDIO_SYSTEM_USAGE_SAFETY = AAUDIO_SYSTEM_USAGE_OFFSET + 1,
391
392 /**
393 * Use this for vehicle status alerts and information, for example the check engine light.
394 * Privileged MODIFY_AUDIO_ROUTING permission required.
395 */
396 AAUDIO_SYSTEM_USAGE_VEHICLE_STATUS = AAUDIO_SYSTEM_USAGE_OFFSET + 2,
397
398 /**
399 * Use this for traffic announcements, etc.
400 * Privileged MODIFY_AUDIO_ROUTING permission required.
401 */
402 AAUDIO_SYSTEM_USAGE_ANNOUNCEMENT = AAUDIO_SYSTEM_USAGE_OFFSET + 3,
Phil Burk361b1422017-12-20 14:24:16 -0800403};
404typedef int32_t aaudio_usage_t;
405
406/**
407 * The CONTENT_TYPE attribute describes "what" you are playing.
408 * It expresses the general category of the content. This information is optional.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700409 * But in case it is known (for instance AAUDIO_CONTENT_TYPE_MOVIE for a
410 * movie streaming service or AAUDIO_CONTENT_TYPE_SPEECH for
Phil Burk361b1422017-12-20 14:24:16 -0800411 * an audio book application) this information might be used by the audio framework to
412 * enforce audio focus.
413 *
gfan4db8ba42021-04-06 15:05:30 -0700414 * Note that these match the equivalent values in
415 * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>
Kevin Rocard68646ba2019-03-20 13:26:49 -0700416 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700417 *
418 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800419 */
420enum {
421
422 /**
423 * Use this for spoken voice, audio books, etcetera.
424 */
425 AAUDIO_CONTENT_TYPE_SPEECH = 1,
426
427 /**
428 * Use this for pre-recorded or live music.
429 */
430 AAUDIO_CONTENT_TYPE_MUSIC = 2,
431
432 /**
433 * Use this for a movie or video soundtrack.
434 */
435 AAUDIO_CONTENT_TYPE_MOVIE = 3,
436
437 /**
438 * Use this for sound is designed to accompany a user action,
439 * such as a click or beep sound made when the user presses a button.
440 */
441 AAUDIO_CONTENT_TYPE_SONIFICATION = 4
442};
443typedef int32_t aaudio_content_type_t;
444
445/**
446 * Defines the audio source.
447 * An audio source defines both a default physical source of audio signal, and a recording
448 * configuration.
449 *
450 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700451 *
452 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800453 */
454enum {
455 /**
456 * Use this preset when other presets do not apply.
457 */
458 AAUDIO_INPUT_PRESET_GENERIC = 1,
459
460 /**
461 * Use this preset when recording video.
462 */
463 AAUDIO_INPUT_PRESET_CAMCORDER = 5,
464
465 /**
466 * Use this preset when doing speech recognition.
467 */
468 AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6,
469
470 /**
471 * Use this preset when doing telephony or voice messaging.
472 */
473 AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7,
474
475 /**
476 * Use this preset to obtain an input with no effects.
477 * Note that this input will not have automatic gain control
478 * so the recorded volume may be very low.
479 */
480 AAUDIO_INPUT_PRESET_UNPROCESSED = 9,
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800481
482 /**
483 * Use this preset for capturing audio meant to be processed in real time
484 * and played back for live performance (e.g karaoke).
485 * The capture path will minimize latency and coupling with playback path.
Eric Laurentb51e3ab2020-04-28 18:29:25 -0700486 * Available since API level 29.
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800487 */
488 AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE = 10,
Phil Burk361b1422017-12-20 14:24:16 -0800489};
490typedef int32_t aaudio_input_preset_t;
491
Phil Burk8149eed2018-05-24 14:09:46 -0700492/**
Kevin Rocard68646ba2019-03-20 13:26:49 -0700493 * Specifying if audio may or may not be captured by other apps or the system.
494 *
gfan4db8ba42021-04-06 15:05:30 -0700495 * Note that these match the equivalent values in
496 * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>
Kevin Rocard68646ba2019-03-20 13:26:49 -0700497 * in the Android Java API.
498 *
499 * Added in API level 29.
500 */
501enum {
502 /**
503 * Indicates that the audio may be captured by any app.
504 *
505 * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*,
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700506 * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and {@link #AAUDIO_USAGE_ASSISTANT}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700507 *
gfan4db8ba42021-04-06 15:05:30 -0700508 * On <a href="/reference/android/os/Build.VERSION_CODES#Q">Build.VERSION_CODES</a>,
509 * this means only {@link #AAUDIO_USAGE_MEDIA} and {@link #AAUDIO_USAGE_GAME} may be captured.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700510 *
gfan4db8ba42021-04-06 15:05:30 -0700511 * See <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_ALL">
512 * ALLOW_CAPTURE_BY_ALL</a>.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700513 */
514 AAUDIO_ALLOW_CAPTURE_BY_ALL = 1,
515 /**
516 * Indicates that the audio may only be captured by system apps.
517 *
518 * System apps can capture for many purposes like accessibility, user guidance...
519 * but have strong restriction. See
gfan4db8ba42021-04-06 15:05:30 -0700520 * <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_SYSTEM">
521 * ALLOW_CAPTURE_BY_SYSTEM</a>
522 * for what the system apps can do with the capture audio.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700523 */
524 AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2,
525 /**
526 * Indicates that the audio may not be recorded by any app, even if it is a system app.
527 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700528 * 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 -0700529 * provide significant and useful features for the user (eg. accessibility).
gfan4db8ba42021-04-06 15:05:30 -0700530 * See <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_NONE">
531 * ALLOW_CAPTURE_BY_NONE</a>.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700532 */
533 AAUDIO_ALLOW_CAPTURE_BY_NONE = 3,
534};
535
536typedef int32_t aaudio_allowed_capture_policy_t;
537
538/**
Phil Burk8149eed2018-05-24 14:09:46 -0700539 * These may be used with AAudioStreamBuilder_setSessionId().
540 *
541 * Added in API level 28.
542 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800543enum {
544 /**
545 * Do not allocate a session ID.
546 * Effects cannot be used with this stream.
547 * Default.
Phil Burk42452c02018-04-10 12:43:33 -0700548 *
549 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800550 */
551 AAUDIO_SESSION_ID_NONE = -1,
552
553 /**
554 * Allocate a session ID that can be used to attach and control
555 * effects using the Java AudioEffects API.
Phil Burk8149eed2018-05-24 14:09:46 -0700556 * Note that using this may result in higher latency.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800557 *
558 * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.
Phil Burk42452c02018-04-10 12:43:33 -0700559 *
560 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800561 */
562 AAUDIO_SESSION_ID_ALLOCATE = 0,
563};
564typedef int32_t aaudio_session_id_t;
565
Phil Burke2155ef2017-02-24 13:50:29 -0800566typedef struct AAudioStreamStruct AAudioStream;
567typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder;
Phil Burk5ed503c2017-02-01 09:38:15 -0800568
Phil Burk5ed503c2017-02-01 09:38:15 -0800569#ifndef AAUDIO_API
Phil Burk3316d5e2017-02-15 11:23:01 -0800570#define AAUDIO_API /* export this symbol */
Phil Burk5ed503c2017-02-01 09:38:15 -0800571#endif
572
573// ============================================================
574// Audio System
575// ============================================================
576
577/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800578 * The text is the ASCII symbol corresponding to the returnCode,
579 * or an English message saying the returnCode is unrecognized.
580 * This is intended for developers to use when debugging.
581 * It is not for display to users.
582 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700583 * Available since API level 26.
584 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800585 * @return pointer to a text representation of an AAudio result code.
586 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700587AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800588
589/**
590 * The text is the ASCII symbol corresponding to the stream state,
591 * or an English message saying the state is unrecognized.
592 * This is intended for developers to use when debugging.
593 * It is not for display to users.
594 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700595 * Available since API level 26.
596 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800597 * @return pointer to a text representation of an AAudio state.
598 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700599AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state)
600 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800601
602// ============================================================
603// StreamBuilder
604// ============================================================
605
606/**
607 * Create a StreamBuilder that can be used to open a Stream.
608 *
609 * The deviceId is initially unspecified, meaning that the current default device will be used.
610 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700611 * The default direction is {@link #AAUDIO_DIRECTION_OUTPUT}.
612 * The default sharing mode is {@link #AAUDIO_SHARING_MODE_SHARED}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800613 * The data format, samplesPerFrames and sampleRate are unspecified and will be
614 * chosen by the device when it is opened.
615 *
616 * AAudioStreamBuilder_delete() must be called when you are done using the builder.
Elliott Hughes64a3b062019-10-29 10:09:30 -0700617 *
618 * Available since API level 26.
Phil Burk5ed503c2017-02-01 09:38:15 -0800619 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700620AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder)
621 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800622
623/**
624 * Request an audio device identified device using an ID.
Phil Burk5ed503c2017-02-01 09:38:15 -0800625 * On Android, for example, the ID could be obtained from the Java AudioManager.
626 *
Kevin Rocard6309d882019-03-20 13:26:49 -0700627 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED},
Phil Burke057ca92017-03-28 11:31:34 -0700628 * in which case the primary device will be used.
Phil Burk5ed503c2017-02-01 09:38:15 -0800629 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700630 * Available since API level 26.
631 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800632 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocard6309d882019-03-20 13:26:49 -0700633 * @param deviceId device identifier or {@link #AAUDIO_UNSPECIFIED}
Phil Burk5ed503c2017-02-01 09:38:15 -0800634 */
Phil Burke2155ef2017-02-24 13:50:29 -0800635AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700636 int32_t deviceId) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800637
Philip P. Moltmannbda45752020-07-17 16:41:18 -0700638/**
639 * Declare the name of the package creating the stream.
640 *
641 * This is usually {@code Context#getPackageName()}.
642 *
643 * The default, if you do not call this function, is a random package in the calling uid.
Nate Myren29457ed2021-05-19 12:29:28 -0700644 * The vast majority of apps have only one package per calling UID. If the package
645 * name does not match the calling UID, then requests will be rejected.
Philip P. Moltmannbda45752020-07-17 16:41:18 -0700646 *
647 * Available since API level 31.
648 *
649 * @param builder reference provided by AAudio_createStreamBuilder()
650 * @param packageName packageName of the calling app.
651 */
652AAUDIO_API void AAudioStreamBuilder_setPackageName(AAudioStreamBuilder* builder,
653 const char * packageName) __INTRODUCED_IN(31);
654
655/**
656 * Declare the attribution tag of the context creating the stream.
657 *
658 * This is usually {@code Context#getAttributionTag()}.
659 *
Nate Myren29457ed2021-05-19 12:29:28 -0700660 * The default, if you do not call this function, is null.
Philip P. Moltmannbda45752020-07-17 16:41:18 -0700661 *
662 * Available since API level 31.
663 *
664 * @param builder reference provided by AAudio_createStreamBuilder()
665 * @param attributionTag attributionTag of the calling context.
666 */
667AAUDIO_API void AAudioStreamBuilder_setAttributionTag(AAudioStreamBuilder* builder,
668 const char * attributionTag) __INTRODUCED_IN(31);
669
Phil Burk5ed503c2017-02-01 09:38:15 -0800670/**
Phil Burke057ca92017-03-28 11:31:34 -0700671 * Request a sample rate in Hertz.
672 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700673 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700674 * An optimal value will then be chosen when the stream is opened.
675 * After opening a stream with an unspecified value, the application must
676 * query for the actual value, which may vary by device.
677 *
678 * If an exact value is specified then an opened stream will use that value.
679 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700680 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700681 * Available since API level 26.
682 *
Phil Burke057ca92017-03-28 11:31:34 -0700683 * @param builder reference provided by AAudio_createStreamBuilder()
684 * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
Phil Burk5ed503c2017-02-01 09:38:15 -0800685 */
Phil Burke2155ef2017-02-24 13:50:29 -0800686AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700687 int32_t sampleRate) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800688
689/**
Phil Burk20523ed2017-04-24 17:04:01 -0700690 * Request a number of channels for the stream.
Phil Burke057ca92017-03-28 11:31:34 -0700691 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700692 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700693 * An optimal value will then be chosen when the stream is opened.
694 * After opening a stream with an unspecified value, the application must
695 * query for the actual value, which may vary by device.
Phil Burk5ed503c2017-02-01 09:38:15 -0800696 *
Phil Burk8f624892017-05-11 11:44:20 -0700697 * If an exact value is specified then an opened stream will use that value.
698 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700699 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700700 * Available since API level 26.
701 *
Phil Burke057ca92017-03-28 11:31:34 -0700702 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk20523ed2017-04-24 17:04:01 -0700703 * @param channelCount Number of channels desired.
Phil Burk5ed503c2017-02-01 09:38:15 -0800704 */
Phil Burk20523ed2017-04-24 17:04:01 -0700705AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700706 int32_t channelCount) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -0700707
708/**
Phil Burke74240d2017-08-03 15:25:43 -0700709 * Identical to AAudioStreamBuilder_setChannelCount().
710 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700711 * Available since API level 26.
712 *
Phil Burke74240d2017-08-03 15:25:43 -0700713 * @param builder reference provided by AAudio_createStreamBuilder()
714 * @param samplesPerFrame Number of samples in a frame.
715 */
716AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700717 int32_t samplesPerFrame) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -0700718
719/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700720 * Request a sample data format, for example {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burke057ca92017-03-28 11:31:34 -0700721 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700722 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700723 * An optimal value will then be chosen when the stream is opened.
724 * After opening a stream with an unspecified value, the application must
725 * query for the actual value, which may vary by device.
Phil Burke057ca92017-03-28 11:31:34 -0700726 *
Phil Burk8f624892017-05-11 11:44:20 -0700727 * If an exact value is specified then an opened stream will use that value.
728 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700729 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700730 * Available since API level 26.
731 *
Phil Burke057ca92017-03-28 11:31:34 -0700732 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700733 * @param format common formats are {@link #AAUDIO_FORMAT_PCM_FLOAT} and
734 * {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800735 */
Phil Burke2155ef2017-02-24 13:50:29 -0800736AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700737 aaudio_format_t format) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800738
739/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800740 * Request a mode for sharing the device.
Phil Burke057ca92017-03-28 11:31:34 -0700741 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700742 * The default, if you do not call this function, is {@link #AAUDIO_SHARING_MODE_SHARED}.
Phil Burke057ca92017-03-28 11:31:34 -0700743 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800744 * The requested sharing mode may not be available.
Phil Burke057ca92017-03-28 11:31:34 -0700745 * The application can query for the actual mode after the stream is opened.
Phil Burk5ed503c2017-02-01 09:38:15 -0800746 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700747 * Available since API level 26.
748 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800749 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700750 * @param sharingMode {@link #AAUDIO_SHARING_MODE_SHARED} or {@link #AAUDIO_SHARING_MODE_EXCLUSIVE}
Phil Burk5ed503c2017-02-01 09:38:15 -0800751 */
Phil Burke2155ef2017-02-24 13:50:29 -0800752AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700753 aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800754
755/**
Phil Burke057ca92017-03-28 11:31:34 -0700756 * Request the direction for a stream.
757 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700758 * The default, if you do not call this function, is {@link #AAUDIO_DIRECTION_OUTPUT}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800759 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700760 * Available since API level 26.
761 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800762 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700763 * @param direction {@link #AAUDIO_DIRECTION_OUTPUT} or {@link #AAUDIO_DIRECTION_INPUT}
Phil Burk5ed503c2017-02-01 09:38:15 -0800764 */
Phil Burke2155ef2017-02-24 13:50:29 -0800765AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700766 aaudio_direction_t direction) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800767
768/**
Phil Burke057ca92017-03-28 11:31:34 -0700769 * Set the requested buffer capacity in frames.
Phil Burk3df348f2017-02-08 11:41:55 -0800770 * The final AAudioStream capacity may differ, but will probably be at least this big.
771 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700772 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk3df348f2017-02-08 11:41:55 -0800773 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700774 * Available since API level 26.
775 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800776 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700777 * @param numFrames the desired buffer capacity in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burk3df348f2017-02-08 11:41:55 -0800778 */
Phil Burke2155ef2017-02-24 13:50:29 -0800779AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700780 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700781
782/**
783 * Set the requested performance mode.
784 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700785 * Supported modes are {@link #AAUDIO_PERFORMANCE_MODE_NONE},
786 * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING} * and {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}.
Phil Burk8149eed2018-05-24 14:09:46 -0700787 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700788 * The default, if you do not call this function, is {@link #AAUDIO_PERFORMANCE_MODE_NONE}.
Phil Burke2fbb592017-05-01 15:05:52 -0700789 *
Phil Burk8149eed2018-05-24 14:09:46 -0700790 * You may not get the mode you requested.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700791 * You can call AAudioStream_getPerformanceMode()
792 * to find out the final mode for the stream.
Phil Burk8149eed2018-05-24 14:09:46 -0700793 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700794 * Available since API level 26.
795 *
Phil Burke2fbb592017-05-01 15:05:52 -0700796 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700797 * @param mode the desired performance mode, eg. {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}
Phil Burke2fbb592017-05-01 15:05:52 -0700798 */
799AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700800 aaudio_performance_mode_t mode) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700801
Phil Burke057ca92017-03-28 11:31:34 -0700802/**
jiabinec3fa352020-08-11 16:29:26 -0700803 * Set the intended use case for the output stream.
Phil Burk361b1422017-12-20 14:24:16 -0800804 *
805 * The AAudio system will use this information to optimize the
806 * behavior of the stream.
807 * This could, for example, affect how volume and focus is handled for the stream.
808 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700809 * The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}.
Phil Burk361b1422017-12-20 14:24:16 -0800810 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700811 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700812 *
Phil Burk361b1422017-12-20 14:24:16 -0800813 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700814 * @param usage the desired usage, eg. {@link #AAUDIO_USAGE_GAME}
Phil Burk361b1422017-12-20 14:24:16 -0800815 */
816AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700817 aaudio_usage_t usage) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800818
819/**
jiabinec3fa352020-08-11 16:29:26 -0700820 * Set the type of audio data that the output stream will carry.
Phil Burk361b1422017-12-20 14:24:16 -0800821 *
822 * The AAudio system will use this information to optimize the
823 * behavior of the stream.
824 * This could, for example, affect whether a stream is paused when a notification occurs.
825 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700826 * The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}.
Phil Burk361b1422017-12-20 14:24:16 -0800827 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700828 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700829 *
Phil Burk361b1422017-12-20 14:24:16 -0800830 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700831 * @param contentType the type of audio data, eg. {@link #AAUDIO_CONTENT_TYPE_SPEECH}
Phil Burk361b1422017-12-20 14:24:16 -0800832 */
833AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700834 aaudio_content_type_t contentType) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800835
836/**
837 * Set the input (capture) preset for the stream.
838 *
839 * The AAudio system will use this information to optimize the
840 * behavior of the stream.
841 * This could, for example, affect which microphones are used and how the
842 * recorded data is processed.
843 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700844 * The default, if you do not call this function, is {@link #AAUDIO_INPUT_PRESET_VOICE_RECOGNITION}.
Phil Burkeaef9b92018-01-18 09:09:42 -0800845 * That is because VOICE_RECOGNITION is the preset with the lowest latency
846 * on many platforms.
Phil Burk361b1422017-12-20 14:24:16 -0800847 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700848 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700849 *
Phil Burk361b1422017-12-20 14:24:16 -0800850 * @param builder reference provided by AAudio_createStreamBuilder()
851 * @param inputPreset the desired configuration for recording
852 */
853AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700854 aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800855
Kevin Rocard68646ba2019-03-20 13:26:49 -0700856/**
857 * Specify whether this stream audio may or may not be captured by other apps or the system.
858 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700859 * The default is {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700860 *
861 * Note that an application can also set its global policy, in which case the most restrictive
gfan4db8ba42021-04-06 15:05:30 -0700862 * policy is always applied. See
863 * <a href="/reference/android/media/AudioManager#setAllowedCapturePolicy(int)">
864 * setAllowedCapturePolicy(int)</a>
Kevin Rocard68646ba2019-03-20 13:26:49 -0700865 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700866 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700867 *
868 * @param builder reference provided by AAudio_createStreamBuilder()
Glenn Kastend3080c32019-10-24 09:54:56 -0700869 * @param capturePolicy the desired level of opt-out from being captured.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700870 */
871AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder,
872 aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29);
873
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800874/** Set the requested session ID.
875 *
876 * The session ID can be used to associate a stream with effects processors.
877 * The effects are controlled using the Android AudioEffect Java API.
878 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700879 * The default, if you do not call this function, is {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800880 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700881 * If set to {@link #AAUDIO_SESSION_ID_ALLOCATE} then a session ID will be allocated
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800882 * when the stream is opened.
883 *
884 * The allocated session ID can be obtained by calling AAudioStream_getSessionId()
885 * and then used with this function when opening another stream.
886 * This allows effects to be shared between streams.
887 *
Phil Burk8149eed2018-05-24 14:09:46 -0700888 * Session IDs from AAudio can be used with the Android Java APIs and vice versa.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800889 * So a session ID from an AAudio stream can be passed to Java
890 * and effects applied using the Java AudioEffect API.
891 *
Phil Burk8149eed2018-05-24 14:09:46 -0700892 * Note that allocating or setting a session ID may result in a stream with higher latency.
893 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800894 * Allocated session IDs will always be positive and nonzero.
895 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700896 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700897 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800898 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700899 * @param sessionId an allocated sessionID or {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800900 */
901AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700902 aaudio_session_id_t sessionId) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800903
Eric Laurentd17c8502019-10-24 15:58:35 -0700904
905/** Indicates whether this input stream must be marked as privacy sensitive or not.
906 *
907 * When true, this input stream is privacy sensitive and any concurrent capture
908 * is not permitted.
909 *
910 * This is off (false) by default except when the input preset is {@link #AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION}
911 * or {@link #AAUDIO_INPUT_PRESET_CAMCORDER}.
912 *
913 * Always takes precedence over default from input preset when set explicitly.
914 *
915 * Only relevant if the stream direction is {@link #AAUDIO_DIRECTION_INPUT}.
916 *
917 * Added in API level 30.
918 *
919 * @param builder reference provided by AAudio_createStreamBuilder()
920 * @param privacySensitive true if capture from this stream must be marked as privacy sensitive,
921 * false otherwise.
922 */
923AAUDIO_API void AAudioStreamBuilder_setPrivacySensitive(AAudioStreamBuilder* builder,
924 bool privacySensitive) __INTRODUCED_IN(30);
925
Phil Burk361b1422017-12-20 14:24:16 -0800926/**
Phil Burke057ca92017-03-28 11:31:34 -0700927 * Return one of these values from the data callback function.
928 */
929enum {
930
931 /**
932 * Continue calling the callback.
933 */
934 AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
935
936 /**
937 * Stop calling the callback.
938 *
939 * The application will still need to call AAudioStream_requestPause()
940 * or AAudioStream_requestStop().
941 */
942 AAUDIO_CALLBACK_RESULT_STOP,
943
944};
945typedef int32_t aaudio_data_callback_result_t;
946
947/**
948 * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
949 *
950 * For an output stream, this function should render and write numFrames of data
951 * in the streams current data format to the audioData buffer.
952 *
953 * For an input stream, this function should read and process numFrames of data
954 * from the audioData buffer.
955 *
Phil Burked0a3fe2017-12-05 14:27:43 -0800956 * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or
957 * AAudioStream_write() on the stream that is making the callback.
958 *
959 * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback()
960 * is called.
961 *
962 * Also note that this callback function should be considered a "real-time" function.
Phil Burke057ca92017-03-28 11:31:34 -0700963 * It must not do anything that could cause an unbounded delay because that can cause the
964 * audio to glitch or pop.
965 *
966 * These are things the function should NOT do:
967 * <ul>
968 * <li>allocate memory using, for example, malloc() or new</li>
969 * <li>any file operations such as opening, closing, reading or writing</li>
970 * <li>any network operations such as streaming</li>
971 * <li>use any mutexes or other synchronization primitives</li>
972 * <li>sleep</li>
Phil Burked0a3fe2017-12-05 14:27:43 -0800973 * <li>stop or close the stream</li>
Phil Burk8149eed2018-05-24 14:09:46 -0700974 * <li>AAudioStream_read()</li>
975 * <li>AAudioStream_write()</li>
976 * </ul>
977 *
978 * The following are OK to call from the data callback:
979 * <ul>
980 * <li>AAudioStream_get*()</li>
981 * <li>AAudio_convertResultToText()</li>
Phil Burke057ca92017-03-28 11:31:34 -0700982 * </ul>
983 *
984 * If you need to move data, eg. MIDI commands, in or out of the callback function then
985 * we recommend the use of non-blocking techniques such as an atomic FIFO.
986 *
987 * @param stream reference provided by AAudioStreamBuilder_openStream()
988 * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
989 * @param audioData a pointer to the audio data
Phil Burked0a3fe2017-12-05 14:27:43 -0800990 * @param numFrames the number of frames to be processed, which can vary
Phil Burke057ca92017-03-28 11:31:34 -0700991 * @return AAUDIO_CALLBACK_RESULT_*
992 */
993typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
994 AAudioStream *stream,
995 void *userData,
996 void *audioData,
997 int32_t numFrames);
998
999/**
1000 * Request that AAudio call this functions when the stream is running.
1001 *
1002 * Note that when using this callback, the audio data will be passed in or out
1003 * of the function as an argument.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001004 * So you cannot call AAudioStream_write() or AAudioStream_read()
1005 * on the same stream that has an active data callback.
Phil Burke057ca92017-03-28 11:31:34 -07001006 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001007 * The callback function will start being called after AAudioStream_requestStart()
1008 * is called.
Phil Burke057ca92017-03-28 11:31:34 -07001009 * It will stop being called after AAudioStream_requestPause() or
1010 * AAudioStream_requestStop() is called.
1011 *
Phil Burk0cb1b542020-11-25 01:01:18 +00001012 * This callback function will be called on a real-time thread owned by AAudio.
1013 * The low latency streams may have callback threads with higher priority than normal streams.
1014 * See {@link #AAudioStream_dataCallback} for more information.
Phil Burke057ca92017-03-28 11:31:34 -07001015 *
1016 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
1017 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001018 * Available since API level 26.
1019 *
Phil Burke057ca92017-03-28 11:31:34 -07001020 * @param builder reference provided by AAudio_createStreamBuilder()
1021 * @param callback pointer to a function that will process audio data.
1022 * @param userData pointer to an application data structure that will be passed
1023 * to the callback functions.
1024 */
1025AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001026 AAudioStream_dataCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001027
1028/**
1029 * Set the requested data callback buffer size in frames.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001030 * See {@link #AAudioStream_dataCallback}.
Phil Burke057ca92017-03-28 11:31:34 -07001031 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001032 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -07001033 *
1034 * For the lowest possible latency, do not call this function. AAudio will then
1035 * call the dataProc callback function with whatever size is optimal.
1036 * That size may vary from one callback to another.
1037 *
1038 * Only use this function if the application requires a specific number of frames for processing.
1039 * The application might, for example, be using an FFT that requires
1040 * a specific power-of-two sized buffer.
1041 *
1042 * AAudio may need to add additional buffering in order to adapt between the internal
1043 * buffer size and the requested buffer size.
1044 *
1045 * If you do call this function then the requested size should be less than
1046 * half the buffer capacity, to allow double buffering.
1047 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001048 * Available since API level 26.
1049 *
Phil Burke057ca92017-03-28 11:31:34 -07001050 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001051 * @param numFrames the desired buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -07001052 */
1053AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001054 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001055
1056/**
1057 * Prototype for the callback function that is passed to
1058 * AAudioStreamBuilder_setErrorCallback().
1059 *
Phil Burk8149eed2018-05-24 14:09:46 -07001060 * The following may NOT be called from the error callback:
1061 * <ul>
1062 * <li>AAudioStream_requestStop()</li>
1063 * <li>AAudioStream_requestPause()</li>
1064 * <li>AAudioStream_close()</li>
1065 * <li>AAudioStream_waitForStateChange()</li>
1066 * <li>AAudioStream_read()</li>
1067 * <li>AAudioStream_write()</li>
1068 * </ul>
1069 *
1070 * The following are OK to call from the error callback:
1071 * <ul>
1072 * <li>AAudioStream_get*()</li>
1073 * <li>AAudio_convertResultToText()</li>
1074 * </ul>
1075 *
Phil Burke057ca92017-03-28 11:31:34 -07001076 * @param stream reference provided by AAudioStreamBuilder_openStream()
1077 * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
1078 * @param error an AAUDIO_ERROR_* value.
1079 */
1080typedef void (*AAudioStream_errorCallback)(
1081 AAudioStream *stream,
1082 void *userData,
1083 aaudio_result_t error);
1084
1085/**
Phil Burked0a3fe2017-12-05 14:27:43 -08001086 * Request that AAudio call this function if any error occurs or the stream is disconnected.
Phil Burke057ca92017-03-28 11:31:34 -07001087 *
1088 * 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 -08001089 * device to be unavailable or "disconnected".
Phil Burke057ca92017-03-28 11:31:34 -07001090 * Another possible cause of error would be a timeout or an unanticipated internal error.
1091 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001092 * In response, this function should signal or create another thread to stop
1093 * and close this stream. The other thread could then reopen a stream on another device.
1094 * Do not stop or close the stream, or reopen the new stream, directly from this callback.
1095 *
1096 * This callback will not be called because of actions by the application, such as stopping
1097 * or closing a stream.
1098 *
Phil Burke057ca92017-03-28 11:31:34 -07001099 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
1100 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001101 * Available since API level 26.
1102 *
Phil Burke057ca92017-03-28 11:31:34 -07001103 * @param builder reference provided by AAudio_createStreamBuilder()
1104 * @param callback pointer to a function that will be called if an error occurs.
1105 * @param userData pointer to an application data structure that will be passed
1106 * to the callback functions.
1107 */
1108AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001109 AAudioStream_errorCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001110
1111/**
1112 * Open a stream based on the options in the StreamBuilder.
1113 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001114 * AAudioStream_close() must be called when finished with the stream to recover
Phil Burk5ed503c2017-02-01 09:38:15 -08001115 * the memory and to free the associated resources.
1116 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001117 * Available since API level 26.
1118 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001119 * @param builder reference provided by AAudio_createStreamBuilder()
1120 * @param stream pointer to a variable to receive the new stream reference
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001121 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001122 */
Phil Burke2155ef2017-02-24 13:50:29 -08001123AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001124 AAudioStream** stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001125
1126/**
1127 * Delete the resources associated with the StreamBuilder.
1128 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001129 * Available since API level 26.
1130 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001131 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001132 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001133 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001134AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder)
1135 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001136
1137// ============================================================
1138// Stream Control
1139// ============================================================
1140
1141/**
Phil Burk8b4e05e2019-12-17 12:12:09 -08001142 * Free the audio resources associated with a stream created by
1143 * AAudioStreamBuilder_openStream().
1144 * AAudioStream_close() should be called at some point after calling
1145 * this function.
Phil Burk5ed503c2017-02-01 09:38:15 -08001146 *
Phil Burk8b4e05e2019-12-17 12:12:09 -08001147 * After this call, the stream will be in {@link #AAUDIO_STREAM_STATE_CLOSING}
1148 *
Phil Burk41561762020-02-05 14:20:33 -08001149 * This function is useful if you want to release the audio resources immediately,
1150 * but still allow queries to the stream to occur from other threads. This often
1151 * happens if you are monitoring stream progress from a UI thread.
1152 *
Phil Burk320910f2020-08-12 14:29:10 +00001153 * NOTE: This function is only fully implemented for MMAP streams,
1154 * which are low latency streams supported by some devices.
1155 * On other "Legacy" streams some audio resources will still be in use
1156 * and some callbacks may still be in process after this call.
1157 *
Elliott Hughes81fc8592021-01-26 16:45:07 -08001158 * Available since API level 30.
1159 *
Phil Burk8b4e05e2019-12-17 12:12:09 -08001160 * @param stream reference provided by AAudioStreamBuilder_openStream()
1161 * @return {@link #AAUDIO_OK} or a negative error.
1162 */
1163AAUDIO_API aaudio_result_t AAudioStream_release(AAudioStream* stream) __INTRODUCED_IN(30);
Phil Burk8b4e05e2019-12-17 12:12:09 -08001164
1165/**
1166 * Delete the internal data structures associated with the stream created
1167 * by AAudioStreamBuilder_openStream().
1168 *
1169 * If AAudioStream_release() has not been called then it will be called automatically.
Elliott Hughes64a3b062019-10-29 10:09:30 -07001170 *
Elliott Hughes81fc8592021-01-26 16:45:07 -08001171 * Available since API level 26.
1172 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001173 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001174 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001175 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001176AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001177
1178/**
1179 * Asynchronously request to start playing the stream. For output streams, one should
1180 * write to the stream to fill the buffer before starting.
1181 * Otherwise it will underflow.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001182 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STARTING} or
1183 * {@link #AAUDIO_STREAM_STATE_STARTED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001184 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001185 * Available since API level 26.
1186 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001187 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001188 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001189 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001190AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001191
1192/**
1193 * Asynchronous request for the stream to pause.
1194 * Pausing a stream will freeze the data flow but not flush any buffers.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001195 * Use AAudioStream_requestStart() to resume playback after a pause.
1196 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_PAUSING} or
1197 * {@link #AAUDIO_STREAM_STATE_PAUSED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001198 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001199 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001200 * For input streams use AAudioStream_requestStop().
1201 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001202 * Available since API level 26.
1203 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001204 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001205 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001206 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001207AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001208
1209/**
1210 * Asynchronous request for the stream to flush.
1211 * Flushing will discard any pending data.
1212 * This call only works if the stream is pausing or paused. TODO review
1213 * Frame counters are not reset by a flush. They may be advanced.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001214 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_FLUSHING} or
1215 * {@link #AAUDIO_STREAM_STATE_FLUSHED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001216 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001217 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001218 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001219 * Available since API level 26.
1220 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001221 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001222 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001223 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001224AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001225
1226/**
1227 * Asynchronous request for the stream to stop.
1228 * The stream will stop after all of the data currently buffered has been played.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001229 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STOPPING} or
1230 * {@link #AAUDIO_STREAM_STATE_STOPPED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001231 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001232 * Available since API level 26.
1233 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001234 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001235 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001236 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001237AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001238
1239/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001240 * Query the current state of the client, eg. {@link #AAUDIO_STREAM_STATE_PAUSING}
Phil Burk5ed503c2017-02-01 09:38:15 -08001241 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001242 * This function will immediately return the state without updating the state.
1243 * If you want to update the client state based on the server state then
1244 * call AAudioStream_waitForStateChange() with currentState
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001245 * set to {@link #AAUDIO_STREAM_STATE_UNKNOWN} and a zero timeout.
Phil Burk3316d5e2017-02-15 11:23:01 -08001246 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001247 * Available since API level 26.
1248 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001249 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001250 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001251AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001252
1253/**
1254 * Wait until the current state no longer matches the input state.
1255 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001256 * This will update the current client state.
1257 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001258 * <pre><code>
Phil Burked0a3fe2017-12-05 14:27:43 -08001259 * aaudio_result_t result = AAUDIO_OK;
1260 * aaudio_stream_state_t currentState = AAudioStream_getState(stream);
1261 * aaudio_stream_state_t inputState = currentState;
1262 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) {
Phil Burk5ed503c2017-02-01 09:38:15 -08001263 * result = AAudioStream_waitForStateChange(
Phil Burked0a3fe2017-12-05 14:27:43 -08001264 * stream, inputState, &currentState, MY_TIMEOUT_NANOS);
1265 * inputState = currentState;
Phil Burk5ed503c2017-02-01 09:38:15 -08001266 * }
1267 * </code></pre>
1268 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001269 * Available since API level 26.
1270 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001271 * @param stream A reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001272 * @param inputState The state we want to avoid.
1273 * @param nextState Pointer to a variable that will be set to the new state.
1274 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001275 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001276 */
Phil Burke2155ef2017-02-24 13:50:29 -08001277AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001278 aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState,
1279 int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001280
1281// ============================================================
1282// Stream I/O
1283// ============================================================
1284
1285/**
1286 * Read data from the stream.
1287 *
1288 * The call will wait until the read is complete or until it runs out of time.
1289 * If timeoutNanos is zero then this call will not wait.
1290 *
1291 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1292 * Time will not stop if the thread is asleep.
1293 * So it will be implemented using CLOCK_BOOTTIME.
1294 *
1295 * This call is "strong non-blocking" unless it has to wait for data.
1296 *
Phil Burk8149eed2018-05-24 14:09:46 -07001297 * If the call times out then zero or a partial frame count will be returned.
1298 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001299 * Available since API level 26.
1300 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001301 * @param stream A stream created using AAudioStreamBuilder_openStream().
1302 * @param buffer The address of the first sample.
1303 * @param numFrames Number of frames to read. Only complete frames will be written.
1304 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Phil Burk3316d5e2017-02-15 11:23:01 -08001305 * @return The number of frames actually read or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001306 */
Phil Burke2155ef2017-02-24 13:50:29 -08001307AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001308 void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001309
1310/**
1311 * Write data to the stream.
1312 *
1313 * The call will wait until the write is complete or until it runs out of time.
1314 * If timeoutNanos is zero then this call will not wait.
1315 *
1316 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1317 * Time will not stop if the thread is asleep.
1318 * So it will be implemented using CLOCK_BOOTTIME.
1319 *
1320 * This call is "strong non-blocking" unless it has to wait for room in the buffer.
1321 *
Phil Burk8149eed2018-05-24 14:09:46 -07001322 * If the call times out then zero or a partial frame count will be returned.
1323 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001324 * Available since API level 26.
1325 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001326 * @param stream A stream created using AAudioStreamBuilder_openStream().
1327 * @param buffer The address of the first sample.
1328 * @param numFrames Number of frames to write. Only complete frames will be written.
1329 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1330 * @return The number of frames actually written or a negative error.
1331 */
Phil Burke2155ef2017-02-24 13:50:29 -08001332AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001333 const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001334
Phil Burk5ed503c2017-02-01 09:38:15 -08001335// ============================================================
1336// Stream - queries
1337// ============================================================
1338
Phil Burk5ed503c2017-02-01 09:38:15 -08001339/**
1340 * This can be used to adjust the latency of the buffer by changing
1341 * the threshold where blocking will occur.
Phil Burk3316d5e2017-02-15 11:23:01 -08001342 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
Phil Burk5ed503c2017-02-01 09:38:15 -08001343 * at run-time for each device.
1344 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001345 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
Phil Burk5ed503c2017-02-01 09:38:15 -08001346 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001347 * Note that you will probably not get the exact size you request.
Phil Burk8149eed2018-05-24 14:09:46 -07001348 * You can check the return value or call AAudioStream_getBufferSizeInFrames()
1349 * to see what the actual final size is.
Phil Burk3316d5e2017-02-15 11:23:01 -08001350 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001351 * Available since API level 26.
1352 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001353 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001354 * @param numFrames requested number of frames that can be filled without blocking
Phil Burk3316d5e2017-02-15 11:23:01 -08001355 * @return actual buffer size in frames or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001356 */
Phil Burke2155ef2017-02-24 13:50:29 -08001357AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001358 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001359
1360/**
1361 * Query the maximum number of frames that can be filled without blocking.
1362 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001363 * Available since API level 26.
1364 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001365 * @param stream reference provided by AAudioStreamBuilder_openStream()
1366 * @return buffer size in frames.
Phil Burk5ed503c2017-02-01 09:38:15 -08001367 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001368AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001369
1370/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001371 * Query the number of frames that the application should read or write at
1372 * one time for optimal performance. It is OK if an application writes
1373 * a different number of frames. But the buffer size may need to be larger
1374 * in order to avoid underruns or overruns.
Phil Burk5ed503c2017-02-01 09:38:15 -08001375 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001376 * Note that this may or may not match the actual device burst size.
1377 * For some endpoints, the burst size can vary dynamically.
1378 * But these tend to be devices with high latency.
1379 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001380 * Available since API level 26.
1381 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001382 * @param stream reference provided by AAudioStreamBuilder_openStream()
1383 * @return burst size
Phil Burk5ed503c2017-02-01 09:38:15 -08001384 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001385AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001386
1387/**
1388 * Query maximum buffer capacity in frames.
1389 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001390 * Available since API level 26.
1391 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001392 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001393 * @return buffer capacity in frames
Phil Burk5ed503c2017-02-01 09:38:15 -08001394 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001395AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001396
1397/**
Phil Burke057ca92017-03-28 11:31:34 -07001398 * Query the size of the buffer that will be passed to the dataProc callback
1399 * in the numFrames parameter.
1400 *
1401 * This call can be used if the application needs to know the value of numFrames before
1402 * the stream is started. This is not normally necessary.
1403 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001404 * If a specific size was requested by calling
1405 * AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size.
Phil Burke057ca92017-03-28 11:31:34 -07001406 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001407 * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001408 * return the size chosen by AAudio, or {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -07001409 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001410 * {@link #AAUDIO_UNSPECIFIED} indicates that the callback buffer size for this stream
Phil Burke057ca92017-03-28 11:31:34 -07001411 * may vary from one dataProc callback to the next.
1412 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001413 * Available since API level 26.
1414 *
Phil Burke057ca92017-03-28 11:31:34 -07001415 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001416 * @return callback buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -07001417 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001418AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001419
1420/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001421 * An XRun is an Underrun or an Overrun.
1422 * During playing, an underrun will occur if the stream is not written in time
1423 * and the system runs out of valid data.
1424 * During recording, an overrun will occur if the stream is not read in time
1425 * and there is no place to put the incoming data so it is discarded.
1426 *
1427 * An underrun or overrun can cause an audible "pop" or "glitch".
1428 *
Phil Burk068c10f2017-05-08 16:36:41 -07001429 * Note that some INPUT devices may not support this function.
1430 * In that case a 0 will always be returned.
1431 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001432 * Available since API level 26.
1433 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001434 * @param stream reference provided by AAudioStreamBuilder_openStream()
1435 * @return the underrun or overrun count
Phil Burk5ed503c2017-02-01 09:38:15 -08001436 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001437AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001438
1439/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001440 * Available since API level 26.
1441 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001442 * @param stream reference provided by AAudioStreamBuilder_openStream()
1443 * @return actual sample rate
Phil Burk5ed503c2017-02-01 09:38:15 -08001444 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001445AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001446
1447/**
Phil Burk20523ed2017-04-24 17:04:01 -07001448 * A stream has one or more channels of data.
1449 * A frame will contain one sample for each channel.
1450 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001451 * Available since API level 26.
1452 *
Phil Burk20523ed2017-04-24 17:04:01 -07001453 * @param stream reference provided by AAudioStreamBuilder_openStream()
1454 * @return actual number of channels
1455 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001456AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -07001457
1458/**
Phil Burke74240d2017-08-03 15:25:43 -07001459 * Identical to AAudioStream_getChannelCount().
1460 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001461 * Available since API level 26.
1462 *
Phil Burke74240d2017-08-03 15:25:43 -07001463 * @param stream reference provided by AAudioStreamBuilder_openStream()
1464 * @return actual number of samples frame
1465 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001466AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -07001467
1468/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001469 * Available since API level 26.
1470 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001471 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke2155ef2017-02-24 13:50:29 -08001472 * @return actual device ID
Phil Burk5ed503c2017-02-01 09:38:15 -08001473 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001474AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001475
1476/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001477 * Available since API level 26.
1478 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001479 * @param stream reference provided by AAudioStreamBuilder_openStream()
1480 * @return actual data format
Phil Burk5ed503c2017-02-01 09:38:15 -08001481 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001482AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001483
1484/**
1485 * Provide actual sharing mode.
Elliott Hughes64a3b062019-10-29 10:09:30 -07001486 *
1487 * Available since API level 26.
1488 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001489 * @param stream reference provided by AAudioStreamBuilder_openStream()
1490 * @return actual sharing mode
Phil Burk5ed503c2017-02-01 09:38:15 -08001491 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001492AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream)
1493 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001494
1495/**
Phil Burke2fbb592017-05-01 15:05:52 -07001496 * Get the performance mode used by the stream.
1497 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001498 * Available since API level 26.
1499 *
Phil Burke2fbb592017-05-01 15:05:52 -07001500 * @param stream reference provided by AAudioStreamBuilder_openStream()
1501 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001502AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream)
1503 __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -07001504
1505/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001506 * Available since API level 26.
1507 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001508 * @param stream reference provided by AAudioStreamBuilder_openStream()
1509 * @return direction
Phil Burk5ed503c2017-02-01 09:38:15 -08001510 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001511AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001512
1513/**
1514 * Passes back the number of frames that have been written since the stream was created.
Phil Burk8149eed2018-05-24 14:09:46 -07001515 * For an output stream, this will be advanced by the application calling write()
1516 * or by a data callback.
Phil Burk3316d5e2017-02-15 11:23:01 -08001517 * For an input stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -08001518 *
1519 * The frame position is monotonically increasing.
1520 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001521 * Available since API level 26.
1522 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001523 * @param stream reference provided by AAudioStreamBuilder_openStream()
1524 * @return frames written
Phil Burk5ed503c2017-02-01 09:38:15 -08001525 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001526AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001527
1528/**
1529 * Passes back the number of frames that have been read since the stream was created.
Phil Burk3316d5e2017-02-15 11:23:01 -08001530 * For an output stream, this will be advanced by the endpoint.
Phil Burk8149eed2018-05-24 14:09:46 -07001531 * For an input stream, this will be advanced by the application calling read()
1532 * or by a data callback.
Phil Burk5ed503c2017-02-01 09:38:15 -08001533 *
1534 * The frame position is monotonically increasing.
1535 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001536 * Available since API level 26.
1537 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001538 * @param stream reference provided by AAudioStreamBuilder_openStream()
1539 * @return frames read
Phil Burk5ed503c2017-02-01 09:38:15 -08001540 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001541AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001542
1543/**
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001544 * Passes back the session ID associated with this stream.
1545 *
1546 * The session ID can be used to associate a stream with effects processors.
1547 * The effects are controlled using the Android AudioEffect Java API.
1548 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001549 * If AAudioStreamBuilder_setSessionId() was
1550 * called with {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001551 * then a new session ID should be allocated once when the stream is opened.
1552 *
1553 * If AAudioStreamBuilder_setSessionId() was called with a previously allocated
1554 * session ID then that value should be returned.
1555 *
1556 * If AAudioStreamBuilder_setSessionId() was not called then this function should
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001557 * return {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001558 *
1559 * The sessionID for a stream should not change once the stream has been opened.
1560 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001561 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001562 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001563 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001564 * @return session ID or {@link #AAUDIO_SESSION_ID_NONE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001565 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001566AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001567
1568/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001569 * Passes back the time at which a particular frame was presented.
1570 * This can be used to synchronize audio with video or MIDI.
1571 * It can also be used to align a recorded stream with a playback stream.
1572 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001573 * Timestamps are only valid when the stream is in {@link #AAUDIO_STREAM_STATE_STARTED}.
1574 * {@link #AAUDIO_ERROR_INVALID_STATE} will be returned if the stream is not started.
Phil Burk5ed503c2017-02-01 09:38:15 -08001575 * Note that because requestStart() is asynchronous, timestamps will not be valid until
1576 * a short time after calling requestStart().
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001577 * So {@link #AAUDIO_ERROR_INVALID_STATE} should not be considered a fatal error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001578 * Just try calling again later.
1579 *
1580 * If an error occurs, then the position and time will not be modified.
1581 *
1582 * The position and time passed back are monotonically increasing.
1583 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001584 * Available since API level 26.
1585 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001586 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burkec159502017-07-25 17:33:47 -07001587 * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
Phil Burk5ed503c2017-02-01 09:38:15 -08001588 * @param framePosition pointer to a variable to receive the position
1589 * @param timeNanoseconds pointer to a variable to receive the time
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001590 * @return {@link #AAUDIO_OK} or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001591 */
Phil Burke2155ef2017-02-24 13:50:29 -08001592AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001593 clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001594
Phil Burk361b1422017-12-20 14:24:16 -08001595/**
1596 * Return the use case for the stream.
1597 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001598 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001599 *
Phil Burk361b1422017-12-20 14:24:16 -08001600 * @param stream reference provided by AAudioStreamBuilder_openStream()
1601 * @return frames read
1602 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001603AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001604
1605/**
1606 * Return the content type for the stream.
1607 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001608 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001609 *
Phil Burk361b1422017-12-20 14:24:16 -08001610 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001611 * @return content type, for example {@link #AAUDIO_CONTENT_TYPE_MUSIC}
Phil Burk361b1422017-12-20 14:24:16 -08001612 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001613AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream)
1614 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001615
1616/**
1617 * Return the input preset for the stream.
1618 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001619 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001620 *
Phil Burk361b1422017-12-20 14:24:16 -08001621 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001622 * @return input preset, for example {@link #AAUDIO_INPUT_PRESET_CAMCORDER}
Phil Burk361b1422017-12-20 14:24:16 -08001623 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001624AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream)
1625 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001626
Kevin Rocard68646ba2019-03-20 13:26:49 -07001627/**
1628 * Return the policy that determines whether the audio may or may not be captured
1629 * by other apps or the system.
1630 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001631 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -07001632 *
1633 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001634 * @return the allowed capture policy, for example {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}
Kevin Rocard68646ba2019-03-20 13:26:49 -07001635 */
1636AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
1637 AAudioStream* stream) __INTRODUCED_IN(29);
1638
Eric Laurentd17c8502019-10-24 15:58:35 -07001639
1640/**
1641 * Return whether this input stream is marked as privacy sensitive or not.
1642 *
1643 * See {@link #AAudioStreamBuilder_setPrivacySensitive()}.
1644 *
1645 * Added in API level 30.
1646 *
1647 * @param stream reference provided by AAudioStreamBuilder_openStream()
1648 * @return true if privacy sensitive, false otherwise
1649 */
1650AAUDIO_API bool AAudioStream_isPrivacySensitive(AAudioStream* stream)
1651 __INTRODUCED_IN(30);
1652
Phil Burk5ed503c2017-02-01 09:38:15 -08001653#ifdef __cplusplus
1654}
1655#endif
1656
1657#endif //AAUDIO_AAUDIO_H
Phil Burka45be8b2017-04-05 14:45:48 -07001658
1659/** @} */