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