blob: 979b8c9c64da13d3dced291c938c9a814baf9715 [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#ifndef AAUDIO_AAUDIODEFINITIONS_H
18#define AAUDIO_AAUDIODEFINITIONS_H
19
20#include <stdint.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26typedef int32_t aaudio_handle_t; // negative handles are error codes
27typedef int32_t aaudio_result_t;
28/**
29 * A platform specific identifier for a device.
30 */
31typedef int32_t aaudio_device_id_t;
32typedef int32_t aaudio_sample_rate_t;
33/** This is used for small quantities such as the number of frames in a buffer. */
34typedef int32_t aaudio_size_frames_t;
35/** This is used for small quantities such as the number of bytes in a frame. */
36typedef int32_t aaudio_size_bytes_t;
37/**
38 * This is used for large quantities, such as the number of frames that have
39 * been played since a stream was started.
40 * At 48000 Hz, a 32-bit integer would wrap around in just over 12 hours.
41 */
42typedef int64_t aaudio_position_frames_t;
43
44typedef int64_t aaudio_nanoseconds_t;
45
46/**
47 * This is used to represent a value that has not been specified.
48 * For example, an application could use AAUDIO_UNSPECIFIED to indicate
49 * that is did not not care what the specific value of a parameter was
50 * and would accept whatever it was given.
51 */
52#define AAUDIO_UNSPECIFIED 0
53#define AAUDIO_DEVICE_UNSPECIFIED ((aaudio_device_id_t) -1)
54#define AAUDIO_NANOS_PER_MICROSECOND ((int64_t)1000)
55#define AAUDIO_NANOS_PER_MILLISECOND (AAUDIO_NANOS_PER_MICROSECOND * 1000)
56#define AAUDIO_MILLIS_PER_SECOND 1000
57#define AAUDIO_NANOS_PER_SECOND (AAUDIO_NANOS_PER_MILLISECOND * AAUDIO_MILLIS_PER_SECOND)
58
59#define AAUDIO_HANDLE_INVALID ((aaudio_handle_t)-1)
60
61enum aaudio_direction_t {
62 AAUDIO_DIRECTION_OUTPUT,
63 AAUDIO_DIRECTION_INPUT,
64 AAUDIO_DIRECTION_COUNT // This should always be last.
65};
66
67enum aaudio_audio_format_t {
68 AAUDIO_FORMAT_INVALID = -1,
69 AAUDIO_FORMAT_UNSPECIFIED = 0,
70 AAUDIO_FORMAT_PCM_I16,
71 AAUDIO_FORMAT_PCM_FLOAT,
72 AAUDIO_FORMAT_PCM_I8_24,
73 AAUDIO_FORMAT_PCM_I32
74};
75
76// TODO These are deprecated. Remove these aliases once all references are replaced.
77#define AAUDIO_FORMAT_PCM16 AAUDIO_FORMAT_PCM_I16
78#define AAUDIO_FORMAT_PCM824 AAUDIO_FORMAT_PCM_I8_24
79#define AAUDIO_FORMAT_PCM32 AAUDIO_FORMAT_PCM_I32
80
81enum {
82 AAUDIO_OK,
83 AAUDIO_ERROR_BASE = -900, // TODO review
84 AAUDIO_ERROR_DISCONNECTED,
85 AAUDIO_ERROR_ILLEGAL_ARGUMENT,
86 AAUDIO_ERROR_INCOMPATIBLE,
87 AAUDIO_ERROR_INTERNAL, // an underlying API returned an error code
88 AAUDIO_ERROR_INVALID_STATE,
89 AAUDIO_ERROR_UNEXPECTED_STATE,
90 AAUDIO_ERROR_UNEXPECTED_VALUE,
91 AAUDIO_ERROR_INVALID_HANDLE,
92 AAUDIO_ERROR_INVALID_QUERY,
93 AAUDIO_ERROR_UNIMPLEMENTED,
94 AAUDIO_ERROR_UNAVAILABLE,
95 AAUDIO_ERROR_NO_FREE_HANDLES,
96 AAUDIO_ERROR_NO_MEMORY,
97 AAUDIO_ERROR_NULL,
98 AAUDIO_ERROR_TIMEOUT,
99 AAUDIO_ERROR_WOULD_BLOCK,
100 AAUDIO_ERROR_INVALID_ORDER,
101 AAUDIO_ERROR_OUT_OF_RANGE,
102 AAUDIO_ERROR_NO_SERVICE
103};
104
105typedef enum {
106 AAUDIO_CLOCK_MONOTONIC, // Clock since booted, pauses when CPU is sleeping.
107 AAUDIO_CLOCK_BOOTTIME, // Clock since booted, runs all the time.
108 AAUDIO_CLOCK_COUNT // This should always be last.
109} aaudio_clockid_t;
110
111typedef enum
112{
113 AAUDIO_STREAM_STATE_UNINITIALIZED = 0,
114 AAUDIO_STREAM_STATE_OPEN,
115 AAUDIO_STREAM_STATE_STARTING,
116 AAUDIO_STREAM_STATE_STARTED,
117 AAUDIO_STREAM_STATE_PAUSING,
118 AAUDIO_STREAM_STATE_PAUSED,
119 AAUDIO_STREAM_STATE_FLUSHING,
120 AAUDIO_STREAM_STATE_FLUSHED,
121 AAUDIO_STREAM_STATE_STOPPING,
122 AAUDIO_STREAM_STATE_STOPPED,
123 AAUDIO_STREAM_STATE_CLOSING,
124 AAUDIO_STREAM_STATE_CLOSED,
125} aaudio_stream_state_t;
126
127// TODO review API
128typedef enum {
129 /**
130 * This will use an AudioTrack object for playing audio
131 * and an AudioRecord for recording data.
132 */
133 AAUDIO_SHARING_MODE_LEGACY,
134 /**
135 * This will be the only stream using a particular source or sink.
136 * This mode will provide the lowest possible latency.
137 * You should close EXCLUSIVE streams immediately when you are not using them.
138 */
139 AAUDIO_SHARING_MODE_EXCLUSIVE,
140 /**
141 * Multiple applications will be mixed by the AAudio Server.
142 * This will have higher latency than the EXCLUSIVE mode.
143 */
144 AAUDIO_SHARING_MODE_SHARED,
145 /**
146 * Multiple applications will do their own mixing into a memory mapped buffer.
147 * It may be possible for malicious applications to read the data produced by
148 * other apps. So do not use this for private data such as telephony or messaging.
149 */
150 AAUDIO_SHARING_MODE_PUBLIC_MIX,
151 AAUDIO_SHARING_MODE_COUNT // This should always be last.
152} aaudio_sharing_mode_t;
153
154#ifdef __cplusplus
155}
156#endif
157
158#endif // AAUDIO_AAUDIODEFINITIONS_H