| 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 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 22 | #include <android/media/IAudioPolicyService.h> |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 23 | #include <android/media/BnCaptureStateListener.h> |
| Mathias Agopian | 7562408 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 24 | #include <binder/IServiceManager.h> |
| Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 25 | #include <binder/ProcessState.h> |
| François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 26 | #include <binder/IPCThreadState.h> |
| Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 27 | #include <media/AidlConversion.h> |
| Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 28 | #include <media/AudioResamplerPublic.h> |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <media/AudioSystem.h> |
| Glenn Kasten | 1ab85ec | 2013-05-31 09:18:43 -0700 | [diff] [blame] | 30 | #include <media/IAudioFlinger.h> |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 31 | #include <media/PolicyAidlConversion.h> |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 32 | #include <media/TypeConverter.h> |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | #include <math.h> |
| 34 | |
| Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 35 | #include <system/audio.h> |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 36 | #include <android/media/GetInputForAttrResponse.h> |
| jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 37 | #include <android/media/AudioMixerAttributesInternal.h> |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 38 | |
| Ytai Ben-Tsvi | 1ff7569 | 2020-11-06 12:16:12 -0800 | [diff] [blame] | 39 | #define VALUE_OR_RETURN_BINDER_STATUS(x) \ |
| Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 40 | ({ auto _tmp = (x); \ |
| Andy Hung | 1131b6e | 2020-12-08 20:47:45 -0800 | [diff] [blame] | 41 | if (!_tmp.ok()) return aidl_utils::binderStatusFromStatusT(_tmp.error()); \ |
| Ytai Ben-Tsvi | a381520 | 2020-10-28 14:58:08 -0700 | [diff] [blame] | 42 | std::move(_tmp.value()); }) |
| Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 43 | |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 44 | // ---------------------------------------------------------------------------- |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 45 | |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | namespace android { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 47 | using aidl_utils::statusTFromBinderStatus; |
| Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 48 | using binder::Status; |
| Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 49 | using content::AttributionSourceState; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 50 | using media::IAudioPolicyService; |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 51 | using media::audio::common::AudioConfig; |
| 52 | using media::audio::common::AudioConfigBase; |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 53 | using media::audio::common::AudioDevice; |
| 54 | using media::audio::common::AudioDeviceDescription; |
| Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 55 | using media::audio::common::AudioFormatDescription; |
| jiabin | e99d088 | 2021-09-17 05:21:25 +0000 | [diff] [blame] | 56 | using media::audio::common::AudioMMapPolicyInfo; |
| 57 | using media::audio::common::AudioMMapPolicyType; |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 58 | using media::audio::common::AudioOffloadInfo; |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 59 | using media::audio::common::AudioSource; |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 60 | using media::audio::common::AudioStreamType; |
| 61 | using media::audio::common::AudioUsage; |
| Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 62 | using media::audio::common::Int; |
| Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 63 | |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | // client singleton for AudioFlinger binder interface |
| 65 | Mutex AudioSystem::gLock; |
| Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 66 | Mutex AudioSystem::gLockErrorCallbacks; |
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 67 | Mutex AudioSystem::gLockAPS; |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | sp<IAudioFlinger> AudioSystem::gAudioFlinger; |
| 69 | sp<AudioSystem::AudioFlingerClient> AudioSystem::gAudioFlingerClient; |
| Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 70 | std::set<audio_error_callback> AudioSystem::gAudioErrorCallbacks; |
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 71 | dynamic_policy_callback AudioSystem::gDynPolicyCallback = NULL; |
| Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 72 | record_config_callback AudioSystem::gRecordConfigCallback = NULL; |
| Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 73 | routing_callback AudioSystem::gRoutingCallback = NULL; |
| Jean-Michel Trivi | 78f2b30 | 2022-04-15 18:18:41 +0000 | [diff] [blame] | 74 | vol_range_init_req_callback AudioSystem::gVolRangeInitReqCallback = NULL; |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 76 | // Required to be held while calling into gSoundTriggerCaptureStateListener. |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 77 | class CaptureStateListenerImpl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 78 | |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 79 | Mutex gSoundTriggerCaptureStateListenerLock; |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 80 | sp<CaptureStateListenerImpl> gSoundTriggerCaptureStateListener = nullptr; |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 81 | |
| Ahaan Ugale | 058f94b | 2021-05-21 02:23:50 -0700 | [diff] [blame] | 82 | // Binder for the AudioFlinger service that's passed to this client process from the system server. |
| 83 | // This allows specific isolated processes to access the audio system. Currently used only for the |
| 84 | // HotwordDetectionService. |
| Andy Hung | 938ef43 | 2023-01-04 11:45:50 -0800 | [diff] [blame] | 85 | static sp<IBinder> gAudioFlingerBinder = nullptr; |
| Ahaan Ugale | 058f94b | 2021-05-21 02:23:50 -0700 | [diff] [blame] | 86 | |
| 87 | void AudioSystem::setAudioFlingerBinder(const sp<IBinder>& audioFlinger) { |
| 88 | if (audioFlinger->getInterfaceDescriptor() != media::IAudioFlingerService::descriptor) { |
| 89 | ALOGE("setAudioFlingerBinder: received a binder of type %s", |
| Tomasz Wasilczyk | 8f36f6e | 2023-08-15 20:59:35 +0000 | [diff] [blame] | 90 | String8(audioFlinger->getInterfaceDescriptor()).c_str()); |
| Ahaan Ugale | 058f94b | 2021-05-21 02:23:50 -0700 | [diff] [blame] | 91 | return; |
| 92 | } |
| 93 | Mutex::Autolock _l(gLock); |
| 94 | if (gAudioFlinger != nullptr) { |
| 95 | ALOGW("setAudioFlingerBinder: ignoring; AudioFlinger connection already established."); |
| 96 | return; |
| 97 | } |
| 98 | gAudioFlingerBinder = audioFlinger; |
| 99 | } |
| 100 | |
| Andy Hung | 938ef43 | 2023-01-04 11:45:50 -0800 | [diff] [blame] | 101 | static sp<IAudioFlinger> gLocalAudioFlinger; // set if we are local. |
| 102 | |
| 103 | status_t AudioSystem::setLocalAudioFlinger(const sp<IAudioFlinger>& af) { |
| 104 | Mutex::Autolock _l(gLock); |
| 105 | if (gAudioFlinger != nullptr) return INVALID_OPERATION; |
| 106 | gLocalAudioFlinger = af; |
| 107 | return OK; |
| 108 | } |
| 109 | |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | // establish binder interface to AudioFlinger service |
| Akshata Kadam | b43ed66 | 2023-08-07 05:49:48 +0000 | [diff] [blame^] | 111 | const sp<IAudioFlinger> AudioSystem::getAudioFlingerImpl(bool canStartThreadPool = true) { |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 112 | sp<IAudioFlinger> af; |
| 113 | sp<AudioFlingerClient> afc; |
| Mikhail Naganov | 69330d4 | 2020-04-08 19:29:50 +0000 | [diff] [blame] | 114 | bool reportNoError = false; |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 115 | { |
| 116 | Mutex::Autolock _l(gLock); |
| Andy Hung | 938ef43 | 2023-01-04 11:45:50 -0800 | [diff] [blame] | 117 | if (gAudioFlinger != nullptr) { |
| 118 | return gAudioFlinger; |
| 119 | } |
| 120 | |
| 121 | if (gAudioFlingerClient == nullptr) { |
| 122 | gAudioFlingerClient = sp<AudioFlingerClient>::make(); |
| 123 | } else { |
| 124 | reportNoError = true; |
| 125 | } |
| 126 | |
| 127 | if (gLocalAudioFlinger != nullptr) { |
| 128 | gAudioFlinger = gLocalAudioFlinger; |
| 129 | } else { |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 130 | sp<IBinder> binder; |
| Ahaan Ugale | 058f94b | 2021-05-21 02:23:50 -0700 | [diff] [blame] | 131 | if (gAudioFlingerBinder != nullptr) { |
| 132 | binder = gAudioFlingerBinder; |
| 133 | } else { |
| 134 | sp<IServiceManager> sm = defaultServiceManager(); |
| 135 | do { |
| 136 | binder = sm->getService(String16(IAudioFlinger::DEFAULT_SERVICE_NAME)); |
| Andy Hung | 938ef43 | 2023-01-04 11:45:50 -0800 | [diff] [blame] | 137 | if (binder != nullptr) break; |
| Ahaan Ugale | 058f94b | 2021-05-21 02:23:50 -0700 | [diff] [blame] | 138 | ALOGW("AudioFlinger not published, waiting..."); |
| 139 | usleep(500000); // 0.5 s |
| 140 | } while (true); |
| 141 | } |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 142 | binder->linkToDeath(gAudioFlingerClient); |
| Andy Hung | 938ef43 | 2023-01-04 11:45:50 -0800 | [diff] [blame] | 143 | const auto afs = interface_cast<media::IAudioFlingerService>(binder); |
| 144 | LOG_ALWAYS_FATAL_IF(afs == nullptr); |
| 145 | gAudioFlinger = sp<AudioFlingerClientAdapter>::make(afs); |
| Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 146 | } |
| Andy Hung | 938ef43 | 2023-01-04 11:45:50 -0800 | [diff] [blame] | 147 | afc = gAudioFlingerClient; |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 148 | af = gAudioFlinger; |
| Andy Hung | 938ef43 | 2023-01-04 11:45:50 -0800 | [diff] [blame] | 149 | // Make sure callbacks can be received by gAudioFlingerClient |
| Akshata Kadam | b43ed66 | 2023-08-07 05:49:48 +0000 | [diff] [blame^] | 150 | if(canStartThreadPool) { |
| 151 | ProcessState::self()->startThreadPool(); |
| 152 | } |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | } |
| Andy Hung | 938ef43 | 2023-01-04 11:45:50 -0800 | [diff] [blame] | 154 | const int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
| 155 | af->registerClient(afc); |
| 156 | IPCThreadState::self()->restoreCallingIdentity(token); |
| Mikhail Naganov | 69330d4 | 2020-04-08 19:29:50 +0000 | [diff] [blame] | 157 | if (reportNoError) reportError(NO_ERROR); |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 158 | return af; |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| Akshata Kadam | b43ed66 | 2023-08-07 05:49:48 +0000 | [diff] [blame^] | 161 | const sp<IAudioFlinger> AudioSystem:: get_audio_flinger() { |
| 162 | return getAudioFlingerImpl(); |
| 163 | } |
| 164 | |
| 165 | const sp<IAudioFlinger> AudioSystem:: get_audio_flinger_for_fuzzer() { |
| 166 | return getAudioFlingerImpl(false); |
| 167 | } |
| 168 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 169 | const sp<AudioSystem::AudioFlingerClient> AudioSystem::getAudioFlingerClient() { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 170 | // calling get_audio_flinger() will initialize gAudioFlingerClient if needed |
| 171 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 172 | if (af == 0) return 0; |
| 173 | Mutex::Autolock _l(gLock); |
| 174 | return gAudioFlingerClient; |
| 175 | } |
| 176 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 177 | sp<AudioIoDescriptor> AudioSystem::getIoDescriptor(audio_io_handle_t ioHandle) { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 178 | sp<AudioIoDescriptor> desc; |
| 179 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 180 | if (afc != 0) { |
| 181 | desc = afc->getIoDescriptor(ioHandle); |
| 182 | } |
| 183 | return desc; |
| 184 | } |
| 185 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 186 | /* static */ status_t AudioSystem::checkAudioFlinger() { |
| Eric Laurent | 4629161 | 2013-07-18 14:38:44 -0700 | [diff] [blame] | 187 | if (defaultServiceManager()->checkService(String16("media.audio_flinger")) != 0) { |
| 188 | return NO_ERROR; |
| 189 | } |
| 190 | return DEAD_OBJECT; |
| 191 | } |
| 192 | |
| Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 193 | // FIXME Declare in binder opcode order, similarly to IAudioFlinger.h and IAudioFlinger.cpp |
| 194 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 195 | status_t AudioSystem::muteMicrophone(bool state) { |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 197 | if (af == 0) return PERMISSION_DENIED; |
| 198 | return af->setMicMute(state); |
| 199 | } |
| 200 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 201 | status_t AudioSystem::isMicrophoneMuted(bool* state) { |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 203 | if (af == 0) return PERMISSION_DENIED; |
| 204 | *state = af->getMicMute(); |
| 205 | return NO_ERROR; |
| 206 | } |
| 207 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 208 | status_t AudioSystem::setMasterVolume(float value) { |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 210 | if (af == 0) return PERMISSION_DENIED; |
| 211 | af->setMasterVolume(value); |
| 212 | return NO_ERROR; |
| 213 | } |
| 214 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 215 | status_t AudioSystem::setMasterMute(bool mute) { |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 217 | if (af == 0) return PERMISSION_DENIED; |
| 218 | af->setMasterMute(mute); |
| 219 | return NO_ERROR; |
| 220 | } |
| 221 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 222 | status_t AudioSystem::getMasterVolume(float* volume) { |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 224 | if (af == 0) return PERMISSION_DENIED; |
| 225 | *volume = af->masterVolume(); |
| 226 | return NO_ERROR; |
| 227 | } |
| 228 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 229 | status_t AudioSystem::getMasterMute(bool* mute) { |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 231 | if (af == 0) return PERMISSION_DENIED; |
| 232 | *mute = af->masterMute(); |
| 233 | return NO_ERROR; |
| 234 | } |
| 235 | |
| Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 236 | status_t AudioSystem::setStreamVolume(audio_stream_type_t stream, float value, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 237 | audio_io_handle_t output) { |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 238 | 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] | 239 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 240 | if (af == 0) return PERMISSION_DENIED; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 241 | af->setStreamVolume(stream, value, output); |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | return NO_ERROR; |
| 243 | } |
| 244 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 245 | status_t AudioSystem::setStreamMute(audio_stream_type_t stream, bool mute) { |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 246 | 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] | 247 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 248 | if (af == 0) return PERMISSION_DENIED; |
| 249 | af->setStreamMute(stream, mute); |
| 250 | return NO_ERROR; |
| 251 | } |
| 252 | |
| Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 253 | status_t AudioSystem::getStreamVolume(audio_stream_type_t stream, float* volume, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 254 | audio_io_handle_t output) { |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 255 | 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] | 256 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 257 | if (af == 0) return PERMISSION_DENIED; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 258 | *volume = af->streamVolume(stream, output); |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | return NO_ERROR; |
| 260 | } |
| 261 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 262 | status_t AudioSystem::getStreamMute(audio_stream_type_t stream, bool* mute) { |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 263 | 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] | 264 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 265 | if (af == 0) return PERMISSION_DENIED; |
| 266 | *mute = af->streamMute(stream); |
| 267 | return NO_ERROR; |
| 268 | } |
| 269 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 270 | status_t AudioSystem::setMode(audio_mode_t mode) { |
| Glenn Kasten | 930f4ca | 2012-01-06 16:47:31 -0800 | [diff] [blame] | 271 | 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] | 272 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 273 | if (af == 0) return PERMISSION_DENIED; |
| 274 | return af->setMode(mode); |
| 275 | } |
| 276 | |
| Mikhail Naganov | e93a086 | 2023-03-15 17:06:59 -0700 | [diff] [blame] | 277 | status_t AudioSystem::setSimulateDeviceConnections(bool enabled) { |
| 278 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 279 | if (af == 0) return PERMISSION_DENIED; |
| 280 | return af->setSimulateDeviceConnections(enabled); |
| 281 | } |
| 282 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 283 | status_t AudioSystem::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) { |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 285 | if (af == 0) return PERMISSION_DENIED; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 286 | return af->setParameters(ioHandle, keyValuePairs); |
| 287 | } |
| 288 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 289 | String8 AudioSystem::getParameters(audio_io_handle_t ioHandle, const String8& keys) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 290 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 291 | String8 result = String8(""); |
| 292 | if (af == 0) return result; |
| 293 | |
| 294 | result = af->getParameters(ioHandle, keys); |
| 295 | return result; |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | } |
| 297 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 298 | status_t AudioSystem::setParameters(const String8& keyValuePairs) { |
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 299 | return setParameters(AUDIO_IO_HANDLE_NONE, keyValuePairs); |
| Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 302 | String8 AudioSystem::getParameters(const String8& keys) { |
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 303 | return getParameters(AUDIO_IO_HANDLE_NONE, keys); |
| Glenn Kasten | c23885e | 2013-12-19 16:35:18 -0800 | [diff] [blame] | 304 | } |
| 305 | |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | // convert volume steps to natural log scale |
| 307 | |
| 308 | // change this value to change volume scaling |
| 309 | static const float dBPerStep = 0.5f; |
| 310 | // shouldn't need to touch these |
| 311 | static const float dBConvert = -dBPerStep * 2.302585093f / 20.0f; |
| 312 | static const float dBConvertInverse = 1.0f / dBConvert; |
| 313 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 314 | float AudioSystem::linearToLog(int volume) { |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | // float v = volume ? exp(float(100 - volume) * dBConvert) : 0; |
| Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 316 | // ALOGD("linearToLog(%d)=%f", volume, v); |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | // return v; |
| 318 | return volume ? exp(float(100 - volume) * dBConvert) : 0; |
| 319 | } |
| 320 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 321 | int AudioSystem::logToLinear(float volume) { |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | // int v = volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
| Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 323 | // ALOGD("logTolinear(%d)=%f", v, volume); |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | // return v; |
| 325 | return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0; |
| 326 | } |
| 327 | |
| Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 328 | /* static */ size_t AudioSystem::calculateMinFrameCount( |
| 329 | uint32_t afLatencyMs, uint32_t afFrameCount, uint32_t afSampleRate, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 330 | uint32_t sampleRate, float speed /*, uint32_t notificationsPerBufferReq*/) { |
| Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 331 | // Ensure that buffer depth covers at least audio hardware latency |
| 332 | uint32_t minBufCount = afLatencyMs / ((1000 * afFrameCount) / afSampleRate); |
| 333 | if (minBufCount < 2) { |
| 334 | minBufCount = 2; |
| 335 | } |
| 336 | #if 0 |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 337 | // The notificationsPerBufferReq parameter is not yet used for non-fast tracks, |
| 338 | // but keeping the code here to make it easier to add later. |
| 339 | if (minBufCount < notificationsPerBufferReq) { |
| 340 | minBufCount = notificationsPerBufferReq; |
| 341 | } |
| Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 342 | #endif |
| 343 | ALOGV("calculateMinFrameCount afLatency %u afFrameCount %u afSampleRate %u " |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 344 | "sampleRate %u speed %f minBufCount: %u" /*" notificationsPerBufferReq %u"*/, |
| 345 | afLatencyMs, afFrameCount, afSampleRate, sampleRate, speed, minBufCount |
| 346 | /*, notificationsPerBufferReq*/); |
| Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 347 | return minBufCount * sourceFramesNeededWithTimestretch( |
| 348 | sampleRate, afFrameCount, afSampleRate, speed); |
| 349 | } |
| 350 | |
| 351 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 352 | status_t |
| 353 | AudioSystem::getOutputSamplingRate(uint32_t* samplingRate, audio_stream_type_t streamType) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 354 | audio_io_handle_t output; |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 356 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 357 | streamType = AUDIO_STREAM_MUSIC; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 360 | output = getOutput(streamType); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 361 | if (output == 0) { |
| 362 | return PERMISSION_DENIED; |
| 363 | } |
| 364 | |
| Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 365 | return getSamplingRate(output, samplingRate); |
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 368 | status_t AudioSystem::getSamplingRate(audio_io_handle_t ioHandle, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 369 | uint32_t* samplingRate) { |
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 370 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 371 | if (af == 0) return PERMISSION_DENIED; |
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 372 | sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); |
| 373 | if (desc == 0) { |
| 374 | *samplingRate = af->sampleRate(ioHandle); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 375 | } else { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 376 | *samplingRate = desc->getSamplingRate(); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 377 | } |
| Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 378 | if (*samplingRate == 0) { |
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 379 | ALOGE("AudioSystem::getSamplingRate failed for ioHandle %d", ioHandle); |
| Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 380 | return BAD_VALUE; |
| 381 | } |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 382 | |
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 383 | ALOGV("getSamplingRate() ioHandle %d, sampling rate %u", ioHandle, *samplingRate); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 384 | |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | return NO_ERROR; |
| 386 | } |
| 387 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 388 | status_t AudioSystem::getOutputFrameCount(size_t* frameCount, audio_stream_type_t streamType) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 389 | audio_io_handle_t output; |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 391 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 392 | streamType = AUDIO_STREAM_MUSIC; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 393 | } |
| Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 394 | |
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 395 | output = getOutput(streamType); |
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 396 | if (output == AUDIO_IO_HANDLE_NONE) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 397 | return PERMISSION_DENIED; |
| 398 | } |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | |
| Jean-Michel Trivi | b7f24b1 | 2014-06-11 10:05:30 -0700 | [diff] [blame] | 400 | return getFrameCount(output, frameCount); |
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 403 | status_t AudioSystem::getFrameCount(audio_io_handle_t ioHandle, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 404 | size_t* frameCount) { |
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 405 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 406 | if (af == 0) return PERMISSION_DENIED; |
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 407 | sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); |
| 408 | if (desc == 0) { |
| 409 | *frameCount = af->frameCount(ioHandle); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 410 | } else { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 411 | *frameCount = desc->getFrameCount(); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 412 | } |
| Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 413 | if (*frameCount == 0) { |
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 414 | ALOGE("AudioSystem::getFrameCount failed for ioHandle %d", ioHandle); |
| Glenn Kasten | f94006c | 2014-01-08 08:56:06 -0800 | [diff] [blame] | 415 | return BAD_VALUE; |
| 416 | } |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 417 | |
| Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 418 | ALOGV("getFrameCount() ioHandle %d, frameCount %zu", ioHandle, *frameCount); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 419 | |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | return NO_ERROR; |
| 421 | } |
| 422 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 423 | status_t AudioSystem::getOutputLatency(uint32_t* latency, audio_stream_type_t streamType) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 424 | audio_io_handle_t output; |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 426 | if (streamType == AUDIO_STREAM_DEFAULT) { |
| 427 | streamType = AUDIO_STREAM_MUSIC; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 428 | } |
| Eric Laurent | 48f7f5e | 2009-04-02 09:32:43 -0700 | [diff] [blame] | 429 | |
| Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 430 | output = getOutput(streamType); |
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 431 | if (output == AUDIO_IO_HANDLE_NONE) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 432 | return PERMISSION_DENIED; |
| 433 | } |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | |
| Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 435 | return getLatency(output, latency); |
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | status_t AudioSystem::getLatency(audio_io_handle_t output, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 439 | uint32_t* latency) { |
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 440 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 441 | if (af == 0) return PERMISSION_DENIED; |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 442 | sp<AudioIoDescriptor> outputDesc = getIoDescriptor(output); |
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 443 | if (outputDesc == 0) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 444 | *latency = af->latency(output); |
| 445 | } else { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 446 | *latency = outputDesc->getLatency(); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| Glenn Kasten | 241618f | 2014-03-25 17:48:57 -0700 | [diff] [blame] | 449 | ALOGV("getLatency() output %d, latency %d", output, *latency); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 450 | |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | return NO_ERROR; |
| 452 | } |
| 453 | |
| Glenn Kasten | dd8104c | 2012-07-02 12:42:44 -0700 | [diff] [blame] | 454 | status_t AudioSystem::getInputBufferSize(uint32_t sampleRate, audio_format_t format, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 455 | audio_channel_mask_t channelMask, size_t* buffSize) { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 456 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 457 | if (afc == 0) { |
| 458 | return NO_INIT; |
| 459 | } |
| 460 | return afc->getInputBufferSize(sampleRate, format, channelMask, buffSize); |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | } |
| 462 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 463 | status_t AudioSystem::setVoiceVolume(float value) { |
| Eric Laurent | f0ee6f4 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 464 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 465 | if (af == 0) return PERMISSION_DENIED; |
| 466 | return af->setVoiceVolume(value); |
| 467 | } |
| 468 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 469 | status_t AudioSystem::getRenderPosition(audio_io_handle_t output, uint32_t* halFrames, |
| 470 | uint32_t* dspFrames) { |
| Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 471 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 472 | if (af == 0) return PERMISSION_DENIED; |
| 473 | |
| Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 474 | return af->getRenderPosition(halFrames, dspFrames, output); |
| Eric Laurent | 342e9cf | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 477 | uint32_t AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) { |
| Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 478 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 479 | uint32_t result = 0; |
| Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 480 | if (af == 0) return result; |
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 481 | if (ioHandle == AUDIO_IO_HANDLE_NONE) return result; |
| Eric Laurent | 05bca2f | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 482 | |
| 483 | result = af->getInputFramesLost(ioHandle); |
| 484 | return result; |
| 485 | } |
| 486 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 487 | audio_unique_id_t AudioSystem::newAudioUniqueId(audio_unique_id_use_t use) { |
| Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 488 | // 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] | 489 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 490 | if (af == 0) return AUDIO_UNIQUE_ID_ALLOCATE; |
| Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 491 | return af->newAudioUniqueId(use); |
| Eric Laurent | be916aa | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 494 | void AudioSystem::acquireAudioSessionId(audio_session_t audioSession, pid_t pid, uid_t uid) { |
| Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 495 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 496 | if (af != 0) { |
| Andy Hung | 8b0bfd9 | 2019-12-23 13:11:11 -0800 | [diff] [blame] | 497 | af->acquireAudioSessionId(audioSession, pid, uid); |
| Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 501 | void AudioSystem::releaseAudioSessionId(audio_session_t audioSession, pid_t pid) { |
| Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 502 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 503 | if (af != 0) { |
| Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 504 | af->releaseAudioSessionId(audioSession, pid); |
| Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 508 | audio_hw_sync_t AudioSystem::getAudioHwSyncForSession(audio_session_t sessionId) { |
| Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 509 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 510 | if (af == 0) return AUDIO_HW_SYNC_INVALID; |
| 511 | return af->getAudioHwSyncForSession(sessionId); |
| 512 | } |
| 513 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 514 | status_t AudioSystem::systemReady() { |
| Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 515 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 516 | if (af == 0) return NO_INIT; |
| 517 | return af->systemReady(); |
| 518 | } |
| 519 | |
| Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 520 | status_t AudioSystem::audioPolicyReady() { |
| 521 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 522 | if (af == 0) return NO_INIT; |
| 523 | return af->audioPolicyReady(); |
| 524 | } |
| 525 | |
| Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 526 | status_t AudioSystem::getFrameCountHAL(audio_io_handle_t ioHandle, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 527 | size_t* frameCount) { |
| Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 528 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 529 | if (af == 0) return PERMISSION_DENIED; |
| 530 | sp<AudioIoDescriptor> desc = getIoDescriptor(ioHandle); |
| 531 | if (desc == 0) { |
| 532 | *frameCount = af->frameCountHAL(ioHandle); |
| 533 | } else { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 534 | *frameCount = desc->getFrameCountHAL(); |
| Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 535 | } |
| 536 | if (*frameCount == 0) { |
| 537 | ALOGE("AudioSystem::getFrameCountHAL failed for ioHandle %d", ioHandle); |
| 538 | return BAD_VALUE; |
| 539 | } |
| 540 | |
| 541 | ALOGV("getFrameCountHAL() ioHandle %d, frameCount %zu", ioHandle, *frameCount); |
| 542 | |
| 543 | return NO_ERROR; |
| 544 | } |
| 545 | |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | // --------------------------------------------------------------------------- |
| 547 | |
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 548 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 549 | void AudioSystem::AudioFlingerClient::clearIoCache() { |
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 550 | Mutex::Autolock _l(mLock); |
| 551 | mIoDescriptors.clear(); |
| 552 | mInBuffSize = 0; |
| 553 | mInSamplingRate = 0; |
| 554 | mInFormat = AUDIO_FORMAT_DEFAULT; |
| 555 | mInChannelMask = AUDIO_CHANNEL_NONE; |
| 556 | } |
| 557 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 558 | void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who __unused) { |
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 559 | { |
| 560 | Mutex::Autolock _l(AudioSystem::gLock); |
| 561 | AudioSystem::gAudioFlinger.clear(); |
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 562 | } |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | |
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 564 | // clear output handles and stream to output map caches |
| 565 | clearIoCache(); |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | |
| Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 567 | reportError(DEAD_OBJECT); |
| 568 | |
| Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 569 | ALOGW("AudioFlinger server died!"); |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 572 | Status AudioSystem::AudioFlingerClient::ioConfigChanged( |
| 573 | media::AudioIoConfigEvent _event, |
| 574 | const media::AudioIoDescriptor& _ioDesc) { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 575 | audio_io_config_event_t event = VALUE_OR_RETURN_BINDER_STATUS( |
| 576 | aidl2legacy_AudioIoConfigEvent_audio_io_config_event_t(_event)); |
| Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 577 | sp<AudioIoDescriptor> ioDesc( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 578 | VALUE_OR_RETURN_BINDER_STATUS( |
| 579 | aidl2legacy_AudioIoDescriptor_AudioIoDescriptor(_ioDesc))); |
| Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 580 | |
| Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 581 | ALOGV("ioConfigChanged() event %d", event); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 582 | |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 583 | if (ioDesc->getIoHandle() == AUDIO_IO_HANDLE_NONE) return Status::ok(); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 584 | |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 585 | audio_port_handle_t deviceId = AUDIO_PORT_HANDLE_NONE; |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 586 | std::vector<sp<AudioDeviceCallback>> callbacksToCall; |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 587 | { |
| 588 | Mutex::Autolock _l(mLock); |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 589 | auto callbacks = std::map<audio_port_handle_t, wp<AudioDeviceCallback>>(); |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 590 | |
| 591 | switch (event) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 592 | case AUDIO_OUTPUT_OPENED: |
| 593 | case AUDIO_OUTPUT_REGISTERED: |
| 594 | case AUDIO_INPUT_OPENED: |
| 595 | case AUDIO_INPUT_REGISTERED: { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 596 | sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->getIoHandle()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 597 | if (oldDesc == 0) { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 598 | mIoDescriptors.add(ioDesc->getIoHandle(), ioDesc); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 599 | } else { |
| 600 | deviceId = oldDesc->getDeviceId(); |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 601 | mIoDescriptors.replaceValueFor(ioDesc->getIoHandle(), ioDesc); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | if (ioDesc->getDeviceId() != AUDIO_PORT_HANDLE_NONE) { |
| 605 | deviceId = ioDesc->getDeviceId(); |
| 606 | if (event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED) { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 607 | auto it = mAudioDeviceCallbacks.find(ioDesc->getIoHandle()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 608 | if (it != mAudioDeviceCallbacks.end()) { |
| 609 | callbacks = it->second; |
| 610 | } |
| 611 | } |
| 612 | } |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 613 | ALOGV("ioConfigChanged() new %s %s %s", |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 614 | event == AUDIO_OUTPUT_OPENED || event == AUDIO_OUTPUT_REGISTERED ? |
| 615 | "output" : "input", |
| 616 | event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED ? |
| 617 | "opened" : "registered", |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 618 | ioDesc->toDebugString().c_str()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 619 | } |
| 620 | break; |
| 621 | case AUDIO_OUTPUT_CLOSED: |
| 622 | case AUDIO_INPUT_CLOSED: { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 623 | if (getIoDescriptor_l(ioDesc->getIoHandle()) == 0) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 624 | ALOGW("ioConfigChanged() closing unknown %s %d", |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 625 | event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->getIoHandle()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 626 | break; |
| 627 | } |
| 628 | ALOGV("ioConfigChanged() %s %d closed", |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 629 | event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->getIoHandle()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 630 | |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 631 | mIoDescriptors.removeItem(ioDesc->getIoHandle()); |
| 632 | mAudioDeviceCallbacks.erase(ioDesc->getIoHandle()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 633 | } |
| 634 | break; |
| 635 | |
| 636 | case AUDIO_OUTPUT_CONFIG_CHANGED: |
| 637 | case AUDIO_INPUT_CONFIG_CHANGED: { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 638 | sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->getIoHandle()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 639 | if (oldDesc == 0) { |
| 640 | ALOGW("ioConfigChanged() modifying unknown %s! %d", |
| 641 | event == AUDIO_OUTPUT_CONFIG_CHANGED ? "output" : "input", |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 642 | ioDesc->getIoHandle()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 643 | break; |
| 644 | } |
| 645 | |
| Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 646 | deviceId = oldDesc->getDeviceId(); |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 647 | mIoDescriptors.replaceValueFor(ioDesc->getIoHandle(), ioDesc); |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 648 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 649 | if (deviceId != ioDesc->getDeviceId()) { |
| 650 | deviceId = ioDesc->getDeviceId(); |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 651 | auto it = mAudioDeviceCallbacks.find(ioDesc->getIoHandle()); |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 652 | if (it != mAudioDeviceCallbacks.end()) { |
| 653 | callbacks = it->second; |
| Francois Gaffie | 24a9fb0 | 2019-01-18 17:51:34 +0100 | [diff] [blame] | 654 | } |
| 655 | } |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 656 | ALOGV("ioConfigChanged() new config for %s %s", |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 657 | event == AUDIO_OUTPUT_CONFIG_CHANGED ? "output" : "input", |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 658 | ioDesc->toDebugString().c_str()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 659 | |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 660 | } |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 661 | break; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 662 | case AUDIO_CLIENT_STARTED: { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 663 | sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->getIoHandle()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 664 | if (oldDesc == 0) { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 665 | ALOGW("ioConfigChanged() start client on unknown io! %d", |
| 666 | ioDesc->getIoHandle()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 667 | break; |
| 668 | } |
| 669 | ALOGV("ioConfigChanged() AUDIO_CLIENT_STARTED io %d port %d num callbacks %zu", |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 670 | ioDesc->getIoHandle(), ioDesc->getPortId(), mAudioDeviceCallbacks.size()); |
| 671 | oldDesc->setPatch(ioDesc->getPatch()); |
| 672 | auto it = mAudioDeviceCallbacks.find(ioDesc->getIoHandle()); |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 673 | if (it != mAudioDeviceCallbacks.end()) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 674 | auto cbks = it->second; |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 675 | auto it2 = cbks.find(ioDesc->getPortId()); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 676 | if (it2 != cbks.end()) { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 677 | callbacks.emplace(ioDesc->getPortId(), it2->second); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 678 | deviceId = oldDesc->getDeviceId(); |
| 679 | } |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 680 | } |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 681 | } |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 682 | break; |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | for (auto wpCbk : callbacks) { |
| 686 | sp<AudioDeviceCallback> spCbk = wpCbk.second.promote(); |
| 687 | if (spCbk != nullptr) { |
| 688 | callbacksToCall.push_back(spCbk); |
| 689 | } |
| Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 690 | } |
| Eric Laurent | 4463ff5 | 2019-02-07 13:56:09 -0800 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | // Callbacks must be called without mLock held. May lead to dead lock if calling for |
| 694 | // example getRoutedDevice that updates the device and tries to acquire mLock. |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 695 | for (auto cb : callbacksToCall) { |
| Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 696 | // If callbacksToCall is not empty, it implies ioDesc->getIoHandle() and deviceId are valid |
| 697 | cb->onAudioDeviceUpdate(ioDesc->getIoHandle(), deviceId); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 698 | } |
| Ytai Ben-Tsvi | 10dc0a6 | 2020-09-18 11:31:55 -0700 | [diff] [blame] | 699 | |
| 700 | return Status::ok(); |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | } |
| 702 | |
| Eric Laurent | 0825031 | 2022-05-03 18:12:28 +0200 | [diff] [blame] | 703 | Status AudioSystem::AudioFlingerClient::onSupportedLatencyModesChanged( |
| Mikhail Naganov | b1a075b | 2022-12-18 02:48:14 +0000 | [diff] [blame] | 704 | int output, const std::vector<media::audio::common::AudioLatencyMode>& latencyModes) { |
| Eric Laurent | 0825031 | 2022-05-03 18:12:28 +0200 | [diff] [blame] | 705 | audio_io_handle_t outputLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 706 | aidl2legacy_int32_t_audio_io_handle_t(output)); |
| 707 | std::vector<audio_latency_mode_t> modesLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 708 | convertContainer<std::vector<audio_latency_mode_t>>( |
| Mikhail Naganov | b1a075b | 2022-12-18 02:48:14 +0000 | [diff] [blame] | 709 | latencyModes, aidl2legacy_AudioLatencyMode_audio_latency_mode_t)); |
| Eric Laurent | 0825031 | 2022-05-03 18:12:28 +0200 | [diff] [blame] | 710 | |
| 711 | std::vector<sp<SupportedLatencyModesCallback>> callbacks; |
| 712 | { |
| 713 | Mutex::Autolock _l(mLock); |
| 714 | for (auto callback : mSupportedLatencyModesCallbacks) { |
| 715 | if (auto ref = callback.promote(); ref != nullptr) { |
| 716 | callbacks.push_back(ref); |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | for (const auto& callback : callbacks) { |
| 721 | callback->onSupportedLatencyModesChanged(outputLegacy, modesLegacy); |
| 722 | } |
| 723 | |
| 724 | return Status::ok(); |
| 725 | } |
| 726 | |
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 727 | status_t AudioSystem::AudioFlingerClient::getInputBufferSize( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 728 | uint32_t sampleRate, audio_format_t format, |
| 729 | audio_channel_mask_t channelMask, size_t* buffSize) { |
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 730 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 731 | if (af == 0) { |
| 732 | return PERMISSION_DENIED; |
| 733 | } |
| 734 | Mutex::Autolock _l(mLock); |
| 735 | // Do we have a stale mInBuffSize or are we requesting the input buffer size for new values |
| 736 | if ((mInBuffSize == 0) || (sampleRate != mInSamplingRate) || (format != mInFormat) |
| 737 | || (channelMask != mInChannelMask)) { |
| 738 | size_t inBuffSize = af->getInputBufferSize(sampleRate, format, channelMask); |
| 739 | if (inBuffSize == 0) { |
| Glenn Kasten | 49f36ba | 2017-12-06 13:02:02 -0800 | [diff] [blame] | 740 | ALOGE("AudioSystem::getInputBufferSize failed sampleRate %d format %#x channelMask %#x", |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 741 | sampleRate, format, channelMask); |
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 742 | return BAD_VALUE; |
| 743 | } |
| 744 | // A benign race is possible here: we could overwrite a fresher cache entry |
| 745 | // save the request params |
| 746 | mInSamplingRate = sampleRate; |
| 747 | mInFormat = format; |
| 748 | mInChannelMask = channelMask; |
| 749 | |
| 750 | mInBuffSize = inBuffSize; |
| 751 | } |
| 752 | |
| 753 | *buffSize = mInBuffSize; |
| 754 | |
| 755 | return NO_ERROR; |
| 756 | } |
| 757 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 758 | sp<AudioIoDescriptor> |
| 759 | AudioSystem::AudioFlingerClient::getIoDescriptor_l(audio_io_handle_t ioHandle) { |
| Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 760 | sp<AudioIoDescriptor> desc; |
| 761 | ssize_t index = mIoDescriptors.indexOfKey(ioHandle); |
| 762 | if (index >= 0) { |
| 763 | desc = mIoDescriptors.valueAt(index); |
| 764 | } |
| 765 | return desc; |
| 766 | } |
| 767 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 768 | sp<AudioIoDescriptor> AudioSystem::AudioFlingerClient::getIoDescriptor(audio_io_handle_t ioHandle) { |
| Praveen Chavan | 49fdeaf | 2015-09-29 02:25:47 -0700 | [diff] [blame] | 769 | Mutex::Autolock _l(mLock); |
| 770 | return getIoDescriptor_l(ioHandle); |
| 771 | } |
| 772 | |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 773 | status_t AudioSystem::AudioFlingerClient::addAudioDeviceCallback( |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 774 | const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 775 | audio_port_handle_t portId) { |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 776 | ALOGV("%s audioIo %d portId %d", __func__, audioIo, portId); |
| Eric Laurent | 4463ff5 | 2019-02-07 13:56:09 -0800 | [diff] [blame] | 777 | Mutex::Autolock _l(mLock); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 778 | auto& callbacks = mAudioDeviceCallbacks.emplace( |
| 779 | audioIo, |
| 780 | std::map<audio_port_handle_t, wp<AudioDeviceCallback>>()).first->second; |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 781 | auto result = callbacks.try_emplace(portId, callback); |
| 782 | if (!result.second) { |
| 783 | return INVALID_OPERATION; |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 784 | } |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 785 | return NO_ERROR; |
| 786 | } |
| 787 | |
| 788 | status_t AudioSystem::AudioFlingerClient::removeAudioDeviceCallback( |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 789 | const wp<AudioDeviceCallback>& callback __unused, audio_io_handle_t audioIo, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 790 | audio_port_handle_t portId) { |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 791 | ALOGV("%s audioIo %d portId %d", __func__, audioIo, portId); |
| Eric Laurent | 4463ff5 | 2019-02-07 13:56:09 -0800 | [diff] [blame] | 792 | Mutex::Autolock _l(mLock); |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 793 | auto it = mAudioDeviceCallbacks.find(audioIo); |
| 794 | if (it == mAudioDeviceCallbacks.end()) { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 795 | return INVALID_OPERATION; |
| 796 | } |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 797 | if (it->second.erase(portId) == 0) { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 798 | return INVALID_OPERATION; |
| 799 | } |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 800 | if (it->second.size() == 0) { |
| 801 | mAudioDeviceCallbacks.erase(audioIo); |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 802 | } |
| 803 | return NO_ERROR; |
| 804 | } |
| 805 | |
| Eric Laurent | 0825031 | 2022-05-03 18:12:28 +0200 | [diff] [blame] | 806 | status_t AudioSystem::AudioFlingerClient::addSupportedLatencyModesCallback( |
| 807 | const sp<SupportedLatencyModesCallback>& callback) { |
| 808 | Mutex::Autolock _l(mLock); |
| 809 | if (std::find(mSupportedLatencyModesCallbacks.begin(), |
| 810 | mSupportedLatencyModesCallbacks.end(), |
| 811 | callback) != mSupportedLatencyModesCallbacks.end()) { |
| 812 | return INVALID_OPERATION; |
| 813 | } |
| 814 | mSupportedLatencyModesCallbacks.push_back(callback); |
| 815 | return NO_ERROR; |
| 816 | } |
| 817 | |
| 818 | status_t AudioSystem::AudioFlingerClient::removeSupportedLatencyModesCallback( |
| 819 | const sp<SupportedLatencyModesCallback>& callback) { |
| 820 | Mutex::Autolock _l(mLock); |
| 821 | auto it = std::find(mSupportedLatencyModesCallbacks.begin(), |
| 822 | mSupportedLatencyModesCallbacks.end(), |
| 823 | callback); |
| 824 | if (it == mSupportedLatencyModesCallbacks.end()) { |
| 825 | return INVALID_OPERATION; |
| 826 | } |
| 827 | mSupportedLatencyModesCallbacks.erase(it); |
| 828 | return NO_ERROR; |
| 829 | } |
| 830 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 831 | /* static */ uintptr_t AudioSystem::addErrorCallback(audio_error_callback cb) { |
| Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 832 | Mutex::Autolock _l(gLockErrorCallbacks); |
| 833 | gAudioErrorCallbacks.insert(cb); |
| 834 | return reinterpret_cast<uintptr_t>(cb); |
| 835 | } |
| 836 | |
| 837 | /* static */ void AudioSystem::removeErrorCallback(uintptr_t cb) { |
| 838 | Mutex::Autolock _l(gLockErrorCallbacks); |
| 839 | gAudioErrorCallbacks.erase(reinterpret_cast<audio_error_callback>(cb)); |
| 840 | } |
| 841 | |
| 842 | /* static */ void AudioSystem::reportError(status_t err) { |
| 843 | Mutex::Autolock _l(gLockErrorCallbacks); |
| 844 | for (auto callback : gAudioErrorCallbacks) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 845 | callback(err); |
| Ytai Ben-Tsvi | 000c3e4 | 2020-01-09 15:26:40 -0800 | [diff] [blame] | 846 | } |
| The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | } |
| 848 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 849 | /*static*/ void AudioSystem::setDynPolicyCallback(dynamic_policy_callback cb) { |
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 850 | Mutex::Autolock _l(gLock); |
| 851 | gDynPolicyCallback = cb; |
| 852 | } |
| 853 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 854 | /*static*/ void AudioSystem::setRecordConfigCallback(record_config_callback cb) { |
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 855 | Mutex::Autolock _l(gLock); |
| 856 | gRecordConfigCallback = cb; |
| 857 | } |
| 858 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 859 | /*static*/ void AudioSystem::setRoutingCallback(routing_callback cb) { |
| Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 860 | Mutex::Autolock _l(gLock); |
| 861 | gRoutingCallback = cb; |
| 862 | } |
| 863 | |
| Jean-Michel Trivi | 78f2b30 | 2022-04-15 18:18:41 +0000 | [diff] [blame] | 864 | /*static*/ void AudioSystem::setVolInitReqCallback(vol_range_init_req_callback cb) { |
| 865 | Mutex::Autolock _l(gLock); |
| 866 | gVolRangeInitReqCallback = cb; |
| 867 | } |
| 868 | |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 869 | // client singleton for AudioPolicyService binder interface |
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 870 | // protected by gLockAPS |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 871 | sp<IAudioPolicyService> AudioSystem::gAudioPolicyService; |
| 872 | sp<AudioSystem::AudioPolicyServiceClient> AudioSystem::gAudioPolicyServiceClient; |
| 873 | |
| 874 | |
| Glenn Kasten | 18a6d90 | 2012-09-24 11:27:56 -0700 | [diff] [blame] | 875 | // establish binder interface to AudioPolicy service |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 876 | const sp<IAudioPolicyService> AudioSystem::get_audio_policy_service() { |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 877 | sp<IAudioPolicyService> ap; |
| 878 | sp<AudioPolicyServiceClient> apc; |
| 879 | { |
| 880 | Mutex::Autolock _l(gLockAPS); |
| 881 | if (gAudioPolicyService == 0) { |
| 882 | sp<IServiceManager> sm = defaultServiceManager(); |
| 883 | sp<IBinder> binder; |
| 884 | do { |
| 885 | binder = sm->getService(String16("media.audio_policy")); |
| 886 | if (binder != 0) |
| 887 | break; |
| 888 | ALOGW("AudioPolicyService not published, waiting..."); |
| 889 | usleep(500000); // 0.5 s |
| 890 | } while (true); |
| 891 | if (gAudioPolicyServiceClient == NULL) { |
| 892 | gAudioPolicyServiceClient = new AudioPolicyServiceClient(); |
| 893 | } |
| 894 | binder->linkToDeath(gAudioPolicyServiceClient); |
| 895 | gAudioPolicyService = interface_cast<IAudioPolicyService>(binder); |
| 896 | LOG_ALWAYS_FATAL_IF(gAudioPolicyService == 0); |
| 897 | apc = gAudioPolicyServiceClient; |
| Eric Laurent | fb00fc7 | 2017-05-25 18:17:12 -0700 | [diff] [blame] | 898 | // Make sure callbacks can be received by gAudioPolicyServiceClient |
| 899 | ProcessState::self()->startThreadPool(); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 900 | } |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 901 | ap = gAudioPolicyService; |
| 902 | } |
| 903 | if (apc != 0) { |
| François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 904 | int64_t token = IPCThreadState::self()->clearCallingIdentity(); |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 905 | ap->registerClient(apc); |
| François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 906 | ap->setAudioPortCallbacksEnabled(apc->isAudioPortCbEnabled()); |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 907 | ap->setAudioVolumeGroupCallbacksEnabled(apc->isAudioVolumeGroupCbEnabled()); |
| François Gaffie | 2443760 | 2018-04-23 15:08:59 +0200 | [diff] [blame] | 908 | IPCThreadState::self()->restoreCallingIdentity(token); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 909 | } |
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 910 | |
| Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 911 | return ap; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| Mikhail Naganov | ec3d579 | 2022-05-06 00:19:55 +0000 | [diff] [blame] | 914 | void AudioSystem::clearAudioPolicyService() { |
| 915 | Mutex::Autolock _l(gLockAPS); |
| 916 | gAudioPolicyService.clear(); |
| 917 | } |
| 918 | |
| Glenn Kasten | fb1fdc9 | 2013-07-10 17:03:19 -0700 | [diff] [blame] | 919 | // --------------------------------------------------------------------------- |
| 920 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 921 | void AudioSystem::onNewAudioModulesAvailable() { |
| Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 922 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 923 | if (aps == 0) return; |
| 924 | aps->onNewAudioModulesAvailable(); |
| 925 | } |
| 926 | |
| Nathalie Le Clair | 88fa275 | 2021-11-23 13:03:41 +0100 | [diff] [blame] | 927 | status_t AudioSystem::setDeviceConnectionState(audio_policy_dev_state_t state, |
| 928 | const android::media::audio::common::AudioPort& port, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 929 | audio_format_t encodedFormat) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 930 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Eric Laurent | 71b63e3 | 2011-09-02 14:20:56 -0700 | [diff] [blame] | 931 | |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 932 | if (aps == 0) return PERMISSION_DENIED; |
| 933 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 934 | return statusTFromBinderStatus( |
| 935 | aps->setDeviceConnectionState( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 936 | VALUE_OR_RETURN_STATUS( |
| 937 | legacy2aidl_audio_policy_dev_state_t_AudioPolicyDeviceState(state)), |
| Nathalie Le Clair | 88fa275 | 2021-11-23 13:03:41 +0100 | [diff] [blame] | 938 | port, |
| Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 939 | VALUE_OR_RETURN_STATUS( |
| 940 | legacy2aidl_audio_format_t_AudioFormatDescription(encodedFormat)))); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 943 | audio_policy_dev_state_t AudioSystem::getDeviceConnectionState(audio_devices_t device, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 944 | const char* device_address) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 945 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 946 | if (aps == 0) return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 947 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 948 | auto result = [&]() -> ConversionResult<audio_policy_dev_state_t> { |
| Mikhail Naganov | 932cb96 | 2021-09-16 01:05:27 +0000 | [diff] [blame] | 949 | AudioDevice deviceAidl = VALUE_OR_RETURN( |
| 950 | legacy2aidl_audio_device_AudioDevice(device, device_address)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 951 | |
| 952 | media::AudioPolicyDeviceState result; |
| 953 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 954 | aps->getDeviceConnectionState(deviceAidl, &result))); |
| 955 | |
| 956 | return aidl2legacy_AudioPolicyDeviceState_audio_policy_dev_state_t(result); |
| 957 | }(); |
| 958 | return result.value_or(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 961 | status_t AudioSystem::handleDeviceConfigChange(audio_devices_t device, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 962 | const char* device_address, |
| 963 | const char* device_name, |
| 964 | audio_format_t encodedFormat) { |
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 965 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 966 | const char* address = ""; |
| 967 | const char* name = ""; |
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 968 | |
| 969 | if (aps == 0) return PERMISSION_DENIED; |
| 970 | |
| 971 | if (device_address != NULL) { |
| 972 | address = device_address; |
| 973 | } |
| 974 | if (device_name != NULL) { |
| 975 | name = device_name; |
| 976 | } |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 977 | |
| Mikhail Naganov | 932cb96 | 2021-09-16 01:05:27 +0000 | [diff] [blame] | 978 | AudioDevice deviceAidl = VALUE_OR_RETURN_STATUS( |
| 979 | legacy2aidl_audio_device_AudioDevice(device, address)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 980 | |
| 981 | return statusTFromBinderStatus( |
| 982 | aps->handleDeviceConfigChange(deviceAidl, name, VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 983 | legacy2aidl_audio_format_t_AudioFormatDescription(encodedFormat)))); |
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 984 | } |
| 985 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 986 | status_t AudioSystem::setPhoneState(audio_mode_t state, uid_t uid) { |
| Glenn Kasten | 347966c | 2012-01-18 14:58:32 -0800 | [diff] [blame] | 987 | if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 988 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 989 | if (aps == 0) return PERMISSION_DENIED; |
| 990 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 991 | return statusTFromBinderStatus(aps->setPhoneState( |
| 992 | VALUE_OR_RETURN_STATUS(legacy2aidl_audio_mode_t_AudioMode(state)), |
| 993 | VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)))); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 996 | status_t |
| 997 | 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] | 998 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 999 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1000 | |
| 1001 | return statusTFromBinderStatus( |
| 1002 | aps->setForceUse( |
| 1003 | VALUE_OR_RETURN_STATUS( |
| 1004 | legacy2aidl_audio_policy_force_use_t_AudioPolicyForceUse(usage)), |
| 1005 | VALUE_OR_RETURN_STATUS( |
| 1006 | legacy2aidl_audio_policy_forced_cfg_t_AudioPolicyForcedConfig( |
| 1007 | config)))); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1010 | 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] | 1011 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1012 | if (aps == 0) return AUDIO_POLICY_FORCE_NONE; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1013 | |
| 1014 | auto result = [&]() -> ConversionResult<audio_policy_forced_cfg_t> { |
| 1015 | media::AudioPolicyForceUse usageAidl = VALUE_OR_RETURN( |
| 1016 | legacy2aidl_audio_policy_force_use_t_AudioPolicyForceUse(usage)); |
| 1017 | media::AudioPolicyForcedConfig configAidl; |
| 1018 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 1019 | aps->getForceUse(usageAidl, &configAidl))); |
| 1020 | return aidl2legacy_AudioPolicyForcedConfig_audio_policy_forced_cfg_t(configAidl); |
| 1021 | }(); |
| 1022 | |
| 1023 | return result.value_or(AUDIO_POLICY_FORCE_NONE); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1027 | audio_io_handle_t AudioSystem::getOutput(audio_stream_type_t stream) { |
| Eric Laurent | 1a9ed11 | 2012-03-20 18:36:01 -0700 | [diff] [blame] | 1028 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1029 | if (aps == 0) return AUDIO_IO_HANDLE_NONE; |
| 1030 | |
| 1031 | auto result = [&]() -> ConversionResult<audio_io_handle_t> { |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1032 | AudioStreamType streamAidl = VALUE_OR_RETURN( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1033 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1034 | int32_t outputAidl; |
| 1035 | RETURN_IF_ERROR( |
| 1036 | statusTFromBinderStatus(aps->getOutput(streamAidl, &outputAidl))); |
| 1037 | return aidl2legacy_int32_t_audio_io_handle_t(outputAidl); |
| 1038 | }(); |
| 1039 | |
| 1040 | return result.value_or(AUDIO_IO_HANDLE_NONE); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1043 | status_t AudioSystem::getOutputForAttr(audio_attributes_t* attr, |
| 1044 | audio_io_handle_t* output, |
| 1045 | audio_session_t session, |
| 1046 | audio_stream_type_t* stream, |
| Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1047 | const AttributionSourceState& attributionSource, |
| jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1048 | audio_config_t* config, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1049 | audio_output_flags_t flags, |
| 1050 | audio_port_handle_t* selectedDeviceId, |
| 1051 | audio_port_handle_t* portId, |
| Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 1052 | std::vector<audio_io_handle_t>* secondaryOutputs, |
| jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 1053 | bool *isSpatialized, |
| 1054 | bool *isBitPerfect) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1055 | if (attr == nullptr) { |
| 1056 | ALOGE("%s NULL audio attributes", __func__); |
| 1057 | return BAD_VALUE; |
| 1058 | } |
| 1059 | if (output == nullptr) { |
| 1060 | ALOGE("%s NULL output - shouldn't happen", __func__); |
| 1061 | return BAD_VALUE; |
| 1062 | } |
| 1063 | if (selectedDeviceId == nullptr) { |
| 1064 | ALOGE("%s NULL selectedDeviceId - shouldn't happen", __func__); |
| 1065 | return BAD_VALUE; |
| 1066 | } |
| 1067 | if (portId == nullptr) { |
| 1068 | ALOGE("%s NULL portId - shouldn't happen", __func__); |
| 1069 | return BAD_VALUE; |
| 1070 | } |
| 1071 | if (secondaryOutputs == nullptr) { |
| 1072 | ALOGE("%s NULL secondaryOutputs - shouldn't happen", __func__); |
| 1073 | return BAD_VALUE; |
| 1074 | } |
| 1075 | |
| Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 1076 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 1077 | if (aps == 0) return NO_INIT; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1078 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 1079 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 1080 | legacy2aidl_audio_attributes_t_AudioAttributes(*attr)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1081 | int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session)); |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1082 | AudioConfig configAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 1083 | legacy2aidl_audio_config_t_AudioConfig(*config, false /*isInput*/)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1084 | int32_t flagsAidl = VALUE_OR_RETURN_STATUS( |
| 1085 | legacy2aidl_audio_output_flags_t_int32_t_mask(flags)); |
| Eric Laurent | f99edd3 | 2021-02-01 15:57:33 +0100 | [diff] [blame] | 1086 | int32_t selectedDeviceIdAidl = VALUE_OR_RETURN_STATUS( |
| 1087 | legacy2aidl_audio_port_handle_t_int32_t(*selectedDeviceId)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1088 | |
| 1089 | media::GetOutputForAttrResponse responseAidl; |
| 1090 | |
| jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1091 | status_t status = statusTFromBinderStatus( |
| Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1092 | aps->getOutputForAttr(attrAidl, sessionAidl, attributionSource, configAidl, flagsAidl, |
| jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1093 | selectedDeviceIdAidl, &responseAidl)); |
| 1094 | if (status != NO_ERROR) { |
| 1095 | config->format = VALUE_OR_RETURN_STATUS( |
| 1096 | aidl2legacy_AudioFormatDescription_audio_format_t(responseAidl.configBase.format)); |
| 1097 | config->channel_mask = VALUE_OR_RETURN_STATUS( |
| 1098 | aidl2legacy_AudioChannelLayout_audio_channel_mask_t( |
| 1099 | responseAidl.configBase.channelMask, false /*isInput*/)); |
| 1100 | config->sample_rate = responseAidl.configBase.sampleRate; |
| 1101 | return status; |
| 1102 | } |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1103 | |
| 1104 | *output = VALUE_OR_RETURN_STATUS( |
| 1105 | aidl2legacy_int32_t_audio_io_handle_t(responseAidl.output)); |
| 1106 | |
| 1107 | if (stream != nullptr) { |
| 1108 | *stream = VALUE_OR_RETURN_STATUS( |
| 1109 | aidl2legacy_AudioStreamType_audio_stream_type_t(responseAidl.stream)); |
| 1110 | } |
| 1111 | *selectedDeviceId = VALUE_OR_RETURN_STATUS( |
| 1112 | aidl2legacy_int32_t_audio_port_handle_t(responseAidl.selectedDeviceId)); |
| 1113 | *portId = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_port_handle_t(responseAidl.portId)); |
| 1114 | *secondaryOutputs = VALUE_OR_RETURN_STATUS(convertContainer<std::vector<audio_io_handle_t>>( |
| 1115 | responseAidl.secondaryOutputs, aidl2legacy_int32_t_audio_io_handle_t)); |
| Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 1116 | *isSpatialized = responseAidl.isSpatialized; |
| jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 1117 | *isBitPerfect = responseAidl.isBitPerfect; |
| Eric Laurent | 0d13fea | 2022-11-04 17:12:08 +0100 | [diff] [blame] | 1118 | *attr = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | f094be2 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 1119 | aidl2legacy_AudioAttributes_audio_attributes_t(responseAidl.attr)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1120 | |
| 1121 | return OK; |
| Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1124 | status_t AudioSystem::startOutput(audio_port_handle_t portId) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1125 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1126 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1127 | |
| 1128 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1129 | return statusTFromBinderStatus(aps->startOutput(portIdAidl)); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1130 | } |
| 1131 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1132 | status_t AudioSystem::stopOutput(audio_port_handle_t portId) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1133 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1134 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1135 | |
| 1136 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1137 | return statusTFromBinderStatus(aps->stopOutput(portIdAidl)); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1140 | void AudioSystem::releaseOutput(audio_port_handle_t portId) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1141 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1142 | if (aps == 0) return; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1143 | |
| 1144 | auto status = [&]() -> status_t { |
| 1145 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS( |
| 1146 | legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1147 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(aps->releaseOutput(portIdAidl))); |
| 1148 | return OK; |
| 1149 | }(); |
| 1150 | |
| 1151 | // Ignore status. |
| 1152 | (void) status; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1155 | status_t AudioSystem::getInputForAttr(const audio_attributes_t* attr, |
| 1156 | audio_io_handle_t* input, |
| 1157 | audio_unique_id_t riid, |
| 1158 | audio_session_t session, |
| Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1159 | const AttributionSourceState &attributionSource, |
| jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1160 | audio_config_base_t* config, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1161 | audio_input_flags_t flags, |
| 1162 | audio_port_handle_t* selectedDeviceId, |
| 1163 | audio_port_handle_t* portId) { |
| 1164 | if (attr == NULL) { |
| 1165 | ALOGE("getInputForAttr NULL attr - shouldn't happen"); |
| 1166 | return BAD_VALUE; |
| 1167 | } |
| 1168 | if (input == NULL) { |
| 1169 | ALOGE("getInputForAttr NULL input - shouldn't happen"); |
| 1170 | return BAD_VALUE; |
| 1171 | } |
| 1172 | if (selectedDeviceId == NULL) { |
| 1173 | ALOGE("getInputForAttr NULL selectedDeviceId - shouldn't happen"); |
| 1174 | return BAD_VALUE; |
| 1175 | } |
| 1176 | if (portId == NULL) { |
| 1177 | ALOGE("getInputForAttr NULL portId - shouldn't happen"); |
| 1178 | return BAD_VALUE; |
| 1179 | } |
| 1180 | |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1181 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 1182 | if (aps == 0) return NO_INIT; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1183 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 1184 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 1185 | legacy2aidl_audio_attributes_t_AudioAttributes(*attr)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1186 | int32_t inputAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(*input)); |
| 1187 | int32_t riidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_unique_id_t_int32_t(riid)); |
| 1188 | int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session)); |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1189 | AudioConfigBase configAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 1190 | legacy2aidl_audio_config_base_t_AudioConfigBase(*config, true /*isInput*/)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1191 | int32_t flagsAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_input_flags_t_int32_t_mask(flags)); |
| Eric Laurent | f99edd3 | 2021-02-01 15:57:33 +0100 | [diff] [blame] | 1192 | int32_t selectedDeviceIdAidl = VALUE_OR_RETURN_STATUS( |
| 1193 | legacy2aidl_audio_port_handle_t_int32_t(*selectedDeviceId)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1194 | |
| 1195 | media::GetInputForAttrResponse response; |
| 1196 | |
| jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1197 | status_t status = statusTFromBinderStatus( |
| Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1198 | aps->getInputForAttr(attrAidl, inputAidl, riidAidl, sessionAidl, attributionSource, |
| jiabin | f1c7397 | 2022-04-14 16:28:52 -0700 | [diff] [blame] | 1199 | configAidl, flagsAidl, selectedDeviceIdAidl, &response)); |
| 1200 | if (status != NO_ERROR) { |
| 1201 | *config = VALUE_OR_RETURN_STATUS( |
| 1202 | aidl2legacy_AudioConfigBase_audio_config_base_t(response.config, true /*isInput*/)); |
| 1203 | return status; |
| 1204 | } |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1205 | |
| 1206 | *input = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_io_handle_t(response.input)); |
| 1207 | *selectedDeviceId = VALUE_OR_RETURN_STATUS( |
| 1208 | aidl2legacy_int32_t_audio_port_handle_t(response.selectedDeviceId)); |
| 1209 | *portId = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_port_handle_t(response.portId)); |
| 1210 | |
| 1211 | return OK; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1214 | status_t AudioSystem::startInput(audio_port_handle_t portId) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1215 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1216 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1217 | |
| 1218 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1219 | return statusTFromBinderStatus(aps->startInput(portIdAidl)); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1222 | status_t AudioSystem::stopInput(audio_port_handle_t portId) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1223 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1224 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1225 | |
| 1226 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1227 | return statusTFromBinderStatus(aps->stopInput(portIdAidl)); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1230 | void AudioSystem::releaseInput(audio_port_handle_t portId) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1231 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1232 | if (aps == 0) return; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1233 | |
| 1234 | auto status = [&]() -> status_t { |
| 1235 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS( |
| 1236 | legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1237 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(aps->releaseInput(portIdAidl))); |
| 1238 | return OK; |
| 1239 | }(); |
| 1240 | |
| 1241 | // Ignore status. |
| 1242 | (void) status; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
| Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1245 | status_t AudioSystem::initStreamVolume(audio_stream_type_t stream, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1246 | int indexMin, |
| 1247 | int indexMax) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1248 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1249 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1250 | |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1251 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1252 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1253 | int32_t indexMinAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(indexMin)); |
| 1254 | int32_t indexMaxAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(indexMax)); |
| Mikhail Naganov | ec3d579 | 2022-05-06 00:19:55 +0000 | [diff] [blame] | 1255 | status_t status = statusTFromBinderStatus( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1256 | aps->initStreamVolume(streamAidl, indexMinAidl, indexMaxAidl)); |
| Mikhail Naganov | ec3d579 | 2022-05-06 00:19:55 +0000 | [diff] [blame] | 1257 | if (status == DEAD_OBJECT) { |
| 1258 | // This is a critical operation since w/o proper stream volumes no audio |
| 1259 | // will be heard. Make sure we recover from a failure in any case. |
| 1260 | ALOGE("Received DEAD_OBJECT from APS, clearing the client"); |
| 1261 | clearAudioPolicyService(); |
| 1262 | } |
| 1263 | return status; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
| Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1266 | status_t AudioSystem::setStreamVolumeIndex(audio_stream_type_t stream, |
| 1267 | int index, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1268 | audio_devices_t device) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1269 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1270 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1271 | |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1272 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1273 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1274 | int32_t indexAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(index)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 1275 | AudioDeviceDescription deviceAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | 21a32ec | 2021-07-08 14:40:12 -0700 | [diff] [blame] | 1276 | legacy2aidl_audio_devices_t_AudioDeviceDescription(device)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1277 | return statusTFromBinderStatus( |
| 1278 | aps->setStreamVolumeIndex(streamAidl, deviceAidl, indexAidl)); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
| Eric Laurent | 83844cc | 2011-11-18 16:43:31 -0800 | [diff] [blame] | 1281 | status_t AudioSystem::getStreamVolumeIndex(audio_stream_type_t stream, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1282 | int* index, |
| 1283 | audio_devices_t device) { |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1284 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1285 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1286 | |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1287 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1288 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 1289 | AudioDeviceDescription deviceAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | 21a32ec | 2021-07-08 14:40:12 -0700 | [diff] [blame] | 1290 | legacy2aidl_audio_devices_t_AudioDeviceDescription(device)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1291 | int32_t indexAidl; |
| 1292 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1293 | aps->getStreamVolumeIndex(streamAidl, deviceAidl, &indexAidl))); |
| 1294 | if (index != nullptr) { |
| 1295 | *index = VALUE_OR_RETURN_STATUS(convertIntegral<int>(indexAidl)); |
| 1296 | } |
| 1297 | return OK; |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1300 | status_t AudioSystem::setVolumeIndexForAttributes(const audio_attributes_t& attr, |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1301 | int index, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1302 | audio_devices_t device) { |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1303 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1304 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1305 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 1306 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 1307 | legacy2aidl_audio_attributes_t_AudioAttributes(attr)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1308 | int32_t indexAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(index)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 1309 | AudioDeviceDescription deviceAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | 21a32ec | 2021-07-08 14:40:12 -0700 | [diff] [blame] | 1310 | legacy2aidl_audio_devices_t_AudioDeviceDescription(device)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1311 | return statusTFromBinderStatus( |
| 1312 | aps->setVolumeIndexForAttributes(attrAidl, deviceAidl, indexAidl)); |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1313 | } |
| 1314 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1315 | status_t AudioSystem::getVolumeIndexForAttributes(const audio_attributes_t& attr, |
| 1316 | int& index, |
| 1317 | audio_devices_t device) { |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1318 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1319 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1320 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 1321 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 1322 | legacy2aidl_audio_attributes_t_AudioAttributes(attr)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 1323 | AudioDeviceDescription deviceAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | 21a32ec | 2021-07-08 14:40:12 -0700 | [diff] [blame] | 1324 | legacy2aidl_audio_devices_t_AudioDeviceDescription(device)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1325 | int32_t indexAidl; |
| 1326 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1327 | aps->getVolumeIndexForAttributes(attrAidl, deviceAidl, &indexAidl))); |
| 1328 | index = VALUE_OR_RETURN_STATUS(convertIntegral<int>(indexAidl)); |
| 1329 | return OK; |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1332 | status_t AudioSystem::getMaxVolumeIndexForAttributes(const audio_attributes_t& attr, int& index) { |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1333 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1334 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1335 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 1336 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 1337 | legacy2aidl_audio_attributes_t_AudioAttributes(attr)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1338 | int32_t indexAidl; |
| 1339 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1340 | aps->getMaxVolumeIndexForAttributes(attrAidl, &indexAidl))); |
| 1341 | index = VALUE_OR_RETURN_STATUS(convertIntegral<int>(indexAidl)); |
| 1342 | return OK; |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1345 | status_t AudioSystem::getMinVolumeIndexForAttributes(const audio_attributes_t& attr, int& index) { |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1346 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1347 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1348 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 1349 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 1350 | legacy2aidl_audio_attributes_t_AudioAttributes(attr)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1351 | int32_t indexAidl; |
| 1352 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1353 | aps->getMinVolumeIndexForAttributes(attrAidl, &indexAidl))); |
| 1354 | index = VALUE_OR_RETURN_STATUS(convertIntegral<int>(indexAidl)); |
| 1355 | return OK; |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1356 | } |
| 1357 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1358 | product_strategy_t AudioSystem::getStrategyForStream(audio_stream_type_t stream) { |
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1359 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1360 | if (aps == 0) return PRODUCT_STRATEGY_NONE; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1361 | |
| 1362 | auto result = [&]() -> ConversionResult<product_strategy_t> { |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1363 | AudioStreamType streamAidl = VALUE_OR_RETURN( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1364 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1365 | int32_t resultAidl; |
| 1366 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 1367 | aps->getStrategyForStream(streamAidl, &resultAidl))); |
| 1368 | return aidl2legacy_int32_t_product_strategy_t(resultAidl); |
| 1369 | }(); |
| 1370 | return result.value_or(PRODUCT_STRATEGY_NONE); |
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
| François Gaffie | f6d3bbe | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 1373 | status_t AudioSystem::getDevicesForAttributes(const audio_attributes_t& aa, |
| Andy Hung | 6d23c0f | 2022-02-16 09:37:15 -0800 | [diff] [blame] | 1374 | AudioDeviceTypeAddrVector* devices, |
| 1375 | bool forVolume) { |
| Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1376 | if (devices == nullptr) { |
| 1377 | return BAD_VALUE; |
| 1378 | } |
| 1379 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1380 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1381 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 1382 | media::audio::common::AudioAttributes aaAidl = VALUE_OR_RETURN_STATUS( |
| 1383 | legacy2aidl_audio_attributes_t_AudioAttributes(aa)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 1384 | std::vector<AudioDevice> retAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1385 | RETURN_STATUS_IF_ERROR( |
| Andy Hung | 6d23c0f | 2022-02-16 09:37:15 -0800 | [diff] [blame] | 1386 | statusTFromBinderStatus(aps->getDevicesForAttributes(aaAidl, forVolume, &retAidl))); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1387 | *devices = VALUE_OR_RETURN_STATUS( |
| 1388 | convertContainer<AudioDeviceTypeAddrVector>( |
| 1389 | retAidl, |
| 1390 | aidl2legacy_AudioDeviceTypeAddress)); |
| 1391 | return OK; |
| Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1392 | } |
| 1393 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1394 | audio_io_handle_t AudioSystem::getOutputForEffect(const effect_descriptor_t* desc) { |
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1395 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Glenn Kasten | efa6ea9 | 2014-01-08 09:10:43 -0800 | [diff] [blame] | 1396 | // FIXME change return type to status_t, and return PERMISSION_DENIED here |
| Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 1397 | if (aps == 0) return AUDIO_IO_HANDLE_NONE; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1398 | |
| 1399 | auto result = [&]() -> ConversionResult<audio_io_handle_t> { |
| 1400 | media::EffectDescriptor descAidl = VALUE_OR_RETURN( |
| 1401 | legacy2aidl_effect_descriptor_t_EffectDescriptor(*desc)); |
| 1402 | int32_t retAidl; |
| 1403 | RETURN_IF_ERROR( |
| 1404 | statusTFromBinderStatus(aps->getOutputForEffect(descAidl, &retAidl))); |
| 1405 | return aidl2legacy_int32_t_audio_io_handle_t(retAidl); |
| 1406 | }(); |
| 1407 | |
| 1408 | return result.value_or(AUDIO_IO_HANDLE_NONE); |
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1411 | status_t AudioSystem::registerEffect(const effect_descriptor_t* desc, |
| 1412 | audio_io_handle_t io, |
| 1413 | product_strategy_t strategy, |
| 1414 | audio_session_t session, |
| 1415 | int id) { |
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1416 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1417 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1418 | |
| 1419 | media::EffectDescriptor descAidl = VALUE_OR_RETURN_STATUS( |
| 1420 | legacy2aidl_effect_descriptor_t_EffectDescriptor(*desc)); |
| 1421 | int32_t ioAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(io)); |
| 1422 | int32_t strategyAidl = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_product_strategy_t(strategy)); |
| 1423 | int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session)); |
| 1424 | int32_t idAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(id)); |
| 1425 | return statusTFromBinderStatus( |
| 1426 | aps->registerEffect(descAidl, ioAidl, strategyAidl, sessionAidl, idAidl)); |
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1429 | status_t AudioSystem::unregisterEffect(int id) { |
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1430 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1431 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1432 | |
| 1433 | int32_t idAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(id)); |
| 1434 | return statusTFromBinderStatus( |
| 1435 | aps->unregisterEffect(idAidl)); |
| Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1438 | status_t AudioSystem::setEffectEnabled(int id, bool enabled) { |
| Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1439 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1440 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1441 | |
| 1442 | int32_t idAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(id)); |
| 1443 | return statusTFromBinderStatus( |
| 1444 | aps->setEffectEnabled(idAidl, enabled)); |
| Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1447 | status_t AudioSystem::moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) { |
| Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1448 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1449 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1450 | |
| 1451 | std::vector<int32_t> idsAidl = VALUE_OR_RETURN_STATUS( |
| 1452 | convertContainer<std::vector<int32_t>>(ids, convertReinterpret<int32_t, int>)); |
| 1453 | int32_t ioAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_io_handle_t_int32_t(io)); |
| 1454 | return statusTFromBinderStatus(aps->moveEffectsToIo(idsAidl, ioAidl)); |
| Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1457 | status_t AudioSystem::isStreamActive(audio_stream_type_t stream, bool* state, uint32_t inPastMs) { |
| Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1458 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1459 | if (aps == 0) return PERMISSION_DENIED; |
| Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1460 | if (state == NULL) return BAD_VALUE; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1461 | |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1462 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1463 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1464 | int32_t inPastMsAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(inPastMs)); |
| 1465 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1466 | aps->isStreamActive(streamAidl, inPastMsAidl, state))); |
| 1467 | return OK; |
| Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1468 | } |
| 1469 | |
| Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1470 | status_t AudioSystem::isStreamActiveRemotely(audio_stream_type_t stream, bool* state, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1471 | uint32_t inPastMs) { |
| Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1472 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1473 | if (aps == 0) return PERMISSION_DENIED; |
| 1474 | if (state == NULL) return BAD_VALUE; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1475 | |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1476 | AudioStreamType streamAidl = VALUE_OR_RETURN_STATUS( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1477 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1478 | int32_t inPastMsAidl = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(inPastMs)); |
| 1479 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1480 | aps->isStreamActiveRemotely(streamAidl, inPastMsAidl, state))); |
| 1481 | return OK; |
| Jean-Michel Trivi | 272ab54 | 2013-02-04 16:26:02 -0800 | [diff] [blame] | 1482 | } |
| 1483 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1484 | status_t AudioSystem::isSourceActive(audio_source_t stream, bool* state) { |
| Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 1485 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1486 | if (aps == 0) return PERMISSION_DENIED; |
| 1487 | if (state == NULL) return BAD_VALUE; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1488 | |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 1489 | AudioSource streamAidl = VALUE_OR_RETURN_STATUS( |
| 1490 | legacy2aidl_audio_source_t_AudioSource(stream)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1491 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1492 | aps->isSourceActive(streamAidl, state))); |
| 1493 | return OK; |
| Jean-Michel Trivi | d708603 | 2012-10-10 12:11:16 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1496 | uint32_t AudioSystem::getPrimaryOutputSamplingRate() { |
| Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1497 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1498 | if (af == 0) return 0; |
| 1499 | return af->getPrimaryOutputSamplingRate(); |
| 1500 | } |
| 1501 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1502 | size_t AudioSystem::getPrimaryOutputFrameCount() { |
| Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 1503 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1504 | if (af == 0) return 0; |
| 1505 | return af->getPrimaryOutputFrameCount(); |
| 1506 | } |
| Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 1507 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1508 | status_t AudioSystem::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) { |
| Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1509 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1510 | if (af == 0) return PERMISSION_DENIED; |
| Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 1511 | return af->setLowRamDevice(isLowRamDevice, totalMemory); |
| Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1514 | void AudioSystem::clearAudioConfigCache() { |
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1515 | // called by restoreTrack_l(), which needs new IAudioFlinger and IAudioPolicyService instances |
| Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1516 | ALOGV("clearAudioConfigCache()"); |
| Eric Laurent | f6778fd | 2014-11-18 17:26:58 -0800 | [diff] [blame] | 1517 | { |
| 1518 | Mutex::Autolock _l(gLock); |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1519 | if (gAudioFlingerClient != 0) { |
| 1520 | gAudioFlingerClient->clearIoCache(); |
| 1521 | } |
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 1522 | gAudioFlinger.clear(); |
| 1523 | } |
| Mikhail Naganov | ec3d579 | 2022-05-06 00:19:55 +0000 | [diff] [blame] | 1524 | clearAudioPolicyService(); |
| Eric Laurent | 9f6530f | 2011-08-30 10:18:54 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
| Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1527 | status_t AudioSystem::setSupportedSystemUsages(const std::vector<audio_usage_t>& systemUsages) { |
| 1528 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1529 | if (aps == nullptr) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1530 | |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1531 | std::vector<AudioUsage> systemUsagesAidl = VALUE_OR_RETURN_STATUS( |
| 1532 | convertContainer<std::vector<AudioUsage>>(systemUsages, |
| 1533 | legacy2aidl_audio_usage_t_AudioUsage)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1534 | return statusTFromBinderStatus(aps->setSupportedSystemUsages(systemUsagesAidl)); |
| Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1535 | } |
| 1536 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1537 | status_t AudioSystem::setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t capturePolicy) { |
| Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1538 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1539 | if (aps == nullptr) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1540 | |
| 1541 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 1542 | int32_t capturePolicyAidl = VALUE_OR_RETURN_STATUS( |
| 1543 | legacy2aidl_audio_flags_mask_t_int32_t_mask(capturePolicy)); |
| 1544 | return statusTFromBinderStatus(aps->setAllowedCapturePolicy(uidAidl, capturePolicyAidl)); |
| Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1547 | audio_offload_mode_t AudioSystem::getOffloadSupport(const audio_offload_info_t& info) { |
| Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1548 | ALOGV("%s", __func__); |
| Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 1549 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1550 | if (aps == 0) return AUDIO_OFFLOAD_NOT_SUPPORTED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1551 | |
| 1552 | auto result = [&]() -> ConversionResult<audio_offload_mode_t> { |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1553 | AudioOffloadInfo infoAidl = VALUE_OR_RETURN( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1554 | legacy2aidl_audio_offload_info_t_AudioOffloadInfo(info)); |
| 1555 | media::AudioOffloadMode retAidl; |
| 1556 | RETURN_IF_ERROR( |
| 1557 | statusTFromBinderStatus(aps->getOffloadSupport(infoAidl, &retAidl))); |
| 1558 | return aidl2legacy_AudioOffloadMode_audio_offload_mode_t(retAidl); |
| 1559 | }(); |
| 1560 | |
| 1561 | return result.value_or(static_cast<audio_offload_mode_t>(0)); |
| Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 1562 | } |
| 1563 | |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1564 | status_t AudioSystem::listAudioPorts(audio_port_role_t role, |
| 1565 | audio_port_type_t type, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1566 | unsigned int* num_ports, |
| 1567 | struct audio_port_v7* ports, |
| 1568 | unsigned int* generation) { |
| 1569 | if (num_ports == nullptr || (*num_ports != 0 && ports == nullptr) || |
| 1570 | generation == nullptr) { |
| 1571 | return BAD_VALUE; |
| 1572 | } |
| 1573 | |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1574 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1575 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1576 | |
| 1577 | media::AudioPortRole roleAidl = VALUE_OR_RETURN_STATUS( |
| 1578 | legacy2aidl_audio_port_role_t_AudioPortRole(role)); |
| 1579 | media::AudioPortType typeAidl = VALUE_OR_RETURN_STATUS( |
| 1580 | legacy2aidl_audio_port_type_t_AudioPortType(type)); |
| Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 1581 | Int numPortsAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1582 | numPortsAidl.value = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*num_ports)); |
| Atneya Nair | c18e9a1 | 2022-12-18 16:45:15 -0800 | [diff] [blame] | 1583 | std::vector<media::AudioPortFw> portsAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1584 | int32_t generationAidl; |
| 1585 | |
| 1586 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1587 | aps->listAudioPorts(roleAidl, typeAidl, &numPortsAidl, &portsAidl, &generationAidl))); |
| 1588 | *num_ports = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(numPortsAidl.value)); |
| 1589 | *generation = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(generationAidl)); |
| 1590 | RETURN_STATUS_IF_ERROR(convertRange(portsAidl.begin(), portsAidl.end(), ports, |
| Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 1591 | aidl2legacy_AudioPortFw_audio_port_v7)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1592 | return OK; |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
| Mikhail Naganov | 15f4671 | 2023-03-23 14:52:15 -0700 | [diff] [blame] | 1595 | status_t AudioSystem::listDeclaredDevicePorts(media::AudioPortRole role, |
| 1596 | std::vector<media::AudioPortFw>* result) { |
| 1597 | if (result == nullptr) return BAD_VALUE; |
| 1598 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1599 | if (aps == 0) return PERMISSION_DENIED; |
| 1600 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(aps->listDeclaredDevicePorts(role, result))); |
| 1601 | return OK; |
| 1602 | } |
| 1603 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1604 | status_t AudioSystem::getAudioPort(struct audio_port_v7* port) { |
| 1605 | if (port == nullptr) { |
| 1606 | return BAD_VALUE; |
| 1607 | } |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1608 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1609 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1610 | |
| Atneya Nair | c18e9a1 | 2022-12-18 16:45:15 -0800 | [diff] [blame] | 1611 | media::AudioPortFw portAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1612 | RETURN_STATUS_IF_ERROR( |
| Mikhail Naganov | 1703156 | 2022-02-23 23:00:27 +0000 | [diff] [blame] | 1613 | statusTFromBinderStatus(aps->getAudioPort(port->id, &portAidl))); |
| Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 1614 | *port = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioPortFw_audio_port_v7(portAidl)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1615 | return OK; |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1618 | status_t AudioSystem::createAudioPatch(const struct audio_patch* patch, |
| 1619 | audio_patch_handle_t* handle) { |
| 1620 | if (patch == nullptr || handle == nullptr) { |
| 1621 | return BAD_VALUE; |
| 1622 | } |
| 1623 | |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1624 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1625 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1626 | |
| Atneya Nair | b6c50a3 | 2022-12-18 16:14:18 -0800 | [diff] [blame] | 1627 | media::AudioPatchFw patchAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 1628 | legacy2aidl_audio_patch_AudioPatchFw(*patch)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1629 | int32_t handleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(*handle)); |
| 1630 | RETURN_STATUS_IF_ERROR( |
| 1631 | statusTFromBinderStatus(aps->createAudioPatch(patchAidl, handleAidl, &handleAidl))); |
| 1632 | *handle = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_patch_handle_t(handleAidl)); |
| 1633 | return OK; |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1636 | status_t AudioSystem::releaseAudioPatch(audio_patch_handle_t handle) { |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1637 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1638 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1639 | |
| 1640 | int32_t handleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(handle)); |
| 1641 | return statusTFromBinderStatus(aps->releaseAudioPatch(handleAidl)); |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1642 | } |
| 1643 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1644 | status_t AudioSystem::listAudioPatches(unsigned int* num_patches, |
| 1645 | struct audio_patch* patches, |
| 1646 | unsigned int* generation) { |
| 1647 | if (num_patches == nullptr || (*num_patches != 0 && patches == nullptr) || |
| 1648 | generation == nullptr) { |
| 1649 | return BAD_VALUE; |
| 1650 | } |
| 1651 | |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1652 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1653 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1654 | |
| 1655 | |
| Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 1656 | Int numPatchesAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1657 | numPatchesAidl.value = VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*num_patches)); |
| Atneya Nair | b6c50a3 | 2022-12-18 16:14:18 -0800 | [diff] [blame] | 1658 | std::vector<media::AudioPatchFw> patchesAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1659 | int32_t generationAidl; |
| 1660 | |
| 1661 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1662 | aps->listAudioPatches(&numPatchesAidl, &patchesAidl, &generationAidl))); |
| 1663 | *num_patches = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(numPatchesAidl.value)); |
| 1664 | *generation = VALUE_OR_RETURN_STATUS(convertIntegral<unsigned int>(generationAidl)); |
| 1665 | RETURN_STATUS_IF_ERROR(convertRange(patchesAidl.begin(), patchesAidl.end(), patches, |
| Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 1666 | aidl2legacy_AudioPatchFw_audio_patch)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1667 | return OK; |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1670 | status_t AudioSystem::setAudioPortConfig(const struct audio_port_config* config) { |
| 1671 | if (config == nullptr) { |
| 1672 | return BAD_VALUE; |
| 1673 | } |
| 1674 | |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1675 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1676 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1677 | |
| Atneya Nair | b8de69b | 2022-12-18 17:26:26 -0800 | [diff] [blame] | 1678 | media::AudioPortConfigFw configAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 1679 | legacy2aidl_audio_port_config_AudioPortConfigFw(*config)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1680 | return statusTFromBinderStatus(aps->setAudioPortConfig(configAidl)); |
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1683 | status_t AudioSystem::addAudioPortCallback(const sp<AudioPortCallback>& callback) { |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1684 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1685 | if (aps == 0) return PERMISSION_DENIED; |
| 1686 | |
| 1687 | Mutex::Autolock _l(gLockAPS); |
| 1688 | if (gAudioPolicyServiceClient == 0) { |
| 1689 | return NO_INIT; |
| 1690 | } |
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1691 | int ret = gAudioPolicyServiceClient->addAudioPortCallback(callback); |
| 1692 | if (ret == 1) { |
| 1693 | aps->setAudioPortCallbacksEnabled(true); |
| 1694 | } |
| 1695 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 1698 | /*static*/ |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1699 | status_t AudioSystem::removeAudioPortCallback(const sp<AudioPortCallback>& callback) { |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1700 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1701 | if (aps == 0) return PERMISSION_DENIED; |
| 1702 | |
| 1703 | Mutex::Autolock _l(gLockAPS); |
| 1704 | if (gAudioPolicyServiceClient == 0) { |
| 1705 | return NO_INIT; |
| 1706 | } |
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 1707 | int ret = gAudioPolicyServiceClient->removeAudioPortCallback(callback); |
| 1708 | if (ret == 0) { |
| 1709 | aps->setAudioPortCallbacksEnabled(false); |
| 1710 | } |
| 1711 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1714 | status_t AudioSystem::addAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback) { |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1715 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1716 | if (aps == 0) return PERMISSION_DENIED; |
| 1717 | |
| 1718 | Mutex::Autolock _l(gLockAPS); |
| 1719 | if (gAudioPolicyServiceClient == 0) { |
| 1720 | return NO_INIT; |
| 1721 | } |
| 1722 | int ret = gAudioPolicyServiceClient->addAudioVolumeGroupCallback(callback); |
| 1723 | if (ret == 1) { |
| 1724 | aps->setAudioVolumeGroupCallbacksEnabled(true); |
| 1725 | } |
| 1726 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
| 1727 | } |
| 1728 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1729 | status_t AudioSystem::removeAudioVolumeGroupCallback(const sp<AudioVolumeGroupCallback>& callback) { |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1730 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1731 | if (aps == 0) return PERMISSION_DENIED; |
| 1732 | |
| 1733 | Mutex::Autolock _l(gLockAPS); |
| 1734 | if (gAudioPolicyServiceClient == 0) { |
| 1735 | return NO_INIT; |
| 1736 | } |
| 1737 | int ret = gAudioPolicyServiceClient->removeAudioVolumeGroupCallback(callback); |
| 1738 | if (ret == 0) { |
| 1739 | aps->setAudioVolumeGroupCallbacksEnabled(false); |
| 1740 | } |
| 1741 | return (ret < 0) ? INVALID_OPERATION : NO_ERROR; |
| 1742 | } |
| 1743 | |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1744 | status_t AudioSystem::addAudioDeviceCallback( |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1745 | const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1746 | audio_port_handle_t portId) { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1747 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 1748 | if (afc == 0) { |
| 1749 | return NO_INIT; |
| 1750 | } |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1751 | status_t status = afc->addAudioDeviceCallback(callback, audioIo, portId); |
| Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1752 | if (status == NO_ERROR) { |
| 1753 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1754 | if (af != 0) { |
| 1755 | af->registerClient(afc); |
| 1756 | } |
| 1757 | } |
| 1758 | return status; |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | status_t AudioSystem::removeAudioDeviceCallback( |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1762 | const wp<AudioDeviceCallback>& callback, audio_io_handle_t audioIo, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1763 | audio_port_handle_t portId) { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1764 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 1765 | if (afc == 0) { |
| 1766 | return NO_INIT; |
| 1767 | } |
| Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1768 | return afc->removeAudioDeviceCallback(callback, audioIo, portId); |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| Eric Laurent | 0825031 | 2022-05-03 18:12:28 +0200 | [diff] [blame] | 1771 | status_t AudioSystem::addSupportedLatencyModesCallback( |
| 1772 | const sp<SupportedLatencyModesCallback>& callback) { |
| 1773 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 1774 | if (afc == 0) { |
| 1775 | return NO_INIT; |
| 1776 | } |
| 1777 | return afc->addSupportedLatencyModesCallback(callback); |
| 1778 | } |
| 1779 | |
| 1780 | status_t AudioSystem::removeSupportedLatencyModesCallback( |
| 1781 | const sp<SupportedLatencyModesCallback>& callback) { |
| 1782 | const sp<AudioFlingerClient> afc = getAudioFlingerClient(); |
| 1783 | if (afc == 0) { |
| 1784 | return NO_INIT; |
| 1785 | } |
| 1786 | return afc->removeSupportedLatencyModesCallback(callback); |
| 1787 | } |
| 1788 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1789 | audio_port_handle_t AudioSystem::getDeviceIdForIo(audio_io_handle_t audioIo) { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 1790 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1791 | if (af == 0) return PERMISSION_DENIED; |
| 1792 | const sp<AudioIoDescriptor> desc = getIoDescriptor(audioIo); |
| 1793 | if (desc == 0) { |
| 1794 | return AUDIO_PORT_HANDLE_NONE; |
| 1795 | } |
| 1796 | return desc->getDeviceId(); |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1799 | status_t AudioSystem::acquireSoundTriggerSession(audio_session_t* session, |
| 1800 | audio_io_handle_t* ioHandle, |
| 1801 | audio_devices_t* device) { |
| 1802 | if (session == nullptr || ioHandle == nullptr || device == nullptr) { |
| 1803 | return BAD_VALUE; |
| 1804 | } |
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1805 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1806 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1807 | |
| 1808 | media::SoundTriggerSession retAidl; |
| 1809 | RETURN_STATUS_IF_ERROR( |
| 1810 | statusTFromBinderStatus(aps->acquireSoundTriggerSession(&retAidl))); |
| 1811 | *session = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_session_t(retAidl.session)); |
| 1812 | *ioHandle = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_io_handle_t(retAidl.ioHandle)); |
| Mikhail Naganov | 21a32ec | 2021-07-08 14:40:12 -0700 | [diff] [blame] | 1813 | *device = VALUE_OR_RETURN_STATUS( |
| 1814 | aidl2legacy_AudioDeviceDescription_audio_devices_t(retAidl.device)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1815 | return OK; |
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1818 | status_t AudioSystem::releaseSoundTriggerSession(audio_session_t session) { |
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1819 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1820 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1821 | |
| 1822 | int32_t sessionAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_session_t_int32_t(session)); |
| 1823 | return statusTFromBinderStatus(aps->releaseSoundTriggerSession(sessionAidl)); |
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1824 | } |
| Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1825 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1826 | audio_mode_t AudioSystem::getPhoneState() { |
| Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1827 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1828 | if (aps == 0) return AUDIO_MODE_INVALID; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1829 | |
| 1830 | auto result = [&]() -> ConversionResult<audio_mode_t> { |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 1831 | media::audio::common::AudioMode retAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1832 | RETURN_IF_ERROR(statusTFromBinderStatus(aps->getPhoneState(&retAidl))); |
| 1833 | return aidl2legacy_AudioMode_audio_mode_t(retAidl); |
| 1834 | }(); |
| 1835 | |
| 1836 | return result.value_or(AUDIO_MODE_INVALID); |
| Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1839 | status_t AudioSystem::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) { |
| Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1840 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1841 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1842 | |
| 1843 | size_t mixesSize = std::min(mixes.size(), size_t{MAX_MIXES_PER_POLICY}); |
| 1844 | std::vector<media::AudioMix> mixesAidl; |
| 1845 | RETURN_STATUS_IF_ERROR( |
| 1846 | convertRange(mixes.begin(), mixes.begin() + mixesSize, std::back_inserter(mixesAidl), |
| 1847 | legacy2aidl_AudioMix)); |
| 1848 | return statusTFromBinderStatus(aps->registerPolicyMixes(mixesAidl, registration)); |
| Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1849 | } |
| Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 1850 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1851 | status_t AudioSystem::setUidDeviceAffinities(uid_t uid, const AudioDeviceTypeAddrVector& devices) { |
| Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1852 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1853 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1854 | |
| 1855 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 1856 | std::vector<AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 1857 | convertContainer<std::vector<AudioDevice>>(devices, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1858 | legacy2aidl_AudioDeviceTypeAddress)); |
| 1859 | return statusTFromBinderStatus(aps->setUidDeviceAffinities(uidAidl, devicesAidl)); |
| Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | status_t AudioSystem::removeUidDeviceAffinities(uid_t uid) { |
| 1863 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1864 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1865 | |
| 1866 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 1867 | return statusTFromBinderStatus(aps->removeUidDeviceAffinities(uidAidl)); |
| Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1868 | } |
| 1869 | |
| Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1870 | status_t AudioSystem::setUserIdDeviceAffinities(int userId, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1871 | const AudioDeviceTypeAddrVector& devices) { |
| Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1872 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1873 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1874 | |
| 1875 | int32_t userIdAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(userId)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 1876 | std::vector<AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 1877 | convertContainer<std::vector<AudioDevice>>(devices, |
| 1878 | legacy2aidl_AudioDeviceTypeAddress)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1879 | return statusTFromBinderStatus( |
| 1880 | aps->setUserIdDeviceAffinities(userIdAidl, devicesAidl)); |
| Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1881 | } |
| 1882 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1883 | status_t AudioSystem::removeUserIdDeviceAffinities(int userId) { |
| Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1884 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1885 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1886 | int32_t userIdAidl = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(userId)); |
| 1887 | return statusTFromBinderStatus(aps->removeUserIdDeviceAffinities(userIdAidl)); |
| Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1888 | } |
| 1889 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1890 | status_t AudioSystem::startAudioSource(const struct audio_port_config* source, |
| 1891 | const audio_attributes_t* attributes, |
| 1892 | audio_port_handle_t* portId) { |
| 1893 | if (source == nullptr || attributes == nullptr || portId == nullptr) { |
| 1894 | return BAD_VALUE; |
| 1895 | } |
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1896 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1897 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1898 | |
| Atneya Nair | b8de69b | 2022-12-18 17:26:26 -0800 | [diff] [blame] | 1899 | media::AudioPortConfigFw sourceAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | 8722725 | 2023-01-13 17:38:10 -0800 | [diff] [blame] | 1900 | legacy2aidl_audio_port_config_AudioPortConfigFw(*source)); |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 1901 | media::audio::common::AudioAttributes attributesAidl = VALUE_OR_RETURN_STATUS( |
| 1902 | legacy2aidl_audio_attributes_t_AudioAttributes(*attributes)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1903 | int32_t portIdAidl; |
| 1904 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 1905 | aps->startAudioSource(sourceAidl, attributesAidl, &portIdAidl))); |
| 1906 | *portId = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 1907 | return OK; |
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1908 | } |
| 1909 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1910 | status_t AudioSystem::stopAudioSource(audio_port_handle_t portId) { |
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1911 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1912 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1913 | |
| 1914 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1915 | return statusTFromBinderStatus(aps->stopAudioSource(portIdAidl)); |
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1918 | status_t AudioSystem::setMasterMono(bool mono) { |
| Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1919 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1920 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1921 | return statusTFromBinderStatus(aps->setMasterMono(mono)); |
| Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1922 | } |
| 1923 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1924 | status_t AudioSystem::getMasterMono(bool* mono) { |
| 1925 | if (mono == nullptr) { |
| 1926 | return BAD_VALUE; |
| 1927 | } |
| Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1928 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1929 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1930 | return statusTFromBinderStatus(aps->getMasterMono(mono)); |
| Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1931 | } |
| 1932 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1933 | status_t AudioSystem::setMasterBalance(float balance) { |
| Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1934 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1935 | if (af == 0) return PERMISSION_DENIED; |
| 1936 | return af->setMasterBalance(balance); |
| 1937 | } |
| 1938 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1939 | status_t AudioSystem::getMasterBalance(float* balance) { |
| Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1940 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1941 | if (af == 0) return PERMISSION_DENIED; |
| 1942 | return af->getMasterBalance(balance); |
| 1943 | } |
| 1944 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1945 | float |
| 1946 | AudioSystem::getStreamVolumeDB(audio_stream_type_t stream, int index, audio_devices_t device) { |
| Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1947 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1948 | if (aps == 0) return NAN; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1949 | |
| 1950 | auto result = [&]() -> ConversionResult<float> { |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 1951 | AudioStreamType streamAidl = VALUE_OR_RETURN( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1952 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 1953 | int32_t indexAidl = VALUE_OR_RETURN(convertIntegral<int32_t>(index)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 1954 | AudioDeviceDescription deviceAidl = VALUE_OR_RETURN( |
| Mikhail Naganov | 21a32ec | 2021-07-08 14:40:12 -0700 | [diff] [blame] | 1955 | legacy2aidl_audio_devices_t_AudioDeviceDescription(device)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1956 | float retAidl; |
| 1957 | RETURN_IF_ERROR(statusTFromBinderStatus( |
| 1958 | aps->getStreamVolumeDB(streamAidl, indexAidl, deviceAidl, &retAidl))); |
| 1959 | return retAidl; |
| 1960 | }(); |
| 1961 | return result.value_or(NAN); |
| Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| Mikhail Naganov | 2a6a301 | 2023-02-13 11:45:03 -0800 | [diff] [blame] | 1964 | status_t AudioSystem::getMicrophones(std::vector<media::MicrophoneInfoFw>* microphones) { |
| jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 1965 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1966 | if (af == 0) return PERMISSION_DENIED; |
| 1967 | return af->getMicrophones(microphones); |
| 1968 | } |
| 1969 | |
| Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 1970 | status_t AudioSystem::setAudioHalPids(const std::vector<pid_t>& pids) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1971 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 1972 | if (af == nullptr) return PERMISSION_DENIED; |
| 1973 | return af->setAudioHalPids(pids); |
| Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1976 | status_t AudioSystem::getSurroundFormats(unsigned int* numSurroundFormats, |
| 1977 | audio_format_t* surroundFormats, |
| Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1978 | bool* surroundFormatsEnabled) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1979 | if (numSurroundFormats == nullptr || (*numSurroundFormats != 0 && |
| 1980 | (surroundFormats == nullptr || |
| 1981 | surroundFormatsEnabled == nullptr))) { |
| 1982 | return BAD_VALUE; |
| 1983 | } |
| 1984 | |
| jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1985 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 1986 | if (aps == 0) return PERMISSION_DENIED; |
| Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 1987 | Int numSurroundFormatsAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1988 | numSurroundFormatsAidl.value = |
| 1989 | VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*numSurroundFormats)); |
| Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 1990 | std::vector<AudioFormatDescription> surroundFormatsAidl; |
| Kriti Dang | 877b27e | 2021-02-02 12:10:40 +0100 | [diff] [blame] | 1991 | std::vector<bool> surroundFormatsEnabledAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1992 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 1993 | aps->getSurroundFormats(&numSurroundFormatsAidl, &surroundFormatsAidl, |
| 1994 | &surroundFormatsEnabledAidl))); |
| Kriti Dang | 877b27e | 2021-02-02 12:10:40 +0100 | [diff] [blame] | 1995 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1996 | *numSurroundFormats = VALUE_OR_RETURN_STATUS( |
| 1997 | convertIntegral<unsigned int>(numSurroundFormatsAidl.value)); |
| 1998 | RETURN_STATUS_IF_ERROR( |
| 1999 | convertRange(surroundFormatsAidl.begin(), surroundFormatsAidl.end(), surroundFormats, |
| Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 2000 | aidl2legacy_AudioFormatDescription_audio_format_t)); |
| Kriti Dang | 877b27e | 2021-02-02 12:10:40 +0100 | [diff] [blame] | 2001 | std::copy(surroundFormatsEnabledAidl.begin(), surroundFormatsEnabledAidl.end(), |
| 2002 | surroundFormatsEnabled); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2003 | return OK; |
| jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 2006 | status_t AudioSystem::getReportedSurroundFormats(unsigned int* numSurroundFormats, |
| 2007 | audio_format_t* surroundFormats) { |
| 2008 | if (numSurroundFormats == nullptr || (*numSurroundFormats != 0 && surroundFormats == nullptr)) { |
| 2009 | return BAD_VALUE; |
| 2010 | } |
| 2011 | |
| 2012 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2013 | if (aps == 0) return PERMISSION_DENIED; |
| Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 2014 | Int numSurroundFormatsAidl; |
| Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 2015 | numSurroundFormatsAidl.value = |
| 2016 | VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*numSurroundFormats)); |
| Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 2017 | std::vector<AudioFormatDescription> surroundFormatsAidl; |
| Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 2018 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2019 | aps->getReportedSurroundFormats(&numSurroundFormatsAidl, &surroundFormatsAidl))); |
| 2020 | |
| 2021 | *numSurroundFormats = VALUE_OR_RETURN_STATUS( |
| 2022 | convertIntegral<unsigned int>(numSurroundFormatsAidl.value)); |
| 2023 | RETURN_STATUS_IF_ERROR( |
| 2024 | convertRange(surroundFormatsAidl.begin(), surroundFormatsAidl.end(), surroundFormats, |
| Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 2025 | aidl2legacy_AudioFormatDescription_audio_format_t)); |
| Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 2026 | return OK; |
| 2027 | } |
| 2028 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2029 | status_t AudioSystem::setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) { |
| jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 2030 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2031 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2032 | |
| Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 2033 | AudioFormatDescription audioFormatAidl = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 2034 | legacy2aidl_audio_format_t_AudioFormatDescription(audioFormat)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2035 | return statusTFromBinderStatus( |
| 2036 | aps->setSurroundFormatEnabled(audioFormatAidl, enabled)); |
| jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 2037 | } |
| 2038 | |
| Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 2039 | status_t AudioSystem::setAssistantServicesUids(const std::vector<uid_t>& uids) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2040 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 2041 | if (aps == 0) return PERMISSION_DENIED; |
| 2042 | |
| Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 2043 | std::vector<int32_t> uidsAidl = VALUE_OR_RETURN_STATUS( |
| 2044 | convertContainer<std::vector<int32_t>>(uids, legacy2aidl_uid_t_int32_t)); |
| 2045 | return statusTFromBinderStatus(aps->setAssistantServicesUids(uidsAidl)); |
| Ahaan Ugale | f51ce00 | 2021-08-04 16:34:20 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
| Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 2048 | status_t AudioSystem::setActiveAssistantServicesUids(const std::vector<uid_t>& activeUids) { |
| 2049 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2050 | if (aps == 0) return PERMISSION_DENIED; |
| 2051 | |
| 2052 | std::vector<int32_t> activeUidsAidl = VALUE_OR_RETURN_STATUS( |
| 2053 | convertContainer<std::vector<int32_t>>(activeUids, legacy2aidl_uid_t_int32_t)); |
| 2054 | return statusTFromBinderStatus(aps->setActiveAssistantServicesUids(activeUidsAidl)); |
| 2055 | } |
| 2056 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2057 | status_t AudioSystem::setA11yServicesUids(const std::vector<uid_t>& uids) { |
| 2058 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 2059 | if (aps == 0) return PERMISSION_DENIED; |
| 2060 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2061 | std::vector<int32_t> uidsAidl = VALUE_OR_RETURN_STATUS( |
| 2062 | convertContainer<std::vector<int32_t>>(uids, legacy2aidl_uid_t_int32_t)); |
| 2063 | return statusTFromBinderStatus(aps->setA11yServicesUids(uidsAidl)); |
| Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2066 | status_t AudioSystem::setCurrentImeUid(uid_t uid) { |
| 2067 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 2068 | if (aps == 0) return PERMISSION_DENIED; |
| 2069 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2070 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 2071 | return statusTFromBinderStatus(aps->setCurrentImeUid(uidAidl)); |
| Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2074 | bool AudioSystem::isHapticPlaybackSupported() { |
| jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 2075 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2076 | if (aps == 0) return false; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2077 | |
| 2078 | auto result = [&]() -> ConversionResult<bool> { |
| 2079 | bool retVal; |
| 2080 | RETURN_IF_ERROR( |
| 2081 | statusTFromBinderStatus(aps->isHapticPlaybackSupported(&retVal))); |
| 2082 | return retVal; |
| 2083 | }(); |
| 2084 | return result.value_or(false); |
| jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| Carter Hsu | 325a8eb | 2022-01-19 19:56:51 +0800 | [diff] [blame] | 2087 | bool AudioSystem::isUltrasoundSupported() { |
| 2088 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2089 | if (aps == 0) return false; |
| 2090 | |
| 2091 | auto result = [&]() -> ConversionResult<bool> { |
| 2092 | bool retVal; |
| 2093 | RETURN_IF_ERROR( |
| 2094 | statusTFromBinderStatus(aps->isUltrasoundSupported(&retVal))); |
| 2095 | return retVal; |
| 2096 | }(); |
| 2097 | return result.value_or(false); |
| 2098 | } |
| 2099 | |
| Patty | dd80758 | 2021-11-04 21:01:03 +0800 | [diff] [blame] | 2100 | status_t AudioSystem::getHwOffloadFormatsSupportedForBluetoothMedia( |
| 2101 | audio_devices_t device, std::vector<audio_format_t>* formats) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2102 | if (formats == nullptr) { |
| 2103 | return BAD_VALUE; |
| 2104 | } |
| 2105 | |
| 2106 | const sp<IAudioPolicyService> |
| 2107 | & aps = AudioSystem::get_audio_policy_service(); |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2108 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2109 | |
| Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 2110 | std::vector<AudioFormatDescription> formatsAidl; |
| Patty | dd80758 | 2021-11-04 21:01:03 +0800 | [diff] [blame] | 2111 | AudioDeviceDescription deviceAidl = VALUE_OR_RETURN_STATUS( |
| 2112 | legacy2aidl_audio_devices_t_AudioDeviceDescription(device)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2113 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| Patty | dd80758 | 2021-11-04 21:01:03 +0800 | [diff] [blame] | 2114 | aps->getHwOffloadFormatsSupportedForBluetoothMedia(deviceAidl, &formatsAidl))); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2115 | *formats = VALUE_OR_RETURN_STATUS( |
| Mikhail Naganov | b60bd1b | 2021-07-15 17:31:43 -0700 | [diff] [blame] | 2116 | convertContainer<std::vector<audio_format_t>>( |
| 2117 | formatsAidl, |
| 2118 | aidl2legacy_AudioFormatDescription_audio_format_t)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2119 | return OK; |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2120 | } |
| 2121 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2122 | status_t AudioSystem::listAudioProductStrategies(AudioProductStrategyVector& strategies) { |
| Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 2123 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2124 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2125 | |
| 2126 | std::vector<media::AudioProductStrategy> strategiesAidl; |
| 2127 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2128 | aps->listAudioProductStrategies(&strategiesAidl))); |
| 2129 | strategies = VALUE_OR_RETURN_STATUS( |
| 2130 | convertContainer<AudioProductStrategyVector>(strategiesAidl, |
| 2131 | aidl2legacy_AudioProductStrategy)); |
| 2132 | return OK; |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2133 | } |
| 2134 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2135 | audio_attributes_t AudioSystem::streamTypeToAttributes(audio_stream_type_t stream) { |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2136 | AudioProductStrategyVector strategies; |
| 2137 | listAudioProductStrategies(strategies); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2138 | for (const auto& strategy : strategies) { |
| François Gaffie | f6d3bbe | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 2139 | auto attrVect = strategy.getVolumeGroupAttributes(); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2140 | auto iter = std::find_if(begin(attrVect), end(attrVect), [&stream](const auto& attributes) { |
| 2141 | return attributes.getStreamType() == stream; |
| 2142 | }); |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2143 | if (iter != end(attrVect)) { |
| 2144 | return iter->getAttributes(); |
| 2145 | } |
| 2146 | } |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2147 | ALOGE("invalid stream type %s when converting to attributes", toString(stream).c_str()); |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2148 | return AUDIO_ATTRIBUTES_INITIALIZER; |
| 2149 | } |
| 2150 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2151 | audio_stream_type_t AudioSystem::attributesToStreamType(const audio_attributes_t& attr) { |
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2152 | product_strategy_t psId; |
| François Gaffie | f6d3bbe | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 2153 | status_t ret = AudioSystem::getProductStrategyFromAudioAttributes(attr, psId); |
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2154 | if (ret != NO_ERROR) { |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2155 | ALOGE("no strategy found for attributes %s", toString(attr).c_str()); |
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2156 | return AUDIO_STREAM_MUSIC; |
| 2157 | } |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2158 | AudioProductStrategyVector strategies; |
| 2159 | listAudioProductStrategies(strategies); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2160 | for (const auto& strategy : strategies) { |
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2161 | if (strategy.getId() == psId) { |
| François Gaffie | f6d3bbe | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 2162 | auto attrVect = strategy.getVolumeGroupAttributes(); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2163 | auto iter = std::find_if(begin(attrVect), end(attrVect), [&attr](const auto& refAttr) { |
| François Gaffie | bc55c9d | 2023-01-17 17:28:09 +0100 | [diff] [blame] | 2164 | return refAttr.matchesScore(attr) > 0; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2165 | }); |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2166 | if (iter != end(attrVect)) { |
| 2167 | return iter->getStreamType(); |
| 2168 | } |
| 2169 | } |
| 2170 | } |
| Jean-Michel Trivi | ed67865 | 2019-12-19 13:39:30 -0800 | [diff] [blame] | 2171 | switch (attr.usage) { |
| 2172 | case AUDIO_USAGE_VIRTUAL_SOURCE: |
| 2173 | // virtual source is not expected to have an associated product strategy |
| 2174 | break; |
| 2175 | default: |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2176 | ALOGE("invalid attributes %s when converting to stream", toString(attr).c_str()); |
| Jean-Michel Trivi | ed67865 | 2019-12-19 13:39:30 -0800 | [diff] [blame] | 2177 | break; |
| 2178 | } |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2179 | return AUDIO_STREAM_MUSIC; |
| 2180 | } |
| 2181 | |
| François Gaffie | f6d3bbe | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 2182 | status_t AudioSystem::getProductStrategyFromAudioAttributes(const audio_attributes_t& aa, |
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 2183 | product_strategy_t& productStrategy, |
| 2184 | bool fallbackOnDefault) { |
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 2185 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2186 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2187 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 2188 | media::audio::common::AudioAttributes aaAidl = VALUE_OR_RETURN_STATUS( |
| 2189 | legacy2aidl_audio_attributes_t_AudioAttributes(aa)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2190 | int32_t productStrategyAidl; |
| 2191 | |
| 2192 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 2193 | aps->getProductStrategyFromAudioAttributes(aaAidl, fallbackOnDefault, |
| 2194 | &productStrategyAidl))); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2195 | productStrategy = VALUE_OR_RETURN_STATUS( |
| 2196 | aidl2legacy_int32_t_product_strategy_t(productStrategyAidl)); |
| 2197 | return OK; |
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2198 | } |
| 2199 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2200 | status_t AudioSystem::listAudioVolumeGroups(AudioVolumeGroupVector& groups) { |
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2201 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2202 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2203 | |
| 2204 | std::vector<media::AudioVolumeGroup> groupsAidl; |
| 2205 | RETURN_STATUS_IF_ERROR( |
| 2206 | statusTFromBinderStatus(aps->listAudioVolumeGroups(&groupsAidl))); |
| 2207 | groups = VALUE_OR_RETURN_STATUS( |
| 2208 | convertContainer<AudioVolumeGroupVector>(groupsAidl, aidl2legacy_AudioVolumeGroup)); |
| 2209 | return OK; |
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2210 | } |
| 2211 | |
| François Gaffie | f6d3bbe | 2022-04-01 14:34:29 +0200 | [diff] [blame] | 2212 | status_t AudioSystem::getVolumeGroupFromAudioAttributes(const audio_attributes_t &aa, |
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 2213 | volume_group_t& volumeGroup, |
| 2214 | bool fallbackOnDefault) { |
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 2215 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2216 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2217 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 2218 | media::audio::common::AudioAttributes aaAidl = VALUE_OR_RETURN_STATUS( |
| 2219 | legacy2aidl_audio_attributes_t_AudioAttributes(aa)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2220 | int32_t volumeGroupAidl; |
| 2221 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| Francois Gaffie | 11b6592 | 2020-09-24 16:59:08 +0200 | [diff] [blame] | 2222 | aps->getVolumeGroupFromAudioAttributes(aaAidl, fallbackOnDefault, &volumeGroupAidl))); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2223 | volumeGroup = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_volume_group_t(volumeGroupAidl)); |
| 2224 | return OK; |
| Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 2225 | } |
| Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 2226 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2227 | status_t AudioSystem::setRttEnabled(bool enabled) { |
| Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 2228 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2229 | if (aps == 0) return PERMISSION_DENIED; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2230 | return statusTFromBinderStatus(aps->setRttEnabled(enabled)); |
| Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2233 | bool AudioSystem::isCallScreenModeSupported() { |
| Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 2234 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2235 | if (aps == 0) return false; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2236 | |
| 2237 | auto result = [&]() -> ConversionResult<bool> { |
| 2238 | bool retAidl; |
| 2239 | RETURN_IF_ERROR( |
| 2240 | statusTFromBinderStatus(aps->isCallScreenModeSupported(&retAidl))); |
| 2241 | return retAidl; |
| 2242 | }(); |
| 2243 | return result.value_or(false); |
| Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 2244 | } |
| 2245 | |
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 2246 | status_t AudioSystem::setDevicesRoleForStrategy(product_strategy_t strategy, |
| 2247 | device_role_t role, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2248 | const AudioDeviceTypeAddrVector& devices) { |
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2249 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2250 | if (aps == 0) { |
| 2251 | return PERMISSION_DENIED; |
| 2252 | } |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2253 | |
| 2254 | int32_t strategyAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_product_strategy_t_int32_t(strategy)); |
| 2255 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 2256 | std::vector<AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2257 | convertContainer<std::vector<AudioDevice>>(devices, |
| 2258 | legacy2aidl_AudioDeviceTypeAddress)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2259 | return statusTFromBinderStatus( |
| 2260 | aps->setDevicesRoleForStrategy(strategyAidl, roleAidl, devicesAidl)); |
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| Paul Wang | 5d7cdb5 | 2022-11-22 09:45:06 +0000 | [diff] [blame] | 2263 | status_t AudioSystem::removeDevicesRoleForStrategy(product_strategy_t strategy, |
| 2264 | device_role_t role, |
| 2265 | const AudioDeviceTypeAddrVector& devices) { |
| 2266 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2267 | if (aps == 0) { |
| 2268 | return PERMISSION_DENIED; |
| 2269 | } |
| 2270 | |
| 2271 | int32_t strategyAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_product_strategy_t_int32_t(strategy)); |
| 2272 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2273 | std::vector<AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2274 | convertContainer<std::vector<AudioDevice>>(devices, |
| 2275 | legacy2aidl_AudioDeviceTypeAddress)); |
| 2276 | return statusTFromBinderStatus( |
| 2277 | aps->removeDevicesRoleForStrategy(strategyAidl, roleAidl, devicesAidl)); |
| 2278 | } |
| 2279 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2280 | status_t |
| Paul Wang | 5d7cdb5 | 2022-11-22 09:45:06 +0000 | [diff] [blame] | 2281 | AudioSystem::clearDevicesRoleForStrategy(product_strategy_t strategy, device_role_t role) { |
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2282 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2283 | if (aps == 0) { |
| 2284 | return PERMISSION_DENIED; |
| 2285 | } |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2286 | int32_t strategyAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_product_strategy_t_int32_t(strategy)); |
| 2287 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2288 | return statusTFromBinderStatus( |
| Paul Wang | 5d7cdb5 | 2022-11-22 09:45:06 +0000 | [diff] [blame] | 2289 | aps->clearDevicesRoleForStrategy(strategyAidl, roleAidl)); |
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
| jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 2292 | status_t AudioSystem::getDevicesForRoleAndStrategy(product_strategy_t strategy, |
| 2293 | device_role_t role, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2294 | AudioDeviceTypeAddrVector& devices) { |
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2295 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2296 | if (aps == 0) { |
| 2297 | return PERMISSION_DENIED; |
| 2298 | } |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2299 | int32_t strategyAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_product_strategy_t_int32_t(strategy)); |
| 2300 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 2301 | std::vector<AudioDevice> devicesAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2302 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2303 | aps->getDevicesForRoleAndStrategy(strategyAidl, roleAidl, &devicesAidl))); |
| 2304 | devices = VALUE_OR_RETURN_STATUS( |
| 2305 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2306 | aidl2legacy_AudioDeviceTypeAddress)); |
| 2307 | return OK; |
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2310 | status_t AudioSystem::setDevicesRoleForCapturePreset(audio_source_t audioSource, |
| 2311 | device_role_t role, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2312 | const AudioDeviceTypeAddrVector& devices) { |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2313 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2314 | if (aps == 0) { |
| 2315 | return PERMISSION_DENIED; |
| 2316 | } |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2317 | |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 2318 | AudioSource audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2319 | legacy2aidl_audio_source_t_AudioSource(audioSource)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2320 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 2321 | std::vector<AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2322 | convertContainer<std::vector<AudioDevice>>(devices, |
| 2323 | legacy2aidl_AudioDeviceTypeAddress)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2324 | return statusTFromBinderStatus( |
| 2325 | aps->setDevicesRoleForCapturePreset(audioSourceAidl, roleAidl, devicesAidl)); |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | status_t AudioSystem::addDevicesRoleForCapturePreset(audio_source_t audioSource, |
| 2329 | device_role_t role, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2330 | const AudioDeviceTypeAddrVector& devices) { |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2331 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2332 | if (aps == 0) { |
| 2333 | return PERMISSION_DENIED; |
| 2334 | } |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 2335 | AudioSource audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2336 | legacy2aidl_audio_source_t_AudioSource(audioSource)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2337 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 2338 | std::vector<AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2339 | convertContainer<std::vector<AudioDevice>>(devices, |
| 2340 | legacy2aidl_AudioDeviceTypeAddress)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2341 | return statusTFromBinderStatus( |
| 2342 | aps->addDevicesRoleForCapturePreset(audioSourceAidl, roleAidl, devicesAidl)); |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | status_t AudioSystem::removeDevicesRoleForCapturePreset( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2346 | audio_source_t audioSource, device_role_t role, const AudioDeviceTypeAddrVector& devices) { |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2347 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2348 | if (aps == 0) { |
| 2349 | return PERMISSION_DENIED; |
| 2350 | } |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 2351 | AudioSource audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2352 | legacy2aidl_audio_source_t_AudioSource(audioSource)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2353 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 2354 | std::vector<AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2355 | convertContainer<std::vector<AudioDevice>>(devices, |
| 2356 | legacy2aidl_AudioDeviceTypeAddress)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2357 | return statusTFromBinderStatus( |
| 2358 | aps->removeDevicesRoleForCapturePreset(audioSourceAidl, roleAidl, devicesAidl)); |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | status_t AudioSystem::clearDevicesRoleForCapturePreset(audio_source_t audioSource, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2362 | device_role_t role) { |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2363 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2364 | if (aps == 0) { |
| 2365 | return PERMISSION_DENIED; |
| 2366 | } |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 2367 | AudioSource audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2368 | legacy2aidl_audio_source_t_AudioSource(audioSource)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2369 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| 2370 | return statusTFromBinderStatus( |
| 2371 | aps->clearDevicesRoleForCapturePreset(audioSourceAidl, roleAidl)); |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | status_t AudioSystem::getDevicesForRoleAndCapturePreset(audio_source_t audioSource, |
| 2375 | device_role_t role, |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2376 | AudioDeviceTypeAddrVector& devices) { |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2377 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2378 | if (aps == 0) { |
| 2379 | return PERMISSION_DENIED; |
| 2380 | } |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 2381 | AudioSource audioSourceAidl = VALUE_OR_RETURN_STATUS( |
| 2382 | legacy2aidl_audio_source_t_AudioSource(audioSource)); |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2383 | media::DeviceRole roleAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_device_role_t_DeviceRole(role)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 2384 | std::vector<AudioDevice> devicesAidl; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2385 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2386 | aps->getDevicesForRoleAndCapturePreset(audioSourceAidl, roleAidl, &devicesAidl))); |
| 2387 | devices = VALUE_OR_RETURN_STATUS( |
| 2388 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2389 | aidl2legacy_AudioDeviceTypeAddress)); |
| 2390 | return OK; |
| Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
| Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 2393 | status_t AudioSystem::getSpatializer(const sp<media::INativeSpatializerCallback>& callback, |
| 2394 | sp<media::ISpatializer>* spatializer) { |
| 2395 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2396 | if (spatializer == nullptr) { |
| 2397 | return BAD_VALUE; |
| 2398 | } |
| 2399 | if (aps == 0) { |
| 2400 | return PERMISSION_DENIED; |
| 2401 | } |
| 2402 | media::GetSpatializerResponse response; |
| 2403 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2404 | aps->getSpatializer(callback, &response))); |
| 2405 | |
| 2406 | *spatializer = response.spatializer; |
| 2407 | return OK; |
| 2408 | } |
| 2409 | |
| 2410 | status_t AudioSystem::canBeSpatialized(const audio_attributes_t *attr, |
| 2411 | const audio_config_t *config, |
| 2412 | const AudioDeviceTypeAddrVector &devices, |
| 2413 | bool *canBeSpatialized) { |
| 2414 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| Ram Mohan | 4329701 | 2022-08-30 16:11:49 +0530 | [diff] [blame] | 2415 | if (canBeSpatialized == nullptr) { |
| 2416 | return BAD_VALUE; |
| 2417 | } |
| Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 2418 | if (aps == 0) { |
| 2419 | return PERMISSION_DENIED; |
| 2420 | } |
| 2421 | audio_attributes_t attributes = attr != nullptr ? *attr : AUDIO_ATTRIBUTES_INITIALIZER; |
| 2422 | audio_config_t configuration = config != nullptr ? *config : AUDIO_CONFIG_INITIALIZER; |
| 2423 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 2424 | std::optional<media::audio::common::AudioAttributes> attrAidl = VALUE_OR_RETURN_STATUS( |
| 2425 | legacy2aidl_audio_attributes_t_AudioAttributes(attributes)); |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 2426 | std::optional<AudioConfig> configAidl = VALUE_OR_RETURN_STATUS( |
| Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 2427 | legacy2aidl_audio_config_t_AudioConfig(configuration, false /*isInput*/)); |
| Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 2428 | std::vector<AudioDevice> devicesAidl = VALUE_OR_RETURN_STATUS( |
| 2429 | convertContainer<std::vector<AudioDevice>>(devices, |
| 2430 | legacy2aidl_AudioDeviceTypeAddress)); |
| Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 2431 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2432 | aps->canBeSpatialized(attrAidl, configAidl, devicesAidl, canBeSpatialized))); |
| 2433 | return OK; |
| 2434 | } |
| 2435 | |
| Vlad Popa | e3fd1c2 | 2022-11-07 21:03:18 +0100 | [diff] [blame] | 2436 | status_t AudioSystem::getSoundDoseInterface(const sp<media::ISoundDoseCallback>& callback, |
| 2437 | sp<media::ISoundDose>* soundDose) { |
| Vlad Popa | 63f047e | 2022-11-05 14:09:19 +0100 | [diff] [blame] | 2438 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2439 | if (af == nullptr) { |
| 2440 | return PERMISSION_DENIED; |
| 2441 | } |
| Vlad Popa | e3fd1c2 | 2022-11-07 21:03:18 +0100 | [diff] [blame] | 2442 | if (soundDose == nullptr) { |
| 2443 | return BAD_VALUE; |
| 2444 | } |
| Vlad Popa | 63f047e | 2022-11-05 14:09:19 +0100 | [diff] [blame] | 2445 | |
| Vlad Popa | e3fd1c2 | 2022-11-07 21:03:18 +0100 | [diff] [blame] | 2446 | RETURN_STATUS_IF_ERROR(af->getSoundDoseInterface(callback, soundDose)); |
| 2447 | return OK; |
| Vlad Popa | 63f047e | 2022-11-05 14:09:19 +0100 | [diff] [blame] | 2448 | } |
| 2449 | |
| jiabin | 2b9d5a1 | 2021-12-10 01:06:29 +0000 | [diff] [blame] | 2450 | status_t AudioSystem::getDirectPlaybackSupport(const audio_attributes_t *attr, |
| 2451 | const audio_config_t *config, |
| 2452 | audio_direct_mode_t* directMode) { |
| 2453 | if (attr == nullptr || config == nullptr || directMode == nullptr) { |
| 2454 | return BAD_VALUE; |
| 2455 | } |
| 2456 | |
| 2457 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2458 | if (aps == 0) { |
| 2459 | return PERMISSION_DENIED; |
| 2460 | } |
| 2461 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 2462 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 2463 | legacy2aidl_audio_attributes_t_AudioAttributes(*attr)); |
| jiabin | 2b9d5a1 | 2021-12-10 01:06:29 +0000 | [diff] [blame] | 2464 | AudioConfig configAidl = VALUE_OR_RETURN_STATUS( |
| 2465 | legacy2aidl_audio_config_t_AudioConfig(*config, false /*isInput*/)); |
| 2466 | |
| 2467 | media::AudioDirectMode retAidl; |
| 2468 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2469 | aps->getDirectPlaybackSupport(attrAidl, configAidl, &retAidl))); |
| 2470 | *directMode = VALUE_OR_RETURN_STATUS(aidl2legacy_int32_t_audio_direct_mode_t_mask( |
| 2471 | static_cast<int32_t>(retAidl))); |
| 2472 | return NO_ERROR; |
| 2473 | } |
| 2474 | |
| Dorin Drimus | f2196d8 | 2022-01-03 12:11:18 +0100 | [diff] [blame] | 2475 | status_t AudioSystem::getDirectProfilesForAttributes(const audio_attributes_t* attr, |
| 2476 | std::vector<audio_profile>* audioProfiles) { |
| Mikhail Naganov | 7b75108 | 2022-06-22 03:24:59 +0000 | [diff] [blame] | 2477 | if (attr == nullptr || audioProfiles == nullptr) { |
| Dorin Drimus | f2196d8 | 2022-01-03 12:11:18 +0100 | [diff] [blame] | 2478 | return BAD_VALUE; |
| 2479 | } |
| 2480 | |
| 2481 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2482 | if (aps == 0) { |
| 2483 | return PERMISSION_DENIED; |
| 2484 | } |
| 2485 | |
| Mikhail Naganov | 2a1cf61 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 2486 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 2487 | legacy2aidl_audio_attributes_t_AudioAttributes(*attr)); |
| Dorin Drimus | f2196d8 | 2022-01-03 12:11:18 +0100 | [diff] [blame] | 2488 | |
| 2489 | std::vector<media::audio::common::AudioProfile> audioProfilesAidl; |
| 2490 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2491 | aps->getDirectProfilesForAttributes(attrAidl, &audioProfilesAidl))); |
| 2492 | *audioProfiles = VALUE_OR_RETURN_STATUS(convertContainer<std::vector<audio_profile>>( |
| 2493 | audioProfilesAidl, aidl2legacy_AudioProfile_audio_profile, false /*isInput*/)); |
| 2494 | |
| 2495 | return NO_ERROR; |
| 2496 | } |
| Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 2497 | |
| Eric Laurent | 0825031 | 2022-05-03 18:12:28 +0200 | [diff] [blame] | 2498 | status_t AudioSystem::setRequestedLatencyMode( |
| 2499 | audio_io_handle_t output, audio_latency_mode_t mode) { |
| 2500 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2501 | if (af == nullptr) { |
| 2502 | return PERMISSION_DENIED; |
| 2503 | } |
| 2504 | return af->setRequestedLatencyMode(output, mode); |
| 2505 | } |
| 2506 | |
| 2507 | status_t AudioSystem::getSupportedLatencyModes(audio_io_handle_t output, |
| 2508 | std::vector<audio_latency_mode_t>* modes) { |
| 2509 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2510 | if (af == nullptr) { |
| 2511 | return PERMISSION_DENIED; |
| 2512 | } |
| 2513 | return af->getSupportedLatencyModes(output, modes); |
| 2514 | } |
| 2515 | |
| Eric Laurent | 49879b7 | 2022-12-20 20:20:23 +0100 | [diff] [blame] | 2516 | status_t AudioSystem::setBluetoothVariableLatencyEnabled(bool enabled) { |
| Eric Laurent | 01eb164 | 2022-12-16 11:45:07 +0100 | [diff] [blame] | 2517 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2518 | if (af == nullptr) { |
| 2519 | return PERMISSION_DENIED; |
| 2520 | } |
| Eric Laurent | 49879b7 | 2022-12-20 20:20:23 +0100 | [diff] [blame] | 2521 | return af->setBluetoothVariableLatencyEnabled(enabled); |
| Eric Laurent | 01eb164 | 2022-12-16 11:45:07 +0100 | [diff] [blame] | 2522 | } |
| 2523 | |
| Eric Laurent | 49879b7 | 2022-12-20 20:20:23 +0100 | [diff] [blame] | 2524 | status_t AudioSystem::isBluetoothVariableLatencyEnabled( |
| 2525 | bool *enabled) { |
| 2526 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2527 | if (af == nullptr) { |
| 2528 | return PERMISSION_DENIED; |
| 2529 | } |
| 2530 | return af->isBluetoothVariableLatencyEnabled(enabled); |
| 2531 | } |
| 2532 | |
| 2533 | status_t AudioSystem::supportsBluetoothVariableLatency( |
| Eric Laurent | 01eb164 | 2022-12-16 11:45:07 +0100 | [diff] [blame] | 2534 | bool *support) { |
| 2535 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2536 | if (af == nullptr) { |
| 2537 | return PERMISSION_DENIED; |
| 2538 | } |
| Eric Laurent | 49879b7 | 2022-12-20 20:20:23 +0100 | [diff] [blame] | 2539 | return af->supportsBluetoothVariableLatency(support); |
| Eric Laurent | 01eb164 | 2022-12-16 11:45:07 +0100 | [diff] [blame] | 2540 | } |
| 2541 | |
| Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 2542 | status_t AudioSystem::getAudioPolicyConfig(media::AudioPolicyConfig *config) { |
| 2543 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2544 | if (af == nullptr) { |
| 2545 | return PERMISSION_DENIED; |
| 2546 | } |
| 2547 | return af->getAudioPolicyConfig(config); |
| 2548 | } |
| 2549 | |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2550 | class CaptureStateListenerImpl : public media::BnCaptureStateListener, |
| 2551 | public IBinder::DeathRecipient { |
| 2552 | public: |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2553 | CaptureStateListenerImpl( |
| 2554 | const sp<IAudioPolicyService>& aps, |
| 2555 | const sp<AudioSystem::CaptureStateListener>& listener) |
| Ytai Ben-Tsvi | a46b6d3 | 2020-08-31 13:29:11 -0700 | [diff] [blame] | 2556 | : mAps(aps), mListener(listener) {} |
| 2557 | |
| 2558 | void init() { |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2559 | bool active; |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2560 | status_t status = statusTFromBinderStatus( |
| 2561 | mAps->registerSoundTriggerCaptureStateListener(this, &active)); |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2562 | if (status != NO_ERROR) { |
| 2563 | mListener->onServiceDied(); |
| 2564 | return; |
| 2565 | } |
| 2566 | mListener->onStateChanged(active); |
| Ytai Ben-Tsvi | a46b6d3 | 2020-08-31 13:29:11 -0700 | [diff] [blame] | 2567 | IInterface::asBinder(mAps)->linkToDeath(this); |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2570 | binder::Status setCaptureState(bool active) override { |
| 2571 | Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock); |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2572 | mListener->onStateChanged(active); |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2573 | return binder::Status::ok(); |
| 2574 | } |
| 2575 | |
| 2576 | void binderDied(const wp<IBinder>&) override { |
| 2577 | Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock); |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2578 | mListener->onServiceDied(); |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2579 | gSoundTriggerCaptureStateListener = nullptr; |
| 2580 | } |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2581 | |
| 2582 | private: |
| 2583 | // Need this in order to keep the death receipent alive. |
| 2584 | sp<IAudioPolicyService> mAps; |
| 2585 | sp<AudioSystem::CaptureStateListener> mListener; |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2586 | }; |
| 2587 | |
| 2588 | status_t AudioSystem::registerSoundTriggerCaptureStateListener( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2589 | const sp<CaptureStateListener>& listener) { |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2590 | LOG_ALWAYS_FATAL_IF(listener == nullptr); |
| 2591 | |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2592 | const sp<IAudioPolicyService>& aps = |
| 2593 | AudioSystem::get_audio_policy_service(); |
| 2594 | if (aps == 0) { |
| 2595 | return PERMISSION_DENIED; |
| 2596 | } |
| 2597 | |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2598 | Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock); |
| Ytai Ben-Tsvi | d9f8283 | 2020-08-27 09:31:10 -0700 | [diff] [blame] | 2599 | gSoundTriggerCaptureStateListener = new CaptureStateListenerImpl(aps, listener); |
| Ytai Ben-Tsvi | a46b6d3 | 2020-08-31 13:29:11 -0700 | [diff] [blame] | 2600 | gSoundTriggerCaptureStateListener->init(); |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2601 | |
| Ytai Ben-Tsvi | 5120eda | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2602 | return NO_ERROR; |
| 2603 | } |
| 2604 | |
| jiabin | 1319f5a | 2021-03-30 22:21:24 +0000 | [diff] [blame] | 2605 | status_t AudioSystem::setVibratorInfos( |
| 2606 | const std::vector<media::AudioVibratorInfo>& vibratorInfos) { |
| 2607 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2608 | if (af == nullptr) { |
| 2609 | return PERMISSION_DENIED; |
| 2610 | } |
| 2611 | return af->setVibratorInfos(vibratorInfos); |
| 2612 | } |
| 2613 | |
| Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 2614 | status_t AudioSystem::getMmapPolicyInfo( |
| jiabin | e99d088 | 2021-09-17 05:21:25 +0000 | [diff] [blame] | 2615 | AudioMMapPolicyType policyType, std::vector<AudioMMapPolicyInfo> *policyInfos) { |
| Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 2616 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2617 | if (af == nullptr) { |
| 2618 | return PERMISSION_DENIED; |
| 2619 | } |
| 2620 | return af->getMmapPolicyInfos(policyType, policyInfos); |
| 2621 | } |
| 2622 | |
| jiabin | e504e7b | 2021-09-18 00:27:08 +0000 | [diff] [blame] | 2623 | int32_t AudioSystem::getAAudioMixerBurstCount() { |
| 2624 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2625 | if (af == nullptr) { |
| 2626 | return PERMISSION_DENIED; |
| 2627 | } |
| 2628 | return af->getAAudioMixerBurstCount(); |
| 2629 | } |
| 2630 | |
| 2631 | int32_t AudioSystem::getAAudioHardwareBurstMinUsec() { |
| 2632 | const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger(); |
| 2633 | if (af == nullptr) { |
| 2634 | return PERMISSION_DENIED; |
| 2635 | } |
| 2636 | return af->getAAudioHardwareBurstMinUsec(); |
| 2637 | } |
| 2638 | |
| jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 2639 | status_t AudioSystem::getSupportedMixerAttributes( |
| 2640 | audio_port_handle_t portId, std::vector<audio_mixer_attributes_t> *mixerAttrs) { |
| 2641 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2642 | if (aps == nullptr) { |
| 2643 | return PERMISSION_DENIED; |
| 2644 | } |
| 2645 | |
| 2646 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 2647 | std::vector<media::AudioMixerAttributesInternal> _aidlReturn; |
| 2648 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2649 | aps->getSupportedMixerAttributes(portIdAidl, &_aidlReturn))); |
| 2650 | *mixerAttrs = VALUE_OR_RETURN_STATUS( |
| 2651 | convertContainer<std::vector<audio_mixer_attributes_t>>( |
| 2652 | _aidlReturn, |
| 2653 | aidl2legacy_AudioMixerAttributesInternal_audio_mixer_attributes_t)); |
| 2654 | return OK; |
| 2655 | } |
| 2656 | |
| 2657 | status_t AudioSystem::setPreferredMixerAttributes(const audio_attributes_t *attr, |
| 2658 | audio_port_handle_t portId, |
| 2659 | uid_t uid, |
| 2660 | const audio_mixer_attributes_t *mixerAttr) { |
| 2661 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2662 | if (aps == nullptr) { |
| 2663 | return PERMISSION_DENIED; |
| 2664 | } |
| 2665 | |
| Mikhail Naganov | f094be2 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 2666 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 2667 | legacy2aidl_audio_attributes_t_AudioAttributes(*attr)); |
| jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 2668 | media::AudioMixerAttributesInternal mixerAttrAidl = VALUE_OR_RETURN_STATUS( |
| 2669 | legacy2aidl_audio_mixer_attributes_t_AudioMixerAttributesInternal(*mixerAttr)); |
| 2670 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 2671 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 2672 | |
| 2673 | return statusTFromBinderStatus( |
| 2674 | aps->setPreferredMixerAttributes(attrAidl, portIdAidl, uidAidl, mixerAttrAidl)); |
| 2675 | } |
| 2676 | |
| 2677 | status_t AudioSystem::getPreferredMixerAttributes( |
| 2678 | const audio_attributes_t *attr, |
| 2679 | audio_port_handle_t portId, |
| 2680 | std::optional<audio_mixer_attributes_t> *mixerAttr) { |
| 2681 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2682 | if (aps == nullptr) { |
| 2683 | return PERMISSION_DENIED; |
| 2684 | } |
| 2685 | |
| Mikhail Naganov | f094be2 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 2686 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 2687 | legacy2aidl_audio_attributes_t_AudioAttributes(*attr)); |
| jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 2688 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 2689 | std::optional<media::AudioMixerAttributesInternal> _aidlReturn; |
| 2690 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( |
| 2691 | aps->getPreferredMixerAttributes(attrAidl, portIdAidl, &_aidlReturn))); |
| 2692 | |
| 2693 | if (_aidlReturn.has_value()) { |
| 2694 | *mixerAttr = VALUE_OR_RETURN_STATUS( |
| 2695 | aidl2legacy_AudioMixerAttributesInternal_audio_mixer_attributes_t( |
| 2696 | _aidlReturn.value())); |
| 2697 | } |
| 2698 | return NO_ERROR; |
| 2699 | } |
| 2700 | |
| 2701 | status_t AudioSystem::clearPreferredMixerAttributes(const audio_attributes_t *attr, |
| 2702 | audio_port_handle_t portId, |
| 2703 | uid_t uid) { |
| 2704 | const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service(); |
| 2705 | if (aps == nullptr) { |
| 2706 | return PERMISSION_DENIED; |
| 2707 | } |
| 2708 | |
| Mikhail Naganov | f094be2 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 2709 | media::audio::common::AudioAttributes attrAidl = VALUE_OR_RETURN_STATUS( |
| 2710 | legacy2aidl_audio_attributes_t_AudioAttributes(*attr)); |
| jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 2711 | int32_t uidAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_uid_t_int32_t(uid)); |
| 2712 | int32_t portIdAidl = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 2713 | return statusTFromBinderStatus( |
| 2714 | aps->clearPreferredMixerAttributes(attrAidl, portIdAidl, uidAidl)); |
| 2715 | } |
| 2716 | |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2717 | // --------------------------------------------------------------------------- |
| 2718 | |
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2719 | int AudioSystem::AudioPolicyServiceClient::addAudioPortCallback( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2720 | const sp<AudioPortCallback>& callback) { |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2721 | Mutex::Autolock _l(mLock); |
| 2722 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 2723 | if (mAudioPortCallbacks[i] == callback) { |
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2724 | return -1; |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2725 | } |
| 2726 | } |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 2727 | mAudioPortCallbacks.add(callback); |
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2728 | return mAudioPortCallbacks.size(); |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2731 | int AudioSystem::AudioPolicyServiceClient::removeAudioPortCallback( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2732 | const sp<AudioPortCallback>& callback) { |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2733 | Mutex::Autolock _l(mLock); |
| 2734 | size_t i; |
| 2735 | for (i = 0; i < mAudioPortCallbacks.size(); i++) { |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 2736 | if (mAudioPortCallbacks[i] == callback) { |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2737 | break; |
| 2738 | } |
| 2739 | } |
| 2740 | if (i == mAudioPortCallbacks.size()) { |
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2741 | return -1; |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2742 | } |
| 2743 | mAudioPortCallbacks.removeAt(i); |
| Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 2744 | return mAudioPortCallbacks.size(); |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
| Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 2747 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2748 | Status AudioSystem::AudioPolicyServiceClient::onAudioPortListUpdate() { |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2749 | Mutex::Autolock _l(mLock); |
| 2750 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 2751 | mAudioPortCallbacks[i]->onAudioPortListUpdate(); |
| 2752 | } |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2753 | return Status::ok(); |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2756 | Status AudioSystem::AudioPolicyServiceClient::onAudioPatchListUpdate() { |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2757 | Mutex::Autolock _l(mLock); |
| 2758 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 2759 | mAudioPortCallbacks[i]->onAudioPatchListUpdate(); |
| 2760 | } |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2761 | return Status::ok(); |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2764 | // ---------------------------------------------------------------------------- |
| 2765 | int AudioSystem::AudioPolicyServiceClient::addAudioVolumeGroupCallback( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2766 | const sp<AudioVolumeGroupCallback>& callback) { |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2767 | Mutex::Autolock _l(mLock); |
| 2768 | for (size_t i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 2769 | if (mAudioVolumeGroupCallback[i] == callback) { |
| 2770 | return -1; |
| 2771 | } |
| 2772 | } |
| 2773 | mAudioVolumeGroupCallback.add(callback); |
| 2774 | return mAudioVolumeGroupCallback.size(); |
| 2775 | } |
| 2776 | |
| 2777 | int AudioSystem::AudioPolicyServiceClient::removeAudioVolumeGroupCallback( |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2778 | const sp<AudioVolumeGroupCallback>& callback) { |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2779 | Mutex::Autolock _l(mLock); |
| 2780 | size_t i; |
| 2781 | for (i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 2782 | if (mAudioVolumeGroupCallback[i] == callback) { |
| 2783 | break; |
| 2784 | } |
| 2785 | } |
| 2786 | if (i == mAudioVolumeGroupCallback.size()) { |
| 2787 | return -1; |
| 2788 | } |
| 2789 | mAudioVolumeGroupCallback.removeAt(i); |
| 2790 | return mAudioVolumeGroupCallback.size(); |
| 2791 | } |
| 2792 | |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2793 | Status AudioSystem::AudioPolicyServiceClient::onAudioVolumeGroupChanged(int32_t group, |
| 2794 | int32_t flags) { |
| 2795 | volume_group_t groupLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2796 | aidl2legacy_int32_t_volume_group_t(group)); |
| 2797 | int flagsLegacy = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(flags)); |
| 2798 | |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2799 | Mutex::Autolock _l(mLock); |
| 2800 | for (size_t i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2801 | mAudioVolumeGroupCallback[i]->onAudioVolumeGroupChanged(groupLegacy, flagsLegacy); |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2802 | } |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2803 | return Status::ok(); |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2804 | } |
| 2805 | // ---------------------------------------------------------------------------- |
| 2806 | |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2807 | Status AudioSystem::AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate( |
| 2808 | const ::std::string& regId, int32_t state) { |
| 2809 | ALOGV("AudioPolicyServiceClient::onDynamicPolicyMixStateUpdate(%s, %d)", regId.c_str(), state); |
| 2810 | |
| 2811 | String8 regIdLegacy = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_string_view_String8(regId)); |
| 2812 | int stateLegacy = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(state)); |
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 2813 | dynamic_policy_callback cb = NULL; |
| 2814 | { |
| 2815 | Mutex::Autolock _l(AudioSystem::gLock); |
| 2816 | cb = gDynPolicyCallback; |
| 2817 | } |
| 2818 | |
| 2819 | if (cb != NULL) { |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2820 | cb(DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE, regIdLegacy, stateLegacy); |
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 2821 | } |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2822 | return Status::ok(); |
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 2823 | } |
| 2824 | |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2825 | Status AudioSystem::AudioPolicyServiceClient::onRecordingConfigurationUpdate( |
| 2826 | int32_t event, |
| 2827 | const media::RecordClientInfo& clientInfo, |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 2828 | const AudioConfigBase& clientConfig, |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2829 | const std::vector<media::EffectDescriptor>& clientEffects, |
| Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 2830 | const AudioConfigBase& deviceConfig, |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2831 | const std::vector<media::EffectDescriptor>& effects, |
| 2832 | int32_t patchHandle, |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 2833 | AudioSource source) { |
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2834 | record_config_callback cb = NULL; |
| 2835 | { |
| 2836 | Mutex::Autolock _l(AudioSystem::gLock); |
| 2837 | cb = gRecordConfigCallback; |
| 2838 | } |
| 2839 | |
| 2840 | if (cb != NULL) { |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2841 | int eventLegacy = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(event)); |
| 2842 | record_client_info_t clientInfoLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2843 | aidl2legacy_RecordClientInfo_record_client_info_t(clientInfo)); |
| 2844 | audio_config_base_t clientConfigLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 2845 | aidl2legacy_AudioConfigBase_audio_config_base_t(clientConfig, true /*isInput*/)); |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2846 | std::vector<effect_descriptor_t> clientEffectsLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2847 | convertContainer<std::vector<effect_descriptor_t>>( |
| 2848 | clientEffects, |
| 2849 | aidl2legacy_EffectDescriptor_effect_descriptor_t)); |
| 2850 | audio_config_base_t deviceConfigLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| Mikhail Naganov | de3fa18 | 2021-07-30 15:06:42 -0700 | [diff] [blame] | 2851 | aidl2legacy_AudioConfigBase_audio_config_base_t(deviceConfig, true /*isInput*/)); |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2852 | std::vector<effect_descriptor_t> effectsLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2853 | convertContainer<std::vector<effect_descriptor_t>>( |
| 2854 | effects, |
| 2855 | aidl2legacy_EffectDescriptor_effect_descriptor_t)); |
| 2856 | audio_patch_handle_t patchHandleLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2857 | aidl2legacy_int32_t_audio_patch_handle_t(patchHandle)); |
| 2858 | audio_source_t sourceLegacy = VALUE_OR_RETURN_BINDER_STATUS( |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 2859 | aidl2legacy_AudioSource_audio_source_t(source)); |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2860 | cb(eventLegacy, &clientInfoLegacy, &clientConfigLegacy, clientEffectsLegacy, |
| 2861 | &deviceConfigLegacy, effectsLegacy, patchHandleLegacy, sourceLegacy); |
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2862 | } |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2863 | return Status::ok(); |
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 2864 | } |
| 2865 | |
| Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 2866 | Status AudioSystem::AudioPolicyServiceClient::onRoutingUpdated() { |
| 2867 | routing_callback cb = NULL; |
| 2868 | { |
| 2869 | Mutex::Autolock _l(AudioSystem::gLock); |
| 2870 | cb = gRoutingCallback; |
| 2871 | } |
| 2872 | |
| 2873 | if (cb != NULL) { |
| 2874 | cb(); |
| 2875 | } |
| 2876 | return Status::ok(); |
| 2877 | } |
| 2878 | |
| Jean-Michel Trivi | 78f2b30 | 2022-04-15 18:18:41 +0000 | [diff] [blame] | 2879 | Status AudioSystem::AudioPolicyServiceClient::onVolumeRangeInitRequest() { |
| 2880 | vol_range_init_req_callback cb = NULL; |
| 2881 | { |
| 2882 | Mutex::Autolock _l(AudioSystem::gLock); |
| 2883 | cb = gVolRangeInitReqCallback; |
| 2884 | } |
| 2885 | |
| 2886 | if (cb != NULL) { |
| 2887 | cb(); |
| 2888 | } |
| 2889 | return Status::ok(); |
| 2890 | } |
| 2891 | |
| Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2892 | void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who __unused) { |
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 2893 | { |
| Eric Laurent | b28753e | 2015-04-01 13:06:28 -0700 | [diff] [blame] | 2894 | Mutex::Autolock _l(mLock); |
| 2895 | for (size_t i = 0; i < mAudioPortCallbacks.size(); i++) { |
| 2896 | mAudioPortCallbacks[i]->onServiceDied(); |
| Glenn Kasten | d2d089f | 2014-11-05 11:48:12 -0800 | [diff] [blame] | 2897 | } |
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 2898 | for (size_t i = 0; i < mAudioVolumeGroupCallback.size(); i++) { |
| 2899 | mAudioVolumeGroupCallback[i]->onServiceDied(); |
| 2900 | } |
| Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 2901 | } |
| Mikhail Naganov | ec3d579 | 2022-05-06 00:19:55 +0000 | [diff] [blame] | 2902 | AudioSystem::clearAudioPolicyService(); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2903 | |
| Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 2904 | ALOGW("AudioPolicyService server died!"); |
| Eric Laurent | c2f1f07 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2907 | ConversionResult<record_client_info_t> |
| 2908 | aidl2legacy_RecordClientInfo_record_client_info_t(const media::RecordClientInfo& aidl) { |
| 2909 | record_client_info_t legacy; |
| 2910 | legacy.riid = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_unique_id_t(aidl.riid)); |
| 2911 | legacy.uid = VALUE_OR_RETURN(aidl2legacy_int32_t_uid_t(aidl.uid)); |
| 2912 | legacy.session = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_session_t(aidl.session)); |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 2913 | legacy.source = VALUE_OR_RETURN(aidl2legacy_AudioSource_audio_source_t(aidl.source)); |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2914 | legacy.port_id = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId)); |
| 2915 | legacy.silenced = aidl.silenced; |
| 2916 | return legacy; |
| 2917 | } |
| 2918 | |
| 2919 | ConversionResult<media::RecordClientInfo> |
| 2920 | legacy2aidl_record_client_info_t_RecordClientInfo(const record_client_info_t& legacy) { |
| 2921 | media::RecordClientInfo aidl; |
| 2922 | aidl.riid = VALUE_OR_RETURN(legacy2aidl_audio_unique_id_t_int32_t(legacy.riid)); |
| 2923 | aidl.uid = VALUE_OR_RETURN(legacy2aidl_uid_t_int32_t(legacy.uid)); |
| 2924 | aidl.session = VALUE_OR_RETURN(legacy2aidl_audio_session_t_int32_t(legacy.session)); |
| Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 2925 | aidl.source = VALUE_OR_RETURN(legacy2aidl_audio_source_t_AudioSource(legacy.source)); |
| Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 2926 | aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy.port_id)); |
| 2927 | aidl.silenced = legacy.silenced; |
| 2928 | return aidl; |
| 2929 | } |
| 2930 | |
| Glenn Kasten | 40bc906 | 2015-03-20 09:09:33 -0700 | [diff] [blame] | 2931 | } // namespace android |