|
1 /* |
|
2 * Copyright (C) 2008 The Android Open Source Project |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 #ifndef ANDROID_AUDIOSYSTEM_H_ |
|
18 #define ANDROID_AUDIOSYSTEM_H_ |
|
19 |
|
20 #include <utils/RefBase.h> |
|
21 #include <utils/threads.h> |
|
22 #include "IAudioFlinger.h" |
|
23 |
|
24 #ifndef VANILLA_ANDROID |
|
25 /* request to open a direct output with get_output() (by opposition to |
|
26 * sharing an output with other AudioTracks) |
|
27 */ |
|
28 typedef enum { |
|
29 AUDIO_POLICY_OUTPUT_FLAG_INDIRECT = 0x0, |
|
30 AUDIO_POLICY_OUTPUT_FLAG_DIRECT = 0x1 |
|
31 } audio_policy_output_flags_t; |
|
32 |
|
33 /* device categories used for audio_policy->set_force_use() */ |
|
34 typedef enum { |
|
35 AUDIO_POLICY_FORCE_NONE, |
|
36 AUDIO_POLICY_FORCE_SPEAKER, |
|
37 AUDIO_POLICY_FORCE_HEADPHONES, |
|
38 AUDIO_POLICY_FORCE_BT_SCO, |
|
39 AUDIO_POLICY_FORCE_BT_A2DP, |
|
40 AUDIO_POLICY_FORCE_WIRED_ACCESSORY, |
|
41 AUDIO_POLICY_FORCE_BT_CAR_DOCK, |
|
42 AUDIO_POLICY_FORCE_BT_DESK_DOCK, |
|
43 |
|
44 #ifdef VANILLA_ANDROID |
|
45 AUDIO_POLICY_FORCE_ANALOG_DOCK, |
|
46 AUDIO_POLICY_FORCE_DIGITAL_DOCK, |
|
47 #endif |
|
48 |
|
49 AUDIO_POLICY_FORCE_CFG_CNT, |
|
50 AUDIO_POLICY_FORCE_CFG_MAX = AUDIO_POLICY_FORCE_CFG_CNT - 1, |
|
51 |
|
52 AUDIO_POLICY_FORCE_DEFAULT = AUDIO_POLICY_FORCE_NONE, |
|
53 } audio_policy_forced_cfg_t; |
|
54 |
|
55 /* usages used for audio_policy->set_force_use() */ |
|
56 typedef enum { |
|
57 AUDIO_POLICY_FORCE_FOR_COMMUNICATION, |
|
58 AUDIO_POLICY_FORCE_FOR_MEDIA, |
|
59 AUDIO_POLICY_FORCE_FOR_RECORD, |
|
60 AUDIO_POLICY_FORCE_FOR_DOCK, |
|
61 |
|
62 AUDIO_POLICY_FORCE_USE_CNT, |
|
63 AUDIO_POLICY_FORCE_USE_MAX = AUDIO_POLICY_FORCE_USE_CNT - 1, |
|
64 } audio_policy_force_use_t; |
|
65 |
|
66 typedef enum { |
|
67 AUDIO_STREAM_DEFAULT = -1, |
|
68 AUDIO_STREAM_VOICE_CALL = 0, |
|
69 AUDIO_STREAM_SYSTEM = 1, |
|
70 AUDIO_STREAM_RING = 2, |
|
71 AUDIO_STREAM_MUSIC = 3, |
|
72 AUDIO_STREAM_ALARM = 4, |
|
73 AUDIO_STREAM_NOTIFICATION = 5, |
|
74 AUDIO_STREAM_BLUETOOTH_SCO = 6, |
|
75 AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user and must be routed to speaker */ |
|
76 AUDIO_STREAM_DTMF = 8, |
|
77 AUDIO_STREAM_TTS = 9, |
|
78 AUDIO_STREAM_FM = 10, |
|
79 |
|
80 AUDIO_STREAM_CNT, |
|
81 AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1, |
|
82 } audio_stream_type_t; |
|
83 |
|
84 /* PCM sub formats */ |
|
85 typedef enum { |
|
86 AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */ |
|
87 AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */ |
|
88 AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */ |
|
89 AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */ |
|
90 } audio_format_pcm_sub_fmt_t; |
|
91 |
|
92 /* Audio format consists in a main format field (upper 8 bits) and a sub format |
|
93 * field (lower 24 bits). |
|
94 * |
|
95 * The main format indicates the main codec type. The sub format field |
|
96 * indicates options and parameters for each format. The sub format is mainly |
|
97 * used for record to indicate for instance the requested bitrate or profile. |
|
98 * It can also be used for certain formats to give informations not present in |
|
99 * the encoded audio stream (e.g. octet alignement for AMR). |
|
100 */ |
|
101 typedef enum { |
|
102 AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL, |
|
103 AUDIO_FORMAT_DEFAULT = 0, |
|
104 AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */ |
|
105 AUDIO_FORMAT_MP3 = 0x01000000UL, |
|
106 AUDIO_FORMAT_AMR_NB = 0x02000000UL, |
|
107 AUDIO_FORMAT_AMR_WB = 0x03000000UL, |
|
108 AUDIO_FORMAT_AAC = 0x04000000UL, |
|
109 AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL, |
|
110 AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL, |
|
111 AUDIO_FORMAT_VORBIS = 0x07000000UL, |
|
112 AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL, |
|
113 AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL, |
|
114 |
|
115 /* Aliases */ |
|
116 AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM | |
|
117 AUDIO_FORMAT_PCM_SUB_16_BIT), |
|
118 AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM | |
|
119 AUDIO_FORMAT_PCM_SUB_8_BIT), |
|
120 AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM | |
|
121 AUDIO_FORMAT_PCM_SUB_32_BIT), |
|
122 AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM | |
|
123 AUDIO_FORMAT_PCM_SUB_8_24_BIT), |
|
124 } audio_format_t; |
|
125 |
|
126 typedef enum { |
|
127 /* output channels */ |
|
128 AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x1, |
|
129 AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x2, |
|
130 AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x4, |
|
131 AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x8, |
|
132 AUDIO_CHANNEL_OUT_BACK_LEFT = 0x10, |
|
133 AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x20, |
|
134 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40, |
|
135 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80, |
|
136 AUDIO_CHANNEL_OUT_BACK_CENTER = 0x100, |
|
137 AUDIO_CHANNEL_OUT_SIDE_LEFT = 0x200, |
|
138 AUDIO_CHANNEL_OUT_SIDE_RIGHT = 0x400, |
|
139 AUDIO_CHANNEL_OUT_TOP_CENTER = 0x800, |
|
140 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT = 0x1000, |
|
141 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER = 0x2000, |
|
142 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT = 0x4000, |
|
143 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT = 0x8000, |
|
144 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER = 0x10000, |
|
145 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT = 0x20000, |
|
146 |
|
147 AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT, |
|
148 AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
|
149 AUDIO_CHANNEL_OUT_FRONT_RIGHT), |
|
150 AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
|
151 AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
|
152 AUDIO_CHANNEL_OUT_BACK_LEFT | |
|
153 AUDIO_CHANNEL_OUT_BACK_RIGHT), |
|
154 AUDIO_CHANNEL_OUT_SURROUND = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
|
155 AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
|
156 AUDIO_CHANNEL_OUT_FRONT_CENTER | |
|
157 AUDIO_CHANNEL_OUT_BACK_CENTER), |
|
158 AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
|
159 AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
|
160 AUDIO_CHANNEL_OUT_FRONT_CENTER | |
|
161 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | |
|
162 AUDIO_CHANNEL_OUT_BACK_LEFT | |
|
163 AUDIO_CHANNEL_OUT_BACK_RIGHT), |
|
164 // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1 |
|
165 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
|
166 AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
|
167 AUDIO_CHANNEL_OUT_FRONT_CENTER | |
|
168 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | |
|
169 AUDIO_CHANNEL_OUT_BACK_LEFT | |
|
170 AUDIO_CHANNEL_OUT_BACK_RIGHT | |
|
171 AUDIO_CHANNEL_OUT_SIDE_LEFT | |
|
172 AUDIO_CHANNEL_OUT_SIDE_RIGHT), |
|
173 AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT | |
|
174 AUDIO_CHANNEL_OUT_FRONT_RIGHT | |
|
175 AUDIO_CHANNEL_OUT_FRONT_CENTER | |
|
176 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | |
|
177 AUDIO_CHANNEL_OUT_BACK_LEFT | |
|
178 AUDIO_CHANNEL_OUT_BACK_RIGHT | |
|
179 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER | |
|
180 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | |
|
181 AUDIO_CHANNEL_OUT_BACK_CENTER| |
|
182 AUDIO_CHANNEL_OUT_SIDE_LEFT| |
|
183 AUDIO_CHANNEL_OUT_SIDE_RIGHT| |
|
184 AUDIO_CHANNEL_OUT_TOP_CENTER| |
|
185 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT| |
|
186 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER| |
|
187 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT| |
|
188 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT| |
|
189 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER| |
|
190 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT), |
|
191 |
|
192 /* input channels */ |
|
193 AUDIO_CHANNEL_IN_LEFT = 0x4, |
|
194 AUDIO_CHANNEL_IN_RIGHT = 0x8, |
|
195 AUDIO_CHANNEL_IN_FRONT = 0x10, |
|
196 AUDIO_CHANNEL_IN_BACK = 0x20, |
|
197 AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40, |
|
198 AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80, |
|
199 AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100, |
|
200 AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200, |
|
201 AUDIO_CHANNEL_IN_PRESSURE = 0x400, |
|
202 AUDIO_CHANNEL_IN_X_AXIS = 0x800, |
|
203 AUDIO_CHANNEL_IN_Y_AXIS = 0x1000, |
|
204 AUDIO_CHANNEL_IN_Z_AXIS = 0x2000, |
|
205 AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000, |
|
206 AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000, |
|
207 |
|
208 AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT, |
|
209 AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT), |
|
210 AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT | |
|
211 AUDIO_CHANNEL_IN_RIGHT | |
|
212 AUDIO_CHANNEL_IN_FRONT | |
|
213 AUDIO_CHANNEL_IN_BACK| |
|
214 AUDIO_CHANNEL_IN_LEFT_PROCESSED | |
|
215 AUDIO_CHANNEL_IN_RIGHT_PROCESSED | |
|
216 AUDIO_CHANNEL_IN_FRONT_PROCESSED | |
|
217 AUDIO_CHANNEL_IN_BACK_PROCESSED| |
|
218 AUDIO_CHANNEL_IN_PRESSURE | |
|
219 AUDIO_CHANNEL_IN_X_AXIS | |
|
220 AUDIO_CHANNEL_IN_Y_AXIS | |
|
221 AUDIO_CHANNEL_IN_Z_AXIS | |
|
222 AUDIO_CHANNEL_IN_VOICE_UPLINK | |
|
223 AUDIO_CHANNEL_IN_VOICE_DNLINK), |
|
224 } audio_channels_t; |
|
225 |
|
226 #if ANDROID_VERSION >= 17 |
|
227 typedef enum { |
|
228 AUDIO_MODE_INVALID = -2, |
|
229 AUDIO_MODE_CURRENT = -1, |
|
230 AUDIO_MODE_NORMAL = 0, |
|
231 AUDIO_MODE_RINGTONE = 1, |
|
232 AUDIO_MODE_IN_CALL = 2, |
|
233 AUDIO_MODE_IN_COMMUNICATION = 3, |
|
234 |
|
235 AUDIO_MODE_CNT, |
|
236 AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1, |
|
237 } audio_mode_t; |
|
238 #endif |
|
239 #endif |
|
240 |
|
241 #if ANDROID_VERSION < 17 |
|
242 typedef enum { |
|
243 /* output devices */ |
|
244 AUDIO_DEVICE_OUT_EARPIECE = 0x1, |
|
245 AUDIO_DEVICE_OUT_SPEAKER = 0x2, |
|
246 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4, |
|
247 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8, |
|
248 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10, |
|
249 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20, |
|
250 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40, |
|
251 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80, |
|
252 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100, |
|
253 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200, |
|
254 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400, |
|
255 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800, |
|
256 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000, |
|
257 AUDIO_DEVICE_OUT_FM = 0x2000, |
|
258 AUDIO_DEVICE_OUT_ANC_HEADSET = 0x4000, |
|
259 AUDIO_DEVICE_OUT_ANC_HEADPHONE = 0x8000, |
|
260 AUDIO_DEVICE_OUT_FM_TX = 0x10000, |
|
261 AUDIO_DEVICE_OUT_DIRECTOUTPUT = 0x20000, |
|
262 AUDIO_DEVICE_OUT_PROXY = 0x40000, |
|
263 AUDIO_DEVICE_OUT_DEFAULT = 0x80000, |
|
264 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE | |
|
265 AUDIO_DEVICE_OUT_SPEAKER | |
|
266 AUDIO_DEVICE_OUT_WIRED_HEADSET | |
|
267 AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
|
268 AUDIO_DEVICE_OUT_BLUETOOTH_SCO | |
|
269 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | |
|
270 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT | |
|
271 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | |
|
272 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
|
273 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | |
|
274 AUDIO_DEVICE_OUT_AUX_DIGITAL | |
|
275 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | |
|
276 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | |
|
277 AUDIO_DEVICE_OUT_FM | |
|
278 AUDIO_DEVICE_OUT_ANC_HEADSET | |
|
279 AUDIO_DEVICE_OUT_ANC_HEADPHONE | |
|
280 AUDIO_DEVICE_OUT_FM_TX | |
|
281 AUDIO_DEVICE_OUT_DIRECTOUTPUT | |
|
282 AUDIO_DEVICE_OUT_PROXY | |
|
283 AUDIO_DEVICE_OUT_DEFAULT), |
|
284 AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | |
|
285 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
|
286 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER), |
|
287 AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO | |
|
288 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | |
|
289 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT), |
|
290 /* input devices */ |
|
291 AUDIO_DEVICE_IN_COMMUNICATION = 0x100000, |
|
292 AUDIO_DEVICE_IN_AMBIENT = 0x200000, |
|
293 AUDIO_DEVICE_IN_BUILTIN_MIC = 0x400000, |
|
294 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x800000, |
|
295 AUDIO_DEVICE_IN_WIRED_HEADSET = 0x1000000, |
|
296 AUDIO_DEVICE_IN_AUX_DIGITAL = 0x2000000, |
|
297 AUDIO_DEVICE_IN_VOICE_CALL = 0x4000000, |
|
298 AUDIO_DEVICE_IN_BACK_MIC = 0x8000000, |
|
299 AUDIO_DEVICE_IN_ANC_HEADSET = 0x10000000, |
|
300 AUDIO_DEVICE_IN_FM_RX = 0x20000000, |
|
301 AUDIO_DEVICE_IN_FM_RX_A2DP = 0x40000000, |
|
302 AUDIO_DEVICE_IN_DEFAULT = 0x80000000, |
|
303 |
|
304 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION | |
|
305 AUDIO_DEVICE_IN_AMBIENT | |
|
306 AUDIO_DEVICE_IN_BUILTIN_MIC | |
|
307 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET | |
|
308 AUDIO_DEVICE_IN_WIRED_HEADSET | |
|
309 AUDIO_DEVICE_IN_AUX_DIGITAL | |
|
310 AUDIO_DEVICE_IN_VOICE_CALL | |
|
311 AUDIO_DEVICE_IN_BACK_MIC | |
|
312 AUDIO_DEVICE_IN_ANC_HEADSET | |
|
313 AUDIO_DEVICE_IN_FM_RX | |
|
314 AUDIO_DEVICE_IN_FM_RX_A2DP | |
|
315 AUDIO_DEVICE_IN_DEFAULT), |
|
316 AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, |
|
317 } audio_devices_t; |
|
318 #else |
|
319 enum { |
|
320 AUDIO_DEVICE_NONE = 0x0, |
|
321 /* reserved bits */ |
|
322 AUDIO_DEVICE_BIT_IN = 0x80000000, |
|
323 AUDIO_DEVICE_BIT_DEFAULT = 0x40000000, |
|
324 /* output devices */ |
|
325 AUDIO_DEVICE_OUT_EARPIECE = 0x1, |
|
326 AUDIO_DEVICE_OUT_SPEAKER = 0x2, |
|
327 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4, |
|
328 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8, |
|
329 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10, |
|
330 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20, |
|
331 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40, |
|
332 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80, |
|
333 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100, |
|
334 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200, |
|
335 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400, |
|
336 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800, |
|
337 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000, |
|
338 AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000, |
|
339 AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000, |
|
340 AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000, |
|
341 AUDIO_DEVICE_OUT_ANC_HEADSET = 0x10000, |
|
342 AUDIO_DEVICE_OUT_ANC_HEADPHONE = 0x20000, |
|
343 AUDIO_DEVICE_OUT_PROXY = 0x40000, |
|
344 AUDIO_DEVICE_OUT_FM = 0x80000, |
|
345 AUDIO_DEVICE_OUT_FM_TX = 0x100000, |
|
346 AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT, |
|
347 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE | |
|
348 AUDIO_DEVICE_OUT_SPEAKER | |
|
349 AUDIO_DEVICE_OUT_WIRED_HEADSET | |
|
350 AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
|
351 AUDIO_DEVICE_OUT_BLUETOOTH_SCO | |
|
352 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | |
|
353 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT | |
|
354 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | |
|
355 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
|
356 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | |
|
357 AUDIO_DEVICE_OUT_AUX_DIGITAL | |
|
358 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | |
|
359 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | |
|
360 AUDIO_DEVICE_OUT_USB_ACCESSORY | |
|
361 AUDIO_DEVICE_OUT_USB_DEVICE | |
|
362 AUDIO_DEVICE_OUT_REMOTE_SUBMIX | |
|
363 AUDIO_DEVICE_OUT_ANC_HEADSET | |
|
364 AUDIO_DEVICE_OUT_ANC_HEADPHONE | |
|
365 AUDIO_DEVICE_OUT_PROXY | |
|
366 AUDIO_DEVICE_OUT_FM | |
|
367 AUDIO_DEVICE_OUT_FM_TX | |
|
368 AUDIO_DEVICE_OUT_DEFAULT), |
|
369 AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | |
|
370 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
|
371 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER), |
|
372 AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO | |
|
373 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | |
|
374 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT), |
|
375 AUDIO_DEVICE_OUT_ALL_USB = (AUDIO_DEVICE_OUT_USB_ACCESSORY | |
|
376 AUDIO_DEVICE_OUT_USB_DEVICE), |
|
377 |
|
378 /* input devices */ |
|
379 AUDIO_DEVICE_IN_COMMUNICATION = AUDIO_DEVICE_BIT_IN | 0x1, |
|
380 AUDIO_DEVICE_IN_AMBIENT = AUDIO_DEVICE_BIT_IN | 0x2, |
|
381 AUDIO_DEVICE_IN_BUILTIN_MIC = AUDIO_DEVICE_BIT_IN | 0x4, |
|
382 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8, |
|
383 AUDIO_DEVICE_IN_WIRED_HEADSET = AUDIO_DEVICE_BIT_IN | 0x10, |
|
384 AUDIO_DEVICE_IN_AUX_DIGITAL = AUDIO_DEVICE_BIT_IN | 0x20, |
|
385 AUDIO_DEVICE_IN_VOICE_CALL = AUDIO_DEVICE_BIT_IN | 0x40, |
|
386 AUDIO_DEVICE_IN_BACK_MIC = AUDIO_DEVICE_BIT_IN | 0x80, |
|
387 AUDIO_DEVICE_IN_REMOTE_SUBMIX = AUDIO_DEVICE_BIT_IN | 0x100, |
|
388 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x200, |
|
389 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x400, |
|
390 AUDIO_DEVICE_IN_USB_ACCESSORY = AUDIO_DEVICE_BIT_IN | 0x800, |
|
391 AUDIO_DEVICE_IN_USB_DEVICE = AUDIO_DEVICE_BIT_IN | 0x1000, |
|
392 AUDIO_DEVICE_IN_ANC_HEADSET = AUDIO_DEVICE_BIT_IN | 0x2000, |
|
393 AUDIO_DEVICE_IN_PROXY = AUDIO_DEVICE_BIT_IN | 0x4000, |
|
394 AUDIO_DEVICE_IN_FM_RX = AUDIO_DEVICE_BIT_IN | 0x8000, |
|
395 AUDIO_DEVICE_IN_FM_RX_A2DP = AUDIO_DEVICE_BIT_IN | 0x10000, |
|
396 AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT, |
|
397 |
|
398 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION | |
|
399 AUDIO_DEVICE_IN_AMBIENT | |
|
400 AUDIO_DEVICE_IN_BUILTIN_MIC | |
|
401 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET | |
|
402 AUDIO_DEVICE_IN_WIRED_HEADSET | |
|
403 AUDIO_DEVICE_IN_AUX_DIGITAL | |
|
404 AUDIO_DEVICE_IN_VOICE_CALL | |
|
405 AUDIO_DEVICE_IN_BACK_MIC | |
|
406 AUDIO_DEVICE_IN_REMOTE_SUBMIX | |
|
407 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET | |
|
408 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET | |
|
409 AUDIO_DEVICE_IN_USB_ACCESSORY | |
|
410 AUDIO_DEVICE_IN_USB_DEVICE | |
|
411 AUDIO_DEVICE_IN_ANC_HEADSET | |
|
412 AUDIO_DEVICE_IN_FM_RX | |
|
413 AUDIO_DEVICE_IN_FM_RX_A2DP | |
|
414 AUDIO_DEVICE_IN_PROXY | |
|
415 AUDIO_DEVICE_IN_DEFAULT), |
|
416 AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, |
|
417 }; |
|
418 |
|
419 typedef uint32_t audio_devices_t; |
|
420 #endif |
|
421 |
|
422 /* device connection states used for audio_policy->set_device_connection_state() |
|
423 * */ |
|
424 typedef enum { |
|
425 AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, |
|
426 AUDIO_POLICY_DEVICE_STATE_AVAILABLE, |
|
427 |
|
428 AUDIO_POLICY_DEVICE_STATE_CNT, |
|
429 AUDIO_POLICY_DEVICE_STATE_MAX = AUDIO_POLICY_DEVICE_STATE_CNT - 1, |
|
430 } audio_policy_dev_state_t; |
|
431 |
|
432 namespace android { |
|
433 |
|
434 typedef void (*audio_error_callback)(status_t err); |
|
435 typedef int audio_io_handle_t; |
|
436 |
|
437 class IAudioPolicyService; |
|
438 class String8; |
|
439 |
|
440 class AudioSystem |
|
441 { |
|
442 public: |
|
443 |
|
444 enum stream_type { |
|
445 DEFAULT =-1, |
|
446 VOICE_CALL = 0, |
|
447 SYSTEM = 1, |
|
448 RING = 2, |
|
449 MUSIC = 3, |
|
450 ALARM = 4, |
|
451 NOTIFICATION = 5, |
|
452 BLUETOOTH_SCO = 6, |
|
453 ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker |
|
454 DTMF = 8, |
|
455 TTS = 9, |
|
456 FM = 10, |
|
457 NUM_STREAM_TYPES |
|
458 }; |
|
459 |
|
460 // Audio sub formats (see AudioSystem::audio_format). |
|
461 enum pcm_sub_format { |
|
462 PCM_SUB_16_BIT = 0x1, // must be 1 for backward compatibility |
|
463 PCM_SUB_8_BIT = 0x2, // must be 2 for backward compatibility |
|
464 }; |
|
465 |
|
466 // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify |
|
467 // bit rate, stereo mode, version... |
|
468 enum mp3_sub_format { |
|
469 //TODO |
|
470 }; |
|
471 |
|
472 // AMR NB/WB sub format field definition: specify frame block interleaving, bandwidth efficient or octet aligned, |
|
473 // encoding mode for recording... |
|
474 enum amr_sub_format { |
|
475 //TODO |
|
476 }; |
|
477 |
|
478 // AAC sub format field definition: specify profile or bitrate for recording... |
|
479 enum aac_sub_format { |
|
480 //TODO |
|
481 }; |
|
482 |
|
483 // VORBIS sub format field definition: specify quality for recording... |
|
484 enum vorbis_sub_format { |
|
485 //TODO |
|
486 }; |
|
487 |
|
488 // Audio format consists in a main format field (upper 8 bits) and a sub format field (lower 24 bits). |
|
489 // The main format indicates the main codec type. The sub format field indicates options and parameters |
|
490 // for each format. The sub format is mainly used for record to indicate for instance the requested bitrate |
|
491 // or profile. It can also be used for certain formats to give informations not present in the encoded |
|
492 // audio stream (e.g. octet alignement for AMR). |
|
493 enum audio_format { |
|
494 INVALID_FORMAT = -1, |
|
495 FORMAT_DEFAULT = 0, |
|
496 PCM = 0x00000000, // must be 0 for backward compatibility |
|
497 MP3 = 0x01000000, |
|
498 AMR_NB = 0x02000000, |
|
499 AMR_WB = 0x03000000, |
|
500 AAC = 0x04000000, |
|
501 HE_AAC_V1 = 0x05000000, |
|
502 HE_AAC_V2 = 0x06000000, |
|
503 VORBIS = 0x07000000, |
|
504 EVRC = 0x08000000, |
|
505 QCELP = 0x09000000, |
|
506 VOIP_PCM_INPUT = 0x0A000000, |
|
507 MAIN_FORMAT_MASK = 0xFF000000, |
|
508 SUB_FORMAT_MASK = 0x00FFFFFF, |
|
509 // Aliases |
|
510 PCM_16_BIT = (PCM|PCM_SUB_16_BIT), |
|
511 PCM_8_BIT = (PCM|PCM_SUB_8_BIT) |
|
512 }; |
|
513 |
|
514 |
|
515 // Channel mask definitions must be kept in sync with JAVA values in /media/java/android/media/AudioFormat.java |
|
516 enum audio_channels { |
|
517 // output channels |
|
518 CHANNEL_OUT_FRONT_LEFT = 0x4, |
|
519 CHANNEL_OUT_FRONT_RIGHT = 0x8, |
|
520 CHANNEL_OUT_FRONT_CENTER = 0x10, |
|
521 CHANNEL_OUT_LOW_FREQUENCY = 0x20, |
|
522 CHANNEL_OUT_BACK_LEFT = 0x40, |
|
523 CHANNEL_OUT_BACK_RIGHT = 0x80, |
|
524 CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100, |
|
525 CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200, |
|
526 CHANNEL_OUT_BACK_CENTER = 0x400, |
|
527 CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT, |
|
528 CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT), |
|
529 CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | |
|
530 CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT), |
|
531 CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | |
|
532 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER), |
|
533 CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | |
|
534 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT), |
|
535 CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | |
|
536 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT | |
|
537 CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER), |
|
538 CHANNEL_OUT_ALL = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT | |
|
539 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT | |
|
540 CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | CHANNEL_OUT_BACK_CENTER), |
|
541 |
|
542 // input channels |
|
543 CHANNEL_IN_LEFT = 0x4, |
|
544 CHANNEL_IN_RIGHT = 0x8, |
|
545 CHANNEL_IN_FRONT = 0x10, |
|
546 CHANNEL_IN_BACK = 0x20, |
|
547 CHANNEL_IN_LEFT_PROCESSED = 0x40, |
|
548 CHANNEL_IN_RIGHT_PROCESSED = 0x80, |
|
549 CHANNEL_IN_FRONT_PROCESSED = 0x100, |
|
550 CHANNEL_IN_BACK_PROCESSED = 0x200, |
|
551 CHANNEL_IN_PRESSURE = 0x400, |
|
552 CHANNEL_IN_X_AXIS = 0x800, |
|
553 CHANNEL_IN_Y_AXIS = 0x1000, |
|
554 CHANNEL_IN_Z_AXIS = 0x2000, |
|
555 CHANNEL_IN_VOICE_UPLINK = 0x4000, |
|
556 CHANNEL_IN_VOICE_DNLINK = 0x8000, |
|
557 CHANNEL_IN_MONO = CHANNEL_IN_FRONT, |
|
558 CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT), |
|
559 CHANNEL_IN_ALL = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_FRONT | CHANNEL_IN_BACK| |
|
560 CHANNEL_IN_LEFT_PROCESSED | CHANNEL_IN_RIGHT_PROCESSED | CHANNEL_IN_FRONT_PROCESSED | CHANNEL_IN_BACK_PROCESSED| |
|
561 CHANNEL_IN_PRESSURE | CHANNEL_IN_X_AXIS | CHANNEL_IN_Y_AXIS | CHANNEL_IN_Z_AXIS | |
|
562 CHANNEL_IN_VOICE_UPLINK | CHANNEL_IN_VOICE_DNLINK) |
|
563 }; |
|
564 |
|
565 enum audio_mode { |
|
566 MODE_INVALID = -2, |
|
567 MODE_CURRENT = -1, |
|
568 MODE_NORMAL = 0, |
|
569 MODE_RINGTONE, |
|
570 MODE_IN_CALL, |
|
571 MODE_IN_COMMUNICATION, |
|
572 NUM_MODES // not a valid entry, denotes end-of-list |
|
573 }; |
|
574 |
|
575 enum audio_in_acoustics { |
|
576 AGC_ENABLE = 0x0001, |
|
577 AGC_DISABLE = 0, |
|
578 NS_ENABLE = 0x0002, |
|
579 NS_DISABLE = 0, |
|
580 TX_IIR_ENABLE = 0x0004, |
|
581 TX_DISABLE = 0 |
|
582 }; |
|
583 |
|
584 // special audio session values |
|
585 enum audio_sessions { |
|
586 SESSION_OUTPUT_STAGE = -1, // session for effects attached to a particular output stream |
|
587 // (value must be less than 0) |
|
588 SESSION_OUTPUT_MIX = 0, // session for effects applied to output mix. These effects can |
|
589 // be moved by audio policy manager to another output stream |
|
590 // (value must be 0) |
|
591 }; |
|
592 |
|
593 /* These are static methods to control the system-wide AudioFlinger |
|
594 * only privileged processes can have access to them |
|
595 */ |
|
596 |
|
597 // mute/unmute microphone |
|
598 static status_t muteMicrophone(bool state); |
|
599 static status_t isMicrophoneMuted(bool *state); |
|
600 |
|
601 // set/get master volume |
|
602 static status_t setMasterVolume(float value); |
|
603 static status_t getMasterVolume(float* volume); |
|
604 // mute/unmute audio outputs |
|
605 static status_t setMasterMute(bool mute); |
|
606 static status_t getMasterMute(bool* mute); |
|
607 |
|
608 // set/get stream volume on specified output |
|
609 static status_t setStreamVolume(int stream, float value, int output); |
|
610 static status_t getStreamVolume(int stream, float* volume, int output); |
|
611 |
|
612 // mute/unmute stream |
|
613 static status_t setStreamMute(int stream, bool mute); |
|
614 static status_t getStreamMute(int stream, bool* mute); |
|
615 |
|
616 // set audio mode in audio hardware (see AudioSystem::audio_mode) |
|
617 static status_t setMode(int mode); |
|
618 |
|
619 // returns true in *state if tracks are active on the specified stream |
|
620 static status_t isStreamActive(int stream, bool *state); |
|
621 |
|
622 // set/get audio hardware parameters. The function accepts a list of parameters |
|
623 // key value pairs in the form: key1=value1;key2=value2;... |
|
624 // Some keys are reserved for standard parameters (See AudioParameter class). |
|
625 static status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs); |
|
626 static String8 getParameters(audio_io_handle_t ioHandle, const String8& keys); |
|
627 |
|
628 static void setErrorCallback(audio_error_callback cb); |
|
629 |
|
630 // helper function to obtain AudioFlinger service handle |
|
631 static const sp<IAudioFlinger>& get_audio_flinger(); |
|
632 |
|
633 static float linearToLog(int volume); |
|
634 static int logToLinear(float volume); |
|
635 |
|
636 static status_t getOutputSamplingRate(int* samplingRate, int stream = DEFAULT); |
|
637 static status_t getOutputFrameCount(int* frameCount, int stream = DEFAULT); |
|
638 static status_t getOutputLatency(uint32_t* latency, int stream = DEFAULT); |
|
639 |
|
640 static bool routedToA2dpOutput(int streamType); |
|
641 |
|
642 static status_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount, |
|
643 size_t* buffSize); |
|
644 |
|
645 static status_t setVoiceVolume(float volume); |
|
646 |
|
647 // return the number of audio frames written by AudioFlinger to audio HAL and |
|
648 // audio dsp to DAC since the output on which the specificed stream is playing |
|
649 // has exited standby. |
|
650 // returned status (from utils/Errors.h) can be: |
|
651 // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data |
|
652 // - INVALID_OPERATION: Not supported on current hardware platform |
|
653 // - BAD_VALUE: invalid parameter |
|
654 // NOTE: this feature is not supported on all hardware platforms and it is |
|
655 // necessary to check returned status before using the returned values. |
|
656 static status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int stream = DEFAULT); |
|
657 |
|
658 static unsigned int getInputFramesLost(audio_io_handle_t ioHandle); |
|
659 |
|
660 static int newAudioSessionId(); |
|
661 // |
|
662 // AudioPolicyService interface |
|
663 // |
|
664 |
|
665 enum audio_devices { |
|
666 // output devices |
|
667 DEVICE_OUT_EARPIECE = 0x1, |
|
668 DEVICE_OUT_SPEAKER = 0x2, |
|
669 DEVICE_OUT_WIRED_HEADSET = 0x4, |
|
670 DEVICE_OUT_WIRED_HEADPHONE = 0x8, |
|
671 DEVICE_OUT_BLUETOOTH_SCO = 0x10, |
|
672 DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20, |
|
673 DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40, |
|
674 DEVICE_OUT_BLUETOOTH_A2DP = 0x80, |
|
675 DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100, |
|
676 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200, |
|
677 DEVICE_OUT_AUX_DIGITAL = 0x400, |
|
678 DEVICE_OUT_DEFAULT = 0x8000, |
|
679 DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET | |
|
680 DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET | |
|
681 DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
|
682 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL | DEVICE_OUT_DEFAULT), |
|
683 DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
|
684 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER), |
|
685 |
|
686 // input devices |
|
687 DEVICE_IN_COMMUNICATION = 0x10000, |
|
688 DEVICE_IN_AMBIENT = 0x20000, |
|
689 DEVICE_IN_BUILTIN_MIC = 0x40000, |
|
690 DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000, |
|
691 DEVICE_IN_WIRED_HEADSET = 0x100000, |
|
692 DEVICE_IN_AUX_DIGITAL = 0x200000, |
|
693 DEVICE_IN_VOICE_CALL = 0x400000, |
|
694 DEVICE_IN_BACK_MIC = 0x800000, |
|
695 DEVICE_IN_DEFAULT = 0x80000000, |
|
696 |
|
697 DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC | |
|
698 DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL | |
|
699 DEVICE_IN_VOICE_CALL | DEVICE_IN_BACK_MIC | DEVICE_IN_DEFAULT) |
|
700 }; |
|
701 |
|
702 // device connection states used for setDeviceConnectionState() |
|
703 enum device_connection_state { |
|
704 DEVICE_STATE_UNAVAILABLE, |
|
705 DEVICE_STATE_AVAILABLE, |
|
706 NUM_DEVICE_STATES |
|
707 }; |
|
708 |
|
709 // request to open a direct output with getOutput() (by opposition to sharing an output with other AudioTracks) |
|
710 enum output_flags { |
|
711 OUTPUT_FLAG_INDIRECT = 0x0, |
|
712 OUTPUT_FLAG_DIRECT = 0x1 |
|
713 }; |
|
714 |
|
715 // device categories used for setForceUse() |
|
716 enum forced_config { |
|
717 FORCE_NONE, |
|
718 FORCE_SPEAKER, |
|
719 FORCE_HEADPHONES, |
|
720 FORCE_BT_SCO, |
|
721 FORCE_BT_A2DP, |
|
722 FORCE_WIRED_ACCESSORY, |
|
723 FORCE_BT_CAR_DOCK, |
|
724 FORCE_BT_DESK_DOCK, |
|
725 NUM_FORCE_CONFIG, |
|
726 FORCE_DEFAULT = FORCE_NONE |
|
727 }; |
|
728 |
|
729 // usages used for setForceUse() |
|
730 enum force_use { |
|
731 FOR_COMMUNICATION, |
|
732 FOR_MEDIA, |
|
733 FOR_RECORD, |
|
734 FOR_DOCK, |
|
735 NUM_FORCE_USE |
|
736 }; |
|
737 |
|
738 // types of io configuration change events received with ioConfigChanged() |
|
739 enum io_config_event { |
|
740 OUTPUT_OPENED, |
|
741 OUTPUT_CLOSED, |
|
742 OUTPUT_CONFIG_CHANGED, |
|
743 INPUT_OPENED, |
|
744 INPUT_CLOSED, |
|
745 INPUT_CONFIG_CHANGED, |
|
746 STREAM_CONFIG_CHANGED, |
|
747 NUM_CONFIG_EVENTS |
|
748 }; |
|
749 |
|
750 // audio output descritor used to cache output configurations in client process to avoid frequent calls |
|
751 // through IAudioFlinger |
|
752 class OutputDescriptor { |
|
753 public: |
|
754 OutputDescriptor() |
|
755 : samplingRate(0), format(0), channels(0), frameCount(0), latency(0) {} |
|
756 |
|
757 uint32_t samplingRate; |
|
758 int32_t format; |
|
759 int32_t channels; |
|
760 size_t frameCount; |
|
761 uint32_t latency; |
|
762 }; |
|
763 |
|
764 // |
|
765 // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions) |
|
766 // |
|
767 static status_t setDeviceConnectionState(audio_devices device, device_connection_state state, const char *device_address); |
|
768 static device_connection_state getDeviceConnectionState(audio_devices device, const char *device_address); |
|
769 static status_t setPhoneState(int state); |
|
770 #if ANDROID_VERSION >= 17 |
|
771 static status_t setPhoneState(audio_mode_t state); |
|
772 #endif |
|
773 static status_t setRingerMode(uint32_t mode, uint32_t mask); |
|
774 #ifdef VANILLA_ANDROID |
|
775 static status_t setForceUse(force_use usage, forced_config config); |
|
776 static forced_config getForceUse(force_use usage); |
|
777 static audio_io_handle_t getOutput(stream_type stream, |
|
778 uint32_t samplingRate = 0, |
|
779 uint32_t format = FORMAT_DEFAULT, |
|
780 uint32_t channels = CHANNEL_OUT_STEREO, |
|
781 output_flags flags = OUTPUT_FLAG_INDIRECT); |
|
782 static status_t setDeviceConnectionState(audio_devices_t device, audio_policy_dev_state_t state, const char *device_address); |
|
783 static status_t setFmVolume(float volume); |
|
784 static audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device, const char *device_address); |
|
785 #else |
|
786 static status_t setForceUse(force_use usage, forced_config config) __attribute__((weak)); |
|
787 static forced_config getForceUse(force_use usage) __attribute__((weak)); |
|
788 static audio_io_handle_t getOutput(stream_type stream, |
|
789 uint32_t samplingRate = 0, |
|
790 uint32_t format = FORMAT_DEFAULT, |
|
791 uint32_t channels = CHANNEL_OUT_STEREO, |
|
792 output_flags flags = OUTPUT_FLAG_INDIRECT) __attribute__((weak)); |
|
793 |
|
794 static status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) __attribute__((weak)); |
|
795 static audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage) __attribute__((weak)); |
|
796 static audio_io_handle_t getOutput(audio_stream_type_t stream, |
|
797 uint32_t samplingRate = 0, |
|
798 uint32_t format = AUDIO_FORMAT_DEFAULT, |
|
799 uint32_t channels = AUDIO_CHANNEL_OUT_STEREO, |
|
800 audio_policy_output_flags_t flags = AUDIO_POLICY_OUTPUT_FLAG_INDIRECT) __attribute__((weak)); |
|
801 static status_t setDeviceConnectionState(audio_devices_t device, audio_policy_dev_state_t state, const char *device_address) __attribute__((weak)); |
|
802 static status_t setFmVolume(float volume) __attribute__((weak)); |
|
803 static audio_policy_dev_state_t getDeviceConnectionState(audio_devices_t device, const char *device_address) __attribute__((weak)); |
|
804 |
|
805 #endif |
|
806 static status_t startOutput(audio_io_handle_t output, |
|
807 AudioSystem::stream_type stream, |
|
808 int session = 0); |
|
809 static status_t stopOutput(audio_io_handle_t output, |
|
810 AudioSystem::stream_type stream, |
|
811 int session = 0); |
|
812 static void releaseOutput(audio_io_handle_t output); |
|
813 static audio_io_handle_t getInput(int inputSource, |
|
814 uint32_t samplingRate = 0, |
|
815 uint32_t format = FORMAT_DEFAULT, |
|
816 uint32_t channels = CHANNEL_IN_MONO, |
|
817 audio_in_acoustics acoustics = (audio_in_acoustics)0); |
|
818 static status_t startInput(audio_io_handle_t input); |
|
819 static status_t stopInput(audio_io_handle_t input); |
|
820 static void releaseInput(audio_io_handle_t input); |
|
821 static status_t initStreamVolume(stream_type stream, |
|
822 int indexMin, |
|
823 int indexMax); |
|
824 static status_t initStreamVolume(audio_stream_type_t stream, |
|
825 int indexMin, |
|
826 int indexMax); |
|
827 static status_t setStreamVolumeIndex(stream_type stream, int index); |
|
828 static status_t setStreamVolumeIndex(audio_stream_type_t stream, int index); |
|
829 #if ANDROID_VERSION >= 17 |
|
830 static status_t setStreamVolumeIndex(audio_stream_type_t stream, |
|
831 int index, |
|
832 audio_devices_t device); |
|
833 static status_t getStreamVolumeIndex(audio_stream_type_t stream, |
|
834 int *index, |
|
835 audio_devices_t device); |
|
836 #endif |
|
837 static status_t getStreamVolumeIndex(stream_type stream, int *index); |
|
838 static status_t getStreamVolumeIndex(audio_stream_type_t stream, int *index); |
|
839 |
|
840 static uint32_t getStrategyForStream(stream_type stream); |
|
841 |
|
842 static audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc); |
|
843 static status_t registerEffect(effect_descriptor_t *desc, |
|
844 audio_io_handle_t output, |
|
845 uint32_t strategy, |
|
846 int session, |
|
847 int id); |
|
848 static status_t unregisterEffect(int id); |
|
849 |
|
850 static const sp<IAudioPolicyService>& get_audio_policy_service(); |
|
851 |
|
852 // ---------------------------------------------------------------------------- |
|
853 |
|
854 static uint32_t popCount(uint32_t u); |
|
855 static bool isOutputDevice(audio_devices device); |
|
856 static bool isInputDevice(audio_devices device); |
|
857 static bool isA2dpDevice(audio_devices device); |
|
858 static bool isBluetoothScoDevice(audio_devices device); |
|
859 static bool isSeperatedStream(stream_type stream); |
|
860 static bool isLowVisibility(stream_type stream); |
|
861 static bool isOutputChannel(uint32_t channel); |
|
862 static bool isInputChannel(uint32_t channel); |
|
863 static bool isValidFormat(uint32_t format); |
|
864 static bool isLinearPCM(uint32_t format); |
|
865 static bool isModeInCall(); |
|
866 |
|
867 private: |
|
868 |
|
869 class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient |
|
870 { |
|
871 public: |
|
872 AudioFlingerClient() { |
|
873 } |
|
874 |
|
875 // DeathRecipient |
|
876 virtual void binderDied(const wp<IBinder>& who); |
|
877 |
|
878 // IAudioFlingerClient |
|
879 |
|
880 // indicate a change in the configuration of an output or input: keeps the cached |
|
881 // values for output/input parameters upto date in client process |
|
882 virtual void ioConfigChanged(int event, int ioHandle, void *param2); |
|
883 }; |
|
884 |
|
885 class AudioPolicyServiceClient: public IBinder::DeathRecipient |
|
886 { |
|
887 public: |
|
888 AudioPolicyServiceClient() { |
|
889 } |
|
890 |
|
891 // DeathRecipient |
|
892 virtual void binderDied(const wp<IBinder>& who); |
|
893 }; |
|
894 |
|
895 static sp<AudioFlingerClient> gAudioFlingerClient; |
|
896 static sp<AudioPolicyServiceClient> gAudioPolicyServiceClient; |
|
897 friend class AudioFlingerClient; |
|
898 friend class AudioPolicyServiceClient; |
|
899 |
|
900 static Mutex gLock; |
|
901 static sp<IAudioFlinger> gAudioFlinger; |
|
902 static audio_error_callback gAudioErrorCallback; |
|
903 |
|
904 static size_t gInBuffSize; |
|
905 // previous parameters for recording buffer size queries |
|
906 static uint32_t gPrevInSamplingRate; |
|
907 static int gPrevInFormat; |
|
908 static int gPrevInChannelCount; |
|
909 |
|
910 static sp<IAudioPolicyService> gAudioPolicyService; |
|
911 |
|
912 // mapping between stream types and outputs |
|
913 static DefaultKeyedVector<int, audio_io_handle_t> gStreamOutputMap; |
|
914 // list of output descritor containing cached parameters (sampling rate, framecount, channel count...) |
|
915 static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs; |
|
916 }; |
|
917 |
|
918 class AudioParameter { |
|
919 |
|
920 public: |
|
921 AudioParameter() {} |
|
922 AudioParameter(const String8& keyValuePairs); |
|
923 virtual ~AudioParameter(); |
|
924 |
|
925 // reserved parameter keys for changing standard parameters with setParameters() function. |
|
926 // Using these keys is mandatory for AudioFlinger to properly monitor audio output/input |
|
927 // configuration changes and act accordingly. |
|
928 // keyRouting: to change audio routing, value is an int in AudioSystem::audio_devices |
|
929 // keySamplingRate: to change sampling rate routing, value is an int |
|
930 // keyFormat: to change audio format, value is an int in AudioSystem::audio_format |
|
931 // keyChannels: to change audio channel configuration, value is an int in AudioSystem::audio_channels |
|
932 // keyFrameCount: to change audio output frame count, value is an int |
|
933 // keyInputSource: to change audio input source, value is an int in audio_source |
|
934 // (defined in media/mediarecorder.h) |
|
935 static const char *keyRouting; |
|
936 static const char *keySamplingRate; |
|
937 static const char *keyFormat; |
|
938 static const char *keyChannels; |
|
939 static const char *keyFrameCount; |
|
940 static const char *keyInputSource; |
|
941 |
|
942 String8 toString(); |
|
943 |
|
944 status_t add(const String8& key, const String8& value); |
|
945 status_t addInt(const String8& key, const int value); |
|
946 status_t addFloat(const String8& key, const float value); |
|
947 |
|
948 status_t remove(const String8& key); |
|
949 |
|
950 status_t get(const String8& key, String8& value); |
|
951 status_t getInt(const String8& key, int& value); |
|
952 status_t getFloat(const String8& key, float& value); |
|
953 status_t getAt(size_t index, String8& key, String8& value); |
|
954 |
|
955 size_t size() { return mParameters.size(); } |
|
956 |
|
957 private: |
|
958 String8 mKeyValuePairs; |
|
959 KeyedVector <String8, String8> mParameters; |
|
960 }; |
|
961 |
|
962 }; // namespace android |
|
963 |
|
964 #endif /*ANDROID_AUDIOSYSTEM_H_*/ |