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> |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame^] | 21 | |
| 22 | #include <android/media/BnCaptureStateListener.h> |
Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <binder/IServiceManager.h> |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 24 | #include <binder/ProcessState.h> |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 25 | #include <binder/IPCThreadState.h> |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 26 | #include <media/AudioResamplerPublic.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <media/AudioSystem.h> |
Glenn Kasten | 1ab85ec | 2013-05-31 09:18:43 -0700 | [diff] [blame] | 28 | #include <media/IAudioFlinger.h> |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 29 | #include <media/IAudioPolicyService.h> |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 30 | #include <media/TypeConverter.h> |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | #include <math.h> |
| 32 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 33 | #include <system/audio.h> |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 34 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 35 | // ---------------------------------------------------------------------------- |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 36 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | namespace android { |
| 38 | |
| 39 | // client singleton for AudioFlinger binder interface |
| 40 | Mutex AudioSystem::gLock; |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 41 | Mutex AudioSystem::gLockErrorCallbacks; |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 42 | Mutex AudioSystem::gLockAPS; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | sp<IAudioFlinger> AudioSystem::gAudioFlinger; |
| 44 | sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient; |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 45 | std::set<audio_error_callback> AudioSystem::gAudioErrorCallbacks; |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 46 | dynamic_policy_callback AudioSystem::gDynPolicyCallback = NULL; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 47 | record_config_callback AudioSystem::gRecordConfigCallback = NULL; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame^] | 49 | // Required to be held while calling into gSoundTriggerCaptureStateListener. |
| 50 | Mutex gSoundTriggerCaptureStateListenerLock; |
| 51 | sp<AudioSystem::CaptureStateListener> gSoundTriggerCaptureStateListener = nullptr; |
| 52 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | // establish binder interface to AudioFlinger service |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 54 | const sp<IAudioFlinger> AudioSystem::get_audio_flinger() |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 56 | sp<IAudioFlinger> af; |
| 57 | sp<AudioFlingerClient> afc; |
| 58 | { |
| 59 | Mutex::Autolock _l(gLock); |
| 60 | if (gAudioFlinger == 0) { |
| 61 | sp<IServiceManager> sm = defaultServiceManager(); |
| 62 | sp<IBinder> binder; |
| 63 | do { |
| 64 | binder = sm->getService(String16("media.audio_flinger")); |
| 65 | if (binder != 0) |
| 66 | break; |
| 67 | ALOGW("AudioFlinger not published, waiting..."); |
| 68 | usleep(500000); // 0.5 s |
| 69 | } while (true); |
| 70 | if (gAudioFlingerClient == NULL) { |
| 71 | gAudioFlingerClient = new AudioFlingerClient(); |
| 72 | } else { |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 73 | reportError(NO_ERROR); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 75 | binder->linkToDeath(gAudioFlingerClient); |
| 76 | gAudioFlinger = interface_cast<IAudioFlinger>(binder); |
| 77 | LOG_ALWAYS_FATAL_IF(gAudioFlinger == 0); |
| 78 | afc = gAudioFlingerClient; |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 79 | // Make sure callbacks can be received by gAudioFlingerClient |
| 80 | ProcessState::self()->startThreadPool(); |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 81 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 82 | af = gAudioFlinger; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 84 | if (afc != 0) { |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 85 | int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 86 | af->registerClient(afc); |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 87 | IPCThreadState::self()->restoreCallingIdentity(token); |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 88 | } |
| 89 | return af; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 92 | const sp<AudioSystem::AudioFlingerClient> AudioSystem::getAudioFlingerClient() |
| 93 | { |
| 94 | // calling get_audio_flinger() will initialize gAudioFlingerClient if needed |
| 95 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 96 | if (af == 0) return 0; |
| 97 | Mutex::Autolock _l(gLock); |
| 98 | return gAudioFlingerClient; |
| 99 | } |
| 100 | |
| 101 | sp<AudioIoDescriptor> AudioSystem::getIoDescriptor(audio_io_handle_t ioHandle) |
| 102 | { |
| 103 | sp<AudioIoDescriptor> desc; |
| 104 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 105 | if (afc != 0) { |
| 106 | desc = afc->getIoDescriptor(ioHandle); |
| 107 | } |
| 108 | return desc; |
| 109 | } |
| 110 | |
Eric Laurent | 4629161 | 2013-07-18 14:38:44 -0700 | [diff] [blame] | 111 | /* static */ status_t AudioSystem::checkAudioFlinger() |
| 112 | { |
| 113 | if (defaultServiceManager()->checkService(String16("media.audio_flinger")) != 0) { |
| 114 | return NO_ERROR; |
| 115 | } |
| 116 | return DEAD_OBJECT; |
| 117 | } |
| 118 | |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 119 | // FIXME Declare in binder opcode order, similarly to IAudioFlinger.h and IAudioFlinger.cpp |
| 120 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 121 | status_t AudioSystem::muteMicrophone(bool state) |
| 122 | { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 124 | if (af == 0) return PERMISSION_DENIED; |
| 125 | return af->setMicMute(state); |
| 126 | } |
| 127 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 128 | status_t AudioSystem::isMicrophoneMuted(bool* state) |
| 129 | { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 131 | if (af == 0) return PERMISSION_DENIED; |
| 132 | *state = af->getMicMute(); |
| 133 | return NO_ERROR; |
| 134 | } |
| 135 | |
| 136 | status_t AudioSystem::setMasterVolume(float value) |
| 137 | { |
| 138 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 139 | if (af == 0) return PERMISSION_DENIED; |
| 140 | af->setMasterVolume(value); |
| 141 | return NO_ERROR; |
| 142 | } |
| 143 | |
| 144 | status_t AudioSystem::setMasterMute(bool mute) |
| 145 | { |
| 146 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 147 | if (af == 0) return PERMISSION_DENIED; |
| 148 | af->setMasterMute(mute); |
| 149 | return NO_ERROR; |
| 150 | } |
| 151 | |
| 152 | status_t AudioSystem::getMasterVolume(float* volume) |
| 153 | { |
| 154 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 155 | if (af == 0) return PERMISSION_DENIED; |
| 156 | *volume = af->masterVolume(); |
| 157 | return NO_ERROR; |
| 158 | } |
| 159 | |
| 160 | status_t AudioSystem::getMasterMute(bool* mute) |
| 161 | { |
| 162 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 163 | if (af == 0) return PERMISSION_DENIED; |
| 164 | *mute = af->masterMute(); |
| 165 | return NO_ERROR; |
| 166 | } |
| 167 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 168 | status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value, |
| 169 | audio_io_handle_t output) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 171 | 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] | 172 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 173 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 174 | af->setStreamVolume(stream, value, output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | return NO_ERROR; |
| 176 | } |
| 177 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 178 | 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] | 179 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 180 | 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] | 181 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 182 | if (af == 0) return PERMISSION_DENIED; |
| 183 | af->setStreamMute(stream, mute); |
| 184 | return NO_ERROR; |
| 185 | } |
| 186 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 187 | status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume, |
| 188 | audio_io_handle_t output) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 190 | 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] | 191 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 192 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 193 | *volume = af->streamVolume(stream, output); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | return NO_ERROR; |
| 195 | } |
| 196 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 197 | 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] | 198 | { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 199 | 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] | 200 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 201 | if (af == 0) return PERMISSION_DENIED; |
| 202 | *mute = af->streamMute(stream); |
| 203 | return NO_ERROR; |
| 204 | } |
| 205 | |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 206 | status_t AudioSystem::setMode(audio_mode_t mode) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | { |
Glenn Kasten | 930f4ca | 2012-01-06 16:47:31 -0800 | [diff] [blame] | 208 | 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] | 209 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 210 | if (af == 0) return PERMISSION_DENIED; |
| 211 | return af->setMode(mode); |
| 212 | } |
| 213 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 214 | status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) |
| 215 | { |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 217 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 218 | return af->setParameters(ioHandle, keyValuePairs); |
| 219 | } |
| 220 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 221 | String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys) |
| 222 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 223 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 224 | String8 result = String8(""); |
| 225 | if (af == 0) return result; |
| 226 | |
| 227 | result = af->getParameters(ioHandle, keys); |
| 228 | return result; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 231 | status_t AudioSystem::setParameters(const String8& keyValuePairs) |
| 232 | { |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 233 | return setParameters(AUDIO_IO_HANDLE_NONE, keyValuePairs); |
Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | String8 AudioSystem::getParameters(const String8& keys) |
| 237 | { |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 238 | return getParameters(AUDIO_IO_HANDLE_NONE, keys); |
Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 239 | } |
| 240 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | // convert volume steps to natural log scale |
| 242 | |
| 243 | // change this value to change volume scaling |
| 244 | static const float dBPerStep = 0.5f; |
| 245 | // shouldn't need to touch these |
| 246 | static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f; |
| 247 | static const float dBConvertInverse = 1.0f / dBConvert; |
| 248 | |
| 249 | float AudioSystem::linearToLog(int volume) |
| 250 | { |
| 251 | // float v = volume ? exp(float(100 - volume) * dBConvert) : 0; |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 252 | // ALOGD("linearToLog(%d)=%f", volume, v); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | // return v; |
| 254 | return volume ? exp(float(100 - volume) * dBConvert) : 0; |
| 255 | } |
| 256 | |
| 257 | int AudioSystem::logToLinear(float volume) |
| 258 | { |
| 259 | // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 260 | // ALOGD("logTolinear(%d)=%f", v, volume); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | // return v; |
| 262 | return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
| 263 | } |
| 264 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 265 | /* static */ size_t AudioSystem::calculateMinFrameCount( |
| 266 | uint32_t afLatencyMs, uint32_t afFrameCount, uint32_t afSampleRate, |
| 267 | uint32_t sampleRate, float speed /*, uint32_t notificationsPerBufferReq*/) |
| 268 | { |
| 269 | // Ensure that buffer depth covers at least audio hardware latency |
| 270 | uint32_t minBufCount = afLatencyMs / ((1000 * afFrameCount) / afSampleRate); |
| 271 | if (minBufCount < 2) { |
| 272 | minBufCount = 2; |
| 273 | } |
| 274 | #if 0 |
| 275 | // The notificationsPerBufferReq parameter is not yet used for non-fast tracks, |
| 276 | // but keeping the code here to make it easier to add later. |
| 277 | if (minBufCount < notificationsPerBufferReq) { |
| 278 | minBufCount = notificationsPerBufferReq; |
| 279 | } |
| 280 | #endif |
| 281 | ALOGV("calculateMinFrameCount afLatency %u afFrameCount %u afSampleRate %u " |
| 282 | "sampleRate %u speed %f minBufCount: %u" /*" notificationsPerBufferReq %u"*/, |
| 283 | afLatencyMs, afFrameCount, afSampleRate, sampleRate, speed, minBufCount |
| 284 | /*, notificationsPerBufferReq*/); |
| 285 | return minBufCount * sourceFramesNeededWithTimestretch( |
| 286 | sampleRate, afFrameCount, afSampleRate, speed); |
| 287 | } |
| 288 | |
| 289 | |
Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 290 | 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] | 291 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 292 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 294 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 295 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 298 | output = getOutput(streamType); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 299 | if (output == 0) { |
| 300 | return PERMISSION_DENIED; |
| 301 | } |
| 302 | |
Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 303 | return getSamplingRate(output, samplingRate); |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 306 | status_t AudioSystem::getSamplingRate(audio_io_handle_t ioHandle, |
Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 307 | uint32_t* samplingRate) |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 308 | { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 309 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 310 | if (af == 0) return PERMISSION_DENIED; |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 311 | sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); |
| 312 | if (desc == 0) { |
| 313 | *samplingRate = af->sampleRate(ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 314 | } else { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 315 | *samplingRate = desc->mSamplingRate; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 316 | } |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 317 | if (*samplingRate == 0) { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 318 | ALOGE("AudioSystem::getSamplingRate failed for ioHandle %d", ioHandle); |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 319 | return BAD_VALUE; |
| 320 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 321 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 322 | ALOGV("getSamplingRate() ioHandle %d, sampling rate %u", ioHandle, *samplingRate); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 323 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | return NO_ERROR; |
| 325 | } |
| 326 | |
Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 327 | 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] | 328 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 329 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 331 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 332 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 333 | } |
Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 334 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 335 | output = getOutput(streamType); |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 336 | if (output == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 337 | return PERMISSION_DENIED; |
| 338 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | |
Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 340 | return getFrameCount(output, frameCount); |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 343 | status_t AudioSystem::getFrameCount(audio_io_handle_t ioHandle, |
Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 344 | size_t* frameCount) |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 345 | { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 346 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 347 | if (af == 0) return PERMISSION_DENIED; |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 348 | sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); |
| 349 | if (desc == 0) { |
| 350 | *frameCount = af->frameCount(ioHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 351 | } else { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 352 | *frameCount = desc->mFrameCount; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 353 | } |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 354 | if (*frameCount == 0) { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 355 | ALOGE("AudioSystem::getFrameCount failed for ioHandle %d", ioHandle); |
Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 356 | return BAD_VALUE; |
| 357 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 358 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 359 | ALOGV("getFrameCount() ioHandle %d, frameCount %zu", ioHandle, *frameCount); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 360 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | return NO_ERROR; |
| 362 | } |
| 363 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 364 | 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] | 365 | { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 366 | audio_io_handle_t output; |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 368 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 369 | streamType = AUDIO_STREAM_MUSIC; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 370 | } |
Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 371 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 372 | output = getOutput(streamType); |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 373 | if (output == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 374 | return PERMISSION_DENIED; |
| 375 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | |
Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 377 | return getLatency(output, latency); |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | status_t AudioSystem::getLatency(audio_io_handle_t output, |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 381 | uint32_t* latency) |
| 382 | { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 383 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 384 | if (af == 0) return PERMISSION_DENIED; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 385 | sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output); |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 386 | if (outputDesc == 0) { |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 387 | *latency = af->latency(output); |
| 388 | } else { |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 389 | *latency = outputDesc->mLatency; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 392 | ALOGV("getLatency() output %d, latency %d", output, *latency); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 393 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | return NO_ERROR; |
| 395 | } |
| 396 | |
Glenn Kasten | dd8104c | 2012-07-02 12:42:44 -0700 | [diff] [blame] | 397 | status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format, |
| 398 | audio_channel_mask_t channelMask, size_t* buffSize) |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 400 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 401 | if (afc == 0) { |
| 402 | return NO_INIT; |
| 403 | } |
| 404 | return afc->getInputBufferSize(sampleRate, format, channelMask, buffSize); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Eric Laurent | f0ee6f4 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 407 | status_t AudioSystem::setVoiceVolume(float value) |
| 408 | { |
| 409 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 410 | if (af == 0) return PERMISSION_DENIED; |
| 411 | return af->setVoiceVolume(value); |
| 412 | } |
| 413 | |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 414 | status_t AudioSystem::getRenderPosition(audio_io_handle_t output, uint32_t *halFrames, |
Glenn Kasten | 0ed1959 | 2014-03-26 07:50:05 -0700 | [diff] [blame] | 415 | uint32_t *dspFrames) |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 416 | { |
| 417 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 418 | if (af == 0) return PERMISSION_DENIED; |
| 419 | |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 420 | return af->getRenderPosition(halFrames, dspFrames, output); |
Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 421 | } |
| 422 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 423 | uint32_t AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) |
| 424 | { |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 425 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 426 | uint32_t result = 0; |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 427 | if (af == 0) return result; |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 428 | if (ioHandle == AUDIO_IO_HANDLE_NONE) return result; |
Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 429 | |
| 430 | result = af->getInputFramesLost(ioHandle); |
| 431 | return result; |
| 432 | } |
| 433 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 434 | audio_unique_id_t AudioSystem::newAudioUniqueId(audio_unique_id_use_t use) |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 435 | { |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 436 | // Must not use AF as IDs will re-roll on audioserver restart, b/130369529. |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 437 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 438 | if (af == 0) return AUDIO_UNIQUE_ID_ALLOCATE; |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 439 | return af->newAudioUniqueId(use); |
Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 442 | void AudioSystem::acquireAudioSessionId(audio_session_t audioSession, pid_t pid, uid_t uid) |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 443 | { |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 444 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 445 | if (af != 0) { |
Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 446 | af->acquireAudioSessionId(audioSession, pid, uid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 450 | void AudioSystem::releaseAudioSessionId(audio_session_t audioSession, pid_t pid) |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 451 | { |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 452 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 453 | if (af != 0) { |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 454 | af->releaseAudioSessionId(audioSession, pid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 458 | audio_hw_sync_t AudioSystem::getAudioHwSyncForSession(audio_session_t sessionId) |
| 459 | { |
| 460 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 461 | if (af == 0) return AUDIO_HW_SYNC_INVALID; |
| 462 | return af->getAudioHwSyncForSession(sessionId); |
| 463 | } |
| 464 | |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 465 | status_t AudioSystem::systemReady() |
| 466 | { |
| 467 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 468 | if (af == 0) return NO_INIT; |
| 469 | return af->systemReady(); |
| 470 | } |
| 471 | |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 472 | status_t AudioSystem::getFrameCountHAL(audio_io_handle_t ioHandle, |
| 473 | size_t* frameCount) |
| 474 | { |
| 475 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 476 | if (af == 0) return PERMISSION_DENIED; |
| 477 | sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); |
| 478 | if (desc == 0) { |
| 479 | *frameCount = af->frameCountHAL(ioHandle); |
| 480 | } else { |
| 481 | *frameCount = desc->mFrameCountHAL; |
| 482 | } |
| 483 | if (*frameCount == 0) { |
| 484 | ALOGE("AudioSystem::getFrameCountHAL failed for ioHandle %d", ioHandle); |
| 485 | return BAD_VALUE; |
| 486 | } |
| 487 | |
| 488 | ALOGV("getFrameCountHAL() ioHandle %d, frameCount %zu", ioHandle, *frameCount); |
| 489 | |
| 490 | return NO_ERROR; |
| 491 | } |
| 492 | |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | // --------------------------------------------------------------------------- |
| 494 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 495 | |
| 496 | void AudioSystem::AudioFlingerClient::clearIoCache() |
| 497 | { |
| 498 | Mutex::Autolock _l(mLock); |
| 499 | mIoDescriptors.clear(); |
| 500 | mInBuffSize = 0; |
| 501 | mInSamplingRate = 0; |
| 502 | mInFormat = AUDIO_FORMAT_DEFAULT; |
| 503 | mInChannelMask = AUDIO_CHANNEL_NONE; |
| 504 | } |
| 505 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 506 | void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who __unused) |
| 507 | { |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 508 | { |
| 509 | Mutex::Autolock _l(AudioSystem::gLock); |
| 510 | AudioSystem::gAudioFlinger.clear(); |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 511 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 513 | // clear output handles and stream to output map caches |
| 514 | clearIoCache(); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 516 | reportError(DEAD_OBJECT); |
| 517 | |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 518 | ALOGW("AudioFlinger server died!"); |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 521 | void AudioSystem::AudioFlingerClient::ioConfigChanged(audio_io_config_event event, |
| 522 | const sp<AudioIoDescriptor>& ioDesc) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 523 | ALOGV("ioConfigChanged() event %d", event); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 524 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 525 | if (ioDesc == 0 || ioDesc->mIoHandle == AUDIO_IO_HANDLE_NONE) return; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 526 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 527 | audio_port_handle_t deviceId = AUDIO_PORT_HANDLE_NONE; |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 528 | std::vector<sp<AudioDeviceCallback>> callbacksToCall; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 529 | { |
| 530 | Mutex::Autolock _l(mLock); |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 531 | auto callbacks = std::map<audio_port_handle_t, wp<AudioDeviceCallback>>(); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 532 | |
| 533 | switch (event) { |
| 534 | case AUDIO_OUTPUT_OPENED: |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 535 | case AUDIO_OUTPUT_REGISTERED: |
| 536 | case AUDIO_INPUT_OPENED: |
| 537 | case AUDIO_INPUT_REGISTERED: { |
Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 538 | sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle); |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 539 | if (oldDesc == 0) { |
| 540 | mIoDescriptors.add(ioDesc->mIoHandle, ioDesc); |
| 541 | } else { |
| 542 | deviceId = oldDesc->getDeviceId(); |
| 543 | mIoDescriptors.replaceValueFor(ioDesc->mIoHandle, ioDesc); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 544 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 545 | |
| 546 | if (ioDesc->getDeviceId() != AUDIO_PORT_HANDLE_NONE) { |
| 547 | deviceId = ioDesc->getDeviceId(); |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 548 | if (event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED) { |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 549 | auto it = mAudioDeviceCallbacks.find(ioDesc->mIoHandle); |
| 550 | if (it != mAudioDeviceCallbacks.end()) { |
| 551 | callbacks = it->second; |
Francois Gaffie | 24a9fb0 | 2019-01-18 17:51:34 +0100 | [diff] [blame] | 552 | } |
| 553 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 554 | } |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 555 | ALOGV("ioConfigChanged() new %s %s %d samplingRate %u, format %#x channel mask %#x " |
| 556 | "frameCount %zu deviceId %d", |
| 557 | event == AUDIO_OUTPUT_OPENED || event == AUDIO_OUTPUT_REGISTERED ? |
| 558 | "output" : "input", |
| 559 | event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED ? |
| 560 | "opened" : "registered", |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 561 | ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat, ioDesc->mChannelMask, |
| 562 | ioDesc->mFrameCount, ioDesc->getDeviceId()); |
| 563 | } break; |
| 564 | case AUDIO_OUTPUT_CLOSED: |
| 565 | case AUDIO_INPUT_CLOSED: { |
Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 566 | if (getIoDescriptor_l(ioDesc->mIoHandle) == 0) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 567 | ALOGW("ioConfigChanged() closing unknown %s %d", |
| 568 | event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle); |
| 569 | break; |
| 570 | } |
| 571 | ALOGV("ioConfigChanged() %s %d closed", |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 572 | event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 573 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 574 | mIoDescriptors.removeItem(ioDesc->mIoHandle); |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 575 | mAudioDeviceCallbacks.erase(ioDesc->mIoHandle); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 576 | } break; |
| 577 | |
| 578 | case AUDIO_OUTPUT_CONFIG_CHANGED: |
| 579 | case AUDIO_INPUT_CONFIG_CHANGED: { |
Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 580 | sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 581 | if (oldDesc == 0) { |
| 582 | ALOGW("ioConfigChanged() modifying unknown output! %d", ioDesc->mIoHandle); |
| 583 | break; |
| 584 | } |
| 585 | |
| 586 | deviceId = oldDesc->getDeviceId(); |
| 587 | mIoDescriptors.replaceValueFor(ioDesc->mIoHandle, ioDesc); |
| 588 | |
| 589 | if (deviceId != ioDesc->getDeviceId()) { |
| 590 | deviceId = ioDesc->getDeviceId(); |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 591 | auto it = mAudioDeviceCallbacks.find(ioDesc->mIoHandle); |
| 592 | if (it != mAudioDeviceCallbacks.end()) { |
| 593 | callbacks = it->second; |
| 594 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 595 | } |
| 596 | ALOGV("ioConfigChanged() new config for %s %d samplingRate %u, format %#x " |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 597 | "channel mask %#x frameCount %zu frameCountHAL %zu deviceId %d", |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 598 | event == AUDIO_OUTPUT_CONFIG_CHANGED ? "output" : "input", |
| 599 | ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat, |
Glenn Kasten | d3bb645 | 2016-12-05 18:14:37 -0800 | [diff] [blame] | 600 | ioDesc->mChannelMask, ioDesc->mFrameCount, ioDesc->mFrameCountHAL, |
| 601 | ioDesc->getDeviceId()); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 602 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 603 | } break; |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 604 | case AUDIO_CLIENT_STARTED: { |
| 605 | sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle); |
| 606 | if (oldDesc == 0) { |
| 607 | ALOGW("ioConfigChanged() start client on unknown io! %d", ioDesc->mIoHandle); |
| 608 | break; |
| 609 | } |
| 610 | ALOGV("ioConfigChanged() AUDIO_CLIENT_STARTED io %d port %d num callbacks %zu", |
| 611 | ioDesc->mIoHandle, ioDesc->mPortId, mAudioDeviceCallbacks.size()); |
| 612 | oldDesc->mPatch = ioDesc->mPatch; |
| 613 | auto it = mAudioDeviceCallbacks.find(ioDesc->mIoHandle); |
| 614 | if (it != mAudioDeviceCallbacks.end()) { |
| 615 | auto cbks = it->second; |
| 616 | auto it2 = cbks.find(ioDesc->mPortId); |
| 617 | if (it2 != cbks.end()) { |
| 618 | callbacks.emplace(ioDesc->mPortId, it2->second); |
| 619 | deviceId = oldDesc->getDeviceId(); |
Francois Gaffie | 24a9fb0 | 2019-01-18 17:51:34 +0100 | [diff] [blame] | 620 | } |
Francois Gaffie | 24a9fb0 | 2019-01-18 17:51:34 +0100 | [diff] [blame] | 621 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 622 | } break; |
| 623 | } |
| 624 | |
| 625 | for (auto wpCbk : callbacks) { |
| 626 | sp<AudioDeviceCallback> spCbk = wpCbk.second.promote(); |
| 627 | if (spCbk != nullptr) { |
| 628 | callbacksToCall.push_back(spCbk); |
| 629 | } |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 630 | } |
Eric Laurent | 4463ff5 | 2019-02-07 13:56:09 -0800 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | // Callbacks must be called without mLock held. May lead to dead lock if calling for |
| 634 | // example getRoutedDevice that updates the device and tries to acquire mLock. |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 635 | for (auto cb : callbacksToCall) { |
| 636 | // If callbacksToCall is not empty, it implies ioDesc->mIoHandle and deviceId are valid |
| 637 | cb->onAudioDeviceUpdate(ioDesc->mIoHandle, deviceId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 638 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 641 | status_t AudioSystem::AudioFlingerClient::getInputBufferSize( |
| 642 | uint32_t sampleRate, audio_format_t format, |
| 643 | audio_channel_mask_t channelMask, size_t* buffSize) |
| 644 | { |
| 645 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 646 | if (af == 0) { |
| 647 | return PERMISSION_DENIED; |
| 648 | } |
| 649 | Mutex::Autolock _l(mLock); |
| 650 | // Do we have a stale mInBuffSize or are we requesting the input buffer size for new values |
| 651 | if ((mInBuffSize == 0) || (sampleRate != mInSamplingRate) || (format != mInFormat) |
| 652 | || (channelMask != mInChannelMask)) { |
| 653 | size_t inBuffSize = af->getInputBufferSize(sampleRate, format, channelMask); |
| 654 | if (inBuffSize == 0) { |
Glenn Kasten | 49f36ba | 2017-12-06 13:02:02 -0800 | [diff] [blame] | 655 | ALOGE("AudioSystem::getInputBufferSize failed sampleRate %d format %#x channelMask %#x", |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 656 | sampleRate, format, channelMask); |
| 657 | return BAD_VALUE; |
| 658 | } |
| 659 | // A benign race is possible here: we could overwrite a fresher cache entry |
| 660 | // save the request params |
| 661 | mInSamplingRate = sampleRate; |
| 662 | mInFormat = format; |
| 663 | mInChannelMask = channelMask; |
| 664 | |
| 665 | mInBuffSize = inBuffSize; |
| 666 | } |
| 667 | |
| 668 | *buffSize = mInBuffSize; |
| 669 | |
| 670 | return NO_ERROR; |
| 671 | } |
| 672 | |
Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 673 | sp<AudioIoDescriptor> AudioSystem::AudioFlingerClient::getIoDescriptor_l(audio_io_handle_t ioHandle) |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 674 | { |
| 675 | sp<AudioIoDescriptor> desc; |
| 676 | ssize_t index = mIoDescriptors.indexOfKey(ioHandle); |
| 677 | if (index >= 0) { |
| 678 | desc = mIoDescriptors.valueAt(index); |
| 679 | } |
| 680 | return desc; |
| 681 | } |
| 682 | |
Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 683 | sp<AudioIoDescriptor> AudioSystem::AudioFlingerClient::getIoDescriptor(audio_io_handle_t ioHandle) |
| 684 | { |
| 685 | Mutex::Autolock _l(mLock); |
| 686 | return getIoDescriptor_l(ioHandle); |
| 687 | } |
| 688 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 689 | status_t AudioSystem::AudioFlingerClient::addAudioDeviceCallback( |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 690 | const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo, |
| 691 | audio_port_handle_t portId) |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 692 | { |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 693 | ALOGV("%s audioIo %d portId %d", __func__, audioIo, portId); |
Eric Laurent | 4463ff5 | 2019-02-07 13:56:09 -0800 | [diff] [blame] | 694 | Mutex::Autolock _l(mLock); |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 695 | auto& callbacks = mAudioDeviceCallbacks.emplace(audioIo, std::map<audio_port_handle_t, wp<AudioDeviceCallback>>()).first->second; |
| 696 | auto result = callbacks.try_emplace(portId, callback); |
| 697 | if (!result.second) { |
| 698 | return INVALID_OPERATION; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 699 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 700 | return NO_ERROR; |
| 701 | } |
| 702 | |
| 703 | status_t AudioSystem::AudioFlingerClient::removeAudioDeviceCallback( |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 704 | const wp<AudioDeviceCallback>& callback __unused, audio_io_handle_t audioIo, |
| 705 | audio_port_handle_t portId) |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 706 | { |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 707 | ALOGV("%s audioIo %d portId %d", __func__, audioIo, portId); |
Eric Laurent | 4463ff5 | 2019-02-07 13:56:09 -0800 | [diff] [blame] | 708 | Mutex::Autolock _l(mLock); |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 709 | auto it = mAudioDeviceCallbacks.find(audioIo); |
| 710 | if (it == mAudioDeviceCallbacks.end()) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 711 | return INVALID_OPERATION; |
| 712 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 713 | if (it->second.erase(portId) == 0) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 714 | return INVALID_OPERATION; |
| 715 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 716 | if (it->second.size() == 0) { |
| 717 | mAudioDeviceCallbacks.erase(audioIo); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 718 | } |
| 719 | return NO_ERROR; |
| 720 | } |
| 721 | |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 722 | /* static */ uintptr_t AudioSystem::addErrorCallback(audio_error_callback cb) |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 723 | { |
Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 724 | Mutex::Autolock _l(gLockErrorCallbacks); |
| 725 | gAudioErrorCallbacks.insert(cb); |
| 726 | return reinterpret_cast<uintptr_t>(cb); |
| 727 | } |
| 728 | |
| 729 | /* static */ void AudioSystem::removeErrorCallback(uintptr_t cb) { |
| 730 | Mutex::Autolock _l(gLockErrorCallbacks); |
| 731 | gAudioErrorCallbacks.erase(reinterpret_cast<audio_error_callback>(cb)); |
| 732 | } |
| 733 | |
| 734 | /* static */ void AudioSystem::reportError(status_t err) { |
| 735 | Mutex::Autolock _l(gLockErrorCallbacks); |
| 736 | for (auto callback : gAudioErrorCallbacks) { |
| 737 | callback(err); |
| 738 | } |
The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 741 | /*static*/ void AudioSystem::setDynPolicyCallback(dynamic_policy_callback cb) |
| 742 | { |
| 743 | Mutex::Autolock _l(gLock); |
| 744 | gDynPolicyCallback = cb; |
| 745 | } |
| 746 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 747 | /*static*/ void AudioSystem::setRecordConfigCallback(record_config_callback cb) |
| 748 | { |
| 749 | Mutex::Autolock _l(gLock); |
| 750 | gRecordConfigCallback = cb; |
| 751 | } |
| 752 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 753 | // client singleton for AudioPolicyService binder interface |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 754 | // protected by gLockAPS |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 755 | sp<IAudioPolicyService> AudioSystem::gAudioPolicyService; |
| 756 | sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient; |
| 757 | |
| 758 | |
Glenn Kasten | 18a6d90 | 2012-09-24 11:27:56 -0700 | [diff] [blame] | 759 | // establish binder interface to AudioPolicy service |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 760 | const sp<IAudioPolicyService> AudioSystem::get_audio_policy_service() |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 761 | { |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 762 | sp<IAudioPolicyService> ap; |
| 763 | sp<AudioPolicyServiceClient> apc; |
| 764 | { |
| 765 | Mutex::Autolock _l(gLockAPS); |
| 766 | if (gAudioPolicyService == 0) { |
| 767 | sp<IServiceManager> sm = defaultServiceManager(); |
| 768 | sp<IBinder> binder; |
| 769 | do { |
| 770 | binder = sm->getService(String16("media.audio_policy")); |
| 771 | if (binder != 0) |
| 772 | break; |
| 773 | ALOGW("AudioPolicyService not published, waiting..."); |
| 774 | usleep(500000); // 0.5 s |
| 775 | } while (true); |
| 776 | if (gAudioPolicyServiceClient == NULL) { |
| 777 | gAudioPolicyServiceClient = new AudioPolicyServiceClient(); |
| 778 | } |
| 779 | binder->linkToDeath(gAudioPolicyServiceClient); |
| 780 | gAudioPolicyService = interface_cast<IAudioPolicyService>(binder); |
| 781 | LOG_ALWAYS_FATAL_IF(gAudioPolicyService == 0); |
| 782 | apc = gAudioPolicyServiceClient; |
Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 783 | // Make sure callbacks can be received by gAudioPolicyServiceClient |
| 784 | ProcessState::self()->startThreadPool(); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 785 | } |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 786 | ap = gAudioPolicyService; |
| 787 | } |
| 788 | if (apc != 0) { |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 789 | int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 790 | ap->registerClient(apc); |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 791 | ap->setAudioPortCallbacksEnabled(apc->isAudioPortCbEnabled()); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 792 | ap->setAudioVolumeGroupCallbacksEnabled(apc->isAudioVolumeGroupCbEnabled()); |
François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 793 | IPCThreadState::self()->restoreCallingIdentity(token); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 794 | } |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 795 | |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 796 | return ap; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Glenn Kasten | fb1fdc9 | 2013-07-10 17:03:19 -0700 | [diff] [blame] | 799 | // --------------------------------------------------------------------------- |
| 800 | |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 801 | void AudioSystem::onNewAudioModulesAvailable() |
| 802 | { |
| 803 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 804 | if (aps == 0) return; |
| 805 | aps->onNewAudioModulesAvailable(); |
| 806 | } |
| 807 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 808 | status_t AudioSystem::setDeviceConnectionState(audio_devices_t device, |
| 809 | audio_policy_dev_state_t state, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 810 | const char *device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 811 | const char *device_name, |
| 812 | audio_format_t encodedFormat) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 813 | { |
| 814 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 815 | const char *address = ""; |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 816 | const char *name = ""; |
Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 817 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 818 | if (aps == 0) return PERMISSION_DENIED; |
| 819 | |
Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 820 | if (device_address != NULL) { |
| 821 | address = device_address; |
| 822 | } |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 823 | if (device_name != NULL) { |
| 824 | name = device_name; |
| 825 | } |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 826 | return aps->setDeviceConnectionState(device, state, address, name, encodedFormat); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 829 | audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 830 | const char *device_address) |
| 831 | { |
| 832 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 833 | if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 834 | |
| 835 | return aps->getDeviceConnectionState(device, device_address); |
| 836 | } |
| 837 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 838 | status_t AudioSystem::handleDeviceConfigChange(audio_devices_t device, |
| 839 | const char *device_address, |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 840 | const char *device_name, |
| 841 | audio_format_t encodedFormat) |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 842 | { |
| 843 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 844 | const char *address = ""; |
| 845 | const char *name = ""; |
| 846 | |
| 847 | if (aps == 0) return PERMISSION_DENIED; |
| 848 | |
| 849 | if (device_address != NULL) { |
| 850 | address = device_address; |
| 851 | } |
| 852 | if (device_name != NULL) { |
| 853 | name = device_name; |
| 854 | } |
Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 855 | return aps->handleDeviceConfigChange(device, address, name, encodedFormat); |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 856 | } |
| 857 | |
Eric Laurent | 00dba06 | 2020-02-11 15:52:09 -0800 | [diff] [blame] | 858 | status_t AudioSystem::setPhoneState(audio_mode_t state, uid_t uid) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 859 | { |
Glenn Kasten | 347966c | 2012-01-18 14:58:32 -0800 | [diff] [blame] | 860 | if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 861 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 862 | if (aps == 0) return PERMISSION_DENIED; |
| 863 | |
Eric Laurent | 00dba06 | 2020-02-11 15:52:09 -0800 | [diff] [blame] | 864 | return aps->setPhoneState(state, uid); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 867 | 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] | 868 | { |
| 869 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 870 | if (aps == 0) return PERMISSION_DENIED; |
| 871 | return aps->setForceUse(usage, config); |
| 872 | } |
| 873 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 874 | 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] | 875 | { |
| 876 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 877 | if (aps == 0) return AUDIO_POLICY_FORCE_NONE; |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 878 | return aps->getForceUse(usage); |
| 879 | } |
| 880 | |
| 881 | |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 882 | audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 883 | { |
Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 884 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 885 | if (aps == 0) return 0; |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 886 | return aps->getOutput(stream); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 889 | status_t AudioSystem::getOutputForAttr(audio_attributes_t *attr, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 890 | audio_io_handle_t *output, |
| 891 | audio_session_t session, |
| 892 | audio_stream_type_t *stream, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 893 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 894 | uid_t uid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 895 | const audio_config_t *config, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 896 | audio_output_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 897 | audio_port_handle_t *selectedDeviceId, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 898 | audio_port_handle_t *portId, |
| 899 | std::vector<audio_io_handle_t> *secondaryOutputs) |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 900 | { |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 901 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 902 | if (aps == 0) return NO_INIT; |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 903 | return aps->getOutputForAttr(attr, output, session, stream, pid, uid, |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 904 | config, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 905 | flags, selectedDeviceId, portId, secondaryOutputs); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 908 | status_t AudioSystem::startOutput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 909 | { |
| 910 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 911 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 912 | return aps->startOutput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 915 | status_t AudioSystem::stopOutput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 916 | { |
| 917 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 918 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 919 | return aps->stopOutput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 922 | void AudioSystem::releaseOutput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 923 | { |
| 924 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 925 | if (aps == 0) return; |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 926 | aps->releaseOutput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 929 | status_t AudioSystem::getInputForAttr(const audio_attributes_t *attr, |
| 930 | audio_io_handle_t *input, |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 931 | audio_unique_id_t riid, |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 932 | audio_session_t session, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 933 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 934 | uid_t uid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 935 | const String16& opPackageName, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 936 | const audio_config_base_t *config, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 937 | audio_input_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 938 | audio_port_handle_t *selectedDeviceId, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 939 | audio_port_handle_t *portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 940 | { |
| 941 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 942 | if (aps == 0) return NO_INIT; |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 943 | return aps->getInputForAttr( |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 944 | attr, input, riid, session, pid, uid, opPackageName, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 945 | config, flags, selectedDeviceId, portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 948 | status_t AudioSystem::startInput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 949 | { |
| 950 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 951 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 952 | return aps->startInput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 955 | status_t AudioSystem::stopInput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 956 | { |
| 957 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 958 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 959 | return aps->stopInput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 962 | void AudioSystem::releaseInput(audio_port_handle_t portId) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 963 | { |
| 964 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 965 | if (aps == 0) return; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 966 | aps->releaseInput(portId); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 967 | } |
| 968 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 969 | status_t AudioSystem::initStreamVolume(audio_stream_type_t stream, |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 970 | int indexMin, |
| 971 | int indexMax) |
| 972 | { |
| 973 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 974 | if (aps == 0) return PERMISSION_DENIED; |
| 975 | return aps->initStreamVolume(stream, indexMin, indexMax); |
| 976 | } |
| 977 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 978 | status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream, |
| 979 | int index, |
| 980 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 981 | { |
| 982 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 983 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 984 | return aps->setStreamVolumeIndex(stream, index, device); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 987 | status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream, |
| 988 | int *index, |
| 989 | audio_devices_t device) |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 990 | { |
| 991 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 992 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 993 | return aps->getStreamVolumeIndex(stream, index, device); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 994 | } |
| 995 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 996 | status_t AudioSystem::setVolumeIndexForAttributes(const audio_attributes_t &attr, |
| 997 | int index, |
| 998 | audio_devices_t device) |
| 999 | { |
| 1000 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1001 | if (aps == 0) return PERMISSION_DENIED; |
| 1002 | return aps->setVolumeIndexForAttributes(attr, index, device); |
| 1003 | } |
| 1004 | |
| 1005 | status_t AudioSystem::getVolumeIndexForAttributes(const audio_attributes_t &attr, |
| 1006 | int &index, |
| 1007 | audio_devices_t device) |
| 1008 | { |
| 1009 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1010 | if (aps == 0) return PERMISSION_DENIED; |
| 1011 | return aps->getVolumeIndexForAttributes(attr, index, device); |
| 1012 | } |
| 1013 | |
| 1014 | status_t AudioSystem::getMaxVolumeIndexForAttributes(const audio_attributes_t &attr, int &index) |
| 1015 | { |
| 1016 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1017 | if (aps == 0) return PERMISSION_DENIED; |
| 1018 | return aps->getMaxVolumeIndexForAttributes(attr, index); |
| 1019 | } |
| 1020 | |
| 1021 | status_t AudioSystem::getMinVolumeIndexForAttributes(const audio_attributes_t &attr, int &index) |
| 1022 | { |
| 1023 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1024 | if (aps == 0) return PERMISSION_DENIED; |
| 1025 | return aps->getMinVolumeIndexForAttributes(attr, index); |
| 1026 | } |
| 1027 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1028 | uint32_t AudioSystem::getStrategyForStream(audio_stream_type_t stream) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1029 | { |
| 1030 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1031 | if (aps == 0) return PRODUCT_STRATEGY_NONE; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1032 | return aps->getStrategyForStream(stream); |
| 1033 | } |
| 1034 | |
Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 1035 | audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream) |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1036 | { |
| 1037 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Glenn Kasten | 45faf7e | 2014-01-17 10:23:01 -0800 | [diff] [blame] | 1038 | if (aps == 0) return AUDIO_DEVICE_NONE; |
Glenn Kasten | 6b2718c | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 1039 | return aps->getDevicesForStream(stream); |
| 1040 | } |
| 1041 | |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1042 | status_t AudioSystem::getDevicesForAttributes(const AudioAttributes &aa, |
| 1043 | AudioDeviceTypeAddrVector *devices) { |
| 1044 | if (devices == nullptr) { |
| 1045 | return BAD_VALUE; |
| 1046 | } |
| 1047 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1048 | if (aps == 0) return PERMISSION_DENIED; |
| 1049 | return aps->getDevicesForAttributes(aa, devices); |
| 1050 | } |
| 1051 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 1052 | audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t *desc) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1053 | { |
| 1054 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
Glenn Kasten | efa6ea9 | 2014-01-08 09:10:43 -0800 | [diff] [blame] | 1055 | // FIXME change return type to status_t, and return PERMISSION_DENIED here |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 1056 | if (aps == 0) return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1057 | return aps->getOutputForEffect(desc); |
| 1058 | } |
| 1059 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 1060 | status_t AudioSystem::registerEffect(const effect_descriptor_t *desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1061 | audio_io_handle_t io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1062 | uint32_t strategy, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1063 | audio_session_t session, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1064 | int id) |
| 1065 | { |
| 1066 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1067 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1068 | return aps->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | status_t AudioSystem::unregisterEffect(int id) |
| 1072 | { |
| 1073 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1074 | if (aps == 0) return PERMISSION_DENIED; |
| 1075 | return aps->unregisterEffect(id); |
| 1076 | } |
| 1077 | |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1078 | status_t AudioSystem::setEffectEnabled(int id, bool enabled) |
| 1079 | { |
| 1080 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1081 | if (aps == 0) return PERMISSION_DENIED; |
| 1082 | return aps->setEffectEnabled(id, enabled); |
| 1083 | } |
| 1084 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1085 | status_t AudioSystem::moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) |
| 1086 | { |
| 1087 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1088 | if (aps == 0) return PERMISSION_DENIED; |
| 1089 | return aps->moveEffectsToIo(ids, io); |
| 1090 | } |
| 1091 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1092 | 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] | 1093 | { |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1094 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1095 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1096 | if (state == NULL) return BAD_VALUE; |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1097 | *state = aps->isStreamActive(stream, inPastMs); |
| 1098 | return NO_ERROR; |
| 1099 | } |
| 1100 | |
Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1101 | status_t AudioSystem::isStreamActiveRemotely(audio_stream_type_t stream, bool* state, |
| 1102 | uint32_t inPastMs) |
| 1103 | { |
| 1104 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1105 | if (aps == 0) return PERMISSION_DENIED; |
| 1106 | if (state == NULL) return BAD_VALUE; |
| 1107 | *state = aps->isStreamActiveRemotely(stream, inPastMs); |
| 1108 | return NO_ERROR; |
| 1109 | } |
| 1110 | |
Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 1111 | status_t AudioSystem::isSourceActive(audio_source_t stream, bool* state) |
| 1112 | { |
| 1113 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1114 | if (aps == 0) return PERMISSION_DENIED; |
| 1115 | if (state == NULL) return BAD_VALUE; |
| 1116 | *state = aps->isSourceActive(stream); |
| 1117 | return NO_ERROR; |
| 1118 | } |
| 1119 | |
Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 1120 | uint32_t AudioSystem::getPrimaryOutputSamplingRate() |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1121 | { |
| 1122 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1123 | if (af == 0) return 0; |
| 1124 | return af->getPrimaryOutputSamplingRate(); |
| 1125 | } |
| 1126 | |
Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 1127 | size_t AudioSystem::getPrimaryOutputFrameCount() |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1128 | { |
| 1129 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1130 | if (af == 0) return 0; |
| 1131 | return af->getPrimaryOutputFrameCount(); |
| 1132 | } |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1133 | |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 1134 | status_t AudioSystem::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1135 | { |
| 1136 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1137 | if (af == 0) return PERMISSION_DENIED; |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 1138 | return af->setLowRamDevice(isLowRamDevice, totalMemory); |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Eric Laurent | 9f6530f | 2011-08-30 10:18:54 -0700 | [diff] [blame] | 1141 | void AudioSystem::clearAudioConfigCache() |
| 1142 | { |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1143 | // called by restoreTrack_l(), which needs new IAudioFlinger and IAudioPolicyService instances |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1144 | ALOGV("clearAudioConfigCache()"); |
Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 1145 | { |
| 1146 | Mutex::Autolock _l(gLock); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1147 | if (gAudioFlingerClient != 0) { |
| 1148 | gAudioFlingerClient->clearIoCache(); |
| 1149 | } |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1150 | gAudioFlinger.clear(); |
| 1151 | } |
| 1152 | { |
| 1153 | Mutex::Autolock _l(gLockAPS); |
| 1154 | gAudioPolicyService.clear(); |
| 1155 | } |
Eric Laurent | 9f6530f | 2011-08-30 10:18:54 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1158 | status_t AudioSystem::setSupportedSystemUsages(const std::vector<audio_usage_t>& systemUsages) { |
| 1159 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1160 | if (aps == nullptr) return PERMISSION_DENIED; |
| 1161 | return aps->setSupportedSystemUsages(systemUsages); |
| 1162 | } |
| 1163 | |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1164 | status_t AudioSystem::setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) { |
| 1165 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1166 | if (aps == nullptr) return PERMISSION_DENIED; |
| 1167 | return aps->setAllowedCapturePolicy(uid, flags); |
| 1168 | } |
| 1169 | |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 1170 | bool AudioSystem::isOffloadSupported(const audio_offload_info_t& info) |
| 1171 | { |
| 1172 | ALOGV("isOffloadSupported()"); |
| 1173 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1174 | if (aps == 0) return false; |
| 1175 | return aps->isOffloadSupported(info); |
| 1176 | } |
| 1177 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1178 | status_t AudioSystem::listAudioPorts(audio_port_role_t role, |
| 1179 | audio_port_type_t type, |
| 1180 | unsigned int *num_ports, |
| 1181 | struct audio_port *ports, |
| 1182 | unsigned int *generation) |
| 1183 | { |
| 1184 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1185 | if (aps == 0) return PERMISSION_DENIED; |
| 1186 | return aps->listAudioPorts(role, type, num_ports, ports, generation); |
| 1187 | } |
| 1188 | |
| 1189 | status_t AudioSystem::getAudioPort(struct audio_port *port) |
| 1190 | { |
| 1191 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1192 | if (aps == 0) return PERMISSION_DENIED; |
| 1193 | return aps->getAudioPort(port); |
| 1194 | } |
| 1195 | |
| 1196 | status_t AudioSystem::createAudioPatch(const struct audio_patch *patch, |
| 1197 | audio_patch_handle_t *handle) |
| 1198 | { |
| 1199 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1200 | if (aps == 0) return PERMISSION_DENIED; |
| 1201 | return aps->createAudioPatch(patch, handle); |
| 1202 | } |
| 1203 | |
| 1204 | status_t AudioSystem::releaseAudioPatch(audio_patch_handle_t handle) |
| 1205 | { |
| 1206 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1207 | if (aps == 0) return PERMISSION_DENIED; |
| 1208 | return aps->releaseAudioPatch(handle); |
| 1209 | } |
| 1210 | |
| 1211 | status_t AudioSystem::listAudioPatches(unsigned int *num_patches, |
| 1212 | struct audio_patch *patches, |
| 1213 | unsigned int *generation) |
| 1214 | { |
| 1215 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1216 | if (aps == 0) return PERMISSION_DENIED; |
| 1217 | return aps->listAudioPatches(num_patches, patches, generation); |
| 1218 | } |
| 1219 | |
| 1220 | status_t AudioSystem::setAudioPortConfig(const struct audio_port_config *config) |
| 1221 | { |
| 1222 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1223 | if (aps == 0) return PERMISSION_DENIED; |
| 1224 | return aps->setAudioPortConfig(config); |
| 1225 | } |
| 1226 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1227 | status_t AudioSystem::addAudioPortCallback(const sp<AudioPortCallback>& callback) |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1228 | { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1229 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1230 | if (aps == 0) return PERMISSION_DENIED; |
| 1231 | |
| 1232 | Mutex::Autolock _l(gLockAPS); |
| 1233 | if (gAudioPolicyServiceClient == 0) { |
| 1234 | return NO_INIT; |
| 1235 | } |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1236 | int ret = gAudioPolicyServiceClient->addAudioPortCallback(callback); |
| 1237 | if (ret == 1) { |
| 1238 | aps->setAudioPortCallbacksEnabled(true); |
| 1239 | } |
| 1240 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 1243 | /*static*/ |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1244 | status_t AudioSystem::removeAudioPortCallback(const sp<AudioPortCallback>& callback) |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1245 | { |
| 1246 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1247 | if (aps == 0) return PERMISSION_DENIED; |
| 1248 | |
| 1249 | Mutex::Autolock _l(gLockAPS); |
| 1250 | if (gAudioPolicyServiceClient == 0) { |
| 1251 | return NO_INIT; |
| 1252 | } |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1253 | int ret = gAudioPolicyServiceClient->removeAudioPortCallback(callback); |
| 1254 | if (ret == 0) { |
| 1255 | aps->setAudioPortCallbacksEnabled(false); |
| 1256 | } |
| 1257 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1260 | status_t AudioSystem::addAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback) |
| 1261 | { |
| 1262 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1263 | if (aps == 0) return PERMISSION_DENIED; |
| 1264 | |
| 1265 | Mutex::Autolock _l(gLockAPS); |
| 1266 | if (gAudioPolicyServiceClient == 0) { |
| 1267 | return NO_INIT; |
| 1268 | } |
| 1269 | int ret = gAudioPolicyServiceClient->addAudioVolumeGroupCallback(callback); |
| 1270 | if (ret == 1) { |
| 1271 | aps->setAudioVolumeGroupCallbacksEnabled(true); |
| 1272 | } |
| 1273 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
| 1274 | } |
| 1275 | |
| 1276 | status_t AudioSystem::removeAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback) |
| 1277 | { |
| 1278 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1279 | if (aps == 0) return PERMISSION_DENIED; |
| 1280 | |
| 1281 | Mutex::Autolock _l(gLockAPS); |
| 1282 | if (gAudioPolicyServiceClient == 0) { |
| 1283 | return NO_INIT; |
| 1284 | } |
| 1285 | int ret = gAudioPolicyServiceClient->removeAudioVolumeGroupCallback(callback); |
| 1286 | if (ret == 0) { |
| 1287 | aps->setAudioVolumeGroupCallbacksEnabled(false); |
| 1288 | } |
| 1289 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
| 1290 | } |
| 1291 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1292 | status_t AudioSystem::addAudioDeviceCallback( |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1293 | const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo, |
| 1294 | audio_port_handle_t portId) |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1295 | { |
| 1296 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 1297 | if (afc == 0) { |
| 1298 | return NO_INIT; |
| 1299 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1300 | status_t status = afc->addAudioDeviceCallback(callback, audioIo, portId); |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1301 | if (status == NO_ERROR) { |
| 1302 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1303 | if (af != 0) { |
| 1304 | af->registerClient(afc); |
| 1305 | } |
| 1306 | } |
| 1307 | return status; |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | status_t AudioSystem::removeAudioDeviceCallback( |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1311 | const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo, |
| 1312 | audio_port_handle_t portId) |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1313 | { |
| 1314 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 1315 | if (afc == 0) { |
| 1316 | return NO_INIT; |
| 1317 | } |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1318 | return afc->removeAudioDeviceCallback(callback, audioIo, portId); |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | audio_port_handle_t AudioSystem::getDeviceIdForIo(audio_io_handle_t audioIo) |
| 1322 | { |
| 1323 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1324 | if (af == 0) return PERMISSION_DENIED; |
| 1325 | const sp<AudioIoDescriptor> desc = getIoDescriptor(audioIo); |
| 1326 | if (desc == 0) { |
| 1327 | return AUDIO_PORT_HANDLE_NONE; |
| 1328 | } |
| 1329 | return desc->getDeviceId(); |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1332 | status_t AudioSystem::acquireSoundTriggerSession(audio_session_t *session, |
| 1333 | audio_io_handle_t *ioHandle, |
| 1334 | audio_devices_t *device) |
| 1335 | { |
| 1336 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1337 | if (aps == 0) return PERMISSION_DENIED; |
| 1338 | return aps->acquireSoundTriggerSession(session, ioHandle, device); |
| 1339 | } |
| 1340 | |
| 1341 | status_t AudioSystem::releaseSoundTriggerSession(audio_session_t session) |
| 1342 | { |
| 1343 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1344 | if (aps == 0) return PERMISSION_DENIED; |
| 1345 | return aps->releaseSoundTriggerSession(session); |
| 1346 | } |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1347 | |
| 1348 | audio_mode_t AudioSystem::getPhoneState() |
| 1349 | { |
| 1350 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1351 | if (aps == 0) return AUDIO_MODE_INVALID; |
| 1352 | return aps->getPhoneState(); |
| 1353 | } |
| 1354 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 1355 | status_t AudioSystem::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1356 | { |
| 1357 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1358 | if (aps == 0) return PERMISSION_DENIED; |
| 1359 | return aps->registerPolicyMixes(mixes, registration); |
| 1360 | } |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1361 | |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1362 | status_t AudioSystem::setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices) |
| 1363 | { |
| 1364 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1365 | if (aps == 0) return PERMISSION_DENIED; |
| 1366 | return aps->setUidDeviceAffinities(uid, devices); |
| 1367 | } |
| 1368 | |
| 1369 | status_t AudioSystem::removeUidDeviceAffinities(uid_t uid) { |
| 1370 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1371 | if (aps == 0) return PERMISSION_DENIED; |
| 1372 | return aps->removeUidDeviceAffinities(uid); |
| 1373 | } |
| 1374 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1375 | status_t AudioSystem::setUserIdDeviceAffinities(int userId, |
| 1376 | const Vector<AudioDeviceTypeAddr>& devices) |
| 1377 | { |
| 1378 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1379 | if (aps == 0) return PERMISSION_DENIED; |
| 1380 | return aps->setUserIdDeviceAffinities(userId, devices); |
| 1381 | } |
| 1382 | |
| 1383 | status_t AudioSystem::removeUserIdDeviceAffinities(int userId) |
| 1384 | { |
| 1385 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1386 | if (aps == 0) return PERMISSION_DENIED; |
| 1387 | return aps->removeUserIdDeviceAffinities(userId); |
| 1388 | } |
| 1389 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1390 | status_t AudioSystem::startAudioSource(const struct audio_port_config *source, |
| 1391 | const audio_attributes_t *attributes, |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1392 | audio_port_handle_t *portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1393 | { |
| 1394 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1395 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1396 | return aps->startAudioSource(source, attributes, portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1399 | status_t AudioSystem::stopAudioSource(audio_port_handle_t portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1400 | { |
| 1401 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1402 | if (aps == 0) return PERMISSION_DENIED; |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1403 | return aps->stopAudioSource(portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1406 | status_t AudioSystem::setMasterMono(bool mono) |
| 1407 | { |
| 1408 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1409 | if (aps == 0) return PERMISSION_DENIED; |
| 1410 | return aps->setMasterMono(mono); |
| 1411 | } |
| 1412 | |
| 1413 | status_t AudioSystem::getMasterMono(bool *mono) |
| 1414 | { |
| 1415 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1416 | if (aps == 0) return PERMISSION_DENIED; |
| 1417 | return aps->getMasterMono(mono); |
| 1418 | } |
| 1419 | |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1420 | status_t AudioSystem::setMasterBalance(float balance) |
| 1421 | { |
| 1422 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1423 | if (af == 0) return PERMISSION_DENIED; |
| 1424 | return af->setMasterBalance(balance); |
| 1425 | } |
| 1426 | |
| 1427 | status_t AudioSystem::getMasterBalance(float *balance) |
| 1428 | { |
| 1429 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1430 | if (af == 0) return PERMISSION_DENIED; |
| 1431 | return af->getMasterBalance(balance); |
| 1432 | } |
| 1433 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1434 | float AudioSystem::getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device) |
| 1435 | { |
| 1436 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1437 | if (aps == 0) return NAN; |
| 1438 | return aps->getStreamVolumeDB(stream, index, device); |
| 1439 | } |
| 1440 | |
jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 1441 | status_t AudioSystem::getMicrophones(std::vector<media::MicrophoneInfo> *microphones) |
| 1442 | { |
| 1443 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1444 | if (af == 0) return PERMISSION_DENIED; |
| 1445 | return af->getMicrophones(microphones); |
| 1446 | } |
| 1447 | |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 1448 | status_t AudioSystem::setAudioHalPids(const std::vector<pid_t>& pids) { |
| 1449 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1450 | if (af == nullptr) return PERMISSION_DENIED; |
| 1451 | return af->setAudioHalPids(pids); |
| 1452 | } |
| 1453 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1454 | status_t AudioSystem::getSurroundFormats(unsigned int *numSurroundFormats, |
| 1455 | audio_format_t *surroundFormats, |
| 1456 | bool *surroundFormatsEnabled, |
| 1457 | bool reported) |
| 1458 | { |
| 1459 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1460 | if (aps == 0) return PERMISSION_DENIED; |
| 1461 | return aps->getSurroundFormats( |
| 1462 | numSurroundFormats, surroundFormats, surroundFormatsEnabled, reported); |
| 1463 | } |
| 1464 | |
| 1465 | status_t AudioSystem::setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) |
| 1466 | { |
| 1467 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1468 | if (aps == 0) return PERMISSION_DENIED; |
| 1469 | return aps->setSurroundFormatEnabled(audioFormat, enabled); |
| 1470 | } |
| 1471 | |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1472 | status_t AudioSystem::setAssistantUid(uid_t uid) |
| 1473 | { |
| 1474 | const sp <IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1475 | if (aps == 0) return PERMISSION_DENIED; |
| 1476 | |
| 1477 | return aps->setAssistantUid(uid); |
| 1478 | } |
| 1479 | |
| 1480 | status_t AudioSystem::setA11yServicesUids(const std::vector<uid_t>& uids) |
| 1481 | { |
| 1482 | const sp <IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1483 | if (aps == 0) return PERMISSION_DENIED; |
| 1484 | |
| 1485 | return aps->setA11yServicesUids(uids); |
| 1486 | } |
| 1487 | |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1488 | status_t AudioSystem::setCurrentImeUid(uid_t uid) |
| 1489 | { |
| 1490 | const sp <IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1491 | if (aps == 0) return PERMISSION_DENIED; |
| 1492 | |
| 1493 | return aps->setCurrentImeUid(uid); |
| 1494 | } |
| 1495 | |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1496 | bool AudioSystem::isHapticPlaybackSupported() |
| 1497 | { |
| 1498 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1499 | if (aps == 0) return false; |
| 1500 | return aps->isHapticPlaybackSupported(); |
| 1501 | } |
| 1502 | |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1503 | status_t AudioSystem::getHwOffloadEncodingFormatsSupportedForA2DP( |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1504 | std::vector<audio_format_t> *formats) { |
| 1505 | const sp <IAudioPolicyService> |
| 1506 | & aps = AudioSystem::get_audio_policy_service(); |
| 1507 | if (aps == 0) return PERMISSION_DENIED; |
| 1508 | return aps->getHwOffloadEncodingFormatsSupportedForA2DP(formats); |
| 1509 | } |
| 1510 | |
| 1511 | status_t AudioSystem::listAudioProductStrategies(AudioProductStrategyVector &strategies) |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1512 | { |
| 1513 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1514 | if (aps == 0) return PERMISSION_DENIED; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1515 | return aps->listAudioProductStrategies(strategies); |
| 1516 | } |
| 1517 | |
| 1518 | audio_attributes_t AudioSystem::streamTypeToAttributes(audio_stream_type_t stream) |
| 1519 | { |
| 1520 | AudioProductStrategyVector strategies; |
| 1521 | listAudioProductStrategies(strategies); |
| 1522 | for (const auto &strategy : strategies) { |
| 1523 | auto attrVect = strategy.getAudioAttributes(); |
| 1524 | auto iter = std::find_if(begin(attrVect), end(attrVect), [&stream](const auto &attributes) { |
| 1525 | return attributes.getStreamType() == stream; }); |
| 1526 | if (iter != end(attrVect)) { |
| 1527 | return iter->getAttributes(); |
| 1528 | } |
| 1529 | } |
| 1530 | ALOGE("invalid stream type %s when converting to attributes", toString(stream).c_str()); |
| 1531 | return AUDIO_ATTRIBUTES_INITIALIZER; |
| 1532 | } |
| 1533 | |
| 1534 | audio_stream_type_t AudioSystem::attributesToStreamType(const audio_attributes_t &attr) |
| 1535 | { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1536 | product_strategy_t psId; |
| 1537 | status_t ret = AudioSystem::getProductStrategyFromAudioAttributes(AudioAttributes(attr), psId); |
| 1538 | if (ret != NO_ERROR) { |
| 1539 | ALOGE("no strategy found for attributes %s", toString(attr).c_str()); |
| 1540 | return AUDIO_STREAM_MUSIC; |
| 1541 | } |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1542 | AudioProductStrategyVector strategies; |
| 1543 | listAudioProductStrategies(strategies); |
| 1544 | for (const auto &strategy : strategies) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1545 | if (strategy.getId() == psId) { |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1546 | auto attrVect = strategy.getAudioAttributes(); |
| 1547 | auto iter = std::find_if(begin(attrVect), end(attrVect), [&attr](const auto &refAttr) { |
| 1548 | return AudioProductStrategy::attributesMatches( |
| 1549 | refAttr.getAttributes(), attr); }); |
| 1550 | if (iter != end(attrVect)) { |
| 1551 | return iter->getStreamType(); |
| 1552 | } |
| 1553 | } |
| 1554 | } |
Jean-Michel Trivi | ed67865 | 2019-12-19 13:39:30 -0800 | [diff] [blame] | 1555 | switch (attr.usage) { |
| 1556 | case AUDIO_USAGE_VIRTUAL_SOURCE: |
| 1557 | // virtual source is not expected to have an associated product strategy |
| 1558 | break; |
| 1559 | default: |
| 1560 | ALOGE("invalid attributes %s when converting to stream", toString(attr).c_str()); |
| 1561 | break; |
| 1562 | } |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1563 | return AUDIO_STREAM_MUSIC; |
| 1564 | } |
| 1565 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1566 | status_t AudioSystem::getProductStrategyFromAudioAttributes(const AudioAttributes &aa, |
| 1567 | product_strategy_t &productStrategy) |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1568 | { |
| 1569 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1570 | if (aps == 0) return PERMISSION_DENIED; |
| 1571 | return aps->getProductStrategyFromAudioAttributes(aa,productStrategy); |
| 1572 | } |
| 1573 | |
| 1574 | status_t AudioSystem::listAudioVolumeGroups(AudioVolumeGroupVector &groups) |
| 1575 | { |
| 1576 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1577 | if (aps == 0) return PERMISSION_DENIED; |
| 1578 | return aps->listAudioVolumeGroups(groups); |
| 1579 | } |
| 1580 | |
| 1581 | status_t AudioSystem::getVolumeGroupFromAudioAttributes(const AudioAttributes &aa, |
| 1582 | volume_group_t &volumeGroup) |
| 1583 | { |
| 1584 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1585 | if (aps == 0) return PERMISSION_DENIED; |
| 1586 | return aps->getVolumeGroupFromAudioAttributes(aa, volumeGroup); |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1587 | } |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1588 | |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1589 | status_t AudioSystem::setRttEnabled(bool enabled) |
| 1590 | { |
| 1591 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1592 | if (aps == 0) return PERMISSION_DENIED; |
| 1593 | return aps->setRttEnabled(enabled); |
| 1594 | } |
| 1595 | |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1596 | bool AudioSystem::isCallScreenModeSupported() |
| 1597 | { |
| 1598 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1599 | if (aps == 0) return false; |
| 1600 | return aps->isCallScreenModeSupported(); |
| 1601 | } |
| 1602 | |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1603 | status_t AudioSystem::setPreferredDeviceForStrategy(product_strategy_t strategy, |
| 1604 | const AudioDeviceTypeAddr &device) |
| 1605 | { |
| 1606 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1607 | if (aps == 0) { |
| 1608 | return PERMISSION_DENIED; |
| 1609 | } |
| 1610 | return aps->setPreferredDeviceForStrategy(strategy, device); |
| 1611 | } |
| 1612 | |
| 1613 | status_t AudioSystem::removePreferredDeviceForStrategy(product_strategy_t strategy) |
| 1614 | { |
| 1615 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1616 | if (aps == 0) { |
| 1617 | return PERMISSION_DENIED; |
| 1618 | } |
| 1619 | return aps->removePreferredDeviceForStrategy(strategy); |
| 1620 | } |
| 1621 | |
| 1622 | status_t AudioSystem::getPreferredDeviceForStrategy(product_strategy_t strategy, |
| 1623 | AudioDeviceTypeAddr &device) |
| 1624 | { |
| 1625 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1626 | if (aps == 0) { |
| 1627 | return PERMISSION_DENIED; |
| 1628 | } |
| 1629 | return aps->getPreferredDeviceForStrategy(strategy, device); |
| 1630 | } |
| 1631 | |
Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame^] | 1632 | class CaptureStateListenerImpl : public media::BnCaptureStateListener, |
| 1633 | public IBinder::DeathRecipient { |
| 1634 | public: |
| 1635 | binder::Status setCaptureState(bool active) override { |
| 1636 | Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock); |
| 1637 | gSoundTriggerCaptureStateListener->onStateChanged(active); |
| 1638 | return binder::Status::ok(); |
| 1639 | } |
| 1640 | |
| 1641 | void binderDied(const wp<IBinder>&) override { |
| 1642 | Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock); |
| 1643 | gSoundTriggerCaptureStateListener->onServiceDied(); |
| 1644 | gSoundTriggerCaptureStateListener = nullptr; |
| 1645 | } |
| 1646 | }; |
| 1647 | |
| 1648 | status_t AudioSystem::registerSoundTriggerCaptureStateListener( |
| 1649 | const sp<CaptureStateListener>& listener) { |
| 1650 | const sp<IAudioPolicyService>& aps = |
| 1651 | AudioSystem::get_audio_policy_service(); |
| 1652 | if (aps == 0) { |
| 1653 | return PERMISSION_DENIED; |
| 1654 | } |
| 1655 | |
| 1656 | sp<CaptureStateListenerImpl> wrapper = new CaptureStateListenerImpl(); |
| 1657 | |
| 1658 | Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock); |
| 1659 | |
| 1660 | bool active; |
| 1661 | status_t status = |
| 1662 | aps->registerSoundTriggerCaptureStateListener(wrapper, &active); |
| 1663 | if (status != NO_ERROR) { |
| 1664 | listener->onServiceDied(); |
| 1665 | return NO_ERROR; |
| 1666 | } |
| 1667 | gSoundTriggerCaptureStateListener = listener; |
| 1668 | listener->onStateChanged(active); |
| 1669 | sp<IBinder> binder = IInterface::asBinder(aps); |
| 1670 | binder->linkToDeath(wrapper); |
| 1671 | return NO_ERROR; |
| 1672 | } |
| 1673 | |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1674 | // --------------------------------------------------------------------------- |
| 1675 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1676 | int AudioSystem::AudioPolicyServiceClient::addAudioPortCallback( |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1677 | const sp<AudioPortCallback>& callback) |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1678 | { |
| 1679 | Mutex::Autolock _l(mLock); |
| 1680 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1681 | if (mAudioPortCallbacks[i] == callback) { |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1682 | return -1; |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1683 | } |
| 1684 | } |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1685 | mAudioPortCallbacks.add(callback); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1686 | return mAudioPortCallbacks.size(); |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1689 | int AudioSystem::AudioPolicyServiceClient::removeAudioPortCallback( |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1690 | const sp<AudioPortCallback>& callback) |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1691 | { |
| 1692 | Mutex::Autolock _l(mLock); |
| 1693 | size_t i; |
| 1694 | for (i = 0; i < mAudioPortCallbacks.size(); i++) { |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1695 | if (mAudioPortCallbacks[i] == callback) { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1696 | break; |
| 1697 | } |
| 1698 | } |
| 1699 | if (i == mAudioPortCallbacks.size()) { |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1700 | return -1; |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1701 | } |
| 1702 | mAudioPortCallbacks.removeAt(i); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1703 | return mAudioPortCallbacks.size(); |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1706 | |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1707 | void AudioSystem::AudioPolicyServiceClient::onAudioPortListUpdate() |
| 1708 | { |
| 1709 | Mutex::Autolock _l(mLock); |
| 1710 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 1711 | mAudioPortCallbacks[i]->onAudioPortListUpdate(); |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | void AudioSystem::AudioPolicyServiceClient::onAudioPatchListUpdate() |
| 1716 | { |
| 1717 | Mutex::Autolock _l(mLock); |
| 1718 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 1719 | mAudioPortCallbacks[i]->onAudioPatchListUpdate(); |
| 1720 | } |
| 1721 | } |
| 1722 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1723 | // ---------------------------------------------------------------------------- |
| 1724 | int AudioSystem::AudioPolicyServiceClient::addAudioVolumeGroupCallback( |
| 1725 | const sp<AudioVolumeGroupCallback>& callback) |
| 1726 | { |
| 1727 | Mutex::Autolock _l(mLock); |
| 1728 | for (size_t i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 1729 | if (mAudioVolumeGroupCallback[i] == callback) { |
| 1730 | return -1; |
| 1731 | } |
| 1732 | } |
| 1733 | mAudioVolumeGroupCallback.add(callback); |
| 1734 | return mAudioVolumeGroupCallback.size(); |
| 1735 | } |
| 1736 | |
| 1737 | int AudioSystem::AudioPolicyServiceClient::removeAudioVolumeGroupCallback( |
| 1738 | const sp<AudioVolumeGroupCallback>& callback) |
| 1739 | { |
| 1740 | Mutex::Autolock _l(mLock); |
| 1741 | size_t i; |
| 1742 | for (i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 1743 | if (mAudioVolumeGroupCallback[i] == callback) { |
| 1744 | break; |
| 1745 | } |
| 1746 | } |
| 1747 | if (i == mAudioVolumeGroupCallback.size()) { |
| 1748 | return -1; |
| 1749 | } |
| 1750 | mAudioVolumeGroupCallback.removeAt(i); |
| 1751 | return mAudioVolumeGroupCallback.size(); |
| 1752 | } |
| 1753 | |
| 1754 | void AudioSystem::AudioPolicyServiceClient::onAudioVolumeGroupChanged(volume_group_t group, |
| 1755 | int flags) |
| 1756 | { |
| 1757 | Mutex::Autolock _l(mLock); |
| 1758 | for (size_t i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 1759 | mAudioVolumeGroupCallback[i]->onAudioVolumeGroupChanged(group, flags); |
| 1760 | } |
| 1761 | } |
| 1762 | // ---------------------------------------------------------------------------- |
| 1763 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1764 | void AudioSystem::AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate( |
| 1765 | String8 regId, int32_t state) |
| 1766 | { |
Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 1767 | ALOGV("AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate(%s, %d)", regId.string(), state); |
| 1768 | dynamic_policy_callback cb = NULL; |
| 1769 | { |
| 1770 | Mutex::Autolock _l(AudioSystem::gLock); |
| 1771 | cb = gDynPolicyCallback; |
| 1772 | } |
| 1773 | |
| 1774 | if (cb != NULL) { |
| 1775 | cb(DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE, regId, state); |
| 1776 | } |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1779 | void AudioSystem::AudioPolicyServiceClient::onRecordingConfigurationUpdate( |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1780 | int event, |
| 1781 | const record_client_info_t *clientInfo, |
| 1782 | const audio_config_base_t *clientConfig, |
| 1783 | std::vector<effect_descriptor_t> clientEffects, |
| 1784 | const audio_config_base_t *deviceConfig, |
| 1785 | std::vector<effect_descriptor_t> effects, |
| 1786 | audio_patch_handle_t patchHandle, |
| 1787 | audio_source_t source) { |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1788 | record_config_callback cb = NULL; |
| 1789 | { |
| 1790 | Mutex::Autolock _l(AudioSystem::gLock); |
| 1791 | cb = gRecordConfigCallback; |
| 1792 | } |
| 1793 | |
| 1794 | if (cb != NULL) { |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 1795 | cb(event, clientInfo, clientConfig, clientEffects, |
| 1796 | deviceConfig, effects, patchHandle, source); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 1797 | } |
| 1798 | } |
| 1799 | |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 1800 | void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who __unused) |
| 1801 | { |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1802 | { |
Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1803 | Mutex::Autolock _l(mLock); |
| 1804 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 1805 | mAudioPortCallbacks[i]->onServiceDied(); |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1806 | } |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1807 | for (size_t i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 1808 | mAudioVolumeGroupCallback[i]->onServiceDied(); |
| 1809 | } |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1810 | } |
Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1811 | { |
| 1812 | Mutex::Autolock _l(gLockAPS); |
| 1813 | AudioSystem::gAudioPolicyService.clear(); |
| 1814 | } |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1815 | |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1816 | ALOGW("AudioPolicyService server died!"); |
Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 1819 | } // namespace android |