blob: b0c82d8fc5faf1bb31c8e5cbc6b7bbe0c44fbdeb [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
Dima Zavindb5cb142011-04-19 22:20:55 -070024/* XXX: Should be include by all the users instead */
25#include <media/AudioParameter.h>
26
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080027namespace android {
28
29typedef void (*audio_error_callback)(status_t err);
Eric Laurentfa2877b2009-07-28 08:44:33 -070030typedef int audio_io_handle_t;
Eric Laurentc2f1f072009-07-17 12:17:14 -070031
32class IAudioPolicyService;
33class String8;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080034
35class AudioSystem
36{
37public:
38
Glenn Kasten4bcae822011-04-04 10:50:50 -070039 // must match android/media/AudioSystem.java STREAM_* constants
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080040 enum stream_type {
Eric Laurentc2f1f072009-07-17 12:17:14 -070041 DEFAULT =-1,
42 VOICE_CALL = 0,
43 SYSTEM = 1,
44 RING = 2,
45 MUSIC = 3,
46 ALARM = 4,
47 NOTIFICATION = 5,
48 BLUETOOTH_SCO = 6,
Eric Laurent29a65002009-03-27 18:18:46 -070049 ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
Eric Laurentc2f1f072009-07-17 12:17:14 -070050 DTMF = 8,
51 TTS = 9,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080052 NUM_STREAM_TYPES
53 };
54
Eric Laurentc2f1f072009-07-17 12:17:14 -070055 // Audio sub formats (see AudioSystem::audio_format).
56 enum pcm_sub_format {
Eric Laurentffe9c252010-06-23 17:38:20 -070057 PCM_SUB_16_BIT = 0x1, // must be 1 for backward compatibility
58 PCM_SUB_8_BIT = 0x2, // must be 2 for backward compatibility
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080059 };
60
Glenn Kasten4bcae822011-04-04 10:50:50 -070061 // FIXME These sub_format enums are currently unused
62
Eric Laurentc2f1f072009-07-17 12:17:14 -070063 // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify
64 // bit rate, stereo mode, version...
65 enum mp3_sub_format {
66 //TODO
67 };
68
69 // AMR NB/WB sub format field definition: specify frame block interleaving, bandwidth efficient or octet aligned,
70 // encoding mode for recording...
71 enum amr_sub_format {
72 //TODO
73 };
74
75 // AAC sub format field definition: specify profile or bitrate for recording...
76 enum aac_sub_format {
77 //TODO
78 };
79
80 // VORBIS sub format field definition: specify quality for recording...
81 enum vorbis_sub_format {
82 //TODO
83 };
84
85 // Audio format consists in a main format field (upper 8 bits) and a sub format field (lower 24 bits).
86 // The main format indicates the main codec type. The sub format field indicates options and parameters
87 // for each format. The sub format is mainly used for record to indicate for instance the requested bitrate
88 // or profile. It can also be used for certain formats to give informations not present in the encoded
89 // audio stream (e.g. octet alignement for AMR).
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080090 enum audio_format {
Eric Laurentc2f1f072009-07-17 12:17:14 -070091 INVALID_FORMAT = -1,
92 FORMAT_DEFAULT = 0,
93 PCM = 0x00000000, // must be 0 for backward compatibility
94 MP3 = 0x01000000,
95 AMR_NB = 0x02000000,
96 AMR_WB = 0x03000000,
97 AAC = 0x04000000,
98 HE_AAC_V1 = 0x05000000,
99 HE_AAC_V2 = 0x06000000,
100 VORBIS = 0x07000000,
101 MAIN_FORMAT_MASK = 0xFF000000,
102 SUB_FORMAT_MASK = 0x00FFFFFF,
103 // Aliases
104 PCM_16_BIT = (PCM|PCM_SUB_16_BIT),
105 PCM_8_BIT = (PCM|PCM_SUB_8_BIT)
106 };
107
108
Glenn Kasten4bcae822011-04-04 10:50:50 -0700109 // Channel mask definitions must be kept in sync with values in /media/java/android/media/AudioFormat.java
Eric Laurentc2f1f072009-07-17 12:17:14 -0700110 enum audio_channels {
111 // output channels
Eric Laurentffe9c252010-06-23 17:38:20 -0700112 CHANNEL_OUT_FRONT_LEFT = 0x4,
113 CHANNEL_OUT_FRONT_RIGHT = 0x8,
114 CHANNEL_OUT_FRONT_CENTER = 0x10,
115 CHANNEL_OUT_LOW_FREQUENCY = 0x20,
116 CHANNEL_OUT_BACK_LEFT = 0x40,
117 CHANNEL_OUT_BACK_RIGHT = 0x80,
118 CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
119 CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
120 CHANNEL_OUT_BACK_CENTER = 0x400,
121 CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT,
122 CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT),
123 CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
124 CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
125 CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
126 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER),
127 CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
128 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
129 CHANNEL_OUT_7POINT1 = (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),
Eric Laurentc2f1f072009-07-17 12:17:14 -0700132 CHANNEL_OUT_ALL = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
133 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
134 CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | CHANNEL_OUT_BACK_CENTER),
135
136 // input channels
Eric Laurent9a920372009-07-27 07:12:26 -0700137 CHANNEL_IN_LEFT = 0x4,
138 CHANNEL_IN_RIGHT = 0x8,
139 CHANNEL_IN_FRONT = 0x10,
140 CHANNEL_IN_BACK = 0x20,
141 CHANNEL_IN_LEFT_PROCESSED = 0x40,
142 CHANNEL_IN_RIGHT_PROCESSED = 0x80,
143 CHANNEL_IN_FRONT_PROCESSED = 0x100,
144 CHANNEL_IN_BACK_PROCESSED = 0x200,
145 CHANNEL_IN_PRESSURE = 0x400,
146 CHANNEL_IN_X_AXIS = 0x800,
147 CHANNEL_IN_Y_AXIS = 0x1000,
148 CHANNEL_IN_Z_AXIS = 0x2000,
149 CHANNEL_IN_VOICE_UPLINK = 0x4000,
150 CHANNEL_IN_VOICE_DNLINK = 0x8000,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700151 CHANNEL_IN_MONO = CHANNEL_IN_FRONT,
152 CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT),
153 CHANNEL_IN_ALL = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_FRONT | CHANNEL_IN_BACK|
154 CHANNEL_IN_LEFT_PROCESSED | CHANNEL_IN_RIGHT_PROCESSED | CHANNEL_IN_FRONT_PROCESSED | CHANNEL_IN_BACK_PROCESSED|
155 CHANNEL_IN_PRESSURE | CHANNEL_IN_X_AXIS | CHANNEL_IN_Y_AXIS | CHANNEL_IN_Z_AXIS |
156 CHANNEL_IN_VOICE_UPLINK | CHANNEL_IN_VOICE_DNLINK)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800157 };
158
Glenn Kasten4bcae822011-04-04 10:50:50 -0700159 // must match android/media/AudioSystem.java MODE_* values
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800160 enum audio_mode {
161 MODE_INVALID = -2,
162 MODE_CURRENT = -1,
163 MODE_NORMAL = 0,
164 MODE_RINGTONE,
165 MODE_IN_CALL,
Jean-Michel Trivif1fb01a2010-11-15 12:11:32 -0800166 MODE_IN_COMMUNICATION,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800167 NUM_MODES // not a valid entry, denotes end-of-list
168 };
169
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800170 enum audio_in_acoustics {
171 AGC_ENABLE = 0x0001,
172 AGC_DISABLE = 0,
173 NS_ENABLE = 0x0002,
174 NS_DISABLE = 0,
175 TX_IIR_ENABLE = 0x0004,
176 TX_DISABLE = 0
177 };
178
Eric Laurentde070132010-07-13 04:45:46 -0700179 // special audio session values
180 enum audio_sessions {
181 SESSION_OUTPUT_STAGE = -1, // session for effects attached to a particular output stream
182 // (value must be less than 0)
183 SESSION_OUTPUT_MIX = 0, // session for effects applied to output mix. These effects can
184 // be moved by audio policy manager to another output stream
185 // (value must be 0)
186 };
187
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800188 /* These are static methods to control the system-wide AudioFlinger
189 * only privileged processes can have access to them
190 */
191
Eric Laurentc2f1f072009-07-17 12:17:14 -0700192 // mute/unmute microphone
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800193 static status_t muteMicrophone(bool state);
194 static status_t isMicrophoneMuted(bool *state);
195
Eric Laurentc2f1f072009-07-17 12:17:14 -0700196 // set/get master volume
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800197 static status_t setMasterVolume(float value);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800198 static status_t getMasterVolume(float* volume);
Glenn Kasten4bcae822011-04-04 10:50:50 -0700199
Eric Laurentc2f1f072009-07-17 12:17:14 -0700200 // mute/unmute audio outputs
201 static status_t setMasterMute(bool mute);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800202 static status_t getMasterMute(bool* mute);
203
Eric Laurentc2f1f072009-07-17 12:17:14 -0700204 // set/get stream volume on specified output
Eric Laurentfa2877b2009-07-28 08:44:33 -0700205 static status_t setStreamVolume(int stream, float value, int output);
206 static status_t getStreamVolume(int stream, float* volume, int output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700207
208 // mute/unmute stream
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800209 static status_t setStreamMute(int stream, bool mute);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800210 static status_t getStreamMute(int stream, bool* mute);
211
Eric Laurentc2f1f072009-07-17 12:17:14 -0700212 // set audio mode in audio hardware (see AudioSystem::audio_mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800213 static status_t setMode(int mode);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800214
Eric Laurenteda6c362011-02-02 09:33:30 -0800215 // returns true in *state if tracks are active on the specified stream or has been active
216 // in the past inPastMs milliseconds
217 static status_t isStreamActive(int stream, bool *state, uint32_t inPastMs = 0);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800218
Eric Laurentc2f1f072009-07-17 12:17:14 -0700219 // set/get audio hardware parameters. The function accepts a list of parameters
220 // key value pairs in the form: key1=value1;key2=value2;...
221 // Some keys are reserved for standard parameters (See AudioParameter class).
222 static status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs);
223 static String8 getParameters(audio_io_handle_t ioHandle, const String8& keys);
224
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800225 static void setErrorCallback(audio_error_callback cb);
226
227 // helper function to obtain AudioFlinger service handle
228 static const sp<IAudioFlinger>& get_audio_flinger();
229
230 static float linearToLog(int volume);
231 static int logToLinear(float volume);
232
233 static status_t getOutputSamplingRate(int* samplingRate, int stream = DEFAULT);
234 static status_t getOutputFrameCount(int* frameCount, int stream = DEFAULT);
235 static status_t getOutputLatency(uint32_t* latency, int stream = DEFAULT);
236
237 static bool routedToA2dpOutput(int streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700238
239 static status_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount,
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800240 size_t* buffSize);
241
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700242 static status_t setVoiceVolume(float volume);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700243
Eric Laurent342e9cf2010-01-19 17:37:09 -0800244 // return the number of audio frames written by AudioFlinger to audio HAL and
Glenn Kasten4bcae822011-04-04 10:50:50 -0700245 // audio dsp to DAC since the output on which the specified stream is playing
Eric Laurent342e9cf2010-01-19 17:37:09 -0800246 // has exited standby.
247 // returned status (from utils/Errors.h) can be:
248 // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data
249 // - INVALID_OPERATION: Not supported on current hardware platform
250 // - BAD_VALUE: invalid parameter
251 // NOTE: this feature is not supported on all hardware platforms and it is
252 // necessary to check returned status before using the returned values.
253 static status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int stream = DEFAULT);
254
Eric Laurent05bca2f2010-02-26 02:47:27 -0800255 static unsigned int getInputFramesLost(audio_io_handle_t ioHandle);
Eric Laurentbe916aa2010-06-01 23:49:17 -0700256
257 static int newAudioSessionId();
Eric Laurentc2f1f072009-07-17 12:17:14 -0700258 //
259 // AudioPolicyService interface
260 //
261
262 enum audio_devices {
263 // output devices
Eric Laurentffe9c252010-06-23 17:38:20 -0700264 DEVICE_OUT_EARPIECE = 0x1,
265 DEVICE_OUT_SPEAKER = 0x2,
266 DEVICE_OUT_WIRED_HEADSET = 0x4,
267 DEVICE_OUT_WIRED_HEADPHONE = 0x8,
268 DEVICE_OUT_BLUETOOTH_SCO = 0x10,
269 DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
270 DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
271 DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
272 DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
273 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
274 DEVICE_OUT_AUX_DIGITAL = 0x400,
Praveen Bharathib235dee2010-10-06 15:23:14 -0500275 DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
276 DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700277 DEVICE_OUT_DEFAULT = 0x8000,
278 DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
279 DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
280 DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
Praveen Bharathib235dee2010-10-06 15:23:14 -0500281 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL |
282 DEVICE_OUT_ANLG_DOCK_HEADSET | DEVICE_OUT_DGTL_DOCK_HEADSET |
283 DEVICE_OUT_DEFAULT),
Eric Laurent492e6662009-12-10 01:03:50 -0800284 DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
285 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
Eric Laurentc2f1f072009-07-17 12:17:14 -0700286
287 // input devices
288 DEVICE_IN_COMMUNICATION = 0x10000,
289 DEVICE_IN_AMBIENT = 0x20000,
290 DEVICE_IN_BUILTIN_MIC = 0x40000,
291 DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
292 DEVICE_IN_WIRED_HEADSET = 0x100000,
293 DEVICE_IN_AUX_DIGITAL = 0x200000,
294 DEVICE_IN_VOICE_CALL = 0x400000,
Eric Laurent90b75fb2009-11-02 05:31:33 -0800295 DEVICE_IN_BACK_MIC = 0x800000,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700296 DEVICE_IN_DEFAULT = 0x80000000,
297
298 DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC |
299 DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL |
Eric Laurent90b75fb2009-11-02 05:31:33 -0800300 DEVICE_IN_VOICE_CALL | DEVICE_IN_BACK_MIC | DEVICE_IN_DEFAULT)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700301 };
302
303 // device connection states used for setDeviceConnectionState()
304 enum device_connection_state {
305 DEVICE_STATE_UNAVAILABLE,
306 DEVICE_STATE_AVAILABLE,
307 NUM_DEVICE_STATES
308 };
309
310 // request to open a direct output with getOutput() (by opposition to sharing an output with other AudioTracks)
311 enum output_flags {
312 OUTPUT_FLAG_INDIRECT = 0x0,
313 OUTPUT_FLAG_DIRECT = 0x1
314 };
315
316 // device categories used for setForceUse()
317 enum forced_config {
318 FORCE_NONE,
319 FORCE_SPEAKER,
320 FORCE_HEADPHONES,
321 FORCE_BT_SCO,
322 FORCE_BT_A2DP,
323 FORCE_WIRED_ACCESSORY,
Eric Laurent7ddd4502009-12-17 03:12:59 -0800324 FORCE_BT_CAR_DOCK,
325 FORCE_BT_DESK_DOCK,
Praveen Bharathib235dee2010-10-06 15:23:14 -0500326 FORCE_ANALOG_DOCK,
327 FORCE_DIGITAL_DOCK,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700328 NUM_FORCE_CONFIG,
329 FORCE_DEFAULT = FORCE_NONE
330 };
331
Glenn Kasten4bcae822011-04-04 10:50:50 -0700332 // usages used for setForceUse(), must match AudioSystem.java
Eric Laurentc2f1f072009-07-17 12:17:14 -0700333 enum force_use {
334 FOR_COMMUNICATION,
335 FOR_MEDIA,
336 FOR_RECORD,
Jean-Michel Trivi48643f32009-12-07 18:40:56 -0800337 FOR_DOCK,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700338 NUM_FORCE_USE
339 };
340
341 // types of io configuration change events received with ioConfigChanged()
342 enum io_config_event {
343 OUTPUT_OPENED,
344 OUTPUT_CLOSED,
345 OUTPUT_CONFIG_CHANGED,
346 INPUT_OPENED,
347 INPUT_CLOSED,
348 INPUT_CONFIG_CHANGED,
349 STREAM_CONFIG_CHANGED,
350 NUM_CONFIG_EVENTS
351 };
352
353 // audio output descritor used to cache output configurations in client process to avoid frequent calls
354 // through IAudioFlinger
355 class OutputDescriptor {
356 public:
357 OutputDescriptor()
358 : samplingRate(0), format(0), channels(0), frameCount(0), latency(0) {}
359
360 uint32_t samplingRate;
361 int32_t format;
362 int32_t channels;
363 size_t frameCount;
364 uint32_t latency;
365 };
366
367 //
368 // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
369 //
370 static status_t setDeviceConnectionState(audio_devices device, device_connection_state state, const char *device_address);
371 static device_connection_state getDeviceConnectionState(audio_devices device, const char *device_address);
372 static status_t setPhoneState(int state);
373 static status_t setRingerMode(uint32_t mode, uint32_t mask);
374 static status_t setForceUse(force_use usage, forced_config config);
375 static forced_config getForceUse(force_use usage);
376 static audio_io_handle_t getOutput(stream_type stream,
377 uint32_t samplingRate = 0,
378 uint32_t format = FORMAT_DEFAULT,
379 uint32_t channels = CHANNEL_OUT_STEREO,
380 output_flags flags = OUTPUT_FLAG_INDIRECT);
Eric Laurentde070132010-07-13 04:45:46 -0700381 static status_t startOutput(audio_io_handle_t output,
382 AudioSystem::stream_type stream,
383 int session = 0);
384 static status_t stopOutput(audio_io_handle_t output,
385 AudioSystem::stream_type stream,
386 int session = 0);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700387 static void releaseOutput(audio_io_handle_t output);
388 static audio_io_handle_t getInput(int inputSource,
389 uint32_t samplingRate = 0,
390 uint32_t format = FORMAT_DEFAULT,
391 uint32_t channels = CHANNEL_IN_MONO,
392 audio_in_acoustics acoustics = (audio_in_acoustics)0);
393 static status_t startInput(audio_io_handle_t input);
394 static status_t stopInput(audio_io_handle_t input);
395 static void releaseInput(audio_io_handle_t input);
396 static status_t initStreamVolume(stream_type stream,
397 int indexMin,
398 int indexMax);
399 static status_t setStreamVolumeIndex(stream_type stream, int index);
400 static status_t getStreamVolumeIndex(stream_type stream, int *index);
401
Eric Laurentde070132010-07-13 04:45:46 -0700402 static uint32_t getStrategyForStream(stream_type stream);
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800403 static uint32_t getDevicesForStream(stream_type stream);
Eric Laurentde070132010-07-13 04:45:46 -0700404
405 static audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc);
406 static status_t registerEffect(effect_descriptor_t *desc,
407 audio_io_handle_t output,
408 uint32_t strategy,
409 int session,
410 int id);
411 static status_t unregisterEffect(int id);
412
Eric Laurentc2f1f072009-07-17 12:17:14 -0700413 static const sp<IAudioPolicyService>& get_audio_policy_service();
414
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800415 // ----------------------------------------------------------------------------
416
Eric Laurentc2f1f072009-07-17 12:17:14 -0700417 static uint32_t popCount(uint32_t u);
418 static bool isOutputDevice(audio_devices device);
419 static bool isInputDevice(audio_devices device);
420 static bool isA2dpDevice(audio_devices device);
421 static bool isBluetoothScoDevice(audio_devices device);
422 static bool isLowVisibility(stream_type stream);
423 static bool isOutputChannel(uint32_t channel);
424 static bool isInputChannel(uint32_t channel);
425 static bool isValidFormat(uint32_t format);
426 static bool isLinearPCM(uint32_t format);
427
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800428private:
429
430 class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient
431 {
432 public:
Eric Laurentc2f1f072009-07-17 12:17:14 -0700433 AudioFlingerClient() {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800434 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700435
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800436 // DeathRecipient
437 virtual void binderDied(const wp<IBinder>& who);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700438
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800439 // IAudioFlingerClient
Eric Laurentc2f1f072009-07-17 12:17:14 -0700440
441 // indicate a change in the configuration of an output or input: keeps the cached
442 // values for output/input parameters upto date in client process
Eric Laurentfa2877b2009-07-28 08:44:33 -0700443 virtual void ioConfigChanged(int event, int ioHandle, void *param2);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800444 };
Eric Laurentc2f1f072009-07-17 12:17:14 -0700445
446 class AudioPolicyServiceClient: public IBinder::DeathRecipient
447 {
448 public:
449 AudioPolicyServiceClient() {
450 }
451
452 // DeathRecipient
453 virtual void binderDied(const wp<IBinder>& who);
454 };
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800455
456 static sp<AudioFlingerClient> gAudioFlingerClient;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700457 static sp<AudioPolicyServiceClient> gAudioPolicyServiceClient;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800458 friend class AudioFlingerClient;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700459 friend class AudioPolicyServiceClient;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800460
461 static Mutex gLock;
462 static sp<IAudioFlinger> gAudioFlinger;
463 static audio_error_callback gAudioErrorCallback;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700464
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800465 static size_t gInBuffSize;
466 // previous parameters for recording buffer size queries
467 static uint32_t gPrevInSamplingRate;
468 static int gPrevInFormat;
469 static int gPrevInChannelCount;
470
Eric Laurentc2f1f072009-07-17 12:17:14 -0700471 static sp<IAudioPolicyService> gAudioPolicyService;
472
473 // mapping between stream types and outputs
474 static DefaultKeyedVector<int, audio_io_handle_t> gStreamOutputMap;
475 // list of output descritor containing cached parameters (sampling rate, framecount, channel count...)
476 static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs;
477};
478
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800479}; // namespace android
480
481#endif /*ANDROID_AUDIOSYSTEM_H_*/