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