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