The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/IServiceManager.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <media/AudioSystem.h> |
Glenn Kasten | 1ab85ec | 2013-05-31 09:18:43 -0700 | [diff] [blame] | 23 | #include <media/IAudioFlinger.h> |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 24 | #include <media/IAudioPolicyService.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <math.h> |
| 26 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 27 | #include <system/audio.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 28 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 29 | // ---------------------------------------------------------------------------- |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 30 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | namespace android { |
| 32 | |
| 33 | // client singleton for AudioFlinger binder interface |
| 34 | Mutex AudioSystem::gLock; |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 35 | Mutex AudioSystem::gLockAPS; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | sp<IAudioFlinger> AudioSystem::gAudioFlinger; |
| 37 | sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient; |
| 38 | audio_error_callback AudioSystem::gAudioErrorCallback = NULL; |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 39 | dynamic_policy_callback AudioSystem::gDynPolicyCallback = NULL; |
Glenn Kasten | 211eeaf | 2012-01-20 09:37:45 -0800 | [diff] [blame] | 40 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | // establish binder interface to AudioFlinger service |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 43 | const sp<IAudioFlinger> AudioSystem::get_audio_flinger() |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 45 | 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 Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 66 | binder->linkToDeath(gAudioFlingerClient); |
| 67 | gAudioFlinger = interface_cast<IAudioFlinger>(binder); |
| 68 | LOG_ALWAYS_FATAL_IF(gAudioFlinger == 0); |
| 69 | afc = gAudioFlingerClient; |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 70 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 71 | af = gAudioFlinger; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 73 | if (afc != 0) { |
| 74 | af->registerClient(afc); |
| 75 | } |
| 76 | return af; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 79 | const 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 | |
| 88 | sp<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 Laurent | 4629161 | 2013-07-18 14:38:44 -0700 | [diff] [blame] | 98 | /* 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 Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 106 | status_t AudioSystem::muteMicrophone(bool state) |
| 107 | { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 109 | if (af == 0) return PERMISSION_DENIED; |
| 110 | return af->setMicMute(state); |
| 111 | } |
| 112 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 113 | status_t AudioSystem::isMicrophoneMuted(bool* state) |
| 114 | { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | 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 | |
| 121 | status_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 | |
| 129 | status_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 | |
| 137 | status_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 | |
| 145 | status_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 Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 153 | status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value, |
| 154 | audio_io_handle_t output) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 156 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 158 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 159 | af->setStreamVolume(stream, value, output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | return NO_ERROR; |
| 161 | } |
| 162 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 163 | status_t AudioSystem::setStreamMute(audio_stream_type_t stream, bool mute) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 165 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | 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 Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 172 | status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume, |
| 173 | audio_io_handle_t output) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 175 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 177 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 178 | *volume = af->streamVolume(stream, output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | return NO_ERROR; |
| 180 | } |
| 181 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 182 | status_t AudioSystem::getStreamMute(audio_stream_type_t stream, bool* mute) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 184 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | 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 Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 191 | status_t AudioSystem::setMode(audio_mode_t mode) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | { |
Glenn Kasten | 930f4ca | 2012-01-06 16:47:31 -0800 | [diff] [blame] | 193 | if (uint32_t(mode) >= AUDIO_MODE_CNT) return BAD_VALUE; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 195 | if (af == 0) return PERMISSION_DENIED; |
| 196 | return af->setMode(mode); |
| 197 | } |
| 198 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 199 | status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) |
| 200 | { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 202 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 203 | return af->setParameters(ioHandle, keyValuePairs); |
| 204 | } |
| 205 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 206 | String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys) |
| 207 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 208 | 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 Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 216 | status_t AudioSystem::setParameters(const String8& keyValuePairs) |
| 217 | { |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 218 | return setParameters(AUDIO_IO_HANDLE_NONE, keyValuePairs); |
Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | String8 AudioSystem::getParameters(const String8& keys) |
| 222 | { |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 223 | return getParameters(AUDIO_IO_HANDLE_NONE, keys); |
Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 224 | } |
| 225 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | // convert volume steps to natural log scale |
| 227 | |
| 228 | // change this value to change volume scaling |
| 229 | static const float dBPerStep = 0.5f; |
| 230 | // shouldn't need to touch these |
| 231 | static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f; |
| 232 | static const float dBConvertInverse = 1.0f / dBConvert; |
| 233 | |
| 234 | float AudioSystem::linearToLog(int volume) |
| 235 | { |
| 236 | // float v = volume ? exp(float(100 - volume) * dBConvert) : 0; |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 237 | // ALOGD("linearToLog(%d)=%f", volume, v); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | // return v; |
| 239 | return volume ? exp(float(100 - volume) * dBConvert) : 0; |
| 240 | } |
| 241 | |
| 242 | int AudioSystem::logToLinear(float volume) |
| 243 | { |
| 244 | // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 245 | // ALOGD("logTolinear(%d)=%f", v, volume); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | // return v; |
| 247 | return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
| 248 | } |
| 249 | |
Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 250 | status_t AudioSystem::getOutputSamplingRate(uint32_t* samplingRate, audio_stream_type_t streamType) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 252 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 254 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 255 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 258 | output = getOutput(streamType); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 259 | if (output == 0) { |
| 260 | return PERMISSION_DENIED; |
| 261 | } |
| 262 | |
Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 263 | return getSamplingRate(output, samplingRate); |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | status_t AudioSystem::getSamplingRate(audio_io_handle_t output, |
Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 267 | uint32_t* samplingRate) |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 268 | { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 269 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 270 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 271 | sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output); |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 272 | if (outputDesc == 0) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 273 | ALOGV("getOutputSamplingRate() no output descriptor for output %d in gOutputs", output); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 274 | *samplingRate = af->sampleRate(output); |
| 275 | } else { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 276 | ALOGV("getOutputSamplingRate() reading from output desc"); |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 277 | *samplingRate = outputDesc->mSamplingRate; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 278 | } |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 279 | if (*samplingRate == 0) { |
Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 280 | ALOGE("AudioSystem::getSamplingRate failed for output %d", output); |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 281 | return BAD_VALUE; |
| 282 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 283 | |
Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 284 | ALOGV("getSamplingRate() output %d, sampling rate %u", output, *samplingRate); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 285 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | return NO_ERROR; |
| 287 | } |
| 288 | |
Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 289 | status_t AudioSystem::getOutputFrameCount(size_t* frameCount, audio_stream_type_t streamType) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 291 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 293 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 294 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 295 | } |
Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 296 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 297 | output = getOutput(streamType); |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 298 | if (output == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 299 | return PERMISSION_DENIED; |
| 300 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | |
Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 302 | return getFrameCount(output, frameCount); |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | status_t AudioSystem::getFrameCount(audio_io_handle_t output, |
Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 306 | size_t* frameCount) |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 307 | { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 308 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 309 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 310 | sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output); |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 311 | if (outputDesc == 0) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 312 | *frameCount = af->frameCount(output); |
| 313 | } else { |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 314 | *frameCount = outputDesc->mFrameCount; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 315 | } |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 316 | if (*frameCount == 0) { |
Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 317 | ALOGE("AudioSystem::getFrameCount failed for output %d", output); |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 318 | return BAD_VALUE; |
| 319 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 320 | |
Mark Salyzyn | 34fb296 | 2014-06-18 16:30:56 -0700 | [diff] [blame] | 321 | ALOGV("getFrameCount() output %d, frameCount %zu", output, *frameCount); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 322 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | return NO_ERROR; |
| 324 | } |
| 325 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 326 | status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 328 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 330 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 331 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 332 | } |
Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 333 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 334 | output = getOutput(streamType); |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 335 | if (output == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 336 | return PERMISSION_DENIED; |
| 337 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | |
Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 339 | return getLatency(output, latency); |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | status_t AudioSystem::getLatency(audio_io_handle_t output, |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 343 | uint32_t* latency) |
| 344 | { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 345 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 346 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 347 | sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output); |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 348 | if (outputDesc == 0) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 349 | *latency = af->latency(output); |
| 350 | } else { |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 351 | *latency = outputDesc->mLatency; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 354 | ALOGV("getLatency() output %d, latency %d", output, *latency); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 355 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | return NO_ERROR; |
| 357 | } |
| 358 | |
Glenn Kasten | dd8104c | 2012-07-02 12:42:44 -0700 | [diff] [blame] | 359 | status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format, |
| 360 | audio_channel_mask_t channelMask, size_t* buffSize) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 362 | 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 Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Eric Laurent | f0ee6f4 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 369 | status_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 PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 376 | status_t AudioSystem::getRenderPosition(audio_io_handle_t output, uint32_t *halFrames, |
Glenn Kasten | 0ed1959 | 2014-03-26 07:50:05 -0700 | [diff] [blame] | 377 | uint32_t *dspFrames) |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 378 | { |
| 379 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 380 | if (af == 0) return PERMISSION_DENIED; |
| 381 | |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 382 | return af->getRenderPosition(halFrames, dspFrames, output); |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 385 | uint32_t AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) |
| 386 | { |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 387 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 388 | uint32_t result = 0; |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 389 | if (af == 0) return result; |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 390 | if (ioHandle == AUDIO_IO_HANDLE_NONE) return result; |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 391 | |
| 392 | result = af->getInputFramesLost(ioHandle); |
| 393 | return result; |
| 394 | } |
| 395 | |
Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 396 | audio_unique_id_t AudioSystem::newAudioUniqueId() |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 397 | { |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 398 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 399 | if (af == 0) return AUDIO_UNIQUE_ID_ALLOCATE; |
| 400 | return af->newAudioUniqueId(); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 403 | void AudioSystem::acquireAudioSessionId(int audioSession, pid_t pid) |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 404 | { |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 405 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 406 | if (af != 0) { |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 407 | af->acquireAudioSessionId(audioSession, pid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 411 | void AudioSystem::releaseAudioSessionId(int audioSession, pid_t pid) |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 412 | { |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 413 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 414 | if (af != 0) { |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 415 | af->releaseAudioSessionId(audioSession, pid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 419 | audio_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 Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | // --------------------------------------------------------------------------- |
| 427 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 428 | |
| 429 | void 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 Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 439 | void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who __unused) |
| 440 | { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 441 | audio_error_callback cb = NULL; |
| 442 | { |
| 443 | Mutex::Autolock _l(AudioSystem::gLock); |
| 444 | AudioSystem::gAudioFlinger.clear(); |
| 445 | cb = gAudioErrorCallback; |
| 446 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 448 | // clear output handles and stream to output map caches |
| 449 | clearIoCache(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 451 | if (cb) { |
| 452 | cb(DEAD_OBJECT); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | } |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 454 | ALOGW("AudioFlinger server died!"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | } |
| 456 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 457 | void AudioSystem::AudioFlingerClient::ioConfigChanged(audio_io_config_event event, |
| 458 | const sp<AudioIoDescriptor>& ioDesc) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 459 | ALOGV("ioConfigChanged() event %d", event); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 460 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 461 | if (ioDesc == 0 || ioDesc->mIoHandle == AUDIO_IO_HANDLE_NONE) return; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 462 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 463 | audio_port_handle_t deviceId = AUDIO_PORT_HANDLE_NONE; |
| 464 | Vector < sp<AudioDeviceCallback> > callbacks; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 465 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 466 | { |
| 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 Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 498 | event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 499 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 500 | 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 Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 528 | } break; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 529 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 530 | } |
| 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 Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 534 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | } |
| 536 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 537 | status_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 | |
| 569 | sp<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 Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 579 | status_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 | |
| 600 | status_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 Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 629 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 630 | Mutex::Autolock _l(gLock); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | gAudioErrorCallback = cb; |
| 632 | } |
| 633 | |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 634 | /*static*/ void AudioSystem::setDynPolicyCallback(dynamic_policy_callback cb) |
| 635 | { |
| 636 | Mutex::Autolock _l(gLock); |
| 637 | gDynPolicyCallback = cb; |
| 638 | } |
| 639 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 640 | // client singleton for AudioPolicyService binder interface |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 641 | // protected by gLockAPS |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 642 | sp<IAudioPolicyService> AudioSystem::gAudioPolicyService; |
| 643 | sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient; |
| 644 | |
| 645 | |
Glenn Kasten | 18a6d90 | 2012-09-24 11:27:56 -0700 | [diff] [blame] | 646 | // establish binder interface to AudioPolicy service |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 647 | const sp<IAudioPolicyService> AudioSystem::get_audio_policy_service() |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 648 | { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 649 | 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 Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 670 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 671 | ap = gAudioPolicyService; |
| 672 | } |
| 673 | if (apc != 0) { |
| 674 | ap->registerClient(apc); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 675 | } |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 676 | |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 677 | return ap; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Glenn Kasten | fb1fdc9 | 2013-07-10 17:03:19 -0700 | [diff] [blame] | 680 | // --------------------------------------------------------------------------- |
| 681 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 682 | status_t AudioSystem::setDeviceConnectionState(audio_devices_t device, |
| 683 | audio_policy_dev_state_t state, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 684 | const char *device_address, |
| 685 | const char *device_name) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 686 | { |
| 687 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 688 | const char *address = ""; |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 689 | const char *name = ""; |
Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 690 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 691 | if (aps == 0) return PERMISSION_DENIED; |
| 692 | |
Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 693 | if (device_address != NULL) { |
| 694 | address = device_address; |
| 695 | } |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 696 | if (device_name != NULL) { |
| 697 | name = device_name; |
| 698 | } |
| 699 | return aps->setDeviceConnectionState(device, state, address, name); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 702 | audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 703 | const char *device_address) |
| 704 | { |
| 705 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 706 | if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 707 | |
| 708 | return aps->getDeviceConnectionState(device, device_address); |
| 709 | } |
| 710 | |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 711 | status_t AudioSystem::setPhoneState(audio_mode_t state) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 712 | { |
Glenn Kasten | 347966c | 2012-01-18 14:58:32 -0800 | [diff] [blame] | 713 | if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 714 | 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 Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 720 | status_t AudioSystem::setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 721 | { |
| 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 Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 727 | audio_policy_forced_cfg_t AudioSystem::getForceUse(audio_policy_force_use_t usage) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 728 | { |
| 729 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 730 | if (aps == 0) return AUDIO_POLICY_FORCE_NONE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 731 | return aps->getForceUse(usage); |
| 732 | } |
| 733 | |
| 734 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 735 | audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 736 | uint32_t samplingRate, |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 737 | audio_format_t format, |
Glenn Kasten | 254af18 | 2012-07-03 14:59:05 -0700 | [diff] [blame] | 738 | audio_channel_mask_t channelMask, |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 739 | audio_output_flags_t flags, |
| 740 | const audio_offload_info_t *offloadInfo) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 741 | { |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 742 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 743 | if (aps == 0) return 0; |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 744 | return aps->getOutput(stream, samplingRate, format, channelMask, flags, offloadInfo); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 747 | status_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 Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 751 | uid_t uid, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 752 | uint32_t samplingRate, |
| 753 | audio_format_t format, |
| 754 | audio_channel_mask_t channelMask, |
| 755 | audio_output_flags_t flags, |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 756 | audio_port_handle_t selectedDeviceId, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 757 | const audio_offload_info_t *offloadInfo) |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 758 | { |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 759 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 760 | if (aps == 0) return NO_INIT; |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 761 | return aps->getOutputForAttr(attr, output, session, stream, uid, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 762 | samplingRate, format, channelMask, |
Paul McLean | aa98119 | 2015-03-21 09:55:15 -0700 | [diff] [blame] | 763 | flags, selectedDeviceId, offloadInfo); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 766 | status_t AudioSystem::startOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 767 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 768 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 769 | { |
| 770 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 771 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 772 | return aps->startOutput(output, stream, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 775 | status_t AudioSystem::stopOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 776 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 777 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 778 | { |
| 779 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 780 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 781 | return aps->stopOutput(output, stream, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 784 | void AudioSystem::releaseOutput(audio_io_handle_t output, |
| 785 | audio_stream_type_t stream, |
| 786 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 787 | { |
| 788 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 789 | if (aps == 0) return; |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 790 | aps->releaseOutput(output, stream, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 793 | status_t AudioSystem::getInputForAttr(const audio_attributes_t *attr, |
| 794 | audio_io_handle_t *input, |
| 795 | audio_session_t session, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 796 | uid_t uid, |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 797 | uint32_t samplingRate, |
| 798 | audio_format_t format, |
| 799 | audio_channel_mask_t channelMask, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 800 | audio_input_flags_t flags, |
| 801 | audio_port_handle_t selectedDeviceId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 802 | { |
| 803 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 804 | if (aps == 0) return NO_INIT; |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 805 | return aps->getInputForAttr( |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 806 | attr, input, session, uid, samplingRate, format, channelMask, flags, selectedDeviceId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 809 | status_t AudioSystem::startInput(audio_io_handle_t input, |
| 810 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 811 | { |
| 812 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 813 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 814 | return aps->startInput(input, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 817 | status_t AudioSystem::stopInput(audio_io_handle_t input, |
| 818 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 819 | { |
| 820 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 821 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 822 | return aps->stopInput(input, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 825 | void AudioSystem::releaseInput(audio_io_handle_t input, |
| 826 | audio_session_t session) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 827 | { |
| 828 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 829 | if (aps == 0) return; |
Eric Laurent | 4dc6806 | 2014-07-28 17:26:49 -0700 | [diff] [blame] | 830 | aps->releaseInput(input, session); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 833 | status_t AudioSystem::initStreamVolume(audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 834 | 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 Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 842 | status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream, |
| 843 | int index, |
| 844 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 845 | { |
| 846 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 847 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 848 | return aps->setStreamVolumeIndex(stream, index, device); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 851 | status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream, |
| 852 | int *index, |
| 853 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 854 | { |
| 855 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 856 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 857 | return aps->getStreamVolumeIndex(stream, index, device); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 860 | uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 861 | { |
| 862 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 863 | if (aps == 0) return 0; |
| 864 | return aps->getStrategyForStream(stream); |
| 865 | } |
| 866 | |
Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 867 | audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream) |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 868 | { |
| 869 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Glenn Kasten | 45faf7e | 2014-01-17 10:23:01 -0800 | [diff] [blame] | 870 | if (aps == 0) return AUDIO_DEVICE_NONE; |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 871 | return aps->getDevicesForStream(stream); |
| 872 | } |
| 873 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 874 | audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t *desc) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 875 | { |
| 876 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Glenn Kasten | efa6ea9 | 2014-01-08 09:10:43 -0800 | [diff] [blame] | 877 | // FIXME change return type to status_t, and return PERMISSION_DENIED here |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 878 | if (aps == 0) return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 879 | return aps->getOutputForEffect(desc); |
| 880 | } |
| 881 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 882 | status_t AudioSystem::registerEffect(const effect_descriptor_t *desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 883 | audio_io_handle_t io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 884 | 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 Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 890 | return aps->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | status_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 Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 900 | status_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 Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 907 | status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs) |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 908 | { |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 909 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 910 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 911 | if (state == NULL) return BAD_VALUE; |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 912 | *state = aps->isStreamActive(stream, inPastMs); |
| 913 | return NO_ERROR; |
| 914 | } |
| 915 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 916 | status_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 Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 926 | status_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 Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 935 | uint32_t AudioSystem::getPrimaryOutputSamplingRate() |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 936 | { |
| 937 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 938 | if (af == 0) return 0; |
| 939 | return af->getPrimaryOutputSamplingRate(); |
| 940 | } |
| 941 | |
Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 942 | size_t AudioSystem::getPrimaryOutputFrameCount() |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 943 | { |
| 944 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 945 | if (af == 0) return 0; |
| 946 | return af->getPrimaryOutputFrameCount(); |
| 947 | } |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 948 | |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 949 | status_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 Laurent | 9f6530f | 2011-08-30 10:18:54 -0700 | [diff] [blame] | 956 | void AudioSystem::clearAudioConfigCache() |
| 957 | { |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 958 | // called by restoreTrack_l(), which needs new IAudioFlinger and IAudioPolicyService instances |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 959 | ALOGV("clearAudioConfigCache()"); |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 960 | { |
| 961 | Mutex::Autolock _l(gLock); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 962 | if (gAudioFlingerClient != 0) { |
| 963 | gAudioFlingerClient->clearIoCache(); |
| 964 | } |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 965 | gAudioFlinger.clear(); |
| 966 | } |
| 967 | { |
| 968 | Mutex::Autolock _l(gLockAPS); |
| 969 | gAudioPolicyService.clear(); |
| 970 | } |
Eric Laurent | 9f6530f | 2011-08-30 10:18:54 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 973 | bool 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 Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 981 | status_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 | |
| 992 | status_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 | |
| 999 | status_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 | |
| 1007 | status_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 | |
| 1014 | status_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 | |
| 1023 | status_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 Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1030 | status_t AudioSystem::addAudioPortCallback(const sp<AudioPortCallback>& callback) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1031 | { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1032 | 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 Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1039 | return gAudioPolicyServiceClient->addAudioPortCallback(callback); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 1042 | /*static*/ |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1043 | status_t AudioSystem::removeAudioPortCallback(const sp<AudioPortCallback>& callback) |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1044 | { |
| 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 Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1052 | return gAudioPolicyServiceClient->removeAudioPortCallback(callback); |
| 1053 | } |
| 1054 | |
| 1055 | status_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 | |
| 1065 | status_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 | |
| 1075 | audio_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 Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1086 | status_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 | |
| 1095 | status_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 Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1101 | |
| 1102 | audio_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 Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1109 | status_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 Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1115 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1116 | status_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 | |
| 1125 | status_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 Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1132 | // --------------------------------------------------------------------------- |
| 1133 | |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1134 | status_t AudioSystem::AudioPolicyServiceClient::addAudioPortCallback( |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1135 | const sp<AudioPortCallback>& callback) |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1136 | { |
| 1137 | Mutex::Autolock _l(mLock); |
| 1138 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1139 | if (mAudioPortCallbacks[i] == callback) { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1140 | return INVALID_OPERATION; |
| 1141 | } |
| 1142 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1143 | mAudioPortCallbacks.add(callback); |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1144 | return NO_ERROR; |
| 1145 | } |
| 1146 | |
| 1147 | status_t AudioSystem::AudioPolicyServiceClient::removeAudioPortCallback( |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1148 | const sp<AudioPortCallback>& callback) |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1149 | { |
| 1150 | Mutex::Autolock _l(mLock); |
| 1151 | size_t i; |
| 1152 | for (i = 0; i < mAudioPortCallbacks.size(); i++) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1153 | if (mAudioPortCallbacks[i] == callback) { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1154 | break; |
| 1155 | } |
| 1156 | } |
| 1157 | if (i == mAudioPortCallbacks.size()) { |
| 1158 | return INVALID_OPERATION; |
| 1159 | } |
| 1160 | mAudioPortCallbacks.removeAt(i); |
| 1161 | return NO_ERROR; |
| 1162 | } |
| 1163 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame^] | 1164 | |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1165 | void 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 | |
| 1173 | void 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 Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1181 | void AudioSystem::AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate( |
| 1182 | String8 regId, int32_t state) |
| 1183 | { |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 1184 | 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 Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 1196 | void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who __unused) |
| 1197 | { |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1198 | { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1199 | Mutex::Autolock _l(mLock); |
| 1200 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 1201 | mAudioPortCallbacks[i]->onServiceDied(); |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1202 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1203 | } |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1204 | { |
| 1205 | Mutex::Autolock _l(gLockAPS); |
| 1206 | AudioSystem::gAudioPolicyService.clear(); |
| 1207 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1208 | |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1209 | ALOGW("AudioPolicyService server died!"); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 1212 | } // namespace android |