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