blob: 00c43dc1a2b9277960e3fb293270efec6e59776c [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 {
47 AAUDIO_DIRECTION_OUTPUT,
48 AAUDIO_DIRECTION_INPUT
49};
50typedef int32_t aaudio_direction_t;
51
52enum {
53 AAUDIO_FORMAT_INVALID = -1,
54 AAUDIO_FORMAT_UNSPECIFIED = 0,
55 AAUDIO_FORMAT_PCM_I16,
Phil Burk74733452017-04-18 19:50:28 -070056 AAUDIO_FORMAT_PCM_FLOAT
Phil Burka4eb0d82017-04-12 15:44:06 -070057};
58typedef int32_t aaudio_format_t;
59
Phil Burka4eb0d82017-04-12 15:44:06 -070060enum {
61 AAUDIO_OK,
62 AAUDIO_ERROR_BASE = -900, // TODO review
63 AAUDIO_ERROR_DISCONNECTED,
64 AAUDIO_ERROR_ILLEGAL_ARGUMENT,
Phil Burk17fff382017-05-16 14:06:45 -070065 // reserved
66 AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2,
Phil Burka4eb0d82017-04-12 15:44:06 -070067 AAUDIO_ERROR_INVALID_STATE,
Phil Burk17fff382017-05-16 14:06:45 -070068 // reserved
69 // reserved
70 AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3,
71 // reserved
72 AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2,
Phil Burka4eb0d82017-04-12 15:44:06 -070073 AAUDIO_ERROR_UNAVAILABLE,
74 AAUDIO_ERROR_NO_FREE_HANDLES,
75 AAUDIO_ERROR_NO_MEMORY,
76 AAUDIO_ERROR_NULL,
77 AAUDIO_ERROR_TIMEOUT,
78 AAUDIO_ERROR_WOULD_BLOCK,
79 AAUDIO_ERROR_INVALID_FORMAT,
80 AAUDIO_ERROR_OUT_OF_RANGE,
81 AAUDIO_ERROR_NO_SERVICE,
82 AAUDIO_ERROR_INVALID_RATE
83};
84typedef int32_t aaudio_result_t;
85
86enum
87{
88 AAUDIO_STREAM_STATE_UNINITIALIZED = 0,
89 AAUDIO_STREAM_STATE_UNKNOWN,
90 AAUDIO_STREAM_STATE_OPEN,
91 AAUDIO_STREAM_STATE_STARTING,
92 AAUDIO_STREAM_STATE_STARTED,
93 AAUDIO_STREAM_STATE_PAUSING,
94 AAUDIO_STREAM_STATE_PAUSED,
95 AAUDIO_STREAM_STATE_FLUSHING,
96 AAUDIO_STREAM_STATE_FLUSHED,
97 AAUDIO_STREAM_STATE_STOPPING,
98 AAUDIO_STREAM_STATE_STOPPED,
99 AAUDIO_STREAM_STATE_CLOSING,
100 AAUDIO_STREAM_STATE_CLOSED,
101 AAUDIO_STREAM_STATE_DISCONNECTED
102};
103typedef int32_t aaudio_stream_state_t;
104
105
106enum {
107 /**
108 * This will be the only stream using a particular source or sink.
109 * This mode will provide the lowest possible latency.
110 * You should close EXCLUSIVE streams immediately when you are not using them.
111 */
112 AAUDIO_SHARING_MODE_EXCLUSIVE,
113 /**
114 * Multiple applications will be mixed by the AAudio Server.
115 * This will have higher latency than the EXCLUSIVE mode.
116 */
117 AAUDIO_SHARING_MODE_SHARED
118};
119typedef int32_t aaudio_sharing_mode_t;
120
Phil Burke2fbb592017-05-01 15:05:52 -0700121
122enum {
123 /**
124 * No particular performance needs. Default.
125 */
126 AAUDIO_PERFORMANCE_MODE_NONE = 10,
127
128 /**
129 * Extending battery life is most important.
130 */
131 AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
132
133 /**
134 * Reducing latency is most important.
135 */
136 AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
137};
138typedef int32_t aaudio_performance_mode_t;
139
Phil Burk361b1422017-12-20 14:24:16 -0800140/**
141 * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for.
142 * This information is used by certain platforms or routing policies
143 * to make more refined volume or routing decisions.
144 *
145 * Note that these match the equivalent values in AudioAttributes in the Android Java API.
146 */
147enum {
148 /**
149 * Use this for streaming media, music performance, video, podcasts, etcetera.
150 */
151 AAUDIO_USAGE_MEDIA = 1,
152
153 /**
154 * Use this for voice over IP, telephony, etcetera.
155 */
156 AAUDIO_USAGE_VOICE_COMMUNICATION = 2,
157
158 /**
159 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.
160 */
161 AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
162
163 /**
164 * Use this to demand the users attention.
165 */
166 AAUDIO_USAGE_ALARM = 4,
167
168 /**
169 * Use this for notifying the user when a message has arrived or some
170 * other background event has occured.
171 */
172 AAUDIO_USAGE_NOTIFICATION = 5,
173
174 /**
175 * Use this when the phone rings.
176 */
177 AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6,
178
179 /**
180 * Use this to attract the users attention when, for example, the battery is low.
181 */
182 AAUDIO_USAGE_NOTIFICATION_EVENT = 10,
183
184 /**
185 * Use this for screen readers, etcetera.
186 */
187 AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
188
189 /**
190 * Use this for driving or navigation directions.
191 */
192 AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
193
194 /**
195 * Use this for user interface sounds, beeps, etcetera.
196 */
197 AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
198
199 /**
200 * Use this for game audio and sound effects.
201 */
202 AAUDIO_USAGE_GAME = 14,
203
204 /**
205 * Use this for audio responses to user queries, audio instructions or help utterances.
206 */
207 AAUDIO_USAGE_ASSISTANT = 16
208};
209typedef int32_t aaudio_usage_t;
210
211/**
212 * The CONTENT_TYPE attribute describes "what" you are playing.
213 * It expresses the general category of the content. This information is optional.
214 * But in case it is known (for instance {@link #AAUDIO_CONTENT_TYPE_MOVIE} for a
215 * movie streaming service or {@link #AAUDIO_CONTENT_TYPE_SPEECH} for
216 * an audio book application) this information might be used by the audio framework to
217 * enforce audio focus.
218 *
219 * Note that these match the equivalent values in AudioAttributes in the Android Java API.
220 */
221enum {
222
223 /**
224 * Use this for spoken voice, audio books, etcetera.
225 */
226 AAUDIO_CONTENT_TYPE_SPEECH = 1,
227
228 /**
229 * Use this for pre-recorded or live music.
230 */
231 AAUDIO_CONTENT_TYPE_MUSIC = 2,
232
233 /**
234 * Use this for a movie or video soundtrack.
235 */
236 AAUDIO_CONTENT_TYPE_MOVIE = 3,
237
238 /**
239 * Use this for sound is designed to accompany a user action,
240 * such as a click or beep sound made when the user presses a button.
241 */
242 AAUDIO_CONTENT_TYPE_SONIFICATION = 4
243};
244typedef int32_t aaudio_content_type_t;
245
246/**
247 * Defines the audio source.
248 * An audio source defines both a default physical source of audio signal, and a recording
249 * configuration.
250 *
251 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
252 */
253enum {
254 /**
255 * Use this preset when other presets do not apply.
256 */
257 AAUDIO_INPUT_PRESET_GENERIC = 1,
258
259 /**
260 * Use this preset when recording video.
261 */
262 AAUDIO_INPUT_PRESET_CAMCORDER = 5,
263
264 /**
265 * Use this preset when doing speech recognition.
266 */
267 AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6,
268
269 /**
270 * Use this preset when doing telephony or voice messaging.
271 */
272 AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7,
273
274 /**
275 * Use this preset to obtain an input with no effects.
276 * Note that this input will not have automatic gain control
277 * so the recorded volume may be very low.
278 */
279 AAUDIO_INPUT_PRESET_UNPROCESSED = 9,
280};
281typedef int32_t aaudio_input_preset_t;
282
Phil Burke2155ef2017-02-24 13:50:29 -0800283typedef struct AAudioStreamStruct AAudioStream;
284typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder;
Phil Burk5ed503c2017-02-01 09:38:15 -0800285
Phil Burk5ed503c2017-02-01 09:38:15 -0800286#ifndef AAUDIO_API
Phil Burk3316d5e2017-02-15 11:23:01 -0800287#define AAUDIO_API /* export this symbol */
Phil Burk5ed503c2017-02-01 09:38:15 -0800288#endif
289
290// ============================================================
291// Audio System
292// ============================================================
293
294/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800295 * The text is the ASCII symbol corresponding to the returnCode,
296 * or an English message saying the returnCode is unrecognized.
297 * This is intended for developers to use when debugging.
298 * It is not for display to users.
299 *
300 * @return pointer to a text representation of an AAudio result code.
301 */
302AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode);
303
304/**
305 * The text is the ASCII symbol corresponding to the stream state,
306 * or an English message saying the state is unrecognized.
307 * This is intended for developers to use when debugging.
308 * It is not for display to users.
309 *
310 * @return pointer to a text representation of an AAudio state.
311 */
312AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state);
313
314// ============================================================
315// StreamBuilder
316// ============================================================
317
318/**
319 * Create a StreamBuilder that can be used to open a Stream.
320 *
321 * The deviceId is initially unspecified, meaning that the current default device will be used.
322 *
323 * The default direction is AAUDIO_DIRECTION_OUTPUT.
Phil Burk3316d5e2017-02-15 11:23:01 -0800324 * The default sharing mode is AAUDIO_SHARING_MODE_SHARED.
Phil Burk5ed503c2017-02-01 09:38:15 -0800325 * The data format, samplesPerFrames and sampleRate are unspecified and will be
326 * chosen by the device when it is opened.
327 *
328 * AAudioStreamBuilder_delete() must be called when you are done using the builder.
329 */
Phil Burke2155ef2017-02-24 13:50:29 -0800330AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder);
Phil Burk5ed503c2017-02-01 09:38:15 -0800331
332/**
333 * Request an audio device identified device using an ID.
Phil Burk5ed503c2017-02-01 09:38:15 -0800334 * On Android, for example, the ID could be obtained from the Java AudioManager.
335 *
Glenn Kasten5f510d22017-05-30 15:52:15 -0700336 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED,
Phil Burke057ca92017-03-28 11:31:34 -0700337 * in which case the primary device will be used.
Phil Burk5ed503c2017-02-01 09:38:15 -0800338 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800339 * @param builder reference provided by AAudio_createStreamBuilder()
Glenn Kasten5f510d22017-05-30 15:52:15 -0700340 * @param deviceId device identifier or AAUDIO_UNSPECIFIED
Phil Burk5ed503c2017-02-01 09:38:15 -0800341 */
Phil Burke2155ef2017-02-24 13:50:29 -0800342AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder,
Phil Burk3316d5e2017-02-15 11:23:01 -0800343 int32_t deviceId);
Phil Burk5ed503c2017-02-01 09:38:15 -0800344
345/**
Phil Burke057ca92017-03-28 11:31:34 -0700346 * Request a sample rate in Hertz.
347 *
Phil Burke057ca92017-03-28 11:31:34 -0700348 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk8f624892017-05-11 11:44:20 -0700349 * An optimal value will then be chosen when the stream is opened.
350 * After opening a stream with an unspecified value, the application must
351 * query for the actual value, which may vary by device.
352 *
353 * If an exact value is specified then an opened stream will use that value.
354 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700355 *
356 * @param builder reference provided by AAudio_createStreamBuilder()
357 * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
Phil Burk5ed503c2017-02-01 09:38:15 -0800358 */
Phil Burke2155ef2017-02-24 13:50:29 -0800359AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder,
Phil Burk3316d5e2017-02-15 11:23:01 -0800360 int32_t sampleRate);
Phil Burk5ed503c2017-02-01 09:38:15 -0800361
362/**
Phil Burk20523ed2017-04-24 17:04:01 -0700363 * Request a number of channels for the stream.
Phil Burke057ca92017-03-28 11:31:34 -0700364 *
Phil Burke057ca92017-03-28 11:31:34 -0700365 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk8f624892017-05-11 11:44:20 -0700366 * An optimal value will then be chosen when the stream is opened.
367 * After opening a stream with an unspecified value, the application must
368 * query for the actual value, which may vary by device.
Phil Burk5ed503c2017-02-01 09:38:15 -0800369 *
Phil Burk8f624892017-05-11 11:44:20 -0700370 * If an exact value is specified then an opened stream will use that value.
371 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700372 *
373 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk20523ed2017-04-24 17:04:01 -0700374 * @param channelCount Number of channels desired.
Phil Burk5ed503c2017-02-01 09:38:15 -0800375 */
Phil Burk20523ed2017-04-24 17:04:01 -0700376AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder,
377 int32_t channelCount);
378
379/**
Phil Burke74240d2017-08-03 15:25:43 -0700380 * Identical to AAudioStreamBuilder_setChannelCount().
381 *
382 * @param builder reference provided by AAudio_createStreamBuilder()
383 * @param samplesPerFrame Number of samples in a frame.
384 */
385AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder,
386 int32_t samplesPerFrame);
387
388/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800389 * Request a sample data format, for example AAUDIO_FORMAT_PCM_I16.
Phil Burke057ca92017-03-28 11:31:34 -0700390 *
391 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk8f624892017-05-11 11:44:20 -0700392 * An optimal value will then be chosen when the stream is opened.
393 * After opening a stream with an unspecified value, the application must
394 * query for the actual value, which may vary by device.
Phil Burke057ca92017-03-28 11:31:34 -0700395 *
Phil Burk8f624892017-05-11 11:44:20 -0700396 * If an exact value is specified then an opened stream will use that value.
397 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700398 *
399 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk8f624892017-05-11 11:44:20 -0700400 * @param format common formats are AAUDIO_FORMAT_PCM_FLOAT and AAUDIO_FORMAT_PCM_I16.
Phil Burk5ed503c2017-02-01 09:38:15 -0800401 */
Phil Burke2155ef2017-02-24 13:50:29 -0800402AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder,
Phil Burk9dca9822017-05-26 14:27:43 -0700403 aaudio_format_t format);
Phil Burk5ed503c2017-02-01 09:38:15 -0800404
405/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800406 * Request a mode for sharing the device.
Phil Burke057ca92017-03-28 11:31:34 -0700407 *
408 * The default, if you do not call this function, is AAUDIO_SHARING_MODE_SHARED.
409 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800410 * The requested sharing mode may not be available.
Phil Burke057ca92017-03-28 11:31:34 -0700411 * The application can query for the actual mode after the stream is opened.
Phil Burk5ed503c2017-02-01 09:38:15 -0800412 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800413 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burke057ca92017-03-28 11:31:34 -0700414 * @param sharingMode AAUDIO_SHARING_MODE_SHARED or AAUDIO_SHARING_MODE_EXCLUSIVE
Phil Burk5ed503c2017-02-01 09:38:15 -0800415 */
Phil Burke2155ef2017-02-24 13:50:29 -0800416AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder,
Phil Burk5ed503c2017-02-01 09:38:15 -0800417 aaudio_sharing_mode_t sharingMode);
418
419/**
Phil Burke057ca92017-03-28 11:31:34 -0700420 * Request the direction for a stream.
421 *
422 * The default, if you do not call this function, is AAUDIO_DIRECTION_OUTPUT.
Phil Burk5ed503c2017-02-01 09:38:15 -0800423 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800424 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk5ed503c2017-02-01 09:38:15 -0800425 * @param direction AAUDIO_DIRECTION_OUTPUT or AAUDIO_DIRECTION_INPUT
Phil Burk5ed503c2017-02-01 09:38:15 -0800426 */
Phil Burke2155ef2017-02-24 13:50:29 -0800427AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder,
Phil Burk3df348f2017-02-08 11:41:55 -0800428 aaudio_direction_t direction);
Phil Burk5ed503c2017-02-01 09:38:15 -0800429
430/**
Phil Burke057ca92017-03-28 11:31:34 -0700431 * Set the requested buffer capacity in frames.
Phil Burk3df348f2017-02-08 11:41:55 -0800432 * The final AAudioStream capacity may differ, but will probably be at least this big.
433 *
Phil Burke057ca92017-03-28 11:31:34 -0700434 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk3df348f2017-02-08 11:41:55 -0800435 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800436 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burke057ca92017-03-28 11:31:34 -0700437 * @param numFrames the desired buffer capacity in frames or AAUDIO_UNSPECIFIED
Phil Burk3df348f2017-02-08 11:41:55 -0800438 */
Phil Burke2155ef2017-02-24 13:50:29 -0800439AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder,
Phil Burke057ca92017-03-28 11:31:34 -0700440 int32_t numFrames);
Phil Burke2fbb592017-05-01 15:05:52 -0700441
442/**
443 * Set the requested performance mode.
444 *
445 * The default, if you do not call this function, is AAUDIO_PERFORMANCE_MODE_NONE.
446 *
447 * @param builder reference provided by AAudio_createStreamBuilder()
448 * @param mode the desired performance mode, eg. AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
449 */
450AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder,
451 aaudio_performance_mode_t mode);
452
Phil Burke057ca92017-03-28 11:31:34 -0700453/**
Phil Burk361b1422017-12-20 14:24:16 -0800454 * Set the intended use case for the stream.
455 *
456 * The AAudio system will use this information to optimize the
457 * behavior of the stream.
458 * This could, for example, affect how volume and focus is handled for the stream.
459 *
460 * The default, if you do not call this function, is AAUDIO_USAGE_MEDIA.
461 *
462 * @param builder reference provided by AAudio_createStreamBuilder()
463 * @param usage the desired usage, eg. AAUDIO_USAGE_GAME
464 */
465AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder,
466 aaudio_usage_t usage);
467
468/**
469 * Set the type of audio data that the stream will carry.
470 *
471 * The AAudio system will use this information to optimize the
472 * behavior of the stream.
473 * This could, for example, affect whether a stream is paused when a notification occurs.
474 *
475 * The default, if you do not call this function, is AAUDIO_CONTENT_TYPE_MUSIC.
476 *
477 * @param builder reference provided by AAudio_createStreamBuilder()
478 * @param contentType the type of audio data, eg. AAUDIO_CONTENT_TYPE_SPEECH
479 */
480AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder,
481 aaudio_content_type_t contentType);
482
483/**
484 * Set the input (capture) preset for the stream.
485 *
486 * The AAudio system will use this information to optimize the
487 * behavior of the stream.
488 * This could, for example, affect which microphones are used and how the
489 * recorded data is processed.
490 *
491 * The default, if you do not call this function, is AAUDIO_INPUT_PRESET_GENERIC.
492 *
493 * @param builder reference provided by AAudio_createStreamBuilder()
494 * @param inputPreset the desired configuration for recording
495 */
496AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
497 aaudio_input_preset_t inputPreset);
498
499/**
Phil Burke057ca92017-03-28 11:31:34 -0700500 * Return one of these values from the data callback function.
501 */
502enum {
503
504 /**
505 * Continue calling the callback.
506 */
507 AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
508
509 /**
510 * Stop calling the callback.
511 *
512 * The application will still need to call AAudioStream_requestPause()
513 * or AAudioStream_requestStop().
514 */
515 AAUDIO_CALLBACK_RESULT_STOP,
516
517};
518typedef int32_t aaudio_data_callback_result_t;
519
520/**
521 * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
522 *
523 * For an output stream, this function should render and write numFrames of data
524 * in the streams current data format to the audioData buffer.
525 *
526 * For an input stream, this function should read and process numFrames of data
527 * from the audioData buffer.
528 *
529 * Note that this callback function should be considered a "real-time" function.
530 * It must not do anything that could cause an unbounded delay because that can cause the
531 * audio to glitch or pop.
532 *
533 * These are things the function should NOT do:
534 * <ul>
535 * <li>allocate memory using, for example, malloc() or new</li>
536 * <li>any file operations such as opening, closing, reading or writing</li>
537 * <li>any network operations such as streaming</li>
538 * <li>use any mutexes or other synchronization primitives</li>
539 * <li>sleep</li>
540 * </ul>
541 *
542 * If you need to move data, eg. MIDI commands, in or out of the callback function then
543 * we recommend the use of non-blocking techniques such as an atomic FIFO.
544 *
545 * @param stream reference provided by AAudioStreamBuilder_openStream()
546 * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
547 * @param audioData a pointer to the audio data
548 * @param numFrames the number of frames to be processed
549 * @return AAUDIO_CALLBACK_RESULT_*
550 */
551typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
552 AAudioStream *stream,
553 void *userData,
554 void *audioData,
555 int32_t numFrames);
556
557/**
558 * Request that AAudio call this functions when the stream is running.
559 *
560 * Note that when using this callback, the audio data will be passed in or out
561 * of the function as an argument.
562 * So you cannot call AAudioStream_write() or AAudioStream_read() on the same stream
563 * that has an active data callback.
564 *
565 * The callback function will start being called after AAudioStream_requestStart() is called.
566 * It will stop being called after AAudioStream_requestPause() or
567 * AAudioStream_requestStop() is called.
568 *
569 * This callback function will be called on a real-time thread owned by AAudio. See
Glenn Kasten0d804362017-04-13 09:20:14 -0700570 * {@link AAudioStream_dataCallback} for more information.
Phil Burke057ca92017-03-28 11:31:34 -0700571 *
572 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
573 *
574 * @param builder reference provided by AAudio_createStreamBuilder()
575 * @param callback pointer to a function that will process audio data.
576 * @param userData pointer to an application data structure that will be passed
577 * to the callback functions.
578 */
579AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder,
580 AAudioStream_dataCallback callback,
581 void *userData);
582
583/**
584 * Set the requested data callback buffer size in frames.
585 * See {@link AAudioStream_dataCallback}.
586 *
587 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
588 *
589 * For the lowest possible latency, do not call this function. AAudio will then
590 * call the dataProc callback function with whatever size is optimal.
591 * That size may vary from one callback to another.
592 *
593 * Only use this function if the application requires a specific number of frames for processing.
594 * The application might, for example, be using an FFT that requires
595 * a specific power-of-two sized buffer.
596 *
597 * AAudio may need to add additional buffering in order to adapt between the internal
598 * buffer size and the requested buffer size.
599 *
600 * If you do call this function then the requested size should be less than
601 * half the buffer capacity, to allow double buffering.
602 *
603 * @param builder reference provided by AAudio_createStreamBuilder()
604 * @param numFrames the desired buffer size in frames or AAUDIO_UNSPECIFIED
605 */
606AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder,
607 int32_t numFrames);
608
609/**
610 * Prototype for the callback function that is passed to
611 * AAudioStreamBuilder_setErrorCallback().
612 *
613 * @param stream reference provided by AAudioStreamBuilder_openStream()
614 * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
615 * @param error an AAUDIO_ERROR_* value.
616 */
617typedef void (*AAudioStream_errorCallback)(
618 AAudioStream *stream,
619 void *userData,
620 aaudio_result_t error);
621
622/**
623 * Request that AAudio call this functions if any error occurs on a callback thread.
624 *
625 * It will be called, for example, if a headset or a USB device is unplugged causing the stream's
626 * device to be unavailable.
627 * In response, this function could signal or launch another thread to reopen a
628 * stream on another device. Do not reopen the stream in this callback.
629 *
630 * This will not be called because of actions by the application, such as stopping
631 * or closing a stream.
632 *
633 * Another possible cause of error would be a timeout or an unanticipated internal error.
634 *
635 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
636 *
637 * @param builder reference provided by AAudio_createStreamBuilder()
638 * @param callback pointer to a function that will be called if an error occurs.
639 * @param userData pointer to an application data structure that will be passed
640 * to the callback functions.
641 */
642AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder,
643 AAudioStream_errorCallback callback,
644 void *userData);
Phil Burk5ed503c2017-02-01 09:38:15 -0800645
646/**
647 * Open a stream based on the options in the StreamBuilder.
648 *
649 * AAudioStream_close must be called when finished with the stream to recover
650 * the memory and to free the associated resources.
651 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800652 * @param builder reference provided by AAudio_createStreamBuilder()
653 * @param stream pointer to a variable to receive the new stream reference
Phil Burk5ed503c2017-02-01 09:38:15 -0800654 * @return AAUDIO_OK or a negative error.
655 */
Phil Burke2155ef2017-02-24 13:50:29 -0800656AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder,
657 AAudioStream** stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800658
659/**
660 * Delete the resources associated with the StreamBuilder.
661 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800662 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk5ed503c2017-02-01 09:38:15 -0800663 * @return AAUDIO_OK or a negative error.
664 */
Phil Burke2155ef2017-02-24 13:50:29 -0800665AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder);
Phil Burk5ed503c2017-02-01 09:38:15 -0800666
667// ============================================================
668// Stream Control
669// ============================================================
670
671/**
672 * Free the resources associated with a stream created by AAudioStreamBuilder_openStream()
673 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800674 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800675 * @return AAUDIO_OK or a negative error.
676 */
Phil Burke2155ef2017-02-24 13:50:29 -0800677AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800678
679/**
680 * Asynchronously request to start playing the stream. For output streams, one should
681 * write to the stream to fill the buffer before starting.
682 * Otherwise it will underflow.
683 * After this call the state will be in AAUDIO_STREAM_STATE_STARTING or AAUDIO_STREAM_STATE_STARTED.
684 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800685 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800686 * @return AAUDIO_OK or a negative error.
687 */
Phil Burke2155ef2017-02-24 13:50:29 -0800688AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800689
690/**
691 * Asynchronous request for the stream to pause.
692 * Pausing a stream will freeze the data flow but not flush any buffers.
693 * Use AAudioStream_Start() to resume playback after a pause.
694 * After this call the state will be in AAUDIO_STREAM_STATE_PAUSING or AAUDIO_STREAM_STATE_PAUSED.
695 *
Phil Burk068c10f2017-05-08 16:36:41 -0700696 * This will return AAUDIO_ERROR_UNIMPLEMENTED for input streams.
697 * For input streams use AAudioStream_requestStop().
698 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800699 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800700 * @return AAUDIO_OK or a negative error.
701 */
Phil Burke2155ef2017-02-24 13:50:29 -0800702AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800703
704/**
705 * Asynchronous request for the stream to flush.
706 * Flushing will discard any pending data.
707 * This call only works if the stream is pausing or paused. TODO review
708 * Frame counters are not reset by a flush. They may be advanced.
709 * After this call the state will be in AAUDIO_STREAM_STATE_FLUSHING or AAUDIO_STREAM_STATE_FLUSHED.
710 *
Phil Burk068c10f2017-05-08 16:36:41 -0700711 * This will return AAUDIO_ERROR_UNIMPLEMENTED for input streams.
712 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800713 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800714 * @return AAUDIO_OK or a negative error.
715 */
Phil Burke2155ef2017-02-24 13:50:29 -0800716AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800717
718/**
719 * Asynchronous request for the stream to stop.
720 * The stream will stop after all of the data currently buffered has been played.
721 * After this call the state will be in AAUDIO_STREAM_STATE_STOPPING or AAUDIO_STREAM_STATE_STOPPED.
722 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800723 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800724 * @return AAUDIO_OK or a negative error.
725 */
Phil Burke2155ef2017-02-24 13:50:29 -0800726AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800727
728/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800729 * Query the current state of the client, eg. AAUDIO_STREAM_STATE_PAUSING
Phil Burk5ed503c2017-02-01 09:38:15 -0800730 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800731 * This function will immediately return the state without updating the state.
732 * If you want to update the client state based on the server state then
733 * call AAudioStream_waitForStateChange() with currentState
734 * set to AAUDIO_STREAM_STATE_UNKNOWN and a zero timeout.
735 *
736 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800737 */
Phil Burke2155ef2017-02-24 13:50:29 -0800738AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800739
740/**
741 * Wait until the current state no longer matches the input state.
742 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800743 * This will update the current client state.
744 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800745 * <pre><code>
746 * aaudio_stream_state_t currentState;
747 * aaudio_result_t result = AAudioStream_getState(stream, &currentState);
748 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSING) {
749 * result = AAudioStream_waitForStateChange(
750 * stream, currentState, &currentState, MY_TIMEOUT_NANOS);
751 * }
752 * </code></pre>
753 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800754 * @param stream A reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800755 * @param inputState The state we want to avoid.
756 * @param nextState Pointer to a variable that will be set to the new state.
757 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
758 * @return AAUDIO_OK or a negative error.
759 */
Phil Burke2155ef2017-02-24 13:50:29 -0800760AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
Phil Burk5ed503c2017-02-01 09:38:15 -0800761 aaudio_stream_state_t inputState,
762 aaudio_stream_state_t *nextState,
Phil Burk3316d5e2017-02-15 11:23:01 -0800763 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800764
765// ============================================================
766// Stream I/O
767// ============================================================
768
769/**
770 * Read data from the stream.
771 *
772 * The call will wait until the read is complete or until it runs out of time.
773 * If timeoutNanos is zero then this call will not wait.
774 *
775 * Note that timeoutNanoseconds is a relative duration in wall clock time.
776 * Time will not stop if the thread is asleep.
777 * So it will be implemented using CLOCK_BOOTTIME.
778 *
779 * This call is "strong non-blocking" unless it has to wait for data.
780 *
781 * @param stream A stream created using AAudioStreamBuilder_openStream().
782 * @param buffer The address of the first sample.
783 * @param numFrames Number of frames to read. Only complete frames will be written.
784 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Phil Burk3316d5e2017-02-15 11:23:01 -0800785 * @return The number of frames actually read or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -0800786 */
Phil Burke2155ef2017-02-24 13:50:29 -0800787AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream,
Phil Burk5ed503c2017-02-01 09:38:15 -0800788 void *buffer,
Phil Burk3316d5e2017-02-15 11:23:01 -0800789 int32_t numFrames,
790 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800791
792/**
793 * Write data to the stream.
794 *
795 * The call will wait until the write is complete or until it runs out of time.
796 * If timeoutNanos is zero then this call will not wait.
797 *
798 * Note that timeoutNanoseconds is a relative duration in wall clock time.
799 * Time will not stop if the thread is asleep.
800 * So it will be implemented using CLOCK_BOOTTIME.
801 *
802 * This call is "strong non-blocking" unless it has to wait for room in the buffer.
803 *
804 * @param stream A stream created using AAudioStreamBuilder_openStream().
805 * @param buffer The address of the first sample.
806 * @param numFrames Number of frames to write. Only complete frames will be written.
807 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
808 * @return The number of frames actually written or a negative error.
809 */
Phil Burke2155ef2017-02-24 13:50:29 -0800810AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream,
Phil Burk5ed503c2017-02-01 09:38:15 -0800811 const void *buffer,
Phil Burk3316d5e2017-02-15 11:23:01 -0800812 int32_t numFrames,
813 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800814
Phil Burk5ed503c2017-02-01 09:38:15 -0800815// ============================================================
816// Stream - queries
817// ============================================================
818
Phil Burk5ed503c2017-02-01 09:38:15 -0800819/**
820 * This can be used to adjust the latency of the buffer by changing
821 * the threshold where blocking will occur.
Phil Burk3316d5e2017-02-15 11:23:01 -0800822 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
Phil Burk5ed503c2017-02-01 09:38:15 -0800823 * at run-time for each device.
824 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800825 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
Phil Burk5ed503c2017-02-01 09:38:15 -0800826 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800827 * Note that you will probably not get the exact size you request.
828 * Call AAudioStream_getBufferSizeInFrames() to see what the actual final size is.
829 *
830 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -0700831 * @param numFrames requested number of frames that can be filled without blocking
Phil Burk3316d5e2017-02-15 11:23:01 -0800832 * @return actual buffer size in frames or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -0800833 */
Phil Burke2155ef2017-02-24 13:50:29 -0800834AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream,
Phil Burke057ca92017-03-28 11:31:34 -0700835 int32_t numFrames);
Phil Burk5ed503c2017-02-01 09:38:15 -0800836
837/**
838 * Query the maximum number of frames that can be filled without blocking.
839 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800840 * @param stream reference provided by AAudioStreamBuilder_openStream()
841 * @return buffer size in frames.
Phil Burk5ed503c2017-02-01 09:38:15 -0800842 */
Phil Burke2155ef2017-02-24 13:50:29 -0800843AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800844
845/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800846 * Query the number of frames that the application should read or write at
847 * one time for optimal performance. It is OK if an application writes
848 * a different number of frames. But the buffer size may need to be larger
849 * in order to avoid underruns or overruns.
Phil Burk5ed503c2017-02-01 09:38:15 -0800850 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800851 * Note that this may or may not match the actual device burst size.
852 * For some endpoints, the burst size can vary dynamically.
853 * But these tend to be devices with high latency.
854 *
855 * @param stream reference provided by AAudioStreamBuilder_openStream()
856 * @return burst size
Phil Burk5ed503c2017-02-01 09:38:15 -0800857 */
Phil Burke2155ef2017-02-24 13:50:29 -0800858AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800859
860/**
861 * Query maximum buffer capacity in frames.
862 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800863 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -0700864 * @return buffer capacity in frames
Phil Burk5ed503c2017-02-01 09:38:15 -0800865 */
Phil Burke2155ef2017-02-24 13:50:29 -0800866AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800867
868/**
Phil Burke057ca92017-03-28 11:31:34 -0700869 * Query the size of the buffer that will be passed to the dataProc callback
870 * in the numFrames parameter.
871 *
872 * This call can be used if the application needs to know the value of numFrames before
873 * the stream is started. This is not normally necessary.
874 *
875 * If a specific size was requested by calling AAudioStreamBuilder_setCallbackSizeInFrames()
876 * then this will be the same size.
877 *
878 * If AAudioStreamBuilder_setCallbackSizeInFrames() was not called then this will
879 * return the size chosen by AAudio, or AAUDIO_UNSPECIFIED.
880 *
881 * AAUDIO_UNSPECIFIED indicates that the callback buffer size for this stream
882 * may vary from one dataProc callback to the next.
883 *
884 * @param stream reference provided by AAudioStreamBuilder_openStream()
885 * @return callback buffer size in frames or AAUDIO_UNSPECIFIED
886 */
887AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream);
888
889/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800890 * An XRun is an Underrun or an Overrun.
891 * During playing, an underrun will occur if the stream is not written in time
892 * and the system runs out of valid data.
893 * During recording, an overrun will occur if the stream is not read in time
894 * and there is no place to put the incoming data so it is discarded.
895 *
896 * An underrun or overrun can cause an audible "pop" or "glitch".
897 *
Phil Burk068c10f2017-05-08 16:36:41 -0700898 * Note that some INPUT devices may not support this function.
899 * In that case a 0 will always be returned.
900 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800901 * @param stream reference provided by AAudioStreamBuilder_openStream()
902 * @return the underrun or overrun count
Phil Burk5ed503c2017-02-01 09:38:15 -0800903 */
Phil Burke2155ef2017-02-24 13:50:29 -0800904AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800905
906/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800907 * @param stream reference provided by AAudioStreamBuilder_openStream()
908 * @return actual sample rate
Phil Burk5ed503c2017-02-01 09:38:15 -0800909 */
Phil Burke2155ef2017-02-24 13:50:29 -0800910AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800911
912/**
Phil Burk20523ed2017-04-24 17:04:01 -0700913 * A stream has one or more channels of data.
914 * A frame will contain one sample for each channel.
915 *
916 * @param stream reference provided by AAudioStreamBuilder_openStream()
917 * @return actual number of channels
918 */
919AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream);
920
921/**
Phil Burke74240d2017-08-03 15:25:43 -0700922 * Identical to AAudioStream_getChannelCount().
923 *
924 * @param stream reference provided by AAudioStreamBuilder_openStream()
925 * @return actual number of samples frame
926 */
927AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream);
928
929/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800930 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke2155ef2017-02-24 13:50:29 -0800931 * @return actual device ID
Phil Burk5ed503c2017-02-01 09:38:15 -0800932 */
Phil Burke2155ef2017-02-24 13:50:29 -0800933AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800934
935/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800936 * @param stream reference provided by AAudioStreamBuilder_openStream()
937 * @return actual data format
Phil Burk5ed503c2017-02-01 09:38:15 -0800938 */
Phil Burk9dca9822017-05-26 14:27:43 -0700939AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800940
941/**
942 * Provide actual sharing mode.
Phil Burk3316d5e2017-02-15 11:23:01 -0800943 * @param stream reference provided by AAudioStreamBuilder_openStream()
944 * @return actual sharing mode
Phil Burk5ed503c2017-02-01 09:38:15 -0800945 */
Phil Burke2155ef2017-02-24 13:50:29 -0800946AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800947
948/**
Phil Burke2fbb592017-05-01 15:05:52 -0700949 * Get the performance mode used by the stream.
950 *
951 * @param stream reference provided by AAudioStreamBuilder_openStream()
952 */
953AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream);
954
955/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800956 * @param stream reference provided by AAudioStreamBuilder_openStream()
957 * @return direction
Phil Burk5ed503c2017-02-01 09:38:15 -0800958 */
Phil Burke2155ef2017-02-24 13:50:29 -0800959AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800960
961/**
962 * Passes back the number of frames that have been written since the stream was created.
963 * For an output stream, this will be advanced by the application calling write().
Phil Burk3316d5e2017-02-15 11:23:01 -0800964 * For an input stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -0800965 *
966 * The frame position is monotonically increasing.
967 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800968 * @param stream reference provided by AAudioStreamBuilder_openStream()
969 * @return frames written
Phil Burk5ed503c2017-02-01 09:38:15 -0800970 */
Phil Burke2155ef2017-02-24 13:50:29 -0800971AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800972
973/**
974 * Passes back the number of frames that have been read since the stream was created.
Phil Burk3316d5e2017-02-15 11:23:01 -0800975 * For an output stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -0800976 * For an input stream, this will be advanced by the application calling read().
977 *
978 * The frame position is monotonically increasing.
979 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800980 * @param stream reference provided by AAudioStreamBuilder_openStream()
981 * @return frames read
Phil Burk5ed503c2017-02-01 09:38:15 -0800982 */
Phil Burke2155ef2017-02-24 13:50:29 -0800983AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800984
985/**
986 * Passes back the time at which a particular frame was presented.
987 * This can be used to synchronize audio with video or MIDI.
988 * It can also be used to align a recorded stream with a playback stream.
989 *
990 * Timestamps are only valid when the stream is in AAUDIO_STREAM_STATE_STARTED.
991 * AAUDIO_ERROR_INVALID_STATE will be returned if the stream is not started.
992 * Note that because requestStart() is asynchronous, timestamps will not be valid until
993 * a short time after calling requestStart().
994 * So AAUDIO_ERROR_INVALID_STATE should not be considered a fatal error.
995 * Just try calling again later.
996 *
997 * If an error occurs, then the position and time will not be modified.
998 *
999 * The position and time passed back are monotonically increasing.
1000 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001001 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burkec159502017-07-25 17:33:47 -07001002 * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
Phil Burk5ed503c2017-02-01 09:38:15 -08001003 * @param framePosition pointer to a variable to receive the position
1004 * @param timeNanoseconds pointer to a variable to receive the time
1005 * @return AAUDIO_OK or a negative error
1006 */
Phil Burke2155ef2017-02-24 13:50:29 -08001007AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream,
Phil Burk3316d5e2017-02-15 11:23:01 -08001008 clockid_t clockid,
1009 int64_t *framePosition,
1010 int64_t *timeNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -08001011
Phil Burk361b1422017-12-20 14:24:16 -08001012/**
1013 * Return the use case for the stream.
1014 *
1015 * @param stream reference provided by AAudioStreamBuilder_openStream()
1016 * @return frames read
1017 */
1018AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream);
1019
1020/**
1021 * Return the content type for the stream.
1022 *
1023 * @param stream reference provided by AAudioStreamBuilder_openStream()
1024 * @return content type, for example AAUDIO_CONTENT_TYPE_MUSIC
1025 */
1026AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream);
1027
1028/**
1029 * Return the input preset for the stream.
1030 *
1031 * @param stream reference provided by AAudioStreamBuilder_openStream()
1032 * @return input preset, for example AAUDIO_INPUT_PRESET_CAMCORDER
1033 */
1034AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream);
1035
Phil Burk5ed503c2017-02-01 09:38:15 -08001036#ifdef __cplusplus
1037}
1038#endif
1039
1040#endif //AAUDIO_AAUDIO_H
Phil Burka45be8b2017-04-05 14:45:48 -07001041
1042/** @} */