blob: 42bb4df4177aa8a78f027ac73fecd44a4de1d766 [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Laurentddb78e72009-07-28 08:44:33 -070027typedef int audio_io_handle_t;
Eric Laurenta553c252009-07-17 12:17:14 -070028
29class IAudioPolicyService;
30class String8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
32class AudioSystem
33{
34public:
35
36 enum stream_type {
Eric Laurenta553c252009-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 Laurent63e45f22009-03-27 18:18:46 -070045 ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
Eric Laurenta553c252009-07-17 12:17:14 -070046 DTMF = 8,
47 TTS = 9,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 NUM_STREAM_TYPES
49 };
50
Eric Laurenta553c252009-07-17 12:17:14 -070051 // Audio sub formats (see AudioSystem::audio_format).
52 enum pcm_sub_format {
53 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 Project9066cfe2009-03-03 19:31:44 -080055 };
56
Eric Laurenta553c252009-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 Project9066cfe2009-03-03 19:31:44 -080084 enum audio_format {
Eric Laurenta553c252009-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 Laurent3026a022009-07-27 07:12:26 -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,
Eric Laurenta553c252009-07-17 12:17:14 -0700115 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),
126 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 Laurent3026a022009-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 Laurenta553c252009-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 Project9066cfe2009-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 Project9066cfe2009-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
171 /* These are static methods to control the system-wide AudioFlinger
172 * only privileged processes can have access to them
173 */
174
Eric Laurenta553c252009-07-17 12:17:14 -0700175 // mute/unmute microphone
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 static status_t muteMicrophone(bool state);
177 static status_t isMicrophoneMuted(bool *state);
178
Eric Laurenta553c252009-07-17 12:17:14 -0700179 // set/get master volume
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 static status_t setMasterVolume(float value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 static status_t getMasterVolume(float* volume);
Eric Laurenta553c252009-07-17 12:17:14 -0700182 // mute/unmute audio outputs
183 static status_t setMasterMute(bool mute);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 static status_t getMasterMute(bool* mute);
185
Eric Laurenta553c252009-07-17 12:17:14 -0700186 // set/get stream volume on specified output
Eric Laurentddb78e72009-07-28 08:44:33 -0700187 static status_t setStreamVolume(int stream, float value, int output);
188 static status_t getStreamVolume(int stream, float* volume, int output);
Eric Laurenta553c252009-07-17 12:17:14 -0700189
190 // mute/unmute stream
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 static status_t setStreamMute(int stream, bool mute);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 static status_t getStreamMute(int stream, bool* mute);
193
Eric Laurenta553c252009-07-17 12:17:14 -0700194 // set audio mode in audio hardware (see AudioSystem::audio_mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 static status_t setMode(int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196
Eric Laurent23f25cd2010-01-25 08:49:09 -0800197 // returns true in *state if tracks are active on the specified stream
198 static status_t isStreamActive(int stream, bool *state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199
Eric Laurenta553c252009-07-17 12:17:14 -0700200 // set/get audio hardware parameters. The function accepts a list of parameters
201 // key value pairs in the form: key1=value1;key2=value2;...
202 // Some keys are reserved for standard parameters (See AudioParameter class).
203 static status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs);
204 static String8 getParameters(audio_io_handle_t ioHandle, const String8& keys);
205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 static void setErrorCallback(audio_error_callback cb);
207
208 // helper function to obtain AudioFlinger service handle
209 static const sp<IAudioFlinger>& get_audio_flinger();
210
211 static float linearToLog(int volume);
212 static int logToLinear(float volume);
213
214 static status_t getOutputSamplingRate(int* samplingRate, int stream = DEFAULT);
215 static status_t getOutputFrameCount(int* frameCount, int stream = DEFAULT);
216 static status_t getOutputLatency(uint32_t* latency, int stream = DEFAULT);
217
218 static bool routedToA2dpOutput(int streamType);
Eric Laurenta553c252009-07-17 12:17:14 -0700219
220 static status_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 size_t* buffSize);
222
Eric Laurent415f3e22009-10-21 08:14:22 -0700223 static status_t setVoiceVolume(float volume);
Eric Laurenta553c252009-07-17 12:17:14 -0700224
Eric Laurent0986e792010-01-19 17:37:09 -0800225 // return the number of audio frames written by AudioFlinger to audio HAL and
226 // audio dsp to DAC since the output on which the specificed stream is playing
227 // has exited standby.
228 // returned status (from utils/Errors.h) can be:
229 // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data
230 // - INVALID_OPERATION: Not supported on current hardware platform
231 // - BAD_VALUE: invalid parameter
232 // NOTE: this feature is not supported on all hardware platforms and it is
233 // necessary to check returned status before using the returned values.
234 static status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int stream = DEFAULT);
235
Eric Laurenta553c252009-07-17 12:17:14 -0700236 //
237 // AudioPolicyService interface
238 //
239
240 enum audio_devices {
241 // output devices
242 DEVICE_OUT_EARPIECE = 0x1,
243 DEVICE_OUT_SPEAKER = 0x2,
244 DEVICE_OUT_WIRED_HEADSET = 0x4,
245 DEVICE_OUT_WIRED_HEADPHONE = 0x8,
246 DEVICE_OUT_BLUETOOTH_SCO = 0x10,
247 DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
248 DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
249 DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
250 DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
251 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
252 DEVICE_OUT_AUX_DIGITAL = 0x400,
Eric Laurenta553c252009-07-17 12:17:14 -0700253 DEVICE_OUT_DEFAULT = 0x8000,
254 DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
255 DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
256 DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
Eric Laurent923d7d72009-11-12 12:09:06 -0800257 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL | DEVICE_OUT_DEFAULT),
Eric Laurentcef3cd72009-12-10 01:03:50 -0800258 DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
259 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
Eric Laurenta553c252009-07-17 12:17:14 -0700260
261 // input devices
262 DEVICE_IN_COMMUNICATION = 0x10000,
263 DEVICE_IN_AMBIENT = 0x20000,
264 DEVICE_IN_BUILTIN_MIC = 0x40000,
265 DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
266 DEVICE_IN_WIRED_HEADSET = 0x100000,
267 DEVICE_IN_AUX_DIGITAL = 0x200000,
268 DEVICE_IN_VOICE_CALL = 0x400000,
Eric Laurentf22a0972009-11-02 05:31:33 -0800269 DEVICE_IN_BACK_MIC = 0x800000,
Eric Laurenta553c252009-07-17 12:17:14 -0700270 DEVICE_IN_DEFAULT = 0x80000000,
271
272 DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC |
273 DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL |
Eric Laurentf22a0972009-11-02 05:31:33 -0800274 DEVICE_IN_VOICE_CALL | DEVICE_IN_BACK_MIC | DEVICE_IN_DEFAULT)
Eric Laurenta553c252009-07-17 12:17:14 -0700275 };
276
277 // device connection states used for setDeviceConnectionState()
278 enum device_connection_state {
279 DEVICE_STATE_UNAVAILABLE,
280 DEVICE_STATE_AVAILABLE,
281 NUM_DEVICE_STATES
282 };
283
284 // request to open a direct output with getOutput() (by opposition to sharing an output with other AudioTracks)
285 enum output_flags {
286 OUTPUT_FLAG_INDIRECT = 0x0,
287 OUTPUT_FLAG_DIRECT = 0x1
288 };
289
290 // device categories used for setForceUse()
291 enum forced_config {
292 FORCE_NONE,
293 FORCE_SPEAKER,
294 FORCE_HEADPHONES,
295 FORCE_BT_SCO,
296 FORCE_BT_A2DP,
297 FORCE_WIRED_ACCESSORY,
Eric Laurenteb14a782009-12-17 03:12:59 -0800298 FORCE_BT_CAR_DOCK,
299 FORCE_BT_DESK_DOCK,
Eric Laurenta553c252009-07-17 12:17:14 -0700300 NUM_FORCE_CONFIG,
301 FORCE_DEFAULT = FORCE_NONE
302 };
303
304 // usages used for setForceUse()
305 enum force_use {
306 FOR_COMMUNICATION,
307 FOR_MEDIA,
308 FOR_RECORD,
Jean-Michel Trivi61544122009-12-07 18:40:56 -0800309 FOR_DOCK,
Eric Laurenta553c252009-07-17 12:17:14 -0700310 NUM_FORCE_USE
311 };
312
313 // types of io configuration change events received with ioConfigChanged()
314 enum io_config_event {
315 OUTPUT_OPENED,
316 OUTPUT_CLOSED,
317 OUTPUT_CONFIG_CHANGED,
318 INPUT_OPENED,
319 INPUT_CLOSED,
320 INPUT_CONFIG_CHANGED,
321 STREAM_CONFIG_CHANGED,
322 NUM_CONFIG_EVENTS
323 };
324
325 // audio output descritor used to cache output configurations in client process to avoid frequent calls
326 // through IAudioFlinger
327 class OutputDescriptor {
328 public:
329 OutputDescriptor()
330 : samplingRate(0), format(0), channels(0), frameCount(0), latency(0) {}
331
332 uint32_t samplingRate;
333 int32_t format;
334 int32_t channels;
335 size_t frameCount;
336 uint32_t latency;
337 };
338
339 //
340 // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
341 //
342 static status_t setDeviceConnectionState(audio_devices device, device_connection_state state, const char *device_address);
343 static device_connection_state getDeviceConnectionState(audio_devices device, const char *device_address);
344 static status_t setPhoneState(int state);
345 static status_t setRingerMode(uint32_t mode, uint32_t mask);
346 static status_t setForceUse(force_use usage, forced_config config);
347 static forced_config getForceUse(force_use usage);
348 static audio_io_handle_t getOutput(stream_type stream,
349 uint32_t samplingRate = 0,
350 uint32_t format = FORMAT_DEFAULT,
351 uint32_t channels = CHANNEL_OUT_STEREO,
352 output_flags flags = OUTPUT_FLAG_INDIRECT);
353 static status_t startOutput(audio_io_handle_t output, AudioSystem::stream_type stream);
354 static status_t stopOutput(audio_io_handle_t output, AudioSystem::stream_type stream);
355 static void releaseOutput(audio_io_handle_t output);
356 static audio_io_handle_t getInput(int inputSource,
357 uint32_t samplingRate = 0,
358 uint32_t format = FORMAT_DEFAULT,
359 uint32_t channels = CHANNEL_IN_MONO,
360 audio_in_acoustics acoustics = (audio_in_acoustics)0);
361 static status_t startInput(audio_io_handle_t input);
362 static status_t stopInput(audio_io_handle_t input);
363 static void releaseInput(audio_io_handle_t input);
364 static status_t initStreamVolume(stream_type stream,
365 int indexMin,
366 int indexMax);
367 static status_t setStreamVolumeIndex(stream_type stream, int index);
368 static status_t getStreamVolumeIndex(stream_type stream, int *index);
369
370 static const sp<IAudioPolicyService>& get_audio_policy_service();
371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 // ----------------------------------------------------------------------------
373
Eric Laurenta553c252009-07-17 12:17:14 -0700374 static uint32_t popCount(uint32_t u);
375 static bool isOutputDevice(audio_devices device);
376 static bool isInputDevice(audio_devices device);
377 static bool isA2dpDevice(audio_devices device);
378 static bool isBluetoothScoDevice(audio_devices device);
379 static bool isLowVisibility(stream_type stream);
380 static bool isOutputChannel(uint32_t channel);
381 static bool isInputChannel(uint32_t channel);
382 static bool isValidFormat(uint32_t format);
383 static bool isLinearPCM(uint32_t format);
384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385private:
386
387 class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient
388 {
389 public:
Eric Laurenta553c252009-07-17 12:17:14 -0700390 AudioFlingerClient() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 }
Eric Laurenta553c252009-07-17 12:17:14 -0700392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 // DeathRecipient
394 virtual void binderDied(const wp<IBinder>& who);
Eric Laurenta553c252009-07-17 12:17:14 -0700395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 // IAudioFlingerClient
Eric Laurenta553c252009-07-17 12:17:14 -0700397
398 // indicate a change in the configuration of an output or input: keeps the cached
399 // values for output/input parameters upto date in client process
Eric Laurentddb78e72009-07-28 08:44:33 -0700400 virtual void ioConfigChanged(int event, int ioHandle, void *param2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 };
Eric Laurenta553c252009-07-17 12:17:14 -0700402
403 class AudioPolicyServiceClient: public IBinder::DeathRecipient
404 {
405 public:
406 AudioPolicyServiceClient() {
407 }
408
409 // DeathRecipient
410 virtual void binderDied(const wp<IBinder>& who);
411 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412
413 static sp<AudioFlingerClient> gAudioFlingerClient;
Eric Laurenta553c252009-07-17 12:17:14 -0700414 static sp<AudioPolicyServiceClient> gAudioPolicyServiceClient;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 friend class AudioFlingerClient;
Eric Laurenta553c252009-07-17 12:17:14 -0700416 friend class AudioPolicyServiceClient;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417
418 static Mutex gLock;
419 static sp<IAudioFlinger> gAudioFlinger;
420 static audio_error_callback gAudioErrorCallback;
Eric Laurenta553c252009-07-17 12:17:14 -0700421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 static size_t gInBuffSize;
423 // previous parameters for recording buffer size queries
424 static uint32_t gPrevInSamplingRate;
425 static int gPrevInFormat;
426 static int gPrevInChannelCount;
427
Eric Laurenta553c252009-07-17 12:17:14 -0700428 static sp<IAudioPolicyService> gAudioPolicyService;
429
430 // mapping between stream types and outputs
431 static DefaultKeyedVector<int, audio_io_handle_t> gStreamOutputMap;
432 // list of output descritor containing cached parameters (sampling rate, framecount, channel count...)
433 static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs;
434};
435
436class AudioParameter {
437
438public:
439 AudioParameter() {}
440 AudioParameter(const String8& keyValuePairs);
441 virtual ~AudioParameter();
442
443 // reserved parameter keys for changeing standard parameters with setParameters() function.
444 // Using these keys is mandatory for AudioFlinger to properly monitor audio output/input
445 // configuration changes and act accordingly.
446 // keyRouting: to change audio routing, value is an int in AudioSystem::audio_devices
447 // keySamplingRate: to change sampling rate routing, value is an int
448 // keyFormat: to change audio format, value is an int in AudioSystem::audio_format
449 // keyChannels: to change audio channel configuration, value is an int in AudioSystem::audio_channels
450 // keyFrameCount: to change audio output frame count, value is an int
451 static const char *keyRouting;
452 static const char *keySamplingRate;
453 static const char *keyFormat;
454 static const char *keyChannels;
455 static const char *keyFrameCount;
456
457 String8 toString();
458
459 status_t add(const String8& key, const String8& value);
460 status_t addInt(const String8& key, const int value);
461 status_t addFloat(const String8& key, const float value);
462
463 status_t remove(const String8& key);
464
465 status_t get(const String8& key, String8& value);
466 status_t getInt(const String8& key, int& value);
467 status_t getFloat(const String8& key, float& value);
Eric Laurent327c27b2009-08-27 00:48:47 -0700468 status_t getAt(size_t index, String8& key, String8& value);
Eric Laurenta553c252009-07-17 12:17:14 -0700469
470 size_t size() { return mParameters.size(); }
471
472private:
473 String8 mKeyValuePairs;
474 KeyedVector <String8, String8> mParameters;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475};
476
477}; // namespace android
478
479#endif /*ANDROID_AUDIOSYSTEM_H_*/