blob: 7ceffd3393b1c6c37fcee9c9b3971eab958c47d0 [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
Glenn Kastenfb1fdc92013-07-10 17:03:19 -0700540// ---------------------------------------------------------------------------
541
Dima Zavinfce7a472011-04-19 22:30:36 -0700542status_t AudioSystem::setDeviceConnectionState(audio_devices_t device,
543 audio_policy_dev_state_t state,
544 const char *device_address)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700545{
546 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurent71b63e32011-09-02 14:20:56 -0700547 const char *address = "";
548
Eric Laurentc2f1f072009-07-17 12:17:14 -0700549 if (aps == 0) return PERMISSION_DENIED;
550
Eric Laurent71b63e32011-09-02 14:20:56 -0700551 if (device_address != NULL) {
552 address = device_address;
553 }
554
555 return aps->setDeviceConnectionState(device, state, address);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700556}
557
Dima Zavinfce7a472011-04-19 22:30:36 -0700558audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700559 const char *device_address)
560{
561 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700562 if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700563
564 return aps->getDeviceConnectionState(device, device_address);
565}
566
Glenn Kastenf78aee72012-01-04 11:00:47 -0800567status_t AudioSystem::setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700568{
Glenn Kasten347966c2012-01-18 14:58:32 -0800569 if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700570 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
571 if (aps == 0) return PERMISSION_DENIED;
572
573 return aps->setPhoneState(state);
574}
575
Dima Zavinfce7a472011-04-19 22:30:36 -0700576status_t AudioSystem::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700577{
578 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
579 if (aps == 0) return PERMISSION_DENIED;
580 return aps->setForceUse(usage, config);
581}
582
Dima Zavinfce7a472011-04-19 22:30:36 -0700583audio_policy_forced_cfg_t AudioSystem::getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700584{
585 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700586 if (aps == 0) return AUDIO_POLICY_FORCE_NONE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700587 return aps->getForceUse(usage);
588}
589
590
Dima Zavinfce7a472011-04-19 22:30:36 -0700591audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700592 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800593 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700594 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000595 audio_output_flags_t flags,
596 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700597{
Eric Laurent1a9ed112012-03-20 18:36:01 -0700598 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
599 if (aps == 0) return 0;
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000600 return aps->getOutput(stream, samplingRate, format, channelMask, flags, offloadInfo);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700601}
602
Eric Laurentde070132010-07-13 04:45:46 -0700603status_t AudioSystem::startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700604 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700605 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700606{
607 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
608 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700609 return aps->startOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700610}
611
Eric Laurentde070132010-07-13 04:45:46 -0700612status_t AudioSystem::stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700613 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700614 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700615{
616 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
617 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700618 return aps->stopOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700619}
620
621void AudioSystem::releaseOutput(audio_io_handle_t output)
622{
623 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
624 if (aps == 0) return;
625 aps->releaseOutput(output);
626}
627
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800628audio_io_handle_t AudioSystem::getInput(audio_source_t inputSource,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700629 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800630 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700631 audio_channel_mask_t channelMask,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700632 int sessionId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700633{
634 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700635 if (aps == 0) return 0;
Glenn Kasten254af182012-07-03 14:59:05 -0700636 return aps->getInput(inputSource, samplingRate, format, channelMask, sessionId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700637}
638
639status_t AudioSystem::startInput(audio_io_handle_t input)
640{
641 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
642 if (aps == 0) return PERMISSION_DENIED;
643 return aps->startInput(input);
644}
645
646status_t AudioSystem::stopInput(audio_io_handle_t input)
647{
648 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
649 if (aps == 0) return PERMISSION_DENIED;
650 return aps->stopInput(input);
651}
652
653void AudioSystem::releaseInput(audio_io_handle_t input)
654{
655 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
656 if (aps == 0) return;
657 aps->releaseInput(input);
658}
659
Dima Zavinfce7a472011-04-19 22:30:36 -0700660status_t AudioSystem::initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700661 int indexMin,
662 int indexMax)
663{
664 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
665 if (aps == 0) return PERMISSION_DENIED;
666 return aps->initStreamVolume(stream, indexMin, indexMax);
667}
668
Eric Laurent83844cc2011-11-18 16:43:31 -0800669status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream,
670 int index,
671 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700672{
673 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
674 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800675 return aps->setStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700676}
677
Eric Laurent83844cc2011-11-18 16:43:31 -0800678status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream,
679 int *index,
680 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700681{
682 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
683 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800684 return aps->getStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700685}
686
Dima Zavinfce7a472011-04-19 22:30:36 -0700687uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700688{
689 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
690 if (aps == 0) return 0;
691 return aps->getStrategyForStream(stream);
692}
693
Eric Laurent63742522012-03-08 13:42:42 -0800694audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800695{
696 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurent63742522012-03-08 13:42:42 -0800697 if (aps == 0) return (audio_devices_t)0;
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800698 return aps->getDevicesForStream(stream);
699}
700
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700701audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700702{
703 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
704 if (aps == 0) return PERMISSION_DENIED;
705 return aps->getOutputForEffect(desc);
706}
707
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700708status_t AudioSystem::registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700709 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700710 uint32_t strategy,
711 int session,
712 int id)
713{
714 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
715 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700716 return aps->registerEffect(desc, io, strategy, session, id);
Eric Laurentde070132010-07-13 04:45:46 -0700717}
718
719status_t AudioSystem::unregisterEffect(int id)
720{
721 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
722 if (aps == 0) return PERMISSION_DENIED;
723 return aps->unregisterEffect(id);
724}
725
Eric Laurentdb7c0792011-08-10 10:37:50 -0700726status_t AudioSystem::setEffectEnabled(int id, bool enabled)
727{
728 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
729 if (aps == 0) return PERMISSION_DENIED;
730 return aps->setEffectEnabled(id, enabled);
731}
732
Glenn Kastenfff6d712012-01-12 16:38:12 -0800733status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs)
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700734{
Eric Laurenteda6c362011-02-02 09:33:30 -0800735 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
736 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700737 if (state == NULL) return BAD_VALUE;
Eric Laurenteda6c362011-02-02 09:33:30 -0800738 *state = aps->isStreamActive(stream, inPastMs);
739 return NO_ERROR;
740}
741
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800742status_t AudioSystem::isStreamActiveRemotely(audio_stream_type_t stream, bool* state,
743 uint32_t inPastMs)
744{
745 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
746 if (aps == 0) return PERMISSION_DENIED;
747 if (state == NULL) return BAD_VALUE;
748 *state = aps->isStreamActiveRemotely(stream, inPastMs);
749 return NO_ERROR;
750}
751
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700752status_t AudioSystem::isSourceActive(audio_source_t stream, bool* state)
753{
754 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
755 if (aps == 0) return PERMISSION_DENIED;
756 if (state == NULL) return BAD_VALUE;
757 *state = aps->isSourceActive(stream);
758 return NO_ERROR;
759}
760
Glenn Kasten3b16c762012-11-14 08:44:39 -0800761uint32_t AudioSystem::getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700762{
763 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
764 if (af == 0) return 0;
765 return af->getPrimaryOutputSamplingRate();
766}
767
Glenn Kastene33054e2012-11-14 12:54:39 -0800768size_t AudioSystem::getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700769{
770 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
771 if (af == 0) return 0;
772 return af->getPrimaryOutputFrameCount();
773}
Eric Laurenteda6c362011-02-02 09:33:30 -0800774
Eric Laurent9f6530f2011-08-30 10:18:54 -0700775void AudioSystem::clearAudioConfigCache()
776{
777 Mutex::Autolock _l(gLock);
Steve Block3856b092011-10-20 11:56:00 +0100778 ALOGV("clearAudioConfigCache()");
Eric Laurent9f6530f2011-08-30 10:18:54 -0700779 gOutputs.clear();
780}
781
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000782bool AudioSystem::isOffloadSupported(const audio_offload_info_t& info)
783{
784 ALOGV("isOffloadSupported()");
785 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
786 if (aps == 0) return false;
787 return aps->isOffloadSupported(info);
788}
789
Eric Laurentc2f1f072009-07-17 12:17:14 -0700790// ---------------------------------------------------------------------------
791
792void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who) {
793 Mutex::Autolock _l(AudioSystem::gLock);
794 AudioSystem::gAudioPolicyService.clear();
795
Steve Block5ff1dd52012-01-05 23:22:43 +0000796 ALOGW("AudioPolicyService server died!");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700797}
798
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800799}; // namespace android