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