blob: 4c2e77bb8ee0b529359ab589fa0aaa08eb6b01dd [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;
Glenn Kastend2d089f2014-11-05 11:48:12 -080035Mutex AudioSystem::gLockAPS;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080036sp<IAudioFlinger> AudioSystem::gAudioFlinger;
37sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient;
38audio_error_callback AudioSystem::gAudioErrorCallback = NULL;
Jean-Michel Trivif613d422015-04-23 18:41:29 -070039dynamic_policy_callback AudioSystem::gDynPolicyCallback = NULL;
Glenn Kasten211eeaf2012-01-20 09:37:45 -080040
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080041
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080042// establish binder interface to AudioFlinger service
Eric Laurent0ebd5f92014-11-19 19:04:52 -080043const sp<IAudioFlinger> AudioSystem::get_audio_flinger()
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080044{
Eric Laurent0ebd5f92014-11-19 19:04:52 -080045 sp<IAudioFlinger> af;
46 sp<AudioFlingerClient> afc;
47 {
48 Mutex::Autolock _l(gLock);
49 if (gAudioFlinger == 0) {
50 sp<IServiceManager> sm = defaultServiceManager();
51 sp<IBinder> binder;
52 do {
53 binder = sm->getService(String16("media.audio_flinger"));
54 if (binder != 0)
55 break;
56 ALOGW("AudioFlinger not published, waiting...");
57 usleep(500000); // 0.5 s
58 } while (true);
59 if (gAudioFlingerClient == NULL) {
60 gAudioFlingerClient = new AudioFlingerClient();
61 } else {
62 if (gAudioErrorCallback) {
63 gAudioErrorCallback(NO_ERROR);
64 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080065 }
Eric Laurent0ebd5f92014-11-19 19:04:52 -080066 binder->linkToDeath(gAudioFlingerClient);
67 gAudioFlinger = interface_cast<IAudioFlinger>(binder);
68 LOG_ALWAYS_FATAL_IF(gAudioFlinger == 0);
69 afc = gAudioFlingerClient;
Glenn Kastene53b9ea2012-03-12 16:29:55 -070070 }
Eric Laurent0ebd5f92014-11-19 19:04:52 -080071 af = gAudioFlinger;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080072 }
Eric Laurent0ebd5f92014-11-19 19:04:52 -080073 if (afc != 0) {
74 af->registerClient(afc);
75 }
76 return af;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080077}
78
Eric Laurent296fb132015-05-01 11:38:42 -070079const sp<AudioSystem::AudioFlingerClient> AudioSystem::getAudioFlingerClient()
80{
81 // calling get_audio_flinger() will initialize gAudioFlingerClient if needed
82 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
83 if (af == 0) return 0;
84 Mutex::Autolock _l(gLock);
85 return gAudioFlingerClient;
86}
87
88sp<AudioIoDescriptor> AudioSystem::getIoDescriptor(audio_io_handle_t ioHandle)
89{
90 sp<AudioIoDescriptor> desc;
91 const sp<AudioFlingerClient> afc = getAudioFlingerClient();
92 if (afc != 0) {
93 desc = afc->getIoDescriptor(ioHandle);
94 }
95 return desc;
96}
97
Eric Laurent46291612013-07-18 14:38:44 -070098/* static */ status_t AudioSystem::checkAudioFlinger()
99{
100 if (defaultServiceManager()->checkService(String16("media.audio_flinger")) != 0) {
101 return NO_ERROR;
102 }
103 return DEAD_OBJECT;
104}
105
Glenn Kasten4944acb2013-08-19 08:39:20 -0700106status_t AudioSystem::muteMicrophone(bool state)
107{
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800108 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
109 if (af == 0) return PERMISSION_DENIED;
110 return af->setMicMute(state);
111}
112
Glenn Kasten4944acb2013-08-19 08:39:20 -0700113status_t AudioSystem::isMicrophoneMuted(bool* state)
114{
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800115 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
116 if (af == 0) return PERMISSION_DENIED;
117 *state = af->getMicMute();
118 return NO_ERROR;
119}
120
121status_t AudioSystem::setMasterVolume(float value)
122{
123 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
124 if (af == 0) return PERMISSION_DENIED;
125 af->setMasterVolume(value);
126 return NO_ERROR;
127}
128
129status_t AudioSystem::setMasterMute(bool mute)
130{
131 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
132 if (af == 0) return PERMISSION_DENIED;
133 af->setMasterMute(mute);
134 return NO_ERROR;
135}
136
137status_t AudioSystem::getMasterVolume(float* volume)
138{
139 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
140 if (af == 0) return PERMISSION_DENIED;
141 *volume = af->masterVolume();
142 return NO_ERROR;
143}
144
145status_t AudioSystem::getMasterMute(bool* mute)
146{
147 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
148 if (af == 0) return PERMISSION_DENIED;
149 *mute = af->masterMute();
150 return NO_ERROR;
151}
152
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800153status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value,
154 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800155{
Dima Zavinfce7a472011-04-19 22:30:36 -0700156 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800157 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
158 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700159 af->setStreamVolume(stream, value, output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800160 return NO_ERROR;
161}
162
Glenn Kastenfff6d712012-01-12 16:38:12 -0800163status_t AudioSystem::setStreamMute(audio_stream_type_t stream, bool mute)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800164{
Dima Zavinfce7a472011-04-19 22:30:36 -0700165 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800166 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
167 if (af == 0) return PERMISSION_DENIED;
168 af->setStreamMute(stream, mute);
169 return NO_ERROR;
170}
171
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800172status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume,
173 audio_io_handle_t output)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800174{
Dima Zavinfce7a472011-04-19 22:30:36 -0700175 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800176 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
177 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700178 *volume = af->streamVolume(stream, output);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800179 return NO_ERROR;
180}
181
Glenn Kastenfff6d712012-01-12 16:38:12 -0800182status_t AudioSystem::getStreamMute(audio_stream_type_t stream, bool* mute)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800183{
Dima Zavinfce7a472011-04-19 22:30:36 -0700184 if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800185 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
186 if (af == 0) return PERMISSION_DENIED;
187 *mute = af->streamMute(stream);
188 return NO_ERROR;
189}
190
Glenn Kastenf78aee72012-01-04 11:00:47 -0800191status_t AudioSystem::setMode(audio_mode_t mode)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800192{
Glenn Kasten930f4ca2012-01-06 16:47:31 -0800193 if (uint32_t(mode) >= AUDIO_MODE_CNT) return BAD_VALUE;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800194 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
195 if (af == 0) return PERMISSION_DENIED;
196 return af->setMode(mode);
197}
198
Glenn Kasten4944acb2013-08-19 08:39:20 -0700199status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs)
200{
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800201 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
202 if (af == 0) return PERMISSION_DENIED;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700203 return af->setParameters(ioHandle, keyValuePairs);
204}
205
Glenn Kasten4944acb2013-08-19 08:39:20 -0700206String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys)
207{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700208 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
209 String8 result = String8("");
210 if (af == 0) return result;
211
212 result = af->getParameters(ioHandle, keys);
213 return result;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800214}
215
Glenn Kastenc23885e2013-12-19 16:35:18 -0800216status_t AudioSystem::setParameters(const String8& keyValuePairs)
217{
Glenn Kasten142f5192014-03-25 17:44:59 -0700218 return setParameters(AUDIO_IO_HANDLE_NONE, keyValuePairs);
Glenn Kastenc23885e2013-12-19 16:35:18 -0800219}
220
221String8 AudioSystem::getParameters(const String8& keys)
222{
Glenn Kasten142f5192014-03-25 17:44:59 -0700223 return getParameters(AUDIO_IO_HANDLE_NONE, keys);
Glenn Kastenc23885e2013-12-19 16:35:18 -0800224}
225
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800226// convert volume steps to natural log scale
227
228// change this value to change volume scaling
229static const float dBPerStep = 0.5f;
230// shouldn't need to touch these
231static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f;
232static const float dBConvertInverse = 1.0f / dBConvert;
233
234float AudioSystem::linearToLog(int volume)
235{
236 // float v = volume ? exp(float(100 - volume) * dBConvert) : 0;
Steve Blockb8a80522011-12-20 16:23:08 +0000237 // ALOGD("linearToLog(%d)=%f", volume, v);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800238 // return v;
239 return volume ? exp(float(100 - volume) * dBConvert) : 0;
240}
241
242int AudioSystem::logToLinear(float volume)
243{
244 // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
Steve Blockb8a80522011-12-20 16:23:08 +0000245 // ALOGD("logTolinear(%d)=%f", v, volume);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800246 // return v;
247 return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
248}
249
Glenn Kasten3b16c762012-11-14 08:44:39 -0800250status_t AudioSystem::getOutputSamplingRate(uint32_t* samplingRate, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800251{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700252 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800253
Dima Zavinfce7a472011-04-19 22:30:36 -0700254 if (streamType == AUDIO_STREAM_DEFAULT) {
255 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700256 }
257
Glenn Kastenfff6d712012-01-12 16:38:12 -0800258 output = getOutput(streamType);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700259 if (output == 0) {
260 return PERMISSION_DENIED;
261 }
262
Jean-Michel Trivib7f24b12014-06-11 10:05:30 -0700263 return getSamplingRate(output, samplingRate);
Eric Laurent1a9ed112012-03-20 18:36:01 -0700264}
265
266status_t AudioSystem::getSamplingRate(audio_io_handle_t output,
Glenn Kasten3b16c762012-11-14 08:44:39 -0800267 uint32_t* samplingRate)
Eric Laurent1a9ed112012-03-20 18:36:01 -0700268{
Eric Laurentf6778fd2014-11-18 17:26:58 -0800269 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
270 if (af == 0) return PERMISSION_DENIED;
Eric Laurent296fb132015-05-01 11:38:42 -0700271 sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output);
Eric Laurent73e26b62015-04-27 16:55:58 -0700272 if (outputDesc == 0) {
Steve Block3856b092011-10-20 11:56:00 +0100273 ALOGV("getOutputSamplingRate() no output descriptor for output %d in gOutputs", output);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700274 *samplingRate = af->sampleRate(output);
275 } else {
Steve Block3856b092011-10-20 11:56:00 +0100276 ALOGV("getOutputSamplingRate() reading from output desc");
Eric Laurent73e26b62015-04-27 16:55:58 -0700277 *samplingRate = outputDesc->mSamplingRate;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700278 }
Glenn Kastenf94006c2014-01-08 08:56:06 -0800279 if (*samplingRate == 0) {
Jean-Michel Trivib7f24b12014-06-11 10:05:30 -0700280 ALOGE("AudioSystem::getSamplingRate failed for output %d", output);
Glenn Kastenf94006c2014-01-08 08:56:06 -0800281 return BAD_VALUE;
282 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700283
Jean-Michel Trivib7f24b12014-06-11 10:05:30 -0700284 ALOGV("getSamplingRate() output %d, sampling rate %u", output, *samplingRate);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700285
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800286 return NO_ERROR;
287}
288
Glenn Kastene33054e2012-11-14 12:54:39 -0800289status_t AudioSystem::getOutputFrameCount(size_t* frameCount, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800290{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700291 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800292
Dima Zavinfce7a472011-04-19 22:30:36 -0700293 if (streamType == AUDIO_STREAM_DEFAULT) {
294 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700295 }
Eric Laurent48f7f5e2009-04-02 09:32:43 -0700296
Glenn Kastenfff6d712012-01-12 16:38:12 -0800297 output = getOutput(streamType);
Glenn Kasten142f5192014-03-25 17:44:59 -0700298 if (output == AUDIO_IO_HANDLE_NONE) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700299 return PERMISSION_DENIED;
300 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800301
Jean-Michel Trivib7f24b12014-06-11 10:05:30 -0700302 return getFrameCount(output, frameCount);
Eric Laurent1a9ed112012-03-20 18:36:01 -0700303}
304
305status_t AudioSystem::getFrameCount(audio_io_handle_t output,
Glenn Kastene33054e2012-11-14 12:54:39 -0800306 size_t* frameCount)
Eric Laurent1a9ed112012-03-20 18:36:01 -0700307{
Eric Laurentf6778fd2014-11-18 17:26:58 -0800308 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
309 if (af == 0) return PERMISSION_DENIED;
Eric Laurent296fb132015-05-01 11:38:42 -0700310 sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output);
Eric Laurent73e26b62015-04-27 16:55:58 -0700311 if (outputDesc == 0) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700312 *frameCount = af->frameCount(output);
313 } else {
Eric Laurent73e26b62015-04-27 16:55:58 -0700314 *frameCount = outputDesc->mFrameCount;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700315 }
Glenn Kastenf94006c2014-01-08 08:56:06 -0800316 if (*frameCount == 0) {
Jean-Michel Trivib7f24b12014-06-11 10:05:30 -0700317 ALOGE("AudioSystem::getFrameCount failed for output %d", output);
Glenn Kastenf94006c2014-01-08 08:56:06 -0800318 return BAD_VALUE;
319 }
Eric Laurentc2f1f072009-07-17 12:17:14 -0700320
Mark Salyzyn34fb2962014-06-18 16:30:56 -0700321 ALOGV("getFrameCount() output %d, frameCount %zu", output, *frameCount);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700322
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800323 return NO_ERROR;
324}
325
Glenn Kastenfff6d712012-01-12 16:38:12 -0800326status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800327{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700328 audio_io_handle_t output;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800329
Dima Zavinfce7a472011-04-19 22:30:36 -0700330 if (streamType == AUDIO_STREAM_DEFAULT) {
331 streamType = AUDIO_STREAM_MUSIC;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700332 }
Eric Laurent48f7f5e2009-04-02 09:32:43 -0700333
Glenn Kastenfff6d712012-01-12 16:38:12 -0800334 output = getOutput(streamType);
Glenn Kasten142f5192014-03-25 17:44:59 -0700335 if (output == AUDIO_IO_HANDLE_NONE) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700336 return PERMISSION_DENIED;
337 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800338
Glenn Kasten241618f2014-03-25 17:48:57 -0700339 return getLatency(output, latency);
Eric Laurent1a9ed112012-03-20 18:36:01 -0700340}
341
342status_t AudioSystem::getLatency(audio_io_handle_t output,
Eric Laurent1a9ed112012-03-20 18:36:01 -0700343 uint32_t* latency)
344{
Eric Laurentf6778fd2014-11-18 17:26:58 -0800345 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
346 if (af == 0) return PERMISSION_DENIED;
Eric Laurent296fb132015-05-01 11:38:42 -0700347 sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output);
Eric Laurent73e26b62015-04-27 16:55:58 -0700348 if (outputDesc == 0) {
Eric Laurentc2f1f072009-07-17 12:17:14 -0700349 *latency = af->latency(output);
350 } else {
Eric Laurent73e26b62015-04-27 16:55:58 -0700351 *latency = outputDesc->mLatency;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700352 }
353
Glenn Kasten241618f2014-03-25 17:48:57 -0700354 ALOGV("getLatency() output %d, latency %d", output, *latency);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700355
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800356 return NO_ERROR;
357}
358
Glenn Kastendd8104c2012-07-02 12:42:44 -0700359status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format,
360 audio_channel_mask_t channelMask, size_t* buffSize)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800361{
Eric Laurent296fb132015-05-01 11:38:42 -0700362 const sp<AudioFlingerClient> afc = getAudioFlingerClient();
363 if (afc == 0) {
364 return NO_INIT;
365 }
366 return afc->getInputBufferSize(sampleRate, format, channelMask, buffSize);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800367}
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
Kévin PETIT377b2ec2014-02-03 12:35:36 +0000376status_t AudioSystem::getRenderPosition(audio_io_handle_t output, uint32_t *halFrames,
Glenn Kasten0ed19592014-03-26 07:50:05 -0700377 uint32_t *dspFrames)
Eric Laurent342e9cf2010-01-19 17:37:09 -0800378{
379 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
380 if (af == 0) return PERMISSION_DENIED;
381
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000382 return af->getRenderPosition(halFrames, dspFrames, output);
Eric Laurent342e9cf2010-01-19 17:37:09 -0800383}
384
Glenn Kasten4944acb2013-08-19 08:39:20 -0700385uint32_t AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle)
386{
Eric Laurent05bca2f2010-02-26 02:47:27 -0800387 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
Glenn Kasten5f972c02014-01-13 09:59:31 -0800388 uint32_t result = 0;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800389 if (af == 0) return result;
Glenn Kasten142f5192014-03-25 17:44:59 -0700390 if (ioHandle == AUDIO_IO_HANDLE_NONE) return result;
Eric Laurent05bca2f2010-02-26 02:47:27 -0800391
392 result = af->getInputFramesLost(ioHandle);
393 return result;
394}
395
Eric Laurentde3f8392014-07-27 18:38:22 -0700396audio_unique_id_t AudioSystem::newAudioUniqueId()
Glenn Kasten4944acb2013-08-19 08:39:20 -0700397{
Eric Laurentbe916aa2010-06-01 23:49:17 -0700398 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
Eric Laurentde3f8392014-07-27 18:38:22 -0700399 if (af == 0) return AUDIO_UNIQUE_ID_ALLOCATE;
400 return af->newAudioUniqueId();
Eric Laurentbe916aa2010-06-01 23:49:17 -0700401}
402
Marco Nelissend457c972014-02-11 08:47:07 -0800403void AudioSystem::acquireAudioSessionId(int audioSession, pid_t pid)
Glenn Kasten4944acb2013-08-19 08:39:20 -0700404{
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700405 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
406 if (af != 0) {
Marco Nelissend457c972014-02-11 08:47:07 -0800407 af->acquireAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700408 }
409}
410
Marco Nelissend457c972014-02-11 08:47:07 -0800411void AudioSystem::releaseAudioSessionId(int audioSession, pid_t pid)
Glenn Kasten4944acb2013-08-19 08:39:20 -0700412{
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700413 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
414 if (af != 0) {
Marco Nelissend457c972014-02-11 08:47:07 -0800415 af->releaseAudioSessionId(audioSession, pid);
Marco Nelissen3a34bef2011-08-02 13:33:41 -0700416 }
417}
418
Eric Laurent93c3d412014-08-01 14:48:35 -0700419audio_hw_sync_t AudioSystem::getAudioHwSyncForSession(audio_session_t sessionId)
420{
421 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
422 if (af == 0) return AUDIO_HW_SYNC_INVALID;
423 return af->getAudioHwSyncForSession(sessionId);
424}
425
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800426// ---------------------------------------------------------------------------
427
Eric Laurent73e26b62015-04-27 16:55:58 -0700428
429void AudioSystem::AudioFlingerClient::clearIoCache()
430{
431 Mutex::Autolock _l(mLock);
432 mIoDescriptors.clear();
433 mInBuffSize = 0;
434 mInSamplingRate = 0;
435 mInFormat = AUDIO_FORMAT_DEFAULT;
436 mInChannelMask = AUDIO_CHANNEL_NONE;
437}
438
Glenn Kasten4944acb2013-08-19 08:39:20 -0700439void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who __unused)
440{
Eric Laurentf6778fd2014-11-18 17:26:58 -0800441 audio_error_callback cb = NULL;
442 {
443 Mutex::Autolock _l(AudioSystem::gLock);
444 AudioSystem::gAudioFlinger.clear();
445 cb = gAudioErrorCallback;
446 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800447
Eric Laurent73e26b62015-04-27 16:55:58 -0700448 // clear output handles and stream to output map caches
449 clearIoCache();
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800450
Eric Laurentf6778fd2014-11-18 17:26:58 -0800451 if (cb) {
452 cb(DEAD_OBJECT);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800453 }
Steve Block5ff1dd52012-01-05 23:22:43 +0000454 ALOGW("AudioFlinger server died!");
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800455}
456
Eric Laurent73e26b62015-04-27 16:55:58 -0700457void AudioSystem::AudioFlingerClient::ioConfigChanged(audio_io_config_event event,
458 const sp<AudioIoDescriptor>& ioDesc) {
Steve Block3856b092011-10-20 11:56:00 +0100459 ALOGV("ioConfigChanged() event %d", event);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700460
Eric Laurent73e26b62015-04-27 16:55:58 -0700461 if (ioDesc == 0 || ioDesc->mIoHandle == AUDIO_IO_HANDLE_NONE) return;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700462
Eric Laurent296fb132015-05-01 11:38:42 -0700463 audio_port_handle_t deviceId = AUDIO_PORT_HANDLE_NONE;
464 Vector < sp<AudioDeviceCallback> > callbacks;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700465
Eric Laurent296fb132015-05-01 11:38:42 -0700466 {
467 Mutex::Autolock _l(mLock);
468
469 switch (event) {
470 case AUDIO_OUTPUT_OPENED:
471 case AUDIO_INPUT_OPENED: {
472 if (getIoDescriptor(ioDesc->mIoHandle) != 0) {
473 ALOGV("ioConfigChanged() opening already existing output! %d", ioDesc->mIoHandle);
474 break;
475 }
476 mIoDescriptors.add(ioDesc->mIoHandle, ioDesc);
477
478 if (ioDesc->getDeviceId() != AUDIO_PORT_HANDLE_NONE) {
479 deviceId = ioDesc->getDeviceId();
480 ssize_t ioIndex = mAudioDeviceCallbacks.indexOfKey(ioDesc->mIoHandle);
481 if (ioIndex >= 0) {
482 callbacks = mAudioDeviceCallbacks.valueAt(ioIndex);
483 }
484 }
485 ALOGV("ioConfigChanged() new %s opened %d samplingRate %u, format %#x channel mask %#x "
486 "frameCount %zu deviceId %d", event == AUDIO_OUTPUT_OPENED ? "output" : "input",
487 ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat, ioDesc->mChannelMask,
488 ioDesc->mFrameCount, ioDesc->getDeviceId());
489 } break;
490 case AUDIO_OUTPUT_CLOSED:
491 case AUDIO_INPUT_CLOSED: {
492 if (getIoDescriptor(ioDesc->mIoHandle) == 0) {
493 ALOGW("ioConfigChanged() closing unknown %s %d",
494 event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle);
495 break;
496 }
497 ALOGV("ioConfigChanged() %s %d closed",
Eric Laurent73e26b62015-04-27 16:55:58 -0700498 event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700499
Eric Laurent296fb132015-05-01 11:38:42 -0700500 mIoDescriptors.removeItem(ioDesc->mIoHandle);
501 mAudioDeviceCallbacks.removeItem(ioDesc->mIoHandle);
502 } break;
503
504 case AUDIO_OUTPUT_CONFIG_CHANGED:
505 case AUDIO_INPUT_CONFIG_CHANGED: {
506 sp<AudioIoDescriptor> oldDesc = getIoDescriptor(ioDesc->mIoHandle);
507 if (oldDesc == 0) {
508 ALOGW("ioConfigChanged() modifying unknown output! %d", ioDesc->mIoHandle);
509 break;
510 }
511
512 deviceId = oldDesc->getDeviceId();
513 mIoDescriptors.replaceValueFor(ioDesc->mIoHandle, ioDesc);
514
515 if (deviceId != ioDesc->getDeviceId()) {
516 deviceId = ioDesc->getDeviceId();
517 ssize_t ioIndex = mAudioDeviceCallbacks.indexOfKey(ioDesc->mIoHandle);
518 if (ioIndex >= 0) {
519 callbacks = mAudioDeviceCallbacks.valueAt(ioIndex);
520 }
521 }
522 ALOGV("ioConfigChanged() new config for %s %d samplingRate %u, format %#x "
523 "channel mask %#x frameCount %zu deviceId %d",
524 event == AUDIO_OUTPUT_CONFIG_CHANGED ? "output" : "input",
525 ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat,
526 ioDesc->mChannelMask, ioDesc->mFrameCount, ioDesc->getDeviceId());
527
Eric Laurentc2f1f072009-07-17 12:17:14 -0700528 } break;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700529 }
Eric Laurent296fb132015-05-01 11:38:42 -0700530 }
531 // callbacks.size() != 0 => ioDesc->mIoHandle and deviceId are valid
532 for (size_t i = 0; i < callbacks.size(); i++) {
533 callbacks[i]->onAudioDeviceUpdate(ioDesc->mIoHandle, deviceId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700534 }
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800535}
536
Eric Laurent73e26b62015-04-27 16:55:58 -0700537status_t AudioSystem::AudioFlingerClient::getInputBufferSize(
538 uint32_t sampleRate, audio_format_t format,
539 audio_channel_mask_t channelMask, size_t* buffSize)
540{
541 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
542 if (af == 0) {
543 return PERMISSION_DENIED;
544 }
545 Mutex::Autolock _l(mLock);
546 // Do we have a stale mInBuffSize or are we requesting the input buffer size for new values
547 if ((mInBuffSize == 0) || (sampleRate != mInSamplingRate) || (format != mInFormat)
548 || (channelMask != mInChannelMask)) {
549 size_t inBuffSize = af->getInputBufferSize(sampleRate, format, channelMask);
550 if (inBuffSize == 0) {
551 ALOGE("AudioSystem::getInputBufferSize failed sampleRate %d format %#x channelMask %x",
552 sampleRate, format, channelMask);
553 return BAD_VALUE;
554 }
555 // A benign race is possible here: we could overwrite a fresher cache entry
556 // save the request params
557 mInSamplingRate = sampleRate;
558 mInFormat = format;
559 mInChannelMask = channelMask;
560
561 mInBuffSize = inBuffSize;
562 }
563
564 *buffSize = mInBuffSize;
565
566 return NO_ERROR;
567}
568
569sp<AudioIoDescriptor> AudioSystem::AudioFlingerClient::getIoDescriptor(audio_io_handle_t ioHandle)
570{
571 sp<AudioIoDescriptor> desc;
572 ssize_t index = mIoDescriptors.indexOfKey(ioHandle);
573 if (index >= 0) {
574 desc = mIoDescriptors.valueAt(index);
575 }
576 return desc;
577}
578
Eric Laurent296fb132015-05-01 11:38:42 -0700579status_t AudioSystem::AudioFlingerClient::addAudioDeviceCallback(
580 const sp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo)
581{
582 Mutex::Autolock _l(mLock);
583 Vector < sp<AudioDeviceCallback> > callbacks;
584 ssize_t ioIndex = mAudioDeviceCallbacks.indexOfKey(audioIo);
585 if (ioIndex >= 0) {
586 callbacks = mAudioDeviceCallbacks.valueAt(ioIndex);
587 }
588
589 for (size_t cbIndex = 0; cbIndex < callbacks.size(); cbIndex++) {
590 if (callbacks[cbIndex] == callback) {
591 return INVALID_OPERATION;
592 }
593 }
594 callbacks.add(callback);
595
596 mAudioDeviceCallbacks.replaceValueFor(audioIo, callbacks);
597 return NO_ERROR;
598}
599
600status_t AudioSystem::AudioFlingerClient::removeAudioDeviceCallback(
601 const sp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo)
602{
603 Mutex::Autolock _l(mLock);
604 ssize_t ioIndex = mAudioDeviceCallbacks.indexOfKey(audioIo);
605 if (ioIndex < 0) {
606 return INVALID_OPERATION;
607 }
608 Vector < sp<AudioDeviceCallback> > callbacks = mAudioDeviceCallbacks.valueAt(ioIndex);
609
610 size_t cbIndex;
611 for (cbIndex = 0; cbIndex < callbacks.size(); cbIndex++) {
612 if (callbacks[cbIndex] == callback) {
613 break;
614 }
615 }
616 if (cbIndex == callbacks.size()) {
617 return INVALID_OPERATION;
618 }
619 callbacks.removeAt(cbIndex);
620 if (callbacks.size() != 0) {
621 mAudioDeviceCallbacks.replaceValueFor(audioIo, callbacks);
622 } else {
623 mAudioDeviceCallbacks.removeItem(audioIo);
624 }
625 return NO_ERROR;
626}
627
628/* static */ void AudioSystem::setErrorCallback(audio_error_callback cb)
Glenn Kasten4944acb2013-08-19 08:39:20 -0700629{
Eric Laurentc2f1f072009-07-17 12:17:14 -0700630 Mutex::Autolock _l(gLock);
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800631 gAudioErrorCallback = cb;
632}
633
Jean-Michel Trivif613d422015-04-23 18:41:29 -0700634/*static*/ void AudioSystem::setDynPolicyCallback(dynamic_policy_callback cb)
635{
636 Mutex::Autolock _l(gLock);
637 gDynPolicyCallback = cb;
638}
639
Eric Laurentc2f1f072009-07-17 12:17:14 -0700640// client singleton for AudioPolicyService binder interface
Glenn Kastend2d089f2014-11-05 11:48:12 -0800641// protected by gLockAPS
Eric Laurentc2f1f072009-07-17 12:17:14 -0700642sp<IAudioPolicyService> AudioSystem::gAudioPolicyService;
643sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient;
644
645
Glenn Kasten18a6d902012-09-24 11:27:56 -0700646// establish binder interface to AudioPolicy service
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800647const sp<IAudioPolicyService> AudioSystem::get_audio_policy_service()
Eric Laurentc2f1f072009-07-17 12:17:14 -0700648{
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800649 sp<IAudioPolicyService> ap;
650 sp<AudioPolicyServiceClient> apc;
651 {
652 Mutex::Autolock _l(gLockAPS);
653 if (gAudioPolicyService == 0) {
654 sp<IServiceManager> sm = defaultServiceManager();
655 sp<IBinder> binder;
656 do {
657 binder = sm->getService(String16("media.audio_policy"));
658 if (binder != 0)
659 break;
660 ALOGW("AudioPolicyService not published, waiting...");
661 usleep(500000); // 0.5 s
662 } while (true);
663 if (gAudioPolicyServiceClient == NULL) {
664 gAudioPolicyServiceClient = new AudioPolicyServiceClient();
665 }
666 binder->linkToDeath(gAudioPolicyServiceClient);
667 gAudioPolicyService = interface_cast<IAudioPolicyService>(binder);
668 LOG_ALWAYS_FATAL_IF(gAudioPolicyService == 0);
669 apc = gAudioPolicyServiceClient;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700670 }
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800671 ap = gAudioPolicyService;
672 }
673 if (apc != 0) {
674 ap->registerClient(apc);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700675 }
Glenn Kastend2d089f2014-11-05 11:48:12 -0800676
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800677 return ap;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700678}
679
Glenn Kastenfb1fdc92013-07-10 17:03:19 -0700680// ---------------------------------------------------------------------------
681
Dima Zavinfce7a472011-04-19 22:30:36 -0700682status_t AudioSystem::setDeviceConnectionState(audio_devices_t device,
683 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -0800684 const char *device_address,
685 const char *device_name)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700686{
687 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurent71b63e32011-09-02 14:20:56 -0700688 const char *address = "";
Paul McLeane743a472015-01-28 11:07:31 -0800689 const char *name = "";
Eric Laurent71b63e32011-09-02 14:20:56 -0700690
Eric Laurentc2f1f072009-07-17 12:17:14 -0700691 if (aps == 0) return PERMISSION_DENIED;
692
Eric Laurent71b63e32011-09-02 14:20:56 -0700693 if (device_address != NULL) {
694 address = device_address;
695 }
Paul McLeane743a472015-01-28 11:07:31 -0800696 if (device_name != NULL) {
697 name = device_name;
698 }
699 return aps->setDeviceConnectionState(device, state, address, name);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700700}
701
Dima Zavinfce7a472011-04-19 22:30:36 -0700702audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700703 const char *device_address)
704{
705 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700706 if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700707
708 return aps->getDeviceConnectionState(device, device_address);
709}
710
Glenn Kastenf78aee72012-01-04 11:00:47 -0800711status_t AudioSystem::setPhoneState(audio_mode_t state)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700712{
Glenn Kasten347966c2012-01-18 14:58:32 -0800713 if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700714 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
715 if (aps == 0) return PERMISSION_DENIED;
716
717 return aps->setPhoneState(state);
718}
719
Dima Zavinfce7a472011-04-19 22:30:36 -0700720status_t AudioSystem::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700721{
722 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
723 if (aps == 0) return PERMISSION_DENIED;
724 return aps->setForceUse(usage, config);
725}
726
Dima Zavinfce7a472011-04-19 22:30:36 -0700727audio_policy_forced_cfg_t AudioSystem::getForceUse(audio_policy_force_use_t usage)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700728{
729 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Dima Zavinfce7a472011-04-19 22:30:36 -0700730 if (aps == 0) return AUDIO_POLICY_FORCE_NONE;
Eric Laurentc2f1f072009-07-17 12:17:14 -0700731 return aps->getForceUse(usage);
732}
733
734
Dima Zavinfce7a472011-04-19 22:30:36 -0700735audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700736 uint32_t samplingRate,
Glenn Kasten58f30212012-01-12 12:27:51 -0800737 audio_format_t format,
Glenn Kasten254af182012-07-03 14:59:05 -0700738 audio_channel_mask_t channelMask,
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000739 audio_output_flags_t flags,
740 const audio_offload_info_t *offloadInfo)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700741{
Eric Laurent1a9ed112012-03-20 18:36:01 -0700742 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
743 if (aps == 0) return 0;
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000744 return aps->getOutput(stream, samplingRate, format, channelMask, flags, offloadInfo);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700745}
746
Eric Laurente83b55d2014-11-14 10:06:21 -0800747status_t AudioSystem::getOutputForAttr(const audio_attributes_t *attr,
748 audio_io_handle_t *output,
749 audio_session_t session,
750 audio_stream_type_t *stream,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700751 uid_t uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800752 uint32_t samplingRate,
753 audio_format_t format,
754 audio_channel_mask_t channelMask,
755 audio_output_flags_t flags,
Paul McLeanaa981192015-03-21 09:55:15 -0700756 audio_port_handle_t selectedDeviceId,
Eric Laurente83b55d2014-11-14 10:06:21 -0800757 const audio_offload_info_t *offloadInfo)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700758{
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700759 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurente83b55d2014-11-14 10:06:21 -0800760 if (aps == 0) return NO_INIT;
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700761 return aps->getOutputForAttr(attr, output, session, stream, uid,
Eric Laurente83b55d2014-11-14 10:06:21 -0800762 samplingRate, format, channelMask,
Paul McLeanaa981192015-03-21 09:55:15 -0700763 flags, selectedDeviceId, offloadInfo);
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700764}
765
Eric Laurentde070132010-07-13 04:45:46 -0700766status_t AudioSystem::startOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700767 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800768 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700769{
770 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
771 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700772 return aps->startOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700773}
774
Eric Laurentde070132010-07-13 04:45:46 -0700775status_t AudioSystem::stopOutput(audio_io_handle_t output,
Dima Zavinfce7a472011-04-19 22:30:36 -0700776 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800777 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700778{
779 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
780 if (aps == 0) return PERMISSION_DENIED;
Eric Laurentde070132010-07-13 04:45:46 -0700781 return aps->stopOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700782}
783
Eric Laurente83b55d2014-11-14 10:06:21 -0800784void AudioSystem::releaseOutput(audio_io_handle_t output,
785 audio_stream_type_t stream,
786 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700787{
788 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
789 if (aps == 0) return;
Eric Laurente83b55d2014-11-14 10:06:21 -0800790 aps->releaseOutput(output, stream, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700791}
792
Eric Laurentcaf7f482014-11-25 17:50:47 -0800793status_t AudioSystem::getInputForAttr(const audio_attributes_t *attr,
794 audio_io_handle_t *input,
795 audio_session_t session,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700796 uid_t uid,
Eric Laurentcaf7f482014-11-25 17:50:47 -0800797 uint32_t samplingRate,
798 audio_format_t format,
799 audio_channel_mask_t channelMask,
Paul McLean466dc8e2015-04-17 13:15:36 -0600800 audio_input_flags_t flags,
801 audio_port_handle_t selectedDeviceId)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700802{
803 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Eric Laurentcaf7f482014-11-25 17:50:47 -0800804 if (aps == 0) return NO_INIT;
Paul McLean466dc8e2015-04-17 13:15:36 -0600805 return aps->getInputForAttr(
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700806 attr, input, session, uid, samplingRate, format, channelMask, flags, selectedDeviceId);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700807}
808
Eric Laurent4dc68062014-07-28 17:26:49 -0700809status_t AudioSystem::startInput(audio_io_handle_t input,
810 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700811{
812 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
813 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent4dc68062014-07-28 17:26:49 -0700814 return aps->startInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700815}
816
Eric Laurent4dc68062014-07-28 17:26:49 -0700817status_t AudioSystem::stopInput(audio_io_handle_t input,
818 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700819{
820 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
821 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent4dc68062014-07-28 17:26:49 -0700822 return aps->stopInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700823}
824
Eric Laurent4dc68062014-07-28 17:26:49 -0700825void AudioSystem::releaseInput(audio_io_handle_t input,
826 audio_session_t session)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700827{
828 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
829 if (aps == 0) return;
Eric Laurent4dc68062014-07-28 17:26:49 -0700830 aps->releaseInput(input, session);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700831}
832
Dima Zavinfce7a472011-04-19 22:30:36 -0700833status_t AudioSystem::initStreamVolume(audio_stream_type_t stream,
Eric Laurentc2f1f072009-07-17 12:17:14 -0700834 int indexMin,
835 int indexMax)
836{
837 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
838 if (aps == 0) return PERMISSION_DENIED;
839 return aps->initStreamVolume(stream, indexMin, indexMax);
840}
841
Eric Laurent83844cc2011-11-18 16:43:31 -0800842status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream,
843 int index,
844 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700845{
846 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
847 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800848 return aps->setStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700849}
850
Eric Laurent83844cc2011-11-18 16:43:31 -0800851status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream,
852 int *index,
853 audio_devices_t device)
Eric Laurentc2f1f072009-07-17 12:17:14 -0700854{
855 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
856 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent83844cc2011-11-18 16:43:31 -0800857 return aps->getStreamVolumeIndex(stream, index, device);
Eric Laurentc2f1f072009-07-17 12:17:14 -0700858}
859
Dima Zavinfce7a472011-04-19 22:30:36 -0700860uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream)
Eric Laurentde070132010-07-13 04:45:46 -0700861{
862 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
863 if (aps == 0) return 0;
864 return aps->getStrategyForStream(stream);
865}
866
Eric Laurent63742522012-03-08 13:42:42 -0800867audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream)
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800868{
869 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Glenn Kasten45faf7e2014-01-17 10:23:01 -0800870 if (aps == 0) return AUDIO_DEVICE_NONE;
Glenn Kasten6b2718c2011-02-04 13:54:26 -0800871 return aps->getDevicesForStream(stream);
872}
873
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700874audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t *desc)
Eric Laurentde070132010-07-13 04:45:46 -0700875{
876 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
Glenn Kastenefa6ea92014-01-08 09:10:43 -0800877 // FIXME change return type to status_t, and return PERMISSION_DENIED here
Glenn Kasten142f5192014-03-25 17:44:59 -0700878 if (aps == 0) return AUDIO_IO_HANDLE_NONE;
Eric Laurentde070132010-07-13 04:45:46 -0700879 return aps->getOutputForEffect(desc);
880}
881
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700882status_t AudioSystem::registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700883 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700884 uint32_t strategy,
885 int session,
886 int id)
887{
888 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
889 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700890 return aps->registerEffect(desc, io, strategy, session, id);
Eric Laurentde070132010-07-13 04:45:46 -0700891}
892
893status_t AudioSystem::unregisterEffect(int id)
894{
895 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
896 if (aps == 0) return PERMISSION_DENIED;
897 return aps->unregisterEffect(id);
898}
899
Eric Laurentdb7c0792011-08-10 10:37:50 -0700900status_t AudioSystem::setEffectEnabled(int id, bool enabled)
901{
902 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
903 if (aps == 0) return PERMISSION_DENIED;
904 return aps->setEffectEnabled(id, enabled);
905}
906
Glenn Kastenfff6d712012-01-12 16:38:12 -0800907status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs)
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700908{
Eric Laurenteda6c362011-02-02 09:33:30 -0800909 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
910 if (aps == 0) return PERMISSION_DENIED;
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700911 if (state == NULL) return BAD_VALUE;
Eric Laurenteda6c362011-02-02 09:33:30 -0800912 *state = aps->isStreamActive(stream, inPastMs);
913 return NO_ERROR;
914}
915
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800916status_t AudioSystem::isStreamActiveRemotely(audio_stream_type_t stream, bool* state,
917 uint32_t inPastMs)
918{
919 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
920 if (aps == 0) return PERMISSION_DENIED;
921 if (state == NULL) return BAD_VALUE;
922 *state = aps->isStreamActiveRemotely(stream, inPastMs);
923 return NO_ERROR;
924}
925
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700926status_t AudioSystem::isSourceActive(audio_source_t stream, bool* state)
927{
928 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
929 if (aps == 0) return PERMISSION_DENIED;
930 if (state == NULL) return BAD_VALUE;
931 *state = aps->isSourceActive(stream);
932 return NO_ERROR;
933}
934
Glenn Kasten3b16c762012-11-14 08:44:39 -0800935uint32_t AudioSystem::getPrimaryOutputSamplingRate()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700936{
937 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
938 if (af == 0) return 0;
939 return af->getPrimaryOutputSamplingRate();
940}
941
Glenn Kastene33054e2012-11-14 12:54:39 -0800942size_t AudioSystem::getPrimaryOutputFrameCount()
Glenn Kastencc0f1cf2012-09-24 11:27:18 -0700943{
944 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
945 if (af == 0) return 0;
946 return af->getPrimaryOutputFrameCount();
947}
Eric Laurenteda6c362011-02-02 09:33:30 -0800948
Glenn Kasten4182c4e2013-07-15 14:45:07 -0700949status_t AudioSystem::setLowRamDevice(bool isLowRamDevice)
950{
951 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
952 if (af == 0) return PERMISSION_DENIED;
953 return af->setLowRamDevice(isLowRamDevice);
954}
955
Eric Laurent9f6530f2011-08-30 10:18:54 -0700956void AudioSystem::clearAudioConfigCache()
957{
Glenn Kastend2d089f2014-11-05 11:48:12 -0800958 // called by restoreTrack_l(), which needs new IAudioFlinger and IAudioPolicyService instances
Steve Block3856b092011-10-20 11:56:00 +0100959 ALOGV("clearAudioConfigCache()");
Eric Laurentf6778fd2014-11-18 17:26:58 -0800960 {
961 Mutex::Autolock _l(gLock);
Eric Laurent296fb132015-05-01 11:38:42 -0700962 if (gAudioFlingerClient != 0) {
963 gAudioFlingerClient->clearIoCache();
964 }
Glenn Kastend2d089f2014-11-05 11:48:12 -0800965 gAudioFlinger.clear();
966 }
967 {
968 Mutex::Autolock _l(gLockAPS);
969 gAudioPolicyService.clear();
970 }
Eric Laurent9f6530f2011-08-30 10:18:54 -0700971}
972
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000973bool AudioSystem::isOffloadSupported(const audio_offload_info_t& info)
974{
975 ALOGV("isOffloadSupported()");
976 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
977 if (aps == 0) return false;
978 return aps->isOffloadSupported(info);
979}
980
Eric Laurent203b1a12014-04-01 10:34:16 -0700981status_t AudioSystem::listAudioPorts(audio_port_role_t role,
982 audio_port_type_t type,
983 unsigned int *num_ports,
984 struct audio_port *ports,
985 unsigned int *generation)
986{
987 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
988 if (aps == 0) return PERMISSION_DENIED;
989 return aps->listAudioPorts(role, type, num_ports, ports, generation);
990}
991
992status_t AudioSystem::getAudioPort(struct audio_port *port)
993{
994 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
995 if (aps == 0) return PERMISSION_DENIED;
996 return aps->getAudioPort(port);
997}
998
999status_t AudioSystem::createAudioPatch(const struct audio_patch *patch,
1000 audio_patch_handle_t *handle)
1001{
1002 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1003 if (aps == 0) return PERMISSION_DENIED;
1004 return aps->createAudioPatch(patch, handle);
1005}
1006
1007status_t AudioSystem::releaseAudioPatch(audio_patch_handle_t handle)
1008{
1009 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1010 if (aps == 0) return PERMISSION_DENIED;
1011 return aps->releaseAudioPatch(handle);
1012}
1013
1014status_t AudioSystem::listAudioPatches(unsigned int *num_patches,
1015 struct audio_patch *patches,
1016 unsigned int *generation)
1017{
1018 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1019 if (aps == 0) return PERMISSION_DENIED;
1020 return aps->listAudioPatches(num_patches, patches, generation);
1021}
1022
1023status_t AudioSystem::setAudioPortConfig(const struct audio_port_config *config)
1024{
1025 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1026 if (aps == 0) return PERMISSION_DENIED;
1027 return aps->setAudioPortConfig(config);
1028}
1029
Eric Laurent296fb132015-05-01 11:38:42 -07001030status_t AudioSystem::addAudioPortCallback(const sp<AudioPortCallback>& callback)
Eric Laurentb52c1522014-05-20 11:27:36 -07001031{
Eric Laurentb28753e2015-04-01 13:06:28 -07001032 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1033 if (aps == 0) return PERMISSION_DENIED;
1034
1035 Mutex::Autolock _l(gLockAPS);
1036 if (gAudioPolicyServiceClient == 0) {
1037 return NO_INIT;
1038 }
Eric Laurent296fb132015-05-01 11:38:42 -07001039 return gAudioPolicyServiceClient->addAudioPortCallback(callback);
Eric Laurentb52c1522014-05-20 11:27:36 -07001040}
1041
Jean-Michel Trivif613d422015-04-23 18:41:29 -07001042/*static*/
Eric Laurent296fb132015-05-01 11:38:42 -07001043status_t AudioSystem::removeAudioPortCallback(const sp<AudioPortCallback>& callback)
Eric Laurentb28753e2015-04-01 13:06:28 -07001044{
1045 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1046 if (aps == 0) return PERMISSION_DENIED;
1047
1048 Mutex::Autolock _l(gLockAPS);
1049 if (gAudioPolicyServiceClient == 0) {
1050 return NO_INIT;
1051 }
Eric Laurent296fb132015-05-01 11:38:42 -07001052 return gAudioPolicyServiceClient->removeAudioPortCallback(callback);
1053}
1054
1055status_t AudioSystem::addAudioDeviceCallback(
1056 const sp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo)
1057{
1058 const sp<AudioFlingerClient> afc = getAudioFlingerClient();
1059 if (afc == 0) {
1060 return NO_INIT;
1061 }
1062 return afc->addAudioDeviceCallback(callback, audioIo);
1063}
1064
1065status_t AudioSystem::removeAudioDeviceCallback(
1066 const sp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo)
1067{
1068 const sp<AudioFlingerClient> afc = getAudioFlingerClient();
1069 if (afc == 0) {
1070 return NO_INIT;
1071 }
1072 return afc->removeAudioDeviceCallback(callback, audioIo);
1073}
1074
1075audio_port_handle_t AudioSystem::getDeviceIdForIo(audio_io_handle_t audioIo)
1076{
1077 const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
1078 if (af == 0) return PERMISSION_DENIED;
1079 const sp<AudioIoDescriptor> desc = getIoDescriptor(audioIo);
1080 if (desc == 0) {
1081 return AUDIO_PORT_HANDLE_NONE;
1082 }
1083 return desc->getDeviceId();
Eric Laurentb28753e2015-04-01 13:06:28 -07001084}
1085
Eric Laurentdf3dc7e2014-07-27 18:39:40 -07001086status_t AudioSystem::acquireSoundTriggerSession(audio_session_t *session,
1087 audio_io_handle_t *ioHandle,
1088 audio_devices_t *device)
1089{
1090 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1091 if (aps == 0) return PERMISSION_DENIED;
1092 return aps->acquireSoundTriggerSession(session, ioHandle, device);
1093}
1094
1095status_t AudioSystem::releaseSoundTriggerSession(audio_session_t session)
1096{
1097 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1098 if (aps == 0) return PERMISSION_DENIED;
1099 return aps->releaseSoundTriggerSession(session);
1100}
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001101
1102audio_mode_t AudioSystem::getPhoneState()
1103{
1104 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1105 if (aps == 0) return AUDIO_MODE_INVALID;
1106 return aps->getPhoneState();
1107}
1108
Eric Laurentbaac1832014-12-01 17:52:59 -08001109status_t AudioSystem::registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
1110{
1111 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1112 if (aps == 0) return PERMISSION_DENIED;
1113 return aps->registerPolicyMixes(mixes, registration);
1114}
Eric Laurentbb6c9a02014-09-25 14:11:47 -07001115
Eric Laurent554a2772015-04-10 11:29:24 -07001116status_t AudioSystem::startAudioSource(const struct audio_port_config *source,
1117 const audio_attributes_t *attributes,
1118 audio_io_handle_t *handle)
1119{
1120 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1121 if (aps == 0) return PERMISSION_DENIED;
1122 return aps->startAudioSource(source, attributes, handle);
1123}
1124
1125status_t AudioSystem::stopAudioSource(audio_io_handle_t handle)
1126{
1127 const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
1128 if (aps == 0) return PERMISSION_DENIED;
1129 return aps->stopAudioSource(handle);
1130}
1131
Eric Laurentc2f1f072009-07-17 12:17:14 -07001132// ---------------------------------------------------------------------------
1133
Eric Laurentb28753e2015-04-01 13:06:28 -07001134status_t AudioSystem::AudioPolicyServiceClient::addAudioPortCallback(
Eric Laurent296fb132015-05-01 11:38:42 -07001135 const sp<AudioPortCallback>& callback)
Eric Laurentb28753e2015-04-01 13:06:28 -07001136{
1137 Mutex::Autolock _l(mLock);
1138 for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) {
Eric Laurent296fb132015-05-01 11:38:42 -07001139 if (mAudioPortCallbacks[i] == callback) {
Eric Laurentb28753e2015-04-01 13:06:28 -07001140 return INVALID_OPERATION;
1141 }
1142 }
Eric Laurent296fb132015-05-01 11:38:42 -07001143 mAudioPortCallbacks.add(callback);
Eric Laurentb28753e2015-04-01 13:06:28 -07001144 return NO_ERROR;
1145}
1146
1147status_t AudioSystem::AudioPolicyServiceClient::removeAudioPortCallback(
Eric Laurent296fb132015-05-01 11:38:42 -07001148 const sp<AudioPortCallback>& callback)
Eric Laurentb28753e2015-04-01 13:06:28 -07001149{
1150 Mutex::Autolock _l(mLock);
1151 size_t i;
1152 for (i = 0; i < mAudioPortCallbacks.size(); i++) {
Eric Laurent296fb132015-05-01 11:38:42 -07001153 if (mAudioPortCallbacks[i] == callback) {
Eric Laurentb28753e2015-04-01 13:06:28 -07001154 break;
1155 }
1156 }
1157 if (i == mAudioPortCallbacks.size()) {
1158 return INVALID_OPERATION;
1159 }
1160 mAudioPortCallbacks.removeAt(i);
1161 return NO_ERROR;
1162}
1163
Eric Laurent296fb132015-05-01 11:38:42 -07001164
Eric Laurentb28753e2015-04-01 13:06:28 -07001165void AudioSystem::AudioPolicyServiceClient::onAudioPortListUpdate()
1166{
1167 Mutex::Autolock _l(mLock);
1168 for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) {
1169 mAudioPortCallbacks[i]->onAudioPortListUpdate();
1170 }
1171}
1172
1173void AudioSystem::AudioPolicyServiceClient::onAudioPatchListUpdate()
1174{
1175 Mutex::Autolock _l(mLock);
1176 for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) {
1177 mAudioPortCallbacks[i]->onAudioPatchListUpdate();
1178 }
1179}
1180
Jean-Michel Trivide801052015-04-14 19:10:14 -07001181void AudioSystem::AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate(
1182 String8 regId, int32_t state)
1183{
Jean-Michel Trivif613d422015-04-23 18:41:29 -07001184 ALOGV("AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate(%s, %d)", regId.string(), state);
1185 dynamic_policy_callback cb = NULL;
1186 {
1187 Mutex::Autolock _l(AudioSystem::gLock);
1188 cb = gDynPolicyCallback;
1189 }
1190
1191 if (cb != NULL) {
1192 cb(DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE, regId, state);
1193 }
Jean-Michel Trivide801052015-04-14 19:10:14 -07001194}
1195
Glenn Kasten4944acb2013-08-19 08:39:20 -07001196void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who __unused)
1197{
Glenn Kastend2d089f2014-11-05 11:48:12 -08001198 {
Eric Laurentb28753e2015-04-01 13:06:28 -07001199 Mutex::Autolock _l(mLock);
1200 for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) {
1201 mAudioPortCallbacks[i]->onServiceDied();
Glenn Kastend2d089f2014-11-05 11:48:12 -08001202 }
Eric Laurentb52c1522014-05-20 11:27:36 -07001203 }
Glenn Kastend2d089f2014-11-05 11:48:12 -08001204 {
1205 Mutex::Autolock _l(gLockAPS);
1206 AudioSystem::gAudioPolicyService.clear();
1207 }
Eric Laurentc2f1f072009-07-17 12:17:14 -07001208
Steve Block5ff1dd52012-01-05 23:22:43 +00001209 ALOGW("AudioPolicyService server died!");
Eric Laurentc2f1f072009-07-17 12:17:14 -07001210}
1211
Glenn Kasten40bc9062015-03-20 09:09:33 -07001212} // namespace android