blob: cce2400321f8cd704aba0079e25268fe19cc062a [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
36 enum stream_type {
Eric Laurentc2f1f072009-07-17 12:17:14 -070037 DEFAULT =-1,
38 VOICE_CALL = 0,
39 SYSTEM = 1,
40 RING = 2,
41 MUSIC = 3,
42 ALARM = 4,
43 NOTIFICATION = 5,
44 BLUETOOTH_SCO = 6,
Eric Laurent29a65002009-03-27 18:18:46 -070045 ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
Eric Laurentc2f1f072009-07-17 12:17:14 -070046 DTMF = 8,
47 TTS = 9,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080048 NUM_STREAM_TYPES
49 };
50
Eric Laurentc2f1f072009-07-17 12:17:14 -070051 // Audio sub formats (see AudioSystem::audio_format).
52 enum pcm_sub_format {
Eric Laurentffe9c252010-06-23 17:38:20 -070053 PCM_SUB_16_BIT = 0x1, // must be 1 for backward compatibility
54 PCM_SUB_8_BIT = 0x2, // must be 2 for backward compatibility
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080055 };
56
Eric Laurentc2f1f072009-07-17 12:17:14 -070057 // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify
58 // bit rate, stereo mode, version...
59 enum mp3_sub_format {
60 //TODO
61 };
62
63 // AMR NB/WB sub format field definition: specify frame block interleaving, bandwidth efficient or octet aligned,
64 // encoding mode for recording...
65 enum amr_sub_format {
66 //TODO
67 };
68
69 // AAC sub format field definition: specify profile or bitrate for recording...
70 enum aac_sub_format {
71 //TODO
72 };
73
74 // VORBIS sub format field definition: specify quality for recording...
75 enum vorbis_sub_format {
76 //TODO
77 };
78
79 // Audio format consists in a main format field (upper 8 bits) and a sub format field (lower 24 bits).
80 // The main format indicates the main codec type. The sub format field indicates options and parameters
81 // for each format. The sub format is mainly used for record to indicate for instance the requested bitrate
82 // or profile. It can also be used for certain formats to give informations not present in the encoded
83 // audio stream (e.g. octet alignement for AMR).
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080084 enum audio_format {
Eric Laurentc2f1f072009-07-17 12:17:14 -070085 INVALID_FORMAT = -1,
86 FORMAT_DEFAULT = 0,
87 PCM = 0x00000000, // must be 0 for backward compatibility
88 MP3 = 0x01000000,
89 AMR_NB = 0x02000000,
90 AMR_WB = 0x03000000,
91 AAC = 0x04000000,
92 HE_AAC_V1 = 0x05000000,
93 HE_AAC_V2 = 0x06000000,
94 VORBIS = 0x07000000,
95 MAIN_FORMAT_MASK = 0xFF000000,
96 SUB_FORMAT_MASK = 0x00FFFFFF,
97 // Aliases
98 PCM_16_BIT = (PCM|PCM_SUB_16_BIT),
99 PCM_8_BIT = (PCM|PCM_SUB_8_BIT)
100 };
101
102
103 // Channel mask definitions must be kept in sync with JAVA values in /media/java/android/media/AudioFormat.java
104 enum audio_channels {
105 // output channels
Eric Laurentffe9c252010-06-23 17:38:20 -0700106 CHANNEL_OUT_FRONT_LEFT = 0x4,
107 CHANNEL_OUT_FRONT_RIGHT = 0x8,
108 CHANNEL_OUT_FRONT_CENTER = 0x10,
109 CHANNEL_OUT_LOW_FREQUENCY = 0x20,
110 CHANNEL_OUT_BACK_LEFT = 0x40,
111 CHANNEL_OUT_BACK_RIGHT = 0x80,
112 CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
113 CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
114 CHANNEL_OUT_BACK_CENTER = 0x400,
115 CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT,
116 CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT),
117 CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
118 CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
119 CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
120 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER),
121 CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
122 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
123 CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
124 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
125 CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER),
Eric Laurentc2f1f072009-07-17 12:17:14 -0700126 CHANNEL_OUT_ALL = (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 | CHANNEL_OUT_BACK_CENTER),
129
130 // input channels
Eric Laurent9a920372009-07-27 07:12:26 -0700131 CHANNEL_IN_LEFT = 0x4,
132 CHANNEL_IN_RIGHT = 0x8,
133 CHANNEL_IN_FRONT = 0x10,
134 CHANNEL_IN_BACK = 0x20,
135 CHANNEL_IN_LEFT_PROCESSED = 0x40,
136 CHANNEL_IN_RIGHT_PROCESSED = 0x80,
137 CHANNEL_IN_FRONT_PROCESSED = 0x100,
138 CHANNEL_IN_BACK_PROCESSED = 0x200,
139 CHANNEL_IN_PRESSURE = 0x400,
140 CHANNEL_IN_X_AXIS = 0x800,
141 CHANNEL_IN_Y_AXIS = 0x1000,
142 CHANNEL_IN_Z_AXIS = 0x2000,
143 CHANNEL_IN_VOICE_UPLINK = 0x4000,
144 CHANNEL_IN_VOICE_DNLINK = 0x8000,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700145 CHANNEL_IN_MONO = CHANNEL_IN_FRONT,
146 CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT),
147 CHANNEL_IN_ALL = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_FRONT | CHANNEL_IN_BACK|
148 CHANNEL_IN_LEFT_PROCESSED | CHANNEL_IN_RIGHT_PROCESSED | CHANNEL_IN_FRONT_PROCESSED | CHANNEL_IN_BACK_PROCESSED|
149 CHANNEL_IN_PRESSURE | CHANNEL_IN_X_AXIS | CHANNEL_IN_Y_AXIS | CHANNEL_IN_Z_AXIS |
150 CHANNEL_IN_VOICE_UPLINK | CHANNEL_IN_VOICE_DNLINK)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800151 };
152
153 enum audio_mode {
154 MODE_INVALID = -2,
155 MODE_CURRENT = -1,
156 MODE_NORMAL = 0,
157 MODE_RINGTONE,
158 MODE_IN_CALL,
159 NUM_MODES // not a valid entry, denotes end-of-list
160 };
161
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800162 enum audio_in_acoustics {
163 AGC_ENABLE = 0x0001,
164 AGC_DISABLE = 0,
165 NS_ENABLE = 0x0002,
166 NS_DISABLE = 0,
167 TX_IIR_ENABLE = 0x0004,
168 TX_DISABLE = 0
169 };
170
Eric Laurentde070132010-07-13 04:45:46 -0700171 // special audio session values
172 enum audio_sessions {
173 SESSION_OUTPUT_STAGE = -1, // session for effects attached to a particular output stream
174 // (value must be less than 0)
175 SESSION_OUTPUT_MIX = 0, // session for effects applied to output mix. These effects can
176 // be moved by audio policy manager to another output stream
177 // (value must be 0)
178 };
179
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800180 /* These are static methods to control the system-wide AudioFlinger
181 * only privileged processes can have access to them
182 */
183
Eric Laurentc2f1f072009-07-17 12:17:14 -0700184 // mute/unmute microphone
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800185 static status_t muteMicrophone(bool state);
186 static status_t isMicrophoneMuted(bool *state);
187
Eric Laurentc2f1f072009-07-17 12:17:14 -0700188 // set/get master volume
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800189 static status_t setMasterVolume(float value);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800190 static status_t getMasterVolume(float* volume);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700191 // mute/unmute audio outputs
192 static status_t setMasterMute(bool mute);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800193 static status_t getMasterMute(bool* mute);
194
Eric Laurentc2f1f072009-07-17 12:17:14 -0700195 // set/get stream volume on specified output
Eric Laurentfa2877b2009-07-28 08:44:33 -0700196 static status_t setStreamVolume(int stream, float value, int output);
197 static status_t getStreamVolume(int stream, float* volume, int output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700198
199 // mute/unmute stream
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800200 static status_t setStreamMute(int stream, bool mute);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800201 static status_t getStreamMute(int stream, bool* mute);
202
Eric Laurentc2f1f072009-07-17 12:17:14 -0700203 // set audio mode in audio hardware (see AudioSystem::audio_mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800204 static status_t setMode(int mode);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800205
Eric Laurentb72a3962010-01-25 08:49:09 -0800206 // returns true in *state if tracks are active on the specified stream
207 static status_t isStreamActive(int stream, bool *state);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800208
Eric Laurentc2f1f072009-07-17 12:17:14 -0700209 // set/get audio hardware parameters. The function accepts a list of parameters
210 // key value pairs in the form: key1=value1;key2=value2;...
211 // Some keys are reserved for standard parameters (See AudioParameter class).
212 static status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs);
213 static String8 getParameters(audio_io_handle_t ioHandle, const String8& keys);
214
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800215 static void setErrorCallback(audio_error_callback cb);
216
217 // helper function to obtain AudioFlinger service handle
218 static const sp<IAudioFlinger>& get_audio_flinger();
219
220 static float linearToLog(int volume);
221 static int logToLinear(float volume);
222
223 static status_t getOutputSamplingRate(int* samplingRate, int stream = DEFAULT);
224 static status_t getOutputFrameCount(int* frameCount, int stream = DEFAULT);
225 static status_t getOutputLatency(uint32_t* latency, int stream = DEFAULT);
226
227 static bool routedToA2dpOutput(int streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700228
229 static status_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800230 size_t* buffSize);
231
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700232 static status_t setVoiceVolume(float volume);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700233
Eric Laurent342e9cf2010-01-19 17:37:09 -0800234 // return the number of audio frames written by AudioFlinger to audio HAL and
235 // audio dsp to DAC since the output on which the specificed stream is playing
236 // has exited standby.
237 // returned status (from utils/Errors.h) can be:
238 // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data
239 // - INVALID_OPERATION: Not supported on current hardware platform
240 // - BAD_VALUE: invalid parameter
241 // NOTE: this feature is not supported on all hardware platforms and it is
242 // necessary to check returned status before using the returned values.
243 static status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int stream = DEFAULT);
244
Eric Laurent05bca2f2010-02-26 02:47:27 -0800245 static unsigned int getInputFramesLost(audio_io_handle_t ioHandle);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700246
247 static int newAudioSessionId();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700248 //
249 // AudioPolicyService interface
250 //
251
252 enum audio_devices {
253 // output devices
Eric Laurentffe9c252010-06-23 17:38:20 -0700254 DEVICE_OUT_EARPIECE = 0x1,
255 DEVICE_OUT_SPEAKER = 0x2,
256 DEVICE_OUT_WIRED_HEADSET = 0x4,
257 DEVICE_OUT_WIRED_HEADPHONE = 0x8,
258 DEVICE_OUT_BLUETOOTH_SCO = 0x10,
259 DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
260 DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
261 DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
262 DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
263 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
264 DEVICE_OUT_AUX_DIGITAL = 0x400,
Praveen Bharathib235dee2010-10-06 15:23:14 -0500265 DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
266 DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700267 DEVICE_OUT_DEFAULT = 0x8000,
268 DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
269 DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
270 DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
Praveen Bharathib235dee2010-10-06 15:23:14 -0500271 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL |
272 DEVICE_OUT_ANLG_DOCK_HEADSET | DEVICE_OUT_DGTL_DOCK_HEADSET |
273 DEVICE_OUT_DEFAULT),
Eric Laurent492e6662009-12-10 01:03:50 -0800274 DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
275 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
Eric Laurentc2f1f072009-07-17 12:17:14 -0700276
277 // input devices
278 DEVICE_IN_COMMUNICATION = 0x10000,
279 DEVICE_IN_AMBIENT = 0x20000,
280 DEVICE_IN_BUILTIN_MIC = 0x40000,
281 DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
282 DEVICE_IN_WIRED_HEADSET = 0x100000,
283 DEVICE_IN_AUX_DIGITAL = 0x200000,
284 DEVICE_IN_VOICE_CALL = 0x400000,
Eric Laurent90b75fb2009-11-02 05:31:33 -0800285 DEVICE_IN_BACK_MIC = 0x800000,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700286 DEVICE_IN_DEFAULT = 0x80000000,
287
288 DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC |
289 DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL |
Eric Laurent90b75fb2009-11-02 05:31:33 -0800290 DEVICE_IN_VOICE_CALL | DEVICE_IN_BACK_MIC | DEVICE_IN_DEFAULT)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700291 };
292
293 // device connection states used for setDeviceConnectionState()
294 enum device_connection_state {
295 DEVICE_STATE_UNAVAILABLE,
296 DEVICE_STATE_AVAILABLE,
297 NUM_DEVICE_STATES
298 };
299
300 // request to open a direct output with getOutput() (by opposition to sharing an output with other AudioTracks)
301 enum output_flags {
302 OUTPUT_FLAG_INDIRECT = 0x0,
303 OUTPUT_FLAG_DIRECT = 0x1
304 };
305
306 // device categories used for setForceUse()
307 enum forced_config {
308 FORCE_NONE,
309 FORCE_SPEAKER,
310 FORCE_HEADPHONES,
311 FORCE_BT_SCO,
312 FORCE_BT_A2DP,
313 FORCE_WIRED_ACCESSORY,
Eric Laurent7ddd4502009-12-17 03:12:59 -0800314 FORCE_BT_CAR_DOCK,
315 FORCE_BT_DESK_DOCK,
Praveen Bharathib235dee2010-10-06 15:23:14 -0500316 FORCE_ANALOG_DOCK,
317 FORCE_DIGITAL_DOCK,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700318 NUM_FORCE_CONFIG,
319 FORCE_DEFAULT = FORCE_NONE
320 };
321
322 // usages used for setForceUse()
323 enum force_use {
324 FOR_COMMUNICATION,
325 FOR_MEDIA,
326 FOR_RECORD,
Jean-Michel Trivi48643f32009-12-07 18:40:56 -0800327 FOR_DOCK,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700328 NUM_FORCE_USE
329 };
330
331 // types of io configuration change events received with ioConfigChanged()
332 enum io_config_event {
333 OUTPUT_OPENED,
334 OUTPUT_CLOSED,
335 OUTPUT_CONFIG_CHANGED,
336 INPUT_OPENED,
337 INPUT_CLOSED,
338 INPUT_CONFIG_CHANGED,
339 STREAM_CONFIG_CHANGED,
340 NUM_CONFIG_EVENTS
341 };
342
343 // audio output descritor used to cache output configurations in client process to avoid frequent calls
344 // through IAudioFlinger
345 class OutputDescriptor {
346 public:
347 OutputDescriptor()
348 : samplingRate(0), format(0), channels(0), frameCount(0), latency(0) {}
349
350 uint32_t samplingRate;
351 int32_t format;
352 int32_t channels;
353 size_t frameCount;
354 uint32_t latency;
355 };
356
357 //
358 // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
359 //
360 static status_t setDeviceConnectionState(audio_devices device, device_connection_state state, const char *device_address);
361 static device_connection_state getDeviceConnectionState(audio_devices device, const char *device_address);
362 static status_t setPhoneState(int state);
363 static status_t setRingerMode(uint32_t mode, uint32_t mask);
364 static status_t setForceUse(force_use usage, forced_config config);
365 static forced_config getForceUse(force_use usage);
366 static audio_io_handle_t getOutput(stream_type stream,
367 uint32_t samplingRate = 0,
368 uint32_t format = FORMAT_DEFAULT,
369 uint32_t channels = CHANNEL_OUT_STEREO,
370 output_flags flags = OUTPUT_FLAG_INDIRECT);
Eric Laurentde070132010-07-13 04:45:46 -0700371 static status_t startOutput(audio_io_handle_t output,
372 AudioSystem::stream_type stream,
373 int session = 0);
374 static status_t stopOutput(audio_io_handle_t output,
375 AudioSystem::stream_type stream,
376 int session = 0);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700377 static void releaseOutput(audio_io_handle_t output);
378 static audio_io_handle_t getInput(int inputSource,
379 uint32_t samplingRate = 0,
380 uint32_t format = FORMAT_DEFAULT,
381 uint32_t channels = CHANNEL_IN_MONO,
382 audio_in_acoustics acoustics = (audio_in_acoustics)0);
383 static status_t startInput(audio_io_handle_t input);
384 static status_t stopInput(audio_io_handle_t input);
385 static void releaseInput(audio_io_handle_t input);
386 static status_t initStreamVolume(stream_type stream,
387 int indexMin,
388 int indexMax);
389 static status_t setStreamVolumeIndex(stream_type stream, int index);
390 static status_t getStreamVolumeIndex(stream_type stream, int *index);
391
Eric Laurentde070132010-07-13 04:45:46 -0700392 static uint32_t getStrategyForStream(stream_type stream);
393
394 static audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc);
395 static status_t registerEffect(effect_descriptor_t *desc,
396 audio_io_handle_t output,
397 uint32_t strategy,
398 int session,
399 int id);
400 static status_t unregisterEffect(int id);
401
Eric Laurentc2f1f072009-07-17 12:17:14 -0700402 static const sp<IAudioPolicyService>& get_audio_policy_service();
403
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800404 // ----------------------------------------------------------------------------
405
Eric Laurentc2f1f072009-07-17 12:17:14 -0700406 static uint32_t popCount(uint32_t u);
407 static bool isOutputDevice(audio_devices device);
408 static bool isInputDevice(audio_devices device);
409 static bool isA2dpDevice(audio_devices device);
410 static bool isBluetoothScoDevice(audio_devices device);
411 static bool isLowVisibility(stream_type stream);
412 static bool isOutputChannel(uint32_t channel);
413 static bool isInputChannel(uint32_t channel);
414 static bool isValidFormat(uint32_t format);
415 static bool isLinearPCM(uint32_t format);
416
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800417private:
418
419 class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient
420 {
421 public:
Eric Laurentc2f1f072009-07-17 12:17:14 -0700422 AudioFlingerClient() {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800423 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700424
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800425 // DeathRecipient
426 virtual void binderDied(const wp<IBinder>& who);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700427
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800428 // IAudioFlingerClient
Eric Laurentc2f1f072009-07-17 12:17:14 -0700429
430 // indicate a change in the configuration of an output or input: keeps the cached
431 // values for output/input parameters upto date in client process
Eric Laurentfa2877b2009-07-28 08:44:33 -0700432 virtual void ioConfigChanged(int event, int ioHandle, void *param2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800433 };
Eric Laurentc2f1f072009-07-17 12:17:14 -0700434
435 class AudioPolicyServiceClient: public IBinder::DeathRecipient
436 {
437 public:
438 AudioPolicyServiceClient() {
439 }
440
441 // DeathRecipient
442 virtual void binderDied(const wp<IBinder>& who);
443 };
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800444
445 static sp<AudioFlingerClient> gAudioFlingerClient;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700446 static sp<AudioPolicyServiceClient> gAudioPolicyServiceClient;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800447 friend class AudioFlingerClient;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700448 friend class AudioPolicyServiceClient;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800449
450 static Mutex gLock;
451 static sp<IAudioFlinger> gAudioFlinger;
452 static audio_error_callback gAudioErrorCallback;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700453
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800454 static size_t gInBuffSize;
455 // previous parameters for recording buffer size queries
456 static uint32_t gPrevInSamplingRate;
457 static int gPrevInFormat;
458 static int gPrevInChannelCount;
459
Eric Laurentc2f1f072009-07-17 12:17:14 -0700460 static sp<IAudioPolicyService> gAudioPolicyService;
461
462 // mapping between stream types and outputs
463 static DefaultKeyedVector<int, audio_io_handle_t> gStreamOutputMap;
464 // list of output descritor containing cached parameters (sampling rate, framecount, channel count...)
465 static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs;
466};
467
468class AudioParameter {
469
470public:
471 AudioParameter() {}
472 AudioParameter(const String8& keyValuePairs);
473 virtual ~AudioParameter();
474
Jean-Michel Trivi56ecd202010-11-09 14:06:52 -0800475 // reserved parameter keys for changing standard parameters with setParameters() function.
Eric Laurentc2f1f072009-07-17 12:17:14 -0700476 // Using these keys is mandatory for AudioFlinger to properly monitor audio output/input
477 // configuration changes and act accordingly.
478 // keyRouting: to change audio routing, value is an int in AudioSystem::audio_devices
479 // keySamplingRate: to change sampling rate routing, value is an int
480 // keyFormat: to change audio format, value is an int in AudioSystem::audio_format
481 // keyChannels: to change audio channel configuration, value is an int in AudioSystem::audio_channels
482 // keyFrameCount: to change audio output frame count, value is an int
Jean-Michel Trivi56ecd202010-11-09 14:06:52 -0800483 // keyInputSource: to change audio input source, value is an int in audio_source
484 // (defined in media/mediarecorder.h)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700485 static const char *keyRouting;
486 static const char *keySamplingRate;
487 static const char *keyFormat;
488 static const char *keyChannels;
489 static const char *keyFrameCount;
Jean-Michel Trivi56ecd202010-11-09 14:06:52 -0800490 static const char *keyInputSource;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700491
492 String8 toString();
493
494 status_t add(const String8& key, const String8& value);
495 status_t addInt(const String8& key, const int value);
496 status_t addFloat(const String8& key, const float value);
497
498 status_t remove(const String8& key);
499
500 status_t get(const String8& key, String8& value);
501 status_t getInt(const String8& key, int& value);
502 status_t getFloat(const String8& key, float& value);
Eric Laurenta9c322e2009-08-27 00:48:47 -0700503 status_t getAt(size_t index, String8& key, String8& value);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700504
505 size_t size() { return mParameters.size(); }
506
507private:
508 String8 mKeyValuePairs;
509 KeyedVector <String8, String8> mParameters;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800510};
511
512}; // namespace android
513
514#endif /*ANDROID_AUDIOSYSTEM_H_*/