blob: 22d6763335a67b1ff8ffe2b6b350d6a46d511655 [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>
Glenn Kasten1ab85ec2013-05-31 09:18:43 -070023#include <media/IAudioFlinger.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070024#include <media/IAudioPolicyService.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080025#include <math.h>
26
Dima Zavin64760242011-05-11 14:15:23 -070027#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070028
Eric Laurentc2f1f072009-07-17 12:17:14 -070029// ----------------------------------------------------------------------------
Eric Laurentc2f1f072009-07-17 12:17:14 -070030
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080031namespace android {
32
33// client singleton for AudioFlinger binder interface
34Mutex AudioSystem::gLock;
35sp<IAudioFlinger> AudioSystem::gAudioFlinger;
36sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient;
37audio_error_callback AudioSystem::gAudioErrorCallback = NULL;
38// Cached values
Glenn Kasten211eeaf2012-01-20 09:37:45 -080039
Eric Laurentc2f1f072009-07-17 12:17:14 -070040DefaultKeyedVector<audio_io_handle_t, AudioSystem::OutputDescriptor *> AudioSystem::gOutputs(0);
41
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -080042// Cached values for recording queries, all protected by gLock
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080043uint32_t AudioSystem::gPrevInSamplingRate = 16000;
Glenn Kasten58f30212012-01-12 12:27:51 -080044audio_format_t AudioSystem::gPrevInFormat = AUDIO_FORMAT_PCM_16_BIT;
Glenn Kastendd8104c2012-07-02 12:42:44 -070045audio_channel_mask_t AudioSystem::gPrevInChannelMask = AUDIO_CHANNEL_IN_MONO;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080046size_t AudioSystem::gInBuffSize = 0;
47
48
49// establish binder interface to AudioFlinger service
50const sp<IAudioFlinger>& AudioSystem::get_audio_flinger()
51{
52 Mutex::Autolock _l(gLock);
Glenn Kasten7fc9a6f2012-01-10 10:46:34 -080053 if (gAudioFlinger == 0) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080054 sp<IServiceManager> sm = defaultServiceManager();
55 sp<IBinder> binder;
56 do {
57 binder = sm->getService(String16("media.audio_flinger"));
58 if (binder != 0)
59 break;
Steve Block5ff1dd52012-01-05 23:22:43 +000060 ALOGW("AudioFlinger not published, waiting...");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080061 usleep(500000); // 0.5 s
Glenn Kastene53b9ea2012-03-12 16:29:55 -070062 } while (true);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080063 if (gAudioFlingerClient == NULL) {
64 gAudioFlingerClient = new AudioFlingerClient();
65 } else {
66 if (gAudioErrorCallback) {
67 gAudioErrorCallback(NO_ERROR);
68 }
Glenn Kastene53b9ea2012-03-12 16:29:55 -070069 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080070 binder->linkToDeath(gAudioFlingerClient);
71 gAudioFlinger = interface_cast<IAudioFlinger>(binder);
72 gAudioFlinger->registerClient(gAudioFlingerClient);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080073 }
Steve Block29357bc2012-01-06 19:20:56 +000074 ALOGE_IF(gAudioFlinger==0, "no AudioFlinger!?");
Eric Laurentc2f1f072009-07-17 12:17:14 -070075
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080076 return gAudioFlinger;
77}
78
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080079status_t AudioSystem::muteMicrophone(bool state) {
80 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
81 if (af == 0) return PERMISSION_DENIED;
82 return af->setMicMute(state);
83}
84
85status_t AudioSystem::isMicrophoneMuted(bool* state) {
86 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
87 if (af == 0) return PERMISSION_DENIED;
88 *state = af->getMicMute();
89 return NO_ERROR;
90}
91
92status_t AudioSystem::setMasterVolume(float value)
93{
94 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
95 if (af == 0) return PERMISSION_DENIED;
96 af->setMasterVolume(value);
97 return NO_ERROR;
98}
99
100status_t AudioSystem::setMasterMute(bool mute)
101{
102 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
103 if (af == 0) return PERMISSION_DENIED;
104 af->setMasterMute(mute);
105 return NO_ERROR;
106}
107
108status_t AudioSystem::getMasterVolume(float* volume)
109{
110 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
111 if (af == 0) return PERMISSION_DENIED;
112 *volume = af->masterVolume();
113 return NO_ERROR;
114}
115
116status_t AudioSystem::getMasterMute(bool* mute)
117{
118 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
119 if (af == 0) return PERMISSION_DENIED;
120 *mute = af->masterMute();
121 return NO_ERROR;
122}
123
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800124status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value,
125 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800126{
Dima Zavinfce7a472011-04-19 22:30:36 -0700127 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800128 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
129 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700130 af->setStreamVolume(stream, value, output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800131 return NO_ERROR;
132}
133
Glenn Kastenfff6d712012-01-12 16:38:12 -0800134status_t AudioSystem::setStreamMute(audio_stream_type_t stream, bool mute)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800135{
Dima Zavinfce7a472011-04-19 22:30:36 -0700136 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800137 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
138 if (af == 0) return PERMISSION_DENIED;
139 af->setStreamMute(stream, mute);
140 return NO_ERROR;
141}
142
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800143status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume,
144 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800145{
Dima Zavinfce7a472011-04-19 22:30:36 -0700146 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800147 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
148 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700149 *volume = af->streamVolume(stream, output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800150 return NO_ERROR;
151}
152
Glenn Kastenfff6d712012-01-12 16:38:12 -0800153status_t AudioSystem::getStreamMute(audio_stream_type_t stream, bool* mute)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800154{
Dima Zavinfce7a472011-04-19 22:30:36 -0700155 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800156 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
157 if (af == 0) return PERMISSION_DENIED;
158 *mute = af->streamMute(stream);
159 return NO_ERROR;
160}
161
Glenn Kastenf78aee72012-01-04 11:00:47 -0800162status_t AudioSystem::setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800163{
Glenn Kasten930f4ca2012-01-06 16:47:31 -0800164 if (uint32_t(mode) >= AUDIO_MODE_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800165 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
166 if (af == 0) return PERMISSION_DENIED;
167 return af->setMode(mode);
168}
169
Eric Laurentc2f1f072009-07-17 12:17:14 -0700170status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800171 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
172 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700173 return af->setParameters(ioHandle, keyValuePairs);
174}
175
176String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys) {
177 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
178 String8 result = String8("");
179 if (af == 0) return result;
180
181 result = af->getParameters(ioHandle, keys);
182 return result;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800183}
184
185// convert volume steps to natural log scale
186
187// change this value to change volume scaling
188static const float dBPerStep = 0.5f;
189// shouldn't need to touch these
190static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f;
191static const float dBConvertInverse = 1.0f / dBConvert;
192
193float AudioSystem::linearToLog(int volume)
194{
195 // float v = volume ? exp(float(100 - volume) * dBConvert) : 0;
Steve Blockb8a80522011-12-20 16:23:08 +0000196 // ALOGD("linearToLog(%d)=%f", volume, v);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800197 // return v;
198 return volume ? exp(float(100 - volume) * dBConvert) : 0;
199}
200
201int AudioSystem::logToLinear(float volume)
202{
203 // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
Steve Blockb8a80522011-12-20 16:23:08 +0000204 // ALOGD("logTolinear(%d)=%f", v, volume);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800205 // return v;
206 return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
207}
208
Glenn Kasten3b16c762012-11-14 08:44:39 -0800209status_t AudioSystem::getOutputSamplingRate(uint32_t* samplingRate, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800210{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700211 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800212
Dima Zavinfce7a472011-04-19 22:30:36 -0700213 if (streamType == AUDIO_STREAM_DEFAULT) {
214 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700215 }
216
Glenn Kastenfff6d712012-01-12 16:38:12 -0800217 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700218 if (output == 0) {
219 return PERMISSION_DENIED;
220 }
221
Eric Laurent1a9ed112012-03-20 18:36:01 -0700222 return getSamplingRate(output, streamType, samplingRate);
223}
224
225status_t AudioSystem::getSamplingRate(audio_io_handle_t output,
226 audio_stream_type_t streamType,
Glenn Kasten3b16c762012-11-14 08:44:39 -0800227 uint32_t* samplingRate)
Eric Laurent1a9ed112012-03-20 18:36:01 -0700228{
229 OutputDescriptor *outputDesc;
230
Eric Laurentc2f1f072009-07-17 12:17:14 -0700231 gLock.lock();
232 outputDesc = AudioSystem::gOutputs.valueFor(output);
Glenn Kastena0d68332012-01-27 16:47:15 -0800233 if (outputDesc == NULL) {
Steve Block3856b092011-10-20 11:56:00 +0100234 ALOGV("getOutputSamplingRate() no output descriptor for output %d in gOutputs", output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700235 gLock.unlock();
236 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
237 if (af == 0) return PERMISSION_DENIED;
238 *samplingRate = af->sampleRate(output);
239 } else {
Steve Block3856b092011-10-20 11:56:00 +0100240 ALOGV("getOutputSamplingRate() reading from output desc");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700241 *samplingRate = outputDesc->samplingRate;
242 gLock.unlock();
243 }
244
Glenn Kasten3b16c762012-11-14 08:44:39 -0800245 ALOGV("getSamplingRate() streamType %d, output %d, sampling rate %u", streamType, output,
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700246 *samplingRate);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700247
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800248 return NO_ERROR;
249}
250
Glenn Kastene33054e2012-11-14 12:54:39 -0800251status_t AudioSystem::getOutputFrameCount(size_t* frameCount, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800252{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700253 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800254
Dima Zavinfce7a472011-04-19 22:30:36 -0700255 if (streamType == AUDIO_STREAM_DEFAULT) {
256 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700257 }
Eric Laurent48f7f5e2009-04-02 09:32:43 -0700258
Glenn Kastenfff6d712012-01-12 16:38:12 -0800259 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700260 if (output == 0) {
261 return PERMISSION_DENIED;
262 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800263
Eric Laurent1a9ed112012-03-20 18:36:01 -0700264 return getFrameCount(output, streamType, frameCount);
265}
266
267status_t AudioSystem::getFrameCount(audio_io_handle_t output,
268 audio_stream_type_t streamType,
Glenn Kastene33054e2012-11-14 12:54:39 -0800269 size_t* frameCount)
Eric Laurent1a9ed112012-03-20 18:36:01 -0700270{
271 OutputDescriptor *outputDesc;
272
Eric Laurentc2f1f072009-07-17 12:17:14 -0700273 gLock.lock();
274 outputDesc = AudioSystem::gOutputs.valueFor(output);
Glenn Kastena0d68332012-01-27 16:47:15 -0800275 if (outputDesc == NULL) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700276 gLock.unlock();
277 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
278 if (af == 0) return PERMISSION_DENIED;
279 *frameCount = af->frameCount(output);
280 } else {
281 *frameCount = outputDesc->frameCount;
282 gLock.unlock();
283 }
284
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700285 ALOGV("getFrameCount() streamType %d, output %d, frameCount %d", streamType, output,
286 *frameCount);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700287
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800288 return NO_ERROR;
289}
290
Glenn Kastenfff6d712012-01-12 16:38:12 -0800291status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800292{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700293 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800294
Dima Zavinfce7a472011-04-19 22:30:36 -0700295 if (streamType == AUDIO_STREAM_DEFAULT) {
296 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700297 }
Eric Laurent48f7f5e2009-04-02 09:32:43 -0700298
Glenn Kastenfff6d712012-01-12 16:38:12 -0800299 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700300 if (output == 0) {
301 return PERMISSION_DENIED;
302 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800303
Eric Laurent1a9ed112012-03-20 18:36:01 -0700304 return getLatency(output, streamType, latency);
305}
306
307status_t AudioSystem::getLatency(audio_io_handle_t output,
308 audio_stream_type_t streamType,
309 uint32_t* latency)
310{
311 OutputDescriptor *outputDesc;
312
Eric Laurentc2f1f072009-07-17 12:17:14 -0700313 gLock.lock();
314 outputDesc = AudioSystem::gOutputs.valueFor(output);
Glenn Kastena0d68332012-01-27 16:47:15 -0800315 if (outputDesc == NULL) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700316 gLock.unlock();
317 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
318 if (af == 0) return PERMISSION_DENIED;
319 *latency = af->latency(output);
320 } else {
321 *latency = outputDesc->latency;
322 gLock.unlock();
323 }
324
Eric Laurent1a9ed112012-03-20 18:36:01 -0700325 ALOGV("getLatency() streamType %d, output %d, latency %d", streamType, output, *latency);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700326
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800327 return NO_ERROR;
328}
329
Glenn Kastendd8104c2012-07-02 12:42:44 -0700330status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format,
331 audio_channel_mask_t channelMask, size_t* buffSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800332{
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800333 gLock.lock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800334 // Do we have a stale gInBufferSize or are we requesting the input buffer size for new values
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800335 size_t inBuffSize = gInBuffSize;
336 if ((inBuffSize == 0) || (sampleRate != gPrevInSamplingRate) || (format != gPrevInFormat)
Glenn Kastendd8104c2012-07-02 12:42:44 -0700337 || (channelMask != gPrevInChannelMask)) {
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800338 gLock.unlock();
339 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
340 if (af == 0) {
341 return PERMISSION_DENIED;
342 }
Glenn Kastendd8104c2012-07-02 12:42:44 -0700343 inBuffSize = af->getInputBufferSize(sampleRate, format, channelMask);
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800344 gLock.lock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800345 // save the request params
346 gPrevInSamplingRate = sampleRate;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700347 gPrevInFormat = format;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700348 gPrevInChannelMask = channelMask;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800349
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800350 gInBuffSize = inBuffSize;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700351 }
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800352 gLock.unlock();
353 *buffSize = inBuffSize;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700354
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800355 return NO_ERROR;
356}
357
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700358status_t AudioSystem::setVoiceVolume(float value)
359{
360 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
361 if (af == 0) return PERMISSION_DENIED;
362 return af->setVoiceVolume(value);
363}
364
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000365status_t AudioSystem::getRenderPosition(audio_io_handle_t output, size_t *halFrames,
366 size_t *dspFrames, audio_stream_type_t stream)
Eric Laurent342e9cf2010-01-19 17:37:09 -0800367{
368 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
369 if (af == 0) return PERMISSION_DENIED;
370
Dima Zavinfce7a472011-04-19 22:30:36 -0700371 if (stream == AUDIO_STREAM_DEFAULT) {
372 stream = AUDIO_STREAM_MUSIC;
Eric Laurent342e9cf2010-01-19 17:37:09 -0800373 }
374
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000375 if (output == 0) {
376 output = getOutput(stream);
377 }
378
379 return af->getRenderPosition(halFrames, dspFrames, output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800380}
381
Glenn Kastene33054e2012-11-14 12:54:39 -0800382size_t AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) {
Eric Laurent05bca2f2010-02-26 02:47:27 -0800383 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
384 unsigned int result = 0;
385 if (af == 0) return result;
Eric Laurentbe55a2d2010-03-11 14:47:00 -0800386 if (ioHandle == 0) return result;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800387
388 result = af->getInputFramesLost(ioHandle);
389 return result;
390}
391
Eric Laurentbe916aa2010-06-01 23:49:17 -0700392int AudioSystem::newAudioSessionId() {
393 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
394 if (af == 0) return 0;
395 return af->newAudioSessionId();
396}
397
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700398void AudioSystem::acquireAudioSessionId(int audioSession) {
399 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
400 if (af != 0) {
401 af->acquireAudioSessionId(audioSession);
402 }
403}
404
405void AudioSystem::releaseAudioSessionId(int audioSession) {
406 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
407 if (af != 0) {
408 af->releaseAudioSessionId(audioSession);
409 }
410}
411
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800412// ---------------------------------------------------------------------------
413
Eric Laurentc2f1f072009-07-17 12:17:14 -0700414void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800415 Mutex::Autolock _l(AudioSystem::gLock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800416
Eric Laurentc2f1f072009-07-17 12:17:14 -0700417 AudioSystem::gAudioFlinger.clear();
Eric Laurent0ef583f2010-01-25 10:27:15 -0800418 // clear output handles and stream to output map caches
Eric Laurent0ef583f2010-01-25 10:27:15 -0800419 AudioSystem::gOutputs.clear();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800420
421 if (gAudioErrorCallback) {
422 gAudioErrorCallback(DEAD_OBJECT);
423 }
Steve Block5ff1dd52012-01-05 23:22:43 +0000424 ALOGW("AudioFlinger server died!");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800425}
426
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800427void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, audio_io_handle_t ioHandle,
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800428 const void *param2) {
Steve Block3856b092011-10-20 11:56:00 +0100429 ALOGV("ioConfigChanged() event %d", event);
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800430 const OutputDescriptor *desc;
Glenn Kasten211eeaf2012-01-20 09:37:45 -0800431 audio_stream_type_t stream;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700432
Eric Laurentfa2877b2009-07-28 08:44:33 -0700433 if (ioHandle == 0) return;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700434
435 Mutex::Autolock _l(AudioSystem::gLock);
436
437 switch (event) {
438 case STREAM_CONFIG_CHANGED:
Eric Laurentc2f1f072009-07-17 12:17:14 -0700439 break;
440 case OUTPUT_OPENED: {
441 if (gOutputs.indexOfKey(ioHandle) >= 0) {
Steve Block3856b092011-10-20 11:56:00 +0100442 ALOGV("ioConfigChanged() opening already existing output! %d", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700443 break;
444 }
Glenn Kastena0d68332012-01-27 16:47:15 -0800445 if (param2 == NULL) break;
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800446 desc = (const OutputDescriptor *)param2;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700447
448 OutputDescriptor *outputDesc = new OutputDescriptor(*desc);
449 gOutputs.add(ioHandle, outputDesc);
Glenn Kastene33054e2012-11-14 12:54:39 -0800450 ALOGV("ioConfigChanged() new output samplingRate %u, format %d channels %#x frameCount %u "
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700451 "latency %d",
452 outputDesc->samplingRate, outputDesc->format, outputDesc->channels,
453 outputDesc->frameCount, outputDesc->latency);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700454 } break;
455 case OUTPUT_CLOSED: {
456 if (gOutputs.indexOfKey(ioHandle) < 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000457 ALOGW("ioConfigChanged() closing unknow output! %d", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700458 break;
459 }
Steve Block3856b092011-10-20 11:56:00 +0100460 ALOGV("ioConfigChanged() output %d closed", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700461
462 gOutputs.removeItem(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700463 } break;
464
465 case OUTPUT_CONFIG_CHANGED: {
466 int index = gOutputs.indexOfKey(ioHandle);
467 if (index < 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000468 ALOGW("ioConfigChanged() modifying unknow output! %d", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700469 break;
470 }
Glenn Kastena0d68332012-01-27 16:47:15 -0800471 if (param2 == NULL) break;
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800472 desc = (const OutputDescriptor *)param2;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700473
Glenn Kasten3b16c762012-11-14 08:44:39 -0800474 ALOGV("ioConfigChanged() new config for output %d samplingRate %u, format %d channels %#x "
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700475 "frameCount %d latency %d",
Eric Laurentc2f1f072009-07-17 12:17:14 -0700476 ioHandle, desc->samplingRate, desc->format,
477 desc->channels, desc->frameCount, desc->latency);
478 OutputDescriptor *outputDesc = gOutputs.valueAt(index);
479 delete outputDesc;
480 outputDesc = new OutputDescriptor(*desc);
481 gOutputs.replaceValueFor(ioHandle, outputDesc);
482 } break;
483 case INPUT_OPENED:
484 case INPUT_CLOSED:
485 case INPUT_CONFIG_CHANGED:
486 break;
487
488 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800489}
490
491void AudioSystem::setErrorCallback(audio_error_callback cb) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700492 Mutex::Autolock _l(gLock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800493 gAudioErrorCallback = cb;
494}
495
Glenn Kastenfff6d712012-01-12 16:38:12 -0800496bool AudioSystem::routedToA2dpOutput(audio_stream_type_t streamType) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700497 switch (streamType) {
Dima Zavinfce7a472011-04-19 22:30:36 -0700498 case AUDIO_STREAM_MUSIC:
499 case AUDIO_STREAM_VOICE_CALL:
500 case AUDIO_STREAM_BLUETOOTH_SCO:
501 case AUDIO_STREAM_SYSTEM:
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800502 return true;
503 default:
504 return false;
505 }
506}
507
508
Eric Laurentc2f1f072009-07-17 12:17:14 -0700509// client singleton for AudioPolicyService binder interface
510sp<IAudioPolicyService> AudioSystem::gAudioPolicyService;
511sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient;
512
513
Glenn Kasten18a6d902012-09-24 11:27:56 -0700514// establish binder interface to AudioPolicy service
Eric Laurentc2f1f072009-07-17 12:17:14 -0700515const sp<IAudioPolicyService>& AudioSystem::get_audio_policy_service()
516{
517 gLock.lock();
Glenn Kasten7fc9a6f2012-01-10 10:46:34 -0800518 if (gAudioPolicyService == 0) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700519 sp<IServiceManager> sm = defaultServiceManager();
520 sp<IBinder> binder;
521 do {
522 binder = sm->getService(String16("media.audio_policy"));
523 if (binder != 0)
524 break;
Steve Block5ff1dd52012-01-05 23:22:43 +0000525 ALOGW("AudioPolicyService not published, waiting...");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700526 usleep(500000); // 0.5 s
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700527 } while (true);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700528 if (gAudioPolicyServiceClient == NULL) {
529 gAudioPolicyServiceClient = new AudioPolicyServiceClient();
530 }
531 binder->linkToDeath(gAudioPolicyServiceClient);
532 gAudioPolicyService = interface_cast<IAudioPolicyService>(binder);
533 gLock.unlock();
534 } else {
535 gLock.unlock();
536 }
537 return gAudioPolicyService;
538}
539
Dima Zavinfce7a472011-04-19 22:30:36 -0700540status_t AudioSystem::setDeviceConnectionState(audio_devices_t device,
541 audio_policy_dev_state_t state,
542 const char *device_address)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700543{
544 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurent71b63e32011-09-02 14:20:56 -0700545 const char *address = "";
546
Eric Laurentc2f1f072009-07-17 12:17:14 -0700547 if (aps == 0) return PERMISSION_DENIED;
548
Eric Laurent71b63e32011-09-02 14:20:56 -0700549 if (device_address != NULL) {
550 address = device_address;
551 }
552
553 return aps->setDeviceConnectionState(device, state, address);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700554}
555
Dima Zavinfce7a472011-04-19 22:30:36 -0700556audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700557 const char *device_address)
558{
559 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700560 if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700561
562 return aps->getDeviceConnectionState(device, device_address);
563}
564
Glenn Kastenf78aee72012-01-04 11:00:47 -0800565status_t AudioSystem::setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700566{
Glenn Kasten347966c2012-01-18 14:58:32 -0800567 if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700568 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
569 if (aps == 0) return PERMISSION_DENIED;
570
571 return aps->setPhoneState(state);
572}
573
Dima Zavinfce7a472011-04-19 22:30:36 -0700574status_t AudioSystem::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700575{
576 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
577 if (aps == 0) return PERMISSION_DENIED;
578 return aps->setForceUse(usage, config);
579}
580
Dima Zavinfce7a472011-04-19 22:30:36 -0700581audio_policy_forced_cfg_t AudioSystem::getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700582{
583 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700584 if (aps == 0) return AUDIO_POLICY_FORCE_NONE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700585 return aps->getForceUse(usage);
586}
587
588
Dima Zavinfce7a472011-04-19 22:30:36 -0700589audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700590 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800591 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700592 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000593 audio_output_flags_t flags,
594 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700595{
Eric Laurent1a9ed112012-03-20 18:36:01 -0700596 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
597 if (aps == 0) return 0;
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000598 return aps->getOutput(stream, samplingRate, format, channelMask, flags, offloadInfo);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700599}
600
Eric Laurentde070132010-07-13 04:45:46 -0700601status_t AudioSystem::startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700602 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700603 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700604{
605 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
606 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700607 return aps->startOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700608}
609
Eric Laurentde070132010-07-13 04:45:46 -0700610status_t AudioSystem::stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700611 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700612 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700613{
614 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
615 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700616 return aps->stopOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700617}
618
619void AudioSystem::releaseOutput(audio_io_handle_t output)
620{
621 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
622 if (aps == 0) return;
623 aps->releaseOutput(output);
624}
625
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800626audio_io_handle_t AudioSystem::getInput(audio_source_t inputSource,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700627 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800628 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700629 audio_channel_mask_t channelMask,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700630 int sessionId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700631{
632 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700633 if (aps == 0) return 0;
Glenn Kasten254af182012-07-03 14:59:05 -0700634 return aps->getInput(inputSource, samplingRate, format, channelMask, sessionId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700635}
636
637status_t AudioSystem::startInput(audio_io_handle_t input)
638{
639 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
640 if (aps == 0) return PERMISSION_DENIED;
641 return aps->startInput(input);
642}
643
644status_t AudioSystem::stopInput(audio_io_handle_t input)
645{
646 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
647 if (aps == 0) return PERMISSION_DENIED;
648 return aps->stopInput(input);
649}
650
651void AudioSystem::releaseInput(audio_io_handle_t input)
652{
653 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
654 if (aps == 0) return;
655 aps->releaseInput(input);
656}
657
Dima Zavinfce7a472011-04-19 22:30:36 -0700658status_t AudioSystem::initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700659 int indexMin,
660 int indexMax)
661{
662 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
663 if (aps == 0) return PERMISSION_DENIED;
664 return aps->initStreamVolume(stream, indexMin, indexMax);
665}
666
Eric Laurent83844cc2011-11-18 16:43:31 -0800667status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream,
668 int index,
669 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700670{
671 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
672 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800673 return aps->setStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700674}
675
Eric Laurent83844cc2011-11-18 16:43:31 -0800676status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream,
677 int *index,
678 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700679{
680 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
681 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800682 return aps->getStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700683}
684
Dima Zavinfce7a472011-04-19 22:30:36 -0700685uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700686{
687 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
688 if (aps == 0) return 0;
689 return aps->getStrategyForStream(stream);
690}
691
Eric Laurent63742522012-03-08 13:42:42 -0800692audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800693{
694 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurent63742522012-03-08 13:42:42 -0800695 if (aps == 0) return (audio_devices_t)0;
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800696 return aps->getDevicesForStream(stream);
697}
698
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700699audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700700{
701 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
702 if (aps == 0) return PERMISSION_DENIED;
703 return aps->getOutputForEffect(desc);
704}
705
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700706status_t AudioSystem::registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700707 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700708 uint32_t strategy,
709 int session,
710 int id)
711{
712 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
713 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700714 return aps->registerEffect(desc, io, strategy, session, id);
Eric Laurentde070132010-07-13 04:45:46 -0700715}
716
717status_t AudioSystem::unregisterEffect(int id)
718{
719 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
720 if (aps == 0) return PERMISSION_DENIED;
721 return aps->unregisterEffect(id);
722}
723
Eric Laurentdb7c0792011-08-10 10:37:50 -0700724status_t AudioSystem::setEffectEnabled(int id, bool enabled)
725{
726 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
727 if (aps == 0) return PERMISSION_DENIED;
728 return aps->setEffectEnabled(id, enabled);
729}
730
Glenn Kastenfff6d712012-01-12 16:38:12 -0800731status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs)
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700732{
Eric Laurenteda6c362011-02-02 09:33:30 -0800733 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
734 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700735 if (state == NULL) return BAD_VALUE;
Eric Laurenteda6c362011-02-02 09:33:30 -0800736 *state = aps->isStreamActive(stream, inPastMs);
737 return NO_ERROR;
738}
739
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800740status_t AudioSystem::isStreamActiveRemotely(audio_stream_type_t stream, bool* state,
741 uint32_t inPastMs)
742{
743 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
744 if (aps == 0) return PERMISSION_DENIED;
745 if (state == NULL) return BAD_VALUE;
746 *state = aps->isStreamActiveRemotely(stream, inPastMs);
747 return NO_ERROR;
748}
749
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700750status_t AudioSystem::isSourceActive(audio_source_t stream, bool* state)
751{
752 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
753 if (aps == 0) return PERMISSION_DENIED;
754 if (state == NULL) return BAD_VALUE;
755 *state = aps->isSourceActive(stream);
756 return NO_ERROR;
757}
758
Glenn Kasten3b16c762012-11-14 08:44:39 -0800759uint32_t AudioSystem::getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700760{
761 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
762 if (af == 0) return 0;
763 return af->getPrimaryOutputSamplingRate();
764}
765
Glenn Kastene33054e2012-11-14 12:54:39 -0800766size_t AudioSystem::getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700767{
768 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
769 if (af == 0) return 0;
770 return af->getPrimaryOutputFrameCount();
771}
Eric Laurenteda6c362011-02-02 09:33:30 -0800772
Eric Laurent9f6530f2011-08-30 10:18:54 -0700773void AudioSystem::clearAudioConfigCache()
774{
775 Mutex::Autolock _l(gLock);
Steve Block3856b092011-10-20 11:56:00 +0100776 ALOGV("clearAudioConfigCache()");
Eric Laurent9f6530f2011-08-30 10:18:54 -0700777 gOutputs.clear();
778}
779
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000780bool AudioSystem::isOffloadSupported(const audio_offload_info_t& info)
781{
782 ALOGV("isOffloadSupported()");
783 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
784 if (aps == 0) return false;
785 return aps->isOffloadSupported(info);
786}
787
Eric Laurentc2f1f072009-07-17 12:17:14 -0700788// ---------------------------------------------------------------------------
789
790void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who) {
791 Mutex::Autolock _l(AudioSystem::gLock);
792 AudioSystem::gAudioPolicyService.clear();
793
Steve Block5ff1dd52012-01-05 23:22:43 +0000794 ALOGW("AudioPolicyService server died!");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700795}
796
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800797}; // namespace android