blob: 19e22f194f76b455179e90959c299b643be16626 [file] [log] [blame]
Phil Burk5ed503c2017-02-01 09:38:15 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
Phil Burka45be8b2017-04-05 14:45:48 -070018 * @addtogroup Audio
19 * @{
20 */
21
22/**
23 * @file AAudio.h
24 */
25
26/**
27 * This is the 'C' API for AAudio.
Phil Burk5ed503c2017-02-01 09:38:15 -080028 */
29#ifndef AAUDIO_AAUDIO_H
30#define AAUDIO_AAUDIO_H
31
Phil Burk3316d5e2017-02-15 11:23:01 -080032#include <time.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080033
34#ifdef __cplusplus
35extern "C" {
36#endif
37
Phil Burka4eb0d82017-04-12 15:44:06 -070038/**
39 * This is used to represent a value that has not been specified.
40 * For example, an application could use AAUDIO_UNSPECIFIED to indicate
41 * that is did not not care what the specific value of a parameter was
42 * and would accept whatever it was given.
43 */
44#define AAUDIO_UNSPECIFIED 0
Phil Burka4eb0d82017-04-12 15:44:06 -070045
46enum {
Phil Burk8149eed2018-05-24 14:09:46 -070047 /**
48 * Audio data will travel out of the device, for example through a speaker.
49 */
Phil Burka4eb0d82017-04-12 15:44:06 -070050 AAUDIO_DIRECTION_OUTPUT,
Phil Burk8149eed2018-05-24 14:09:46 -070051
52
53 /**
54 * Audio data will travel into the device, for example from a microphone.
55 */
Phil Burka4eb0d82017-04-12 15:44:06 -070056 AAUDIO_DIRECTION_INPUT
57};
58typedef int32_t aaudio_direction_t;
59
60enum {
61 AAUDIO_FORMAT_INVALID = -1,
62 AAUDIO_FORMAT_UNSPECIFIED = 0,
Phil Burk8149eed2018-05-24 14:09:46 -070063
64 /**
65 * This format uses the int16_t data type.
66 * The maximum range of the data is -32768 to 32767.
67 */
Phil Burka4eb0d82017-04-12 15:44:06 -070068 AAUDIO_FORMAT_PCM_I16,
Phil Burk8149eed2018-05-24 14:09:46 -070069
70 /**
71 * This format uses the float data type.
72 * The nominal range of the data is [-1.0f, 1.0f).
73 * Values outside that range may be clipped.
74 *
75 * See also 'floatData' at
76 * https://developer.android.com/reference/android/media/AudioTrack#write(float[],%20int,%20int,%20int)
77 */
Phil Burk74733452017-04-18 19:50:28 -070078 AAUDIO_FORMAT_PCM_FLOAT
Phil Burka4eb0d82017-04-12 15:44:06 -070079};
80typedef int32_t aaudio_format_t;
81
Phil Burk8149eed2018-05-24 14:09:46 -070082/**
83 * These result codes are returned from AAudio functions to indicate success or failure.
84 * Note that error return codes may change in the future so applications should generally
85 * not rely on specific return codes.
86 */
Phil Burka4eb0d82017-04-12 15:44:06 -070087enum {
Phil Burk8149eed2018-05-24 14:09:46 -070088 /**
89 * The call was successful.
90 */
Phil Burka4eb0d82017-04-12 15:44:06 -070091 AAUDIO_OK,
92 AAUDIO_ERROR_BASE = -900, // TODO review
Phil Burk8149eed2018-05-24 14:09:46 -070093
94 /**
95 * The audio device was disconnected. This could occur, for example, when headphones
96 * are plugged in or unplugged. The stream cannot be used after the device is disconnected.
97 * Applications should stop and close the stream.
98 * If this error is received in an error callback then another thread should be
99 * used to stop and close the stream.
100 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700101 AAUDIO_ERROR_DISCONNECTED,
Phil Burk8149eed2018-05-24 14:09:46 -0700102
103 /**
104 * An invalid parameter was passed to AAudio.
105 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700106 AAUDIO_ERROR_ILLEGAL_ARGUMENT,
Phil Burk17fff382017-05-16 14:06:45 -0700107 // reserved
108 AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2,
Phil Burk8149eed2018-05-24 14:09:46 -0700109
110 /**
111 * The requested operation is not appropriate for the current state of AAudio.
112 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700113 AAUDIO_ERROR_INVALID_STATE,
Phil Burk17fff382017-05-16 14:06:45 -0700114 // reserved
115 // reserved
Phil Burk8149eed2018-05-24 14:09:46 -0700116 /* The server rejected the handle used to identify the stream.
117 */
Phil Burk17fff382017-05-16 14:06:45 -0700118 AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3,
119 // reserved
Phil Burk8149eed2018-05-24 14:09:46 -0700120
121 /**
122 * The function is not implemented for this stream.
123 */
Phil Burk17fff382017-05-16 14:06:45 -0700124 AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2,
Phil Burk8149eed2018-05-24 14:09:46 -0700125
126 /**
127 * A resource or information is unavailable.
128 * This could occur when an application tries to open too many streams,
129 * or a timestamp is not available.
130 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700131 AAUDIO_ERROR_UNAVAILABLE,
132 AAUDIO_ERROR_NO_FREE_HANDLES,
Phil Burk8149eed2018-05-24 14:09:46 -0700133
134 /**
135 * Memory could not be allocated.
136 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700137 AAUDIO_ERROR_NO_MEMORY,
Phil Burk8149eed2018-05-24 14:09:46 -0700138
139 /**
140 * A NULL pointer was passed to AAudio.
141 * Or a NULL pointer was detected internally.
142 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700143 AAUDIO_ERROR_NULL,
Phil Burk8149eed2018-05-24 14:09:46 -0700144
145 /**
146 * An operation took longer than expected.
147 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700148 AAUDIO_ERROR_TIMEOUT,
149 AAUDIO_ERROR_WOULD_BLOCK,
Phil Burk8149eed2018-05-24 14:09:46 -0700150
151 /**
152 * The requested data format is not supported.
153 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700154 AAUDIO_ERROR_INVALID_FORMAT,
Phil Burk8149eed2018-05-24 14:09:46 -0700155
156 /**
157 * A requested was out of range.
158 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700159 AAUDIO_ERROR_OUT_OF_RANGE,
Phil Burk8149eed2018-05-24 14:09:46 -0700160
161 /**
162 * The audio service was not available.
163 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700164 AAUDIO_ERROR_NO_SERVICE,
Phil Burk8149eed2018-05-24 14:09:46 -0700165
166 /**
167 * The requested sample rate was not supported.
168 */
Phil Burka4eb0d82017-04-12 15:44:06 -0700169 AAUDIO_ERROR_INVALID_RATE
170};
171typedef int32_t aaudio_result_t;
172
173enum
174{
175 AAUDIO_STREAM_STATE_UNINITIALIZED = 0,
176 AAUDIO_STREAM_STATE_UNKNOWN,
177 AAUDIO_STREAM_STATE_OPEN,
178 AAUDIO_STREAM_STATE_STARTING,
179 AAUDIO_STREAM_STATE_STARTED,
180 AAUDIO_STREAM_STATE_PAUSING,
181 AAUDIO_STREAM_STATE_PAUSED,
182 AAUDIO_STREAM_STATE_FLUSHING,
183 AAUDIO_STREAM_STATE_FLUSHED,
184 AAUDIO_STREAM_STATE_STOPPING,
185 AAUDIO_STREAM_STATE_STOPPED,
186 AAUDIO_STREAM_STATE_CLOSING,
187 AAUDIO_STREAM_STATE_CLOSED,
188 AAUDIO_STREAM_STATE_DISCONNECTED
189};
190typedef int32_t aaudio_stream_state_t;
191
192
193enum {
194 /**
195 * This will be the only stream using a particular source or sink.
196 * This mode will provide the lowest possible latency.
197 * You should close EXCLUSIVE streams immediately when you are not using them.
198 */
199 AAUDIO_SHARING_MODE_EXCLUSIVE,
200 /**
201 * Multiple applications will be mixed by the AAudio Server.
202 * This will have higher latency than the EXCLUSIVE mode.
203 */
204 AAUDIO_SHARING_MODE_SHARED
205};
206typedef int32_t aaudio_sharing_mode_t;
207
Phil Burke2fbb592017-05-01 15:05:52 -0700208
209enum {
210 /**
211 * No particular performance needs. Default.
212 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800213 AAUDIO_PERFORMANCE_MODE_NONE = 10,
Phil Burke2fbb592017-05-01 15:05:52 -0700214
215 /**
Phil Burk8149eed2018-05-24 14:09:46 -0700216 * Extending battery life is more important than low latency.
Phil Burked0a3fe2017-12-05 14:27:43 -0800217 *
218 * This mode is not supported in input streams.
Phil Burk8149eed2018-05-24 14:09:46 -0700219 * For input, mode NONE will be used if this is requested.
Phil Burke2fbb592017-05-01 15:05:52 -0700220 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800221 AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
Phil Burke2fbb592017-05-01 15:05:52 -0700222
223 /**
Phil Burk8149eed2018-05-24 14:09:46 -0700224 * Reducing latency is more important than battery life.
Phil Burke2fbb592017-05-01 15:05:52 -0700225 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800226 AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
Phil Burke2fbb592017-05-01 15:05:52 -0700227};
228typedef int32_t aaudio_performance_mode_t;
229
Phil Burk361b1422017-12-20 14:24:16 -0800230/**
231 * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for.
232 * This information is used by certain platforms or routing policies
233 * to make more refined volume or routing decisions.
234 *
Kevin Rocard68646ba2019-03-20 13:26:49 -0700235 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
236 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700237 *
238 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800239 */
240enum {
241 /**
242 * Use this for streaming media, music performance, video, podcasts, etcetera.
243 */
244 AAUDIO_USAGE_MEDIA = 1,
245
246 /**
247 * Use this for voice over IP, telephony, etcetera.
248 */
249 AAUDIO_USAGE_VOICE_COMMUNICATION = 2,
250
251 /**
252 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.
253 */
254 AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
255
256 /**
257 * Use this to demand the users attention.
258 */
259 AAUDIO_USAGE_ALARM = 4,
260
261 /**
262 * Use this for notifying the user when a message has arrived or some
263 * other background event has occured.
264 */
265 AAUDIO_USAGE_NOTIFICATION = 5,
266
267 /**
268 * Use this when the phone rings.
269 */
270 AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6,
271
272 /**
273 * Use this to attract the users attention when, for example, the battery is low.
274 */
275 AAUDIO_USAGE_NOTIFICATION_EVENT = 10,
276
277 /**
278 * Use this for screen readers, etcetera.
279 */
280 AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
281
282 /**
283 * Use this for driving or navigation directions.
284 */
285 AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
286
287 /**
288 * Use this for user interface sounds, beeps, etcetera.
289 */
290 AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
291
292 /**
293 * Use this for game audio and sound effects.
294 */
295 AAUDIO_USAGE_GAME = 14,
296
297 /**
298 * Use this for audio responses to user queries, audio instructions or help utterances.
299 */
300 AAUDIO_USAGE_ASSISTANT = 16
301};
302typedef int32_t aaudio_usage_t;
303
304/**
305 * The CONTENT_TYPE attribute describes "what" you are playing.
306 * It expresses the general category of the content. This information is optional.
307 * But in case it is known (for instance {@link #AAUDIO_CONTENT_TYPE_MOVIE} for a
308 * movie streaming service or {@link #AAUDIO_CONTENT_TYPE_SPEECH} for
309 * an audio book application) this information might be used by the audio framework to
310 * enforce audio focus.
311 *
Kevin Rocard68646ba2019-03-20 13:26:49 -0700312 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
313 * in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700314 *
315 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800316 */
317enum {
318
319 /**
320 * Use this for spoken voice, audio books, etcetera.
321 */
322 AAUDIO_CONTENT_TYPE_SPEECH = 1,
323
324 /**
325 * Use this for pre-recorded or live music.
326 */
327 AAUDIO_CONTENT_TYPE_MUSIC = 2,
328
329 /**
330 * Use this for a movie or video soundtrack.
331 */
332 AAUDIO_CONTENT_TYPE_MOVIE = 3,
333
334 /**
335 * Use this for sound is designed to accompany a user action,
336 * such as a click or beep sound made when the user presses a button.
337 */
338 AAUDIO_CONTENT_TYPE_SONIFICATION = 4
339};
340typedef int32_t aaudio_content_type_t;
341
342/**
343 * Defines the audio source.
344 * An audio source defines both a default physical source of audio signal, and a recording
345 * configuration.
346 *
347 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
Phil Burk42452c02018-04-10 12:43:33 -0700348 *
349 * Added in API level 28.
Phil Burk361b1422017-12-20 14:24:16 -0800350 */
351enum {
352 /**
353 * Use this preset when other presets do not apply.
354 */
355 AAUDIO_INPUT_PRESET_GENERIC = 1,
356
357 /**
358 * Use this preset when recording video.
359 */
360 AAUDIO_INPUT_PRESET_CAMCORDER = 5,
361
362 /**
363 * Use this preset when doing speech recognition.
364 */
365 AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6,
366
367 /**
368 * Use this preset when doing telephony or voice messaging.
369 */
370 AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7,
371
372 /**
373 * Use this preset to obtain an input with no effects.
374 * Note that this input will not have automatic gain control
375 * so the recorded volume may be very low.
376 */
377 AAUDIO_INPUT_PRESET_UNPROCESSED = 9,
Eric Laurentae4b6ec2019-01-15 18:34:38 -0800378
379 /**
380 * Use this preset for capturing audio meant to be processed in real time
381 * and played back for live performance (e.g karaoke).
382 * The capture path will minimize latency and coupling with playback path.
383 */
384 AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE = 10,
Phil Burk361b1422017-12-20 14:24:16 -0800385};
386typedef int32_t aaudio_input_preset_t;
387
Phil Burk8149eed2018-05-24 14:09:46 -0700388/**
Kevin Rocard68646ba2019-03-20 13:26:49 -0700389 * Specifying if audio may or may not be captured by other apps or the system.
390 *
391 * Note that these match the equivalent values in {@link android.media.AudioAttributes}
392 * in the Android Java API.
393 *
394 * Added in API level 29.
395 */
396enum {
397 /**
398 * Indicates that the audio may be captured by any app.
399 *
400 * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*,
401 * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and AAUDIO_USAGE_ASSISTANT.
402 *
403 * On {@link Android.os.Build.VERSION_CODES.Q}, this means only {@link AAUDIO_USAGE_MEDIA}
404 * and {@link AAUDIO_USAGE_GAME} may be captured.
405 *
406 * See {@link android.media.AudioAttributes.ALLOW_CAPTURE_BY_ALL}.
407 */
408 AAUDIO_ALLOW_CAPTURE_BY_ALL = 1,
409 /**
410 * Indicates that the audio may only be captured by system apps.
411 *
412 * System apps can capture for many purposes like accessibility, user guidance...
413 * but have strong restriction. See
414 * {@link android.media.AudioAttributes.ALLOW_CAPTURE_BY_SYSTEM} for what the system apps
415 * can do with the capture audio.
416 */
417 AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2,
418 /**
419 * Indicates that the audio may not be recorded by any app, even if it is a system app.
420 *
421 * It is encouraged to use {@link ALLOW_CAPTURE_BY_SYSTEM} instead of this value as system apps
422 * provide significant and useful features for the user (eg. accessibility).
423 * See {@link android.media.AudioAttributes.ALLOW_CAPTURE_BY_NONE}.
424 */
425 AAUDIO_ALLOW_CAPTURE_BY_NONE = 3,
426};
427
428typedef int32_t aaudio_allowed_capture_policy_t;
429
430/**
Phil Burk8149eed2018-05-24 14:09:46 -0700431 * These may be used with AAudioStreamBuilder_setSessionId().
432 *
433 * Added in API level 28.
434 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800435enum {
436 /**
437 * Do not allocate a session ID.
438 * Effects cannot be used with this stream.
439 * Default.
Phil Burk42452c02018-04-10 12:43:33 -0700440 *
441 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800442 */
443 AAUDIO_SESSION_ID_NONE = -1,
444
445 /**
446 * Allocate a session ID that can be used to attach and control
447 * effects using the Java AudioEffects API.
Phil Burk8149eed2018-05-24 14:09:46 -0700448 * Note that using this may result in higher latency.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800449 *
450 * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.
Phil Burk42452c02018-04-10 12:43:33 -0700451 *
452 * Added in API level 28.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800453 */
454 AAUDIO_SESSION_ID_ALLOCATE = 0,
455};
456typedef int32_t aaudio_session_id_t;
457
Phil Burke2155ef2017-02-24 13:50:29 -0800458typedef struct AAudioStreamStruct AAudioStream;
459typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder;
Phil Burk5ed503c2017-02-01 09:38:15 -0800460
Phil Burk5ed503c2017-02-01 09:38:15 -0800461#ifndef AAUDIO_API
Phil Burk3316d5e2017-02-15 11:23:01 -0800462#define AAUDIO_API /* export this symbol */
Phil Burk5ed503c2017-02-01 09:38:15 -0800463#endif
464
465// ============================================================
466// Audio System
467// ============================================================
468
469/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800470 * The text is the ASCII symbol corresponding to the returnCode,
471 * or an English message saying the returnCode is unrecognized.
472 * This is intended for developers to use when debugging.
473 * It is not for display to users.
474 *
475 * @return pointer to a text representation of an AAudio result code.
476 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700477AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800478
479/**
480 * The text is the ASCII symbol corresponding to the stream state,
481 * or an English message saying the state is unrecognized.
482 * This is intended for developers to use when debugging.
483 * It is not for display to users.
484 *
485 * @return pointer to a text representation of an AAudio state.
486 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700487AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state)
488 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800489
490// ============================================================
491// StreamBuilder
492// ============================================================
493
494/**
495 * Create a StreamBuilder that can be used to open a Stream.
496 *
497 * The deviceId is initially unspecified, meaning that the current default device will be used.
498 *
499 * The default direction is AAUDIO_DIRECTION_OUTPUT.
Phil Burk3316d5e2017-02-15 11:23:01 -0800500 * The default sharing mode is AAUDIO_SHARING_MODE_SHARED.
Phil Burk5ed503c2017-02-01 09:38:15 -0800501 * The data format, samplesPerFrames and sampleRate are unspecified and will be
502 * chosen by the device when it is opened.
503 *
504 * AAudioStreamBuilder_delete() must be called when you are done using the builder.
505 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700506AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder)
507 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800508
509/**
510 * Request an audio device identified device using an ID.
Phil Burk5ed503c2017-02-01 09:38:15 -0800511 * On Android, for example, the ID could be obtained from the Java AudioManager.
512 *
Glenn Kasten5f510d22017-05-30 15:52:15 -0700513 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED,
Phil Burke057ca92017-03-28 11:31:34 -0700514 * in which case the primary device will be used.
Phil Burk5ed503c2017-02-01 09:38:15 -0800515 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800516 * @param builder reference provided by AAudio_createStreamBuilder()
Glenn Kasten5f510d22017-05-30 15:52:15 -0700517 * @param deviceId device identifier or AAUDIO_UNSPECIFIED
Phil Burk5ed503c2017-02-01 09:38:15 -0800518 */
Phil Burke2155ef2017-02-24 13:50:29 -0800519AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700520 int32_t deviceId) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800521
522/**
Phil Burke057ca92017-03-28 11:31:34 -0700523 * Request a sample rate in Hertz.
524 *
Phil Burke057ca92017-03-28 11:31:34 -0700525 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk8f624892017-05-11 11:44:20 -0700526 * An optimal value will then be chosen when the stream is opened.
527 * After opening a stream with an unspecified value, the application must
528 * query for the actual value, which may vary by device.
529 *
530 * If an exact value is specified then an opened stream will use that value.
531 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700532 *
533 * @param builder reference provided by AAudio_createStreamBuilder()
534 * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
Phil Burk5ed503c2017-02-01 09:38:15 -0800535 */
Phil Burke2155ef2017-02-24 13:50:29 -0800536AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700537 int32_t sampleRate) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800538
539/**
Phil Burk20523ed2017-04-24 17:04:01 -0700540 * Request a number of channels for the stream.
Phil Burke057ca92017-03-28 11:31:34 -0700541 *
Phil Burke057ca92017-03-28 11:31:34 -0700542 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk8f624892017-05-11 11:44:20 -0700543 * An optimal value will then be chosen when the stream is opened.
544 * After opening a stream with an unspecified value, the application must
545 * query for the actual value, which may vary by device.
Phil Burk5ed503c2017-02-01 09:38:15 -0800546 *
Phil Burk8f624892017-05-11 11:44:20 -0700547 * If an exact value is specified then an opened stream will use that value.
548 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700549 *
550 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk20523ed2017-04-24 17:04:01 -0700551 * @param channelCount Number of channels desired.
Phil Burk5ed503c2017-02-01 09:38:15 -0800552 */
Phil Burk20523ed2017-04-24 17:04:01 -0700553AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700554 int32_t channelCount) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -0700555
556/**
Phil Burke74240d2017-08-03 15:25:43 -0700557 * Identical to AAudioStreamBuilder_setChannelCount().
558 *
559 * @param builder reference provided by AAudio_createStreamBuilder()
560 * @param samplesPerFrame Number of samples in a frame.
561 */
562AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700563 int32_t samplesPerFrame) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -0700564
565/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800566 * Request a sample data format, for example AAUDIO_FORMAT_PCM_I16.
Phil Burke057ca92017-03-28 11:31:34 -0700567 *
568 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk8f624892017-05-11 11:44:20 -0700569 * An optimal value will then be chosen when the stream is opened.
570 * After opening a stream with an unspecified value, the application must
571 * query for the actual value, which may vary by device.
Phil Burke057ca92017-03-28 11:31:34 -0700572 *
Phil Burk8f624892017-05-11 11:44:20 -0700573 * If an exact value is specified then an opened stream will use that value.
574 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700575 *
576 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk8f624892017-05-11 11:44:20 -0700577 * @param format common formats are AAUDIO_FORMAT_PCM_FLOAT and AAUDIO_FORMAT_PCM_I16.
Phil Burk5ed503c2017-02-01 09:38:15 -0800578 */
Phil Burke2155ef2017-02-24 13:50:29 -0800579AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700580 aaudio_format_t format) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800581
582/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800583 * Request a mode for sharing the device.
Phil Burke057ca92017-03-28 11:31:34 -0700584 *
585 * The default, if you do not call this function, is AAUDIO_SHARING_MODE_SHARED.
586 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800587 * The requested sharing mode may not be available.
Phil Burke057ca92017-03-28 11:31:34 -0700588 * The application can query for the actual mode after the stream is opened.
Phil Burk5ed503c2017-02-01 09:38:15 -0800589 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800590 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burke057ca92017-03-28 11:31:34 -0700591 * @param sharingMode AAUDIO_SHARING_MODE_SHARED or AAUDIO_SHARING_MODE_EXCLUSIVE
Phil Burk5ed503c2017-02-01 09:38:15 -0800592 */
Phil Burke2155ef2017-02-24 13:50:29 -0800593AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700594 aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800595
596/**
Phil Burke057ca92017-03-28 11:31:34 -0700597 * Request the direction for a stream.
598 *
599 * The default, if you do not call this function, is AAUDIO_DIRECTION_OUTPUT.
Phil Burk5ed503c2017-02-01 09:38:15 -0800600 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800601 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk5ed503c2017-02-01 09:38:15 -0800602 * @param direction AAUDIO_DIRECTION_OUTPUT or AAUDIO_DIRECTION_INPUT
Phil Burk5ed503c2017-02-01 09:38:15 -0800603 */
Phil Burke2155ef2017-02-24 13:50:29 -0800604AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700605 aaudio_direction_t direction) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800606
607/**
Phil Burke057ca92017-03-28 11:31:34 -0700608 * Set the requested buffer capacity in frames.
Phil Burk3df348f2017-02-08 11:41:55 -0800609 * The final AAudioStream capacity may differ, but will probably be at least this big.
610 *
Phil Burke057ca92017-03-28 11:31:34 -0700611 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk3df348f2017-02-08 11:41:55 -0800612 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800613 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burke057ca92017-03-28 11:31:34 -0700614 * @param numFrames the desired buffer capacity in frames or AAUDIO_UNSPECIFIED
Phil Burk3df348f2017-02-08 11:41:55 -0800615 */
Phil Burke2155ef2017-02-24 13:50:29 -0800616AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700617 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700618
619/**
620 * Set the requested performance mode.
621 *
Phil Burk8149eed2018-05-24 14:09:46 -0700622 * Supported modes are AAUDIO_PERFORMANCE_MODE_NONE, AAUDIO_PERFORMANCE_MODE_POWER_SAVING
623 * and AAUDIO_PERFORMANCE_MODE_LOW_LATENCY.
624 *
Phil Burke2fbb592017-05-01 15:05:52 -0700625 * The default, if you do not call this function, is AAUDIO_PERFORMANCE_MODE_NONE.
626 *
Phil Burk8149eed2018-05-24 14:09:46 -0700627 * You may not get the mode you requested.
628 * You can call AAudioStream_getPerformanceMode() to find out the final mode for the stream.
629 *
Phil Burke2fbb592017-05-01 15:05:52 -0700630 * @param builder reference provided by AAudio_createStreamBuilder()
631 * @param mode the desired performance mode, eg. AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
632 */
633AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700634 aaudio_performance_mode_t mode) __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -0700635
Phil Burke057ca92017-03-28 11:31:34 -0700636/**
Phil Burk361b1422017-12-20 14:24:16 -0800637 * Set the intended use case for the stream.
638 *
639 * The AAudio system will use this information to optimize the
640 * behavior of the stream.
641 * This could, for example, affect how volume and focus is handled for the stream.
642 *
643 * The default, if you do not call this function, is AAUDIO_USAGE_MEDIA.
644 *
Phil Burk42452c02018-04-10 12:43:33 -0700645 * Added in API level 28.
646 *
Phil Burk361b1422017-12-20 14:24:16 -0800647 * @param builder reference provided by AAudio_createStreamBuilder()
648 * @param usage the desired usage, eg. AAUDIO_USAGE_GAME
649 */
650AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700651 aaudio_usage_t usage) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800652
653/**
654 * Set the type of audio data that the stream will carry.
655 *
656 * The AAudio system will use this information to optimize the
657 * behavior of the stream.
658 * This could, for example, affect whether a stream is paused when a notification occurs.
659 *
660 * The default, if you do not call this function, is AAUDIO_CONTENT_TYPE_MUSIC.
661 *
Phil Burk42452c02018-04-10 12:43:33 -0700662 * Added in API level 28.
663 *
Phil Burk361b1422017-12-20 14:24:16 -0800664 * @param builder reference provided by AAudio_createStreamBuilder()
665 * @param contentType the type of audio data, eg. AAUDIO_CONTENT_TYPE_SPEECH
666 */
667AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700668 aaudio_content_type_t contentType) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800669
670/**
671 * Set the input (capture) preset for the stream.
672 *
673 * The AAudio system will use this information to optimize the
674 * behavior of the stream.
675 * This could, for example, affect which microphones are used and how the
676 * recorded data is processed.
677 *
Phil Burkeaef9b92018-01-18 09:09:42 -0800678 * The default, if you do not call this function, is AAUDIO_INPUT_PRESET_VOICE_RECOGNITION.
679 * That is because VOICE_RECOGNITION is the preset with the lowest latency
680 * on many platforms.
Phil Burk361b1422017-12-20 14:24:16 -0800681 *
Phil Burk42452c02018-04-10 12:43:33 -0700682 * Added in API level 28.
683 *
Phil Burk361b1422017-12-20 14:24:16 -0800684 * @param builder reference provided by AAudio_createStreamBuilder()
685 * @param inputPreset the desired configuration for recording
686 */
687AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700688 aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -0800689
Kevin Rocard68646ba2019-03-20 13:26:49 -0700690/**
691 * Specify whether this stream audio may or may not be captured by other apps or the system.
692 *
693 * The default is AAUDIO_ALLOW_CAPTURE_BY_ALL.
694 *
695 * Note that an application can also set its global policy, in which case the most restrictive
696 * policy is always applied. See {@link android.media.AudioAttributes.setAllowedCapturePolicy}
697 *
698 * Added in API level 29.
699 *
700 * @param builder reference provided by AAudio_createStreamBuilder()
701 * @param inputPreset the desired level of opt-out from being captured.
702 */
703AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder,
704 aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29);
705
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800706/** Set the requested session ID.
707 *
708 * The session ID can be used to associate a stream with effects processors.
709 * The effects are controlled using the Android AudioEffect Java API.
710 *
711 * The default, if you do not call this function, is AAUDIO_SESSION_ID_NONE.
712 *
713 * If set to AAUDIO_SESSION_ID_ALLOCATE then a session ID will be allocated
714 * when the stream is opened.
715 *
716 * The allocated session ID can be obtained by calling AAudioStream_getSessionId()
717 * and then used with this function when opening another stream.
718 * This allows effects to be shared between streams.
719 *
Phil Burk8149eed2018-05-24 14:09:46 -0700720 * Session IDs from AAudio can be used with the Android Java APIs and vice versa.
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800721 * So a session ID from an AAudio stream can be passed to Java
722 * and effects applied using the Java AudioEffect API.
723 *
Phil Burk8149eed2018-05-24 14:09:46 -0700724 * Note that allocating or setting a session ID may result in a stream with higher latency.
725 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800726 * Allocated session IDs will always be positive and nonzero.
727 *
Phil Burk42452c02018-04-10 12:43:33 -0700728 * Added in API level 28.
729 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800730 * @param builder reference provided by AAudio_createStreamBuilder()
731 * @param sessionId an allocated sessionID or AAUDIO_SESSION_ID_ALLOCATE
732 */
733AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700734 aaudio_session_id_t sessionId) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800735
Phil Burk361b1422017-12-20 14:24:16 -0800736/**
Phil Burke057ca92017-03-28 11:31:34 -0700737 * Return one of these values from the data callback function.
738 */
739enum {
740
741 /**
742 * Continue calling the callback.
743 */
744 AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
745
746 /**
747 * Stop calling the callback.
748 *
749 * The application will still need to call AAudioStream_requestPause()
750 * or AAudioStream_requestStop().
751 */
752 AAUDIO_CALLBACK_RESULT_STOP,
753
754};
755typedef int32_t aaudio_data_callback_result_t;
756
757/**
758 * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
759 *
760 * For an output stream, this function should render and write numFrames of data
761 * in the streams current data format to the audioData buffer.
762 *
763 * For an input stream, this function should read and process numFrames of data
764 * from the audioData buffer.
765 *
Phil Burked0a3fe2017-12-05 14:27:43 -0800766 * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or
767 * AAudioStream_write() on the stream that is making the callback.
768 *
769 * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback()
770 * is called.
771 *
772 * Also note that this callback function should be considered a "real-time" function.
Phil Burke057ca92017-03-28 11:31:34 -0700773 * It must not do anything that could cause an unbounded delay because that can cause the
774 * audio to glitch or pop.
775 *
776 * These are things the function should NOT do:
777 * <ul>
778 * <li>allocate memory using, for example, malloc() or new</li>
779 * <li>any file operations such as opening, closing, reading or writing</li>
780 * <li>any network operations such as streaming</li>
781 * <li>use any mutexes or other synchronization primitives</li>
782 * <li>sleep</li>
Phil Burked0a3fe2017-12-05 14:27:43 -0800783 * <li>stop or close the stream</li>
Phil Burk8149eed2018-05-24 14:09:46 -0700784 * <li>AAudioStream_read()</li>
785 * <li>AAudioStream_write()</li>
786 * </ul>
787 *
788 * The following are OK to call from the data callback:
789 * <ul>
790 * <li>AAudioStream_get*()</li>
791 * <li>AAudio_convertResultToText()</li>
Phil Burke057ca92017-03-28 11:31:34 -0700792 * </ul>
793 *
794 * If you need to move data, eg. MIDI commands, in or out of the callback function then
795 * we recommend the use of non-blocking techniques such as an atomic FIFO.
796 *
797 * @param stream reference provided by AAudioStreamBuilder_openStream()
798 * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
799 * @param audioData a pointer to the audio data
Phil Burked0a3fe2017-12-05 14:27:43 -0800800 * @param numFrames the number of frames to be processed, which can vary
Phil Burke057ca92017-03-28 11:31:34 -0700801 * @return AAUDIO_CALLBACK_RESULT_*
802 */
803typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
804 AAudioStream *stream,
805 void *userData,
806 void *audioData,
807 int32_t numFrames);
808
809/**
810 * Request that AAudio call this functions when the stream is running.
811 *
812 * Note that when using this callback, the audio data will be passed in or out
813 * of the function as an argument.
814 * So you cannot call AAudioStream_write() or AAudioStream_read() on the same stream
815 * that has an active data callback.
816 *
817 * The callback function will start being called after AAudioStream_requestStart() is called.
818 * It will stop being called after AAudioStream_requestPause() or
819 * AAudioStream_requestStop() is called.
820 *
821 * This callback function will be called on a real-time thread owned by AAudio. See
Glenn Kasten0d804362017-04-13 09:20:14 -0700822 * {@link AAudioStream_dataCallback} for more information.
Phil Burke057ca92017-03-28 11:31:34 -0700823 *
824 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
825 *
826 * @param builder reference provided by AAudio_createStreamBuilder()
827 * @param callback pointer to a function that will process audio data.
828 * @param userData pointer to an application data structure that will be passed
829 * to the callback functions.
830 */
831AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700832 AAudioStream_dataCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -0700833
834/**
835 * Set the requested data callback buffer size in frames.
836 * See {@link AAudioStream_dataCallback}.
837 *
838 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
839 *
840 * For the lowest possible latency, do not call this function. AAudio will then
841 * call the dataProc callback function with whatever size is optimal.
842 * That size may vary from one callback to another.
843 *
844 * Only use this function if the application requires a specific number of frames for processing.
845 * The application might, for example, be using an FFT that requires
846 * a specific power-of-two sized buffer.
847 *
848 * AAudio may need to add additional buffering in order to adapt between the internal
849 * buffer size and the requested buffer size.
850 *
851 * If you do call this function then the requested size should be less than
852 * half the buffer capacity, to allow double buffering.
853 *
854 * @param builder reference provided by AAudio_createStreamBuilder()
855 * @param numFrames the desired buffer size in frames or AAUDIO_UNSPECIFIED
856 */
857AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700858 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -0700859
860/**
861 * Prototype for the callback function that is passed to
862 * AAudioStreamBuilder_setErrorCallback().
863 *
Phil Burk8149eed2018-05-24 14:09:46 -0700864 * The following may NOT be called from the error callback:
865 * <ul>
866 * <li>AAudioStream_requestStop()</li>
867 * <li>AAudioStream_requestPause()</li>
868 * <li>AAudioStream_close()</li>
869 * <li>AAudioStream_waitForStateChange()</li>
870 * <li>AAudioStream_read()</li>
871 * <li>AAudioStream_write()</li>
872 * </ul>
873 *
874 * The following are OK to call from the error callback:
875 * <ul>
876 * <li>AAudioStream_get*()</li>
877 * <li>AAudio_convertResultToText()</li>
878 * </ul>
879 *
Phil Burke057ca92017-03-28 11:31:34 -0700880 * @param stream reference provided by AAudioStreamBuilder_openStream()
881 * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
882 * @param error an AAUDIO_ERROR_* value.
883 */
884typedef void (*AAudioStream_errorCallback)(
885 AAudioStream *stream,
886 void *userData,
887 aaudio_result_t error);
888
889/**
Phil Burked0a3fe2017-12-05 14:27:43 -0800890 * Request that AAudio call this function if any error occurs or the stream is disconnected.
Phil Burke057ca92017-03-28 11:31:34 -0700891 *
892 * 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 -0800893 * device to be unavailable or "disconnected".
Phil Burke057ca92017-03-28 11:31:34 -0700894 * Another possible cause of error would be a timeout or an unanticipated internal error.
895 *
Phil Burked0a3fe2017-12-05 14:27:43 -0800896 * In response, this function should signal or create another thread to stop
897 * and close this stream. The other thread could then reopen a stream on another device.
898 * Do not stop or close the stream, or reopen the new stream, directly from this callback.
899 *
900 * This callback will not be called because of actions by the application, such as stopping
901 * or closing a stream.
902 *
Phil Burke057ca92017-03-28 11:31:34 -0700903 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
904 *
905 * @param builder reference provided by AAudio_createStreamBuilder()
906 * @param callback pointer to a function that will be called if an error occurs.
907 * @param userData pointer to an application data structure that will be passed
908 * to the callback functions.
909 */
910AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700911 AAudioStream_errorCallback callback, void *userData) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800912
913/**
914 * Open a stream based on the options in the StreamBuilder.
915 *
916 * AAudioStream_close must be called when finished with the stream to recover
917 * the memory and to free the associated resources.
918 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800919 * @param builder reference provided by AAudio_createStreamBuilder()
920 * @param stream pointer to a variable to receive the new stream reference
Phil Burk5ed503c2017-02-01 09:38:15 -0800921 * @return AAUDIO_OK or a negative error.
922 */
Phil Burke2155ef2017-02-24 13:50:29 -0800923AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder,
Elliott Hughes85a41532018-06-18 13:17:24 -0700924 AAudioStream** stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800925
926/**
927 * Delete the resources associated with the StreamBuilder.
928 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800929 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk5ed503c2017-02-01 09:38:15 -0800930 * @return AAUDIO_OK or a negative error.
931 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700932AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder)
933 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800934
935// ============================================================
936// Stream Control
937// ============================================================
938
939/**
940 * Free the resources associated with a stream created by AAudioStreamBuilder_openStream()
941 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800942 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800943 * @return AAUDIO_OK or a negative error.
944 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700945AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800946
947/**
948 * Asynchronously request to start playing the stream. For output streams, one should
949 * write to the stream to fill the buffer before starting.
950 * Otherwise it will underflow.
951 * After this call the state will be in AAUDIO_STREAM_STATE_STARTING or AAUDIO_STREAM_STATE_STARTED.
952 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800953 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800954 * @return AAUDIO_OK or a negative error.
955 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700956AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800957
958/**
959 * Asynchronous request for the stream to pause.
960 * Pausing a stream will freeze the data flow but not flush any buffers.
961 * Use AAudioStream_Start() to resume playback after a pause.
962 * After this call the state will be in AAUDIO_STREAM_STATE_PAUSING or AAUDIO_STREAM_STATE_PAUSED.
963 *
Phil Burk068c10f2017-05-08 16:36:41 -0700964 * This will return AAUDIO_ERROR_UNIMPLEMENTED for input streams.
965 * For input streams use AAudioStream_requestStop().
966 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800967 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800968 * @return AAUDIO_OK or a negative error.
969 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700970AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800971
972/**
973 * Asynchronous request for the stream to flush.
974 * Flushing will discard any pending data.
975 * This call only works if the stream is pausing or paused. TODO review
976 * Frame counters are not reset by a flush. They may be advanced.
977 * After this call the state will be in AAUDIO_STREAM_STATE_FLUSHING or AAUDIO_STREAM_STATE_FLUSHED.
978 *
Phil Burk068c10f2017-05-08 16:36:41 -0700979 * This will return AAUDIO_ERROR_UNIMPLEMENTED for input streams.
980 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800981 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800982 * @return AAUDIO_OK or a negative error.
983 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700984AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800985
986/**
987 * Asynchronous request for the stream to stop.
988 * The stream will stop after all of the data currently buffered has been played.
989 * After this call the state will be in AAUDIO_STREAM_STATE_STOPPING or AAUDIO_STREAM_STATE_STOPPED.
990 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800991 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800992 * @return AAUDIO_OK or a negative error.
993 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700994AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -0800995
996/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800997 * Query the current state of the client, eg. AAUDIO_STREAM_STATE_PAUSING
Phil Burk5ed503c2017-02-01 09:38:15 -0800998 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800999 * This function will immediately return the state without updating the state.
1000 * If you want to update the client state based on the server state then
1001 * call AAudioStream_waitForStateChange() with currentState
1002 * set to AAUDIO_STREAM_STATE_UNKNOWN and a zero timeout.
1003 *
1004 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001005 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001006AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001007
1008/**
1009 * Wait until the current state no longer matches the input state.
1010 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001011 * This will update the current client state.
1012 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001013 * <pre><code>
Phil Burked0a3fe2017-12-05 14:27:43 -08001014 * aaudio_result_t result = AAUDIO_OK;
1015 * aaudio_stream_state_t currentState = AAudioStream_getState(stream);
1016 * aaudio_stream_state_t inputState = currentState;
1017 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) {
Phil Burk5ed503c2017-02-01 09:38:15 -08001018 * result = AAudioStream_waitForStateChange(
Phil Burked0a3fe2017-12-05 14:27:43 -08001019 * stream, inputState, &currentState, MY_TIMEOUT_NANOS);
1020 * inputState = currentState;
Phil Burk5ed503c2017-02-01 09:38:15 -08001021 * }
1022 * </code></pre>
1023 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001024 * @param stream A reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -08001025 * @param inputState The state we want to avoid.
1026 * @param nextState Pointer to a variable that will be set to the new state.
1027 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1028 * @return AAUDIO_OK or a negative error.
1029 */
Phil Burke2155ef2017-02-24 13:50:29 -08001030AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001031 aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState,
1032 int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001033
1034// ============================================================
1035// Stream I/O
1036// ============================================================
1037
1038/**
1039 * Read data from the stream.
1040 *
1041 * The call will wait until the read is complete or until it runs out of time.
1042 * If timeoutNanos is zero then this call will not wait.
1043 *
1044 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1045 * Time will not stop if the thread is asleep.
1046 * So it will be implemented using CLOCK_BOOTTIME.
1047 *
1048 * This call is "strong non-blocking" unless it has to wait for data.
1049 *
Phil Burk8149eed2018-05-24 14:09:46 -07001050 * If the call times out then zero or a partial frame count will be returned.
1051 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001052 * @param stream A stream created using AAudioStreamBuilder_openStream().
1053 * @param buffer The address of the first sample.
1054 * @param numFrames Number of frames to read. Only complete frames will be written.
1055 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Phil Burk3316d5e2017-02-15 11:23:01 -08001056 * @return The number of frames actually read or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -08001057 */
Phil Burke2155ef2017-02-24 13:50:29 -08001058AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001059 void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001060
1061/**
1062 * Write data to the stream.
1063 *
1064 * The call will wait until the write is complete or until it runs out of time.
1065 * If timeoutNanos is zero then this call will not wait.
1066 *
1067 * Note that timeoutNanoseconds is a relative duration in wall clock time.
1068 * Time will not stop if the thread is asleep.
1069 * So it will be implemented using CLOCK_BOOTTIME.
1070 *
1071 * This call is "strong non-blocking" unless it has to wait for room in the buffer.
1072 *
Phil Burk8149eed2018-05-24 14:09:46 -07001073 * If the call times out then zero or a partial frame count will be returned.
1074 *
Phil Burk5ed503c2017-02-01 09:38:15 -08001075 * @param stream A stream created using AAudioStreamBuilder_openStream().
1076 * @param buffer The address of the first sample.
1077 * @param numFrames Number of frames to write. Only complete frames will be written.
1078 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
1079 * @return The number of frames actually written or a negative error.
1080 */
Phil Burke2155ef2017-02-24 13:50:29 -08001081AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001082 const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001083
Phil Burk5ed503c2017-02-01 09:38:15 -08001084// ============================================================
1085// Stream - queries
1086// ============================================================
1087
Phil Burk5ed503c2017-02-01 09:38:15 -08001088/**
1089 * This can be used to adjust the latency of the buffer by changing
1090 * the threshold where blocking will occur.
Phil Burk3316d5e2017-02-15 11:23:01 -08001091 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
Phil Burk5ed503c2017-02-01 09:38:15 -08001092 * at run-time for each device.
1093 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001094 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
Phil Burk5ed503c2017-02-01 09:38:15 -08001095 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001096 * Note that you will probably not get the exact size you request.
Phil Burk8149eed2018-05-24 14:09:46 -07001097 * You can check the return value or call AAudioStream_getBufferSizeInFrames()
1098 * to see what the actual final size is.
Phil Burk3316d5e2017-02-15 11:23:01 -08001099 *
1100 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001101 * @param numFrames requested number of frames that can be filled without blocking
Phil Burk3316d5e2017-02-15 11:23:01 -08001102 * @return actual buffer size in frames or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -08001103 */
Phil Burke2155ef2017-02-24 13:50:29 -08001104AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001105 int32_t numFrames) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001106
1107/**
1108 * Query the maximum number of frames that can be filled without blocking.
1109 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001110 * @param stream reference provided by AAudioStreamBuilder_openStream()
1111 * @return buffer size in frames.
Phil Burk5ed503c2017-02-01 09:38:15 -08001112 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001113AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001114
1115/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001116 * Query the number of frames that the application should read or write at
1117 * one time for optimal performance. It is OK if an application writes
1118 * a different number of frames. But the buffer size may need to be larger
1119 * in order to avoid underruns or overruns.
Phil Burk5ed503c2017-02-01 09:38:15 -08001120 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001121 * Note that this may or may not match the actual device burst size.
1122 * For some endpoints, the burst size can vary dynamically.
1123 * But these tend to be devices with high latency.
1124 *
1125 * @param stream reference provided by AAudioStreamBuilder_openStream()
1126 * @return burst size
Phil Burk5ed503c2017-02-01 09:38:15 -08001127 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001128AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001129
1130/**
1131 * Query maximum buffer capacity in frames.
1132 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001133 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -07001134 * @return buffer capacity in frames
Phil Burk5ed503c2017-02-01 09:38:15 -08001135 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001136AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001137
1138/**
Phil Burke057ca92017-03-28 11:31:34 -07001139 * Query the size of the buffer that will be passed to the dataProc callback
1140 * in the numFrames parameter.
1141 *
1142 * This call can be used if the application needs to know the value of numFrames before
1143 * the stream is started. This is not normally necessary.
1144 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001145 * If a specific size was requested by calling AAudioStreamBuilder_setFramesPerDataCallback()
Phil Burke057ca92017-03-28 11:31:34 -07001146 * then this will be the same size.
1147 *
Phil Burked0a3fe2017-12-05 14:27:43 -08001148 * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will
Phil Burke057ca92017-03-28 11:31:34 -07001149 * return the size chosen by AAudio, or AAUDIO_UNSPECIFIED.
1150 *
1151 * AAUDIO_UNSPECIFIED indicates that the callback buffer size for this stream
1152 * may vary from one dataProc callback to the next.
1153 *
1154 * @param stream reference provided by AAudioStreamBuilder_openStream()
1155 * @return callback buffer size in frames or AAUDIO_UNSPECIFIED
1156 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001157AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke057ca92017-03-28 11:31:34 -07001158
1159/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001160 * An XRun is an Underrun or an Overrun.
1161 * During playing, an underrun will occur if the stream is not written in time
1162 * and the system runs out of valid data.
1163 * During recording, an overrun will occur if the stream is not read in time
1164 * and there is no place to put the incoming data so it is discarded.
1165 *
1166 * An underrun or overrun can cause an audible "pop" or "glitch".
1167 *
Phil Burk068c10f2017-05-08 16:36:41 -07001168 * Note that some INPUT devices may not support this function.
1169 * In that case a 0 will always be returned.
1170 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001171 * @param stream reference provided by AAudioStreamBuilder_openStream()
1172 * @return the underrun or overrun count
Phil Burk5ed503c2017-02-01 09:38:15 -08001173 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001174AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001175
1176/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001177 * @param stream reference provided by AAudioStreamBuilder_openStream()
1178 * @return actual sample rate
Phil Burk5ed503c2017-02-01 09:38:15 -08001179 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001180AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001181
1182/**
Phil Burk20523ed2017-04-24 17:04:01 -07001183 * A stream has one or more channels of data.
1184 * A frame will contain one sample for each channel.
1185 *
1186 * @param stream reference provided by AAudioStreamBuilder_openStream()
1187 * @return actual number of channels
1188 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001189AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk20523ed2017-04-24 17:04:01 -07001190
1191/**
Phil Burke74240d2017-08-03 15:25:43 -07001192 * Identical to AAudioStream_getChannelCount().
1193 *
1194 * @param stream reference provided by AAudioStreamBuilder_openStream()
1195 * @return actual number of samples frame
1196 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001197AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burke74240d2017-08-03 15:25:43 -07001198
1199/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001200 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke2155ef2017-02-24 13:50:29 -08001201 * @return actual device ID
Phil Burk5ed503c2017-02-01 09:38:15 -08001202 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001203AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001204
1205/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001206 * @param stream reference provided by AAudioStreamBuilder_openStream()
1207 * @return actual data format
Phil Burk5ed503c2017-02-01 09:38:15 -08001208 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001209AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001210
1211/**
1212 * Provide actual sharing mode.
Phil Burk3316d5e2017-02-15 11:23:01 -08001213 * @param stream reference provided by AAudioStreamBuilder_openStream()
1214 * @return actual sharing mode
Phil Burk5ed503c2017-02-01 09:38:15 -08001215 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001216AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream)
1217 __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001218
1219/**
Phil Burke2fbb592017-05-01 15:05:52 -07001220 * Get the performance mode used by the stream.
1221 *
1222 * @param stream reference provided by AAudioStreamBuilder_openStream()
1223 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001224AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream)
1225 __INTRODUCED_IN(26);
Phil Burke2fbb592017-05-01 15:05:52 -07001226
1227/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001228 * @param stream reference provided by AAudioStreamBuilder_openStream()
1229 * @return direction
Phil Burk5ed503c2017-02-01 09:38:15 -08001230 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001231AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001232
1233/**
1234 * Passes back the number of frames that have been written since the stream was created.
Phil Burk8149eed2018-05-24 14:09:46 -07001235 * For an output stream, this will be advanced by the application calling write()
1236 * or by a data callback.
Phil Burk3316d5e2017-02-15 11:23:01 -08001237 * For an input stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -08001238 *
1239 * The frame position is monotonically increasing.
1240 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001241 * @param stream reference provided by AAudioStreamBuilder_openStream()
1242 * @return frames written
Phil Burk5ed503c2017-02-01 09:38:15 -08001243 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001244AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001245
1246/**
1247 * Passes back the number of frames that have been read since the stream was created.
Phil Burk3316d5e2017-02-15 11:23:01 -08001248 * For an output stream, this will be advanced by the endpoint.
Phil Burk8149eed2018-05-24 14:09:46 -07001249 * For an input stream, this will be advanced by the application calling read()
1250 * or by a data callback.
Phil Burk5ed503c2017-02-01 09:38:15 -08001251 *
1252 * The frame position is monotonically increasing.
1253 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001254 * @param stream reference provided by AAudioStreamBuilder_openStream()
1255 * @return frames read
Phil Burk5ed503c2017-02-01 09:38:15 -08001256 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001257AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001258
1259/**
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001260 * Passes back the session ID associated with this stream.
1261 *
1262 * The session ID can be used to associate a stream with effects processors.
1263 * The effects are controlled using the Android AudioEffect Java API.
1264 *
1265 * If AAudioStreamBuilder_setSessionId() was called with AAUDIO_SESSION_ID_ALLOCATE
1266 * then a new session ID should be allocated once when the stream is opened.
1267 *
1268 * If AAudioStreamBuilder_setSessionId() was called with a previously allocated
1269 * session ID then that value should be returned.
1270 *
1271 * If AAudioStreamBuilder_setSessionId() was not called then this function should
1272 * return AAUDIO_SESSION_ID_NONE.
1273 *
1274 * The sessionID for a stream should not change once the stream has been opened.
1275 *
Phil Burk42452c02018-04-10 12:43:33 -07001276 * Added in API level 28.
1277 *
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001278 * @param stream reference provided by AAudioStreamBuilder_openStream()
1279 * @return session ID or AAUDIO_SESSION_ID_NONE
1280 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001281AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001282
1283/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001284 * Passes back the time at which a particular frame was presented.
1285 * This can be used to synchronize audio with video or MIDI.
1286 * It can also be used to align a recorded stream with a playback stream.
1287 *
1288 * Timestamps are only valid when the stream is in AAUDIO_STREAM_STATE_STARTED.
1289 * AAUDIO_ERROR_INVALID_STATE will be returned if the stream is not started.
1290 * Note that because requestStart() is asynchronous, timestamps will not be valid until
1291 * a short time after calling requestStart().
1292 * So AAUDIO_ERROR_INVALID_STATE should not be considered a fatal error.
1293 * Just try calling again later.
1294 *
1295 * If an error occurs, then the position and time will not be modified.
1296 *
1297 * The position and time passed back are monotonically increasing.
1298 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001299 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burkec159502017-07-25 17:33:47 -07001300 * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
Phil Burk5ed503c2017-02-01 09:38:15 -08001301 * @param framePosition pointer to a variable to receive the position
1302 * @param timeNanoseconds pointer to a variable to receive the time
1303 * @return AAUDIO_OK or a negative error
1304 */
Phil Burke2155ef2017-02-24 13:50:29 -08001305AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream,
Elliott Hughes85a41532018-06-18 13:17:24 -07001306 clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds) __INTRODUCED_IN(26);
Phil Burk5ed503c2017-02-01 09:38:15 -08001307
Phil Burk361b1422017-12-20 14:24:16 -08001308/**
1309 * Return the use case for the stream.
1310 *
Phil Burk42452c02018-04-10 12:43:33 -07001311 * Added in API level 28.
1312 *
Phil Burk361b1422017-12-20 14:24:16 -08001313 * @param stream reference provided by AAudioStreamBuilder_openStream()
1314 * @return frames read
1315 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001316AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream) __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001317
1318/**
1319 * Return the content type for the stream.
1320 *
Phil Burk42452c02018-04-10 12:43:33 -07001321 * Added in API level 28.
1322 *
Phil Burk361b1422017-12-20 14:24:16 -08001323 * @param stream reference provided by AAudioStreamBuilder_openStream()
1324 * @return content type, for example AAUDIO_CONTENT_TYPE_MUSIC
1325 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001326AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream)
1327 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001328
1329/**
1330 * Return the input preset for the stream.
1331 *
Phil Burk42452c02018-04-10 12:43:33 -07001332 * Added in API level 28.
1333 *
Phil Burk361b1422017-12-20 14:24:16 -08001334 * @param stream reference provided by AAudioStreamBuilder_openStream()
1335 * @return input preset, for example AAUDIO_INPUT_PRESET_CAMCORDER
1336 */
Elliott Hughes85a41532018-06-18 13:17:24 -07001337AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream)
1338 __INTRODUCED_IN(28);
Phil Burk361b1422017-12-20 14:24:16 -08001339
Kevin Rocard68646ba2019-03-20 13:26:49 -07001340/**
1341 * Return the policy that determines whether the audio may or may not be captured
1342 * by other apps or the system.
1343 *
1344 * Added in API level 29.
1345 *
1346 * @param stream reference provided by AAudioStreamBuilder_openStream()
1347 * @return the allowed capture policy, for example AAUDIO_ALLOW_CAPTURE_BY_ALL
1348 */
1349AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
1350 AAudioStream* stream) __INTRODUCED_IN(29);
1351
Phil Burk5ed503c2017-02-01 09:38:15 -08001352#ifdef __cplusplus
1353}
1354#endif
1355
1356#endif //AAUDIO_AAUDIO_H
Phil Burka45be8b2017-04-05 14:45:48 -07001357
1358/** @} */