Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 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 | |
Jeff Brown | 8ecc7af | 2013-08-16 20:09:37 -0700 | [diff] [blame] | 34 | /* device address used to refer to the standard remote submix */ |
| 35 | #define AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS "0" |
| 36 | |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 37 | /* AudioFlinger and AudioPolicy services use I/O handles to identify audio sources and sinks */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 38 | typedef int audio_io_handle_t; |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 39 | #define AUDIO_IO_HANDLE_NONE 0 |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 40 | |
| 41 | /* Audio stream types */ |
| 42 | typedef enum { |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 43 | /* These values must kept in sync with |
| 44 | * frameworks/base/media/java/android/media/AudioSystem.java |
| 45 | */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 46 | AUDIO_STREAM_DEFAULT = -1, |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 47 | AUDIO_STREAM_MIN = 0, |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 48 | AUDIO_STREAM_VOICE_CALL = 0, |
| 49 | AUDIO_STREAM_SYSTEM = 1, |
| 50 | AUDIO_STREAM_RING = 2, |
| 51 | AUDIO_STREAM_MUSIC = 3, |
| 52 | AUDIO_STREAM_ALARM = 4, |
| 53 | AUDIO_STREAM_NOTIFICATION = 5, |
| 54 | AUDIO_STREAM_BLUETOOTH_SCO = 6, |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 55 | AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user |
| 56 | * and must be routed to speaker |
| 57 | */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 58 | AUDIO_STREAM_DTMF = 8, |
| 59 | AUDIO_STREAM_TTS = 9, |
| 60 | |
| 61 | AUDIO_STREAM_CNT, |
| 62 | AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1, |
| 63 | } audio_stream_type_t; |
| 64 | |
| 65 | /* Do not change these values without updating their counterparts |
Jean-Michel Trivi | 0d580e8 | 2014-05-21 14:43:14 -0700 | [diff] [blame] | 66 | * in frameworks/base/media/java/android/media/AudioAttributes.java |
| 67 | */ |
| 68 | typedef enum { |
| 69 | AUDIO_CONTENT_TYPE_UNKNOWN = 0, |
| 70 | AUDIO_CONTENT_TYPE_SPEECH = 1, |
| 71 | AUDIO_CONTENT_TYPE_MUSIC = 2, |
| 72 | AUDIO_CONTENT_TYPE_MOVIE = 3, |
| 73 | AUDIO_CONTENT_TYPE_SONIFICATION = 4, |
| 74 | |
| 75 | AUDIO_CONTENT_TYPE_CNT, |
| 76 | AUDIO_CONTENT_TYPE_MAX = AUDIO_CONTENT_TYPE_CNT - 1, |
| 77 | } audio_content_type_t; |
| 78 | |
| 79 | /* Do not change these values without updating their counterparts |
| 80 | * in frameworks/base/media/java/android/media/AudioAttributes.java |
| 81 | */ |
| 82 | typedef enum { |
| 83 | AUDIO_USAGE_UNKNOWN = 0, |
| 84 | AUDIO_USAGE_MEDIA = 1, |
| 85 | AUDIO_USAGE_VOICE_COMMUNICATION = 2, |
| 86 | AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3, |
| 87 | AUDIO_USAGE_ALARM = 4, |
| 88 | AUDIO_USAGE_NOTIFICATION = 5, |
| 89 | AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE = 6, |
| 90 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST = 7, |
| 91 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT = 8, |
| 92 | AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED = 9, |
| 93 | AUDIO_USAGE_NOTIFICATION_EVENT = 10, |
| 94 | AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11, |
| 95 | AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12, |
| 96 | AUDIO_USAGE_ASSISTANCE_SONIFICATION = 13, |
| 97 | AUDIO_USAGE_GAME = 14, |
| 98 | |
| 99 | AUDIO_USAGE_CNT, |
| 100 | AUDIO_USAGE_MAX = AUDIO_USAGE_CNT - 1, |
| 101 | } audio_usage_t; |
| 102 | |
| 103 | typedef uint32_t audio_flags_mask_t; |
| 104 | |
| 105 | /* Do not change these values without updating their counterparts |
| 106 | * in frameworks/base/media/java/android/media/AudioAttributes.java |
| 107 | */ |
| 108 | enum { |
| 109 | AUDIO_FLAG_AUDIBILITY_ENFORCED = 0x1, |
| 110 | AUDIO_FLAG_SECURE = 0x2, |
| 111 | AUDIO_FLAG_SCO = 0x4, |
Jean-Michel Trivi | c3dbe12 | 2014-07-21 18:08:41 -0700 | [diff] [blame] | 112 | AUDIO_FLAG_BEACON = 0x8 |
Jean-Michel Trivi | 0d580e8 | 2014-05-21 14:43:14 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | /* Do not change these values without updating their counterparts |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 116 | * in frameworks/base/media/java/android/media/MediaRecorder.java, |
Mike Lockwood | c8183af | 2014-05-12 12:56:03 -0700 | [diff] [blame] | 117 | * frameworks/av/services/audiopolicy/AudioPolicyService.cpp, |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 118 | * and system/media/audio_effects/include/audio_effects/audio_effects_conf.h! |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 119 | */ |
| 120 | typedef enum { |
| 121 | AUDIO_SOURCE_DEFAULT = 0, |
| 122 | AUDIO_SOURCE_MIC = 1, |
| 123 | AUDIO_SOURCE_VOICE_UPLINK = 2, |
| 124 | AUDIO_SOURCE_VOICE_DOWNLINK = 3, |
| 125 | AUDIO_SOURCE_VOICE_CALL = 4, |
| 126 | AUDIO_SOURCE_CAMCORDER = 5, |
| 127 | AUDIO_SOURCE_VOICE_RECOGNITION = 6, |
| 128 | AUDIO_SOURCE_VOICE_COMMUNICATION = 7, |
Jean-Michel Trivi | e11866a | 2012-08-16 17:53:30 -0700 | [diff] [blame] | 129 | AUDIO_SOURCE_REMOTE_SUBMIX = 8, /* Source for the mix to be presented remotely. */ |
| 130 | /* An example of remote presentation is Wifi Display */ |
| 131 | /* where a dongle attached to a TV can be used to */ |
| 132 | /* play the mix captured by this audio source. */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 133 | AUDIO_SOURCE_CNT, |
| 134 | AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1, |
Eric Laurent | 04c12ca | 2013-09-09 10:39:54 -0700 | [diff] [blame] | 135 | AUDIO_SOURCE_HOTWORD = 1999, /* A low-priority, preemptible audio source for |
| 136 | for background software hotword detection. |
| 137 | Same tuning as AUDIO_SOURCE_VOICE_RECOGNITION. |
| 138 | Used only internally to the framework. Not exposed |
| 139 | at the audio HAL. */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 140 | } audio_source_t; |
| 141 | |
Jean-Michel Trivi | 0d580e8 | 2014-05-21 14:43:14 -0700 | [diff] [blame] | 142 | /* Audio attributes */ |
| 143 | #define AUDIO_ATTRIBUTES_TAGS_MAX_SIZE 256 |
| 144 | typedef struct { |
| 145 | audio_content_type_t content_type; |
| 146 | audio_usage_t usage; |
| 147 | audio_source_t source; |
| 148 | audio_flags_mask_t flags; |
| 149 | char tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE]; /* UTF8 */ |
| 150 | } audio_attributes_t; |
| 151 | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 152 | /* special audio session values |
| 153 | * (XXX: should this be living in the audio effects land?) |
| 154 | */ |
| 155 | typedef enum { |
| 156 | /* session for effects attached to a particular output stream |
| 157 | * (value must be less than 0) |
| 158 | */ |
| 159 | AUDIO_SESSION_OUTPUT_STAGE = -1, |
| 160 | |
| 161 | /* session for effects applied to output mix. These effects can |
| 162 | * be moved by audio policy manager to another output stream |
| 163 | * (value must be 0) |
| 164 | */ |
| 165 | AUDIO_SESSION_OUTPUT_MIX = 0, |
Glenn Kasten | b4f2b4e | 2012-06-25 14:57:36 -0700 | [diff] [blame] | 166 | |
| 167 | /* application does not specify an explicit session ID to be used, |
| 168 | * and requests a new session ID to be allocated |
| 169 | * TODO use unique values for AUDIO_SESSION_OUTPUT_MIX and AUDIO_SESSION_ALLOCATE, |
| 170 | * after all uses have been updated from 0 to the appropriate symbol, and have been tested. |
| 171 | */ |
| 172 | AUDIO_SESSION_ALLOCATE = 0, |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 173 | } audio_session_t; |
| 174 | |
| 175 | /* Audio sub formats (see enum audio_format). */ |
| 176 | |
| 177 | /* PCM sub formats */ |
| 178 | typedef enum { |
Glenn Kasten | c0a5109 | 2014-01-31 07:51:17 -0800 | [diff] [blame] | 179 | /* All of these are in native byte order */ |
Eric Laurent | 9714b27 | 2011-05-26 13:52:47 -0700 | [diff] [blame] | 180 | AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */ |
| 181 | AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */ |
| 182 | AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */ |
| 183 | AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */ |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 184 | AUDIO_FORMAT_PCM_SUB_FLOAT = 0x5, /* PCM single-precision floating point */ |
Glenn Kasten | c0a5109 | 2014-01-31 07:51:17 -0800 | [diff] [blame] | 185 | AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED = 0x6, /* PCM signed .23 fixed point packed in 3 bytes */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 186 | } audio_format_pcm_sub_fmt_t; |
| 187 | |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 188 | /* The audio_format_*_sub_fmt_t declarations are not currently used */ |
| 189 | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 190 | /* MP3 sub format field definition : can use 11 LSBs in the same way as MP3 |
| 191 | * frame header to specify bit rate, stereo mode, version... |
| 192 | */ |
| 193 | typedef enum { |
| 194 | AUDIO_FORMAT_MP3_SUB_NONE = 0x0, |
| 195 | } audio_format_mp3_sub_fmt_t; |
| 196 | |
| 197 | /* AMR NB/WB sub format field definition: specify frame block interleaving, |
| 198 | * bandwidth efficient or octet aligned, encoding mode for recording... |
| 199 | */ |
| 200 | typedef enum { |
| 201 | AUDIO_FORMAT_AMR_SUB_NONE = 0x0, |
| 202 | } audio_format_amr_sub_fmt_t; |
| 203 | |
| 204 | /* AAC sub format field definition: specify profile or bitrate for recording... */ |
| 205 | typedef enum { |
aarti jadhav-gaikwad | 923e740 | 2014-06-18 15:23:09 +0530 | [diff] [blame] | 206 | AUDIO_FORMAT_AAC_SUB_MAIN = 0x1, |
| 207 | AUDIO_FORMAT_AAC_SUB_LC = 0x2, |
| 208 | AUDIO_FORMAT_AAC_SUB_SSR = 0x4, |
| 209 | AUDIO_FORMAT_AAC_SUB_LTP = 0x8, |
| 210 | AUDIO_FORMAT_AAC_SUB_HE_V1 = 0x10, |
| 211 | AUDIO_FORMAT_AAC_SUB_SCALABLE = 0x20, |
| 212 | AUDIO_FORMAT_AAC_SUB_ERLC = 0x40, |
| 213 | AUDIO_FORMAT_AAC_SUB_LD = 0x80, |
| 214 | AUDIO_FORMAT_AAC_SUB_HE_V2 = 0x100, |
| 215 | AUDIO_FORMAT_AAC_SUB_ELD = 0x200, |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 216 | } audio_format_aac_sub_fmt_t; |
| 217 | |
| 218 | /* VORBIS sub format field definition: specify quality for recording... */ |
| 219 | typedef enum { |
| 220 | AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0, |
| 221 | } audio_format_vorbis_sub_fmt_t; |
| 222 | |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 223 | /* Audio format consists of a main format field (upper 8 bits) and a sub format |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 224 | * field (lower 24 bits). |
| 225 | * |
| 226 | * The main format indicates the main codec type. The sub format field |
| 227 | * indicates options and parameters for each format. The sub format is mainly |
| 228 | * used for record to indicate for instance the requested bitrate or profile. |
| 229 | * It can also be used for certain formats to give informations not present in |
| 230 | * the encoded audio stream (e.g. octet alignement for AMR). |
| 231 | */ |
| 232 | typedef enum { |
| 233 | AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL, |
| 234 | AUDIO_FORMAT_DEFAULT = 0, |
| 235 | AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */ |
| 236 | AUDIO_FORMAT_MP3 = 0x01000000UL, |
| 237 | AUDIO_FORMAT_AMR_NB = 0x02000000UL, |
| 238 | AUDIO_FORMAT_AMR_WB = 0x03000000UL, |
| 239 | AUDIO_FORMAT_AAC = 0x04000000UL, |
aarti jadhav-gaikwad | 923e740 | 2014-06-18 15:23:09 +0530 | [diff] [blame] | 240 | AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V1*/ |
| 241 | AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL, /* Deprecated, Use AUDIO_FORMAT_AAC_HE_V2*/ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 242 | AUDIO_FORMAT_VORBIS = 0x07000000UL, |
Vignesh Venkatasubramanian | 76edb1c | 2014-01-29 09:47:56 -0800 | [diff] [blame] | 243 | AUDIO_FORMAT_OPUS = 0x08000000UL, |
Eric Laurent | ce30de3 | 2014-06-10 15:39:16 -0700 | [diff] [blame] | 244 | AUDIO_FORMAT_AC3 = 0x09000000UL, |
| 245 | AUDIO_FORMAT_E_AC3 = 0x0A000000UL, |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 246 | AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL, |
| 247 | AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL, |
| 248 | |
| 249 | /* Aliases */ |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 250 | /* note != AudioFormat.ENCODING_PCM_16BIT */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 251 | AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM | |
| 252 | AUDIO_FORMAT_PCM_SUB_16_BIT), |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 253 | /* note != AudioFormat.ENCODING_PCM_8BIT */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 254 | AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM | |
| 255 | AUDIO_FORMAT_PCM_SUB_8_BIT), |
Eric Laurent | 9714b27 | 2011-05-26 13:52:47 -0700 | [diff] [blame] | 256 | AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM | |
| 257 | AUDIO_FORMAT_PCM_SUB_32_BIT), |
| 258 | AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM | |
| 259 | AUDIO_FORMAT_PCM_SUB_8_24_BIT), |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 260 | AUDIO_FORMAT_PCM_FLOAT = (AUDIO_FORMAT_PCM | |
| 261 | AUDIO_FORMAT_PCM_SUB_FLOAT), |
Glenn Kasten | c0a5109 | 2014-01-31 07:51:17 -0800 | [diff] [blame] | 262 | AUDIO_FORMAT_PCM_24_BIT_PACKED = (AUDIO_FORMAT_PCM | |
| 263 | AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED), |
aarti jadhav-gaikwad | 923e740 | 2014-06-18 15:23:09 +0530 | [diff] [blame] | 264 | AUDIO_FORMAT_AAC_MAIN = (AUDIO_FORMAT_AAC | |
| 265 | AUDIO_FORMAT_AAC_SUB_MAIN), |
| 266 | AUDIO_FORMAT_AAC_LC = (AUDIO_FORMAT_AAC | |
| 267 | AUDIO_FORMAT_AAC_SUB_LC), |
| 268 | AUDIO_FORMAT_AAC_SSR = (AUDIO_FORMAT_AAC | |
| 269 | AUDIO_FORMAT_AAC_SUB_SSR), |
| 270 | AUDIO_FORMAT_AAC_LTP = (AUDIO_FORMAT_AAC | |
| 271 | AUDIO_FORMAT_AAC_SUB_LTP), |
| 272 | AUDIO_FORMAT_AAC_HE_V1 = (AUDIO_FORMAT_AAC | |
| 273 | AUDIO_FORMAT_AAC_SUB_HE_V1), |
| 274 | AUDIO_FORMAT_AAC_SCALABLE = (AUDIO_FORMAT_AAC | |
| 275 | AUDIO_FORMAT_AAC_SUB_SCALABLE), |
| 276 | AUDIO_FORMAT_AAC_ERLC = (AUDIO_FORMAT_AAC | |
| 277 | AUDIO_FORMAT_AAC_SUB_ERLC), |
| 278 | AUDIO_FORMAT_AAC_LD = (AUDIO_FORMAT_AAC | |
| 279 | AUDIO_FORMAT_AAC_SUB_LD), |
| 280 | AUDIO_FORMAT_AAC_HE_V2 = (AUDIO_FORMAT_AAC | |
| 281 | AUDIO_FORMAT_AAC_SUB_HE_V2), |
| 282 | AUDIO_FORMAT_AAC_ELD = (AUDIO_FORMAT_AAC | |
| 283 | AUDIO_FORMAT_AAC_SUB_ELD), |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 284 | } audio_format_t; |
| 285 | |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 286 | /* For the channel mask for position assignment representation */ |
Glenn Kasten | 16a7a04 | 2012-07-03 15:21:05 -0700 | [diff] [blame] | 287 | enum { |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 288 | |
| 289 | /* These can be a complete audio_channel_mask_t. */ |
| 290 | |
Eric Laurent | 4cd0501 | 2014-02-18 12:40:36 -0800 | [diff] [blame] | 291 | AUDIO_CHANNEL_NONE = 0x0, |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 292 | AUDIO_CHANNEL_INVALID = 0xC0000000, |
| 293 | |
| 294 | /* These can be the bits portion of an audio_channel_mask_t |
| 295 | * with representation AUDIO_CHANNEL_REPRESENTATION_POSITION. |
| 296 | * Using these bits as a complete audio_channel_mask_t is deprecated. |
| 297 | */ |
| 298 | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 299 | /* output channels */ |
Jean-Michel Trivi | 6d4f397 | 2011-07-25 16:19:07 -0700 | [diff] [blame] | 300 | AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x1, |
| 301 | AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x2, |
| 302 | AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x4, |
| 303 | AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x8, |
| 304 | AUDIO_CHANNEL_OUT_BACK_LEFT = 0x10, |
| 305 | AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x20, |
| 306 | AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40, |
| 307 | AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80, |
| 308 | AUDIO_CHANNEL_OUT_BACK_CENTER = 0x100, |
| 309 | AUDIO_CHANNEL_OUT_SIDE_LEFT = 0x200, |
| 310 | AUDIO_CHANNEL_OUT_SIDE_RIGHT = 0x400, |
| 311 | AUDIO_CHANNEL_OUT_TOP_CENTER = 0x800, |
| 312 | AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT = 0x1000, |
| 313 | AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER = 0x2000, |
| 314 | AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT = 0x4000, |
| 315 | AUDIO_CHANNEL_OUT_TOP_BACK_LEFT = 0x8000, |
| 316 | AUDIO_CHANNEL_OUT_TOP_BACK_CENTER = 0x10000, |
| 317 | AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT = 0x20000, |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 318 | |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 319 | /* TODO: should these be considered complete channel masks, or only bits? */ |
| 320 | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 321 | AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT, |
| 322 | AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
| 323 | AUDIO_CHANNEL_OUT_FRONT_RIGHT), |
| 324 | AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
| 325 | AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
| 326 | AUDIO_CHANNEL_OUT_BACK_LEFT | |
| 327 | AUDIO_CHANNEL_OUT_BACK_RIGHT), |
Glenn Kasten | b8d5939 | 2014-04-29 08:41:46 -0700 | [diff] [blame] | 328 | AUDIO_CHANNEL_OUT_QUAD_BACK = AUDIO_CHANNEL_OUT_QUAD, |
Glenn Kasten | ee7c17b | 2014-04-29 08:43:19 -0700 | [diff] [blame] | 329 | /* like AUDIO_CHANNEL_OUT_QUAD_BACK with *_SIDE_* instead of *_BACK_* */ |
| 330 | AUDIO_CHANNEL_OUT_QUAD_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
| 331 | AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
| 332 | AUDIO_CHANNEL_OUT_SIDE_LEFT | |
| 333 | AUDIO_CHANNEL_OUT_SIDE_RIGHT), |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 334 | AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
| 335 | AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
| 336 | AUDIO_CHANNEL_OUT_FRONT_CENTER | |
| 337 | AUDIO_CHANNEL_OUT_LOW_FREQUENCY | |
| 338 | AUDIO_CHANNEL_OUT_BACK_LEFT | |
| 339 | AUDIO_CHANNEL_OUT_BACK_RIGHT), |
Glenn Kasten | b8d5939 | 2014-04-29 08:41:46 -0700 | [diff] [blame] | 340 | AUDIO_CHANNEL_OUT_5POINT1_BACK = AUDIO_CHANNEL_OUT_5POINT1, |
Glenn Kasten | ee7c17b | 2014-04-29 08:43:19 -0700 | [diff] [blame] | 341 | /* like AUDIO_CHANNEL_OUT_5POINT1_BACK with *_SIDE_* instead of *_BACK_* */ |
| 342 | AUDIO_CHANNEL_OUT_5POINT1_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
| 343 | AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
| 344 | AUDIO_CHANNEL_OUT_FRONT_CENTER | |
| 345 | AUDIO_CHANNEL_OUT_LOW_FREQUENCY | |
| 346 | AUDIO_CHANNEL_OUT_SIDE_LEFT | |
| 347 | AUDIO_CHANNEL_OUT_SIDE_RIGHT), |
Jean-Michel Trivi | 33fad99 | 2011-07-24 16:31:03 -0700 | [diff] [blame] | 348 | // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1 |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 349 | AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
| 350 | AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
| 351 | AUDIO_CHANNEL_OUT_FRONT_CENTER | |
| 352 | AUDIO_CHANNEL_OUT_LOW_FREQUENCY | |
| 353 | AUDIO_CHANNEL_OUT_BACK_LEFT | |
| 354 | AUDIO_CHANNEL_OUT_BACK_RIGHT | |
Jean-Michel Trivi | 33fad99 | 2011-07-24 16:31:03 -0700 | [diff] [blame] | 355 | AUDIO_CHANNEL_OUT_SIDE_LEFT | |
| 356 | AUDIO_CHANNEL_OUT_SIDE_RIGHT), |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 357 | AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
| 358 | AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
| 359 | AUDIO_CHANNEL_OUT_FRONT_CENTER | |
| 360 | AUDIO_CHANNEL_OUT_LOW_FREQUENCY | |
| 361 | AUDIO_CHANNEL_OUT_BACK_LEFT | |
| 362 | AUDIO_CHANNEL_OUT_BACK_RIGHT | |
| 363 | AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER | |
| 364 | AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | |
Jean-Michel Trivi | 33fad99 | 2011-07-24 16:31:03 -0700 | [diff] [blame] | 365 | AUDIO_CHANNEL_OUT_BACK_CENTER| |
| 366 | AUDIO_CHANNEL_OUT_SIDE_LEFT| |
| 367 | AUDIO_CHANNEL_OUT_SIDE_RIGHT| |
| 368 | AUDIO_CHANNEL_OUT_TOP_CENTER| |
| 369 | AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT| |
| 370 | AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER| |
| 371 | AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT| |
| 372 | AUDIO_CHANNEL_OUT_TOP_BACK_LEFT| |
| 373 | AUDIO_CHANNEL_OUT_TOP_BACK_CENTER| |
| 374 | AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT), |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 375 | |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 376 | /* These are bits only, not complete values */ |
| 377 | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 378 | /* input channels */ |
| 379 | AUDIO_CHANNEL_IN_LEFT = 0x4, |
| 380 | AUDIO_CHANNEL_IN_RIGHT = 0x8, |
| 381 | AUDIO_CHANNEL_IN_FRONT = 0x10, |
| 382 | AUDIO_CHANNEL_IN_BACK = 0x20, |
| 383 | AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40, |
| 384 | AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80, |
| 385 | AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100, |
| 386 | AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200, |
| 387 | AUDIO_CHANNEL_IN_PRESSURE = 0x400, |
| 388 | AUDIO_CHANNEL_IN_X_AXIS = 0x800, |
| 389 | AUDIO_CHANNEL_IN_Y_AXIS = 0x1000, |
| 390 | AUDIO_CHANNEL_IN_Z_AXIS = 0x2000, |
| 391 | AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000, |
| 392 | AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000, |
| 393 | |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 394 | /* TODO: should these be considered complete channel masks, or only bits, or deprecated? */ |
| 395 | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 396 | AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT, |
| 397 | AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT), |
Eric Laurent | 6c70cee | 2013-01-17 17:31:49 -0800 | [diff] [blame] | 398 | AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK), |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 399 | AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT | |
| 400 | AUDIO_CHANNEL_IN_RIGHT | |
| 401 | AUDIO_CHANNEL_IN_FRONT | |
| 402 | AUDIO_CHANNEL_IN_BACK| |
| 403 | AUDIO_CHANNEL_IN_LEFT_PROCESSED | |
| 404 | AUDIO_CHANNEL_IN_RIGHT_PROCESSED | |
| 405 | AUDIO_CHANNEL_IN_FRONT_PROCESSED | |
| 406 | AUDIO_CHANNEL_IN_BACK_PROCESSED| |
| 407 | AUDIO_CHANNEL_IN_PRESSURE | |
| 408 | AUDIO_CHANNEL_IN_X_AXIS | |
| 409 | AUDIO_CHANNEL_IN_Y_AXIS | |
| 410 | AUDIO_CHANNEL_IN_Z_AXIS | |
| 411 | AUDIO_CHANNEL_IN_VOICE_UPLINK | |
| 412 | AUDIO_CHANNEL_IN_VOICE_DNLINK), |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 413 | }; |
| 414 | |
Glenn Kasten | ee7c17b | 2014-04-29 08:43:19 -0700 | [diff] [blame] | 415 | /* A channel mask per se only defines the presence or absence of a channel, not the order. |
| 416 | * But see AUDIO_INTERLEAVE_* below for the platform convention of order. |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 417 | * |
| 418 | * audio_channel_mask_t is an opaque type and its internal layout should not |
| 419 | * be assumed as it may change in the future. |
| 420 | * Instead, always use the functions declared in this header to examine. |
| 421 | * |
| 422 | * These are the current representations: |
| 423 | * |
| 424 | * AUDIO_CHANNEL_REPRESENTATION_POSITION |
| 425 | * is a channel mask representation for position assignment. |
| 426 | * Each low-order bit corresponds to the spatial position of a transducer (output), |
| 427 | * or interpretation of channel (input). |
| 428 | * The user of a channel mask needs to know the context of whether it is for output or input. |
| 429 | * The constants AUDIO_CHANNEL_OUT_* or AUDIO_CHANNEL_IN_* apply to the bits portion. |
| 430 | * It is not permitted for no bits to be set. |
| 431 | * |
| 432 | * AUDIO_CHANNEL_REPRESENTATION_INDEX |
| 433 | * is a channel mask representation for index assignment. |
| 434 | * Each low-order bit corresponds to a selected channel. |
| 435 | * There is no platform interpretation of the various bits. |
| 436 | * There is no concept of output or input. |
| 437 | * It is not permitted for no bits to be set. |
| 438 | * |
| 439 | * All other representations are reserved for future use. |
| 440 | * |
| 441 | * Warning: current representation distinguishes between input and output, but this will not the be |
| 442 | * case in future revisions of the platform. Wherever there is an ambiguity between input and output |
| 443 | * that is currently resolved by checking the channel mask, the implementer should look for ways to |
| 444 | * fix it with additional information outside of the mask. |
Glenn Kasten | ee7c17b | 2014-04-29 08:43:19 -0700 | [diff] [blame] | 445 | */ |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 446 | typedef uint32_t audio_channel_mask_t; |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 447 | |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 448 | /* Maximum number of channels for all representations */ |
| 449 | #define AUDIO_CHANNEL_COUNT_MAX 30 |
| 450 | |
| 451 | /* log(2) of maximum number of representations, not part of public API */ |
| 452 | #define AUDIO_CHANNEL_REPRESENTATION_LOG2 2 |
| 453 | |
| 454 | /* Representations */ |
| 455 | typedef enum { |
| 456 | AUDIO_CHANNEL_REPRESENTATION_POSITION = 0, // must be zero for compatibility |
| 457 | // 1 is reserved for future use |
| 458 | AUDIO_CHANNEL_REPRESENTATION_INDEX = 2, |
| 459 | // 3 is reserved for future use |
| 460 | } audio_channel_representation_t; |
| 461 | |
| 462 | /* The return value is undefined if the channel mask is invalid. */ |
| 463 | static inline uint32_t audio_channel_mask_get_bits(audio_channel_mask_t channel) |
| 464 | { |
| 465 | return channel & ((1 << AUDIO_CHANNEL_COUNT_MAX) - 1); |
| 466 | } |
| 467 | |
| 468 | /* The return value is undefined if the channel mask is invalid. */ |
| 469 | static inline audio_channel_representation_t audio_channel_mask_get_representation( |
| 470 | audio_channel_mask_t channel) |
| 471 | { |
| 472 | // The right shift should be sufficient, but also "and" for safety in case mask is not 32 bits |
| 473 | return (audio_channel_representation_t) |
| 474 | ((channel >> AUDIO_CHANNEL_COUNT_MAX) & ((1 << AUDIO_CHANNEL_REPRESENTATION_LOG2) - 1)); |
| 475 | } |
| 476 | |
| 477 | /* Returns true if the channel mask is valid, |
| 478 | * or returns false for AUDIO_CHANNEL_NONE, AUDIO_CHANNEL_INVALID, and other invalid values. |
| 479 | * This function is unable to determine whether a channel mask for position assignment |
| 480 | * is invalid because an output mask has an invalid output bit set, |
| 481 | * or because an input mask has an invalid input bit set. |
| 482 | * All other APIs that take a channel mask assume that it is valid. |
| 483 | */ |
| 484 | static inline bool audio_channel_mask_is_valid(audio_channel_mask_t channel) |
| 485 | { |
| 486 | uint32_t bits = audio_channel_mask_get_bits(channel); |
| 487 | audio_channel_representation_t representation = audio_channel_mask_get_representation(channel); |
| 488 | switch (representation) { |
| 489 | case AUDIO_CHANNEL_REPRESENTATION_POSITION: |
| 490 | case AUDIO_CHANNEL_REPRESENTATION_INDEX: |
| 491 | break; |
| 492 | default: |
| 493 | bits = 0; |
| 494 | break; |
| 495 | } |
| 496 | return bits != 0; |
| 497 | } |
| 498 | |
| 499 | /* Not part of public API */ |
| 500 | static inline audio_channel_mask_t audio_channel_mask_from_representation_and_bits( |
| 501 | audio_channel_representation_t representation, uint32_t bits) |
| 502 | { |
| 503 | return (audio_channel_mask_t) ((representation << AUDIO_CHANNEL_COUNT_MAX) | bits); |
| 504 | } |
| 505 | |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 506 | /* Expresses the convention when stereo audio samples are stored interleaved |
| 507 | * in an array. This should improve readability by allowing code to use |
| 508 | * symbolic indices instead of hard-coded [0] and [1]. |
Glenn Kasten | ee7c17b | 2014-04-29 08:43:19 -0700 | [diff] [blame] | 509 | * |
| 510 | * For multi-channel beyond stereo, the platform convention is that channels |
| 511 | * are interleaved in order from least significant channel mask bit |
| 512 | * to most significant channel mask bit, with unused bits skipped. |
| 513 | * Any exceptions to this convention will be noted at the appropriate API. |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 514 | */ |
| 515 | enum { |
| 516 | AUDIO_INTERLEAVE_LEFT = 0, |
| 517 | AUDIO_INTERLEAVE_RIGHT = 1, |
| 518 | }; |
| 519 | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 520 | typedef enum { |
| 521 | AUDIO_MODE_INVALID = -2, |
| 522 | AUDIO_MODE_CURRENT = -1, |
| 523 | AUDIO_MODE_NORMAL = 0, |
| 524 | AUDIO_MODE_RINGTONE = 1, |
| 525 | AUDIO_MODE_IN_CALL = 2, |
| 526 | AUDIO_MODE_IN_COMMUNICATION = 3, |
| 527 | |
| 528 | AUDIO_MODE_CNT, |
| 529 | AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1, |
| 530 | } audio_mode_t; |
| 531 | |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 532 | /* This enum is deprecated */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 533 | typedef enum { |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 534 | AUDIO_IN_ACOUSTICS_NONE = 0, |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 535 | AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001, |
| 536 | AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0, |
| 537 | AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002, |
| 538 | AUDIO_IN_ACOUSTICS_NS_DISABLE = 0, |
| 539 | AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004, |
| 540 | AUDIO_IN_ACOUSTICS_TX_DISABLE = 0, |
| 541 | } audio_in_acoustics_t; |
| 542 | |
Glenn Kasten | 16a7a04 | 2012-07-03 15:21:05 -0700 | [diff] [blame] | 543 | enum { |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 544 | AUDIO_DEVICE_NONE = 0x0, |
| 545 | /* reserved bits */ |
| 546 | AUDIO_DEVICE_BIT_IN = 0x80000000, |
| 547 | AUDIO_DEVICE_BIT_DEFAULT = 0x40000000, |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 548 | /* output devices */ |
| 549 | AUDIO_DEVICE_OUT_EARPIECE = 0x1, |
| 550 | AUDIO_DEVICE_OUT_SPEAKER = 0x2, |
| 551 | AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4, |
| 552 | AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8, |
| 553 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10, |
| 554 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20, |
| 555 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40, |
| 556 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80, |
| 557 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100, |
| 558 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200, |
| 559 | AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400, |
Eric Laurent | abcb999 | 2014-05-16 15:11:08 -0700 | [diff] [blame] | 560 | AUDIO_DEVICE_OUT_HDMI = AUDIO_DEVICE_OUT_AUX_DIGITAL, |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 561 | /* uses an analog connection (multiplexed over the USB connector pins for instance) */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 562 | AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800, |
| 563 | AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000, |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 564 | /* USB accessory mode: your Android device is a USB device and the dock is a USB host */ |
Eric Laurent | 79f90bd | 2012-04-06 08:57:48 -0700 | [diff] [blame] | 565 | AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000, |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 566 | /* USB host mode: your Android device is a USB host and the dock is a USB device */ |
Eric Laurent | 79f90bd | 2012-04-06 08:57:48 -0700 | [diff] [blame] | 567 | AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000, |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 568 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000, |
Eric Laurent | abcb999 | 2014-05-16 15:11:08 -0700 | [diff] [blame] | 569 | /* Telephony voice TX path */ |
| 570 | AUDIO_DEVICE_OUT_TELEPHONY_TX = 0x10000, |
| 571 | /* Analog jack with line impedance detected */ |
| 572 | AUDIO_DEVICE_OUT_LINE = 0x20000, |
| 573 | /* HDMI Audio Return Channel */ |
| 574 | AUDIO_DEVICE_OUT_HDMI_ARC = 0x40000, |
| 575 | /* S/PDIF out */ |
| 576 | AUDIO_DEVICE_OUT_SPDIF = 0x80000, |
| 577 | /* FM transmitter out */ |
| 578 | AUDIO_DEVICE_OUT_FM = 0x100000, |
Jungshik Jang | cadd5bb | 2014-07-15 19:40:32 +0900 | [diff] [blame] | 579 | /* Line out for av devices */ |
| 580 | AUDIO_DEVICE_OUT_AUX_LINE = 0x200000, |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 581 | AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT, |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 582 | AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE | |
| 583 | AUDIO_DEVICE_OUT_SPEAKER | |
| 584 | AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 585 | AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 586 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO | |
| 587 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | |
| 588 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT | |
| 589 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | |
| 590 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
| 591 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | |
Eric Laurent | abcb999 | 2014-05-16 15:11:08 -0700 | [diff] [blame] | 592 | AUDIO_DEVICE_OUT_HDMI | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 593 | AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | |
| 594 | AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | |
Eric Laurent | 79f90bd | 2012-04-06 08:57:48 -0700 | [diff] [blame] | 595 | AUDIO_DEVICE_OUT_USB_ACCESSORY | |
| 596 | AUDIO_DEVICE_OUT_USB_DEVICE | |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 597 | AUDIO_DEVICE_OUT_REMOTE_SUBMIX | |
Eric Laurent | abcb999 | 2014-05-16 15:11:08 -0700 | [diff] [blame] | 598 | AUDIO_DEVICE_OUT_TELEPHONY_TX | |
| 599 | AUDIO_DEVICE_OUT_LINE | |
| 600 | AUDIO_DEVICE_OUT_HDMI_ARC | |
| 601 | AUDIO_DEVICE_OUT_SPDIF | |
| 602 | AUDIO_DEVICE_OUT_FM | |
Jungshik Jang | cadd5bb | 2014-07-15 19:40:32 +0900 | [diff] [blame] | 603 | AUDIO_DEVICE_OUT_AUX_LINE | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 604 | AUDIO_DEVICE_OUT_DEFAULT), |
| 605 | AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | |
| 606 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
| 607 | AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER), |
| 608 | AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO | |
| 609 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | |
| 610 | AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT), |
Eric Laurent | 79f90bd | 2012-04-06 08:57:48 -0700 | [diff] [blame] | 611 | AUDIO_DEVICE_OUT_ALL_USB = (AUDIO_DEVICE_OUT_USB_ACCESSORY | |
| 612 | AUDIO_DEVICE_OUT_USB_DEVICE), |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 613 | |
| 614 | /* input devices */ |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 615 | AUDIO_DEVICE_IN_COMMUNICATION = AUDIO_DEVICE_BIT_IN | 0x1, |
| 616 | AUDIO_DEVICE_IN_AMBIENT = AUDIO_DEVICE_BIT_IN | 0x2, |
| 617 | AUDIO_DEVICE_IN_BUILTIN_MIC = AUDIO_DEVICE_BIT_IN | 0x4, |
| 618 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8, |
| 619 | AUDIO_DEVICE_IN_WIRED_HEADSET = AUDIO_DEVICE_BIT_IN | 0x10, |
| 620 | AUDIO_DEVICE_IN_AUX_DIGITAL = AUDIO_DEVICE_BIT_IN | 0x20, |
Eric Laurent | abcb999 | 2014-05-16 15:11:08 -0700 | [diff] [blame] | 621 | AUDIO_DEVICE_IN_HDMI = AUDIO_DEVICE_IN_AUX_DIGITAL, |
| 622 | /* Telephony voice RX path */ |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 623 | AUDIO_DEVICE_IN_VOICE_CALL = AUDIO_DEVICE_BIT_IN | 0x40, |
Eric Laurent | abcb999 | 2014-05-16 15:11:08 -0700 | [diff] [blame] | 624 | AUDIO_DEVICE_IN_TELEPHONY_RX = AUDIO_DEVICE_IN_VOICE_CALL, |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 625 | AUDIO_DEVICE_IN_BACK_MIC = AUDIO_DEVICE_BIT_IN | 0x80, |
| 626 | AUDIO_DEVICE_IN_REMOTE_SUBMIX = AUDIO_DEVICE_BIT_IN | 0x100, |
| 627 | AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x200, |
| 628 | AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x400, |
| 629 | AUDIO_DEVICE_IN_USB_ACCESSORY = AUDIO_DEVICE_BIT_IN | 0x800, |
| 630 | AUDIO_DEVICE_IN_USB_DEVICE = AUDIO_DEVICE_BIT_IN | 0x1000, |
Eric Laurent | abcb999 | 2014-05-16 15:11:08 -0700 | [diff] [blame] | 631 | /* FM tuner input */ |
| 632 | AUDIO_DEVICE_IN_FM_TUNER = AUDIO_DEVICE_BIT_IN | 0x2000, |
| 633 | /* TV tuner input */ |
| 634 | AUDIO_DEVICE_IN_TV_TUNER = AUDIO_DEVICE_BIT_IN | 0x4000, |
| 635 | /* Analog jack with line impedance detected */ |
| 636 | AUDIO_DEVICE_IN_LINE = AUDIO_DEVICE_BIT_IN | 0x8000, |
| 637 | /* S/PDIF in */ |
| 638 | AUDIO_DEVICE_IN_SPDIF = AUDIO_DEVICE_BIT_IN | 0x10000, |
Mike Lockwood | c8183af | 2014-05-12 12:56:03 -0700 | [diff] [blame] | 639 | AUDIO_DEVICE_IN_BLUETOOTH_A2DP = AUDIO_DEVICE_BIT_IN | 0x20000, |
Terry Heo | b63dd8a | 2014-06-27 15:25:56 +0900 | [diff] [blame] | 640 | AUDIO_DEVICE_IN_LOOPBACK = AUDIO_DEVICE_BIT_IN | 0x40000, |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 641 | AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT, |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 642 | |
| 643 | AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION | |
| 644 | AUDIO_DEVICE_IN_AMBIENT | |
| 645 | AUDIO_DEVICE_IN_BUILTIN_MIC | |
| 646 | AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET | |
| 647 | AUDIO_DEVICE_IN_WIRED_HEADSET | |
Eric Laurent | abcb999 | 2014-05-16 15:11:08 -0700 | [diff] [blame] | 648 | AUDIO_DEVICE_IN_HDMI | |
| 649 | AUDIO_DEVICE_IN_TELEPHONY_RX | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 650 | AUDIO_DEVICE_IN_BACK_MIC | |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 651 | AUDIO_DEVICE_IN_REMOTE_SUBMIX | |
| 652 | AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET | |
| 653 | AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET | |
| 654 | AUDIO_DEVICE_IN_USB_ACCESSORY | |
| 655 | AUDIO_DEVICE_IN_USB_DEVICE | |
Eric Laurent | abcb999 | 2014-05-16 15:11:08 -0700 | [diff] [blame] | 656 | AUDIO_DEVICE_IN_FM_TUNER | |
| 657 | AUDIO_DEVICE_IN_TV_TUNER | |
| 658 | AUDIO_DEVICE_IN_LINE | |
| 659 | AUDIO_DEVICE_IN_SPDIF | |
Mike Lockwood | c8183af | 2014-05-12 12:56:03 -0700 | [diff] [blame] | 660 | AUDIO_DEVICE_IN_BLUETOOTH_A2DP | |
Terry Heo | b63dd8a | 2014-06-27 15:25:56 +0900 | [diff] [blame] | 661 | AUDIO_DEVICE_IN_LOOPBACK | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 662 | AUDIO_DEVICE_IN_DEFAULT), |
| 663 | AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, |
Paul McLean | 00b8972 | 2014-04-18 14:29:22 -0700 | [diff] [blame] | 664 | AUDIO_DEVICE_IN_ALL_USB = (AUDIO_DEVICE_IN_USB_ACCESSORY | |
| 665 | AUDIO_DEVICE_IN_USB_DEVICE), |
Glenn Kasten | 16a7a04 | 2012-07-03 15:21:05 -0700 | [diff] [blame] | 666 | }; |
| 667 | |
| 668 | typedef uint32_t audio_devices_t; |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 669 | |
Eric Laurent | 545ab46 | 2012-04-16 18:05:39 -0700 | [diff] [blame] | 670 | /* the audio output flags serve two purposes: |
| 671 | * - when an AudioTrack is created they indicate a "wish" to be connected to an |
| 672 | * output stream with attributes corresponding to the specified flags |
| 673 | * - when present in an output profile descriptor listed for a particular audio |
| 674 | * hardware module, they indicate that an output stream can be opened that |
| 675 | * supports the attributes indicated by the flags. |
| 676 | * the audio policy manager will try to match the flags in the request |
| 677 | * (when getOuput() is called) to an available output stream. |
| 678 | */ |
| 679 | typedef enum { |
Eric Laurent | 9aec362 | 2012-04-13 16:52:58 -0700 | [diff] [blame] | 680 | AUDIO_OUTPUT_FLAG_NONE = 0x0, // no attributes |
| 681 | AUDIO_OUTPUT_FLAG_DIRECT = 0x1, // this output directly connects a track |
| 682 | // to one output stream: no software mixer |
| 683 | AUDIO_OUTPUT_FLAG_PRIMARY = 0x2, // this output is the primary output of |
| 684 | // the device. It is unique and must be |
| 685 | // present. It is opened by default and |
| 686 | // receives routing, audio mode and volume |
| 687 | // controls related to voice calls. |
| 688 | AUDIO_OUTPUT_FLAG_FAST = 0x4, // output supports "fast tracks", |
| 689 | // defined elsewhere |
Richard Fitzgerald | 05529a1 | 2013-03-25 16:07:43 +0000 | [diff] [blame] | 690 | AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8, // use deep audio buffers |
| 691 | AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD = 0x10, // offload playback of compressed |
| 692 | // streams to hardware codec |
| 693 | AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20 // use non-blocking write |
Eric Laurent | 545ab46 | 2012-04-16 18:05:39 -0700 | [diff] [blame] | 694 | } audio_output_flags_t; |
| 695 | |
Glenn Kasten | c051ffd | 2013-08-01 07:35:33 -0700 | [diff] [blame] | 696 | /* The audio input flags are analogous to audio output flags. |
| 697 | * Currently they are used only when an AudioRecord is created, |
| 698 | * to indicate a preference to be connected to an input stream with |
| 699 | * attributes corresponding to the specified flags. |
| 700 | */ |
| 701 | typedef enum { |
| 702 | AUDIO_INPUT_FLAG_NONE = 0x0, // no attributes |
| 703 | AUDIO_INPUT_FLAG_FAST = 0x1, // prefer an input that supports "fast tracks" |
| 704 | } audio_input_flags_t; |
| 705 | |
Richard Fitzgerald | 05529a1 | 2013-03-25 16:07:43 +0000 | [diff] [blame] | 706 | /* Additional information about compressed streams offloaded to |
| 707 | * hardware playback |
| 708 | * The version and size fields must be initialized by the caller by using |
| 709 | * one of the constants defined here. |
| 710 | */ |
| 711 | typedef struct { |
| 712 | uint16_t version; // version of the info structure |
| 713 | uint16_t size; // total size of the structure including version and size |
| 714 | uint32_t sample_rate; // sample rate in Hz |
| 715 | audio_channel_mask_t channel_mask; // channel mask |
| 716 | audio_format_t format; // audio format |
| 717 | audio_stream_type_t stream_type; // stream type |
| 718 | uint32_t bit_rate; // bit rate in bits per second |
| 719 | int64_t duration_us; // duration in microseconds, -1 if unknown |
| 720 | bool has_video; // true if stream is tied to a video stream |
| 721 | bool is_streaming; // true if streaming, false if local playback |
| 722 | } audio_offload_info_t; |
| 723 | |
| 724 | #define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \ |
| 725 | ((((maj) & 0xff) << 8) | ((min) & 0xff)) |
| 726 | |
| 727 | #define AUDIO_OFFLOAD_INFO_VERSION_0_1 AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1) |
| 728 | #define AUDIO_OFFLOAD_INFO_VERSION_CURRENT AUDIO_OFFLOAD_INFO_VERSION_0_1 |
| 729 | |
| 730 | static const audio_offload_info_t AUDIO_INFO_INITIALIZER = { |
| 731 | version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT, |
| 732 | size: sizeof(audio_offload_info_t), |
Mark Salyzyn | 4887842 | 2014-05-22 16:08:52 -0700 | [diff] [blame] | 733 | sample_rate: 0, |
| 734 | channel_mask: 0, |
| 735 | format: AUDIO_FORMAT_DEFAULT, |
| 736 | stream_type: AUDIO_STREAM_VOICE_CALL, |
| 737 | bit_rate: 0, |
| 738 | duration_us: 0, |
| 739 | has_video: false, |
| 740 | is_streaming: false |
Richard Fitzgerald | 05529a1 | 2013-03-25 16:07:43 +0000 | [diff] [blame] | 741 | }; |
| 742 | |
Eric Laurent | 0a381a3 | 2014-07-27 16:18:21 -0700 | [diff] [blame^] | 743 | /* common audio stream configuration parameters |
| 744 | * You should memset() the entire structure to zero before use to |
| 745 | * ensure forward compatibility |
| 746 | */ |
| 747 | struct audio_config { |
| 748 | uint32_t sample_rate; |
| 749 | audio_channel_mask_t channel_mask; |
| 750 | audio_format_t format; |
| 751 | audio_offload_info_t offload_info; |
| 752 | size_t frame_count; |
| 753 | }; |
| 754 | typedef struct audio_config audio_config_t; |
| 755 | |
| 756 | static const audio_config_t AUDIO_CONFIG_INITIALIZER = { |
| 757 | sample_rate: 0, |
| 758 | channel_mask: AUDIO_CHANNEL_NONE, |
| 759 | format: AUDIO_FORMAT_DEFAULT, |
| 760 | offload_info: { |
| 761 | version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT, |
| 762 | size: sizeof(audio_offload_info_t), |
| 763 | sample_rate: 0, |
| 764 | channel_mask: 0, |
| 765 | format: AUDIO_FORMAT_DEFAULT, |
| 766 | stream_type: AUDIO_STREAM_VOICE_CALL, |
| 767 | bit_rate: 0, |
| 768 | duration_us: 0, |
| 769 | has_video: false, |
| 770 | is_streaming: false |
| 771 | }, |
| 772 | frame_count: 0, |
| 773 | }; |
| 774 | |
Eric Laurent | 4cd0501 | 2014-02-18 12:40:36 -0800 | [diff] [blame] | 775 | |
| 776 | /* audio hw module handle functions or structures referencing a module */ |
| 777 | typedef int audio_module_handle_t; |
| 778 | |
| 779 | /****************************** |
| 780 | * Volume control |
| 781 | *****************************/ |
| 782 | |
| 783 | /* If the audio hardware supports gain control on some audio paths, |
| 784 | * the platform can expose them in the audio_policy.conf file. The audio HAL |
| 785 | * will then implement gain control functions that will use the following data |
| 786 | * structures. */ |
| 787 | |
| 788 | /* Type of gain control exposed by an audio port */ |
| 789 | #define AUDIO_GAIN_MODE_JOINT 0x1 /* supports joint channel gain control */ |
| 790 | #define AUDIO_GAIN_MODE_CHANNELS 0x2 /* supports separate channel gain control */ |
| 791 | #define AUDIO_GAIN_MODE_RAMP 0x4 /* supports gain ramps */ |
| 792 | |
| 793 | typedef uint32_t audio_gain_mode_t; |
| 794 | |
| 795 | |
| 796 | /* An audio_gain struct is a representation of a gain stage. |
| 797 | * A gain stage is always attached to an audio port. */ |
| 798 | struct audio_gain { |
| 799 | audio_gain_mode_t mode; /* e.g. AUDIO_GAIN_MODE_JOINT */ |
| 800 | audio_channel_mask_t channel_mask; /* channels which gain an be controlled. |
| 801 | N/A if AUDIO_GAIN_MODE_CHANNELS is not supported */ |
| 802 | int min_value; /* minimum gain value in millibels */ |
| 803 | int max_value; /* maximum gain value in millibels */ |
| 804 | int default_value; /* default gain value in millibels */ |
| 805 | unsigned int step_value; /* gain step in millibels */ |
| 806 | unsigned int min_ramp_ms; /* minimum ramp duration in ms */ |
| 807 | unsigned int max_ramp_ms; /* maximum ramp duration in ms */ |
| 808 | }; |
| 809 | |
| 810 | /* The gain configuration structure is used to get or set the gain values of a |
| 811 | * given port */ |
| 812 | struct audio_gain_config { |
| 813 | int index; /* index of the corresponding audio_gain in the |
| 814 | audio_port gains[] table */ |
| 815 | audio_gain_mode_t mode; /* mode requested for this command */ |
| 816 | audio_channel_mask_t channel_mask; /* channels which gain value follows. |
| 817 | N/A in joint mode */ |
Jungshik Jang | f7e5aea | 2014-07-11 09:50:45 +0900 | [diff] [blame] | 818 | int values[sizeof(audio_channel_mask_t) * 8]; /* gain values in millibels |
| 819 | for each channel ordered from LSb to MSb in |
| 820 | channel mask. The number of values is 1 in joint |
| 821 | mode or popcount(channel_mask) */ |
Eric Laurent | 4cd0501 | 2014-02-18 12:40:36 -0800 | [diff] [blame] | 822 | unsigned int ramp_duration_ms; /* ramp duration in ms */ |
| 823 | }; |
| 824 | |
| 825 | /****************************** |
| 826 | * Routing control |
| 827 | *****************************/ |
| 828 | |
| 829 | /* Types defined here are used to describe an audio source or sink at internal |
| 830 | * framework interfaces (audio policy, patch panel) or at the audio HAL. |
| 831 | * Sink and sources are grouped in a concept of “audio port” representing an |
| 832 | * audio end point at the edge of the system managed by the module exposing |
| 833 | * the interface. */ |
| 834 | |
| 835 | /* Audio port role: either source or sink */ |
| 836 | typedef enum { |
| 837 | AUDIO_PORT_ROLE_NONE, |
| 838 | AUDIO_PORT_ROLE_SOURCE, |
| 839 | AUDIO_PORT_ROLE_SINK, |
| 840 | } audio_port_role_t; |
| 841 | |
| 842 | /* Audio port type indicates if it is a session (e.g AudioTrack), |
| 843 | * a mix (e.g PlaybackThread output) or a physical device |
| 844 | * (e.g AUDIO_DEVICE_OUT_SPEAKER) */ |
| 845 | typedef enum { |
| 846 | AUDIO_PORT_TYPE_NONE, |
| 847 | AUDIO_PORT_TYPE_DEVICE, |
| 848 | AUDIO_PORT_TYPE_MIX, |
| 849 | AUDIO_PORT_TYPE_SESSION, |
| 850 | } audio_port_type_t; |
| 851 | |
| 852 | /* Each port has a unique ID or handle allocated by policy manager */ |
| 853 | typedef int audio_port_handle_t; |
| 854 | #define AUDIO_PORT_HANDLE_NONE 0 |
| 855 | |
| 856 | |
| 857 | /* maximum audio device address length */ |
| 858 | #define AUDIO_DEVICE_MAX_ADDRESS_LEN 32 |
| 859 | |
| 860 | /* extension for audio port configuration structure when the audio port is a |
| 861 | * hardware device */ |
| 862 | struct audio_port_config_device_ext { |
| 863 | audio_module_handle_t hw_module; /* module the device is attached to */ |
| 864 | audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */ |
| 865 | char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; /* device address. "" if N/A */ |
| 866 | }; |
| 867 | |
| 868 | /* extension for audio port configuration structure when the audio port is a |
| 869 | * sub mix */ |
| 870 | struct audio_port_config_mix_ext { |
| 871 | audio_module_handle_t hw_module; /* module the stream is attached to */ |
| 872 | audio_io_handle_t handle; /* I/O handle of the input/output stream */ |
| 873 | union { |
| 874 | //TODO: change use case for output streams: use strategy and mixer attributes |
| 875 | audio_stream_type_t stream; |
| 876 | audio_source_t source; |
| 877 | } usecase; |
| 878 | }; |
| 879 | |
| 880 | /* extension for audio port configuration structure when the audio port is an |
| 881 | * audio session */ |
| 882 | struct audio_port_config_session_ext { |
| 883 | audio_session_t session; /* audio session */ |
| 884 | }; |
| 885 | |
| 886 | /* Flags indicating which fields are to be considered in struct audio_port_config */ |
| 887 | #define AUDIO_PORT_CONFIG_SAMPLE_RATE 0x1 |
| 888 | #define AUDIO_PORT_CONFIG_CHANNEL_MASK 0x2 |
| 889 | #define AUDIO_PORT_CONFIG_FORMAT 0x4 |
| 890 | #define AUDIO_PORT_CONFIG_GAIN 0x8 |
| 891 | #define AUDIO_PORT_CONFIG_ALL (AUDIO_PORT_CONFIG_SAMPLE_RATE | \ |
| 892 | AUDIO_PORT_CONFIG_CHANNEL_MASK | \ |
| 893 | AUDIO_PORT_CONFIG_FORMAT | \ |
| 894 | AUDIO_PORT_CONFIG_GAIN) |
| 895 | |
| 896 | /* audio port configuration structure used to specify a particular configuration of |
| 897 | * an audio port */ |
| 898 | struct audio_port_config { |
| 899 | audio_port_handle_t id; /* port unique ID */ |
| 900 | audio_port_role_t role; /* sink or source */ |
| 901 | audio_port_type_t type; /* device, mix ... */ |
| 902 | unsigned int config_mask; /* e.g AUDIO_PORT_CONFIG_ALL */ |
| 903 | unsigned int sample_rate; /* sampling rate in Hz */ |
| 904 | audio_channel_mask_t channel_mask; /* channel mask if applicable */ |
| 905 | audio_format_t format; /* format if applicable */ |
| 906 | struct audio_gain_config gain; /* gain to apply if applicable */ |
| 907 | union { |
| 908 | struct audio_port_config_device_ext device; /* device specific info */ |
| 909 | struct audio_port_config_mix_ext mix; /* mix specific info */ |
| 910 | struct audio_port_config_session_ext session; /* session specific info */ |
| 911 | } ext; |
| 912 | }; |
| 913 | |
| 914 | |
| 915 | /* max number of sampling rates in audio port */ |
| 916 | #define AUDIO_PORT_MAX_SAMPLING_RATES 16 |
| 917 | /* max number of channel masks in audio port */ |
| 918 | #define AUDIO_PORT_MAX_CHANNEL_MASKS 16 |
| 919 | /* max number of audio formats in audio port */ |
| 920 | #define AUDIO_PORT_MAX_FORMATS 16 |
| 921 | /* max number of gain controls in audio port */ |
| 922 | #define AUDIO_PORT_MAX_GAINS 16 |
| 923 | |
| 924 | /* extension for audio port structure when the audio port is a hardware device */ |
| 925 | struct audio_port_device_ext { |
| 926 | audio_module_handle_t hw_module; /* module the device is attached to */ |
| 927 | audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */ |
| 928 | char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; |
| 929 | }; |
| 930 | |
| 931 | /* Latency class of the audio mix */ |
| 932 | typedef enum { |
| 933 | AUDIO_LATENCY_LOW, |
| 934 | AUDIO_LATENCY_NORMAL, |
| 935 | } audio_mix_latency_class_t; |
| 936 | |
| 937 | /* extension for audio port structure when the audio port is a sub mix */ |
| 938 | struct audio_port_mix_ext { |
| 939 | audio_module_handle_t hw_module; /* module the stream is attached to */ |
| 940 | audio_io_handle_t handle; /* I/O handle of the input.output stream */ |
| 941 | audio_mix_latency_class_t latency_class; /* latency class */ |
| 942 | // other attributes: routing strategies |
| 943 | }; |
| 944 | |
| 945 | /* extension for audio port structure when the audio port is an audio session */ |
| 946 | struct audio_port_session_ext { |
| 947 | audio_session_t session; /* audio session */ |
| 948 | }; |
| 949 | |
| 950 | |
| 951 | struct audio_port { |
| 952 | audio_port_handle_t id; /* port unique ID */ |
| 953 | audio_port_role_t role; /* sink or source */ |
| 954 | audio_port_type_t type; /* device, mix ... */ |
| 955 | unsigned int num_sample_rates; /* number of sampling rates in following array */ |
| 956 | unsigned int sample_rates[AUDIO_PORT_MAX_SAMPLING_RATES]; |
| 957 | unsigned int num_channel_masks; /* number of channel masks in following array */ |
| 958 | audio_channel_mask_t channel_masks[AUDIO_PORT_MAX_CHANNEL_MASKS]; |
| 959 | unsigned int num_formats; /* number of formats in following array */ |
| 960 | audio_format_t formats[AUDIO_PORT_MAX_FORMATS]; |
| 961 | unsigned int num_gains; /* number of gains in following array */ |
| 962 | struct audio_gain gains[AUDIO_PORT_MAX_GAINS]; |
| 963 | struct audio_port_config active_config; /* current audio port configuration */ |
| 964 | union { |
| 965 | struct audio_port_device_ext device; |
| 966 | struct audio_port_mix_ext mix; |
| 967 | struct audio_port_session_ext session; |
| 968 | } ext; |
| 969 | }; |
| 970 | |
| 971 | /* An audio patch represents a connection between one or more source ports and |
| 972 | * one or more sink ports. Patches are connected and disconnected by audio policy manager or by |
| 973 | * applications via framework APIs. |
| 974 | * Each patch is identified by a handle at the interface used to create that patch. For instance, |
| 975 | * when a patch is created by the audio HAL, the HAL allocates and returns a handle. |
| 976 | * This handle is unique to a given audio HAL hardware module. |
| 977 | * But the same patch receives another system wide unique handle allocated by the framework. |
| 978 | * This unique handle is used for all transactions inside the framework. |
| 979 | */ |
| 980 | typedef int audio_patch_handle_t; |
| 981 | #define AUDIO_PATCH_HANDLE_NONE 0 |
| 982 | |
| 983 | #define AUDIO_PATCH_PORTS_MAX 16 |
| 984 | |
| 985 | struct audio_patch { |
| 986 | audio_patch_handle_t id; /* patch unique ID */ |
| 987 | unsigned int num_sources; /* number of sources in following array */ |
| 988 | struct audio_port_config sources[AUDIO_PATCH_PORTS_MAX]; |
| 989 | unsigned int num_sinks; /* number of sinks in following array */ |
| 990 | struct audio_port_config sinks[AUDIO_PATCH_PORTS_MAX]; |
| 991 | }; |
| 992 | |
| 993 | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 994 | static inline bool audio_is_output_device(audio_devices_t device) |
| 995 | { |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 996 | if (((device & AUDIO_DEVICE_BIT_IN) == 0) && |
| 997 | (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0)) |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 998 | return true; |
| 999 | else |
| 1000 | return false; |
| 1001 | } |
| 1002 | |
| 1003 | static inline bool audio_is_input_device(audio_devices_t device) |
| 1004 | { |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 1005 | if ((device & AUDIO_DEVICE_BIT_IN) != 0) { |
| 1006 | device &= ~AUDIO_DEVICE_BIT_IN; |
| 1007 | if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0)) |
| 1008 | return true; |
| 1009 | } |
| 1010 | return false; |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 1013 | static inline bool audio_is_output_devices(audio_devices_t device) |
| 1014 | { |
| 1015 | return (device & AUDIO_DEVICE_BIT_IN) == 0; |
| 1016 | } |
| 1017 | |
Mike Lockwood | c8183af | 2014-05-12 12:56:03 -0700 | [diff] [blame] | 1018 | static inline bool audio_is_a2dp_in_device(audio_devices_t device) |
| 1019 | { |
| 1020 | if ((device & AUDIO_DEVICE_BIT_IN) != 0) { |
| 1021 | device &= ~AUDIO_DEVICE_BIT_IN; |
| 1022 | if ((popcount(device) == 1) && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP)) |
| 1023 | return true; |
| 1024 | } |
| 1025 | return false; |
| 1026 | } |
Eric Laurent | eeeee80 | 2012-08-28 14:29:07 -0700 | [diff] [blame] | 1027 | |
Mike Lockwood | c8183af | 2014-05-12 12:56:03 -0700 | [diff] [blame] | 1028 | static inline bool audio_is_a2dp_out_device(audio_devices_t device) |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1029 | { |
| 1030 | if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP)) |
| 1031 | return true; |
| 1032 | else |
| 1033 | return false; |
| 1034 | } |
| 1035 | |
Mike Lockwood | c8183af | 2014-05-12 12:56:03 -0700 | [diff] [blame] | 1036 | // Deprecated - use audio_is_a2dp_out_device() instead |
| 1037 | static inline bool audio_is_a2dp_device(audio_devices_t device) |
| 1038 | { |
| 1039 | return audio_is_a2dp_out_device(device); |
| 1040 | } |
| 1041 | |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1042 | static inline bool audio_is_bluetooth_sco_device(audio_devices_t device) |
| 1043 | { |
Eric Laurent | b526630 | 2014-04-24 13:36:47 -0700 | [diff] [blame] | 1044 | if ((device & AUDIO_DEVICE_BIT_IN) == 0) { |
| 1045 | if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL_SCO) == 0)) |
| 1046 | return true; |
| 1047 | } else { |
| 1048 | device &= ~AUDIO_DEVICE_BIT_IN; |
| 1049 | if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) == 0)) |
| 1050 | return true; |
| 1051 | } |
| 1052 | |
| 1053 | return false; |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
Paul McLean | 00b8972 | 2014-04-18 14:29:22 -0700 | [diff] [blame] | 1056 | static inline bool audio_is_usb_out_device(audio_devices_t device) |
| 1057 | { |
| 1058 | return ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB)); |
| 1059 | } |
| 1060 | |
| 1061 | static inline bool audio_is_usb_in_device(audio_devices_t device) |
| 1062 | { |
| 1063 | if ((device & AUDIO_DEVICE_BIT_IN) != 0) { |
| 1064 | device &= ~AUDIO_DEVICE_BIT_IN; |
| 1065 | if (popcount(device) == 1 && (device & AUDIO_DEVICE_IN_ALL_USB) != 0) |
| 1066 | return true; |
| 1067 | } |
| 1068 | return false; |
| 1069 | } |
| 1070 | |
| 1071 | /* OBSOLETE - use audio_is_usb_out_device() instead. */ |
Eric Laurent | 79f90bd | 2012-04-06 08:57:48 -0700 | [diff] [blame] | 1072 | static inline bool audio_is_usb_device(audio_devices_t device) |
| 1073 | { |
Paul McLean | 00b8972 | 2014-04-18 14:29:22 -0700 | [diff] [blame] | 1074 | return audio_is_usb_out_device(device); |
Eric Laurent | 79f90bd | 2012-04-06 08:57:48 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Jean-Michel Trivi | e11866a | 2012-08-16 17:53:30 -0700 | [diff] [blame] | 1077 | static inline bool audio_is_remote_submix_device(audio_devices_t device) |
| 1078 | { |
Jeff Brown | 8ecc7af | 2013-08-16 20:09:37 -0700 | [diff] [blame] | 1079 | if ((device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX |
| 1080 | || (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX) |
Jean-Michel Trivi | e11866a | 2012-08-16 17:53:30 -0700 | [diff] [blame] | 1081 | return true; |
| 1082 | else |
| 1083 | return false; |
| 1084 | } |
| 1085 | |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1086 | /* Returns true if: |
| 1087 | * representation is valid, and |
| 1088 | * there is at least one channel bit set which _could_ correspond to an input channel, and |
| 1089 | * there are no channel bits set which could _not_ correspond to an input channel. |
| 1090 | * Otherwise returns false. |
| 1091 | */ |
Glenn Kasten | f7326dc | 2013-07-19 14:50:21 -0700 | [diff] [blame] | 1092 | static inline bool audio_is_input_channel(audio_channel_mask_t channel) |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1093 | { |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1094 | uint32_t bits = audio_channel_mask_get_bits(channel); |
| 1095 | switch (audio_channel_mask_get_representation(channel)) { |
| 1096 | case AUDIO_CHANNEL_REPRESENTATION_POSITION: |
| 1097 | if (bits & ~AUDIO_CHANNEL_IN_ALL) { |
| 1098 | bits = 0; |
| 1099 | } |
| 1100 | // fall through |
| 1101 | case AUDIO_CHANNEL_REPRESENTATION_INDEX: |
| 1102 | return bits != 0; |
| 1103 | default: |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1104 | return false; |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1105 | } |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1108 | /* Returns true if: |
| 1109 | * representation is valid, and |
| 1110 | * there is at least one channel bit set which _could_ correspond to an output channel, and |
| 1111 | * there are no channel bits set which could _not_ correspond to an output channel. |
| 1112 | * Otherwise returns false. |
| 1113 | */ |
Glenn Kasten | f7326dc | 2013-07-19 14:50:21 -0700 | [diff] [blame] | 1114 | static inline bool audio_is_output_channel(audio_channel_mask_t channel) |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1115 | { |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1116 | uint32_t bits = audio_channel_mask_get_bits(channel); |
| 1117 | switch (audio_channel_mask_get_representation(channel)) { |
| 1118 | case AUDIO_CHANNEL_REPRESENTATION_POSITION: |
| 1119 | if (bits & ~AUDIO_CHANNEL_OUT_ALL) { |
| 1120 | bits = 0; |
| 1121 | } |
| 1122 | // fall through |
| 1123 | case AUDIO_CHANNEL_REPRESENTATION_INDEX: |
| 1124 | return bits != 0; |
| 1125 | default: |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1126 | return false; |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1127 | } |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Andy Hung | a7e8f86 | 2014-05-15 18:35:38 -0700 | [diff] [blame] | 1130 | /* Returns the number of channels from an input channel mask, |
| 1131 | * used in the context of audio input or recording. |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1132 | * If a channel bit is set which could _not_ correspond to an input channel, |
| 1133 | * it is excluded from the count. |
| 1134 | * Returns zero if the representation is invalid. |
Andy Hung | a7e8f86 | 2014-05-15 18:35:38 -0700 | [diff] [blame] | 1135 | */ |
| 1136 | static inline uint32_t audio_channel_count_from_in_mask(audio_channel_mask_t channel) |
| 1137 | { |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1138 | uint32_t bits = audio_channel_mask_get_bits(channel); |
| 1139 | switch (audio_channel_mask_get_representation(channel)) { |
| 1140 | case AUDIO_CHANNEL_REPRESENTATION_POSITION: |
| 1141 | // TODO: We can now merge with from_out_mask and remove anding |
| 1142 | bits &= AUDIO_CHANNEL_IN_ALL; |
| 1143 | // fall through |
| 1144 | case AUDIO_CHANNEL_REPRESENTATION_INDEX: |
| 1145 | return popcount(bits); |
| 1146 | default: |
| 1147 | return 0; |
| 1148 | } |
Andy Hung | a7e8f86 | 2014-05-15 18:35:38 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /* Returns the number of channels from an output channel mask, |
| 1152 | * used in the context of audio output or playback. |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1153 | * If a channel bit is set which could _not_ correspond to an output channel, |
| 1154 | * it is excluded from the count. |
| 1155 | * Returns zero if the representation is invalid. |
Andy Hung | a7e8f86 | 2014-05-15 18:35:38 -0700 | [diff] [blame] | 1156 | */ |
| 1157 | static inline uint32_t audio_channel_count_from_out_mask(audio_channel_mask_t channel) |
| 1158 | { |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1159 | uint32_t bits = audio_channel_mask_get_bits(channel); |
| 1160 | switch (audio_channel_mask_get_representation(channel)) { |
| 1161 | case AUDIO_CHANNEL_REPRESENTATION_POSITION: |
| 1162 | // TODO: We can now merge with from_in_mask and remove anding |
| 1163 | bits &= AUDIO_CHANNEL_OUT_ALL; |
| 1164 | // fall through |
| 1165 | case AUDIO_CHANNEL_REPRESENTATION_INDEX: |
| 1166 | return popcount(bits); |
| 1167 | default: |
| 1168 | return 0; |
| 1169 | } |
Andy Hung | a7e8f86 | 2014-05-15 18:35:38 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1172 | /* Derive an output channel mask for position assignment from a channel count. |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1173 | * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel |
| 1174 | * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad, |
| 1175 | * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC |
| 1176 | * for continuity with stereo. |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1177 | * Returns the matching channel mask, |
| 1178 | * or AUDIO_CHANNEL_NONE if the channel count is zero, |
| 1179 | * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the |
| 1180 | * configurations for which a default output channel mask is defined. |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1181 | */ |
Glenn Kasten | 89f7ba3 | 2012-03-14 13:45:31 -0700 | [diff] [blame] | 1182 | static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count) |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1183 | { |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1184 | uint32_t bits; |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 1185 | switch (channel_count) { |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1186 | case 0: |
| 1187 | return AUDIO_CHANNEL_NONE; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1188 | case 1: |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1189 | bits = AUDIO_CHANNEL_OUT_MONO; |
| 1190 | break; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1191 | case 2: |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1192 | bits = AUDIO_CHANNEL_OUT_STEREO; |
| 1193 | break; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1194 | case 3: |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1195 | bits = AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER; |
| 1196 | break; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1197 | case 4: // 4.0 |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1198 | bits = AUDIO_CHANNEL_OUT_QUAD; |
| 1199 | break; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1200 | case 5: // 5.0 |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1201 | bits = AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER; |
| 1202 | break; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1203 | case 6: // 5.1 |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1204 | bits = AUDIO_CHANNEL_OUT_5POINT1; |
| 1205 | break; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1206 | case 7: // 6.1 |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1207 | bits = AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER; |
| 1208 | break; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1209 | case 8: |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1210 | bits = AUDIO_CHANNEL_OUT_7POINT1; |
| 1211 | break; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1212 | default: |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1213 | return AUDIO_CHANNEL_INVALID; |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1214 | } |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1215 | return audio_channel_mask_from_representation_and_bits( |
| 1216 | AUDIO_CHANNEL_REPRESENTATION_POSITION, bits); |
Jean-Michel Trivi | 4ab051a | 2012-03-02 16:41:35 -0800 | [diff] [blame] | 1217 | } |
| 1218 | |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1219 | /* Derive an input channel mask for position assignment from a channel count. |
| 1220 | * Currently handles only mono and stereo. |
| 1221 | * Returns the matching channel mask, |
| 1222 | * or AUDIO_CHANNEL_NONE if the channel count is zero, |
| 1223 | * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the |
| 1224 | * configurations for which a default input channel mask is defined. |
| 1225 | */ |
Glenn Kasten | 89f7ba3 | 2012-03-14 13:45:31 -0700 | [diff] [blame] | 1226 | static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count) |
| 1227 | { |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1228 | uint32_t bits; |
Glenn Kasten | 89f7ba3 | 2012-03-14 13:45:31 -0700 | [diff] [blame] | 1229 | switch (channel_count) { |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1230 | case 0: |
| 1231 | return AUDIO_CHANNEL_NONE; |
Glenn Kasten | 89f7ba3 | 2012-03-14 13:45:31 -0700 | [diff] [blame] | 1232 | case 1: |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1233 | bits = AUDIO_CHANNEL_IN_MONO; |
| 1234 | break; |
Glenn Kasten | 89f7ba3 | 2012-03-14 13:45:31 -0700 | [diff] [blame] | 1235 | case 2: |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1236 | bits = AUDIO_CHANNEL_IN_STEREO; |
| 1237 | break; |
Glenn Kasten | 89f7ba3 | 2012-03-14 13:45:31 -0700 | [diff] [blame] | 1238 | default: |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1239 | return AUDIO_CHANNEL_INVALID; |
Glenn Kasten | 89f7ba3 | 2012-03-14 13:45:31 -0700 | [diff] [blame] | 1240 | } |
Glenn Kasten | 432b7c6 | 2014-04-14 17:47:03 -0700 | [diff] [blame] | 1241 | return audio_channel_mask_from_representation_and_bits( |
| 1242 | AUDIO_CHANNEL_REPRESENTATION_POSITION, bits); |
| 1243 | } |
| 1244 | |
| 1245 | /* Derive a channel mask for index assignment from a channel count. |
| 1246 | * Returns the matching channel mask, |
| 1247 | * or AUDIO_CHANNEL_NONE if the channel count is zero, |
| 1248 | * or AUDIO_CHANNEL_INVALID if the channel count exceeds AUDIO_CHANNEL_COUNT_MAX. |
| 1249 | */ |
| 1250 | static inline audio_channel_mask_t audio_channel_mask_for_index_assignment_from_count( |
| 1251 | uint32_t channel_count) |
| 1252 | { |
| 1253 | if (channel_count == 0) { |
| 1254 | return AUDIO_CHANNEL_NONE; |
| 1255 | } |
| 1256 | if (channel_count > AUDIO_CHANNEL_COUNT_MAX) { |
| 1257 | return AUDIO_CHANNEL_INVALID; |
| 1258 | } |
| 1259 | uint32_t bits = (1 << channel_count) - 1; |
| 1260 | return audio_channel_mask_from_representation_and_bits( |
| 1261 | AUDIO_CHANNEL_REPRESENTATION_INDEX, bits); |
Glenn Kasten | 89f7ba3 | 2012-03-14 13:45:31 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Glenn Kasten | 828bf0c | 2012-01-12 12:34:42 -0800 | [diff] [blame] | 1264 | static inline bool audio_is_valid_format(audio_format_t format) |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1265 | { |
| 1266 | switch (format & AUDIO_FORMAT_MAIN_MASK) { |
| 1267 | case AUDIO_FORMAT_PCM: |
Glenn Kasten | 45b9581 | 2014-03-07 12:31:03 -0800 | [diff] [blame] | 1268 | switch (format) { |
| 1269 | case AUDIO_FORMAT_PCM_16_BIT: |
| 1270 | case AUDIO_FORMAT_PCM_8_BIT: |
| 1271 | case AUDIO_FORMAT_PCM_32_BIT: |
| 1272 | case AUDIO_FORMAT_PCM_8_24_BIT: |
| 1273 | case AUDIO_FORMAT_PCM_FLOAT: |
| 1274 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: |
| 1275 | return true; |
| 1276 | default: |
Eric Laurent | da38224 | 2011-06-16 21:13:43 -0700 | [diff] [blame] | 1277 | return false; |
| 1278 | } |
Glenn Kasten | 45b9581 | 2014-03-07 12:31:03 -0800 | [diff] [blame] | 1279 | /* not reached */ |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1280 | case AUDIO_FORMAT_MP3: |
| 1281 | case AUDIO_FORMAT_AMR_NB: |
| 1282 | case AUDIO_FORMAT_AMR_WB: |
| 1283 | case AUDIO_FORMAT_AAC: |
| 1284 | case AUDIO_FORMAT_HE_AAC_V1: |
| 1285 | case AUDIO_FORMAT_HE_AAC_V2: |
| 1286 | case AUDIO_FORMAT_VORBIS: |
Eric Laurent | ce30de3 | 2014-06-10 15:39:16 -0700 | [diff] [blame] | 1287 | case AUDIO_FORMAT_OPUS: |
| 1288 | case AUDIO_FORMAT_AC3: |
| 1289 | case AUDIO_FORMAT_E_AC3: |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1290 | return true; |
| 1291 | default: |
| 1292 | return false; |
| 1293 | } |
| 1294 | } |
| 1295 | |
Glenn Kasten | 828bf0c | 2012-01-12 12:34:42 -0800 | [diff] [blame] | 1296 | static inline bool audio_is_linear_pcm(audio_format_t format) |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1297 | { |
Eric Laurent | da38224 | 2011-06-16 21:13:43 -0700 | [diff] [blame] | 1298 | return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM); |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
Glenn Kasten | 828bf0c | 2012-01-12 12:34:42 -0800 | [diff] [blame] | 1301 | static inline size_t audio_bytes_per_sample(audio_format_t format) |
Eric Laurent | da38224 | 2011-06-16 21:13:43 -0700 | [diff] [blame] | 1302 | { |
| 1303 | size_t size = 0; |
| 1304 | |
| 1305 | switch (format) { |
Jean-Michel Trivi | 427d2b4 | 2012-03-05 15:38:15 -0800 | [diff] [blame] | 1306 | case AUDIO_FORMAT_PCM_32_BIT: |
| 1307 | case AUDIO_FORMAT_PCM_8_24_BIT: |
| 1308 | size = sizeof(int32_t); |
| 1309 | break; |
Andy Hung | 173f499 | 2014-03-06 17:18:58 -0800 | [diff] [blame] | 1310 | case AUDIO_FORMAT_PCM_24_BIT_PACKED: |
| 1311 | size = sizeof(uint8_t) * 3; |
| 1312 | break; |
Jean-Michel Trivi | 427d2b4 | 2012-03-05 15:38:15 -0800 | [diff] [blame] | 1313 | case AUDIO_FORMAT_PCM_16_BIT: |
| 1314 | size = sizeof(int16_t); |
| 1315 | break; |
| 1316 | case AUDIO_FORMAT_PCM_8_BIT: |
| 1317 | size = sizeof(uint8_t); |
| 1318 | break; |
Glenn Kasten | 1c3e16f | 2011-12-19 09:21:48 -0800 | [diff] [blame] | 1319 | case AUDIO_FORMAT_PCM_FLOAT: |
| 1320 | size = sizeof(float); |
| 1321 | break; |
Jean-Michel Trivi | 427d2b4 | 2012-03-05 15:38:15 -0800 | [diff] [blame] | 1322 | default: |
| 1323 | break; |
Eric Laurent | da38224 | 2011-06-16 21:13:43 -0700 | [diff] [blame] | 1324 | } |
| 1325 | return size; |
| 1326 | } |
Dima Zavin | e8e4be5 | 2011-05-12 10:25:33 -0700 | [diff] [blame] | 1327 | |
| 1328 | __END_DECLS |
| 1329 | |
| 1330 | #endif // ANDROID_AUDIO_CORE_H |