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