blob: 43b520584da5fe1d214067160ab10dd44467d6b4 [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/**
18 * This is the 'C' ABI for AAudio.
19 */
20#ifndef AAUDIO_AAUDIO_H
21#define AAUDIO_AAUDIO_H
22
Phil Burk3316d5e2017-02-15 11:23:01 -080023#include <time.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080024#include "AAudioDefinitions.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
Phil Burk3316d5e2017-02-15 11:23:01 -080030typedef struct AAudioStreamStruct * AAudioStream;
31typedef struct AAudioStreamBuilderStruct * AAudioStreamBuilder;
Phil Burk5ed503c2017-02-01 09:38:15 -080032
Phil Burk3316d5e2017-02-15 11:23:01 -080033#define AAUDIO_STREAM_NONE ((AAudioStream)nullptr)
34#define AAUDIO_STREAM_BUILDER_NONE ((AAudioStreamBuilder)nullptr)
Phil Burk5ed503c2017-02-01 09:38:15 -080035
Phil Burk5ed503c2017-02-01 09:38:15 -080036#ifndef AAUDIO_API
Phil Burk3316d5e2017-02-15 11:23:01 -080037#define AAUDIO_API /* export this symbol */
Phil Burk5ed503c2017-02-01 09:38:15 -080038#endif
39
40// ============================================================
41// Audio System
42// ============================================================
43
44/**
Phil Burk5ed503c2017-02-01 09:38:15 -080045 * The text is the ASCII symbol corresponding to the returnCode,
46 * or an English message saying the returnCode is unrecognized.
47 * This is intended for developers to use when debugging.
48 * It is not for display to users.
49 *
50 * @return pointer to a text representation of an AAudio result code.
51 */
52AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode);
53
54/**
55 * The text is the ASCII symbol corresponding to the stream state,
56 * or an English message saying the state is unrecognized.
57 * This is intended for developers to use when debugging.
58 * It is not for display to users.
59 *
60 * @return pointer to a text representation of an AAudio state.
61 */
62AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state);
63
64// ============================================================
65// StreamBuilder
66// ============================================================
67
68/**
69 * Create a StreamBuilder that can be used to open a Stream.
70 *
71 * The deviceId is initially unspecified, meaning that the current default device will be used.
72 *
73 * The default direction is AAUDIO_DIRECTION_OUTPUT.
Phil Burk3316d5e2017-02-15 11:23:01 -080074 * The default sharing mode is AAUDIO_SHARING_MODE_SHARED.
Phil Burk5ed503c2017-02-01 09:38:15 -080075 * The data format, samplesPerFrames and sampleRate are unspecified and will be
76 * chosen by the device when it is opened.
77 *
78 * AAudioStreamBuilder_delete() must be called when you are done using the builder.
79 */
80AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder *builder);
81
82/**
83 * Request an audio device identified device using an ID.
Phil Burk5ed503c2017-02-01 09:38:15 -080084 * On Android, for example, the ID could be obtained from the Java AudioManager.
85 *
86 * By default, the primary device will be used.
87 *
Phil Burk3316d5e2017-02-15 11:23:01 -080088 * @param builder reference provided by AAudio_createStreamBuilder()
89 * @param deviceId device identifier or AAUDIO_DEVICE_UNSPECIFIED
Phil Burk5ed503c2017-02-01 09:38:15 -080090 */
Phil Burk3316d5e2017-02-15 11:23:01 -080091AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder builder,
92 int32_t deviceId);
Phil Burk5ed503c2017-02-01 09:38:15 -080093
94/**
95 * Request a sample rate in Hz.
96 * The stream may be opened with a different sample rate.
97 * So the application should query for the actual rate after the stream is opened.
98 *
99 * Technically, this should be called the "frame rate" or "frames per second",
100 * because it refers to the number of complete frames transferred per second.
101 * But it is traditionally called "sample rate". Se we use that term.
102 *
103 * Default is AAUDIO_UNSPECIFIED.
Phil Burk5ed503c2017-02-01 09:38:15 -0800104
Phil Burk5ed503c2017-02-01 09:38:15 -0800105 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800106AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder builder,
107 int32_t sampleRate);
Phil Burk5ed503c2017-02-01 09:38:15 -0800108
109/**
110 * Request a number of samples per frame.
111 * The stream may be opened with a different value.
112 * So the application should query for the actual value after the stream is opened.
113 *
114 * Default is AAUDIO_UNSPECIFIED.
115 *
116 * Note, this quantity is sometimes referred to as "channel count".
Phil Burk5ed503c2017-02-01 09:38:15 -0800117 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800118AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder builder,
Phil Burk5ed503c2017-02-01 09:38:15 -0800119 int32_t samplesPerFrame);
120
121/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800122 * Request a sample data format, for example AAUDIO_FORMAT_PCM_I16.
123 * The application should query for the actual format after the stream is opened.
Phil Burk5ed503c2017-02-01 09:38:15 -0800124 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800125AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder builder,
Phil Burk5ed503c2017-02-01 09:38:15 -0800126 aaudio_audio_format_t format);
127
128/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800129 * Request a mode for sharing the device.
130 * The requested sharing mode may not be available.
131 * So the application should query for the actual mode after the stream is opened.
132 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800133 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk5ed503c2017-02-01 09:38:15 -0800134 * @param sharingMode AAUDIO_SHARING_MODE_LEGACY or AAUDIO_SHARING_MODE_EXCLUSIVE
Phil Burk5ed503c2017-02-01 09:38:15 -0800135 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800136AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder builder,
Phil Burk5ed503c2017-02-01 09:38:15 -0800137 aaudio_sharing_mode_t sharingMode);
138
139/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800140 * Request the direction for a stream. The default is AAUDIO_DIRECTION_OUTPUT.
141 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800142 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk5ed503c2017-02-01 09:38:15 -0800143 * @param direction AAUDIO_DIRECTION_OUTPUT or AAUDIO_DIRECTION_INPUT
Phil Burk5ed503c2017-02-01 09:38:15 -0800144 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800145AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder builder,
Phil Burk3df348f2017-02-08 11:41:55 -0800146 aaudio_direction_t direction);
Phil Burk5ed503c2017-02-01 09:38:15 -0800147
148/**
Phil Burk3df348f2017-02-08 11:41:55 -0800149 * Set the requested maximum buffer capacity in frames.
150 * The final AAudioStream capacity may differ, but will probably be at least this big.
151 *
152 * Default is AAUDIO_UNSPECIFIED.
153 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800154 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk3df348f2017-02-08 11:41:55 -0800155 * @param frames the desired buffer capacity in frames or AAUDIO_UNSPECIFIED
Phil Burk3df348f2017-02-08 11:41:55 -0800156 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800157AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder builder,
158 int32_t frames);
Phil Burk5ed503c2017-02-01 09:38:15 -0800159
160/**
161 * Open a stream based on the options in the StreamBuilder.
162 *
163 * AAudioStream_close must be called when finished with the stream to recover
164 * the memory and to free the associated resources.
165 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800166 * @param builder reference provided by AAudio_createStreamBuilder()
167 * @param stream pointer to a variable to receive the new stream reference
Phil Burk5ed503c2017-02-01 09:38:15 -0800168 * @return AAUDIO_OK or a negative error.
169 */
170AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder builder,
171 AAudioStream *stream);
172
173/**
174 * Delete the resources associated with the StreamBuilder.
175 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800176 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk5ed503c2017-02-01 09:38:15 -0800177 * @return AAUDIO_OK or a negative error.
178 */
179AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder builder);
180
181// ============================================================
182// Stream Control
183// ============================================================
184
185/**
186 * Free the resources associated with a stream created by AAudioStreamBuilder_openStream()
187 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800188 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800189 * @return AAUDIO_OK or a negative error.
190 */
191AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream stream);
192
193/**
194 * Asynchronously request to start playing the stream. For output streams, one should
195 * write to the stream to fill the buffer before starting.
196 * Otherwise it will underflow.
197 * After this call the state will be in AAUDIO_STREAM_STATE_STARTING or AAUDIO_STREAM_STATE_STARTED.
198 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800199 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800200 * @return AAUDIO_OK or a negative error.
201 */
202AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream stream);
203
204/**
205 * Asynchronous request for the stream to pause.
206 * Pausing a stream will freeze the data flow but not flush any buffers.
207 * Use AAudioStream_Start() to resume playback after a pause.
208 * After this call the state will be in AAUDIO_STREAM_STATE_PAUSING or AAUDIO_STREAM_STATE_PAUSED.
209 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800210 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800211 * @return AAUDIO_OK or a negative error.
212 */
213AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream stream);
214
215/**
216 * Asynchronous request for the stream to flush.
217 * Flushing will discard any pending data.
218 * This call only works if the stream is pausing or paused. TODO review
219 * Frame counters are not reset by a flush. They may be advanced.
220 * After this call the state will be in AAUDIO_STREAM_STATE_FLUSHING or AAUDIO_STREAM_STATE_FLUSHED.
221 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800222 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800223 * @return AAUDIO_OK or a negative error.
224 */
225AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream stream);
226
227/**
228 * Asynchronous request for the stream to stop.
229 * The stream will stop after all of the data currently buffered has been played.
230 * After this call the state will be in AAUDIO_STREAM_STATE_STOPPING or AAUDIO_STREAM_STATE_STOPPED.
231 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800232 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800233 * @return AAUDIO_OK or a negative error.
234 */
235AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream stream);
236
237/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800238 * Query the current state of the client, eg. AAUDIO_STREAM_STATE_PAUSING
Phil Burk5ed503c2017-02-01 09:38:15 -0800239 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800240 * This function will immediately return the state without updating the state.
241 * If you want to update the client state based on the server state then
242 * call AAudioStream_waitForStateChange() with currentState
243 * set to AAUDIO_STREAM_STATE_UNKNOWN and a zero timeout.
244 *
245 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800246 * @param state pointer to a variable that will be set to the current state
Phil Burk5ed503c2017-02-01 09:38:15 -0800247 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800248AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800249
250/**
251 * Wait until the current state no longer matches the input state.
252 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800253 * This will update the current client state.
254 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800255 * <pre><code>
256 * aaudio_stream_state_t currentState;
257 * aaudio_result_t result = AAudioStream_getState(stream, &currentState);
258 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSING) {
259 * result = AAudioStream_waitForStateChange(
260 * stream, currentState, &currentState, MY_TIMEOUT_NANOS);
261 * }
262 * </code></pre>
263 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800264 * @param stream A reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800265 * @param inputState The state we want to avoid.
266 * @param nextState Pointer to a variable that will be set to the new state.
267 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
268 * @return AAUDIO_OK or a negative error.
269 */
270AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream stream,
271 aaudio_stream_state_t inputState,
272 aaudio_stream_state_t *nextState,
Phil Burk3316d5e2017-02-15 11:23:01 -0800273 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800274
275// ============================================================
276// Stream I/O
277// ============================================================
278
279/**
280 * Read data from the stream.
281 *
282 * The call will wait until the read is complete or until it runs out of time.
283 * If timeoutNanos is zero then this call will not wait.
284 *
285 * Note that timeoutNanoseconds is a relative duration in wall clock time.
286 * Time will not stop if the thread is asleep.
287 * So it will be implemented using CLOCK_BOOTTIME.
288 *
289 * This call is "strong non-blocking" unless it has to wait for data.
290 *
291 * @param stream A stream created using AAudioStreamBuilder_openStream().
292 * @param buffer The address of the first sample.
293 * @param numFrames Number of frames to read. Only complete frames will be written.
294 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Phil Burk3316d5e2017-02-15 11:23:01 -0800295 * @return The number of frames actually read or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -0800296 */
297AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream stream,
298 void *buffer,
Phil Burk3316d5e2017-02-15 11:23:01 -0800299 int32_t numFrames,
300 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800301
302/**
303 * Write data to the stream.
304 *
305 * The call will wait until the write is complete or until it runs out of time.
306 * If timeoutNanos is zero then this call will not wait.
307 *
308 * Note that timeoutNanoseconds is a relative duration in wall clock time.
309 * Time will not stop if the thread is asleep.
310 * So it will be implemented using CLOCK_BOOTTIME.
311 *
312 * This call is "strong non-blocking" unless it has to wait for room in the buffer.
313 *
314 * @param stream A stream created using AAudioStreamBuilder_openStream().
315 * @param buffer The address of the first sample.
316 * @param numFrames Number of frames to write. Only complete frames will be written.
317 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
318 * @return The number of frames actually written or a negative error.
319 */
320AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream stream,
321 const void *buffer,
Phil Burk3316d5e2017-02-15 11:23:01 -0800322 int32_t numFrames,
323 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800324
325
326// ============================================================
327// High priority audio threads
328// ============================================================
329
330typedef void *(aaudio_audio_thread_proc_t)(void *);
331
332/**
333 * Create a thread associated with a stream. The thread has special properties for
334 * low latency audio performance. This thread can be used to implement a callback API.
335 *
336 * Only one thread may be associated with a stream.
337 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800338 * If you are using multiple streams then we recommend that you only do
339 * blocking reads or writes on one stream. You can do non-blocking I/O on the
340 * other streams by setting the timeout to zero.
341 * This thread should be created for the stream that you will block on.
342 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800343 * Note that this API is in flux.
344 *
345 * @param stream A stream created using AAudioStreamBuilder_openStream().
346 * @param periodNanoseconds the estimated period at which the audio thread will need to wake up
Glenn Kastenf26ad102017-01-12 09:14:45 -0800347 * @param threadProc your thread entry point
Phil Burk5ed503c2017-02-01 09:38:15 -0800348 * @param arg an argument that will be passed to your thread entry point
349 * @return AAUDIO_OK or a negative error.
350 */
351AAUDIO_API aaudio_result_t AAudioStream_createThread(AAudioStream stream,
Phil Burk3316d5e2017-02-15 11:23:01 -0800352 int64_t periodNanoseconds,
Phil Burk5ed503c2017-02-01 09:38:15 -0800353 aaudio_audio_thread_proc_t *threadProc,
354 void *arg);
355
356/**
357 * Wait until the thread exits or an error occurs.
Phil Burk5ed503c2017-02-01 09:38:15 -0800358 *
359 * @param stream A stream created using AAudioStreamBuilder_openStream().
360 * @param returnArg a pointer to a variable to receive the return value
361 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
362 * @return AAUDIO_OK or a negative error.
363 */
364AAUDIO_API aaudio_result_t AAudioStream_joinThread(AAudioStream stream,
365 void **returnArg,
Phil Burk3316d5e2017-02-15 11:23:01 -0800366 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800367
368// ============================================================
369// Stream - queries
370// ============================================================
371
372
373/**
374 * This can be used to adjust the latency of the buffer by changing
375 * the threshold where blocking will occur.
Phil Burk3316d5e2017-02-15 11:23:01 -0800376 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
Phil Burk5ed503c2017-02-01 09:38:15 -0800377 * at run-time for each device.
378 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800379 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
Phil Burk5ed503c2017-02-01 09:38:15 -0800380 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800381 * Note that you will probably not get the exact size you request.
382 * Call AAudioStream_getBufferSizeInFrames() to see what the actual final size is.
383 *
384 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800385 * @param requestedFrames requested number of frames that can be filled without blocking
Phil Burk3316d5e2017-02-15 11:23:01 -0800386 * @return actual buffer size in frames or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -0800387 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800388AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream stream,
389 int32_t requestedFrames);
Phil Burk5ed503c2017-02-01 09:38:15 -0800390
391/**
392 * Query the maximum number of frames that can be filled without blocking.
393 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800394 * @param stream reference provided by AAudioStreamBuilder_openStream()
395 * @return buffer size in frames.
Phil Burk5ed503c2017-02-01 09:38:15 -0800396 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800397AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800398
399/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800400 * Query the number of frames that the application should read or write at
401 * one time for optimal performance. It is OK if an application writes
402 * a different number of frames. But the buffer size may need to be larger
403 * in order to avoid underruns or overruns.
Phil Burk5ed503c2017-02-01 09:38:15 -0800404 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800405 * Note that this may or may not match the actual device burst size.
406 * For some endpoints, the burst size can vary dynamically.
407 * But these tend to be devices with high latency.
408 *
409 * @param stream reference provided by AAudioStreamBuilder_openStream()
410 * @return burst size
Phil Burk5ed503c2017-02-01 09:38:15 -0800411 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800412AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800413
414/**
415 * Query maximum buffer capacity in frames.
416 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800417 * @param stream reference provided by AAudioStreamBuilder_openStream()
418 * @return the buffer capacity in frames
Phil Burk5ed503c2017-02-01 09:38:15 -0800419 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800420AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800421
422/**
423 * An XRun is an Underrun or an Overrun.
424 * During playing, an underrun will occur if the stream is not written in time
425 * and the system runs out of valid data.
426 * During recording, an overrun will occur if the stream is not read in time
427 * and there is no place to put the incoming data so it is discarded.
428 *
429 * An underrun or overrun can cause an audible "pop" or "glitch".
430 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800431 * @param stream reference provided by AAudioStreamBuilder_openStream()
432 * @return the underrun or overrun count
Phil Burk5ed503c2017-02-01 09:38:15 -0800433 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800434AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800435
436/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800437 * @param stream reference provided by AAudioStreamBuilder_openStream()
438 * @return actual sample rate
Phil Burk5ed503c2017-02-01 09:38:15 -0800439 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800440AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800441
442/**
443 * The samplesPerFrame is also known as channelCount.
444 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800445 * @param stream reference provided by AAudioStreamBuilder_openStream()
446 * @return actual samples per frame
Phil Burk5ed503c2017-02-01 09:38:15 -0800447 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800448AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800449
450/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800451 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800452 * @param deviceId pointer to variable to receive the actual device ID
453 * @return AAUDIO_OK or a negative error.
454 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800455AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream stream,
456 int32_t *deviceId);
Phil Burk5ed503c2017-02-01 09:38:15 -0800457
458/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800459 * @param stream reference provided by AAudioStreamBuilder_openStream()
460 * @return actual data format
Phil Burk5ed503c2017-02-01 09:38:15 -0800461 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800462AAUDIO_API aaudio_audio_format_t AAudioStream_getFormat(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800463
464/**
465 * Provide actual sharing mode.
Phil Burk3316d5e2017-02-15 11:23:01 -0800466 * @param stream reference provided by AAudioStreamBuilder_openStream()
467 * @return actual sharing mode
Phil Burk5ed503c2017-02-01 09:38:15 -0800468 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800469AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800470
471/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800472 * @param stream reference provided by AAudioStreamBuilder_openStream()
473 * @return direction
Phil Burk5ed503c2017-02-01 09:38:15 -0800474 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800475AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800476
477/**
478 * Passes back the number of frames that have been written since the stream was created.
479 * For an output stream, this will be advanced by the application calling write().
Phil Burk3316d5e2017-02-15 11:23:01 -0800480 * For an input stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -0800481 *
482 * The frame position is monotonically increasing.
483 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800484 * @param stream reference provided by AAudioStreamBuilder_openStream()
485 * @return frames written
Phil Burk5ed503c2017-02-01 09:38:15 -0800486 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800487AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800488
489/**
490 * Passes back the number of frames that have been read since the stream was created.
Phil Burk3316d5e2017-02-15 11:23:01 -0800491 * For an output stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -0800492 * For an input stream, this will be advanced by the application calling read().
493 *
494 * The frame position is monotonically increasing.
495 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800496 * @param stream reference provided by AAudioStreamBuilder_openStream()
497 * @return frames read
Phil Burk5ed503c2017-02-01 09:38:15 -0800498 */
Phil Burk3316d5e2017-02-15 11:23:01 -0800499AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800500
501/**
502 * Passes back the time at which a particular frame was presented.
503 * This can be used to synchronize audio with video or MIDI.
504 * It can also be used to align a recorded stream with a playback stream.
505 *
506 * Timestamps are only valid when the stream is in AAUDIO_STREAM_STATE_STARTED.
507 * AAUDIO_ERROR_INVALID_STATE will be returned if the stream is not started.
508 * Note that because requestStart() is asynchronous, timestamps will not be valid until
509 * a short time after calling requestStart().
510 * So AAUDIO_ERROR_INVALID_STATE should not be considered a fatal error.
511 * Just try calling again later.
512 *
513 * If an error occurs, then the position and time will not be modified.
514 *
515 * The position and time passed back are monotonically increasing.
516 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800517 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800518 * @param clockid AAUDIO_CLOCK_MONOTONIC or AAUDIO_CLOCK_BOOTTIME
519 * @param framePosition pointer to a variable to receive the position
520 * @param timeNanoseconds pointer to a variable to receive the time
521 * @return AAUDIO_OK or a negative error
522 */
523AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream stream,
Phil Burk3316d5e2017-02-15 11:23:01 -0800524 clockid_t clockid,
525 int64_t *framePosition,
526 int64_t *timeNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800527
528#ifdef __cplusplus
529}
530#endif
531
532#endif //AAUDIO_AAUDIO_H