Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1 | /* |
| 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 Burk | a45be8b | 2017-04-05 14:45:48 -0700 | [diff] [blame] | 18 | * @addtogroup Audio |
| 19 | * @{ |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * @file AAudio.h |
| 24 | */ |
| 25 | |
| 26 | /** |
| 27 | * This is the 'C' API for AAudio. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 28 | */ |
| 29 | #ifndef AAUDIO_AAUDIO_H |
| 30 | #define AAUDIO_AAUDIO_H |
| 31 | |
Elliott Hughes | 9c1fca2 | 2020-06-12 09:53:12 -0700 | [diff] [blame] | 32 | #include <stdbool.h> |
| 33 | #include <stdint.h> |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 34 | #include <time.h> |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 35 | |
| 36 | #ifdef __cplusplus |
| 37 | extern "C" { |
| 38 | #endif |
| 39 | |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 40 | /** |
| 41 | * This is used to represent a value that has not been specified. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 42 | * For example, an application could use {@link #AAUDIO_UNSPECIFIED} to indicate |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 43 | * that is did not not care what the specific value of a parameter was |
| 44 | * and would accept whatever it was given. |
| 45 | */ |
| 46 | #define AAUDIO_UNSPECIFIED 0 |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 47 | |
| 48 | enum { |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 49 | /** |
| 50 | * Audio data will travel out of the device, for example through a speaker. |
| 51 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 52 | AAUDIO_DIRECTION_OUTPUT, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 53 | |
| 54 | |
| 55 | /** |
| 56 | * Audio data will travel into the device, for example from a microphone. |
| 57 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 58 | AAUDIO_DIRECTION_INPUT |
| 59 | }; |
| 60 | typedef int32_t aaudio_direction_t; |
| 61 | |
| 62 | enum { |
| 63 | AAUDIO_FORMAT_INVALID = -1, |
| 64 | AAUDIO_FORMAT_UNSPECIFIED = 0, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * This format uses the int16_t data type. |
Phil Burk | 04e805b | 2018-03-27 09:13:53 -0700 | [diff] [blame] | 68 | * The maximum range of the data is -32768 (0x8000) to 32767 (0x7FFF). |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 69 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 70 | AAUDIO_FORMAT_PCM_I16, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * This format uses the float data type. |
| 74 | * The nominal range of the data is [-1.0f, 1.0f). |
| 75 | * Values outside that range may be clipped. |
| 76 | * |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 77 | * See also the float Data in |
| 78 | * <a href="/reference/android/media/AudioTrack#write(float[],%20int,%20int,%20int)"> |
| 79 | * write(float[], int, int, int)</a>. |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 80 | */ |
Phil Burk | 04e805b | 2018-03-27 09:13:53 -0700 | [diff] [blame] | 81 | AAUDIO_FORMAT_PCM_FLOAT, |
| 82 | |
| 83 | /** |
| 84 | * This format uses 24-bit samples packed into 3 bytes. |
Phil Burk | cfd3a6f | 2021-06-30 00:00:44 +0000 | [diff] [blame] | 85 | * The bytes are in little-endian order, so the least significant byte |
| 86 | * comes first in the byte array. |
| 87 | * |
Phil Burk | 04e805b | 2018-03-27 09:13:53 -0700 | [diff] [blame] | 88 | * The maximum range of the data is -8388608 (0x800000) |
| 89 | * to 8388607 (0x7FFFFF). |
| 90 | * |
| 91 | * Note that the lower precision bits may be ignored by the device. |
| 92 | * |
| 93 | * Available since API level 31. |
| 94 | */ |
| 95 | AAUDIO_FORMAT_PCM_I24_PACKED, |
| 96 | |
| 97 | /** |
| 98 | * This format uses 32-bit samples stored in an int32_t data type. |
| 99 | * The maximum range of the data is -2147483648 (0x80000000) |
| 100 | * to 2147483647 (0x7FFFFFFF). |
| 101 | * |
| 102 | * Note that the lower precision bits may be ignored by the device. |
| 103 | * |
| 104 | * Available since API level 31. |
| 105 | */ |
| 106 | AAUDIO_FORMAT_PCM_I32 |
| 107 | |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 108 | }; |
| 109 | typedef int32_t aaudio_format_t; |
| 110 | |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 111 | /** |
| 112 | * These result codes are returned from AAudio functions to indicate success or failure. |
| 113 | * Note that error return codes may change in the future so applications should generally |
| 114 | * not rely on specific return codes. |
| 115 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 116 | enum { |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 117 | /** |
| 118 | * The call was successful. |
| 119 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 120 | AAUDIO_OK, |
| 121 | AAUDIO_ERROR_BASE = -900, // TODO review |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * The audio device was disconnected. This could occur, for example, when headphones |
| 125 | * are plugged in or unplugged. The stream cannot be used after the device is disconnected. |
| 126 | * Applications should stop and close the stream. |
| 127 | * If this error is received in an error callback then another thread should be |
| 128 | * used to stop and close the stream. |
| 129 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 130 | AAUDIO_ERROR_DISCONNECTED, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * An invalid parameter was passed to AAudio. |
| 134 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 135 | AAUDIO_ERROR_ILLEGAL_ARGUMENT, |
Phil Burk | 17fff38 | 2017-05-16 14:06:45 -0700 | [diff] [blame] | 136 | // reserved |
| 137 | AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 138 | |
| 139 | /** |
| 140 | * The requested operation is not appropriate for the current state of AAudio. |
| 141 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 142 | AAUDIO_ERROR_INVALID_STATE, |
Phil Burk | 17fff38 | 2017-05-16 14:06:45 -0700 | [diff] [blame] | 143 | // reserved |
| 144 | // reserved |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 145 | /* The server rejected the handle used to identify the stream. |
| 146 | */ |
Phil Burk | 17fff38 | 2017-05-16 14:06:45 -0700 | [diff] [blame] | 147 | AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3, |
| 148 | // reserved |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * The function is not implemented for this stream. |
| 152 | */ |
Phil Burk | 17fff38 | 2017-05-16 14:06:45 -0700 | [diff] [blame] | 153 | AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 154 | |
| 155 | /** |
| 156 | * A resource or information is unavailable. |
| 157 | * This could occur when an application tries to open too many streams, |
| 158 | * or a timestamp is not available. |
| 159 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 160 | AAUDIO_ERROR_UNAVAILABLE, |
| 161 | AAUDIO_ERROR_NO_FREE_HANDLES, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * Memory could not be allocated. |
| 165 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 166 | AAUDIO_ERROR_NO_MEMORY, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * A NULL pointer was passed to AAudio. |
| 170 | * Or a NULL pointer was detected internally. |
| 171 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 172 | AAUDIO_ERROR_NULL, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * An operation took longer than expected. |
| 176 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 177 | AAUDIO_ERROR_TIMEOUT, |
| 178 | AAUDIO_ERROR_WOULD_BLOCK, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * The requested data format is not supported. |
| 182 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 183 | AAUDIO_ERROR_INVALID_FORMAT, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * A requested was out of range. |
| 187 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 188 | AAUDIO_ERROR_OUT_OF_RANGE, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * The audio service was not available. |
| 192 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 193 | AAUDIO_ERROR_NO_SERVICE, |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * The requested sample rate was not supported. |
| 197 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 198 | AAUDIO_ERROR_INVALID_RATE |
| 199 | }; |
| 200 | typedef int32_t aaudio_result_t; |
| 201 | |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 202 | /** |
| 203 | * AAudio Stream states, for details, refer to |
| 204 | * <a href="/ndk/guides/audio/aaudio/aaudio#using-streams">Using an Audio Stream</a> |
| 205 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 206 | enum |
| 207 | { |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 208 | |
| 209 | /** |
| 210 | * The stream is created but not initialized yet. |
| 211 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 212 | AAUDIO_STREAM_STATE_UNINITIALIZED = 0, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 213 | /** |
| 214 | * The stream is in an unrecognized state. |
| 215 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 216 | AAUDIO_STREAM_STATE_UNKNOWN, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | * The stream is open and ready to use. |
| 220 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 221 | AAUDIO_STREAM_STATE_OPEN, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 222 | /** |
| 223 | * The stream is just starting up. |
| 224 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 225 | AAUDIO_STREAM_STATE_STARTING, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 226 | /** |
| 227 | * The stream has started. |
| 228 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 229 | AAUDIO_STREAM_STATE_STARTED, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 230 | /** |
| 231 | * The stream is pausing. |
| 232 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 233 | AAUDIO_STREAM_STATE_PAUSING, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 234 | /** |
| 235 | * The stream has paused, could be restarted or flushed. |
| 236 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 237 | AAUDIO_STREAM_STATE_PAUSED, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 238 | /** |
| 239 | * The stream is being flushed. |
| 240 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 241 | AAUDIO_STREAM_STATE_FLUSHING, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 242 | /** |
| 243 | * The stream is flushed, ready to be restarted. |
| 244 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 245 | AAUDIO_STREAM_STATE_FLUSHED, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 246 | /** |
| 247 | * The stream is stopping. |
| 248 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 249 | AAUDIO_STREAM_STATE_STOPPING, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 250 | /** |
| 251 | * The stream has been stopped. |
| 252 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 253 | AAUDIO_STREAM_STATE_STOPPED, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 254 | /** |
| 255 | * The stream is closing. |
| 256 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 257 | AAUDIO_STREAM_STATE_CLOSING, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 258 | /** |
| 259 | * The stream has been closed. |
| 260 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 261 | AAUDIO_STREAM_STATE_CLOSED, |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 262 | /** |
| 263 | * The stream is disconnected from audio device. |
| 264 | */ |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 265 | AAUDIO_STREAM_STATE_DISCONNECTED |
| 266 | }; |
| 267 | typedef int32_t aaudio_stream_state_t; |
| 268 | |
| 269 | |
| 270 | enum { |
| 271 | /** |
| 272 | * This will be the only stream using a particular source or sink. |
| 273 | * This mode will provide the lowest possible latency. |
| 274 | * You should close EXCLUSIVE streams immediately when you are not using them. |
| 275 | */ |
| 276 | AAUDIO_SHARING_MODE_EXCLUSIVE, |
| 277 | /** |
| 278 | * Multiple applications will be mixed by the AAudio Server. |
| 279 | * This will have higher latency than the EXCLUSIVE mode. |
| 280 | */ |
| 281 | AAUDIO_SHARING_MODE_SHARED |
| 282 | }; |
| 283 | typedef int32_t aaudio_sharing_mode_t; |
| 284 | |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 285 | |
| 286 | enum { |
| 287 | /** |
| 288 | * No particular performance needs. Default. |
| 289 | */ |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 290 | AAUDIO_PERFORMANCE_MODE_NONE = 10, |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 293 | * Extending battery life is more important than low latency. |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 294 | * |
| 295 | * This mode is not supported in input streams. |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 296 | * For input, mode NONE will be used if this is requested. |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 297 | */ |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 298 | AAUDIO_PERFORMANCE_MODE_POWER_SAVING, |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 299 | |
| 300 | /** |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 301 | * Reducing latency is more important than battery life. |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 302 | */ |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 303 | AAUDIO_PERFORMANCE_MODE_LOW_LATENCY |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 304 | }; |
| 305 | typedef int32_t aaudio_performance_mode_t; |
| 306 | |
Hayden Gomes | 3e8bbb9 | 2020-01-10 13:37:05 -0800 | [diff] [blame] | 307 | #define AAUDIO_SYSTEM_USAGE_OFFSET 1000 |
| 308 | |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 309 | /** |
| 310 | * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for. |
| 311 | * This information is used by certain platforms or routing policies |
| 312 | * to make more refined volume or routing decisions. |
| 313 | * |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 314 | * Note that these match the equivalent values in |
| 315 | * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a> |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 316 | * in the Android Java API. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 317 | * |
| 318 | * Added in API level 28. |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 319 | */ |
| 320 | enum { |
| 321 | /** |
| 322 | * Use this for streaming media, music performance, video, podcasts, etcetera. |
| 323 | */ |
| 324 | AAUDIO_USAGE_MEDIA = 1, |
| 325 | |
| 326 | /** |
| 327 | * Use this for voice over IP, telephony, etcetera. |
| 328 | */ |
| 329 | AAUDIO_USAGE_VOICE_COMMUNICATION = 2, |
| 330 | |
| 331 | /** |
| 332 | * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera. |
| 333 | */ |
| 334 | AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3, |
| 335 | |
| 336 | /** |
| 337 | * Use this to demand the users attention. |
| 338 | */ |
| 339 | AAUDIO_USAGE_ALARM = 4, |
| 340 | |
| 341 | /** |
| 342 | * Use this for notifying the user when a message has arrived or some |
| 343 | * other background event has occured. |
| 344 | */ |
| 345 | AAUDIO_USAGE_NOTIFICATION = 5, |
| 346 | |
| 347 | /** |
| 348 | * Use this when the phone rings. |
| 349 | */ |
| 350 | AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6, |
| 351 | |
| 352 | /** |
| 353 | * Use this to attract the users attention when, for example, the battery is low. |
| 354 | */ |
| 355 | AAUDIO_USAGE_NOTIFICATION_EVENT = 10, |
| 356 | |
| 357 | /** |
| 358 | * Use this for screen readers, etcetera. |
| 359 | */ |
| 360 | AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11, |
| 361 | |
| 362 | /** |
| 363 | * Use this for driving or navigation directions. |
| 364 | */ |
| 365 | AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12, |
| 366 | |
| 367 | /** |
| 368 | * Use this for user interface sounds, beeps, etcetera. |
| 369 | */ |
| 370 | AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13, |
| 371 | |
| 372 | /** |
| 373 | * Use this for game audio and sound effects. |
| 374 | */ |
| 375 | AAUDIO_USAGE_GAME = 14, |
| 376 | |
| 377 | /** |
| 378 | * Use this for audio responses to user queries, audio instructions or help utterances. |
| 379 | */ |
Hayden Gomes | 3e8bbb9 | 2020-01-10 13:37:05 -0800 | [diff] [blame] | 380 | AAUDIO_USAGE_ASSISTANT = 16, |
| 381 | |
| 382 | /** |
| 383 | * Use this in case of playing sounds in an emergency. |
| 384 | * Privileged MODIFY_AUDIO_ROUTING permission required. |
| 385 | */ |
| 386 | AAUDIO_SYSTEM_USAGE_EMERGENCY = AAUDIO_SYSTEM_USAGE_OFFSET, |
| 387 | |
| 388 | /** |
| 389 | * Use this for safety sounds and alerts, for example backup camera obstacle detection. |
| 390 | * Privileged MODIFY_AUDIO_ROUTING permission required. |
| 391 | */ |
| 392 | AAUDIO_SYSTEM_USAGE_SAFETY = AAUDIO_SYSTEM_USAGE_OFFSET + 1, |
| 393 | |
| 394 | /** |
| 395 | * Use this for vehicle status alerts and information, for example the check engine light. |
| 396 | * Privileged MODIFY_AUDIO_ROUTING permission required. |
| 397 | */ |
| 398 | AAUDIO_SYSTEM_USAGE_VEHICLE_STATUS = AAUDIO_SYSTEM_USAGE_OFFSET + 2, |
| 399 | |
| 400 | /** |
| 401 | * Use this for traffic announcements, etc. |
| 402 | * Privileged MODIFY_AUDIO_ROUTING permission required. |
| 403 | */ |
| 404 | AAUDIO_SYSTEM_USAGE_ANNOUNCEMENT = AAUDIO_SYSTEM_USAGE_OFFSET + 3, |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 405 | }; |
| 406 | typedef int32_t aaudio_usage_t; |
| 407 | |
| 408 | /** |
| 409 | * The CONTENT_TYPE attribute describes "what" you are playing. |
| 410 | * It expresses the general category of the content. This information is optional. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 411 | * But in case it is known (for instance AAUDIO_CONTENT_TYPE_MOVIE for a |
| 412 | * movie streaming service or AAUDIO_CONTENT_TYPE_SPEECH for |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 413 | * an audio book application) this information might be used by the audio framework to |
| 414 | * enforce audio focus. |
| 415 | * |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 416 | * Note that these match the equivalent values in |
| 417 | * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a> |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 418 | * in the Android Java API. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 419 | * |
| 420 | * Added in API level 28. |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 421 | */ |
| 422 | enum { |
| 423 | |
| 424 | /** |
| 425 | * Use this for spoken voice, audio books, etcetera. |
| 426 | */ |
| 427 | AAUDIO_CONTENT_TYPE_SPEECH = 1, |
| 428 | |
| 429 | /** |
| 430 | * Use this for pre-recorded or live music. |
| 431 | */ |
| 432 | AAUDIO_CONTENT_TYPE_MUSIC = 2, |
| 433 | |
| 434 | /** |
| 435 | * Use this for a movie or video soundtrack. |
| 436 | */ |
| 437 | AAUDIO_CONTENT_TYPE_MOVIE = 3, |
| 438 | |
| 439 | /** |
| 440 | * Use this for sound is designed to accompany a user action, |
| 441 | * such as a click or beep sound made when the user presses a button. |
| 442 | */ |
| 443 | AAUDIO_CONTENT_TYPE_SONIFICATION = 4 |
| 444 | }; |
| 445 | typedef int32_t aaudio_content_type_t; |
| 446 | |
| 447 | /** |
| 448 | * Defines the audio source. |
| 449 | * An audio source defines both a default physical source of audio signal, and a recording |
| 450 | * configuration. |
| 451 | * |
| 452 | * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 453 | * |
| 454 | * Added in API level 28. |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 455 | */ |
| 456 | enum { |
| 457 | /** |
| 458 | * Use this preset when other presets do not apply. |
| 459 | */ |
| 460 | AAUDIO_INPUT_PRESET_GENERIC = 1, |
| 461 | |
| 462 | /** |
| 463 | * Use this preset when recording video. |
| 464 | */ |
| 465 | AAUDIO_INPUT_PRESET_CAMCORDER = 5, |
| 466 | |
| 467 | /** |
| 468 | * Use this preset when doing speech recognition. |
| 469 | */ |
| 470 | AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6, |
| 471 | |
| 472 | /** |
| 473 | * Use this preset when doing telephony or voice messaging. |
| 474 | */ |
| 475 | AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7, |
| 476 | |
| 477 | /** |
| 478 | * Use this preset to obtain an input with no effects. |
| 479 | * Note that this input will not have automatic gain control |
| 480 | * so the recorded volume may be very low. |
| 481 | */ |
| 482 | AAUDIO_INPUT_PRESET_UNPROCESSED = 9, |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 483 | |
| 484 | /** |
| 485 | * Use this preset for capturing audio meant to be processed in real time |
| 486 | * and played back for live performance (e.g karaoke). |
| 487 | * The capture path will minimize latency and coupling with playback path. |
Eric Laurent | b51e3ab | 2020-04-28 18:29:25 -0700 | [diff] [blame] | 488 | * Available since API level 29. |
Eric Laurent | ae4b6ec | 2019-01-15 18:34:38 -0800 | [diff] [blame] | 489 | */ |
| 490 | AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE = 10, |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 491 | }; |
| 492 | typedef int32_t aaudio_input_preset_t; |
| 493 | |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 494 | /** |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 495 | * Specifying if audio may or may not be captured by other apps or the system. |
| 496 | * |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 497 | * Note that these match the equivalent values in |
| 498 | * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a> |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 499 | * in the Android Java API. |
| 500 | * |
| 501 | * Added in API level 29. |
| 502 | */ |
| 503 | enum { |
| 504 | /** |
| 505 | * Indicates that the audio may be captured by any app. |
| 506 | * |
| 507 | * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*, |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 508 | * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and {@link #AAUDIO_USAGE_ASSISTANT}. |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 509 | * |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 510 | * On <a href="/reference/android/os/Build.VERSION_CODES#Q">Build.VERSION_CODES</a>, |
| 511 | * this means only {@link #AAUDIO_USAGE_MEDIA} and {@link #AAUDIO_USAGE_GAME} may be captured. |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 512 | * |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 513 | * See <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_ALL"> |
| 514 | * ALLOW_CAPTURE_BY_ALL</a>. |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 515 | */ |
| 516 | AAUDIO_ALLOW_CAPTURE_BY_ALL = 1, |
| 517 | /** |
| 518 | * Indicates that the audio may only be captured by system apps. |
| 519 | * |
| 520 | * System apps can capture for many purposes like accessibility, user guidance... |
| 521 | * but have strong restriction. See |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 522 | * <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_SYSTEM"> |
| 523 | * ALLOW_CAPTURE_BY_SYSTEM</a> |
| 524 | * for what the system apps can do with the capture audio. |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 525 | */ |
| 526 | AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2, |
| 527 | /** |
| 528 | * Indicates that the audio may not be recorded by any app, even if it is a system app. |
| 529 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 530 | * It is encouraged to use {@link #AAUDIO_ALLOW_CAPTURE_BY_SYSTEM} instead of this value as system apps |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 531 | * provide significant and useful features for the user (eg. accessibility). |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 532 | * See <a href="/reference/android/media/AudioAttributes.html#ALLOW_CAPTURE_BY_NONE"> |
| 533 | * ALLOW_CAPTURE_BY_NONE</a>. |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 534 | */ |
| 535 | AAUDIO_ALLOW_CAPTURE_BY_NONE = 3, |
| 536 | }; |
| 537 | |
| 538 | typedef int32_t aaudio_allowed_capture_policy_t; |
| 539 | |
| 540 | /** |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 541 | * These may be used with AAudioStreamBuilder_setSessionId(). |
| 542 | * |
| 543 | * Added in API level 28. |
| 544 | */ |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 545 | enum { |
| 546 | /** |
| 547 | * Do not allocate a session ID. |
| 548 | * Effects cannot be used with this stream. |
| 549 | * Default. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 550 | * |
| 551 | * Added in API level 28. |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 552 | */ |
| 553 | AAUDIO_SESSION_ID_NONE = -1, |
| 554 | |
| 555 | /** |
| 556 | * Allocate a session ID that can be used to attach and control |
| 557 | * effects using the Java AudioEffects API. |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 558 | * Note that using this may result in higher latency. |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 559 | * |
| 560 | * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 561 | * |
| 562 | * Added in API level 28. |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 563 | */ |
| 564 | AAUDIO_SESSION_ID_ALLOCATE = 0, |
| 565 | }; |
| 566 | typedef int32_t aaudio_session_id_t; |
| 567 | |
jiabin | a909409 | 2021-06-28 20:36:45 +0000 | [diff] [blame] | 568 | /** |
| 569 | * Defines the audio channel mask. |
| 570 | * Channel masks are used to describe the samples and their |
| 571 | * arrangement in the audio frame. They are also used in the endpoint |
| 572 | * (e.g. a USB audio interface, a DAC connected to headphones) to |
| 573 | * specify allowable configurations of a particular device. |
| 574 | * |
| 575 | * Added in API level 32. |
| 576 | */ |
| 577 | enum { |
| 578 | /** |
| 579 | * Invalid channel mask |
| 580 | */ |
| 581 | AAUDIO_CHANNEL_INVALID = -1, |
| 582 | |
| 583 | /** |
| 584 | * Output audio channel mask |
| 585 | */ |
| 586 | AAUDIO_CHANNEL_FRONT_LEFT = 1 << 0, |
| 587 | AAUDIO_CHANNEL_FRONT_RIGHT = 1 << 1, |
| 588 | AAUDIO_CHANNEL_FRONT_CENTER = 1 << 2, |
| 589 | AAUDIO_CHANNEL_LOW_FREQUENCY = 1 << 3, |
| 590 | AAUDIO_CHANNEL_BACK_LEFT = 1 << 4, |
| 591 | AAUDIO_CHANNEL_BACK_RIGHT = 1 << 5, |
| 592 | AAUDIO_CHANNEL_FRONT_LEFT_OF_CENTER = 1 << 6, |
| 593 | AAUDIO_CHANNEL_FRONT_RIGHT_OF_CENTER = 1 << 7, |
| 594 | AAUDIO_CHANNEL_BACK_CENTER = 1 << 8, |
| 595 | AAUDIO_CHANNEL_SIDE_LEFT = 1 << 9, |
| 596 | AAUDIO_CHANNEL_SIDE_RIGHT = 1 << 10, |
| 597 | AAUDIO_CHANNEL_TOP_CENTER = 1 << 11, |
| 598 | AAUDIO_CHANNEL_TOP_FRONT_LEFT = 1 << 12, |
| 599 | AAUDIO_CHANNEL_TOP_FRONT_CENTER = 1 << 13, |
| 600 | AAUDIO_CHANNEL_TOP_FRONT_RIGHT = 1 << 14, |
| 601 | AAUDIO_CHANNEL_TOP_BACK_LEFT = 1 << 15, |
| 602 | AAUDIO_CHANNEL_TOP_BACK_CENTER = 1 << 16, |
| 603 | AAUDIO_CHANNEL_TOP_BACK_RIGHT = 1 << 17, |
| 604 | AAUDIO_CHANNEL_TOP_SIDE_LEFT = 1 << 18, |
| 605 | AAUDIO_CHANNEL_TOP_SIDE_RIGHT = 1 << 19, |
| 606 | AAUDIO_CHANNEL_BOTTOM_FRONT_LEFT = 1 << 20, |
| 607 | AAUDIO_CHANNEL_BOTTOM_FRONT_CENTER = 1 << 21, |
| 608 | AAUDIO_CHANNEL_BOTTOM_FRONT_RIGHT = 1 << 22, |
| 609 | AAUDIO_CHANNEL_LOW_FREQUENCY_2 = 1 << 23, |
| 610 | AAUDIO_CHANNEL_FRONT_WIDE_LEFT = 1 << 24, |
| 611 | AAUDIO_CHANNEL_FRONT_WIDE_RIGHT = 1 << 25, |
| 612 | |
| 613 | AAUDIO_CHANNEL_MONO = AAUDIO_CHANNEL_FRONT_LEFT, |
| 614 | AAUDIO_CHANNEL_STEREO = AAUDIO_CHANNEL_FRONT_LEFT | |
| 615 | AAUDIO_CHANNEL_FRONT_RIGHT, |
| 616 | AAUDIO_CHANNEL_2POINT1 = AAUDIO_CHANNEL_FRONT_LEFT | |
| 617 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 618 | AAUDIO_CHANNEL_LOW_FREQUENCY, |
| 619 | AAUDIO_CHANNEL_TRI = AAUDIO_CHANNEL_FRONT_LEFT | |
| 620 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 621 | AAUDIO_CHANNEL_FRONT_CENTER, |
| 622 | AAUDIO_CHANNEL_TRI_BACK = AAUDIO_CHANNEL_FRONT_LEFT | |
| 623 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 624 | AAUDIO_CHANNEL_BACK_CENTER, |
| 625 | AAUDIO_CHANNEL_3POINT1 = AAUDIO_CHANNEL_FRONT_LEFT | |
| 626 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 627 | AAUDIO_CHANNEL_FRONT_CENTER | |
| 628 | AAUDIO_CHANNEL_LOW_FREQUENCY, |
| 629 | AAUDIO_CHANNEL_2POINT0POINT2 = AAUDIO_CHANNEL_FRONT_LEFT | |
| 630 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 631 | AAUDIO_CHANNEL_TOP_SIDE_LEFT | |
| 632 | AAUDIO_CHANNEL_TOP_SIDE_RIGHT, |
| 633 | AAUDIO_CHANNEL_2POINT1POINT2 = AAUDIO_CHANNEL_2POINT0POINT2 | |
| 634 | AAUDIO_CHANNEL_LOW_FREQUENCY, |
| 635 | AAUDIO_CHANNEL_3POINT0POINT2 = AAUDIO_CHANNEL_FRONT_LEFT | |
| 636 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 637 | AAUDIO_CHANNEL_FRONT_CENTER | |
| 638 | AAUDIO_CHANNEL_TOP_SIDE_LEFT | |
| 639 | AAUDIO_CHANNEL_TOP_SIDE_RIGHT, |
| 640 | AAUDIO_CHANNEL_3POINT1POINT2 = AAUDIO_CHANNEL_3POINT0POINT2 | |
| 641 | AAUDIO_CHANNEL_LOW_FREQUENCY, |
| 642 | AAUDIO_CHANNEL_QUAD = AAUDIO_CHANNEL_FRONT_LEFT | |
| 643 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 644 | AAUDIO_CHANNEL_BACK_LEFT | |
| 645 | AAUDIO_CHANNEL_BACK_RIGHT, |
| 646 | AAUDIO_CHANNEL_QUAD_SIDE = AAUDIO_CHANNEL_FRONT_LEFT | |
| 647 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 648 | AAUDIO_CHANNEL_SIDE_LEFT | |
| 649 | AAUDIO_CHANNEL_SIDE_RIGHT, |
| 650 | AAUDIO_CHANNEL_SURROUND = AAUDIO_CHANNEL_FRONT_LEFT | |
| 651 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 652 | AAUDIO_CHANNEL_FRONT_CENTER | |
| 653 | AAUDIO_CHANNEL_BACK_CENTER, |
| 654 | AAUDIO_CHANNEL_PENTA = AAUDIO_CHANNEL_QUAD | |
| 655 | AAUDIO_CHANNEL_FRONT_CENTER, |
| 656 | // aka 5POINT1_BACK |
| 657 | AAUDIO_CHANNEL_5POINT1 = AAUDIO_CHANNEL_FRONT_LEFT | |
| 658 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 659 | AAUDIO_CHANNEL_FRONT_CENTER | |
| 660 | AAUDIO_CHANNEL_LOW_FREQUENCY | |
| 661 | AAUDIO_CHANNEL_BACK_LEFT | |
| 662 | AAUDIO_CHANNEL_BACK_RIGHT, |
| 663 | AAUDIO_CHANNEL_5POINT1_SIDE = AAUDIO_CHANNEL_FRONT_LEFT | |
| 664 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 665 | AAUDIO_CHANNEL_FRONT_CENTER | |
| 666 | AAUDIO_CHANNEL_LOW_FREQUENCY | |
| 667 | AAUDIO_CHANNEL_SIDE_LEFT | |
| 668 | AAUDIO_CHANNEL_SIDE_RIGHT, |
| 669 | AAUDIO_CHANNEL_6POINT1 = AAUDIO_CHANNEL_FRONT_LEFT | |
| 670 | AAUDIO_CHANNEL_FRONT_RIGHT | |
| 671 | AAUDIO_CHANNEL_FRONT_CENTER | |
| 672 | AAUDIO_CHANNEL_LOW_FREQUENCY | |
| 673 | AAUDIO_CHANNEL_BACK_LEFT | |
| 674 | AAUDIO_CHANNEL_BACK_RIGHT | |
| 675 | AAUDIO_CHANNEL_BACK_CENTER, |
| 676 | AAUDIO_CHANNEL_7POINT1 = AAUDIO_CHANNEL_5POINT1 | |
| 677 | AAUDIO_CHANNEL_SIDE_LEFT | |
| 678 | AAUDIO_CHANNEL_SIDE_RIGHT, |
| 679 | AAUDIO_CHANNEL_5POINT1POINT2 = AAUDIO_CHANNEL_5POINT1 | |
| 680 | AAUDIO_CHANNEL_TOP_SIDE_LEFT | |
| 681 | AAUDIO_CHANNEL_TOP_SIDE_RIGHT, |
| 682 | AAUDIO_CHANNEL_5POINT1POINT4 = AAUDIO_CHANNEL_5POINT1 | |
| 683 | AAUDIO_CHANNEL_TOP_FRONT_LEFT | |
| 684 | AAUDIO_CHANNEL_TOP_FRONT_RIGHT | |
| 685 | AAUDIO_CHANNEL_TOP_BACK_LEFT | |
| 686 | AAUDIO_CHANNEL_TOP_BACK_RIGHT, |
| 687 | AAUDIO_CHANNEL_7POINT1POINT2 = AAUDIO_CHANNEL_7POINT1 | |
| 688 | AAUDIO_CHANNEL_TOP_SIDE_LEFT | |
| 689 | AAUDIO_CHANNEL_TOP_SIDE_RIGHT, |
| 690 | AAUDIO_CHANNEL_7POINT1POINT4 = AAUDIO_CHANNEL_7POINT1 | |
| 691 | AAUDIO_CHANNEL_TOP_FRONT_LEFT | |
| 692 | AAUDIO_CHANNEL_TOP_FRONT_RIGHT | |
| 693 | AAUDIO_CHANNEL_TOP_BACK_LEFT | |
| 694 | AAUDIO_CHANNEL_TOP_BACK_RIGHT, |
| 695 | AAUDIO_CHANNEL_9POINT1POINT4 = AAUDIO_CHANNEL_7POINT1POINT4 | |
| 696 | AAUDIO_CHANNEL_FRONT_WIDE_LEFT | |
| 697 | AAUDIO_CHANNEL_FRONT_WIDE_RIGHT, |
| 698 | AAUDIO_CHANNEL_9POINT1POINT6 = AAUDIO_CHANNEL_9POINT1POINT4 | |
| 699 | AAUDIO_CHANNEL_TOP_SIDE_LEFT | |
| 700 | AAUDIO_CHANNEL_TOP_SIDE_RIGHT, |
| 701 | |
| 702 | AAUDIO_CHANNEL_FRONT_BACK = AAUDIO_CHANNEL_FRONT_CENTER | |
| 703 | AAUDIO_CHANNEL_BACK_CENTER, |
| 704 | }; |
| 705 | typedef uint32_t aaudio_channel_mask_t; |
| 706 | |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 707 | typedef struct AAudioStreamStruct AAudioStream; |
| 708 | typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 709 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 710 | #ifndef AAUDIO_API |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 711 | #define AAUDIO_API /* export this symbol */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 712 | #endif |
| 713 | |
| 714 | // ============================================================ |
| 715 | // Audio System |
| 716 | // ============================================================ |
| 717 | |
| 718 | /** |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 719 | * The text is the ASCII symbol corresponding to the returnCode, |
| 720 | * or an English message saying the returnCode is unrecognized. |
| 721 | * This is intended for developers to use when debugging. |
| 722 | * It is not for display to users. |
| 723 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 724 | * Available since API level 26. |
| 725 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 726 | * @return pointer to a text representation of an AAudio result code. |
| 727 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 728 | AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 729 | |
| 730 | /** |
| 731 | * The text is the ASCII symbol corresponding to the stream state, |
| 732 | * or an English message saying the state is unrecognized. |
| 733 | * This is intended for developers to use when debugging. |
| 734 | * It is not for display to users. |
| 735 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 736 | * Available since API level 26. |
| 737 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 738 | * @return pointer to a text representation of an AAudio state. |
| 739 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 740 | AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state) |
| 741 | __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 742 | |
| 743 | // ============================================================ |
| 744 | // StreamBuilder |
| 745 | // ============================================================ |
| 746 | |
| 747 | /** |
| 748 | * Create a StreamBuilder that can be used to open a Stream. |
| 749 | * |
| 750 | * The deviceId is initially unspecified, meaning that the current default device will be used. |
| 751 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 752 | * The default direction is {@link #AAUDIO_DIRECTION_OUTPUT}. |
| 753 | * The default sharing mode is {@link #AAUDIO_SHARING_MODE_SHARED}. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 754 | * The data format, samplesPerFrames and sampleRate are unspecified and will be |
| 755 | * chosen by the device when it is opened. |
| 756 | * |
| 757 | * AAudioStreamBuilder_delete() must be called when you are done using the builder. |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 758 | * |
| 759 | * Available since API level 26. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 760 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 761 | AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder) |
| 762 | __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 763 | |
| 764 | /** |
| 765 | * Request an audio device identified device using an ID. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 766 | * On Android, for example, the ID could be obtained from the Java AudioManager. |
| 767 | * |
Kevin Rocard | 6309d88 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 768 | * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}, |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 769 | * in which case the primary device will be used. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 770 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 771 | * Available since API level 26. |
| 772 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 773 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | 6309d88 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 774 | * @param deviceId device identifier or {@link #AAUDIO_UNSPECIFIED} |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 775 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 776 | AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 777 | int32_t deviceId) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 778 | |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 779 | /** |
| 780 | * Declare the name of the package creating the stream. |
| 781 | * |
| 782 | * This is usually {@code Context#getPackageName()}. |
| 783 | * |
| 784 | * The default, if you do not call this function, is a random package in the calling uid. |
Nate Myren | 29457ed | 2021-05-19 12:29:28 -0700 | [diff] [blame] | 785 | * The vast majority of apps have only one package per calling UID. If the package |
| 786 | * name does not match the calling UID, then requests will be rejected. |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 787 | * |
| 788 | * Available since API level 31. |
| 789 | * |
| 790 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 791 | * @param packageName packageName of the calling app. |
| 792 | */ |
| 793 | AAUDIO_API void AAudioStreamBuilder_setPackageName(AAudioStreamBuilder* builder, |
| 794 | const char * packageName) __INTRODUCED_IN(31); |
| 795 | |
| 796 | /** |
| 797 | * Declare the attribution tag of the context creating the stream. |
| 798 | * |
| 799 | * This is usually {@code Context#getAttributionTag()}. |
| 800 | * |
Nate Myren | 29457ed | 2021-05-19 12:29:28 -0700 | [diff] [blame] | 801 | * The default, if you do not call this function, is null. |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 802 | * |
| 803 | * Available since API level 31. |
| 804 | * |
| 805 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 806 | * @param attributionTag attributionTag of the calling context. |
| 807 | */ |
| 808 | AAUDIO_API void AAudioStreamBuilder_setAttributionTag(AAudioStreamBuilder* builder, |
| 809 | const char * attributionTag) __INTRODUCED_IN(31); |
| 810 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 811 | /** |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 812 | * Request a sample rate in Hertz. |
| 813 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 814 | * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. |
Phil Burk | 8f62489 | 2017-05-11 11:44:20 -0700 | [diff] [blame] | 815 | * An optimal value will then be chosen when the stream is opened. |
| 816 | * After opening a stream with an unspecified value, the application must |
| 817 | * query for the actual value, which may vary by device. |
| 818 | * |
| 819 | * If an exact value is specified then an opened stream will use that value. |
| 820 | * If a stream cannot be opened with the specified value then the open will fail. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 821 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 822 | * Available since API level 26. |
| 823 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 824 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 825 | * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 826 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 827 | AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 828 | int32_t sampleRate) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 829 | |
| 830 | /** |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame] | 831 | * Request a number of channels for the stream. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 832 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 833 | * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. |
Phil Burk | 8f62489 | 2017-05-11 11:44:20 -0700 | [diff] [blame] | 834 | * An optimal value will then be chosen when the stream is opened. |
| 835 | * After opening a stream with an unspecified value, the application must |
| 836 | * query for the actual value, which may vary by device. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 837 | * |
Phil Burk | 8f62489 | 2017-05-11 11:44:20 -0700 | [diff] [blame] | 838 | * If an exact value is specified then an opened stream will use that value. |
| 839 | * If a stream cannot be opened with the specified value then the open will fail. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 840 | * |
jiabin | a909409 | 2021-06-28 20:36:45 +0000 | [diff] [blame] | 841 | * As the channel count provided here may be different from the corresponding channel count |
| 842 | * of channel mask used in {@link AAudioStreamBuilder_setChannelMask}, the last called function |
| 843 | * will be respected if both this function and {@link AAudioStreamBuilder_setChannelMask} are |
| 844 | * called. |
| 845 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 846 | * Available since API level 26. |
| 847 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 848 | * @param builder reference provided by AAudio_createStreamBuilder() |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame] | 849 | * @param channelCount Number of channels desired. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 850 | */ |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame] | 851 | AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 852 | int32_t channelCount) __INTRODUCED_IN(26); |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame] | 853 | |
| 854 | /** |
Phil Burk | e74240d | 2017-08-03 15:25:43 -0700 | [diff] [blame] | 855 | * Identical to AAudioStreamBuilder_setChannelCount(). |
| 856 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 857 | * Available since API level 26. |
| 858 | * |
Phil Burk | e74240d | 2017-08-03 15:25:43 -0700 | [diff] [blame] | 859 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 860 | * @param samplesPerFrame Number of samples in a frame. |
jiabin | a909409 | 2021-06-28 20:36:45 +0000 | [diff] [blame] | 861 | * |
| 862 | * @deprecated use {@link AAudioStreamBuilder_setChannelCount} |
Phil Burk | e74240d | 2017-08-03 15:25:43 -0700 | [diff] [blame] | 863 | */ |
| 864 | AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 865 | int32_t samplesPerFrame) __INTRODUCED_IN(26); |
Phil Burk | e74240d | 2017-08-03 15:25:43 -0700 | [diff] [blame] | 866 | |
| 867 | /** |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 868 | * Request a sample data format, for example {@link #AAUDIO_FORMAT_PCM_I16}. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 869 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 870 | * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. |
Phil Burk | 8f62489 | 2017-05-11 11:44:20 -0700 | [diff] [blame] | 871 | * An optimal value will then be chosen when the stream is opened. |
| 872 | * After opening a stream with an unspecified value, the application must |
| 873 | * query for the actual value, which may vary by device. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 874 | * |
Phil Burk | 8f62489 | 2017-05-11 11:44:20 -0700 | [diff] [blame] | 875 | * If an exact value is specified then an opened stream will use that value. |
| 876 | * If a stream cannot be opened with the specified value then the open will fail. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 877 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 878 | * Available since API level 26. |
| 879 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 880 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 881 | * @param format common formats are {@link #AAUDIO_FORMAT_PCM_FLOAT} and |
| 882 | * {@link #AAUDIO_FORMAT_PCM_I16}. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 883 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 884 | AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 885 | aaudio_format_t format) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 886 | |
| 887 | /** |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 888 | * Request a mode for sharing the device. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 889 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 890 | * The default, if you do not call this function, is {@link #AAUDIO_SHARING_MODE_SHARED}. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 891 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 892 | * The requested sharing mode may not be available. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 893 | * The application can query for the actual mode after the stream is opened. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 894 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 895 | * Available since API level 26. |
| 896 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 897 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 898 | * @param sharingMode {@link #AAUDIO_SHARING_MODE_SHARED} or {@link #AAUDIO_SHARING_MODE_EXCLUSIVE} |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 899 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 900 | AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 901 | aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 902 | |
| 903 | /** |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 904 | * Request the direction for a stream. |
| 905 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 906 | * The default, if you do not call this function, is {@link #AAUDIO_DIRECTION_OUTPUT}. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 907 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 908 | * Available since API level 26. |
| 909 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 910 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 911 | * @param direction {@link #AAUDIO_DIRECTION_OUTPUT} or {@link #AAUDIO_DIRECTION_INPUT} |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 912 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 913 | AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 914 | aaudio_direction_t direction) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 915 | |
| 916 | /** |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 917 | * Set the requested buffer capacity in frames. |
Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 918 | * The final AAudioStream capacity may differ, but will probably be at least this big. |
| 919 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 920 | * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. |
Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 921 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 922 | * Available since API level 26. |
| 923 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 924 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 925 | * @param numFrames the desired buffer capacity in frames or {@link #AAUDIO_UNSPECIFIED} |
Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 926 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 927 | AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 928 | int32_t numFrames) __INTRODUCED_IN(26); |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 929 | |
| 930 | /** |
| 931 | * Set the requested performance mode. |
| 932 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 933 | * Supported modes are {@link #AAUDIO_PERFORMANCE_MODE_NONE}, |
| 934 | * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING} * and {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}. |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 935 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 936 | * The default, if you do not call this function, is {@link #AAUDIO_PERFORMANCE_MODE_NONE}. |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 937 | * |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 938 | * You may not get the mode you requested. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 939 | * You can call AAudioStream_getPerformanceMode() |
| 940 | * to find out the final mode for the stream. |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 941 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 942 | * Available since API level 26. |
| 943 | * |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 944 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 945 | * @param mode the desired performance mode, eg. {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY} |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 946 | */ |
| 947 | AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 948 | aaudio_performance_mode_t mode) __INTRODUCED_IN(26); |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 949 | |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 950 | /** |
jiabin | ec3fa35 | 2020-08-11 16:29:26 -0700 | [diff] [blame] | 951 | * Set the intended use case for the output stream. |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 952 | * |
| 953 | * The AAudio system will use this information to optimize the |
| 954 | * behavior of the stream. |
| 955 | * This could, for example, affect how volume and focus is handled for the stream. |
| 956 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 957 | * The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}. |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 958 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 959 | * Available since API level 28. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 960 | * |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 961 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 962 | * @param usage the desired usage, eg. {@link #AAUDIO_USAGE_GAME} |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 963 | */ |
| 964 | AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 965 | aaudio_usage_t usage) __INTRODUCED_IN(28); |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 966 | |
| 967 | /** |
jiabin | ec3fa35 | 2020-08-11 16:29:26 -0700 | [diff] [blame] | 968 | * Set the type of audio data that the output stream will carry. |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 969 | * |
| 970 | * The AAudio system will use this information to optimize the |
| 971 | * behavior of the stream. |
| 972 | * This could, for example, affect whether a stream is paused when a notification occurs. |
| 973 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 974 | * The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}. |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 975 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 976 | * Available since API level 28. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 977 | * |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 978 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 979 | * @param contentType the type of audio data, eg. {@link #AAUDIO_CONTENT_TYPE_SPEECH} |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 980 | */ |
| 981 | AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 982 | aaudio_content_type_t contentType) __INTRODUCED_IN(28); |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 983 | |
| 984 | /** |
| 985 | * Set the input (capture) preset for the stream. |
| 986 | * |
| 987 | * The AAudio system will use this information to optimize the |
| 988 | * behavior of the stream. |
| 989 | * This could, for example, affect which microphones are used and how the |
| 990 | * recorded data is processed. |
| 991 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 992 | * The default, if you do not call this function, is {@link #AAUDIO_INPUT_PRESET_VOICE_RECOGNITION}. |
Phil Burk | eaef9b9 | 2018-01-18 09:09:42 -0800 | [diff] [blame] | 993 | * That is because VOICE_RECOGNITION is the preset with the lowest latency |
| 994 | * on many platforms. |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 995 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 996 | * Available since API level 28. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 997 | * |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 998 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 999 | * @param inputPreset the desired configuration for recording |
| 1000 | */ |
| 1001 | AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1002 | aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28); |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1003 | |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1004 | /** |
| 1005 | * Specify whether this stream audio may or may not be captured by other apps or the system. |
| 1006 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1007 | * The default is {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}. |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1008 | * |
| 1009 | * Note that an application can also set its global policy, in which case the most restrictive |
gfan | 4db8ba4 | 2021-04-06 15:05:30 -0700 | [diff] [blame] | 1010 | * policy is always applied. See |
| 1011 | * <a href="/reference/android/media/AudioManager#setAllowedCapturePolicy(int)"> |
| 1012 | * setAllowedCapturePolicy(int)</a> |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1013 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1014 | * Available since API level 29. |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1015 | * |
| 1016 | * @param builder reference provided by AAudio_createStreamBuilder() |
Glenn Kasten | d3080c3 | 2019-10-24 09:54:56 -0700 | [diff] [blame] | 1017 | * @param capturePolicy the desired level of opt-out from being captured. |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1018 | */ |
| 1019 | AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder, |
| 1020 | aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29); |
| 1021 | |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1022 | /** Set the requested session ID. |
| 1023 | * |
| 1024 | * The session ID can be used to associate a stream with effects processors. |
| 1025 | * The effects are controlled using the Android AudioEffect Java API. |
| 1026 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1027 | * The default, if you do not call this function, is {@link #AAUDIO_SESSION_ID_NONE}. |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1028 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1029 | * If set to {@link #AAUDIO_SESSION_ID_ALLOCATE} then a session ID will be allocated |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1030 | * when the stream is opened. |
| 1031 | * |
| 1032 | * The allocated session ID can be obtained by calling AAudioStream_getSessionId() |
| 1033 | * and then used with this function when opening another stream. |
| 1034 | * This allows effects to be shared between streams. |
| 1035 | * |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 1036 | * Session IDs from AAudio can be used with the Android Java APIs and vice versa. |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1037 | * So a session ID from an AAudio stream can be passed to Java |
| 1038 | * and effects applied using the Java AudioEffect API. |
| 1039 | * |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 1040 | * Note that allocating or setting a session ID may result in a stream with higher latency. |
| 1041 | * |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1042 | * Allocated session IDs will always be positive and nonzero. |
| 1043 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1044 | * Available since API level 28. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 1045 | * |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1046 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1047 | * @param sessionId an allocated sessionID or {@link #AAUDIO_SESSION_ID_ALLOCATE} |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1048 | */ |
| 1049 | AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1050 | aaudio_session_id_t sessionId) __INTRODUCED_IN(28); |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1051 | |
Eric Laurent | d17c850 | 2019-10-24 15:58:35 -0700 | [diff] [blame] | 1052 | |
| 1053 | /** Indicates whether this input stream must be marked as privacy sensitive or not. |
| 1054 | * |
| 1055 | * When true, this input stream is privacy sensitive and any concurrent capture |
| 1056 | * is not permitted. |
| 1057 | * |
| 1058 | * This is off (false) by default except when the input preset is {@link #AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION} |
| 1059 | * or {@link #AAUDIO_INPUT_PRESET_CAMCORDER}. |
| 1060 | * |
| 1061 | * Always takes precedence over default from input preset when set explicitly. |
| 1062 | * |
| 1063 | * Only relevant if the stream direction is {@link #AAUDIO_DIRECTION_INPUT}. |
| 1064 | * |
| 1065 | * Added in API level 30. |
| 1066 | * |
| 1067 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 1068 | * @param privacySensitive true if capture from this stream must be marked as privacy sensitive, |
| 1069 | * false otherwise. |
| 1070 | */ |
| 1071 | AAUDIO_API void AAudioStreamBuilder_setPrivacySensitive(AAudioStreamBuilder* builder, |
| 1072 | bool privacySensitive) __INTRODUCED_IN(30); |
| 1073 | |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1074 | /** |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1075 | * Return one of these values from the data callback function. |
| 1076 | */ |
| 1077 | enum { |
| 1078 | |
| 1079 | /** |
| 1080 | * Continue calling the callback. |
| 1081 | */ |
| 1082 | AAUDIO_CALLBACK_RESULT_CONTINUE = 0, |
| 1083 | |
| 1084 | /** |
| 1085 | * Stop calling the callback. |
| 1086 | * |
| 1087 | * The application will still need to call AAudioStream_requestPause() |
| 1088 | * or AAudioStream_requestStop(). |
| 1089 | */ |
| 1090 | AAUDIO_CALLBACK_RESULT_STOP, |
| 1091 | |
| 1092 | }; |
| 1093 | typedef int32_t aaudio_data_callback_result_t; |
| 1094 | |
| 1095 | /** |
| 1096 | * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback(). |
| 1097 | * |
| 1098 | * For an output stream, this function should render and write numFrames of data |
| 1099 | * in the streams current data format to the audioData buffer. |
| 1100 | * |
| 1101 | * For an input stream, this function should read and process numFrames of data |
| 1102 | * from the audioData buffer. |
| 1103 | * |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 1104 | * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or |
| 1105 | * AAudioStream_write() on the stream that is making the callback. |
| 1106 | * |
| 1107 | * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback() |
| 1108 | * is called. |
| 1109 | * |
| 1110 | * Also note that this callback function should be considered a "real-time" function. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1111 | * It must not do anything that could cause an unbounded delay because that can cause the |
| 1112 | * audio to glitch or pop. |
| 1113 | * |
| 1114 | * These are things the function should NOT do: |
| 1115 | * <ul> |
| 1116 | * <li>allocate memory using, for example, malloc() or new</li> |
| 1117 | * <li>any file operations such as opening, closing, reading or writing</li> |
| 1118 | * <li>any network operations such as streaming</li> |
| 1119 | * <li>use any mutexes or other synchronization primitives</li> |
| 1120 | * <li>sleep</li> |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 1121 | * <li>stop or close the stream</li> |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 1122 | * <li>AAudioStream_read()</li> |
| 1123 | * <li>AAudioStream_write()</li> |
| 1124 | * </ul> |
| 1125 | * |
| 1126 | * The following are OK to call from the data callback: |
| 1127 | * <ul> |
| 1128 | * <li>AAudioStream_get*()</li> |
| 1129 | * <li>AAudio_convertResultToText()</li> |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1130 | * </ul> |
| 1131 | * |
| 1132 | * If you need to move data, eg. MIDI commands, in or out of the callback function then |
| 1133 | * we recommend the use of non-blocking techniques such as an atomic FIFO. |
| 1134 | * |
| 1135 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1136 | * @param userData the same address that was passed to AAudioStreamBuilder_setCallback() |
| 1137 | * @param audioData a pointer to the audio data |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 1138 | * @param numFrames the number of frames to be processed, which can vary |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1139 | * @return AAUDIO_CALLBACK_RESULT_* |
| 1140 | */ |
| 1141 | typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)( |
| 1142 | AAudioStream *stream, |
| 1143 | void *userData, |
| 1144 | void *audioData, |
| 1145 | int32_t numFrames); |
| 1146 | |
| 1147 | /** |
| 1148 | * Request that AAudio call this functions when the stream is running. |
| 1149 | * |
| 1150 | * Note that when using this callback, the audio data will be passed in or out |
| 1151 | * of the function as an argument. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1152 | * So you cannot call AAudioStream_write() or AAudioStream_read() |
| 1153 | * on the same stream that has an active data callback. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1154 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1155 | * The callback function will start being called after AAudioStream_requestStart() |
| 1156 | * is called. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1157 | * It will stop being called after AAudioStream_requestPause() or |
| 1158 | * AAudioStream_requestStop() is called. |
| 1159 | * |
Phil Burk | 0cb1b54 | 2020-11-25 01:01:18 +0000 | [diff] [blame] | 1160 | * This callback function will be called on a real-time thread owned by AAudio. |
| 1161 | * The low latency streams may have callback threads with higher priority than normal streams. |
| 1162 | * See {@link #AAudioStream_dataCallback} for more information. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1163 | * |
| 1164 | * Note that the AAudio callbacks will never be called simultaneously from multiple threads. |
| 1165 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1166 | * Available since API level 26. |
| 1167 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1168 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 1169 | * @param callback pointer to a function that will process audio data. |
| 1170 | * @param userData pointer to an application data structure that will be passed |
| 1171 | * to the callback functions. |
| 1172 | */ |
| 1173 | AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1174 | AAudioStream_dataCallback callback, void *userData) __INTRODUCED_IN(26); |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1175 | |
| 1176 | /** |
| 1177 | * Set the requested data callback buffer size in frames. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1178 | * See {@link #AAudioStream_dataCallback}. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1179 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1180 | * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1181 | * |
| 1182 | * For the lowest possible latency, do not call this function. AAudio will then |
| 1183 | * call the dataProc callback function with whatever size is optimal. |
| 1184 | * That size may vary from one callback to another. |
| 1185 | * |
| 1186 | * Only use this function if the application requires a specific number of frames for processing. |
| 1187 | * The application might, for example, be using an FFT that requires |
| 1188 | * a specific power-of-two sized buffer. |
| 1189 | * |
| 1190 | * AAudio may need to add additional buffering in order to adapt between the internal |
| 1191 | * buffer size and the requested buffer size. |
| 1192 | * |
| 1193 | * If you do call this function then the requested size should be less than |
| 1194 | * half the buffer capacity, to allow double buffering. |
| 1195 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1196 | * Available since API level 26. |
| 1197 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1198 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1199 | * @param numFrames the desired buffer size in frames or {@link #AAUDIO_UNSPECIFIED} |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1200 | */ |
| 1201 | AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1202 | int32_t numFrames) __INTRODUCED_IN(26); |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1203 | |
| 1204 | /** |
| 1205 | * Prototype for the callback function that is passed to |
| 1206 | * AAudioStreamBuilder_setErrorCallback(). |
| 1207 | * |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 1208 | * The following may NOT be called from the error callback: |
| 1209 | * <ul> |
| 1210 | * <li>AAudioStream_requestStop()</li> |
| 1211 | * <li>AAudioStream_requestPause()</li> |
| 1212 | * <li>AAudioStream_close()</li> |
| 1213 | * <li>AAudioStream_waitForStateChange()</li> |
| 1214 | * <li>AAudioStream_read()</li> |
| 1215 | * <li>AAudioStream_write()</li> |
| 1216 | * </ul> |
| 1217 | * |
| 1218 | * The following are OK to call from the error callback: |
| 1219 | * <ul> |
| 1220 | * <li>AAudioStream_get*()</li> |
| 1221 | * <li>AAudio_convertResultToText()</li> |
| 1222 | * </ul> |
| 1223 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1224 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1225 | * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback() |
| 1226 | * @param error an AAUDIO_ERROR_* value. |
| 1227 | */ |
| 1228 | typedef void (*AAudioStream_errorCallback)( |
| 1229 | AAudioStream *stream, |
| 1230 | void *userData, |
| 1231 | aaudio_result_t error); |
| 1232 | |
| 1233 | /** |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 1234 | * Request that AAudio call this function if any error occurs or the stream is disconnected. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1235 | * |
| 1236 | * It will be called, for example, if a headset or a USB device is unplugged causing the stream's |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 1237 | * device to be unavailable or "disconnected". |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1238 | * Another possible cause of error would be a timeout or an unanticipated internal error. |
| 1239 | * |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 1240 | * In response, this function should signal or create another thread to stop |
| 1241 | * and close this stream. The other thread could then reopen a stream on another device. |
| 1242 | * Do not stop or close the stream, or reopen the new stream, directly from this callback. |
| 1243 | * |
| 1244 | * This callback will not be called because of actions by the application, such as stopping |
| 1245 | * or closing a stream. |
| 1246 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1247 | * Note that the AAudio callbacks will never be called simultaneously from multiple threads. |
| 1248 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1249 | * Available since API level 26. |
| 1250 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1251 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 1252 | * @param callback pointer to a function that will be called if an error occurs. |
| 1253 | * @param userData pointer to an application data structure that will be passed |
| 1254 | * to the callback functions. |
| 1255 | */ |
| 1256 | AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1257 | AAudioStream_errorCallback callback, void *userData) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1258 | |
| 1259 | /** |
| 1260 | * Open a stream based on the options in the StreamBuilder. |
| 1261 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1262 | * AAudioStream_close() must be called when finished with the stream to recover |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1263 | * the memory and to free the associated resources. |
| 1264 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1265 | * Available since API level 26. |
| 1266 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1267 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 1268 | * @param stream pointer to a variable to receive the new stream reference |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1269 | * @return {@link #AAUDIO_OK} or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1270 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 1271 | AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1272 | AAudioStream** stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1273 | |
| 1274 | /** |
| 1275 | * Delete the resources associated with the StreamBuilder. |
| 1276 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1277 | * Available since API level 26. |
| 1278 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1279 | * @param builder reference provided by AAudio_createStreamBuilder() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1280 | * @return {@link #AAUDIO_OK} or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1281 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1282 | AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder) |
| 1283 | __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1284 | |
jiabin | a909409 | 2021-06-28 20:36:45 +0000 | [diff] [blame] | 1285 | /** |
| 1286 | * Set audio channel mask for the stream. |
| 1287 | * |
| 1288 | * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. |
| 1289 | * If both channel mask and count are not set, then stereo will then be chosen when the |
| 1290 | * stream is opened. |
| 1291 | * After opening a stream with an unspecified value, the application must query for the |
| 1292 | * actual value, which may vary by device. |
| 1293 | * |
| 1294 | * If an exact value is specified then an opened stream will use that value. |
| 1295 | * If a stream cannot be opened with the specified value then the open will fail. |
| 1296 | * |
| 1297 | * As the corresponding channel count of provided channel mask here may be different |
| 1298 | * from the channel count used in {@link AAudioStreamBuilder_setChannelCount} or |
| 1299 | * {@link AAudioStreamBuilder_setSamplesPerFrame}, the last called function will be |
| 1300 | * respected if this function and {@link AAudioStreamBuilder_setChannelCount} or |
| 1301 | * {@link AAudioStreamBuilder_setSamplesPerFrame} are called. |
| 1302 | * |
| 1303 | * Available since API level 32. |
| 1304 | * |
| 1305 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 1306 | * @param channelMask Audio channel mask desired. |
| 1307 | */ |
| 1308 | AAUDIO_API void AAudioStreamBuilder_setChannelMask(AAudioStreamBuilder* builder, |
| 1309 | aaudio_channel_mask_t channelMask) __INTRODUCED_IN(32); |
| 1310 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1311 | // ============================================================ |
| 1312 | // Stream Control |
| 1313 | // ============================================================ |
| 1314 | |
| 1315 | /** |
Phil Burk | 8b4e05e | 2019-12-17 12:12:09 -0800 | [diff] [blame] | 1316 | * Free the audio resources associated with a stream created by |
| 1317 | * AAudioStreamBuilder_openStream(). |
| 1318 | * AAudioStream_close() should be called at some point after calling |
| 1319 | * this function. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1320 | * |
Phil Burk | 8b4e05e | 2019-12-17 12:12:09 -0800 | [diff] [blame] | 1321 | * After this call, the stream will be in {@link #AAUDIO_STREAM_STATE_CLOSING} |
| 1322 | * |
Phil Burk | 4156176 | 2020-02-05 14:20:33 -0800 | [diff] [blame] | 1323 | * This function is useful if you want to release the audio resources immediately, |
| 1324 | * but still allow queries to the stream to occur from other threads. This often |
| 1325 | * happens if you are monitoring stream progress from a UI thread. |
| 1326 | * |
Phil Burk | 320910f | 2020-08-12 14:29:10 +0000 | [diff] [blame] | 1327 | * NOTE: This function is only fully implemented for MMAP streams, |
| 1328 | * which are low latency streams supported by some devices. |
| 1329 | * On other "Legacy" streams some audio resources will still be in use |
| 1330 | * and some callbacks may still be in process after this call. |
| 1331 | * |
Elliott Hughes | 81fc859 | 2021-01-26 16:45:07 -0800 | [diff] [blame] | 1332 | * Available since API level 30. |
| 1333 | * |
Phil Burk | 8b4e05e | 2019-12-17 12:12:09 -0800 | [diff] [blame] | 1334 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1335 | * @return {@link #AAUDIO_OK} or a negative error. |
| 1336 | */ |
| 1337 | AAUDIO_API aaudio_result_t AAudioStream_release(AAudioStream* stream) __INTRODUCED_IN(30); |
Phil Burk | 8b4e05e | 2019-12-17 12:12:09 -0800 | [diff] [blame] | 1338 | |
| 1339 | /** |
| 1340 | * Delete the internal data structures associated with the stream created |
| 1341 | * by AAudioStreamBuilder_openStream(). |
| 1342 | * |
| 1343 | * If AAudioStream_release() has not been called then it will be called automatically. |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1344 | * |
Elliott Hughes | 81fc859 | 2021-01-26 16:45:07 -0800 | [diff] [blame] | 1345 | * Available since API level 26. |
| 1346 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1347 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1348 | * @return {@link #AAUDIO_OK} or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1349 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1350 | AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1351 | |
| 1352 | /** |
| 1353 | * Asynchronously request to start playing the stream. For output streams, one should |
| 1354 | * write to the stream to fill the buffer before starting. |
| 1355 | * Otherwise it will underflow. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1356 | * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STARTING} or |
| 1357 | * {@link #AAUDIO_STREAM_STATE_STARTED}. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1358 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1359 | * Available since API level 26. |
| 1360 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1361 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1362 | * @return {@link #AAUDIO_OK} or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1363 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1364 | AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1365 | |
| 1366 | /** |
| 1367 | * Asynchronous request for the stream to pause. |
| 1368 | * Pausing a stream will freeze the data flow but not flush any buffers. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1369 | * Use AAudioStream_requestStart() to resume playback after a pause. |
| 1370 | * After this call the state will be in {@link #AAUDIO_STREAM_STATE_PAUSING} or |
| 1371 | * {@link #AAUDIO_STREAM_STATE_PAUSED}. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1372 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1373 | * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams. |
Phil Burk | 068c10f | 2017-05-08 16:36:41 -0700 | [diff] [blame] | 1374 | * For input streams use AAudioStream_requestStop(). |
| 1375 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1376 | * Available since API level 26. |
| 1377 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1378 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1379 | * @return {@link #AAUDIO_OK} or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1380 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1381 | AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1382 | |
| 1383 | /** |
| 1384 | * Asynchronous request for the stream to flush. |
| 1385 | * Flushing will discard any pending data. |
| 1386 | * This call only works if the stream is pausing or paused. TODO review |
| 1387 | * Frame counters are not reset by a flush. They may be advanced. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1388 | * After this call the state will be in {@link #AAUDIO_STREAM_STATE_FLUSHING} or |
| 1389 | * {@link #AAUDIO_STREAM_STATE_FLUSHED}. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1390 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1391 | * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams. |
Phil Burk | 068c10f | 2017-05-08 16:36:41 -0700 | [diff] [blame] | 1392 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1393 | * Available since API level 26. |
| 1394 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1395 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1396 | * @return {@link #AAUDIO_OK} or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1397 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1398 | AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1399 | |
| 1400 | /** |
| 1401 | * Asynchronous request for the stream to stop. |
| 1402 | * The stream will stop after all of the data currently buffered has been played. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1403 | * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STOPPING} or |
| 1404 | * {@link #AAUDIO_STREAM_STATE_STOPPED}. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1405 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1406 | * Available since API level 26. |
| 1407 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1408 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1409 | * @return {@link #AAUDIO_OK} or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1410 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1411 | AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1412 | |
| 1413 | /** |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1414 | * Query the current state of the client, eg. {@link #AAUDIO_STREAM_STATE_PAUSING} |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1415 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1416 | * This function will immediately return the state without updating the state. |
| 1417 | * If you want to update the client state based on the server state then |
| 1418 | * call AAudioStream_waitForStateChange() with currentState |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1419 | * set to {@link #AAUDIO_STREAM_STATE_UNKNOWN} and a zero timeout. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1420 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1421 | * Available since API level 26. |
| 1422 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1423 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1424 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1425 | AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1426 | |
| 1427 | /** |
| 1428 | * Wait until the current state no longer matches the input state. |
| 1429 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1430 | * This will update the current client state. |
| 1431 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1432 | * <pre><code> |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 1433 | * aaudio_result_t result = AAUDIO_OK; |
| 1434 | * aaudio_stream_state_t currentState = AAudioStream_getState(stream); |
| 1435 | * aaudio_stream_state_t inputState = currentState; |
| 1436 | * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) { |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1437 | * result = AAudioStream_waitForStateChange( |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 1438 | * stream, inputState, ¤tState, MY_TIMEOUT_NANOS); |
| 1439 | * inputState = currentState; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1440 | * } |
| 1441 | * </code></pre> |
| 1442 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1443 | * Available since API level 26. |
| 1444 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1445 | * @param stream A reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1446 | * @param inputState The state we want to avoid. |
| 1447 | * @param nextState Pointer to a variable that will be set to the new state. |
| 1448 | * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion. |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1449 | * @return {@link #AAUDIO_OK} or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1450 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 1451 | AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1452 | aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState, |
| 1453 | int64_t timeoutNanoseconds) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1454 | |
| 1455 | // ============================================================ |
| 1456 | // Stream I/O |
| 1457 | // ============================================================ |
| 1458 | |
| 1459 | /** |
| 1460 | * Read data from the stream. |
| 1461 | * |
| 1462 | * The call will wait until the read is complete or until it runs out of time. |
| 1463 | * If timeoutNanos is zero then this call will not wait. |
| 1464 | * |
| 1465 | * Note that timeoutNanoseconds is a relative duration in wall clock time. |
| 1466 | * Time will not stop if the thread is asleep. |
| 1467 | * So it will be implemented using CLOCK_BOOTTIME. |
| 1468 | * |
| 1469 | * This call is "strong non-blocking" unless it has to wait for data. |
| 1470 | * |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 1471 | * If the call times out then zero or a partial frame count will be returned. |
| 1472 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1473 | * Available since API level 26. |
| 1474 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1475 | * @param stream A stream created using AAudioStreamBuilder_openStream(). |
| 1476 | * @param buffer The address of the first sample. |
| 1477 | * @param numFrames Number of frames to read. Only complete frames will be written. |
| 1478 | * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1479 | * @return The number of frames actually read or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1480 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 1481 | AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1482 | void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1483 | |
| 1484 | /** |
| 1485 | * Write data to the stream. |
| 1486 | * |
| 1487 | * The call will wait until the write is complete or until it runs out of time. |
| 1488 | * If timeoutNanos is zero then this call will not wait. |
| 1489 | * |
| 1490 | * Note that timeoutNanoseconds is a relative duration in wall clock time. |
| 1491 | * Time will not stop if the thread is asleep. |
| 1492 | * So it will be implemented using CLOCK_BOOTTIME. |
| 1493 | * |
| 1494 | * This call is "strong non-blocking" unless it has to wait for room in the buffer. |
| 1495 | * |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 1496 | * If the call times out then zero or a partial frame count will be returned. |
| 1497 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1498 | * Available since API level 26. |
| 1499 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1500 | * @param stream A stream created using AAudioStreamBuilder_openStream(). |
| 1501 | * @param buffer The address of the first sample. |
| 1502 | * @param numFrames Number of frames to write. Only complete frames will be written. |
| 1503 | * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion. |
| 1504 | * @return The number of frames actually written or a negative error. |
| 1505 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 1506 | AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1507 | const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1508 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1509 | // ============================================================ |
| 1510 | // Stream - queries |
| 1511 | // ============================================================ |
| 1512 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1513 | /** |
| 1514 | * This can be used to adjust the latency of the buffer by changing |
| 1515 | * the threshold where blocking will occur. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1516 | * By combining this with AAudioStream_getXRunCount(), the latency can be tuned |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1517 | * at run-time for each device. |
| 1518 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1519 | * This cannot be set higher than AAudioStream_getBufferCapacityInFrames(). |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1520 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1521 | * Note that you will probably not get the exact size you request. |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 1522 | * You can check the return value or call AAudioStream_getBufferSizeInFrames() |
| 1523 | * to see what the actual final size is. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1524 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1525 | * Available since API level 26. |
| 1526 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1527 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1528 | * @param numFrames requested number of frames that can be filled without blocking |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1529 | * @return actual buffer size in frames or a negative error |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1530 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 1531 | AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1532 | int32_t numFrames) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1533 | |
| 1534 | /** |
| 1535 | * Query the maximum number of frames that can be filled without blocking. |
| 1536 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1537 | * Available since API level 26. |
| 1538 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1539 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1540 | * @return buffer size in frames. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1541 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1542 | AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1543 | |
| 1544 | /** |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1545 | * Query the number of frames that the application should read or write at |
| 1546 | * one time for optimal performance. It is OK if an application writes |
| 1547 | * a different number of frames. But the buffer size may need to be larger |
| 1548 | * in order to avoid underruns or overruns. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1549 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1550 | * Note that this may or may not match the actual device burst size. |
| 1551 | * For some endpoints, the burst size can vary dynamically. |
| 1552 | * But these tend to be devices with high latency. |
| 1553 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1554 | * Available since API level 26. |
| 1555 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1556 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1557 | * @return burst size |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1558 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1559 | AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1560 | |
| 1561 | /** |
| 1562 | * Query maximum buffer capacity in frames. |
| 1563 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1564 | * Available since API level 26. |
| 1565 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1566 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1567 | * @return buffer capacity in frames |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1568 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1569 | AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1570 | |
| 1571 | /** |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1572 | * Query the size of the buffer that will be passed to the dataProc callback |
| 1573 | * in the numFrames parameter. |
| 1574 | * |
| 1575 | * This call can be used if the application needs to know the value of numFrames before |
| 1576 | * the stream is started. This is not normally necessary. |
| 1577 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1578 | * If a specific size was requested by calling |
| 1579 | * AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1580 | * |
Phil Burk | ed0a3fe | 2017-12-05 14:27:43 -0800 | [diff] [blame] | 1581 | * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1582 | * return the size chosen by AAudio, or {@link #AAUDIO_UNSPECIFIED}. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1583 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1584 | * {@link #AAUDIO_UNSPECIFIED} indicates that the callback buffer size for this stream |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1585 | * may vary from one dataProc callback to the next. |
| 1586 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1587 | * Available since API level 26. |
| 1588 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1589 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1590 | * @return callback buffer size in frames or {@link #AAUDIO_UNSPECIFIED} |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1591 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1592 | AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 1593 | |
| 1594 | /** |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1595 | * An XRun is an Underrun or an Overrun. |
| 1596 | * During playing, an underrun will occur if the stream is not written in time |
| 1597 | * and the system runs out of valid data. |
| 1598 | * During recording, an overrun will occur if the stream is not read in time |
| 1599 | * and there is no place to put the incoming data so it is discarded. |
| 1600 | * |
| 1601 | * An underrun or overrun can cause an audible "pop" or "glitch". |
| 1602 | * |
Phil Burk | 068c10f | 2017-05-08 16:36:41 -0700 | [diff] [blame] | 1603 | * Note that some INPUT devices may not support this function. |
| 1604 | * In that case a 0 will always be returned. |
| 1605 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1606 | * Available since API level 26. |
| 1607 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1608 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1609 | * @return the underrun or overrun count |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1610 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1611 | AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1612 | |
| 1613 | /** |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1614 | * Available since API level 26. |
| 1615 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1616 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1617 | * @return actual sample rate |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1618 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1619 | AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1620 | |
| 1621 | /** |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame] | 1622 | * A stream has one or more channels of data. |
| 1623 | * A frame will contain one sample for each channel. |
| 1624 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1625 | * Available since API level 26. |
| 1626 | * |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame] | 1627 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1628 | * @return actual number of channels |
| 1629 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1630 | AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame] | 1631 | |
| 1632 | /** |
Phil Burk | e74240d | 2017-08-03 15:25:43 -0700 | [diff] [blame] | 1633 | * Identical to AAudioStream_getChannelCount(). |
| 1634 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1635 | * Available since API level 26. |
| 1636 | * |
Phil Burk | e74240d | 2017-08-03 15:25:43 -0700 | [diff] [blame] | 1637 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1638 | * @return actual number of samples frame |
| 1639 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1640 | AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | e74240d | 2017-08-03 15:25:43 -0700 | [diff] [blame] | 1641 | |
| 1642 | /** |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1643 | * Available since API level 26. |
| 1644 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1645 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 1646 | * @return actual device ID |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1647 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1648 | AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1649 | |
| 1650 | /** |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1651 | * Available since API level 26. |
| 1652 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1653 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1654 | * @return actual data format |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1655 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1656 | AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1657 | |
| 1658 | /** |
| 1659 | * Provide actual sharing mode. |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1660 | * |
| 1661 | * Available since API level 26. |
| 1662 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1663 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1664 | * @return actual sharing mode |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1665 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1666 | AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream) |
| 1667 | __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1668 | |
| 1669 | /** |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 1670 | * Get the performance mode used by the stream. |
| 1671 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1672 | * Available since API level 26. |
| 1673 | * |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 1674 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1675 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1676 | AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream) |
| 1677 | __INTRODUCED_IN(26); |
Phil Burk | e2fbb59 | 2017-05-01 15:05:52 -0700 | [diff] [blame] | 1678 | |
| 1679 | /** |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1680 | * Available since API level 26. |
| 1681 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1682 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1683 | * @return direction |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1684 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1685 | AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1686 | |
| 1687 | /** |
| 1688 | * Passes back the number of frames that have been written since the stream was created. |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 1689 | * For an output stream, this will be advanced by the application calling write() |
| 1690 | * or by a data callback. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1691 | * For an input stream, this will be advanced by the endpoint. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1692 | * |
| 1693 | * The frame position is monotonically increasing. |
| 1694 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1695 | * Available since API level 26. |
| 1696 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1697 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1698 | * @return frames written |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1699 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1700 | AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1701 | |
| 1702 | /** |
| 1703 | * Passes back the number of frames that have been read since the stream was created. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1704 | * For an output stream, this will be advanced by the endpoint. |
Phil Burk | 8149eed | 2018-05-24 14:09:46 -0700 | [diff] [blame] | 1705 | * For an input stream, this will be advanced by the application calling read() |
| 1706 | * or by a data callback. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1707 | * |
| 1708 | * The frame position is monotonically increasing. |
| 1709 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1710 | * Available since API level 26. |
| 1711 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1712 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1713 | * @return frames read |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1714 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1715 | AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1716 | |
| 1717 | /** |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1718 | * Passes back the session ID associated with this stream. |
| 1719 | * |
| 1720 | * The session ID can be used to associate a stream with effects processors. |
| 1721 | * The effects are controlled using the Android AudioEffect Java API. |
| 1722 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1723 | * If AAudioStreamBuilder_setSessionId() was |
| 1724 | * called with {@link #AAUDIO_SESSION_ID_ALLOCATE} |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1725 | * then a new session ID should be allocated once when the stream is opened. |
| 1726 | * |
| 1727 | * If AAudioStreamBuilder_setSessionId() was called with a previously allocated |
| 1728 | * session ID then that value should be returned. |
| 1729 | * |
| 1730 | * If AAudioStreamBuilder_setSessionId() was not called then this function should |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1731 | * return {@link #AAUDIO_SESSION_ID_NONE}. |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1732 | * |
| 1733 | * The sessionID for a stream should not change once the stream has been opened. |
| 1734 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1735 | * Available since API level 28. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 1736 | * |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1737 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1738 | * @return session ID or {@link #AAUDIO_SESSION_ID_NONE} |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1739 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1740 | AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream) __INTRODUCED_IN(28); |
Phil Burk | 7e7dcaa | 2018-01-03 15:16:15 -0800 | [diff] [blame] | 1741 | |
| 1742 | /** |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1743 | * Passes back the time at which a particular frame was presented. |
| 1744 | * This can be used to synchronize audio with video or MIDI. |
| 1745 | * It can also be used to align a recorded stream with a playback stream. |
| 1746 | * |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1747 | * Timestamps are only valid when the stream is in {@link #AAUDIO_STREAM_STATE_STARTED}. |
| 1748 | * {@link #AAUDIO_ERROR_INVALID_STATE} will be returned if the stream is not started. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1749 | * Note that because requestStart() is asynchronous, timestamps will not be valid until |
| 1750 | * a short time after calling requestStart(). |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1751 | * So {@link #AAUDIO_ERROR_INVALID_STATE} should not be considered a fatal error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1752 | * Just try calling again later. |
| 1753 | * |
| 1754 | * If an error occurs, then the position and time will not be modified. |
| 1755 | * |
| 1756 | * The position and time passed back are monotonically increasing. |
| 1757 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1758 | * Available since API level 26. |
| 1759 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 1760 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | ec15950 | 2017-07-25 17:33:47 -0700 | [diff] [blame] | 1761 | * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1762 | * @param framePosition pointer to a variable to receive the position |
| 1763 | * @param timeNanoseconds pointer to a variable to receive the time |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1764 | * @return {@link #AAUDIO_OK} or a negative error |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1765 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 1766 | AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream, |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1767 | clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds) __INTRODUCED_IN(26); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1768 | |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1769 | /** |
| 1770 | * Return the use case for the stream. |
| 1771 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1772 | * Available since API level 28. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 1773 | * |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1774 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1775 | * @return frames read |
| 1776 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1777 | AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream) __INTRODUCED_IN(28); |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1778 | |
| 1779 | /** |
| 1780 | * Return the content type for the stream. |
| 1781 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1782 | * Available since API level 28. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 1783 | * |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1784 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1785 | * @return content type, for example {@link #AAUDIO_CONTENT_TYPE_MUSIC} |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1786 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1787 | AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream) |
| 1788 | __INTRODUCED_IN(28); |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1789 | |
| 1790 | /** |
| 1791 | * Return the input preset for the stream. |
| 1792 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1793 | * Available since API level 28. |
Phil Burk | 42452c0 | 2018-04-10 12:43:33 -0700 | [diff] [blame] | 1794 | * |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1795 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1796 | * @return input preset, for example {@link #AAUDIO_INPUT_PRESET_CAMCORDER} |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1797 | */ |
Elliott Hughes | 85a4153 | 2018-06-18 13:17:24 -0700 | [diff] [blame] | 1798 | AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream) |
| 1799 | __INTRODUCED_IN(28); |
Phil Burk | 361b142 | 2017-12-20 14:24:16 -0800 | [diff] [blame] | 1800 | |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1801 | /** |
| 1802 | * Return the policy that determines whether the audio may or may not be captured |
| 1803 | * by other apps or the system. |
| 1804 | * |
Elliott Hughes | 64a3b06 | 2019-10-29 10:09:30 -0700 | [diff] [blame] | 1805 | * Available since API level 29. |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1806 | * |
| 1807 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Kevin Rocard | fb7e846 | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1808 | * @return the allowed capture policy, for example {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL} |
Kevin Rocard | 68646ba | 2019-03-20 13:26:49 -0700 | [diff] [blame] | 1809 | */ |
| 1810 | AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy( |
| 1811 | AAudioStream* stream) __INTRODUCED_IN(29); |
| 1812 | |
Eric Laurent | d17c850 | 2019-10-24 15:58:35 -0700 | [diff] [blame] | 1813 | |
| 1814 | /** |
| 1815 | * Return whether this input stream is marked as privacy sensitive or not. |
| 1816 | * |
| 1817 | * See {@link #AAudioStreamBuilder_setPrivacySensitive()}. |
| 1818 | * |
| 1819 | * Added in API level 30. |
| 1820 | * |
| 1821 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1822 | * @return true if privacy sensitive, false otherwise |
| 1823 | */ |
| 1824 | AAUDIO_API bool AAudioStream_isPrivacySensitive(AAudioStream* stream) |
| 1825 | __INTRODUCED_IN(30); |
| 1826 | |
jiabin | a909409 | 2021-06-28 20:36:45 +0000 | [diff] [blame] | 1827 | /** |
| 1828 | * Return the channel mask for the stream. This will be the mask set using |
| 1829 | * {@link #AAudioStreamBuilder_setChannelMask}, or {@link #AAUDIO_UNSPECIFIED} otherwise. |
| 1830 | * |
| 1831 | * Available since API level 32. |
| 1832 | * |
| 1833 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 1834 | * @return actual channel mask |
| 1835 | */ |
| 1836 | AAUDIO_API aaudio_channel_mask_t AAudioStream_getChannelMask(AAudioStream* stream) |
| 1837 | __INTRODUCED_IN(32); |
| 1838 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1839 | #ifdef __cplusplus |
| 1840 | } |
| 1841 | #endif |
| 1842 | |
| 1843 | #endif //AAUDIO_AAUDIO_H |
Phil Burk | a45be8b | 2017-04-05 14:45:48 -0700 | [diff] [blame] | 1844 | |
| 1845 | /** @} */ |