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