blob: aaf2dddbe5f2ec40c7d32ad61078d864671b898f [file] [log] [blame]
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006-2007 The Android Open Source Project
Mingming Yin84f109b2012-12-27 17:43:05 -08003 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
4 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -08007 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#define LOG_TAG "AudioSystem"
22//#define LOG_NDEBUG 0
23
24#include <utils/Log.h>
Mathias Agopian75624082009-05-19 19:08:10 -070025#include <binder/IServiceManager.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080026#include <media/AudioSystem.h>
Eric Laurentc2f1f072009-07-17 12:17:14 -070027#include <media/IAudioPolicyService.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080028#include <math.h>
29
Dima Zavin64760242011-05-11 14:15:23 -070030#include <system/audio.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070031
Eric Laurentc2f1f072009-07-17 12:17:14 -070032// ----------------------------------------------------------------------------
Eric Laurentc2f1f072009-07-17 12:17:14 -070033
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080034namespace android {
35
36// client singleton for AudioFlinger binder interface
37Mutex AudioSystem::gLock;
38sp<IAudioFlinger> AudioSystem::gAudioFlinger;
39sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient;
40audio_error_callback AudioSystem::gAudioErrorCallback = NULL;
41// Cached values
Glenn Kasten211eeaf2012-01-20 09:37:45 -080042
Eric Laurentc2f1f072009-07-17 12:17:14 -070043DefaultKeyedVector<audio_io_handle_t, AudioSystem::OutputDescriptor *> AudioSystem::gOutputs(0);
44
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -080045// Cached values for recording queries, all protected by gLock
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080046uint32_t AudioSystem::gPrevInSamplingRate = 16000;
Glenn Kasten58f30212012-01-12 12:27:51 -080047audio_format_t AudioSystem::gPrevInFormat = AUDIO_FORMAT_PCM_16_BIT;
Glenn Kastendd8104c2012-07-02 12:42:44 -070048audio_channel_mask_t AudioSystem::gPrevInChannelMask = AUDIO_CHANNEL_IN_MONO;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080049size_t AudioSystem::gInBuffSize = 0;
50
51
52// establish binder interface to AudioFlinger service
53const sp<IAudioFlinger>& AudioSystem::get_audio_flinger()
54{
55 Mutex::Autolock _l(gLock);
Glenn Kasten7fc9a6f2012-01-10 10:46:34 -080056 if (gAudioFlinger == 0) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080057 sp<IServiceManager> sm = defaultServiceManager();
58 sp<IBinder> binder;
59 do {
60 binder = sm->getService(String16("media.audio_flinger"));
61 if (binder != 0)
62 break;
Steve Block5ff1dd52012-01-05 23:22:43 +000063 ALOGW("AudioFlinger not published, waiting...");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080064 usleep(500000); // 0.5 s
Glenn Kastene53b9ea2012-03-12 16:29:55 -070065 } while (true);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080066 if (gAudioFlingerClient == NULL) {
67 gAudioFlingerClient = new AudioFlingerClient();
68 } else {
69 if (gAudioErrorCallback) {
70 gAudioErrorCallback(NO_ERROR);
71 }
Glenn Kastene53b9ea2012-03-12 16:29:55 -070072 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080073 binder->linkToDeath(gAudioFlingerClient);
74 gAudioFlinger = interface_cast<IAudioFlinger>(binder);
75 gAudioFlinger->registerClient(gAudioFlingerClient);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080076 }
Steve Block29357bc2012-01-06 19:20:56 +000077 ALOGE_IF(gAudioFlinger==0, "no AudioFlinger!?");
Eric Laurentc2f1f072009-07-17 12:17:14 -070078
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080079 return gAudioFlinger;
80}
81
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080082status_t AudioSystem::muteMicrophone(bool state) {
83 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
84 if (af == 0) return PERMISSION_DENIED;
85 return af->setMicMute(state);
86}
87
88status_t AudioSystem::isMicrophoneMuted(bool* state) {
89 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
90 if (af == 0) return PERMISSION_DENIED;
91 *state = af->getMicMute();
92 return NO_ERROR;
93}
94
95status_t AudioSystem::setMasterVolume(float value)
96{
97 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
98 if (af == 0) return PERMISSION_DENIED;
99 af->setMasterVolume(value);
100 return NO_ERROR;
101}
102
103status_t AudioSystem::setMasterMute(bool mute)
104{
105 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
106 if (af == 0) return PERMISSION_DENIED;
107 af->setMasterMute(mute);
108 return NO_ERROR;
109}
110
111status_t AudioSystem::getMasterVolume(float* volume)
112{
113 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
114 if (af == 0) return PERMISSION_DENIED;
115 *volume = af->masterVolume();
116 return NO_ERROR;
117}
118
119status_t AudioSystem::getMasterMute(bool* mute)
120{
121 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
122 if (af == 0) return PERMISSION_DENIED;
123 *mute = af->masterMute();
124 return NO_ERROR;
125}
126
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800127status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value,
128 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800129{
Dima Zavinfce7a472011-04-19 22:30:36 -0700130 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800131 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
132 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700133 af->setStreamVolume(stream, value, output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800134 return NO_ERROR;
135}
136
Glenn Kastenfff6d712012-01-12 16:38:12 -0800137status_t AudioSystem::setStreamMute(audio_stream_type_t stream, bool mute)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800138{
Dima Zavinfce7a472011-04-19 22:30:36 -0700139 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800140 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
141 if (af == 0) return PERMISSION_DENIED;
142 af->setStreamMute(stream, mute);
143 return NO_ERROR;
144}
145
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800146status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume,
147 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800148{
Dima Zavinfce7a472011-04-19 22:30:36 -0700149 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800150 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
151 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700152 *volume = af->streamVolume(stream, output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800153 return NO_ERROR;
154}
155
Glenn Kastenfff6d712012-01-12 16:38:12 -0800156status_t AudioSystem::getStreamMute(audio_stream_type_t stream, bool* mute)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800157{
Dima Zavinfce7a472011-04-19 22:30:36 -0700158 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800159 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
160 if (af == 0) return PERMISSION_DENIED;
161 *mute = af->streamMute(stream);
162 return NO_ERROR;
163}
164
Glenn Kastenf78aee72012-01-04 11:00:47 -0800165status_t AudioSystem::setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800166{
Glenn Kasten930f4ca2012-01-06 16:47:31 -0800167 if (uint32_t(mode) >= AUDIO_MODE_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800168 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
169 if (af == 0) return PERMISSION_DENIED;
170 return af->setMode(mode);
171}
172
Eric Laurentc2f1f072009-07-17 12:17:14 -0700173status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800174 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
175 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700176 return af->setParameters(ioHandle, keyValuePairs);
177}
178
179String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys) {
180 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
181 String8 result = String8("");
182 if (af == 0) return result;
183
184 result = af->getParameters(ioHandle, keys);
185 return result;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800186}
187
188// convert volume steps to natural log scale
189
190// change this value to change volume scaling
191static const float dBPerStep = 0.5f;
192// shouldn't need to touch these
193static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f;
194static const float dBConvertInverse = 1.0f / dBConvert;
195
196float AudioSystem::linearToLog(int volume)
197{
198 // float v = volume ? exp(float(100 - volume) * dBConvert) : 0;
Steve Blockb8a80522011-12-20 16:23:08 +0000199 // ALOGD("linearToLog(%d)=%f", volume, v);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800200 // return v;
201 return volume ? exp(float(100 - volume) * dBConvert) : 0;
202}
203
204int AudioSystem::logToLinear(float volume)
205{
206 // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
Steve Blockb8a80522011-12-20 16:23:08 +0000207 // ALOGD("logTolinear(%d)=%f", v, volume);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800208 // return v;
209 return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
210}
211
Andreas Huberc8139852012-01-18 10:51:55 -0800212// DEPRECATED
213status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType) {
214 return getOutputSamplingRate(samplingRate, (audio_stream_type_t)streamType);
215}
216
Glenn Kastenfff6d712012-01-12 16:38:12 -0800217status_t AudioSystem::getOutputSamplingRate(int* samplingRate, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800218{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700219 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800220
Dima Zavinfce7a472011-04-19 22:30:36 -0700221 if (streamType == AUDIO_STREAM_DEFAULT) {
222 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700223 }
224
Glenn Kastenfff6d712012-01-12 16:38:12 -0800225 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700226 if (output == 0) {
227 return PERMISSION_DENIED;
228 }
229
Eric Laurent1a9ed112012-03-20 18:36:01 -0700230 return getSamplingRate(output, streamType, samplingRate);
231}
232
233status_t AudioSystem::getSamplingRate(audio_io_handle_t output,
234 audio_stream_type_t streamType,
235 int* samplingRate)
236{
237 OutputDescriptor *outputDesc;
238
Eric Laurentc2f1f072009-07-17 12:17:14 -0700239 gLock.lock();
240 outputDesc = AudioSystem::gOutputs.valueFor(output);
Glenn Kastena0d68332012-01-27 16:47:15 -0800241 if (outputDesc == NULL) {
Steve Block3856b092011-10-20 11:56:00 +0100242 ALOGV("getOutputSamplingRate() no output descriptor for output %d in gOutputs", output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700243 gLock.unlock();
244 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
245 if (af == 0) return PERMISSION_DENIED;
246 *samplingRate = af->sampleRate(output);
247 } else {
Steve Block3856b092011-10-20 11:56:00 +0100248 ALOGV("getOutputSamplingRate() reading from output desc");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700249 *samplingRate = outputDesc->samplingRate;
250 gLock.unlock();
251 }
252
Eric Laurent1a9ed112012-03-20 18:36:01 -0700253 ALOGV("getSamplingRate() streamType %d, output %d, sampling rate %d", streamType, output, *samplingRate);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700254
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800255 return NO_ERROR;
256}
257
Andreas Huberc8139852012-01-18 10:51:55 -0800258// DEPRECATED
259status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType) {
260 return getOutputFrameCount(frameCount, (audio_stream_type_t)streamType);
261}
262
Glenn Kastenfff6d712012-01-12 16:38:12 -0800263status_t AudioSystem::getOutputFrameCount(int* frameCount, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800264{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700265 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800266
Dima Zavinfce7a472011-04-19 22:30:36 -0700267 if (streamType == AUDIO_STREAM_DEFAULT) {
268 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700269 }
Eric Laurent48f7f5e2009-04-02 09:32:43 -0700270
Glenn Kastenfff6d712012-01-12 16:38:12 -0800271 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700272 if (output == 0) {
273 return PERMISSION_DENIED;
274 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800275
Eric Laurent1a9ed112012-03-20 18:36:01 -0700276 return getFrameCount(output, streamType, frameCount);
277}
278
279status_t AudioSystem::getFrameCount(audio_io_handle_t output,
280 audio_stream_type_t streamType,
281 int* frameCount)
282{
283 OutputDescriptor *outputDesc;
284
Eric Laurentc2f1f072009-07-17 12:17:14 -0700285 gLock.lock();
286 outputDesc = AudioSystem::gOutputs.valueFor(output);
Glenn Kastena0d68332012-01-27 16:47:15 -0800287 if (outputDesc == NULL) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700288 gLock.unlock();
289 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
290 if (af == 0) return PERMISSION_DENIED;
291 *frameCount = af->frameCount(output);
292 } else {
293 *frameCount = outputDesc->frameCount;
294 gLock.unlock();
295 }
296
Eric Laurent1a9ed112012-03-20 18:36:01 -0700297 ALOGV("getFrameCount() streamType %d, output %d, frameCount %d", streamType, output, *frameCount);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700298
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800299 return NO_ERROR;
300}
301
Glenn Kastenfff6d712012-01-12 16:38:12 -0800302status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800303{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700304 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800305
Dima Zavinfce7a472011-04-19 22:30:36 -0700306 if (streamType == AUDIO_STREAM_DEFAULT) {
307 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700308 }
Eric Laurent48f7f5e2009-04-02 09:32:43 -0700309
Glenn Kastenfff6d712012-01-12 16:38:12 -0800310 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700311 if (output == 0) {
312 return PERMISSION_DENIED;
313 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800314
Eric Laurent1a9ed112012-03-20 18:36:01 -0700315 return getLatency(output, streamType, latency);
316}
317
318status_t AudioSystem::getLatency(audio_io_handle_t output,
319 audio_stream_type_t streamType,
320 uint32_t* latency)
321{
322 OutputDescriptor *outputDesc;
323
Eric Laurentc2f1f072009-07-17 12:17:14 -0700324 gLock.lock();
325 outputDesc = AudioSystem::gOutputs.valueFor(output);
Glenn Kastena0d68332012-01-27 16:47:15 -0800326 if (outputDesc == NULL) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700327 gLock.unlock();
328 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
329 if (af == 0) return PERMISSION_DENIED;
330 *latency = af->latency(output);
331 } else {
332 *latency = outputDesc->latency;
333 gLock.unlock();
334 }
335
Eric Laurent1a9ed112012-03-20 18:36:01 -0700336 ALOGV("getLatency() streamType %d, output %d, latency %d", streamType, output, *latency);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700337
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800338 return NO_ERROR;
339}
340
Glenn Kastendd8104c2012-07-02 12:42:44 -0700341status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format,
342 audio_channel_mask_t channelMask, size_t* buffSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800343{
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800344 gLock.lock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800345 // Do we have a stale gInBufferSize or are we requesting the input buffer size for new values
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800346 size_t inBuffSize = gInBuffSize;
347 if ((inBuffSize == 0) || (sampleRate != gPrevInSamplingRate) || (format != gPrevInFormat)
Glenn Kastendd8104c2012-07-02 12:42:44 -0700348 || (channelMask != gPrevInChannelMask)) {
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800349 gLock.unlock();
350 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
351 if (af == 0) {
352 return PERMISSION_DENIED;
353 }
Glenn Kastendd8104c2012-07-02 12:42:44 -0700354 inBuffSize = af->getInputBufferSize(sampleRate, format, channelMask);
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800355 gLock.lock();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800356 // save the request params
357 gPrevInSamplingRate = sampleRate;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700358 gPrevInFormat = format;
Glenn Kastendd8104c2012-07-02 12:42:44 -0700359 gPrevInChannelMask = channelMask;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800360
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800361 gInBuffSize = inBuffSize;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700362 }
Glenn Kastenf8c1a6f2012-01-10 09:01:19 -0800363 gLock.unlock();
364 *buffSize = inBuffSize;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700365
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800366 return NO_ERROR;
367}
368
Eric Laurentf0ee6f42009-10-21 08:14:22 -0700369status_t AudioSystem::setVoiceVolume(float value)
370{
371 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
372 if (af == 0) return PERMISSION_DENIED;
373 return af->setVoiceVolume(value);
374}
375
Glenn Kastenfff6d712012-01-12 16:38:12 -0800376status_t AudioSystem::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, audio_stream_type_t stream)
Eric Laurent342e9cf2010-01-19 17:37:09 -0800377{
378 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
379 if (af == 0) return PERMISSION_DENIED;
380
Dima Zavinfce7a472011-04-19 22:30:36 -0700381 if (stream == AUDIO_STREAM_DEFAULT) {
382 stream = AUDIO_STREAM_MUSIC;
Eric Laurent342e9cf2010-01-19 17:37:09 -0800383 }
384
Glenn Kastenfff6d712012-01-12 16:38:12 -0800385 return af->getRenderPosition(halFrames, dspFrames, getOutput(stream));
Eric Laurent342e9cf2010-01-19 17:37:09 -0800386}
387
Eric Laurent05bca2f2010-02-26 02:47:27 -0800388unsigned int AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) {
389 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
390 unsigned int result = 0;
391 if (af == 0) return result;
Eric Laurentbe55a2d2010-03-11 14:47:00 -0800392 if (ioHandle == 0) return result;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800393
394 result = af->getInputFramesLost(ioHandle);
395 return result;
396}
397
Eric Laurentbe916aa2010-06-01 23:49:17 -0700398int AudioSystem::newAudioSessionId() {
399 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
400 if (af == 0) return 0;
401 return af->newAudioSessionId();
402}
403
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700404void AudioSystem::acquireAudioSessionId(int audioSession) {
405 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
406 if (af != 0) {
407 af->acquireAudioSessionId(audioSession);
408 }
409}
410
411void AudioSystem::releaseAudioSessionId(int audioSession) {
412 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
413 if (af != 0) {
414 af->releaseAudioSessionId(audioSession);
415 }
416}
417
Mingming Yin84f109b2012-12-27 17:43:05 -0800418#ifdef QCOM_FM_ENABLED
419status_t AudioSystem::setFmVolume(float value)
420{
421 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
422 if (af == 0) return PERMISSION_DENIED;
423 return af->setFmVolume(value);
424}
425#endif
426
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800427// ---------------------------------------------------------------------------
428
Eric Laurentc2f1f072009-07-17 12:17:14 -0700429void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who) {
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800430 Mutex::Autolock _l(AudioSystem::gLock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800431
Eric Laurentc2f1f072009-07-17 12:17:14 -0700432 AudioSystem::gAudioFlinger.clear();
Eric Laurent0ef583f2010-01-25 10:27:15 -0800433 // clear output handles and stream to output map caches
Eric Laurent0ef583f2010-01-25 10:27:15 -0800434 AudioSystem::gOutputs.clear();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800435
436 if (gAudioErrorCallback) {
437 gAudioErrorCallback(DEAD_OBJECT);
438 }
Steve Block5ff1dd52012-01-05 23:22:43 +0000439 ALOGW("AudioFlinger server died!");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800440}
441
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800442void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, audio_io_handle_t ioHandle,
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800443 const void *param2) {
Steve Block3856b092011-10-20 11:56:00 +0100444 ALOGV("ioConfigChanged() event %d", event);
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800445 const OutputDescriptor *desc;
Glenn Kasten211eeaf2012-01-20 09:37:45 -0800446 audio_stream_type_t stream;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700447
Eric Laurentfa2877b2009-07-28 08:44:33 -0700448 if (ioHandle == 0) return;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700449
450 Mutex::Autolock _l(AudioSystem::gLock);
451
452 switch (event) {
453 case STREAM_CONFIG_CHANGED:
Eric Laurentc2f1f072009-07-17 12:17:14 -0700454 break;
455 case OUTPUT_OPENED: {
456 if (gOutputs.indexOfKey(ioHandle) >= 0) {
Steve Block3856b092011-10-20 11:56:00 +0100457 ALOGV("ioConfigChanged() opening already existing output! %d", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700458 break;
459 }
Glenn Kastena0d68332012-01-27 16:47:15 -0800460 if (param2 == NULL) break;
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800461 desc = (const OutputDescriptor *)param2;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700462
463 OutputDescriptor *outputDesc = new OutputDescriptor(*desc);
464 gOutputs.add(ioHandle, outputDesc);
Glenn Kasten254af182012-07-03 14:59:05 -0700465 ALOGV("ioConfigChanged() new output samplingRate %d, format %d channels %#x frameCount %d latency %d",
Eric Laurentc2f1f072009-07-17 12:17:14 -0700466 outputDesc->samplingRate, outputDesc->format, outputDesc->channels, outputDesc->frameCount, outputDesc->latency);
467 } break;
468 case OUTPUT_CLOSED: {
469 if (gOutputs.indexOfKey(ioHandle) < 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000470 ALOGW("ioConfigChanged() closing unknow output! %d", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700471 break;
472 }
Steve Block3856b092011-10-20 11:56:00 +0100473 ALOGV("ioConfigChanged() output %d closed", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700474
475 gOutputs.removeItem(ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700476 } break;
477
478 case OUTPUT_CONFIG_CHANGED: {
479 int index = gOutputs.indexOfKey(ioHandle);
480 if (index < 0) {
Steve Block5ff1dd52012-01-05 23:22:43 +0000481 ALOGW("ioConfigChanged() modifying unknow output! %d", ioHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700482 break;
483 }
Glenn Kastena0d68332012-01-27 16:47:15 -0800484 if (param2 == NULL) break;
Glenn Kastenb81cc8c2012-03-01 09:14:51 -0800485 desc = (const OutputDescriptor *)param2;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700486
Glenn Kasten254af182012-07-03 14:59:05 -0700487 ALOGV("ioConfigChanged() new config for output %d samplingRate %d, format %d channels %#x frameCount %d latency %d",
Eric Laurentc2f1f072009-07-17 12:17:14 -0700488 ioHandle, desc->samplingRate, desc->format,
489 desc->channels, desc->frameCount, desc->latency);
490 OutputDescriptor *outputDesc = gOutputs.valueAt(index);
491 delete outputDesc;
492 outputDesc = new OutputDescriptor(*desc);
493 gOutputs.replaceValueFor(ioHandle, outputDesc);
494 } break;
495 case INPUT_OPENED:
496 case INPUT_CLOSED:
497 case INPUT_CONFIG_CHANGED:
498 break;
499
500 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800501}
502
503void AudioSystem::setErrorCallback(audio_error_callback cb) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700504 Mutex::Autolock _l(gLock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800505 gAudioErrorCallback = cb;
506}
507
Glenn Kastenfff6d712012-01-12 16:38:12 -0800508bool AudioSystem::routedToA2dpOutput(audio_stream_type_t streamType) {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700509 switch (streamType) {
Dima Zavinfce7a472011-04-19 22:30:36 -0700510 case AUDIO_STREAM_MUSIC:
511 case AUDIO_STREAM_VOICE_CALL:
512 case AUDIO_STREAM_BLUETOOTH_SCO:
513 case AUDIO_STREAM_SYSTEM:
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800514 return true;
515 default:
516 return false;
517 }
518}
519
520
Eric Laurentc2f1f072009-07-17 12:17:14 -0700521// client singleton for AudioPolicyService binder interface
522sp<IAudioPolicyService> AudioSystem::gAudioPolicyService;
523sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient;
524
525
526// establish binder interface to AudioFlinger service
527const sp<IAudioPolicyService>& AudioSystem::get_audio_policy_service()
528{
529 gLock.lock();
Glenn Kasten7fc9a6f2012-01-10 10:46:34 -0800530 if (gAudioPolicyService == 0) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700531 sp<IServiceManager> sm = defaultServiceManager();
532 sp<IBinder> binder;
533 do {
534 binder = sm->getService(String16("media.audio_policy"));
535 if (binder != 0)
536 break;
Steve Block5ff1dd52012-01-05 23:22:43 +0000537 ALOGW("AudioPolicyService not published, waiting...");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700538 usleep(500000); // 0.5 s
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700539 } while (true);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700540 if (gAudioPolicyServiceClient == NULL) {
541 gAudioPolicyServiceClient = new AudioPolicyServiceClient();
542 }
543 binder->linkToDeath(gAudioPolicyServiceClient);
544 gAudioPolicyService = interface_cast<IAudioPolicyService>(binder);
545 gLock.unlock();
546 } else {
547 gLock.unlock();
548 }
549 return gAudioPolicyService;
550}
551
Dima Zavinfce7a472011-04-19 22:30:36 -0700552status_t AudioSystem::setDeviceConnectionState(audio_devices_t device,
553 audio_policy_dev_state_t state,
554 const char *device_address)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700555{
556 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurent71b63e32011-09-02 14:20:56 -0700557 const char *address = "";
558
Eric Laurentc2f1f072009-07-17 12:17:14 -0700559 if (aps == 0) return PERMISSION_DENIED;
560
Eric Laurent71b63e32011-09-02 14:20:56 -0700561 if (device_address != NULL) {
562 address = device_address;
563 }
564
565 return aps->setDeviceConnectionState(device, state, address);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700566}
567
Dima Zavinfce7a472011-04-19 22:30:36 -0700568audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700569 const char *device_address)
570{
571 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700572 if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700573
574 return aps->getDeviceConnectionState(device, device_address);
575}
576
Hashcode0ee5c422012-11-30 00:28:40 -0800577extern "C" audio_policy_dev_state_t _ZN7android11AudioSystem24getDeviceConnectionStateE15audio_devices_tPKc(audio_devices_t device,
578 const char *device_address)
579{
580 return AudioSystem::getDeviceConnectionState(device, device_address);
581}
582
Glenn Kastenf78aee72012-01-04 11:00:47 -0800583status_t AudioSystem::setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700584{
Glenn Kasten347966c2012-01-18 14:58:32 -0800585 if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700586 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
587 if (aps == 0) return PERMISSION_DENIED;
588
589 return aps->setPhoneState(state);
590}
591
Dima Zavinfce7a472011-04-19 22:30:36 -0700592status_t AudioSystem::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700593{
594 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
595 if (aps == 0) return PERMISSION_DENIED;
596 return aps->setForceUse(usage, config);
597}
598
Dima Zavinfce7a472011-04-19 22:30:36 -0700599audio_policy_forced_cfg_t AudioSystem::getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700600{
601 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700602 if (aps == 0) return AUDIO_POLICY_FORCE_NONE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700603 return aps->getForceUse(usage);
604}
605
606
Dima Zavinfce7a472011-04-19 22:30:36 -0700607audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700608 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800609 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700610 audio_channel_mask_t channelMask,
Eric Laurent0ca3cf92012-04-18 09:24:29 -0700611 audio_output_flags_t flags)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700612{
Eric Laurent1a9ed112012-03-20 18:36:01 -0700613 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
614 if (aps == 0) return 0;
Glenn Kasten254af182012-07-03 14:59:05 -0700615 return aps->getOutput(stream, samplingRate, format, channelMask, flags);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700616}
617
Ricardo Cerqueira22fe2e02012-07-12 01:36:11 +0100618extern "C" audio_io_handle_t _ZN7android11AudioSystem9getOutputE19audio_stream_type_tjjj27audio_policy_output_flags_t(audio_stream_type_t stream,
619 uint32_t samplingRate,
620 uint32_t format,
621 uint32_t channels,
622 audio_output_flags_t flags) {
623 return AudioSystem::getOutput(stream,samplingRate,(audio_format_t) format, channels, flags);
624}
625
Eric Laurentde070132010-07-13 04:45:46 -0700626status_t AudioSystem::startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700627 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700628 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700629{
630 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
631 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700632 return aps->startOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700633}
634
Eric Laurentde070132010-07-13 04:45:46 -0700635status_t AudioSystem::stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700636 audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700637 int session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700638{
639 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
640 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700641 return aps->stopOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700642}
643
644void AudioSystem::releaseOutput(audio_io_handle_t output)
645{
646 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
647 if (aps == 0) return;
648 aps->releaseOutput(output);
649}
650
Glenn Kasteneba51fb2012-01-23 13:58:49 -0800651audio_io_handle_t AudioSystem::getInput(audio_source_t inputSource,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700652 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800653 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700654 audio_channel_mask_t channelMask,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700655 int sessionId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700656{
657 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurentfa2877b2009-07-28 08:44:33 -0700658 if (aps == 0) return 0;
Glenn Kasten254af182012-07-03 14:59:05 -0700659 return aps->getInput(inputSource, samplingRate, format, channelMask, sessionId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700660}
661
662status_t AudioSystem::startInput(audio_io_handle_t input)
663{
664 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
665 if (aps == 0) return PERMISSION_DENIED;
666 return aps->startInput(input);
667}
668
669status_t AudioSystem::stopInput(audio_io_handle_t input)
670{
671 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
672 if (aps == 0) return PERMISSION_DENIED;
673 return aps->stopInput(input);
674}
675
676void AudioSystem::releaseInput(audio_io_handle_t input)
677{
678 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
679 if (aps == 0) return;
680 aps->releaseInput(input);
681}
682
Dima Zavinfce7a472011-04-19 22:30:36 -0700683status_t AudioSystem::initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700684 int indexMin,
685 int indexMax)
686{
687 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
688 if (aps == 0) return PERMISSION_DENIED;
689 return aps->initStreamVolume(stream, indexMin, indexMax);
690}
691
Eric Laurent83844cc2011-11-18 16:43:31 -0800692status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream,
693 int index,
694 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700695{
696 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
697 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800698 return aps->setStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700699}
700
Eric Laurent83844cc2011-11-18 16:43:31 -0800701status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream,
702 int *index,
703 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700704{
705 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
706 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800707 return aps->getStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700708}
709
Dima Zavinfce7a472011-04-19 22:30:36 -0700710uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700711{
712 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
713 if (aps == 0) return 0;
714 return aps->getStrategyForStream(stream);
715}
716
Eric Laurent63742522012-03-08 13:42:42 -0800717audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800718{
719 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurent63742522012-03-08 13:42:42 -0800720 if (aps == 0) return (audio_devices_t)0;
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800721 return aps->getDevicesForStream(stream);
722}
723
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700724audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700725{
726 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
727 if (aps == 0) return PERMISSION_DENIED;
728 return aps->getOutputForEffect(desc);
729}
730
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700731status_t AudioSystem::registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700732 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700733 uint32_t strategy,
734 int session,
735 int id)
736{
737 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
738 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700739 return aps->registerEffect(desc, io, strategy, session, id);
Eric Laurentde070132010-07-13 04:45:46 -0700740}
741
742status_t AudioSystem::unregisterEffect(int id)
743{
744 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
745 if (aps == 0) return PERMISSION_DENIED;
746 return aps->unregisterEffect(id);
747}
748
Eric Laurentdb7c0792011-08-10 10:37:50 -0700749status_t AudioSystem::setEffectEnabled(int id, bool enabled)
750{
751 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
752 if (aps == 0) return PERMISSION_DENIED;
753 return aps->setEffectEnabled(id, enabled);
754}
755
Glenn Kastenfff6d712012-01-12 16:38:12 -0800756status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs)
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700757{
Eric Laurenteda6c362011-02-02 09:33:30 -0800758 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
759 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700760 if (state == NULL) return BAD_VALUE;
Eric Laurenteda6c362011-02-02 09:33:30 -0800761 *state = aps->isStreamActive(stream, inPastMs);
762 return NO_ERROR;
763}
764
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700765status_t AudioSystem::isSourceActive(audio_source_t stream, bool* state)
766{
767 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
768 if (aps == 0) return PERMISSION_DENIED;
769 if (state == NULL) return BAD_VALUE;
770 *state = aps->isSourceActive(stream);
771 return NO_ERROR;
772}
773
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700774int32_t AudioSystem::getPrimaryOutputSamplingRate()
775{
776 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
777 if (af == 0) return 0;
778 return af->getPrimaryOutputSamplingRate();
779}
780
781int32_t AudioSystem::getPrimaryOutputFrameCount()
782{
783 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
784 if (af == 0) return 0;
785 return af->getPrimaryOutputFrameCount();
786}
Eric Laurenteda6c362011-02-02 09:33:30 -0800787
Eric Laurent9f6530f2011-08-30 10:18:54 -0700788void AudioSystem::clearAudioConfigCache()
789{
790 Mutex::Autolock _l(gLock);
Steve Block3856b092011-10-20 11:56:00 +0100791 ALOGV("clearAudioConfigCache()");
Eric Laurent9f6530f2011-08-30 10:18:54 -0700792 gOutputs.clear();
793}
794
Eric Laurentc2f1f072009-07-17 12:17:14 -0700795// ---------------------------------------------------------------------------
796
797void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who) {
798 Mutex::Autolock _l(AudioSystem::gLock);
799 AudioSystem::gAudioPolicyService.clear();
800
Steve Block5ff1dd52012-01-05 23:22:43 +0000801 ALOGW("AudioPolicyService server died!");
Eric Laurentc2f1f072009-07-17 12:17:14 -0700802}
803
codeworkx0e69fea2013-01-14 20:43:57 +0000804#ifdef USE_SAMSUNG_SEPARATEDSTREAM
805extern "C" bool _ZN7android11AudioSystem17isSeparatedStreamE19audio_stream_type_t(audio_stream_type_t stream)
806{
807 ALOGD("audio_stream_type_t: %d", stream);
808 ALOGD("isSeparatedStream: false");
809 return false;
810}
811#endif // USE_SAMSUNG_SEPARATEDSTREAM
812
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800813}; // namespace android