blob: edf4b8b753795d8821720483b3452db73480df89 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
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 <media/IAudioFlinger.h>
23
24namespace android {
25
26typedef void (*audio_error_callback)(status_t err);
Eric Laurentfa2877b2009-07-28 08:44:33 -070027typedef int audio_io_handle_t;
Eric Laurentc2f1f072009-07-17 12:17:14 -070028
29class IAudioPolicyService;
30class String8;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080031
32class AudioSystem
33{
34public:
35
Glenn Kasten4bcae822011-04-04 10:50:50 -070036 // must match android/media/AudioSystem.java STREAM_* constants
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080037 enum stream_type {
Eric Laurentc2f1f072009-07-17 12:17:14 -070038 DEFAULT =-1,
39 VOICE_CALL = 0,
40 SYSTEM = 1,
41 RING = 2,
42 MUSIC = 3,
43 ALARM = 4,
44 NOTIFICATION = 5,
45 BLUETOOTH_SCO = 6,
Eric Laurent29a65002009-03-27 18:18:46 -070046 ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
Eric Laurentc2f1f072009-07-17 12:17:14 -070047 DTMF = 8,
48 TTS = 9,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080049 NUM_STREAM_TYPES
50 };
51
Eric Laurentc2f1f072009-07-17 12:17:14 -070052 // Audio sub formats (see AudioSystem::audio_format).
53 enum pcm_sub_format {
Eric Laurentffe9c252010-06-23 17:38:20 -070054 PCM_SUB_16_BIT = 0x1, // must be 1 for backward compatibility
55 PCM_SUB_8_BIT = 0x2, // must be 2 for backward compatibility
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080056 };
57
Glenn Kasten4bcae822011-04-04 10:50:50 -070058 // FIXME These sub_format enums are currently unused
59
Eric Laurentc2f1f072009-07-17 12:17:14 -070060 // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify
61 // bit rate, stereo mode, version...
62 enum mp3_sub_format {
63 //TODO
64 };
65
66 // AMR NB/WB sub format field definition: specify frame block interleaving, bandwidth efficient or octet aligned,
67 // encoding mode for recording...
68 enum amr_sub_format {
69 //TODO
70 };
71
72 // AAC sub format field definition: specify profile or bitrate for recording...
73 enum aac_sub_format {
74 //TODO
75 };
76
77 // VORBIS sub format field definition: specify quality for recording...
78 enum vorbis_sub_format {
79 //TODO
80 };
81
82 // Audio format consists in a main format field (upper 8 bits) and a sub format field (lower 24 bits).
83 // The main format indicates the main codec type. The sub format field indicates options and parameters
84 // for each format. The sub format is mainly used for record to indicate for instance the requested bitrate
85 // or profile. It can also be used for certain formats to give informations not present in the encoded
86 // audio stream (e.g. octet alignement for AMR).
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080087 enum audio_format {
Eric Laurentc2f1f072009-07-17 12:17:14 -070088 INVALID_FORMAT = -1,
89 FORMAT_DEFAULT = 0,
90 PCM = 0x00000000, // must be 0 for backward compatibility
91 MP3 = 0x01000000,
92 AMR_NB = 0x02000000,
93 AMR_WB = 0x03000000,
94 AAC = 0x04000000,
95 HE_AAC_V1 = 0x05000000,
96 HE_AAC_V2 = 0x06000000,
97 VORBIS = 0x07000000,
98 MAIN_FORMAT_MASK = 0xFF000000,
99 SUB_FORMAT_MASK = 0x00FFFFFF,
100 // Aliases
101 PCM_16_BIT = (PCM|PCM_SUB_16_BIT),
102 PCM_8_BIT = (PCM|PCM_SUB_8_BIT)
103 };
104
105
Glenn Kasten4bcae822011-04-04 10:50:50 -0700106 // Channel mask definitions must be kept in sync with values in /media/java/android/media/AudioFormat.java
Eric Laurentc2f1f072009-07-17 12:17:14 -0700107 enum audio_channels {
108 // output channels
Eric Laurentffe9c252010-06-23 17:38:20 -0700109 CHANNEL_OUT_FRONT_LEFT = 0x4,
110 CHANNEL_OUT_FRONT_RIGHT = 0x8,
111 CHANNEL_OUT_FRONT_CENTER = 0x10,
112 CHANNEL_OUT_LOW_FREQUENCY = 0x20,
113 CHANNEL_OUT_BACK_LEFT = 0x40,
114 CHANNEL_OUT_BACK_RIGHT = 0x80,
115 CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
116 CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
117 CHANNEL_OUT_BACK_CENTER = 0x400,
118 CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT,
119 CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT),
120 CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
121 CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
122 CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
123 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER),
124 CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
125 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
126 CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
127 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
128 CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER),
Eric Laurentc2f1f072009-07-17 12:17:14 -0700129 CHANNEL_OUT_ALL = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
130 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
131 CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | CHANNEL_OUT_BACK_CENTER),
132
133 // input channels
Eric Laurent9a920372009-07-27 07:12:26 -0700134 CHANNEL_IN_LEFT = 0x4,
135 CHANNEL_IN_RIGHT = 0x8,
136 CHANNEL_IN_FRONT = 0x10,
137 CHANNEL_IN_BACK = 0x20,
138 CHANNEL_IN_LEFT_PROCESSED = 0x40,
139 CHANNEL_IN_RIGHT_PROCESSED = 0x80,
140 CHANNEL_IN_FRONT_PROCESSED = 0x100,
141 CHANNEL_IN_BACK_PROCESSED = 0x200,
142 CHANNEL_IN_PRESSURE = 0x400,
143 CHANNEL_IN_X_AXIS = 0x800,
144 CHANNEL_IN_Y_AXIS = 0x1000,
145 CHANNEL_IN_Z_AXIS = 0x2000,
146 CHANNEL_IN_VOICE_UPLINK = 0x4000,
147 CHANNEL_IN_VOICE_DNLINK = 0x8000,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700148 CHANNEL_IN_MONO = CHANNEL_IN_FRONT,
149 CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT),
150 CHANNEL_IN_ALL = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_FRONT | CHANNEL_IN_BACK|
151 CHANNEL_IN_LEFT_PROCESSED | CHANNEL_IN_RIGHT_PROCESSED | CHANNEL_IN_FRONT_PROCESSED | CHANNEL_IN_BACK_PROCESSED|
152 CHANNEL_IN_PRESSURE | CHANNEL_IN_X_AXIS | CHANNEL_IN_Y_AXIS | CHANNEL_IN_Z_AXIS |
153 CHANNEL_IN_VOICE_UPLINK | CHANNEL_IN_VOICE_DNLINK)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800154 };
155
Glenn Kasten4bcae822011-04-04 10:50:50 -0700156 // must match android/media/AudioSystem.java MODE_* values
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800157 enum audio_mode {
158 MODE_INVALID = -2,
159 MODE_CURRENT = -1,
160 MODE_NORMAL = 0,
161 MODE_RINGTONE,
162 MODE_IN_CALL,
Jean-Michel Trivif1fb01a2010-11-15 12:11:32 -0800163 MODE_IN_COMMUNICATION,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800164 NUM_MODES // not a valid entry, denotes end-of-list
165 };
166
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167 enum audio_in_acoustics {
168 AGC_ENABLE = 0x0001,
169 AGC_DISABLE = 0,
170 NS_ENABLE = 0x0002,
171 NS_DISABLE = 0,
172 TX_IIR_ENABLE = 0x0004,
173 TX_DISABLE = 0
174 };
175
Eric Laurentde070132010-07-13 04:45:46 -0700176 // special audio session values
177 enum audio_sessions {
178 SESSION_OUTPUT_STAGE = -1, // session for effects attached to a particular output stream
179 // (value must be less than 0)
180 SESSION_OUTPUT_MIX = 0, // session for effects applied to output mix. These effects can
181 // be moved by audio policy manager to another output stream
182 // (value must be 0)
183 };
184
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800185 /* These are static methods to control the system-wide AudioFlinger
186 * only privileged processes can have access to them
187 */
188
Eric Laurentc2f1f072009-07-17 12:17:14 -0700189 // mute/unmute microphone
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800190 static status_t muteMicrophone(bool state);
191 static status_t isMicrophoneMuted(bool *state);
192
Eric Laurentc2f1f072009-07-17 12:17:14 -0700193 // set/get master volume
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800194 static status_t setMasterVolume(float value);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800195 static status_t getMasterVolume(float* volume);
Glenn Kasten4bcae822011-04-04 10:50:50 -0700196
Eric Laurentc2f1f072009-07-17 12:17:14 -0700197 // mute/unmute audio outputs
198 static status_t setMasterMute(bool mute);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800199 static status_t getMasterMute(bool* mute);
200
Eric Laurentc2f1f072009-07-17 12:17:14 -0700201 // set/get stream volume on specified output
Eric Laurentfa2877b2009-07-28 08:44:33 -0700202 static status_t setStreamVolume(int stream, float value, int output);
203 static status_t getStreamVolume(int stream, float* volume, int output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700204
205 // mute/unmute stream
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800206 static status_t setStreamMute(int stream, bool mute);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800207 static status_t getStreamMute(int stream, bool* mute);
208
Eric Laurentc2f1f072009-07-17 12:17:14 -0700209 // set audio mode in audio hardware (see AudioSystem::audio_mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800210 static status_t setMode(int mode);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800211
Eric Laurenteda6c362011-02-02 09:33:30 -0800212 // returns true in *state if tracks are active on the specified stream or has been active
213 // in the past inPastMs milliseconds
214 static status_t isStreamActive(int stream, bool *state, uint32_t inPastMs = 0);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800215
Eric Laurentc2f1f072009-07-17 12:17:14 -0700216 // set/get audio hardware parameters. The function accepts a list of parameters
217 // key value pairs in the form: key1=value1;key2=value2;...
218 // Some keys are reserved for standard parameters (See AudioParameter class).
219 static status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs);
220 static String8 getParameters(audio_io_handle_t ioHandle, const String8& keys);
221
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800222 static void setErrorCallback(audio_error_callback cb);
223
224 // helper function to obtain AudioFlinger service handle
225 static const sp<IAudioFlinger>& get_audio_flinger();
226
227 static float linearToLog(int volume);
228 static int logToLinear(float volume);
229
230 static status_t getOutputSamplingRate(int* samplingRate, int stream = DEFAULT);
231 static status_t getOutputFrameCount(int* frameCount, int stream = DEFAULT);
232 static status_t getOutputLatency(uint32_t* latency, int stream = DEFAULT);
233
234 static bool routedToA2dpOutput(int streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700235
236 static status_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800237 size_t* buffSize);
238
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700239 static status_t setVoiceVolume(float volume);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700240
Eric Laurent342e9cf2010-01-19 17:37:09 -0800241 // return the number of audio frames written by AudioFlinger to audio HAL and
Glenn Kasten4bcae822011-04-04 10:50:50 -0700242 // audio dsp to DAC since the output on which the specified stream is playing
Eric Laurent342e9cf2010-01-19 17:37:09 -0800243 // has exited standby.
244 // returned status (from utils/Errors.h) can be:
245 // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data
246 // - INVALID_OPERATION: Not supported on current hardware platform
247 // - BAD_VALUE: invalid parameter
248 // NOTE: this feature is not supported on all hardware platforms and it is
249 // necessary to check returned status before using the returned values.
250 static status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int stream = DEFAULT);
251
Eric Laurent05bca2f2010-02-26 02:47:27 -0800252 static unsigned int getInputFramesLost(audio_io_handle_t ioHandle);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700253
254 static int newAudioSessionId();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700255 //
256 // AudioPolicyService interface
257 //
258
259 enum audio_devices {
260 // output devices
Eric Laurentffe9c252010-06-23 17:38:20 -0700261 DEVICE_OUT_EARPIECE = 0x1,
262 DEVICE_OUT_SPEAKER = 0x2,
263 DEVICE_OUT_WIRED_HEADSET = 0x4,
264 DEVICE_OUT_WIRED_HEADPHONE = 0x8,
265 DEVICE_OUT_BLUETOOTH_SCO = 0x10,
266 DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
267 DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
268 DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
269 DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
270 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
271 DEVICE_OUT_AUX_DIGITAL = 0x400,
Praveen Bharathib235dee2010-10-06 15:23:14 -0500272 DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
273 DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700274 DEVICE_OUT_DEFAULT = 0x8000,
275 DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
276 DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
277 DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
Praveen Bharathib235dee2010-10-06 15:23:14 -0500278 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL |
279 DEVICE_OUT_ANLG_DOCK_HEADSET | DEVICE_OUT_DGTL_DOCK_HEADSET |
280 DEVICE_OUT_DEFAULT),
Eric Laurent492e6662009-12-10 01:03:50 -0800281 DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
282 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
Eric Laurentc2f1f072009-07-17 12:17:14 -0700283
284 // input devices
285 DEVICE_IN_COMMUNICATION = 0x10000,
286 DEVICE_IN_AMBIENT = 0x20000,
287 DEVICE_IN_BUILTIN_MIC = 0x40000,
288 DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
289 DEVICE_IN_WIRED_HEADSET = 0x100000,
290 DEVICE_IN_AUX_DIGITAL = 0x200000,
291 DEVICE_IN_VOICE_CALL = 0x400000,
Eric Laurent90b75fb2009-11-02 05:31:33 -0800292 DEVICE_IN_BACK_MIC = 0x800000,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700293 DEVICE_IN_DEFAULT = 0x80000000,
294
295 DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC |
296 DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL |
Eric Laurent90b75fb2009-11-02 05:31:33 -0800297 DEVICE_IN_VOICE_CALL | DEVICE_IN_BACK_MIC | DEVICE_IN_DEFAULT)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700298 };
299
300 // device connection states used for setDeviceConnectionState()
301 enum device_connection_state {
302 DEVICE_STATE_UNAVAILABLE,
303 DEVICE_STATE_AVAILABLE,
304 NUM_DEVICE_STATES
305 };
306
307 // request to open a direct output with getOutput() (by opposition to sharing an output with other AudioTracks)
308 enum output_flags {
309 OUTPUT_FLAG_INDIRECT = 0x0,
310 OUTPUT_FLAG_DIRECT = 0x1
311 };
312
313 // device categories used for setForceUse()
314 enum forced_config {
315 FORCE_NONE,
316 FORCE_SPEAKER,
317 FORCE_HEADPHONES,
318 FORCE_BT_SCO,
319 FORCE_BT_A2DP,
320 FORCE_WIRED_ACCESSORY,
Eric Laurent7ddd4502009-12-17 03:12:59 -0800321 FORCE_BT_CAR_DOCK,
322 FORCE_BT_DESK_DOCK,
Praveen Bharathib235dee2010-10-06 15:23:14 -0500323 FORCE_ANALOG_DOCK,
324 FORCE_DIGITAL_DOCK,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700325 NUM_FORCE_CONFIG,
326 FORCE_DEFAULT = FORCE_NONE
327 };
328
Glenn Kasten4bcae822011-04-04 10:50:50 -0700329 // usages used for setForceUse(), must match AudioSystem.java
Eric Laurentc2f1f072009-07-17 12:17:14 -0700330 enum force_use {
331 FOR_COMMUNICATION,
332 FOR_MEDIA,
333 FOR_RECORD,
Jean-Michel Trivi48643f32009-12-07 18:40:56 -0800334 FOR_DOCK,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700335 NUM_FORCE_USE
336 };
337
338 // types of io configuration change events received with ioConfigChanged()
339 enum io_config_event {
340 OUTPUT_OPENED,
341 OUTPUT_CLOSED,
342 OUTPUT_CONFIG_CHANGED,
343 INPUT_OPENED,
344 INPUT_CLOSED,
345 INPUT_CONFIG_CHANGED,
346 STREAM_CONFIG_CHANGED,
347 NUM_CONFIG_EVENTS
348 };
349
350 // audio output descritor used to cache output configurations in client process to avoid frequent calls
351 // through IAudioFlinger
352 class OutputDescriptor {
353 public:
354 OutputDescriptor()
355 : samplingRate(0), format(0), channels(0), frameCount(0), latency(0) {}
356
357 uint32_t samplingRate;
358 int32_t format;
359 int32_t channels;
360 size_t frameCount;
361 uint32_t latency;
362 };
363
364 //
365 // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
366 //
367 static status_t setDeviceConnectionState(audio_devices device, device_connection_state state, const char *device_address);
368 static device_connection_state getDeviceConnectionState(audio_devices device, const char *device_address);
369 static status_t setPhoneState(int state);
370 static status_t setRingerMode(uint32_t mode, uint32_t mask);
371 static status_t setForceUse(force_use usage, forced_config config);
372 static forced_config getForceUse(force_use usage);
373 static audio_io_handle_t getOutput(stream_type stream,
374 uint32_t samplingRate = 0,
375 uint32_t format = FORMAT_DEFAULT,
376 uint32_t channels = CHANNEL_OUT_STEREO,
377 output_flags flags = OUTPUT_FLAG_INDIRECT);
Eric Laurentde070132010-07-13 04:45:46 -0700378 static status_t startOutput(audio_io_handle_t output,
379 AudioSystem::stream_type stream,
380 int session = 0);
381 static status_t stopOutput(audio_io_handle_t output,
382 AudioSystem::stream_type stream,
383 int session = 0);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700384 static void releaseOutput(audio_io_handle_t output);
385 static audio_io_handle_t getInput(int inputSource,
386 uint32_t samplingRate = 0,
387 uint32_t format = FORMAT_DEFAULT,
388 uint32_t channels = CHANNEL_IN_MONO,
389 audio_in_acoustics acoustics = (audio_in_acoustics)0);
390 static status_t startInput(audio_io_handle_t input);
391 static status_t stopInput(audio_io_handle_t input);
392 static void releaseInput(audio_io_handle_t input);
393 static status_t initStreamVolume(stream_type stream,
394 int indexMin,
395 int indexMax);
396 static status_t setStreamVolumeIndex(stream_type stream, int index);
397 static status_t getStreamVolumeIndex(stream_type stream, int *index);
398
Eric Laurentde070132010-07-13 04:45:46 -0700399 static uint32_t getStrategyForStream(stream_type stream);
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800400 static uint32_t getDevicesForStream(stream_type stream);
Eric Laurentde070132010-07-13 04:45:46 -0700401
402 static audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc);
403 static status_t registerEffect(effect_descriptor_t *desc,
404 audio_io_handle_t output,
405 uint32_t strategy,
406 int session,
407 int id);
408 static status_t unregisterEffect(int id);
409
Eric Laurentc2f1f072009-07-17 12:17:14 -0700410 static const sp<IAudioPolicyService>& get_audio_policy_service();
411
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800412 // ----------------------------------------------------------------------------
413
Eric Laurentc2f1f072009-07-17 12:17:14 -0700414 static uint32_t popCount(uint32_t u);
415 static bool isOutputDevice(audio_devices device);
416 static bool isInputDevice(audio_devices device);
417 static bool isA2dpDevice(audio_devices device);
418 static bool isBluetoothScoDevice(audio_devices device);
419 static bool isLowVisibility(stream_type stream);
420 static bool isOutputChannel(uint32_t channel);
421 static bool isInputChannel(uint32_t channel);
422 static bool isValidFormat(uint32_t format);
423 static bool isLinearPCM(uint32_t format);
424
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800425private:
426
427 class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient
428 {
429 public:
Eric Laurentc2f1f072009-07-17 12:17:14 -0700430 AudioFlingerClient() {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800431 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700432
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800433 // DeathRecipient
434 virtual void binderDied(const wp<IBinder>& who);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700435
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800436 // IAudioFlingerClient
Eric Laurentc2f1f072009-07-17 12:17:14 -0700437
438 // indicate a change in the configuration of an output or input: keeps the cached
439 // values for output/input parameters upto date in client process
Eric Laurentfa2877b2009-07-28 08:44:33 -0700440 virtual void ioConfigChanged(int event, int ioHandle, void *param2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800441 };
Eric Laurentc2f1f072009-07-17 12:17:14 -0700442
443 class AudioPolicyServiceClient: public IBinder::DeathRecipient
444 {
445 public:
446 AudioPolicyServiceClient() {
447 }
448
449 // DeathRecipient
450 virtual void binderDied(const wp<IBinder>& who);
451 };
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800452
453 static sp<AudioFlingerClient> gAudioFlingerClient;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700454 static sp<AudioPolicyServiceClient> gAudioPolicyServiceClient;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800455 friend class AudioFlingerClient;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700456 friend class AudioPolicyServiceClient;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800457
458 static Mutex gLock;
459 static sp<IAudioFlinger> gAudioFlinger;
460 static audio_error_callback gAudioErrorCallback;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700461
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800462 static size_t gInBuffSize;
463 // previous parameters for recording buffer size queries
464 static uint32_t gPrevInSamplingRate;
465 static int gPrevInFormat;
466 static int gPrevInChannelCount;
467
Eric Laurentc2f1f072009-07-17 12:17:14 -0700468 static sp<IAudioPolicyService> gAudioPolicyService;
469
470 // mapping between stream types and outputs
471 static DefaultKeyedVector<int, audio_io_handle_t> gStreamOutputMap;
472 // list of output descritor containing cached parameters (sampling rate, framecount, channel count...)
473 static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs;
474};
475
476class AudioParameter {
477
478public:
479 AudioParameter() {}
480 AudioParameter(const String8& keyValuePairs);
481 virtual ~AudioParameter();
482
Jean-Michel Trivi56ecd202010-11-09 14:06:52 -0800483 // reserved parameter keys for changing standard parameters with setParameters() function.
Eric Laurentc2f1f072009-07-17 12:17:14 -0700484 // Using these keys is mandatory for AudioFlinger to properly monitor audio output/input
485 // configuration changes and act accordingly.
486 // keyRouting: to change audio routing, value is an int in AudioSystem::audio_devices
487 // keySamplingRate: to change sampling rate routing, value is an int
488 // keyFormat: to change audio format, value is an int in AudioSystem::audio_format
489 // keyChannels: to change audio channel configuration, value is an int in AudioSystem::audio_channels
490 // keyFrameCount: to change audio output frame count, value is an int
Jean-Michel Trivi56ecd202010-11-09 14:06:52 -0800491 // keyInputSource: to change audio input source, value is an int in audio_source
492 // (defined in media/mediarecorder.h)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700493 static const char *keyRouting;
494 static const char *keySamplingRate;
495 static const char *keyFormat;
496 static const char *keyChannels;
497 static const char *keyFrameCount;
Jean-Michel Trivi56ecd202010-11-09 14:06:52 -0800498 static const char *keyInputSource;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700499
500 String8 toString();
501
502 status_t add(const String8& key, const String8& value);
503 status_t addInt(const String8& key, const int value);
504 status_t addFloat(const String8& key, const float value);
505
506 status_t remove(const String8& key);
507
508 status_t get(const String8& key, String8& value);
509 status_t getInt(const String8& key, int& value);
510 status_t getFloat(const String8& key, float& value);
Eric Laurenta9c322e2009-08-27 00:48:47 -0700511 status_t getAt(size_t index, String8& key, String8& value);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700512
513 size_t size() { return mParameters.size(); }
514
515private:
516 String8 mKeyValuePairs;
517 KeyedVector <String8, String8> mParameters;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800518};
519
520}; // namespace android
521
522#endif /*ANDROID_AUDIOSYSTEM_H_*/