blob: 333392546c4934def3c7233337fd14fbf510f336 [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// TODO b/182392769: reexamine if Identity can be used
639/**
640 * Declare the name of the package creating the stream.
641 *
642 * This is usually {@code Context#getPackageName()}.
643 *
644 * The default, if you do not call this function, is a random package in the calling uid.
645 *
646 * Available since API level 31.
647 *
648 * @param builder reference provided by AAudio_createStreamBuilder()
649 * @param packageName packageName of the calling app.
650 */
651AAUDIO_API void AAudioStreamBuilder_setPackageName(AAudioStreamBuilder* builder,
652 const char * packageName) __INTRODUCED_IN(31);
653
654/**
655 * Declare the attribution tag of the context creating the stream.
656 *
657 * This is usually {@code Context#getAttributionTag()}.
658 *
659 * The default, if you do not call this function, is the default attribution tag.
660 *
661 * Available since API level 31.
662 *
663 * @param builder reference provided by AAudio_createStreamBuilder()
664 * @param attributionTag attributionTag of the calling context.
665 */
666AAUDIO_API void AAudioStreamBuilder_setAttributionTag(AAudioStreamBuilder* builder,
667 const char * attributionTag) __INTRODUCED_IN(31);
668
Phil Burk5ed503c2017-02-01 09:38:15 -0800669/**
Phil Burke057ca92017-03-28 11:31:34 -0700670 * Request a sample rate in Hertz.
671 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700672 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700673 * An optimal value will then be chosen when the stream is opened.
674 * After opening a stream with an unspecified value, the application must
675 * query for the actual value, which may vary by device.
676 *
677 * If an exact value is specified then an opened stream will use that value.
678 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700679 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700680 * Available since API level 26.
681 *
Phil Burke057ca92017-03-28 11:31:34 -0700682 * @param builder reference provided by AAudio_createStreamBuilder()
683 * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
Phil Burk5ed503c2017-02-01 09:38:15 -0800684 */
Phil Burke2155ef2017-02-24 13:50:29 -0800685AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700686 int32_t sampleRate) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800687
688/**
Phil Burk20523ed2017-04-24 17:04:01 -0700689 * Request a number of channels for the stream.
Phil Burke057ca92017-03-28 11:31:34 -0700690 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700691 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700692 * An optimal value will then be chosen when the stream is opened.
693 * After opening a stream with an unspecified value, the application must
694 * query for the actual value, which may vary by device.
Phil Burk5ed503c2017-02-01 09:38:15 -0800695 *
Phil Burk8f624892017-05-11 11:44:20 -0700696 * If an exact value is specified then an opened stream will use that value.
697 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700698 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700699 * Available since API level 26.
700 *
Phil Burke057ca92017-03-28 11:31:34 -0700701 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk20523ed2017-04-24 17:04:01 -0700702 * @param channelCount Number of channels desired.
Phil Burk5ed503c2017-02-01 09:38:15 -0800703 */
Phil Burk20523ed2017-04-24 17:04:01 -0700704AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700705 int32_t channelCount) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -0700706
707/**
Phil Burke74240d2017-08-03 15:25:43 -0700708 * Identical to AAudioStreamBuilder_setChannelCount().
709 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700710 * Available since API level 26.
711 *
Phil Burke74240d2017-08-03 15:25:43 -0700712 * @param builder reference provided by AAudio_createStreamBuilder()
713 * @param samplesPerFrame Number of samples in a frame.
714 */
715AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700716 int32_t samplesPerFrame) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -0700717
718/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700719 * Request a sample data format, for example {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burke057ca92017-03-28 11:31:34 -0700720 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700721 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk8f624892017-05-11 11:44:20 -0700722 * An optimal value will then be chosen when the stream is opened.
723 * After opening a stream with an unspecified value, the application must
724 * query for the actual value, which may vary by device.
Phil Burke057ca92017-03-28 11:31:34 -0700725 *
Phil Burk8f624892017-05-11 11:44:20 -0700726 * If an exact value is specified then an opened stream will use that value.
727 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700728 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700729 * Available since API level 26.
730 *
Phil Burke057ca92017-03-28 11:31:34 -0700731 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700732 * @param format common formats are {@link #AAUDIO_FORMAT_PCM_FLOAT} and
733 * {@link #AAUDIO_FORMAT_PCM_I16}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800734 */
Phil Burke2155ef2017-02-24 13:50:29 -0800735AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700736 aaudio_format_t format) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800737
738/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800739 * Request a mode for sharing the device.
Phil Burke057ca92017-03-28 11:31:34 -0700740 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700741 * The default, if you do not call this function, is {@link #AAUDIO_SHARING_MODE_SHARED}.
Phil Burke057ca92017-03-28 11:31:34 -0700742 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800743 * The requested sharing mode may not be available.
Phil Burke057ca92017-03-28 11:31:34 -0700744 * The application can query for the actual mode after the stream is opened.
Phil Burk5ed503c2017-02-01 09:38:15 -0800745 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700746 * Available since API level 26.
747 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800748 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700749 * @param sharingMode {@link #AAUDIO_SHARING_MODE_SHARED} or {@link #AAUDIO_SHARING_MODE_EXCLUSIVE}
Phil Burk5ed503c2017-02-01 09:38:15 -0800750 */
Phil Burke2155ef2017-02-24 13:50:29 -0800751AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700752 aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800753
754/**
Phil Burke057ca92017-03-28 11:31:34 -0700755 * Request the direction for a stream.
756 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700757 * The default, if you do not call this function, is {@link #AAUDIO_DIRECTION_OUTPUT}.
Phil Burk5ed503c2017-02-01 09:38:15 -0800758 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700759 * Available since API level 26.
760 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800761 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700762 * @param direction {@link #AAUDIO_DIRECTION_OUTPUT} or {@link #AAUDIO_DIRECTION_INPUT}
Phil Burk5ed503c2017-02-01 09:38:15 -0800763 */
Phil Burke2155ef2017-02-24 13:50:29 -0800764AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700765 aaudio_direction_t direction) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800766
767/**
Phil Burke057ca92017-03-28 11:31:34 -0700768 * Set the requested buffer capacity in frames.
Phil Burk3df348f2017-02-08 11:41:55 -0800769 * The final AAudioStream capacity may differ, but will probably be at least this big.
770 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700771 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burk3df348f2017-02-08 11:41:55 -0800772 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700773 * Available since API level 26.
774 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800775 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700776 * @param numFrames the desired buffer capacity in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burk3df348f2017-02-08 11:41:55 -0800777 */
Phil Burke2155ef2017-02-24 13:50:29 -0800778AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700779 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700780
781/**
782 * Set the requested performance mode.
783 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700784 * Supported modes are {@link #AAUDIO_PERFORMANCE_MODE_NONE},
785 * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING} * and {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}.
Phil Burk8149eed2018-05-24 14:09:46 -0700786 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700787 * The default, if you do not call this function, is {@link #AAUDIO_PERFORMANCE_MODE_NONE}.
Phil Burke2fbb592017-05-01 15:05:52 -0700788 *
Phil Burk8149eed2018-05-24 14:09:46 -0700789 * You may not get the mode you requested.
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700790 * You can call AAudioStream_getPerformanceMode()
791 * to find out the final mode for the stream.
Phil Burk8149eed2018-05-24 14:09:46 -0700792 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700793 * Available since API level 26.
794 *
Phil Burke2fbb592017-05-01 15:05:52 -0700795 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700796 * @param mode the desired performance mode, eg. {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}
Phil Burke2fbb592017-05-01 15:05:52 -0700797 */
798AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700799 aaudio_performance_mode_t mode) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700800
Phil Burke057ca92017-03-28 11:31:34 -0700801/**
jiabinec3fa352020-08-11 16:29:26 -0700802 * Set the intended use case for the output stream.
Phil Burk361b1422017-12-20 14:24:16 -0800803 *
804 * The AAudio system will use this information to optimize the
805 * behavior of the stream.
806 * This could, for example, affect how volume and focus is handled for the stream.
807 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700808 * The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}.
Phil Burk361b1422017-12-20 14:24:16 -0800809 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700810 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700811 *
Phil Burk361b1422017-12-20 14:24:16 -0800812 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700813 * @param usage the desired usage, eg. {@link #AAUDIO_USAGE_GAME}
Phil Burk361b1422017-12-20 14:24:16 -0800814 */
815AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700816 aaudio_usage_t usage) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800817
818/**
jiabinec3fa352020-08-11 16:29:26 -0700819 * Set the type of audio data that the output stream will carry.
Phil Burk361b1422017-12-20 14:24:16 -0800820 *
821 * The AAudio system will use this information to optimize the
822 * behavior of the stream.
823 * This could, for example, affect whether a stream is paused when a notification occurs.
824 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700825 * The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}.
Phil Burk361b1422017-12-20 14:24:16 -0800826 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700827 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700828 *
Phil Burk361b1422017-12-20 14:24:16 -0800829 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700830 * @param contentType the type of audio data, eg. {@link #AAUDIO_CONTENT_TYPE_SPEECH}
Phil Burk361b1422017-12-20 14:24:16 -0800831 */
832AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700833 aaudio_content_type_t contentType) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800834
835/**
836 * Set the input (capture) preset for the stream.
837 *
838 * The AAudio system will use this information to optimize the
839 * behavior of the stream.
840 * This could, for example, affect which microphones are used and how the
841 * recorded data is processed.
842 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700843 * The default, if you do not call this function, is {@link #AAUDIO_INPUT_PRESET_VOICE_RECOGNITION}.
Phil Burkeaef9b92018-01-18 09:09:42 -0800844 * That is because VOICE_RECOGNITION is the preset with the lowest latency
845 * on many platforms.
Phil Burk361b1422017-12-20 14:24:16 -0800846 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700847 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700848 *
Phil Burk361b1422017-12-20 14:24:16 -0800849 * @param builder reference provided by AAudio_createStreamBuilder()
850 * @param inputPreset the desired configuration for recording
851 */
852AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700853 aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800854
Kevin Rocard68646ba2019-03-20 13:26:49 -0700855/**
856 * Specify whether this stream audio may or may not be captured by other apps or the system.
857 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700858 * The default is {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700859 *
860 * Note that an application can also set its global policy, in which case the most restrictive
gfan4db8ba42021-04-06 15:05:30 -0700861 * policy is always applied. See
862 * <a href="/reference/android/media/AudioManager#setAllowedCapturePolicy(int)">
863 * setAllowedCapturePolicy(int)</a>
Kevin Rocard68646ba2019-03-20 13:26:49 -0700864 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700865 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700866 *
867 * @param builder reference provided by AAudio_createStreamBuilder()
Glenn Kastend3080c32019-10-24 09:54:56 -0700868 * @param capturePolicy the desired level of opt-out from being captured.
Kevin Rocard68646ba2019-03-20 13:26:49 -0700869 */
870AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder,
871 aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29);
872
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800873/** Set the requested session ID.
874 *
875 * The session ID can be used to associate a stream with effects processors.
876 * The effects are controlled using the Android AudioEffect Java API.
877 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700878 * The default, if you do not call this function, is {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800879 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700880 * If set to {@link #AAUDIO_SESSION_ID_ALLOCATE} then a session ID will be allocated
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800881 * when the stream is opened.
882 *
883 * The allocated session ID can be obtained by calling AAudioStream_getSessionId()
884 * and then used with this function when opening another stream.
885 * This allows effects to be shared between streams.
886 *
Phil Burk8149eed2018-05-24 14:09:46 -0700887 * Session IDs from AAudio can be used with the Android Java APIs and vice versa.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800888 * So a session ID from an AAudio stream can be passed to Java
889 * and effects applied using the Java AudioEffect API.
890 *
Phil Burk8149eed2018-05-24 14:09:46 -0700891 * Note that allocating or setting a session ID may result in a stream with higher latency.
892 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800893 * Allocated session IDs will always be positive and nonzero.
894 *
Elliott Hughes64a3b062019-10-29 10:09:30 -0700895 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -0700896 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800897 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -0700898 * @param sessionId an allocated sessionID or {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800899 */
900AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700901 aaudio_session_id_t sessionId) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800902
Eric Laurentd17c8502019-10-24 15:58:35 -0700903
904/** Indicates whether this input stream must be marked as privacy sensitive or not.
905 *
906 * When true, this input stream is privacy sensitive and any concurrent capture
907 * is not permitted.
908 *
909 * This is off (false) by default except when the input preset is {@link #AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION}
910 * or {@link #AAUDIO_INPUT_PRESET_CAMCORDER}.
911 *
912 * Always takes precedence over default from input preset when set explicitly.
913 *
914 * Only relevant if the stream direction is {@link #AAUDIO_DIRECTION_INPUT}.
915 *
916 * Added in API level 30.
917 *
918 * @param builder reference provided by AAudio_createStreamBuilder()
919 * @param privacySensitive true if capture from this stream must be marked as privacy sensitive,
920 * false otherwise.
921 */
922AAUDIO_API void AAudioStreamBuilder_setPrivacySensitive(AAudioStreamBuilder* builder,
923 bool privacySensitive) __INTRODUCED_IN(30);
924
Phil Burk361b1422017-12-20 14:24:16 -0800925/**
Phil Burke057ca92017-03-28 11:31:34 -0700926 * Return one of these values from the data callback function.
927 */
928enum {
929
930 /**
931 * Continue calling the callback.
932 */
933 AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
934
935 /**
936 * Stop calling the callback.
937 *
938 * The application will still need to call AAudioStream_requestPause()
939 * or AAudioStream_requestStop().
940 */
941 AAUDIO_CALLBACK_RESULT_STOP,
942
943};
944typedef int32_t aaudio_data_callback_result_t;
945
946/**
947 * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
948 *
949 * For an output stream, this function should render and write numFrames of data
950 * in the streams current data format to the audioData buffer.
951 *
952 * For an input stream, this function should read and process numFrames of data
953 * from the audioData buffer.
954 *
Phil Burked0a3fe2017-12-05 14:27:43 -0800955 * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or
956 * AAudioStream_write() on the stream that is making the callback.
957 *
958 * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback()
959 * is called.
960 *
961 * Also note that this callback function should be considered a "real-time" function.
Phil Burke057ca92017-03-28 11:31:34 -0700962 * It must not do anything that could cause an unbounded delay because that can cause the
963 * audio to glitch or pop.
964 *
965 * These are things the function should NOT do:
966 * <ul>
967 * <li>allocate memory using, for example, malloc() or new</li>
968 * <li>any file operations such as opening, closing, reading or writing</li>
969 * <li>any network operations such as streaming</li>
970 * <li>use any mutexes or other synchronization primitives</li>
971 * <li>sleep</li>
Phil Burked0a3fe2017-12-05 14:27:43 -0800972 * <li>stop or close the stream</li>
Phil Burk8149eed2018-05-24 14:09:46 -0700973 * <li>AAudioStream_read()</li>
974 * <li>AAudioStream_write()</li>
975 * </ul>
976 *
977 * The following are OK to call from the data callback:
978 * <ul>
979 * <li>AAudioStream_get*()</li>
980 * <li>AAudio_convertResultToText()</li>
Phil Burke057ca92017-03-28 11:31:34 -0700981 * </ul>
982 *
983 * If you need to move data, eg. MIDI commands, in or out of the callback function then
984 * we recommend the use of non-blocking techniques such as an atomic FIFO.
985 *
986 * @param stream reference provided by AAudioStreamBuilder_openStream()
987 * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
988 * @param audioData a pointer to the audio data
Phil Burked0a3fe2017-12-05 14:27:43 -0800989 * @param numFrames the number of frames to be processed, which can vary
Phil Burke057ca92017-03-28 11:31:34 -0700990 * @return AAUDIO_CALLBACK_RESULT_*
991 */
992typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
993 AAudioStream *stream,
994 void *userData,
995 void *audioData,
996 int32_t numFrames);
997
998/**
999 * Request that AAudio call this functions when the stream is running.
1000 *
1001 * Note that when using this callback, the audio data will be passed in or out
1002 * of the function as an argument.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001003 * So you cannot call AAudioStream_write() or AAudioStream_read()
1004 * on the same stream that has an active data callback.
Phil Burke057ca92017-03-28 11:31:34 -07001005 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001006 * The callback function will start being called after AAudioStream_requestStart()
1007 * is called.
Phil Burke057ca92017-03-28 11:31:34 -07001008 * It will stop being called after AAudioStream_requestPause() or
1009 * AAudioStream_requestStop() is called.
1010 *
Phil Burk0cb1b542020-11-25 01:01:18 +00001011 * This callback function will be called on a real-time thread owned by AAudio.
1012 * The low latency streams may have callback threads with higher priority than normal streams.
1013 * See {@link #AAudioStream_dataCallback} for more information.
Phil Burke057ca92017-03-28 11:31:34 -07001014 *
1015 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
1016 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001017 * Available since API level 26.
1018 *
Phil Burke057ca92017-03-28 11:31:34 -07001019 * @param builder reference provided by AAudio_createStreamBuilder()
1020 * @param callback pointer to a function that will process audio data.
1021 * @param userData pointer to an application data structure that will be passed
1022 * to the callback functions.
1023 */
1024AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001025 AAudioStream_dataCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001026
1027/**
1028 * Set the requested data callback buffer size in frames.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001029 * See {@link #AAudioStream_dataCallback}.
Phil Burke057ca92017-03-28 11:31:34 -07001030 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001031 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -07001032 *
1033 * For the lowest possible latency, do not call this function. AAudio will then
1034 * call the dataProc callback function with whatever size is optimal.
1035 * That size may vary from one callback to another.
1036 *
1037 * Only use this function if the application requires a specific number of frames for processing.
1038 * The application might, for example, be using an FFT that requires
1039 * a specific power-of-two sized buffer.
1040 *
1041 * AAudio may need to add additional buffering in order to adapt between the internal
1042 * buffer size and the requested buffer size.
1043 *
1044 * If you do call this function then the requested size should be less than
1045 * half the buffer capacity, to allow double buffering.
1046 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001047 * Available since API level 26.
1048 *
Phil Burke057ca92017-03-28 11:31:34 -07001049 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001050 * @param numFrames the desired buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -07001051 */
1052AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001053 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001054
1055/**
1056 * Prototype for the callback function that is passed to
1057 * AAudioStreamBuilder_setErrorCallback().
1058 *
Phil Burk8149eed2018-05-24 14:09:46 -07001059 * The following may NOT be called from the error callback:
1060 * <ul>
1061 * <li>AAudioStream_requestStop()</li>
1062 * <li>AAudioStream_requestPause()</li>
1063 * <li>AAudioStream_close()</li>
1064 * <li>AAudioStream_waitForStateChange()</li>
1065 * <li>AAudioStream_read()</li>
1066 * <li>AAudioStream_write()</li>
1067 * </ul>
1068 *
1069 * The following are OK to call from the error callback:
1070 * <ul>
1071 * <li>AAudioStream_get*()</li>
1072 * <li>AAudio_convertResultToText()</li>
1073 * </ul>
1074 *
Phil Burke057ca92017-03-28 11:31:34 -07001075 * @param stream reference provided by AAudioStreamBuilder_openStream()
1076 * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
1077 * @param error an AAUDIO_ERROR_* value.
1078 */
1079typedef void (*AAudioStream_errorCallback)(
1080 AAudioStream *stream,
1081 void *userData,
1082 aaudio_result_t error);
1083
1084/**
Phil Burked0a3fe2017-12-05 14:27:43 -08001085 * Request that AAudio call this function if any error occurs or the stream is disconnected.
Phil Burke057ca92017-03-28 11:31:34 -07001086 *
1087 * 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 -08001088 * device to be unavailable or "disconnected".
Phil Burke057ca92017-03-28 11:31:34 -07001089 * Another possible cause of error would be a timeout or an unanticipated internal error.
1090 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001091 * In response, this function should signal or create another thread to stop
1092 * and close this stream. The other thread could then reopen a stream on another device.
1093 * Do not stop or close the stream, or reopen the new stream, directly from this callback.
1094 *
1095 * This callback will not be called because of actions by the application, such as stopping
1096 * or closing a stream.
1097 *
Phil Burke057ca92017-03-28 11:31:34 -07001098 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
1099 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001100 * Available since API level 26.
1101 *
Phil Burke057ca92017-03-28 11:31:34 -07001102 * @param builder reference provided by AAudio_createStreamBuilder()
1103 * @param callback pointer to a function that will be called if an error occurs.
1104 * @param userData pointer to an application data structure that will be passed
1105 * to the callback functions.
1106 */
1107AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001108 AAudioStream_errorCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001109
1110/**
1111 * Open a stream based on the options in the StreamBuilder.
1112 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001113 * AAudioStream_close() must be called when finished with the stream to recover
Phil Burk5ed503c2017-02-01 09:38:15 -08001114 * the memory and to free the associated resources.
1115 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001116 * Available since API level 26.
1117 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001118 * @param builder reference provided by AAudio_createStreamBuilder()
1119 * @param stream pointer to a variable to receive the new stream reference
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001120 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001121 */
Phil Burke2155ef2017-02-24 13:50:29 -08001122AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -07001123 AAudioStream** stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001124
1125/**
1126 * Delete the resources associated with the StreamBuilder.
1127 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001128 * Available since API level 26.
1129 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001130 * @param builder reference provided by AAudio_createStreamBuilder()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001131 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001132 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001133AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder)
1134 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001135
1136// ============================================================
1137// Stream Control
1138// ============================================================
1139
1140/**
Phil Burk8b4e05e2019-12-17 12:12:09 -08001141 * Free the audio resources associated with a stream created by
1142 * AAudioStreamBuilder_openStream().
1143 * AAudioStream_close() should be called at some point after calling
1144 * this function.
Phil Burk5ed503c2017-02-01 09:38:15 -08001145 *
Phil Burk8b4e05e2019-12-17 12:12:09 -08001146 * After this call, the stream will be in {@link #AAUDIO_STREAM_STATE_CLOSING}
1147 *
Phil Burk41561762020-02-05 14:20:33 -08001148 * This function is useful if you want to release the audio resources immediately,
1149 * but still allow queries to the stream to occur from other threads. This often
1150 * happens if you are monitoring stream progress from a UI thread.
1151 *
Phil Burk320910f2020-08-12 14:29:10 +00001152 * NOTE: This function is only fully implemented for MMAP streams,
1153 * which are low latency streams supported by some devices.
1154 * On other "Legacy" streams some audio resources will still be in use
1155 * and some callbacks may still be in process after this call.
1156 *
Elliott Hughes81fc8592021-01-26 16:45:07 -08001157 * Available since API level 30.
1158 *
Phil Burk8b4e05e2019-12-17 12:12:09 -08001159 * @param stream reference provided by AAudioStreamBuilder_openStream()
1160 * @return {@link #AAUDIO_OK} or a negative error.
1161 */
1162AAUDIO_API aaudio_result_t AAudioStream_release(AAudioStream* stream) __INTRODUCED_IN(30);
Phil Burk8b4e05e2019-12-17 12:12:09 -08001163
1164/**
1165 * Delete the internal data structures associated with the stream created
1166 * by AAudioStreamBuilder_openStream().
1167 *
1168 * If AAudioStream_release() has not been called then it will be called automatically.
Elliott Hughes64a3b062019-10-29 10:09:30 -07001169 *
Elliott Hughes81fc8592021-01-26 16:45:07 -08001170 * Available since API level 26.
1171 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001172 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001173 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001174 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001175AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001176
1177/**
1178 * Asynchronously request to start playing the stream. For output streams, one should
1179 * write to the stream to fill the buffer before starting.
1180 * Otherwise it will underflow.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001181 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STARTING} or
1182 * {@link #AAUDIO_STREAM_STATE_STARTED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001183 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001184 * Available since API level 26.
1185 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001186 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001187 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001188 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001189AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001190
1191/**
1192 * Asynchronous request for the stream to pause.
1193 * Pausing a stream will freeze the data flow but not flush any buffers.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001194 * Use AAudioStream_requestStart() to resume playback after a pause.
1195 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_PAUSING} or
1196 * {@link #AAUDIO_STREAM_STATE_PAUSED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001197 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001198 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001199 * For input streams use AAudioStream_requestStop().
1200 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001201 * Available since API level 26.
1202 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001203 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001204 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001205 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001206AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001207
1208/**
1209 * Asynchronous request for the stream to flush.
1210 * Flushing will discard any pending data.
1211 * This call only works if the stream is pausing or paused. TODO review
1212 * Frame counters are not reset by a flush. They may be advanced.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001213 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_FLUSHING} or
1214 * {@link #AAUDIO_STREAM_STATE_FLUSHED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001215 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001216 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams.
Phil Burk068c10f2017-05-08 16:36:41 -07001217 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001218 * Available since API level 26.
1219 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001220 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001221 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001222 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001223AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001224
1225/**
1226 * Asynchronous request for the stream to stop.
1227 * The stream will stop after all of the data currently buffered has been played.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001228 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STOPPING} or
1229 * {@link #AAUDIO_STREAM_STATE_STOPPED}.
Phil Burk5ed503c2017-02-01 09:38:15 -08001230 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001231 * Available since API level 26.
1232 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001233 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001234 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001235 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001236AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001237
1238/**
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001239 * Query the current state of the client, eg. {@link #AAUDIO_STREAM_STATE_PAUSING}
Phil Burk5ed503c2017-02-01 09:38:15 -08001240 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001241 * This function will immediately return the state without updating the state.
1242 * If you want to update the client state based on the server state then
1243 * call AAudioStream_waitForStateChange() with currentState
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001244 * set to {@link #AAUDIO_STREAM_STATE_UNKNOWN} and a zero timeout.
Phil Burk3316d5e2017-02-15 11:23:01 -08001245 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001246 * Available since API level 26.
1247 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001248 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001249 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001250AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001251
1252/**
1253 * Wait until the current state no longer matches the input state.
1254 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001255 * This will update the current client state.
1256 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001257 * <pre><code>
Phil Burked0a3fe2017-12-05 14:27:43 -08001258 * aaudio_result_t result = AAUDIO_OK;
1259 * aaudio_stream_state_t currentState = AAudioStream_getState(stream);
1260 * aaudio_stream_state_t inputState = currentState;
1261 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) {
Phil Burk5ed503c2017-02-01 09:38:15 -08001262 * result = AAudioStream_waitForStateChange(
Phil Burked0a3fe2017-12-05 14:27:43 -08001263 * stream, inputState, &currentState, MY_TIMEOUT_NANOS);
1264 * inputState = currentState;
Phil Burk5ed503c2017-02-01 09:38:15 -08001265 * }
1266 * </code></pre>
1267 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001268 * Available since API level 26.
1269 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001270 * @param stream A reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001271 * @param inputState The state we want to avoid.
1272 * @param nextState Pointer to a variable that will be set to the new state.
1273 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001274 * @return {@link #AAUDIO_OK} or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001275 */
Phil Burke2155ef2017-02-24 13:50:29 -08001276AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001277 aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState,
1278 int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001279
1280// ============================================================
1281// Stream I/O
1282// ============================================================
1283
1284/**
1285 * Read data from the stream.
1286 *
1287 * The call will wait until the read is complete or until it runs out of time.
1288 * If timeoutNanos is zero then this call will not wait.
1289 *
1290 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1291 * Time will not stop if the thread is asleep.
1292 * So it will be implemented using CLOCK_BOOTTIME.
1293 *
1294 * This call is "strong non-blocking" unless it has to wait for data.
1295 *
Phil Burk8149eed2018-05-24 14:09:46 -07001296 * If the call times out then zero or a partial frame count will be returned.
1297 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001298 * Available since API level 26.
1299 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001300 * @param stream A stream created using AAudioStreamBuilder_openStream().
1301 * @param buffer The address of the first sample.
1302 * @param numFrames Number of frames to read. Only complete frames will be written.
1303 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Phil Burk3316d5e2017-02-15 11:23:01 -08001304 * @return The number of frames actually read or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001305 */
Phil Burke2155ef2017-02-24 13:50:29 -08001306AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001307 void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001308
1309/**
1310 * Write data to the stream.
1311 *
1312 * The call will wait until the write is complete or until it runs out of time.
1313 * If timeoutNanos is zero then this call will not wait.
1314 *
1315 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1316 * Time will not stop if the thread is asleep.
1317 * So it will be implemented using CLOCK_BOOTTIME.
1318 *
1319 * This call is "strong non-blocking" unless it has to wait for room in the buffer.
1320 *
Phil Burk8149eed2018-05-24 14:09:46 -07001321 * If the call times out then zero or a partial frame count will be returned.
1322 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001323 * Available since API level 26.
1324 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001325 * @param stream A stream created using AAudioStreamBuilder_openStream().
1326 * @param buffer The address of the first sample.
1327 * @param numFrames Number of frames to write. Only complete frames will be written.
1328 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1329 * @return The number of frames actually written or a negative error.
1330 */
Phil Burke2155ef2017-02-24 13:50:29 -08001331AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001332 const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001333
Phil Burk5ed503c2017-02-01 09:38:15 -08001334// ============================================================
1335// Stream - queries
1336// ============================================================
1337
Phil Burk5ed503c2017-02-01 09:38:15 -08001338/**
1339 * This can be used to adjust the latency of the buffer by changing
1340 * the threshold where blocking will occur.
Phil Burk3316d5e2017-02-15 11:23:01 -08001341 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
Phil Burk5ed503c2017-02-01 09:38:15 -08001342 * at run-time for each device.
1343 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001344 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
Phil Burk5ed503c2017-02-01 09:38:15 -08001345 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001346 * Note that you will probably not get the exact size you request.
Phil Burk8149eed2018-05-24 14:09:46 -07001347 * You can check the return value or call AAudioStream_getBufferSizeInFrames()
1348 * to see what the actual final size is.
Phil Burk3316d5e2017-02-15 11:23:01 -08001349 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001350 * Available since API level 26.
1351 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001352 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001353 * @param numFrames requested number of frames that can be filled without blocking
Phil Burk3316d5e2017-02-15 11:23:01 -08001354 * @return actual buffer size in frames or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001355 */
Phil Burke2155ef2017-02-24 13:50:29 -08001356AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001357 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001358
1359/**
1360 * Query the maximum number of frames that can be filled without blocking.
1361 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001362 * Available since API level 26.
1363 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001364 * @param stream reference provided by AAudioStreamBuilder_openStream()
1365 * @return buffer size in frames.
Phil Burk5ed503c2017-02-01 09:38:15 -08001366 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001367AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001368
1369/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001370 * Query the number of frames that the application should read or write at
1371 * one time for optimal performance. It is OK if an application writes
1372 * a different number of frames. But the buffer size may need to be larger
1373 * in order to avoid underruns or overruns.
Phil Burk5ed503c2017-02-01 09:38:15 -08001374 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001375 * Note that this may or may not match the actual device burst size.
1376 * For some endpoints, the burst size can vary dynamically.
1377 * But these tend to be devices with high latency.
1378 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001379 * Available since API level 26.
1380 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001381 * @param stream reference provided by AAudioStreamBuilder_openStream()
1382 * @return burst size
Phil Burk5ed503c2017-02-01 09:38:15 -08001383 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001384AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001385
1386/**
1387 * Query maximum buffer capacity in frames.
1388 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001389 * Available since API level 26.
1390 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001391 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001392 * @return buffer capacity in frames
Phil Burk5ed503c2017-02-01 09:38:15 -08001393 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001394AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001395
1396/**
Phil Burke057ca92017-03-28 11:31:34 -07001397 * Query the size of the buffer that will be passed to the dataProc callback
1398 * in the numFrames parameter.
1399 *
1400 * This call can be used if the application needs to know the value of numFrames before
1401 * the stream is started. This is not normally necessary.
1402 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001403 * If a specific size was requested by calling
1404 * AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size.
Phil Burke057ca92017-03-28 11:31:34 -07001405 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001406 * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001407 * return the size chosen by AAudio, or {@link #AAUDIO_UNSPECIFIED}.
Phil Burke057ca92017-03-28 11:31:34 -07001408 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001409 * {@link #AAUDIO_UNSPECIFIED} indicates that the callback buffer size for this stream
Phil Burke057ca92017-03-28 11:31:34 -07001410 * may vary from one dataProc callback to the next.
1411 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001412 * Available since API level 26.
1413 *
Phil Burke057ca92017-03-28 11:31:34 -07001414 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001415 * @return callback buffer size in frames or {@link #AAUDIO_UNSPECIFIED}
Phil Burke057ca92017-03-28 11:31:34 -07001416 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001417AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001418
1419/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001420 * An XRun is an Underrun or an Overrun.
1421 * During playing, an underrun will occur if the stream is not written in time
1422 * and the system runs out of valid data.
1423 * During recording, an overrun will occur if the stream is not read in time
1424 * and there is no place to put the incoming data so it is discarded.
1425 *
1426 * An underrun or overrun can cause an audible "pop" or "glitch".
1427 *
Phil Burk068c10f2017-05-08 16:36:41 -07001428 * Note that some INPUT devices may not support this function.
1429 * In that case a 0 will always be returned.
1430 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001431 * Available since API level 26.
1432 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001433 * @param stream reference provided by AAudioStreamBuilder_openStream()
1434 * @return the underrun or overrun count
Phil Burk5ed503c2017-02-01 09:38:15 -08001435 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001436AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001437
1438/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001439 * Available since API level 26.
1440 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001441 * @param stream reference provided by AAudioStreamBuilder_openStream()
1442 * @return actual sample rate
Phil Burk5ed503c2017-02-01 09:38:15 -08001443 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001444AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001445
1446/**
Phil Burk20523ed2017-04-24 17:04:01 -07001447 * A stream has one or more channels of data.
1448 * A frame will contain one sample for each channel.
1449 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001450 * Available since API level 26.
1451 *
Phil Burk20523ed2017-04-24 17:04:01 -07001452 * @param stream reference provided by AAudioStreamBuilder_openStream()
1453 * @return actual number of channels
1454 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001455AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -07001456
1457/**
Phil Burke74240d2017-08-03 15:25:43 -07001458 * Identical to AAudioStream_getChannelCount().
1459 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001460 * Available since API level 26.
1461 *
Phil Burke74240d2017-08-03 15:25:43 -07001462 * @param stream reference provided by AAudioStreamBuilder_openStream()
1463 * @return actual number of samples frame
1464 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001465AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -07001466
1467/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001468 * Available since API level 26.
1469 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001470 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke2155ef2017-02-24 13:50:29 -08001471 * @return actual device ID
Phil Burk5ed503c2017-02-01 09:38:15 -08001472 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001473AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001474
1475/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001476 * Available since API level 26.
1477 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001478 * @param stream reference provided by AAudioStreamBuilder_openStream()
1479 * @return actual data format
Phil Burk5ed503c2017-02-01 09:38:15 -08001480 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001481AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001482
1483/**
1484 * Provide actual sharing mode.
Elliott Hughes64a3b062019-10-29 10:09:30 -07001485 *
1486 * Available since API level 26.
1487 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001488 * @param stream reference provided by AAudioStreamBuilder_openStream()
1489 * @return actual sharing mode
Phil Burk5ed503c2017-02-01 09:38:15 -08001490 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001491AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream)
1492 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001493
1494/**
Phil Burke2fbb592017-05-01 15:05:52 -07001495 * Get the performance mode used by the stream.
1496 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001497 * Available since API level 26.
1498 *
Phil Burke2fbb592017-05-01 15:05:52 -07001499 * @param stream reference provided by AAudioStreamBuilder_openStream()
1500 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001501AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream)
1502 __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -07001503
1504/**
Elliott Hughes64a3b062019-10-29 10:09:30 -07001505 * Available since API level 26.
1506 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001507 * @param stream reference provided by AAudioStreamBuilder_openStream()
1508 * @return direction
Phil Burk5ed503c2017-02-01 09:38:15 -08001509 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001510AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001511
1512/**
1513 * Passes back the number of frames that have been written since the stream was created.
Phil Burk8149eed2018-05-24 14:09:46 -07001514 * For an output stream, this will be advanced by the application calling write()
1515 * or by a data callback.
Phil Burk3316d5e2017-02-15 11:23:01 -08001516 * For an input stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -08001517 *
1518 * The frame position is monotonically increasing.
1519 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001520 * Available since API level 26.
1521 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001522 * @param stream reference provided by AAudioStreamBuilder_openStream()
1523 * @return frames written
Phil Burk5ed503c2017-02-01 09:38:15 -08001524 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001525AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001526
1527/**
1528 * Passes back the number of frames that have been read since the stream was created.
Phil Burk3316d5e2017-02-15 11:23:01 -08001529 * For an output stream, this will be advanced by the endpoint.
Phil Burk8149eed2018-05-24 14:09:46 -07001530 * For an input stream, this will be advanced by the application calling read()
1531 * or by a data callback.
Phil Burk5ed503c2017-02-01 09:38:15 -08001532 *
1533 * The frame position is monotonically increasing.
1534 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001535 * Available since API level 26.
1536 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001537 * @param stream reference provided by AAudioStreamBuilder_openStream()
1538 * @return frames read
Phil Burk5ed503c2017-02-01 09:38:15 -08001539 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001540AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001541
1542/**
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001543 * Passes back the session ID associated with this stream.
1544 *
1545 * The session ID can be used to associate a stream with effects processors.
1546 * The effects are controlled using the Android AudioEffect Java API.
1547 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001548 * If AAudioStreamBuilder_setSessionId() was
1549 * called with {@link #AAUDIO_SESSION_ID_ALLOCATE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001550 * then a new session ID should be allocated once when the stream is opened.
1551 *
1552 * If AAudioStreamBuilder_setSessionId() was called with a previously allocated
1553 * session ID then that value should be returned.
1554 *
1555 * If AAudioStreamBuilder_setSessionId() was not called then this function should
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001556 * return {@link #AAUDIO_SESSION_ID_NONE}.
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001557 *
1558 * The sessionID for a stream should not change once the stream has been opened.
1559 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001560 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001561 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001562 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001563 * @return session ID or {@link #AAUDIO_SESSION_ID_NONE}
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001564 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001565AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001566
1567/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001568 * Passes back the time at which a particular frame was presented.
1569 * This can be used to synchronize audio with video or MIDI.
1570 * It can also be used to align a recorded stream with a playback stream.
1571 *
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001572 * Timestamps are only valid when the stream is in {@link #AAUDIO_STREAM_STATE_STARTED}.
1573 * {@link #AAUDIO_ERROR_INVALID_STATE} will be returned if the stream is not started.
Phil Burk5ed503c2017-02-01 09:38:15 -08001574 * Note that because requestStart() is asynchronous, timestamps will not be valid until
1575 * a short time after calling requestStart().
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001576 * So {@link #AAUDIO_ERROR_INVALID_STATE} should not be considered a fatal error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001577 * Just try calling again later.
1578 *
1579 * If an error occurs, then the position and time will not be modified.
1580 *
1581 * The position and time passed back are monotonically increasing.
1582 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001583 * Available since API level 26.
1584 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001585 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burkec159502017-07-25 17:33:47 -07001586 * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
Phil Burk5ed503c2017-02-01 09:38:15 -08001587 * @param framePosition pointer to a variable to receive the position
1588 * @param timeNanoseconds pointer to a variable to receive the time
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001589 * @return {@link #AAUDIO_OK} or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001590 */
Phil Burke2155ef2017-02-24 13:50:29 -08001591AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001592 clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001593
Phil Burk361b1422017-12-20 14:24:16 -08001594/**
1595 * Return the use case for the stream.
1596 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001597 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001598 *
Phil Burk361b1422017-12-20 14:24:16 -08001599 * @param stream reference provided by AAudioStreamBuilder_openStream()
1600 * @return frames read
1601 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001602AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001603
1604/**
1605 * Return the content type for the stream.
1606 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001607 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001608 *
Phil Burk361b1422017-12-20 14:24:16 -08001609 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001610 * @return content type, for example {@link #AAUDIO_CONTENT_TYPE_MUSIC}
Phil Burk361b1422017-12-20 14:24:16 -08001611 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001612AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream)
1613 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001614
1615/**
1616 * Return the input preset for the stream.
1617 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001618 * Available since API level 28.
Phil Burk42452c02018-04-10 12:43:33 -07001619 *
Phil Burk361b1422017-12-20 14:24:16 -08001620 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001621 * @return input preset, for example {@link #AAUDIO_INPUT_PRESET_CAMCORDER}
Phil Burk361b1422017-12-20 14:24:16 -08001622 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001623AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream)
1624 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001625
Kevin Rocard68646ba2019-03-20 13:26:49 -07001626/**
1627 * Return the policy that determines whether the audio may or may not be captured
1628 * by other apps or the system.
1629 *
Elliott Hughes64a3b062019-10-29 10:09:30 -07001630 * Available since API level 29.
Kevin Rocard68646ba2019-03-20 13:26:49 -07001631 *
1632 * @param stream reference provided by AAudioStreamBuilder_openStream()
Kevin Rocardfb7e8462019-03-20 13:26:49 -07001633 * @return the allowed capture policy, for example {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}
Kevin Rocard68646ba2019-03-20 13:26:49 -07001634 */
1635AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
1636 AAudioStream* stream) __INTRODUCED_IN(29);
1637
Eric Laurentd17c8502019-10-24 15:58:35 -07001638
1639/**
1640 * Return whether this input stream is marked as privacy sensitive or not.
1641 *
1642 * See {@link #AAudioStreamBuilder_setPrivacySensitive()}.
1643 *
1644 * Added in API level 30.
1645 *
1646 * @param stream reference provided by AAudioStreamBuilder_openStream()
1647 * @return true if privacy sensitive, false otherwise
1648 */
1649AAUDIO_API bool AAudioStream_isPrivacySensitive(AAudioStream* stream)
1650 __INTRODUCED_IN(30);
1651
Phil Burk5ed503c2017-02-01 09:38:15 -08001652#ifdef __cplusplus
1653}
1654#endif
1655
1656#endif //AAUDIO_AAUDIO_H
Phil Burka45be8b2017-04-05 14:45:48 -07001657
1658/** @} */