aaudio_sys/
lib.rs

1extern crate libc;
2
3use std::ffi::c_void;
4
5/// Low-level wrappers for AAudio API.
6
7pub enum AAudioStream {}
8pub enum AAudioStreamBuilder {}
9
10/// This is used to represent a value that has not been specified.
11/// For example, an application could use `UNSPECIFIED` to indicate
12/// that is did not not care what the specific value of a parameter was
13/// and would accept whatever it was given.
14pub const UNSPECIFIED: i32 = 0;
15
16pub const SESSION_ID_NONE: i32 = -1;
17pub const SESSION_ID_ALLOCATE: i32 = 0;
18
19pub const DIRECTION_OUTPUT: i32 = 0;
20pub const DIRECTION_INPUT: i32 = 0;
21
22pub const FORMAT_INVALID: i32 = -1;
23pub const FORMAT_PCM_I16: i32 = 1;
24pub const FORMAT_PCM_FLOAT: i32 = 2;
25
26pub const SHARING_EXCLUSIVE: i32 = 0;
27pub const SHARING_SHARED: i32 = 1;
28
29pub const USAGE_MEDIA: i32 = 1;
30pub const USAGE_VOICE_COMMUNICATION: i32 = 2;
31pub const USAGE_VOICE_COMMUNICATION_SIGNALLING: i32 = 3;
32pub const USAGE_ALARM: i32 = 4;
33pub const USAGE_NOTIFICATION: i32 = 5;
34pub const USAGE_NOTIFICATION_RINGTONE: i32 = 6;
35pub const USAGE_NOTIFICATION_EVENT: i32 = 10;
36pub const USAGE_ASSISTANCE_ACCESSIBILITY: i32 = 11;
37pub const USAGE_ASSISTANCE_NAVIGATION_GUIDANCE: i32 = 12;
38pub const USAGE_ASSISTANCE_SONIFICATION: i32 = 13;
39pub const USAGE_GAME: i32 = 14;
40pub const USAGE_ASSISTANT: i32 = 16;
41pub const USAGE_EMERGENCY: i32 = 1000;
42pub const USAGE_SAFETY: i32 = 1001;
43pub const USAGE_VEHICLE_STATUS: i32 = 1002;
44pub const USAGE_ANNOUNCEMENT: i32 = 1003;
45
46pub const INPUT_PRESET_GENERIC: i32 = 1;
47pub const INPUT_PRESET_CAMCORDER: i32 = 5;
48pub const INPUT_PRESET_VOICE_RECOGNITION: i32 = 6;
49pub const INPUT_PRESET_VOICE_COMMUNICATION: i32 = 7;
50pub const INPUT_PRESET_UNPROCESSED: i32 = 9;
51pub const INPUT_PRESET_VOICE_PERFORMANCE: i32 = 10;
52
53pub const CONTENT_TYPE_SPEECH: i32 = 1;
54pub const CONTENT_TYPE_MUSIC: i32 = 2;
55pub const CONTENT_TYPE_MOVIE: i32 = 3;
56pub const CONTENT_TYPE_SONIFICATION: i32 = 4;
57
58pub const ALLOW_CAPTURE_BY_ALL: i32 = 1;
59pub const ALLOW_CAPTURE_BY_SYSTEM: i32 = 2;
60pub const ALLOW_CAPTURE_BY_NONE: i32 = 3;
61
62pub const CALLBACK_CONTINUE: i32 = 0;
63pub const CALLBACK_STOP: i32 = 1;
64
65pub const PERFORMANCE_MODE_NONE: i32 = 10;
66pub const PERFORMANCE_MODE_POWER_SAVING: i32 = 11;
67pub const PERFORMANCE_MODE_LOW_LATENCY: i32 = 12;
68
69pub const STREAM_STATE_UNINITIALIZED: i32 = 0;
70pub const STREAM_STATE_UNKNOWN: i32 = 1;
71pub const STREAM_STATE_OPEN: i32 = 2;
72pub const STREAM_STATE_STARTING: i32 = 3;
73pub const STREAM_STATE_STARTED: i32 = 4;
74pub const STREAM_STATE_PAUSING: i32 = 5;
75pub const STREAM_STATE_PAUSED: i32 = 6;
76pub const STREAM_STATE_FLUSHING: i32 = 7;
77pub const STREAM_STATE_FLUSHED: i32 = 8;
78pub const STREAM_STATE_STOPPING: i32 = 9;
79pub const STREAM_STATE_STOPPED: i32 = 10;
80pub const STREAM_STATE_CLOSING: i32 = 11;
81pub const STREAM_STATE_CLOSED: i32 = 12;
82pub const STREAM_STATE_DISCONNECTED: i32 = 13;
83
84pub const OK: i32 = 0;
85
86const ERROR_BASE: i32 = -900;
87
88/// The audio device was disconnected. This could occur, for example, when headphones
89/// are plugged in or unplugged. The stream cannot be used after the device is disconnected.
90/// Applications should stop and close the stream.
91/// If this error is received in an error callback then another thread should be
92/// used to stop and close the stream.
93pub const ERROR_DISCONNECTED: i32 = ERROR_BASE + 1;
94
95/// An invalid parameter was passed to AAudio.
96pub const ERROR_ILLEGAL_ARGUMENT: i32 = ERROR_BASE + 2;
97
98pub const ERROR_INTERNAL: i32 = ERROR_ILLEGAL_ARGUMENT + 2;
99
100/// The requested operation is not appropriate for the current state of AAudio.
101pub const ERROR_INVALID_STATE: i32 = ERROR_INTERNAL + 1;
102
103/// The server rejected the handle used to identify the stream.
104pub const ERROR_INVALID_HANDLE: i32 = ERROR_INVALID_STATE + 3;
105
106/// The function is not implemented for this stream.
107pub const ERROR_UNIMPLEMENTED: i32 = ERROR_INVALID_HANDLE + 2;
108
109/// A resource or information is unavailable.
110/// This could occur when an application tries to open too many streams,
111/// or a timestamp is not available.
112pub const ERROR_UNAVAILABLE: i32 = ERROR_UNIMPLEMENTED + 1;
113pub const ERROR_NO_FREE_HANDLES: i32 = ERROR_UNIMPLEMENTED + 2;
114
115/// Memory could not be allocated.
116pub const ERROR_NO_MEMORY: i32 = ERROR_UNIMPLEMENTED + 3;
117
118/// A NULL pointer was passed to AAudio.
119/// Or a NULL pointer was detected internally.
120pub const ERROR_NULL: i32 = ERROR_UNIMPLEMENTED + 4;
121
122/// An operation took longer than expected.
123pub const ERROR_TIMEOUT: i32 = ERROR_UNIMPLEMENTED + 5;
124pub const ERROR_WOULD_BLOCK: i32 = ERROR_UNIMPLEMENTED + 6;
125
126/// The requested data format is not supported.
127pub const ERROR_INVALID_FORMAT: i32 = ERROR_UNIMPLEMENTED + 7;
128
129/// A requested was out of range.
130pub const ERROR_OUT_OF_RANGE: i32 = ERROR_UNIMPLEMENTED + 8;
131
132/// The audio service was not available.
133pub const ERROR_NO_SERVICE: i32 = ERROR_UNIMPLEMENTED + 9;
134
135/// The requested sample rate was not supported.
136pub const ERROR_INVALID_RATE: i32 = ERROR_UNIMPLEMENTED + 10;
137
138/// Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
139///
140/// For an output stream, this function should render and write numFrames of data
141/// in the streams current data format to the audioData buffer.
142///
143/// For an input stream, this function should read and process numFrames of data
144/// from the audioData buffer.
145///
146/// The audio data is passed through the buffer. So do NOT call AAudioStream_read() or
147/// AAudioStream_write() on the stream that is making the callback.
148///
149/// Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback()
150/// is called.
151///
152/// Also note that this callback function should be considered a "real-time" function.
153/// It must not do anything that could cause an unbounded delay because that can cause the
154/// audio to glitch or pop.
155///
156/// These are things the function should NOT do:
157/// * allocate memory using, for example, malloc() or new
158/// * any file operations such as opening, closing, reading or writing
159/// * any network operations such as streaming
160/// * use any mutexes or other synchronization primitives
161/// * sleep
162/// * stop or close the stream
163/// * AAudioStream_read()
164/// * AAudioStream_write()
165///
166/// The following are OK to call from the data callback:
167/// * `AAudioStream_get*()`
168/// * AAudio_convertResultToText()
169///
170/// If you need to move data, eg. MIDI commands, in or out of the callback function then
171/// we recommend the use of non-blocking techniques such as an atomic FIFO.
172///
173/// * `stream` - reference provided by AAudioStreamBuilder_openStream()
174/// * `user_data` - the same address that was passed to AAudioStreamBuilder_setCallback()
175/// * `audio_data` - a pointer to the audio data
176/// * `num_frames` - the number of frames to be processed, which can vary
177///
178/// Returns CallbackResult (Continue = 0, Stop = 1)
179pub type DataCallback = Option<
180    unsafe extern "C" fn(
181        stream: *mut AAudioStream,
182        user_data: *mut c_void,
183        audio_data: *mut c_void,
184        num_frames: i32,
185    ) -> i32,
186>;
187
188/// Prototype for the callback function that is passed to
189/// AAudioStreamBuilder_setErrorCallback().
190///
191/// The following may NOT be called from the error callback:
192/// * AAudioStream_requestStop()
193/// * AAudioStream_requestPause()
194/// * AAudioStream_close()
195/// * AAudioStream_waitForStateChange()
196/// * AAudioStream_read()
197/// * AAudioStream_write()
198///
199/// The following are OK to call from the error callback:
200/// * AAudioStream_get*()
201/// * AAudio_convertResultToText()
202///
203/// * `stream` - reference provided by AAudioStreamBuilder_openStream()
204/// * `user_data` - the same address that was passed to AAudioStreamBuilder_setErrorCallback()
205/// * `error` - an AAUDIO_ERROR_* value.
206pub type ErrorCallback =
207    Option<unsafe extern "C" fn(stream: *mut AAudioStream, user_data: *mut c_void, error: i32)>;
208
209#[link(name = "aaudio")]
210extern "C" {
211    /// Create a StreamBuilder that can be used to open a Stream.
212    ///
213    /// The deviceId is initially unspecified, meaning that the current default device will be used.
214    ///
215    /// The default direction is `DIRECTION_OUTPUT`.
216    /// The default sharing mode is `SHARING_MODE_SHARED`.
217    /// The data format, samplesPerFrames and sampleRate are unspecified and will be
218    /// chosen by the device when it is opened.
219    ///
220    /// AAudioStreamBuilder_delete() must be called when you are done using the builder.
221    ///
222    /// Available since API level 26.
223    pub fn AAudio_createStreamBuilder(builder: *mut *mut AAudioStreamBuilder) -> i32;
224
225    /// Request an audio device identified device using an ID.
226    /// On Android, for example, the ID could be obtained from the Java AudioManager.
227    ///
228    /// The default, if you do not call this function, is `UNSPECIFIED`,
229    /// in which case the primary device will be used.
230    ///
231    /// Available since API level 26.
232    ///
233    /// # Arguments
234    ///
235    /// * `builder` - reference provided by AAudio_createStreamBuilder()
236    /// * `device_id` - device identifier or `UNSPECIFIED`
237    pub fn AAudioStreamBuilder_setDeviceId(builder: *mut AAudioStreamBuilder, device_id: i32);
238
239    /// Request a sample rate in Hertz.
240    ///
241    /// The default, if you do not call this function, is `UNSPECIFIED`.
242    /// An optimal value will then be chosen when the stream is opened.
243    /// After opening a stream with an unspecified value, the application must
244    /// query for the actual value, which may vary by device.
245    ///
246    /// If an exact value is specified then an opened stream will use that value.
247    /// If a stream cannot be opened with the specified value then the open will fail.
248    ///
249    /// Available since API level 26.
250    ///
251    /// # Arguments
252    ///
253    /// * `builder` - reference provided by AAudio_createStreamBuilder()
254    /// * `sample_rate` - frames per second. Common rates include 44100 and 48000 Hz.
255    pub fn AAudioStreamBuilder_setSampleRate(builder: *mut AAudioStreamBuilder, sample_rate: i32);
256
257    /// Request a number of channels for the stream.
258    ///
259    /// The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
260    /// An optimal value will then be chosen when the stream is opened.
261    /// After opening a stream with an unspecified value, the application must
262    /// query for the actual value, which may vary by device.
263    ///
264    /// If an exact value is specified then an opened stream will use that value.
265    /// If a stream cannot be opened with the specified value then the open will fail.
266    ///
267    /// Available since API level 26.
268    ///
269    /// # Arguments
270    ///
271    /// * `builder` - reference provided by AAudio_createStreamBuilder()
272    /// * `channel_count` - Number of channels desired.
273    pub fn AAudioStreamBuilder_setChannelCount(
274        builder: *mut AAudioStreamBuilder,
275        channel_count: i32,
276    );
277
278    /// Request a sample data format, for example `FORMAT_PCM_I16`.
279    ///
280    /// The default, if you do not call this function, is `UNSPECIFIED`.
281    /// An optimal value will then be chosen when the stream is opened.
282    /// After opening a stream with an unspecified value, the application must
283    /// query for the actual value, which may vary by device.
284    ///
285    /// If an exact value is specified then an opened stream will use that value.
286    /// If a stream cannot be opened with the specified value then the open will fail.
287    ///
288    /// Available since API level 26.
289    ///
290    /// # Arguments
291    ///
292    /// * `builder` - reference provided by AAudio_createStreamBuilder()
293    /// * `format` - the sample data format.
294    pub fn AAudioStreamBuilder_setFormat(builder: *mut AAudioStreamBuilder, format: i32);
295
296    /// Request a mode for sharing the device.
297    ///
298    /// The default, if you do not call this function, is `SHARING_MODE_SHARED`.
299    ///
300    /// The requested sharing mode may not be available.
301    /// The application can query for the actual mode after the stream is opened.
302    ///
303    /// Available since API level 26.
304    ///
305    /// # Arguments
306    ///
307    /// * `builder` - reference provided by AAudio_createStreamBuilder()
308    /// * `sharing_mode` - `SHARING_MODE_SHARED` or `SHARING_MODE_EXCLUSIVE`
309    pub fn AAudioStreamBuilder_setSharingMode(builder: *mut AAudioStreamBuilder, sharing_mode: i32);
310
311    /// Request the direction for a stream.
312    ///
313    /// The default, if you do not call this function, is Output.
314    ///
315    /// Available since API level 26.
316    ///
317    /// # Arguments
318    ///
319    /// * `builder` - reference provided by AAudio_createStreamBuilder()
320    /// * `direction` - `DIRECTION_OUTPUT` or `DIRECTION_INPUT`
321    pub fn AAudioStreamBuilder_setDirection(builder: *mut AAudioStreamBuilder, direction: i32);
322
323    /// Set the requested buffer capacity in frames.
324    /// The final AAudioStream capacity may differ, but will probably be at least this big.
325    ///
326    /// The default, if you do not call this function, is `UNSPECIFIED`.
327    ///
328    /// Available since API level 26.
329    ///
330    /// # Arguments
331    ///
332    /// * `builder` - reference provided by AAudio_createStreamBuilder()
333    /// * `numFrames` - the desired buffer capacity in frames or `UNSPECIFIED`
334    pub fn AAudioStreamBuilder_setBufferCapacityInFrames(
335        builder: *mut AAudioStreamBuilder,
336        num_frames: i32,
337    );
338
339    /// Set the requested performance mode.
340    ///
341    /// Supported modes are None, PowerSaving and LowLatency.
342    ///
343    /// The default, if you do not call this function, is None.
344    ///
345    /// You may not get the mode you requested.
346    /// You can call AAudioStream_getPerformanceMode()
347    /// to find out the final mode for the stream.
348    ///
349    /// Available since API level 26.
350    ///
351    /// # Arguments
352    ///
353    /// * `builder` - reference provided by AAudio_createStreamBuilder()
354    /// * `mode` - the desired performance mode, eg. LowLatency
355    pub fn AAudioStreamBuilder_setPerformanceMode(builder: *mut AAudioStreamBuilder, mode: i32);
356
357    /// Set the intended use case for the stream.
358    ///
359    /// The AAudio system will use this information to optimize the
360    /// behavior of the stream.
361    /// This could, for example, affect how volume and focus is handled for the stream.
362    ///
363    /// The default, if you do not call this function, is Media.
364    ///
365    /// Available since API level 28.
366    ///
367    /// * `builder` - reference provided by AAudio_createStreamBuilder()
368    /// * `usage` - the desired usage, eg. Game
369    pub fn AAudioStreamBuilder_setUsage(builder: *mut AAudioStreamBuilder, usage: i32);
370
371    /// Set the type of audio data that the stream will carry.
372    ///
373    /// The AAudio system will use this information to optimize the
374    /// behavior of the stream.
375    /// This could, for example, affect whether a stream is paused when a notification occurs.
376    ///
377    /// The default, if you do not call this function, is Music.
378    ///
379    /// Available since API level 28.
380    ///
381    /// # Arguments
382    ///
383    /// * `builder` - reference provided by AAudio_createStreamBuilder()
384    /// * `content_type` - the type of audio data, eg. Speech
385    pub fn AAudioStreamBuilder_setContentType(builder: *mut AAudioStreamBuilder, content_type: i32);
386
387    /// Set the input (capture) preset for the stream.
388    ///
389    /// The AAudio system will use this information to optimize the
390    /// behavior of the stream.
391    /// This could, for example, affect which microphones are used and how the
392    /// recorded data is processed.
393    ///
394    /// The default, if you do not call this function, is VoiceRecognition.
395    /// That is because VoiceRecognition is the preset with the lowest latency
396    /// on many platforms.
397    ///
398    /// Available since API level 28.
399    ///
400    /// # Arguments
401    ///
402    /// * `builder` - reference provided by AAudio_createStreamBuilder()
403    /// * `input_preset` - the desired configuration for recording
404    pub fn AAudioStreamBuilder_setInputPreset(builder: *mut AAudioStreamBuilder, input_preset: i32);
405
406    /// Specify whether this stream audio may or may not be captured by other apps or the system.
407    ///
408    /// The default is AllowCaptureByAll.
409    ///
410    /// Note that an application can also set its global policy, in which case the most restrictive
411    /// policy is always applied. See android.media.AudioAttributes#setAllowedCapturePolicy(int)
412    ///
413    /// Available since API level 29.
414    ///
415    /// `builder` - reference provided by AAudio_createStreamBuilder()
416    /// `capturePolicy` - the desired level of opt-out from being captured.
417    pub fn AAudioStreamBuilder_setAllowedCapturePolicy(
418        builder: *mut AAudioStreamBuilder,
419        capture_policy: i32,
420    );
421
422    /// The session ID can be used to associate a stream with effects processors.
423    /// The effects are controlled using the Android AudioEffect Java API.
424    ///
425    /// The default, if you do not call this function, is `SESSION_ID_NONE`.
426    ///
427    /// If set to `SESSION_ID_ALLOCATE` then a session ID will be allocated
428    /// when the stream is opened.
429    ///
430    /// The allocated session ID can be obtained by calling AAudioStream_getSessionId()
431    /// and then used with this function when opening another stream.
432    /// This allows effects to be shared between streams.
433    ///
434    /// Session IDs from AAudio can be used with the Android Java APIs and vice versa.
435    /// So a session ID from an AAudio stream can be passed to Java
436    /// and effects applied using the Java AudioEffect API.
437    ///
438    /// Note that allocating or setting a session ID may result in a stream with higher latency.
439    ///
440    /// Allocated session IDs will always be positive and nonzero.
441    ///
442    /// Available since API level 28.
443    ///
444    /// # Arguments
445    ///
446    /// * `builder` - reference provided by AAudio_createStreamBuilder()
447    /// * `session_id` - an allocated sessionID or `SESSION_ID_ALLOCATE`
448    pub fn AAudioStreamBuilder_setSessionId(builder: *mut AAudioStreamBuilder, session_id: i32);
449
450    /// Indicates whether this input stream must be marked as privacy sensitive or not.
451    ///
452    /// When true, this input stream is privacy sensitive and any concurrent capture
453    /// is not permitted.
454    ///
455    /// This is off (false) by default except when the input preset is `VoiceCommunication`
456    /// or `Camcorder`.
457    ///
458    /// Always takes precedence over default from input preset when set explicitly.
459    ///
460    /// Only relevant if the stream direction is `Input`.
461    ///
462    /// Added in API level 30.
463    ///
464    /// # Arguments
465    ///
466    /// * `builder` - reference provided by AAudio_createStreamBuilder()
467    /// * `privacy_sensitive` - true if capture from this stream must be marked as privacy sensitive, false otherwise.
468    pub fn AAudioStreamBuilder_setPrivacySensitive(
469        builder: *mut AAudioStreamBuilder,
470        privacy_sensitive: bool,
471    );
472
473    /// Request that AAudio call this functions when the stream is running.
474    ///
475    /// Note that when using this callback, the audio data will be passed in or out
476    /// of the function as an argument.
477    /// So you cannot call AAudioStream_write() or AAudioStream_read()
478    /// on the same stream that has an active data callback.
479    ///
480    /// The callback function will start being called after AAudioStream_requestStart()
481    /// is called.
482    /// It will stop being called after AAudioStream_requestPause() or
483    /// AAudioStream_requestStop() is called.
484    ///
485    /// This callback function will be called on a real-time thread owned by AAudio. See
486    /// `DataCallback` for more information.
487    ///
488    /// Note that the AAudio callbacks will never be called simultaneously from multiple threads.
489    ///
490    /// Available since API level 26.
491    ///
492    /// * `builder` - reference provided by AAudio_createStreamBuilder()
493    /// * `callback` - pointer to a function that will process audio data.
494    /// * `user_data` - pointer to an application data structure that will be passed
495    ///          to the callback functions.
496    pub fn AAudioStreamBuilder_setDataCallback(
497        builder: *mut AAudioStreamBuilder,
498        callback: DataCallback,
499        user_data: *mut c_void,
500    );
501
502    /// Set the requested data callback buffer size in frames.
503    /// See `DataCallback`.
504    ///
505    /// The default, if you do not call this function, is `Unspecified`.
506    ///
507    /// For the lowest possible latency, do not call this function. AAudio will then
508    /// call the dataProc callback function with whatever size is optimal.
509    /// That size may vary from one callback to another.
510    ///
511    /// Only use this function if the application requires a specific number of frames for processing.
512    /// The application might, for example, be using an FFT that requires
513    /// a specific power-of-two sized buffer.
514    ///
515    /// AAudio may need to add additional buffering in order to adapt between the internal
516    /// buffer size and the requested buffer size.
517    ///
518    /// If you do call this function then the requested size should be less than
519    /// half the buffer capacity, to allow double buffering.
520    ///
521    /// Available since API level 26.
522    ///
523    /// * `builder` - reference provided by AAudio_createStreamBuilder()
524    /// * `num_frames` - the desired buffer size in frames or `Unspecified`
525    pub fn AAudioStreamBuilder_setFramesPerDataCallback(
526        builder: *mut AAudioStreamBuilder,
527        num_frames: i32,
528    );
529
530    /// Request that AAudio call this function if any error occurs or the stream is disconnected.
531    ///
532    /// It will be called, for example, if a headset or a USB device is unplugged causing the stream's
533    /// device to be unavailable or "disconnected".
534    /// Another possible cause of error would be a timeout or an unanticipated internal error.
535    ///
536    /// In response, this function should signal or create another thread to stop
537    /// and close this stream. The other thread could then reopen a stream on another device.
538    /// Do not stop or close the stream, or reopen the new stream, directly from this callback.
539    ///
540    /// This callback will not be called because of actions by the application, such as stopping
541    /// or closing a stream.
542    ///
543    /// Note that the AAudio callbacks will never be called simultaneously from multiple threads.
544    ///
545    /// Available since API level 26.
546    ///
547    /// # Arguments
548    ///
549    /// * `builder` - reference provided by AAudio_createStreamBuilder()
550    /// * `callback` - pointer to a function that will be called if an error occurs.
551    /// * `user_data` - pointer to an application data structure that will be passed
552    ///          to the callback functions.
553    pub fn AAudioStreamBuilder_setErrorCallback(
554        builder: *mut AAudioStreamBuilder,
555        callback: ErrorCallback,
556        user_data: *mut c_void,
557    );
558
559    /// Open a stream based on the options in the StreamBuilder.
560    /// Returns 0 for OK or a negative error.
561    ///
562    /// AAudioStream_close() must be called when finished with the stream to recover
563    /// the memory and to free the associated resources.
564    ///
565    /// Available since API level 26.
566    ///
567    /// # Arguments
568    ///
569    /// * `builder` - reference provided by AAudio_createStreamBuilder()
570    /// * `stream` - pointer to a variable to receive the new stream reference
571    pub fn AAudioStreamBuilder_openStream(
572        builder: *mut AAudioStreamBuilder,
573        stream: *mut *mut AAudioStream,
574    ) -> i32;
575
576    /// Delete the resources associated with the StreamBuilder.
577    /// Returns 0 for OK or a negative error.
578    ///
579    /// Available since API level 26.
580    ///
581    /// # Arguments
582    ///
583    /// * `builder` - reference provided by AAudio_createStreamBuilder()
584    /// @return 0 for OK or a negative error.
585    pub fn AAudioStreamBuilder_delete(builder: *mut AAudioStreamBuilder) -> i32;
586
587    /// Free the audio resources associated with a stream created by
588    /// AAudioStreamBuilder_openStream().
589    /// AAudioStream_close() should be called at some point after calling
590    /// this function.
591    ///
592    /// Returns 0 for OK or a negative error.
593    ///
594    /// After this call, the stream will be in Closing state
595    ///
596    /// This function is useful if you want to release the audio resources immediately,
597    /// but still allow queries to the stream to occur from other threads. This often
598    /// happens if you are monitoring stream progress from a UI thread.
599    ///
600    /// Available since API level 30.
601    ///
602    /// # Arguments
603    ///
604    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
605    pub fn AAudioStream_release(stream: *mut AAudioStream) -> i32;
606
607    /// Delete the internal data structures associated with the stream created
608    /// by AAudioStreamBuilder_openStream().
609    ///
610    /// Returns 0 for OK or a negative error.
611    ///
612    /// If AAudioStream_release() has not been called then it will be called automatically.
613    ///
614    /// # Arguments
615    ///
616    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
617    pub fn AAudioStream_close(stream: *mut AAudioStream) -> i32;
618
619    /// Asynchronously request to start playing the stream. For output streams, one should
620    /// write to the stream to fill the buffer before starting.
621    /// Otherwise it will underflow.
622    /// After this call the state will be in `Starting` or `Started`.
623    ///
624    /// Returns 0 for OK or a negative error.
625    ///
626    /// Available since API level 26.
627    ///
628    /// # Arguments
629    ///
630    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
631    pub fn AAudioStream_requestStart(stream: *mut AAudioStream) -> i32;
632
633    /// Asynchronous request for the stream to pause.
634    /// Pausing a stream will freeze the data flow but not flush any buffers.
635    /// Use AAudioStream_requestStart() to resume playback after a pause.
636    /// After this call the state will be in `Pausing` or
637    /// `Paused`.
638    ///
639    /// Returns 0 for OK or a negative error.
640    ///
641    /// This will return `Unimplemented` for input streams.
642    /// For input streams use AAudioStream_requestStop().
643    ///
644    /// Available since API level 26.
645    ///
646    /// # Arguments
647    ///
648    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
649    pub fn AAudioStream_requestPause(stream: *mut AAudioStream) -> i32;
650
651    /// Asynchronous request for the stream to flush.
652    /// Flushing will discard any pending data.
653    /// This call only works if the stream is pausing or paused.
654    /// Frame counters are not reset by a flush. They may be advanced.
655    /// After this call the state will be in `Flushing` or `Flushed`.
656    ///
657    /// Returns 0 for OK or a negative error.
658    ///
659    /// This will return `Unimplemented` for input streams.
660    ///
661    /// Available since API level 26.
662    ///
663    /// # Arguments
664    ///
665    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
666    pub fn AAudioStream_requestFlush(stream: *mut AAudioStream) -> i32;
667
668    /// Asynchronous request for the stream to stop.
669    /// The stream will stop after all of the data currently buffered has been played.
670    /// After this call the state will be in `Stopping` or `Stopped`.
671    ///
672    /// Returns 0 for OK or a negative error.
673    ///
674    /// Available since API level 26.
675    ///
676    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
677    pub fn AAudioStream_requestStop(stream: *mut AAudioStream) -> i32;
678
679    /// Query the current state of the client, eg. `Pausing`.
680    ///
681    /// This function will immediately return the state without updating the state.
682    /// If you want to update the client state based on the server state then
683    /// call AAudioStream_waitForStateChange() with currentState
684    /// set to `Unknown` and a zero timeout.
685    ///
686    /// Available since API level 26.
687    ///
688    /// # Arguments
689    ///
690    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
691    pub fn AAudioStream_getState(stream: *mut AAudioStream) -> i32;
692
693    /// Wait until the current state no longer matches the input state.
694    ///
695    /// Returns 0 for OK or a negative error.
696    ///
697    /// This will update the current client state.
698    ///
699    /// Available since API level 26.
700    ///
701    /// # Arguments
702    ///
703    /// * `stream` - A reference provided by AAudioStreamBuilder_openStream()
704    /// * `input_state` - The state we want to avoid.
705    /// * `next_state` - Pointer to a variable that will be set to the new state.
706    /// * `timeout_nanoseconds` - Maximum number of nanoseconds to wait for completion.
707    pub fn AAudioStream_waitForStateChange(
708        stream: *mut AAudioStream,
709        input_state: i32,
710        next_state: *mut i32,
711        timeout_nanoseconds: i64,
712    ) -> i32;
713
714    /// Read data from the stream.
715    /// Returns the number of frames actually read or a negative error.
716    ///
717    /// The call will wait until the read is complete or until it runs out of time.
718    /// If timeoutNanos is zero then this call will not wait.
719    ///
720    /// Note that timeoutNanoseconds is a relative duration in wall clock time.
721    /// Time will not stop if the thread is asleep.
722    /// So it will be implemented using CLOCK_BOOTTIME.
723    ///
724    /// This call is "strong non-blocking" unless it has to wait for data.
725    ///
726    /// If the call times out then zero or a partial frame count will be returned.
727    ///
728    /// Available since API level 26.
729    ///
730    /// # Arguments
731    ///
732    /// * `stream` - A stream created using AAudioStreamBuilder_openStream().
733    /// * `buffer` - The address of the first sample.
734    /// * `num_frames` - Number of frames to read. Only complete frames will be written.
735    /// * `timeout_nanoseconds` - Maximum number of nanoseconds to wait for completion.
736    pub fn AAudioStream_read(
737        stream: *mut AAudioStream,
738        buffer: *mut c_void,
739        num_frames: i32,
740        timeout_nanoseconds: i64,
741    ) -> i32;
742
743    /// Write data to the stream.
744    /// Returns the number of frames actually written or a negative error.
745    ///
746    /// The call will wait until the write is complete or until it runs out of time.
747    /// If timeoutNanos is zero then this call will not wait.
748    ///
749    /// Note that timeoutNanoseconds is a relative duration in wall clock time.
750    /// Time will not stop if the thread is asleep.
751    /// So it will be implemented using CLOCK_BOOTTIME.
752    ///
753    /// This call is "strong non-blocking" unless it has to wait for room in the buffer.
754    ///
755    /// If the call times out then zero or a partial frame count will be returned.
756    ///
757    /// Available since API level 26.
758    ///
759    /// # Arguments
760    ///
761    /// * `stream` - A stream created using AAudioStreamBuilder_openStream().
762    /// * `buffer` - The address of the first sample.
763    /// * `num_frames` - Number of frames to write. Only complete frames will be written.
764    /// * `timeout_nanoseconds` - Maximum number of nanoseconds to wait for completion.
765    pub fn AAudioStream_write(
766        stream: *mut AAudioStream,
767        buffer: *const c_void,
768        num_frames: i32,
769        timeout_nanoseconds: i64,
770    ) -> i32;
771
772    /// This can be used to adjust the latency of the buffer by changing
773    /// the threshold where blocking will occur.
774    /// By combining this with AAudioStream_getXRunCount(), the latency can be tuned
775    /// at run-time for each device.
776    /// Returns actual buffer size in frames or a negative error.
777    ///
778    /// This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
779    ///
780    /// Note that you will probably not get the exact size you request.
781    /// You can check the return value or call AAudioStream_getBufferSizeInFrames()
782    /// to see what the actual final size is.
783    ///
784    /// Available since API level 26.
785    ///
786    /// # Arguments
787    ///
788    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
789    /// * `num_frames` - requested number of frames that can be filled without blocking
790    pub fn AAudioStream_setBufferSizeInFrames(stream: *mut AAudioStream, num_frames: i32) -> i32;
791
792    /// Query the maximum number of frames that can be filled without blocking.
793    ///
794    /// Available since API level 26.
795    ///
796    /// Stream reference provided by AAudioStreamBuilder_openStream()
797    pub fn AAudioStream_getBufferSizeInFrames(stream: *mut AAudioStream) -> i32;
798
799    /// Query the number of frames that the application should read or write at
800    /// one time for optimal performance. It is OK if an application writes
801    /// a different number of frames. But the buffer size may need to be larger
802    /// in order to avoid underruns or overruns.
803    ///
804    /// Note that this may or may not match the actual device burst size.
805    /// For some endpoints, the burst size can vary dynamically.
806    /// But these tend to be devices with high latency.
807    ///
808    /// Available since API level 26.
809    ///
810    /// # Arguments
811    ///
812    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
813    pub fn AAudioStream_getFramesPerBurst(stream: *mut AAudioStream) -> i32;
814
815    /// Query maximum buffer capacity in frames.
816    ///
817    /// Available since API level 26.
818    ///
819    /// # Arguments
820    ///
821    /// @param stream reference provided by AAudioStreamBuilder_openStream()
822    pub fn AAudioStream_getBufferCapacityInFrames(stream: *mut AAudioStream) -> i32;
823
824    /// Query the size of the buffer that will be passed to the dataProc callback
825    /// in the numFrames parameter.
826    ///
827    /// This call can be used if the application needs to know the value of numFrames before
828    /// the stream is started. This is not normally necessary.
829    ///
830    /// If a specific size was requested by calling
831    /// AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size.
832    ///
833    /// If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will
834    /// return the size chosen by AAudio, or `UNSPECIFIED`.
835    ///
836    /// `UNSPECIFIED` indicates that the callback buffer size for this stream
837    /// may vary from one dataProc callback to the next.
838    ///
839    /// Available since API level 26.
840    ///
841    /// # Arguments
842    ///
843    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
844    pub fn AAudioStream_getFramesPerDataCallback(stream: *mut AAudioStream) -> i32;
845
846    /// An XRun is an Underrun or an Overrun.
847    /// During playing, an underrun will occur if the stream is not written in time
848    /// and the system runs out of valid data.
849    /// During recording, an overrun will occur if the stream is not read in time
850    /// and there is no place to put the incoming data so it is discarded.
851    ///
852    /// An underrun or overrun can cause an audible "pop" or "glitch".
853    ///
854    /// Note that some INPUT devices may not support this function.
855    /// In that case a 0 will always be returned.
856    ///
857    /// Available since API level 26.
858    ///
859    /// # Arguments
860    ///
861    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
862    pub fn AAudioStream_getXRunCount(stream: *mut AAudioStream) -> i32;
863
864    /// Available since API level 26.
865    /// Returns the actual sample rate.
866    ///
867    /// # Arguments
868    ///
869    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
870    pub fn AAudioStream_getSampleRate(stream: *mut AAudioStream) -> i32;
871
872    /// A stream has one or more channels of data.
873    /// A frame will contain one sample for each channel.
874    ///
875    /// Available since API level 26.
876    ///
877    /// # Arguments
878    ///
879    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
880    pub fn AAudioStream_getChannelCount(stream: *mut AAudioStream) -> i32;
881
882    /// Available since API level 26.
883    /// Returns the actual device ID.
884    ///
885    /// # Arguments
886    ///
887    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
888    pub fn AAudioStream_getDeviceId(stream: *mut AAudioStream) -> i32;
889
890    /// Available since API level 26.
891    /// Returns the actual data format.
892    ///
893    /// # Arguments
894    ///
895    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
896    pub fn AAudioStream_getFormat(stream: *mut AAudioStream) -> i32;
897
898    /// Provide actual sharing mode.
899    ///
900    /// Available since API level 26.
901    ///
902    /// # Arguments
903    ///
904    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
905    pub fn AAudioStream_getSharingMode(stream: *mut AAudioStream) -> i32;
906
907    /// Get the performance mode used by the stream.
908    ///
909    /// Available since API level 26.
910    ///
911    /// # Arguments
912    ///
913    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
914    pub fn AAudioStream_getPerformanceMode(stream: *mut AAudioStream) -> i32;
915
916    /// Available since API level 26.
917    ///
918    /// # Arguments
919    ///
920    /// `stream` - reference provided by AAudioStreamBuilder_openStream()
921    pub fn AAudioStream_getDirection(stream: *mut AAudioStream) -> i32;
922
923    /// Passes back the number of frames that have been written since the stream was created.
924    /// For an output stream, this will be advanced by the application calling write()
925    /// or by a data callback.
926    /// For an input stream, this will be advanced by the endpoint.
927    ///
928    /// The frame position is monotonically increasing.
929    ///
930    /// Available since API level 26.
931    ///
932    /// # Arguments
933    ///
934    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
935    pub fn AAudioStream_getFramesWritten(stream: *mut AAudioStream) -> i64;
936
937    /// Passes back the number of frames that have been read since the stream was created.
938    /// For an output stream, this will be advanced by the endpoint.
939    /// For an input stream, this will be advanced by the application calling read()
940    /// or by a data callback.
941    ///
942    /// The frame position is monotonically increasing.
943    ///
944    /// Available since API level 26.
945    ///
946    /// # Arguments
947    ///
948    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
949    pub fn AAudioStream_getFramesRead(stream: *mut AAudioStream) -> i64;
950
951    /// Passes back the session ID associated with this stream.
952    ///
953    /// The session ID can be used to associate a stream with effects processors.
954    /// The effects are controlled using the Android AudioEffect Java API.
955    ///
956    /// If AAudioStreamBuilder_setSessionId() was called with `SESSION_ID_ALLOCATE`
957    /// then a new session ID should be allocated once when the stream is opened.
958    ///
959    /// If AAudioStreamBuilder_setSessionId() was called with a previously allocated
960    /// session ID then that value should be returned.
961    ///
962    /// If AAudioStreamBuilder_setSessionId() was not called then this function should
963    /// return `SESSION_ID_NONE`.
964    ///
965    /// The sessionID for a stream should not change once the stream has been opened.
966    ///
967    /// Available since API level 28.
968    ///
969    /// # Arguments
970    ///
971    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
972    pub fn AAudioStream_getSessionId(stream: *mut AAudioStream) -> i32;
973
974    /// Passes back the time at which a particular frame was presented.
975    /// This can be used to synchronize audio with video or MIDI.
976    /// It can also be used to align a recorded stream with a playback stream.
977    /// Returns 0 for OK or a negative error.
978    ///
979    /// Timestamps are only valid when the stream is in `STREAM_STATE_STARTED`.
980    /// `ERROR_INVALID_STATE` will be returned if the stream is not started.
981    /// Note that because requestStart() is asynchronous, timestamps will not be valid until
982    /// a short time after calling requestStart().
983    /// So `ERROR_INVALID_STATE` should not be considered a fatal error.
984    /// Just try calling again later.
985    ///
986    /// If an error occurs, then the position and time will not be modified.
987    ///
988    /// The position and time passed back are monotonically increasing.
989    ///
990    /// Available since API level 26.
991    ///
992    /// # Arguments
993    ///
994    /// * `stream` - reference provided by AAudioStreamBuilder_openStream()
995    /// * `clockid` - CLOCK_MONOTONIC or CLOCK_BOOTTIME
996    /// * `frame_position` - pointer to a variable to receive the position
997    /// * `time_nanoseconds` - pointer to a variable to receive the time
998    pub fn AAudioStream_getTimestamp(
999        stream: *mut AAudioStream,
1000        clockid: libc::clockid_t,
1001        frame_positon: *mut i64,
1002        time_nanoseconds: *mut i64,
1003    ) -> i32;
1004}