Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 17 | #include <algorithm> |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 18 | #include <cstddef> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 19 | #include <cstdint> |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 20 | #include <iterator> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 21 | #include <memory> |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 22 | #define LOG_TAG "EffectsFactoryHalAidl" |
| 23 | //#define LOG_NDEBUG 0 |
| 24 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 25 | #include <error/expected_utils.h> |
Shunkai Yao | 8f6ad0f | 2023-04-18 23:14:25 +0000 | [diff] [blame] | 26 | #include <aidl/android/media/audio/common/AudioStreamType.h> |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 27 | #include <android/binder_manager.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 28 | #include <media/AidlConversionCppNdk.h> |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 29 | #include <media/AidlConversionEffect.h> |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 30 | #include <system/audio.h> |
Shunkai Yao | 007caf0 | 2023-05-17 00:52:54 +0000 | [diff] [blame] | 31 | #include <system/audio_aidl_utils.h> |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 32 | #include <utils/Log.h> |
| 33 | |
Mikhail Naganov | d8f2441 | 2024-03-20 18:15:42 -0700 | [diff] [blame] | 34 | #include "AidlUtils.h" |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 35 | #include "EffectBufferHalAidl.h" |
| 36 | #include "EffectHalAidl.h" |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 37 | #include "EffectProxy.h" |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 38 | #include "EffectsFactoryHalAidl.h" |
| 39 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 40 | using ::aidl::android::legacy2aidl_audio_uuid_t_AudioUuid; |
Shunkai Yao | 8f6ad0f | 2023-04-18 23:14:25 +0000 | [diff] [blame] | 41 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
| 42 | using ::aidl::android::hardware::audio::effect::Descriptor; |
| 43 | using ::aidl::android::hardware::audio::effect::IFactory; |
| 44 | using ::aidl::android::hardware::audio::effect::Processing; |
François Gaffie | 0971d30 | 2024-05-30 13:41:30 +0200 | [diff] [blame] | 45 | using ::aidl::android::media::audio::common::AudioDevice; |
| 46 | using ::aidl::android::media::audio::common::AudioDeviceAddress; |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 47 | using ::aidl::android::media::audio::common::AudioSource; |
| 48 | using ::aidl::android::media::audio::common::AudioStreamType; |
Shunkai Yao | 8f6ad0f | 2023-04-18 23:14:25 +0000 | [diff] [blame] | 49 | using ::aidl::android::media::audio::common::AudioUuid; |
Shunkai Yao | 007caf0 | 2023-05-17 00:52:54 +0000 | [diff] [blame] | 50 | using ::android::audio::utils::toString; |
Shunkai Yao | 8f6ad0f | 2023-04-18 23:14:25 +0000 | [diff] [blame] | 51 | using ::android::base::unexpected; |
| 52 | using ::android::detail::AudioHalVersionInfo; |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 53 | |
| 54 | namespace android { |
| 55 | namespace effect { |
| 56 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 57 | EffectsFactoryHalAidl::EffectsFactoryHalAidl(std::shared_ptr<IFactory> effectsFactory) |
| 58 | : mFactory(effectsFactory), |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 59 | mHalVersion(AudioHalVersionInfo( |
| 60 | AudioHalVersionInfo::Type::AIDL, |
| 61 | [this]() { |
| 62 | int32_t majorVersion = 0; |
| 63 | return (mFactory && mFactory->getInterfaceVersion(&majorVersion).isOk()) |
| 64 | ? majorVersion |
| 65 | : 0; |
| 66 | }())), |
| 67 | mHalDescList([this]() { |
| 68 | std::vector<Descriptor> list; |
| 69 | if (mFactory) { |
| 70 | mFactory->queryEffects(std::nullopt, std::nullopt, std::nullopt, &list).isOk(); |
| 71 | } |
| 72 | return list; |
| 73 | }()), |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 74 | mProxyUuidDescriptorMap([this]() { |
| 75 | std::map<AudioUuid, std::vector<Descriptor>> proxyUuidMap; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 76 | for (const auto& desc : mHalDescList) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 77 | if (desc.common.id.proxy.has_value()) { |
| 78 | const auto& uuid = desc.common.id.proxy.value(); |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 79 | if (proxyUuidMap.count(uuid) == 0) { |
| 80 | proxyUuidMap.insert({uuid, {desc}}); |
| 81 | } else { |
| 82 | proxyUuidMap[uuid].emplace_back(desc); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 83 | } |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 84 | } |
| 85 | } |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 86 | return proxyUuidMap; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 87 | }()), |
| 88 | mProxyDescList([this]() { |
| 89 | std::vector<Descriptor> list; |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 90 | for (const auto& proxy : mProxyUuidDescriptorMap) { |
| 91 | if (Descriptor desc; |
| 92 | EffectProxy::buildDescriptor(proxy.first /* uuid */, |
| 93 | proxy.second /* sub-effect descriptor list */, |
| 94 | &desc /* proxy descriptor */) |
| 95 | .isOk()) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 96 | list.emplace_back(std::move(desc)); |
| 97 | } |
| 98 | } |
| 99 | return list; |
| 100 | }()), |
| 101 | mNonProxyDescList([this]() { |
| 102 | std::vector<Descriptor> list; |
| 103 | std::copy_if(mHalDescList.begin(), mHalDescList.end(), std::back_inserter(list), |
| 104 | [](const Descriptor& desc) { return !desc.common.id.proxy.has_value(); }); |
| 105 | return list; |
| 106 | }()), |
Shunkai Yao | 8f6ad0f | 2023-04-18 23:14:25 +0000 | [diff] [blame] | 107 | mEffectCount(mNonProxyDescList.size() + mProxyDescList.size()), |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 108 | mAidlProcessings([this]() -> std::vector<Processing> { |
| 109 | std::vector<Processing> processings; |
| 110 | if (!mFactory || !mFactory->queryProcessing(std::nullopt, &processings).isOk()) { |
| 111 | ALOGE("%s queryProcessing failed", __func__); |
| 112 | } |
| 113 | return processings; |
| 114 | }()) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 115 | ALOG_ASSERT(mFactory != nullptr, "Provided IEffectsFactory service is NULL"); |
| 116 | ALOGI("%s with %zu nonProxyEffects and %zu proxyEffects", __func__, mNonProxyDescList.size(), |
| 117 | mProxyDescList.size()); |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | status_t EffectsFactoryHalAidl::queryNumberEffects(uint32_t *pNumEffects) { |
| 121 | if (pNumEffects == nullptr) { |
| 122 | return BAD_VALUE; |
| 123 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 124 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 125 | *pNumEffects = mEffectCount; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 126 | return OK; |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | status_t EffectsFactoryHalAidl::getDescriptor(uint32_t index, effect_descriptor_t* pDescriptor) { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 130 | if (pDescriptor == nullptr) { |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 131 | return BAD_VALUE; |
| 132 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 133 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 134 | if (index >= mEffectCount) { |
| 135 | ALOGE("%s index %d exceed max number %zu", __func__, index, mEffectCount); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 136 | return INVALID_OPERATION; |
| 137 | } |
| 138 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 139 | if (index >= mNonProxyDescList.size()) { |
| 140 | *pDescriptor = |
| 141 | VALUE_OR_RETURN_STATUS(::aidl::android::aidl2legacy_Descriptor_effect_descriptor( |
| 142 | mProxyDescList.at(index - mNonProxyDescList.size()))); |
| 143 | } else { |
| 144 | *pDescriptor = |
| 145 | VALUE_OR_RETURN_STATUS(::aidl::android::aidl2legacy_Descriptor_effect_descriptor( |
| 146 | mNonProxyDescList.at(index))); |
| 147 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 148 | return OK; |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 151 | status_t EffectsFactoryHalAidl::getDescriptor(const effect_uuid_t* halUuid, |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 152 | effect_descriptor_t* pDescriptor) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 153 | if (halUuid == nullptr) { |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 154 | return BAD_VALUE; |
| 155 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 156 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 157 | AudioUuid uuid = |
| 158 | VALUE_OR_RETURN_STATUS(::aidl::android::legacy2aidl_audio_uuid_t_AudioUuid(*halUuid)); |
| 159 | return getHalDescriptorWithImplUuid(uuid, pDescriptor); |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 162 | status_t EffectsFactoryHalAidl::getDescriptors(const effect_uuid_t* halType, |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 163 | std::vector<effect_descriptor_t>* descriptors) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 164 | if (halType == nullptr) { |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 165 | return BAD_VALUE; |
| 166 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 167 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 168 | AudioUuid type = |
| 169 | VALUE_OR_RETURN_STATUS(::aidl::android::legacy2aidl_audio_uuid_t_AudioUuid(*halType)); |
| 170 | return getHalDescriptorWithTypeUuid(type, descriptors); |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 173 | status_t EffectsFactoryHalAidl::createEffect(const effect_uuid_t* uuid, int32_t sessionId, |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 174 | int32_t ioId, int32_t deviceId __unused, |
| 175 | sp<EffectHalInterface>* effect) { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 176 | if (uuid == nullptr || effect == nullptr) { |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 177 | return BAD_VALUE; |
| 178 | } |
Shunkai Yao | ac61ee9 | 2024-03-14 21:57:46 +0000 | [diff] [blame] | 179 | ALOGV("%s session %d ioId %d", __func__, sessionId, ioId); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 180 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 181 | AudioUuid aidlUuid = |
| 182 | VALUE_OR_RETURN_STATUS(::aidl::android::legacy2aidl_audio_uuid_t_AudioUuid(*uuid)); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 183 | std::shared_ptr<IEffect> aidlEffect; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 184 | // Use EffectProxy interface instead of IFactory to create |
| 185 | const bool isProxy = isProxyEffect(aidlUuid); |
| 186 | if (isProxy) { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 187 | aidlEffect = ndk::SharedRefBase::make<EffectProxy>( |
| 188 | aidlUuid, mProxyUuidDescriptorMap.at(aidlUuid) /* sub-effect descriptor list */, |
| 189 | mFactory); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 190 | } else { |
| 191 | RETURN_STATUS_IF_ERROR( |
| 192 | statusTFromBinderStatus(mFactory->createEffect(aidlUuid, &aidlEffect))); |
| 193 | } |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 194 | if (aidlEffect == nullptr) { |
Shunkai Yao | 007caf0 | 2023-05-17 00:52:54 +0000 | [diff] [blame] | 195 | ALOGE("%s failed to create effect with UUID: %s", __func__, toString(aidlUuid).c_str()); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 196 | return NAME_NOT_FOUND; |
| 197 | } |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 198 | Descriptor desc; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 199 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(aidlEffect->getDescriptor(&desc))); |
| 200 | |
Mikhail Naganov | 89c22e4 | 2023-06-14 15:49:59 -0700 | [diff] [blame] | 201 | *effect = sp<EffectHalAidl>::make(mFactory, aidlEffect, sessionId, ioId, desc, isProxy); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 202 | return OK; |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | status_t EffectsFactoryHalAidl::dumpEffects(int fd) { |
Shunkai Yao | 1b7efb0 | 2024-04-11 23:37:00 +0000 | [diff] [blame] | 206 | // TODO: b/333803769 improve the effect dump implementation |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 207 | RETURN_STATUS_IF_ERROR(mFactory->dump(fd, nullptr, 0)); |
Shunkai Yao | 1b7efb0 | 2024-04-11 23:37:00 +0000 | [diff] [blame] | 208 | return OK; |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | status_t EffectsFactoryHalAidl::allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 212 | return EffectBufferHalAidl::allocate(size, buffer); |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | status_t EffectsFactoryHalAidl::mirrorBuffer(void* external, size_t size, |
| 216 | sp<EffectBufferHalInterface>* buffer) { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 217 | return EffectBufferHalAidl::mirror(external, size, buffer); |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | AudioHalVersionInfo EffectsFactoryHalAidl::getHalVersion() const { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 221 | return mHalVersion; |
| 222 | } |
| 223 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 224 | status_t EffectsFactoryHalAidl::getHalDescriptorWithImplUuid(const AudioUuid& uuid, |
| 225 | effect_descriptor_t* pDescriptor) { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 226 | if (pDescriptor == nullptr) { |
| 227 | return BAD_VALUE; |
| 228 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 229 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 230 | const auto& list = isProxyEffect(uuid) ? mProxyDescList : mNonProxyDescList; |
| 231 | auto matchIt = std::find_if(list.begin(), list.end(), |
| 232 | [&](const auto& desc) { return desc.common.id.uuid == uuid; }); |
| 233 | if (matchIt == list.end()) { |
Shunkai Yao | 007caf0 | 2023-05-17 00:52:54 +0000 | [diff] [blame] | 234 | ALOGE("%s UUID not found in HAL and proxy list %s", __func__, toString(uuid).c_str()); |
Shunkai Yao | 849c56c | 2023-11-01 02:43:09 +0000 | [diff] [blame] | 235 | return NAME_NOT_FOUND; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | *pDescriptor = VALUE_OR_RETURN_STATUS( |
| 239 | ::aidl::android::aidl2legacy_Descriptor_effect_descriptor(*matchIt)); |
| 240 | return OK; |
| 241 | } |
| 242 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 243 | status_t EffectsFactoryHalAidl::getHalDescriptorWithTypeUuid( |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 244 | const AudioUuid& type, std::vector<effect_descriptor_t>* descriptors) { |
| 245 | if (descriptors == nullptr) { |
| 246 | return BAD_VALUE; |
| 247 | } |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 248 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 249 | std::vector<Descriptor> result; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 250 | std::copy_if(mNonProxyDescList.begin(), mNonProxyDescList.end(), std::back_inserter(result), |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 251 | [&](auto& desc) { return desc.common.id.type == type; }); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 252 | std::copy_if(mProxyDescList.begin(), mProxyDescList.end(), std::back_inserter(result), |
| 253 | [&](auto& desc) { return desc.common.id.type == type; }); |
| 254 | if (result.empty()) { |
Shunkai Yao | 007caf0 | 2023-05-17 00:52:54 +0000 | [diff] [blame] | 255 | ALOGW("%s UUID type not found in HAL and proxy list %s", __func__, toString(type).c_str()); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 256 | return BAD_VALUE; |
| 257 | } |
| 258 | |
| 259 | *descriptors = VALUE_OR_RETURN_STATUS( |
| 260 | aidl::android::convertContainer<std::vector<effect_descriptor_t>>( |
| 261 | result, ::aidl::android::aidl2legacy_Descriptor_effect_descriptor)); |
| 262 | return OK; |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 265 | bool EffectsFactoryHalAidl::isProxyEffect(const AudioUuid& uuid) const { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 266 | return 0 != mProxyUuidDescriptorMap.count(uuid); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Shunkai Yao | 8f6ad0f | 2023-04-18 23:14:25 +0000 | [diff] [blame] | 269 | std::shared_ptr<const effectsConfig::Processings> EffectsFactoryHalAidl::getProcessings() const { |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 270 | |
| 271 | auto getConfigEffectWithDescriptor = |
| 272 | [](const auto& desc) -> std::shared_ptr<const effectsConfig::Effect> { |
| 273 | effectsConfig::Effect effect = {.name = desc.common.name, .isProxy = false}; |
| 274 | if (const auto uuid = |
| 275 | ::aidl::android::aidl2legacy_AudioUuid_audio_uuid_t(desc.common.id.uuid); |
| 276 | uuid.ok()) { |
Shunkai Yao | e708d97 | 2023-06-29 01:39:54 +0000 | [diff] [blame] | 277 | static_cast<effectsConfig::EffectImpl&>(effect).uuid = uuid.value(); |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 278 | return std::make_shared<const effectsConfig::Effect>(effect); |
| 279 | } else { |
| 280 | return nullptr; |
| 281 | } |
| 282 | }; |
| 283 | |
| 284 | auto getConfigProcessingWithAidlProcessing = |
| 285 | [&](const auto& aidlProcess, std::vector<effectsConfig::InputStream>& preprocess, |
François Gaffie | 0971d30 | 2024-05-30 13:41:30 +0200 | [diff] [blame] | 286 | std::vector<effectsConfig::OutputStream>& postprocess, |
| 287 | std::vector<effectsConfig::DeviceEffects>& deviceprocess) { |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 288 | if (aidlProcess.type.getTag() == Processing::Type::streamType) { |
| 289 | AudioStreamType aidlType = |
| 290 | aidlProcess.type.template get<Processing::Type::streamType>(); |
| 291 | const auto type = |
| 292 | ::aidl::android::aidl2legacy_AudioStreamType_audio_stream_type_t( |
| 293 | aidlType); |
| 294 | if (!type.ok()) { |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | std::vector<std::shared_ptr<const effectsConfig::Effect>> effects; |
| 299 | std::transform(aidlProcess.ids.begin(), aidlProcess.ids.end(), |
| 300 | std::back_inserter(effects), getConfigEffectWithDescriptor); |
| 301 | effectsConfig::OutputStream stream = {.type = type.value(), |
| 302 | .effects = std::move(effects)}; |
| 303 | postprocess.emplace_back(stream); |
| 304 | } else if (aidlProcess.type.getTag() == Processing::Type::source) { |
| 305 | AudioSource aidlType = |
| 306 | aidlProcess.type.template get<Processing::Type::source>(); |
| 307 | const auto type = |
| 308 | ::aidl::android::aidl2legacy_AudioSource_audio_source_t(aidlType); |
| 309 | if (!type.ok()) { |
| 310 | return; |
| 311 | } |
| 312 | |
| 313 | std::vector<std::shared_ptr<const effectsConfig::Effect>> effects; |
| 314 | std::transform(aidlProcess.ids.begin(), aidlProcess.ids.end(), |
| 315 | std::back_inserter(effects), getConfigEffectWithDescriptor); |
| 316 | effectsConfig::InputStream stream = {.type = type.value(), |
| 317 | .effects = std::move(effects)}; |
| 318 | preprocess.emplace_back(stream); |
François Gaffie | 0971d30 | 2024-05-30 13:41:30 +0200 | [diff] [blame] | 319 | } else if (aidlProcess.type.getTag() == Processing::Type::device) { |
| 320 | AudioDevice aidlDevice = |
| 321 | aidlProcess.type.template get<Processing::Type::device>(); |
| 322 | std::vector<std::shared_ptr<const effectsConfig::Effect>> effects; |
| 323 | std::transform(aidlProcess.ids.begin(), aidlProcess.ids.end(), |
| 324 | std::back_inserter(effects), getConfigEffectWithDescriptor); |
| 325 | audio_devices_t type; |
| 326 | char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; |
| 327 | status_t status = ::aidl::android::aidl2legacy_AudioDevice_audio_device( |
| 328 | aidlDevice, &type, address); |
| 329 | if (status != NO_ERROR) { |
| 330 | ALOGE("%s device effect has invalid device type / address", __func__); |
| 331 | return; |
| 332 | } |
| 333 | effectsConfig::DeviceEffects device = { |
| 334 | {.type = type, .effects = std::move(effects)}, |
| 335 | .address = address, |
| 336 | }; |
| 337 | deviceprocess.emplace_back(device); |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 338 | } |
| 339 | }; |
| 340 | |
| 341 | static std::shared_ptr<const effectsConfig::Processings> processings( |
| 342 | [&]() -> std::shared_ptr<const effectsConfig::Processings> { |
| 343 | std::vector<effectsConfig::InputStream> preprocess; |
| 344 | std::vector<effectsConfig::OutputStream> postprocess; |
François Gaffie | 0971d30 | 2024-05-30 13:41:30 +0200 | [diff] [blame] | 345 | std::vector<effectsConfig::DeviceEffects> deviceprocess; |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 346 | for (const auto& processing : mAidlProcessings) { |
François Gaffie | 0971d30 | 2024-05-30 13:41:30 +0200 | [diff] [blame] | 347 | getConfigProcessingWithAidlProcessing(processing, preprocess, postprocess, |
| 348 | deviceprocess); |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 349 | } |
| 350 | |
François Gaffie | 0971d30 | 2024-05-30 13:41:30 +0200 | [diff] [blame] | 351 | if (0 == preprocess.size() && 0 == postprocess.size() && |
| 352 | 0 == deviceprocess.size()) { |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 353 | return nullptr; |
| 354 | } |
| 355 | |
| 356 | return std::make_shared<const effectsConfig::Processings>( |
| 357 | effectsConfig::Processings({.preprocess = std::move(preprocess), |
François Gaffie | 0971d30 | 2024-05-30 13:41:30 +0200 | [diff] [blame] | 358 | .postprocess = std::move(postprocess), |
| 359 | .deviceprocess = std::move(deviceprocess)})); |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 360 | }()); |
| 361 | |
| 362 | return processings; |
Shunkai Yao | 8f6ad0f | 2023-04-18 23:14:25 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Shunkai Yao | 0a51cf9 | 2023-05-10 22:42:56 +0000 | [diff] [blame] | 365 | // Return 0 for AIDL, as the AIDL interface is not aware of the configuration file. |
Shunkai Yao | 8f6ad0f | 2023-04-18 23:14:25 +0000 | [diff] [blame] | 366 | ::android::error::Result<size_t> EffectsFactoryHalAidl::getSkippedElements() const { |
Shunkai Yao | 8f6ad0f | 2023-04-18 23:14:25 +0000 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 370 | } // namespace effect |
| 371 | |
| 372 | // When a shared library is built from a static library, even explicit |
| 373 | // exports from a static library are optimized out unless actually used by |
| 374 | // the shared library. See EffectsFactoryHalEntry.cpp. |
| 375 | extern "C" void* createIEffectsFactoryImpl() { |
Mikhail Naganov | d8f2441 | 2024-03-20 18:15:42 -0700 | [diff] [blame] | 376 | return new effect::EffectsFactoryHalAidl(getServiceInstance<IFactory>("default")); |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | } // namespace android |