1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18 #ifndef ANDROID_AUDIO_CORE_H 19 #define ANDROID_AUDIO_CORE_H 20 21 #include <stdbool.h> 22 #include <stdint.h> 23 #include <sys/cdefs.h> 24 #include <sys/types.h> 25 26 #include <cutils/bitops.h> 27 28 __BEGIN_DECLS 29 30 /* The enums were moved here mostly from 31 * frameworks/base/include/media/AudioSystem.h 32 */ 33 34 /* device address used to refer to the standard remote submix */ 35 #define AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS "0" 36 37 typedef int audio_io_handle_t; 38 39 /* Audio stream types */ 40 typedef enum { 41 AUDIO_STREAM_DEFAULT = -1, 42 AUDIO_STREAM_VOICE_CALL = 0, 43 AUDIO_STREAM_SYSTEM = 1, 44 AUDIO_STREAM_RING = 2, 45 AUDIO_STREAM_MUSIC = 3, 46 AUDIO_STREAM_ALARM = 4, 47 AUDIO_STREAM_NOTIFICATION = 5, 48 AUDIO_STREAM_BLUETOOTH_SCO = 6, 49 AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user and must be routed to speaker */ 50 AUDIO_STREAM_DTMF = 8, 51 AUDIO_STREAM_TTS = 9, 52 53 AUDIO_STREAM_CNT, 54 AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1, 55 } audio_stream_type_t; 56 57 /* Do not change these values without updating their counterparts 58 * in media/java/android/media/MediaRecorder.java! 59 */ 60 typedef enum { 61 AUDIO_SOURCE_DEFAULT = 0, 62 AUDIO_SOURCE_MIC = 1, 63 AUDIO_SOURCE_VOICE_UPLINK = 2, 64 AUDIO_SOURCE_VOICE_DOWNLINK = 3, 65 AUDIO_SOURCE_VOICE_CALL = 4, 66 AUDIO_SOURCE_CAMCORDER = 5, 67 AUDIO_SOURCE_VOICE_RECOGNITION = 6, 68 AUDIO_SOURCE_VOICE_COMMUNICATION = 7, 69 AUDIO_SOURCE_REMOTE_SUBMIX = 8, /* Source for the mix to be presented remotely. */ 70 /* An example of remote presentation is Wifi Display */ 71 /* where a dongle attached to a TV can be used to */ 72 /* play the mix captured by this audio source. */ 73 AUDIO_SOURCE_CNT, 74 AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1, 75 AUDIO_SOURCE_HOTWORD = 1999, /* A low-priority, preemptible audio source for 76 for background software hotword detection. 77 Same tuning as AUDIO_SOURCE_VOICE_RECOGNITION. 78 Used only internally to the framework. Not exposed 79 at the audio HAL. */ 80 } audio_source_t; 81 82 /* special audio session values 83 * (XXX: should this be living in the audio effects land?) 84 */ 85 typedef enum { 86 /* session for effects attached to a particular output stream 87 * (value must be less than 0) 88 */ 89 AUDIO_SESSION_OUTPUT_STAGE = -1, 90 91 /* session for effects applied to output mix. These effects can 92 * be moved by audio policy manager to another output stream 93 * (value must be 0) 94 */ 95 AUDIO_SESSION_OUTPUT_MIX = 0, 96 } audio_session_t; 97 98 /* Audio sub formats (see enum audio_format). */ 99 100 /* PCM sub formats */ 101 typedef enum { 102 AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */ 103 AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */ 104 AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */ 105 AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */ 106 } audio_format_pcm_sub_fmt_t; 107 108 /* MP3 sub format field definition : can use 11 LSBs in the same way as MP3 109 * frame header to specify bit rate, stereo mode, version... 110 */ 111 typedef enum { 112 AUDIO_FORMAT_MP3_SUB_NONE = 0x0, 113 } audio_format_mp3_sub_fmt_t; 114 115 /* AMR NB/WB sub format field definition: specify frame block interleaving, 116 * bandwidth efficient or octet aligned, encoding mode for recording... 117 */ 118 typedef enum { 119 AUDIO_FORMAT_AMR_SUB_NONE = 0x0, 120 } audio_format_amr_sub_fmt_t; 121 122 /* AAC sub format field definition: specify profile or bitrate for recording... */ 123 typedef enum { 124 AUDIO_FORMAT_AAC_SUB_NONE = 0x0, 125 } audio_format_aac_sub_fmt_t; 126 127 /* VORBIS sub format field definition: specify quality for recording... */ 128 typedef enum { 129 AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0, 130 } audio_format_vorbis_sub_fmt_t; 131 132 /* Audio format consists in a main format field (upper 8 bits) and a sub format 133 * field (lower 24 bits). 134 * 135 * The main format indicates the main codec type. The sub format field 136 * indicates options and parameters for each format. The sub format is mainly 137 * used for record to indicate for instance the requested bitrate or profile. 138 * It can also be used for certain formats to give informations not present in 139 * the encoded audio stream (e.g. octet alignement for AMR). 140 */ 141 typedef enum { 142 AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL, 143 AUDIO_FORMAT_DEFAULT = 0, 144 AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */ 145 AUDIO_FORMAT_MP3 = 0x01000000UL, 146 AUDIO_FORMAT_AMR_NB = 0x02000000UL, 147 AUDIO_FORMAT_AMR_WB = 0x03000000UL, 148 AUDIO_FORMAT_AAC = 0x04000000UL, 149 AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL, 150 AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL, 151 AUDIO_FORMAT_VORBIS = 0x07000000UL, 152 AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL, 153 AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL, 154 155 /* Aliases */ 156 AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM | 157 AUDIO_FORMAT_PCM_SUB_16_BIT), 158 AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM | 159 AUDIO_FORMAT_PCM_SUB_8_BIT), 160 AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM | 161 AUDIO_FORMAT_PCM_SUB_32_BIT), 162 AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM | 163 AUDIO_FORMAT_PCM_SUB_8_24_BIT), 164 } audio_format_t; 165 166 enum { 167 /* output channels */ 168 AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x1, 169 AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x2, 170 AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x4, 171 AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x8, 172 AUDIO_CHANNEL_OUT_BACK_LEFT = 0x10, 173 AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x20, 174 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40, 175 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80, 176 AUDIO_CHANNEL_OUT_BACK_CENTER = 0x100, 177 AUDIO_CHANNEL_OUT_SIDE_LEFT = 0x200, 178 AUDIO_CHANNEL_OUT_SIDE_RIGHT = 0x400, 179 AUDIO_CHANNEL_OUT_TOP_CENTER = 0x800, 180 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT = 0x1000, 181 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER = 0x2000, 182 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT = 0x4000, 183 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT = 0x8000, 184 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER = 0x10000, 185 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT = 0x20000, 186 187 AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT, 188 AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 189 AUDIO_CHANNEL_OUT_FRONT_RIGHT), 190 AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 191 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 192 AUDIO_CHANNEL_OUT_BACK_LEFT | 193 AUDIO_CHANNEL_OUT_BACK_RIGHT), 194 AUDIO_CHANNEL_OUT_SURROUND = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 195 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 196 AUDIO_CHANNEL_OUT_FRONT_CENTER | 197 AUDIO_CHANNEL_OUT_BACK_CENTER), 198 AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 199 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 200 AUDIO_CHANNEL_OUT_FRONT_CENTER | 201 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 202 AUDIO_CHANNEL_OUT_BACK_LEFT | 203 AUDIO_CHANNEL_OUT_BACK_RIGHT), 204 // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1 205 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 206 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 207 AUDIO_CHANNEL_OUT_FRONT_CENTER | 208 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 209 AUDIO_CHANNEL_OUT_BACK_LEFT | 210 AUDIO_CHANNEL_OUT_BACK_RIGHT | 211 AUDIO_CHANNEL_OUT_SIDE_LEFT | 212 AUDIO_CHANNEL_OUT_SIDE_RIGHT), 213 AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 214 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 215 AUDIO_CHANNEL_OUT_FRONT_CENTER | 216 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 217 AUDIO_CHANNEL_OUT_BACK_LEFT | 218 AUDIO_CHANNEL_OUT_BACK_RIGHT | 219 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER | 220 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | 221 AUDIO_CHANNEL_OUT_BACK_CENTER| 222 AUDIO_CHANNEL_OUT_SIDE_LEFT| 223 AUDIO_CHANNEL_OUT_SIDE_RIGHT| 224 AUDIO_CHANNEL_OUT_TOP_CENTER| 225 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT| 226 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER| 227 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT| 228 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT| 229 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER| 230 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT), 231 232 /* input channels */ 233 AUDIO_CHANNEL_IN_LEFT = 0x4, 234 AUDIO_CHANNEL_IN_RIGHT = 0x8, 235 AUDIO_CHANNEL_IN_FRONT = 0x10, 236 AUDIO_CHANNEL_IN_BACK = 0x20, 237 AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40, 238 AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80, 239 AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100, 240 AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200, 241 AUDIO_CHANNEL_IN_PRESSURE = 0x400, 242 AUDIO_CHANNEL_IN_X_AXIS = 0x800, 243 AUDIO_CHANNEL_IN_Y_AXIS = 0x1000, 244 AUDIO_CHANNEL_IN_Z_AXIS = 0x2000, 245 AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000, 246 AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000, 247 248 AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT, 249 AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT), 250 AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK), 251 AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT | 252 AUDIO_CHANNEL_IN_RIGHT | 253 AUDIO_CHANNEL_IN_FRONT | 254 AUDIO_CHANNEL_IN_BACK| 255 AUDIO_CHANNEL_IN_LEFT_PROCESSED | 256 AUDIO_CHANNEL_IN_RIGHT_PROCESSED | 257 AUDIO_CHANNEL_IN_FRONT_PROCESSED | 258 AUDIO_CHANNEL_IN_BACK_PROCESSED| 259 AUDIO_CHANNEL_IN_PRESSURE | 260 AUDIO_CHANNEL_IN_X_AXIS | 261 AUDIO_CHANNEL_IN_Y_AXIS | 262 AUDIO_CHANNEL_IN_Z_AXIS | 263 AUDIO_CHANNEL_IN_VOICE_UPLINK | 264 AUDIO_CHANNEL_IN_VOICE_DNLINK), 265 }; 266 267 typedef uint32_t audio_channel_mask_t; 268 269 typedef enum { 270 AUDIO_MODE_INVALID = -2, 271 AUDIO_MODE_CURRENT = -1, 272 AUDIO_MODE_NORMAL = 0, 273 AUDIO_MODE_RINGTONE = 1, 274 AUDIO_MODE_IN_CALL = 2, 275 AUDIO_MODE_IN_COMMUNICATION = 3, 276 277 AUDIO_MODE_CNT, 278 AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1, 279 } audio_mode_t; 280 281 typedef enum { 282 AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001, 283 AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0, 284 AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002, 285 AUDIO_IN_ACOUSTICS_NS_DISABLE = 0, 286 AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004, 287 AUDIO_IN_ACOUSTICS_TX_DISABLE = 0, 288 } audio_in_acoustics_t; 289 290 enum { 291 AUDIO_DEVICE_NONE = 0x0, 292 /* reserved bits */ 293 AUDIO_DEVICE_BIT_IN = 0x80000000, 294 AUDIO_DEVICE_BIT_DEFAULT = 0x40000000, 295 /* output devices */ 296 AUDIO_DEVICE_OUT_EARPIECE = 0x1, 297 AUDIO_DEVICE_OUT_SPEAKER = 0x2, 298 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4, 299 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8, 300 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10, 301 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20, 302 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40, 303 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80, 304 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100, 305 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200, 306 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400, 307 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800, 308 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000, 309 AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000, 310 AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000, 311 AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000, 312 AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT, 313 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE | 314 AUDIO_DEVICE_OUT_SPEAKER | 315 AUDIO_DEVICE_OUT_WIRED_HEADSET | 316 AUDIO_DEVICE_OUT_WIRED_HEADPHONE | 317 AUDIO_DEVICE_OUT_BLUETOOTH_SCO | 318 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | 319 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT | 320 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | 321 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | 322 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | 323 AUDIO_DEVICE_OUT_AUX_DIGITAL | 324 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | 325 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | 326 AUDIO_DEVICE_OUT_USB_ACCESSORY | 327 AUDIO_DEVICE_OUT_USB_DEVICE | 328 AUDIO_DEVICE_OUT_REMOTE_SUBMIX | 329 AUDIO_DEVICE_OUT_DEFAULT), 330 AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | 331 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | 332 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER), 333 AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO | 334 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | 335 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT), 336 AUDIO_DEVICE_OUT_ALL_USB = (AUDIO_DEVICE_OUT_USB_ACCESSORY | 337 AUDIO_DEVICE_OUT_USB_DEVICE), 338 339 /* input devices */ 340 AUDIO_DEVICE_IN_COMMUNICATION = AUDIO_DEVICE_BIT_IN | 0x1, 341 AUDIO_DEVICE_IN_AMBIENT = AUDIO_DEVICE_BIT_IN | 0x2, 342 AUDIO_DEVICE_IN_BUILTIN_MIC = AUDIO_DEVICE_BIT_IN | 0x4, 343 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8, 344 AUDIO_DEVICE_IN_WIRED_HEADSET = AUDIO_DEVICE_BIT_IN | 0x10, 345 AUDIO_DEVICE_IN_AUX_DIGITAL = AUDIO_DEVICE_BIT_IN | 0x20, 346 AUDIO_DEVICE_IN_VOICE_CALL = AUDIO_DEVICE_BIT_IN | 0x40, 347 AUDIO_DEVICE_IN_BACK_MIC = AUDIO_DEVICE_BIT_IN | 0x80, 348 AUDIO_DEVICE_IN_REMOTE_SUBMIX = AUDIO_DEVICE_BIT_IN | 0x100, 349 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x200, 350 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x400, 351 AUDIO_DEVICE_IN_USB_ACCESSORY = AUDIO_DEVICE_BIT_IN | 0x800, 352 AUDIO_DEVICE_IN_USB_DEVICE = AUDIO_DEVICE_BIT_IN | 0x1000, 353 AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT, 354 355 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION | 356 AUDIO_DEVICE_IN_AMBIENT | 357 AUDIO_DEVICE_IN_BUILTIN_MIC | 358 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET | 359 AUDIO_DEVICE_IN_WIRED_HEADSET | 360 AUDIO_DEVICE_IN_AUX_DIGITAL | 361 AUDIO_DEVICE_IN_VOICE_CALL | 362 AUDIO_DEVICE_IN_BACK_MIC | 363 AUDIO_DEVICE_IN_REMOTE_SUBMIX | 364 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET | 365 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET | 366 AUDIO_DEVICE_IN_USB_ACCESSORY | 367 AUDIO_DEVICE_IN_USB_DEVICE | 368 AUDIO_DEVICE_IN_DEFAULT), 369 AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, 370 }; 371 372 typedef uint32_t audio_devices_t; 373 374 /* the audio output flags serve two purposes: 375 * - when an AudioTrack is created they indicate a "wish" to be connected to an 376 * output stream with attributes corresponding to the specified flags 377 * - when present in an output profile descriptor listed for a particular audio 378 * hardware module, they indicate that an output stream can be opened that 379 * supports the attributes indicated by the flags. 380 * the audio policy manager will try to match the flags in the request 381 * (when getOuput() is called) to an available output stream. 382 */ 383 typedef enum { 384 AUDIO_OUTPUT_FLAG_NONE = 0x0, // no attributes 385 AUDIO_OUTPUT_FLAG_DIRECT = 0x1, // this output directly connects a track 386 // to one output stream: no software mixer 387 AUDIO_OUTPUT_FLAG_PRIMARY = 0x2, // this output is the primary output of 388 // the device. It is unique and must be 389 // present. It is opened by default and 390 // receives routing, audio mode and volume 391 // controls related to voice calls. 392 AUDIO_OUTPUT_FLAG_FAST = 0x4, // output supports "fast tracks", 393 // defined elsewhere 394 AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8, // use deep audio buffers 395 AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD = 0x10, // offload playback of compressed 396 // streams to hardware codec 397 AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20 // use non-blocking write 398 } audio_output_flags_t; 399 400 /* The audio input flags are analogous to audio output flags. 401 * Currently they are used only when an AudioRecord is created, 402 * to indicate a preference to be connected to an input stream with 403 * attributes corresponding to the specified flags. 404 */ 405 typedef enum { 406 AUDIO_INPUT_FLAG_NONE = 0x0, // no attributes 407 AUDIO_INPUT_FLAG_FAST = 0x1, // prefer an input that supports "fast tracks" 408 } audio_input_flags_t; 409 410 /* Additional information about compressed streams offloaded to 411 * hardware playback 412 * The version and size fields must be initialized by the caller by using 413 * one of the constants defined here. 414 */ 415 typedef struct { 416 uint16_t version; // version of the info structure 417 uint16_t size; // total size of the structure including version and size 418 uint32_t sample_rate; // sample rate in Hz 419 audio_channel_mask_t channel_mask; // channel mask 420 audio_format_t format; // audio format 421 audio_stream_type_t stream_type; // stream type 422 uint32_t bit_rate; // bit rate in bits per second 423 int64_t duration_us; // duration in microseconds, -1 if unknown 424 bool has_video; // true if stream is tied to a video stream 425 bool is_streaming; // true if streaming, false if local playback 426 } audio_offload_info_t; 427 428 #define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \ 429 ((((maj) & 0xff) << 8) | ((min) & 0xff)) 430 431 #define AUDIO_OFFLOAD_INFO_VERSION_0_1 AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1) 432 #define AUDIO_OFFLOAD_INFO_VERSION_CURRENT AUDIO_OFFLOAD_INFO_VERSION_0_1 433 434 static const audio_offload_info_t AUDIO_INFO_INITIALIZER = { 435 version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT, 436 size: sizeof(audio_offload_info_t), 437 }; 438 439 static inline bool audio_is_output_device(audio_devices_t device) 440 { 441 if (((device & AUDIO_DEVICE_BIT_IN) == 0) && 442 (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0)) 443 return true; 444 else 445 return false; 446 } 447 448 static inline bool audio_is_input_device(audio_devices_t device) 449 { 450 if ((device & AUDIO_DEVICE_BIT_IN) != 0) { 451 device &= ~AUDIO_DEVICE_BIT_IN; 452 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0)) 453 return true; 454 } 455 return false; 456 } 457 458 static inline bool audio_is_output_devices(audio_devices_t device) 459 { 460 return (device & AUDIO_DEVICE_BIT_IN) == 0; 461 } 462 463 464 static inline bool audio_is_a2dp_device(audio_devices_t device) 465 { 466 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP)) 467 return true; 468 else 469 return false; 470 } 471 472 static inline bool audio_is_bluetooth_sco_device(audio_devices_t device) 473 { 474 device &= ~AUDIO_DEVICE_BIT_IN; 475 if ((popcount(device) == 1) && (device & (AUDIO_DEVICE_OUT_ALL_SCO | 476 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET))) 477 return true; 478 else 479 return false; 480 } 481 482 static inline bool audio_is_usb_device(audio_devices_t device) 483 { 484 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB)) 485 return true; 486 else 487 return false; 488 } 489 490 static inline bool audio_is_remote_submix_device(audio_devices_t device) 491 { 492 if ((device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX 493 || (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX) 494 return true; 495 else 496 return false; 497 } 498 499 static inline bool audio_is_input_channel(audio_channel_mask_t channel) 500 { 501 if ((channel & ~AUDIO_CHANNEL_IN_ALL) == 0) 502 return channel != 0; 503 else 504 return false; 505 } 506 507 static inline bool audio_is_output_channel(audio_channel_mask_t channel) 508 { 509 if ((channel & ~AUDIO_CHANNEL_OUT_ALL) == 0) 510 return channel != 0; 511 else 512 return false; 513 } 514 515 /* Derive an output channel mask from a channel count. 516 * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel 517 * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad, 518 * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC 519 * for continuity with stereo. 520 * Returns the matching channel mask, or 0 if the number of channels exceeds that of the 521 * configurations for which a default channel mask is defined. 522 */ 523 static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count) 524 { 525 switch(channel_count) { 526 case 1: 527 return AUDIO_CHANNEL_OUT_MONO; 528 case 2: 529 return AUDIO_CHANNEL_OUT_STEREO; 530 case 3: 531 return (AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER); 532 case 4: // 4.0 533 return AUDIO_CHANNEL_OUT_QUAD; 534 case 5: // 5.0 535 return (AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER); 536 case 6: // 5.1 537 return AUDIO_CHANNEL_OUT_5POINT1; 538 case 7: // 6.1 539 return (AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER); 540 case 8: 541 return AUDIO_CHANNEL_OUT_7POINT1; 542 default: 543 return 0; 544 } 545 } 546 547 /* Similar to above, but for input. Currently handles only mono and stereo. */ 548 static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count) 549 { 550 switch (channel_count) { 551 case 1: 552 return AUDIO_CHANNEL_IN_MONO; 553 case 2: 554 return AUDIO_CHANNEL_IN_STEREO; 555 default: 556 return 0; 557 } 558 } 559 560 static inline bool audio_is_valid_format(audio_format_t format) 561 { 562 switch (format & AUDIO_FORMAT_MAIN_MASK) { 563 case AUDIO_FORMAT_PCM: 564 if (format != AUDIO_FORMAT_PCM_16_BIT && 565 format != AUDIO_FORMAT_PCM_8_BIT) { 566 return false; 567 } 568 case AUDIO_FORMAT_MP3: 569 case AUDIO_FORMAT_AMR_NB: 570 case AUDIO_FORMAT_AMR_WB: 571 case AUDIO_FORMAT_AAC: 572 case AUDIO_FORMAT_HE_AAC_V1: 573 case AUDIO_FORMAT_HE_AAC_V2: 574 case AUDIO_FORMAT_VORBIS: 575 return true; 576 default: 577 return false; 578 } 579 } 580 581 static inline bool audio_is_linear_pcm(audio_format_t format) 582 { 583 return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM); 584 } 585 586 static inline size_t audio_bytes_per_sample(audio_format_t format) 587 { 588 size_t size = 0; 589 590 switch (format) { 591 case AUDIO_FORMAT_PCM_32_BIT: 592 case AUDIO_FORMAT_PCM_8_24_BIT: 593 size = sizeof(int32_t); 594 break; 595 case AUDIO_FORMAT_PCM_16_BIT: 596 size = sizeof(int16_t); 597 break; 598 case AUDIO_FORMAT_PCM_8_BIT: 599 size = sizeof(uint8_t); 600 break; 601 default: 602 break; 603 } 604 return size; 605 } 606 607 __END_DECLS 608 609 #endif // ANDROID_AUDIO_CORE_H 610