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