blob: a6dedecd7a51431172f09416df5a8de88523c4e6 [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006-2007 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#define LOG_TAG "AudioSystem"
18//#define LOG_NDEBUG 0
19
20#include <utils/Log.h>
Mathias Agopian75624082009-05-19 19:08:10 -070021#include <binder/IServiceManager.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080022#include <media/AudioSystem.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070023#include <media/IAudioPolicyService.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080024#include <math.h>
25
Dima Zavin64760242011-05-11 14:15:23 -070026#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070027
Eric Laurentc2f1f072009-07-17 12:17:14 -070028// ----------------------------------------------------------------------------
Eric Laurentc2f1f072009-07-17 12:17:14 -070029
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080030namespace android {
31
32// client singleton for AudioFlinger binder interface
33Mutex AudioSystem::gLock;
34sp<IAudioFlinger> AudioSystem::gAudioFlinger;
35sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient;
36audio_error_callback AudioSystem::gAudioErrorCallback = NULL;
37// Cached values
Glenn Kasten211eeaf2012-01-20 09:37:45 -080038
Eric Laurentc2f1f072009-07-17 12:17:14 -070039DefaultKeyedVector<audio_io_handle_t, AudioSystem::OutputDescriptor *> AudioSystem::gOutputs(0);
40
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -080041// Cached values for recording queries, all protected by gLock
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080042uint32_t AudioSystem::gPrevInSamplingRate = 16000;
Glenn Kasten58f30212012-01-12 12:27:51 -080043audio_format_t AudioSystem::gPrevInFormat = AUDIO_FORMAT_PCM_16_BIT;
Glenn Kastendd8104c2012-07-02 12:42:44 -070044audio_channel_mask_t AudioSystem::gPrevInChannelMask = AUDIO_CHANNEL_IN_MONO;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080045size_t AudioSystem::gInBuffSize = 0;
46
47
48// establish binder interface to AudioFlinger service
49const sp<IAudioFlinger>& AudioSystem::get_audio_flinger()
50{
51 Mutex::Autolock _l(gLock);
Glenn Kasten7fc9a6f2012-01-10 10:46:34 -080052 if (gAudioFlinger == 0) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080053 sp<IServiceManager> sm = defaultServiceManager();
54 sp<IBinder> binder;
55 do {
56 binder = sm->getService(String16("media.audio_flinger"));
57 if (binder != 0)
58 break;
Steve Block5ff1dd52012-01-05 23:22:43 +000059 ALOGW("AudioFlinger not published, waiting...");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080060 usleep(500000); // 0.5 s
Glenn Kastene53b9ea2012-03-12 16:29:55 -070061 } while (true);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080062 if (gAudioFlingerClient == NULL) {
63 gAudioFlingerClient = new AudioFlingerClient();
64 } else {
65 if (gAudioErrorCallback) {
66 gAudioErrorCallback(NO_ERROR);
67 }
Glenn Kastene53b9ea2012-03-12 16:29:55 -070068 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080069 binder->linkToDeath(gAudioFlingerClient);
70 gAudioFlinger = interface_cast<IAudioFlinger>(binder);
71 gAudioFlinger->registerClient(gAudioFlingerClient);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080072 }
Steve Block29357bc2012-01-06 19:20:56 +000073 ALOGE_IF(gAudioFlinger==0, "no AudioFlinger!?");
Eric Laurentc2f1f072009-07-17 12:17:14 -070074
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080075 return gAudioFlinger;
76}
77
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080078status_t AudioSystem::muteMicrophone(bool state) {
79 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
80 if (af == 0) return PERMISSION_DENIED;
81 return af->setMicMute(state);
82}
83
84status_t AudioSystem::isMicrophoneMuted(bool* state) {
85 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
86 if (af == 0) return PERMISSION_DENIED;
87 *state = af->getMicMute();
88 return NO_ERROR;
89}
90
91status_t AudioSystem::setMasterVolume(float value)
92{
93 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
94 if (af == 0) return PERMISSION_DENIED;
95 af->setMasterVolume(value);
96 return NO_ERROR;
97}
98
99status_t AudioSystem::setMasterMute(bool mute)
100{
101 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
102 if (af == 0) return PERMISSION_DENIED;
103 af->setMasterMute(mute);
104 return NO_ERROR;
105}
106
107status_t AudioSystem::getMasterVolume(float* volume)
108{
109 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
110 if (af == 0) return PERMISSION_DENIED;
111 *volume = af->masterVolume();
112 return NO_ERROR;
113}
114
115status_t AudioSystem::getMasterMute(bool* mute)
116{
117 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
118 if (af == 0) return PERMISSION_DENIED;
119 *mute = af->masterMute();
120 return NO_ERROR;
121}
122
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800123status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value,
124 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800125{
Dima Zavinfce7a472011-04-19 22:30:36 -0700126 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800127 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
128 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700129 af->setStreamVolume(stream, value, output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800130 return NO_ERROR;
131}
132
Glenn Kastenfff6d712012-01-12 16:38:12 -0800133status_t AudioSystem::setStreamMute(audio_stream_type_t stream, bool mute)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800134{
Dima Zavinfce7a472011-04-19 22:30:36 -0700135 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800136 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
137 if (af == 0) return PERMISSION_DENIED;
138 af->setStreamMute(stream, mute);
139 return NO_ERROR;
140}
141
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800142status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume,
143 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800144{
Dima Zavinfce7a472011-04-19 22:30:36 -0700145 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800146 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
147 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700148 *volume = af->streamVolume(stream, output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800149 return NO_ERROR;
150}
151
Glenn Kastenfff6d712012-01-12 16:38:12 -0800152status_t AudioSystem::getStreamMute(audio_stream_type_t stream, bool* mute)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800153{
Dima Zavinfce7a472011-04-19 22:30:36 -0700154 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800155 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
156 if (af == 0) return PERMISSION_DENIED;
157 *mute = af->streamMute(stream);
158 return NO_ERROR;
159}
160
Glenn Kastenf78aee72012-01-04 11:00:47 -0800161status_t AudioSystem::setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800162{
Glenn Kasten930f4ca2012-01-06 16:47:31 -0800163 if (uint32_t(mode) >= AUDIO_MODE_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800164 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
165 if (af == 0) return PERMISSION_DENIED;
166 return af->setMode(mode);
167}
168
Eric Laurentc2f1f072009-07-17 12:17:14 -0700169status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800170 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
171 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700172 return af->setParameters(ioHandle, keyValuePairs);
173}
174
175String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys) {
176 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
177 String8 result = String8("");
178 if (af == 0) return result;
179
180 result = af->getParameters(ioHandle, keys);
181 return result;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800182}
183
184// convert volume steps to natural log scale
185
186// change this value to change volume scaling
187static const float dBPerStep = 0.5f;
188// shouldn't need to touch these
189static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f;
190static const float dBConvertInverse = 1.0f / dBConvert;
191
192float AudioSystem::linearToLog(int volume)
193{
194 // float v = volume ? exp(float(100 - volume) * dBConvert) : 0;
Steve Blockb8a80522011-12-20 16:23:08 +0000195 // ALOGD("linearToLog(%d)=%f", volume, v);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800196 // return v;
197 return volume ? exp(float(100 - volume) * dBConvert) : 0;
198}
199
200int AudioSystem::logToLinear(float volume)
201{
202 // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
Steve Blockb8a80522011-12-20 16:23:08 +0000203 // ALOGD("logTolinear(%d)=%f", v, volume);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800204 // return v;
205 return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
206}
207
Glenn Kasten3b16c762012-11-14 08:44:39 -0800208status_t AudioSystem::getOutputSamplingRate(uint32_t* samplingRate, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800209{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700210 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800211
Dima Zavinfce7a472011-04-19 22:30:36 -0700212 if (streamType == AUDIO_STREAM_DEFAULT) {
213 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700214 }
215
Glenn Kastenfff6d712012-01-12 16:38:12 -0800216 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700217 if (output == 0) {
218 return PERMISSION_DENIED;
219 }
220
Eric Laurent1a9ed112012-03-20 18:36:01 -0700221 return getSamplingRate(output, streamType, samplingRate);
222}
223
224status_t AudioSystem::getSamplingRate(audio_io_handle_t output,
225 audio_stream_type_t streamType,
Glenn Kasten3b16c762012-11-14 08:44:39 -0800226 uint32_t* samplingRate)
Eric Laurent1a9ed112012-03-20 18:36:01 -0700227{
228 OutputDescriptor *outputDesc;
229
Eric Laurentc2f1f072009-07-17 12:17:14 -0700230 gLock.lock();
231 outputDesc = AudioSystem::gOutputs.valueFor(output);
Glenn Kastena0d68332012-01-27 16:47:15 -0800232 if (outputDesc == NULL) {
Steve Block3856b092011-10-20 11:56:00 +0100233 ALOGV("getOutputSamplingRate() no output descriptor for output %d in gOutputs", output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700234 gLock.unlock();
235 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
236 if (af == 0) return PERMISSION_DENIED;
237 *samplingRate = af->sampleRate(output);
238 } else {
Steve Block3856b092011-10-20 11:56:00 +0100239 ALOGV("getOutputSamplingRate() reading from output desc");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700240 *samplingRate = outputDesc->samplingRate;
241 gLock.unlock();
242 }
243
Glenn Kasten3b16c762012-11-14 08:44:39 -0800244 ALOGV("getSamplingRate() streamType %d, output %d, sampling rate %u", streamType, output,
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700245 *samplingRate);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700246
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800247 return NO_ERROR;
248}
249
Glenn Kastene33054e2012-11-14 12:54:39 -0800250status_t AudioSystem::getOutputFrameCount(size_t* frameCount, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800251{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700252 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800253
Dima Zavinfce7a472011-04-19 22:30:36 -0700254 if (streamType == AUDIO_STREAM_DEFAULT) {
255 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700256 }
Eric Laurent48f7f5e2009-04-02 09:32:43 -0700257
Glenn Kastenfff6d712012-01-12 16:38:12 -0800258 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700259 if (output == 0) {
260 return PERMISSION_DENIED;
261 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800262
Eric Laurent1a9ed112012-03-20 18:36:01 -0700263 return getFrameCount(output, streamType, frameCount);
264}
265
266status_t AudioSystem::getFrameCount(audio_io_handle_t output,
267 audio_stream_type_t streamType,
Glenn Kastene33054e2012-11-14 12:54:39 -0800268 size_t* frameCount)
Eric Laurent1a9ed112012-03-20 18:36:01 -0700269{
270 OutputDescriptor *outputDesc;
271
Eric Laurentc2f1f072009-07-17 12:17:14 -0700272 gLock.lock();
273 outputDesc = AudioSystem::gOutputs.valueFor(output);
Glenn Kastena0d68332012-01-27 16:47:15 -0800274 if (outputDesc == NULL) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700275 gLock.unlock();
276 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
277 if (af == 0) return PERMISSION_DENIED;
278 *frameCount = af->frameCount(output);
279 } else {
280 *frameCount = outputDesc->frameCount;
281 gLock.unlock();
282 }
283
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700284 ALOGV("getFrameCount() streamType %d, output %d, frameCount %d", streamType, output,
285 *frameCount);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700286
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800287 return NO_ERROR;
288}
289
Glenn Kastenfff6d712012-01-12 16:38:12 -0800290status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800291{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700292 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800293
Dima Zavinfce7a472011-04-19 22:30:36 -0700294 if (streamType == AUDIO_STREAM_DEFAULT) {
295 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700296 }
Eric Laurent48f7f5e2009-04-02 09:32:43 -0700297
Glenn Kastenfff6d712012-01-12 16:38:12 -0800298 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700299 if (output == 0) {
300 return PERMISSION_DENIED;
301 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800302
Eric Laurent1a9ed112012-03-20 18:36:01 -0700303 return getLatency(output, streamType, latency);
304}
305
306status_t AudioSystem::getLatency(audio_io_handle_t output,
307 audio_stream_type_t streamType,
308 uint32_t* latency)
309{
310 OutputDescriptor *outputDesc;
311
Eric Laurentc2f1f072009-07-17 12:17:14 -0700312 gLock.lock();
313 outputDesc = AudioSystem::gOutputs.valueFor(output);
Glenn Kastena0d68332012-01-27 16:47:15 -0800314 if (outputDesc == NULL) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700315 gLock.unlock();
316 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
317 if (af == 0) return PERMISSION_DENIED;
318 *latency = af->latency(output);
319 } else {
320 *latency = outputDesc->latency;
321 gLock.unlock();
322 }
323
Eric Laurent1a9ed112012-03-20 18:36:01 -0700324 ALOGV("getLatency() streamType %d, output %d, latency %d", streamType, output, *latency);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700325
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800326 return NO_ERROR;
327}
328
Glenn Kastendd8104c2012-07-02 12:42:44 -0700329status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format,
330 audio_channel_mask_t channelMask, size_t* buffSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800331{
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800332 gLock.lock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800333 // Do we have a stale gInBufferSize or are we requesting the input buffer size for new values
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800334 size_t inBuffSize = gInBuffSize;
335 if ((inBuffSize == 0) || (sampleRate != gPrevInSamplingRate) || (format != gPrevInFormat)
Glenn Kastendd8104c2012-07-02 12:42:44 -0700336 || (channelMask != gPrevInChannelMask)) {
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800337 gLock.unlock();
338 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
339 if (af == 0) {
340 return PERMISSION_DENIED;
341 }
Glenn Kastendd8104c2012-07-02 12:42:44 -0700342 inBuffSize = af->getInputBufferSize(sampleRate, format, channelMask);
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800343 gLock.lock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800344 // save the request params
345 gPrevInSamplingRate = sampleRate;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700346 gPrevInFormat = format;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700347 gPrevInChannelMask = channelMask;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800348
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800349 gInBuffSize = inBuffSize;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700350 }
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800351 gLock.unlock();
352 *buffSize = inBuffSize;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700353
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800354 return NO_ERROR;
355}
356
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700357status_t AudioSystem::setVoiceVolume(float value)
358{
359 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
360 if (af == 0) return PERMISSION_DENIED;
361 return af->setVoiceVolume(value);
362}
363
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000364status_t AudioSystem::getRenderPosition(audio_io_handle_t output, size_t *halFrames,
365 size_t *dspFrames, audio_stream_type_t stream)
Eric Laurent342e9cf2010-01-19 17:37:09 -0800366{
367 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
368 if (af == 0) return PERMISSION_DENIED;
369
Dima Zavinfce7a472011-04-19 22:30:36 -0700370 if (stream == AUDIO_STREAM_DEFAULT) {
371 stream = AUDIO_STREAM_MUSIC;
Eric Laurent342e9cf2010-01-19 17:37:09 -0800372 }
373
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000374 if (output == 0) {
375 output = getOutput(stream);
376 }
377
378 return af->getRenderPosition(halFrames, dspFrames, output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800379}
380
Glenn Kastene33054e2012-11-14 12:54:39 -0800381size_t AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) {
Eric Laurent05bca2f2010-02-26 02:47:27 -0800382 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
383 unsigned int result = 0;
384 if (af == 0) return result;
Eric Laurentbe55a2d2010-03-11 14:47:00 -0800385 if (ioHandle == 0) return result;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800386
387 result = af->getInputFramesLost(ioHandle);
388 return result;
389}
390
Eric Laurentbe916aa2010-06-01 23:49:17 -0700391int AudioSystem::newAudioSessionId() {
392 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
393 if (af == 0) return 0;
394 return af->newAudioSessionId();
395}
396
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700397void AudioSystem::acquireAudioSessionId(int audioSession) {
398 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
399 if (af != 0) {
400 af->acquireAudioSessionId(audioSession);
401 }
402}
403
404void AudioSystem::releaseAudioSessionId(int audioSession) {
405 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
406 if (af != 0) {
407 af->releaseAudioSessionId(audioSession);
408 }
409}
410
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800411// ---------------------------------------------------------------------------
412
Eric Laurentc2f1f072009-07-17 12:17:14 -0700413void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800414 Mutex::Autolock _l(AudioSystem::gLock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800415
Eric Laurentc2f1f072009-07-17 12:17:14 -0700416 AudioSystem::gAudioFlinger.clear();
Eric Laurent0ef583f2010-01-25 10:27:15 -0800417 // clear output handles and stream to output map caches
Eric Laurent0ef583f2010-01-25 10:27:15 -0800418 AudioSystem::gOutputs.clear();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800419
420 if (gAudioErrorCallback) {
421 gAudioErrorCallback(DEAD_OBJECT);
422 }
Steve Block5ff1dd52012-01-05 23:22:43 +0000423 ALOGW("AudioFlinger server died!");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800424}
425
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800426void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, audio_io_handle_t ioHandle,
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800427 const void *param2) {
Steve Block3856b092011-10-20 11:56:00 +0100428 ALOGV("ioConfigChanged() event %d", event);
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800429 const OutputDescriptor *desc;
Glenn Kasten211eeaf2012-01-20 09:37:45 -0800430 audio_stream_type_t stream;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700431
Eric Laurentfa2877b2009-07-28 08:44:33 -0700432 if (ioHandle == 0) return;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700433
434 Mutex::Autolock _l(AudioSystem::gLock);
435
436 switch (event) {
437 case STREAM_CONFIG_CHANGED:
Eric Laurentc2f1f072009-07-17 12:17:14 -0700438 break;
439 case OUTPUT_OPENED: {
440 if (gOutputs.indexOfKey(ioHandle) >= 0) {
Steve Block3856b092011-10-20 11:56:00 +0100441 ALOGV("ioConfigChanged() opening already existing output! %d", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700442 break;
443 }
Glenn Kastena0d68332012-01-27 16:47:15 -0800444 if (param2 == NULL) break;
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800445 desc = (const OutputDescriptor *)param2;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700446
447 OutputDescriptor *outputDesc = new OutputDescriptor(*desc);
448 gOutputs.add(ioHandle, outputDesc);
Glenn Kastene33054e2012-11-14 12:54:39 -0800449 ALOGV("ioConfigChanged() new output samplingRate %u, format %d channels %#x frameCount %u "
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700450 "latency %d",
451 outputDesc->samplingRate, outputDesc->format, outputDesc->channels,
452 outputDesc->frameCount, outputDesc->latency);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700453 } break;
454 case OUTPUT_CLOSED: {
455 if (gOutputs.indexOfKey(ioHandle) < 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000456 ALOGW("ioConfigChanged() closing unknow output! %d", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700457 break;
458 }
Steve Block3856b092011-10-20 11:56:00 +0100459 ALOGV("ioConfigChanged() output %d closed", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700460
461 gOutputs.removeItem(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700462 } break;
463
464 case OUTPUT_CONFIG_CHANGED: {
465 int index = gOutputs.indexOfKey(ioHandle);
466 if (index < 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000467 ALOGW("ioConfigChanged() modifying unknow output! %d", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700468 break;
469 }
Glenn Kastena0d68332012-01-27 16:47:15 -0800470 if (param2 == NULL) break;
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800471 desc = (const OutputDescriptor *)param2;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700472
Glenn Kasten3b16c762012-11-14 08:44:39 -0800473 ALOGV("ioConfigChanged() new config for output %d samplingRate %u, format %d channels %#x "
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700474 "frameCount %d latency %d",
Eric Laurentc2f1f072009-07-17 12:17:14 -0700475 ioHandle, desc->samplingRate, desc->format,
476 desc->channels, desc->frameCount, desc->latency);
477 OutputDescriptor *outputDesc = gOutputs.valueAt(index);
478 delete outputDesc;
479 outputDesc = new OutputDescriptor(*desc);
480 gOutputs.replaceValueFor(ioHandle, outputDesc);
481 } break;
482 case INPUT_OPENED:
483 case INPUT_CLOSED:
484 case INPUT_CONFIG_CHANGED:
485 break;
486
487 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800488}
489
490void AudioSystem::setErrorCallback(audio_error_callback cb) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700491 Mutex::Autolock _l(gLock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800492 gAudioErrorCallback = cb;
493}
494
Glenn Kastenfff6d712012-01-12 16:38:12 -0800495bool AudioSystem::routedToA2dpOutput(audio_stream_type_t streamType) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700496 switch (streamType) {
Dima Zavinfce7a472011-04-19 22:30:36 -0700497 case AUDIO_STREAM_MUSIC:
498 case AUDIO_STREAM_VOICE_CALL:
499 case AUDIO_STREAM_BLUETOOTH_SCO:
500 case AUDIO_STREAM_SYSTEM:
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800501 return true;
502 default:
503 return false;
504 }
505}
506
507
Eric Laurentc2f1f072009-07-17 12:17:14 -0700508// client singleton for AudioPolicyService binder interface
509sp<IAudioPolicyService> AudioSystem::gAudioPolicyService;
510sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient;
511
512
Glenn Kasten18a6d902012-09-24 11:27:56 -0700513// establish binder interface to AudioPolicy service
Eric Laurentc2f1f072009-07-17 12:17:14 -0700514const sp<IAudioPolicyService>& AudioSystem::get_audio_policy_service()
515{
516 gLock.lock();
Glenn Kasten7fc9a6f2012-01-10 10:46:34 -0800517 if (gAudioPolicyService == 0) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700518 sp<IServiceManager> sm = defaultServiceManager();
519 sp<IBinder> binder;
520 do {
521 binder = sm->getService(String16("media.audio_policy"));
522 if (binder != 0)
523 break;
Steve Block5ff1dd52012-01-05 23:22:43 +0000524 ALOGW("AudioPolicyService not published, waiting...");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700525 usleep(500000); // 0.5 s
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700526 } while (true);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700527 if (gAudioPolicyServiceClient == NULL) {
528 gAudioPolicyServiceClient = new AudioPolicyServiceClient();
529 }
530 binder->linkToDeath(gAudioPolicyServiceClient);
531 gAudioPolicyService = interface_cast<IAudioPolicyService>(binder);
532 gLock.unlock();
533 } else {
534 gLock.unlock();
535 }
536 return gAudioPolicyService;
537}
538
Dima Zavinfce7a472011-04-19 22:30:36 -0700539status_t AudioSystem::setDeviceConnectionState(audio_devices_t device,
540 audio_policy_dev_state_t state,
541 const char *device_address)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700542{
543 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurent71b63e32011-09-02 14:20:56 -0700544 const char *address = "";
545
Eric Laurentc2f1f072009-07-17 12:17:14 -0700546 if (aps == 0) return PERMISSION_DENIED;
547
Eric Laurent71b63e32011-09-02 14:20:56 -0700548 if (device_address != NULL) {
549 address = device_address;
550 }
551
552 return aps->setDeviceConnectionState(device, state, address);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700553}
554
Dima Zavinfce7a472011-04-19 22:30:36 -0700555audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700556 const char *device_address)
557{
558 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700559 if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700560
561 return aps->getDeviceConnectionState(device, device_address);
562}
563
Glenn Kastenf78aee72012-01-04 11:00:47 -0800564status_t AudioSystem::setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700565{
Glenn Kasten347966c2012-01-18 14:58:32 -0800566 if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700567 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
568 if (aps == 0) return PERMISSION_DENIED;
569
570 return aps->setPhoneState(state);
571}
572
Dima Zavinfce7a472011-04-19 22:30:36 -0700573status_t AudioSystem::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700574{
575 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
576 if (aps == 0) return PERMISSION_DENIED;
577 return aps->setForceUse(usage, config);
578}
579
Dima Zavinfce7a472011-04-19 22:30:36 -0700580audio_policy_forced_cfg_t AudioSystem::getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700581{
582 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700583 if (aps == 0) return AUDIO_POLICY_FORCE_NONE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700584 return aps->getForceUse(usage);
585}
586
587
Dima Zavinfce7a472011-04-19 22:30:36 -0700588audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700589 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800590 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700591 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000592 audio_output_flags_t flags,
593 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700594{
Eric Laurent1a9ed112012-03-20 18:36:01 -0700595 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
596 if (aps == 0) return 0;
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000597 return aps->getOutput(stream, samplingRate, format, channelMask, flags, offloadInfo);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700598}
599
Eric Laurentde070132010-07-13 04:45:46 -0700600status_t AudioSystem::startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700601 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700602 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700603{
604 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
605 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700606 return aps->startOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700607}
608
Eric Laurentde070132010-07-13 04:45:46 -0700609status_t AudioSystem::stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700610 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700611 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700612{
613 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
614 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700615 return aps->stopOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700616}
617
618void AudioSystem::releaseOutput(audio_io_handle_t output)
619{
620 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
621 if (aps == 0) return;
622 aps->releaseOutput(output);
623}
624
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800625audio_io_handle_t AudioSystem::getInput(audio_source_t inputSource,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700626 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800627 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700628 audio_channel_mask_t channelMask,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700629 int sessionId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700630{
631 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700632 if (aps == 0) return 0;
Glenn Kasten254af182012-07-03 14:59:05 -0700633 return aps->getInput(inputSource, samplingRate, format, channelMask, sessionId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700634}
635
636status_t AudioSystem::startInput(audio_io_handle_t input)
637{
638 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
639 if (aps == 0) return PERMISSION_DENIED;
640 return aps->startInput(input);
641}
642
643status_t AudioSystem::stopInput(audio_io_handle_t input)
644{
645 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
646 if (aps == 0) return PERMISSION_DENIED;
647 return aps->stopInput(input);
648}
649
650void AudioSystem::releaseInput(audio_io_handle_t input)
651{
652 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
653 if (aps == 0) return;
654 aps->releaseInput(input);
655}
656
Dima Zavinfce7a472011-04-19 22:30:36 -0700657status_t AudioSystem::initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700658 int indexMin,
659 int indexMax)
660{
661 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
662 if (aps == 0) return PERMISSION_DENIED;
663 return aps->initStreamVolume(stream, indexMin, indexMax);
664}
665
Eric Laurent83844cc2011-11-18 16:43:31 -0800666status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream,
667 int index,
668 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700669{
670 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
671 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800672 return aps->setStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700673}
674
Eric Laurent83844cc2011-11-18 16:43:31 -0800675status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream,
676 int *index,
677 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700678{
679 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
680 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800681 return aps->getStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700682}
683
Dima Zavinfce7a472011-04-19 22:30:36 -0700684uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700685{
686 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
687 if (aps == 0) return 0;
688 return aps->getStrategyForStream(stream);
689}
690
Eric Laurent63742522012-03-08 13:42:42 -0800691audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800692{
693 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurent63742522012-03-08 13:42:42 -0800694 if (aps == 0) return (audio_devices_t)0;
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800695 return aps->getDevicesForStream(stream);
696}
697
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700698audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700699{
700 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
701 if (aps == 0) return PERMISSION_DENIED;
702 return aps->getOutputForEffect(desc);
703}
704
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700705status_t AudioSystem::registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700706 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700707 uint32_t strategy,
708 int session,
709 int id)
710{
711 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
712 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700713 return aps->registerEffect(desc, io, strategy, session, id);
Eric Laurentde070132010-07-13 04:45:46 -0700714}
715
716status_t AudioSystem::unregisterEffect(int id)
717{
718 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
719 if (aps == 0) return PERMISSION_DENIED;
720 return aps->unregisterEffect(id);
721}
722
Eric Laurentdb7c0792011-08-10 10:37:50 -0700723status_t AudioSystem::setEffectEnabled(int id, bool enabled)
724{
725 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
726 if (aps == 0) return PERMISSION_DENIED;
727 return aps->setEffectEnabled(id, enabled);
728}
729
Glenn Kastenfff6d712012-01-12 16:38:12 -0800730status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs)
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700731{
Eric Laurenteda6c362011-02-02 09:33:30 -0800732 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
733 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700734 if (state == NULL) return BAD_VALUE;
Eric Laurenteda6c362011-02-02 09:33:30 -0800735 *state = aps->isStreamActive(stream, inPastMs);
736 return NO_ERROR;
737}
738
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800739status_t AudioSystem::isStreamActiveRemotely(audio_stream_type_t stream, bool* state,
740 uint32_t inPastMs)
741{
742 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
743 if (aps == 0) return PERMISSION_DENIED;
744 if (state == NULL) return BAD_VALUE;
745 *state = aps->isStreamActiveRemotely(stream, inPastMs);
746 return NO_ERROR;
747}
748
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700749status_t AudioSystem::isSourceActive(audio_source_t stream, bool* state)
750{
751 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
752 if (aps == 0) return PERMISSION_DENIED;
753 if (state == NULL) return BAD_VALUE;
754 *state = aps->isSourceActive(stream);
755 return NO_ERROR;
756}
757
Glenn Kasten3b16c762012-11-14 08:44:39 -0800758uint32_t AudioSystem::getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700759{
760 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
761 if (af == 0) return 0;
762 return af->getPrimaryOutputSamplingRate();
763}
764
Glenn Kastene33054e2012-11-14 12:54:39 -0800765size_t AudioSystem::getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700766{
767 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
768 if (af == 0) return 0;
769 return af->getPrimaryOutputFrameCount();
770}
Eric Laurenteda6c362011-02-02 09:33:30 -0800771
Eric Laurent9f6530f2011-08-30 10:18:54 -0700772void AudioSystem::clearAudioConfigCache()
773{
774 Mutex::Autolock _l(gLock);
Steve Block3856b092011-10-20 11:56:00 +0100775 ALOGV("clearAudioConfigCache()");
Eric Laurent9f6530f2011-08-30 10:18:54 -0700776 gOutputs.clear();
777}
778
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000779bool AudioSystem::isOffloadSupported(const audio_offload_info_t& info)
780{
781 ALOGV("isOffloadSupported()");
782 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
783 if (aps == 0) return false;
784 return aps->isOffloadSupported(info);
785}
786
Eric Laurentc2f1f072009-07-17 12:17:14 -0700787// ---------------------------------------------------------------------------
788
789void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who) {
790 Mutex::Autolock _l(AudioSystem::gLock);
791 AudioSystem::gAudioPolicyService.clear();
792
Steve Block5ff1dd52012-01-05 23:22:43 +0000793 ALOGW("AudioPolicyService server died!");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700794}
795
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800796}; // namespace android