Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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 | #include <algorithm> |
Shunkai Yao | 849ba4c | 2023-07-11 18:10:18 +0000 | [diff] [blame] | 18 | #include <cstddef> |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 19 | #include <iterator> |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 20 | #include <memory> |
| 21 | #define LOG_TAG "EffectProxy" |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 22 | // #define LOG_NDEBUG 0 |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 23 | |
| 24 | #include <fmq/AidlMessageQueue.h> |
Shunkai Yao | 007caf0 | 2023-05-17 00:52:54 +0000 | [diff] [blame] | 25 | #include <system/audio_aidl_utils.h> |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 26 | #include <utils/Log.h> |
| 27 | |
| 28 | #include "EffectProxy.h" |
| 29 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 30 | using ::aidl::android::hardware::audio::effect::Capability; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 31 | using ::aidl::android::hardware::audio::effect::CommandId; |
| 32 | using ::aidl::android::hardware::audio::effect::Descriptor; |
| 33 | using ::aidl::android::hardware::audio::effect::Flags; |
| 34 | using ::aidl::android::hardware::audio::effect::IEffect; |
| 35 | using ::aidl::android::hardware::audio::effect::IFactory; |
| 36 | using ::aidl::android::hardware::audio::effect::Parameter; |
| 37 | using ::aidl::android::hardware::audio::effect::State; |
| 38 | using ::aidl::android::media::audio::common::AudioUuid; |
| 39 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 40 | namespace android::effect { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 41 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 42 | EffectProxy::EffectProxy(const AudioUuid& uuid, const std::vector<Descriptor>& descriptors, |
| 43 | const std::shared_ptr<IFactory>& factory) |
| 44 | : mDescriptorCommon(buildDescriptorCommon(uuid, descriptors)), |
| 45 | mSubEffects( |
| 46 | [](const std::vector<Descriptor>& descs, const std::shared_ptr<IFactory>& factory) { |
| 47 | std::vector<SubEffect> subEffects; |
| 48 | ALOG_ASSERT(factory, "invalid EffectFactory handle"); |
| 49 | ndk::ScopedAStatus status = ndk::ScopedAStatus::ok(); |
| 50 | for (const auto& desc : descs) { |
| 51 | SubEffect sub({.descriptor = desc}); |
| 52 | status = factory->createEffect(desc.common.id.uuid, &sub.handle); |
| 53 | if (!status.isOk() || !sub.handle) { |
| 54 | sub.handle = nullptr; |
| 55 | ALOGW("%s create sub-effect %s failed", __func__, |
| 56 | ::android::audio::utils::toString(desc.common.id.uuid).c_str()); |
| 57 | } |
| 58 | subEffects.emplace_back(sub); |
| 59 | } |
| 60 | return subEffects; |
| 61 | }(descriptors, factory)), |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 62 | mFactory(factory) {} |
| 63 | |
| 64 | EffectProxy::~EffectProxy() { |
| 65 | close(); |
| 66 | destroy(); |
| 67 | mSubEffects.clear(); |
| 68 | } |
| 69 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 70 | ndk::ScopedAStatus EffectProxy::destroy() { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 71 | ALOGV("%s: %s", __func__, |
| 72 | ::android::audio::utils::toString(mDescriptorCommon.id.type).c_str()); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 73 | return runWithAllSubEffects([&](std::shared_ptr<IEffect>& effect) { |
| 74 | ndk::ScopedAStatus status = mFactory->destroyEffect(effect); |
| 75 | if (status.isOk()) { |
| 76 | effect.reset(); |
| 77 | } |
| 78 | return status; |
| 79 | }); |
| 80 | } |
| 81 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 82 | ndk::ScopedAStatus EffectProxy::setOffloadParam(const effect_offload_param_t* offload) { |
| 83 | const auto& itor = std::find_if(mSubEffects.begin(), mSubEffects.end(), [&](const auto& sub) { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 84 | const auto& desc = sub.descriptor; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 85 | return offload->isOffload == |
| 86 | (desc.common.flags.hwAcceleratorMode == Flags::HardwareAccelerator::TUNNEL); |
| 87 | }); |
| 88 | if (itor == mSubEffects.end()) { |
| 89 | ALOGE("%s no %soffload sub-effect found", __func__, offload->isOffload ? "" : "non-"); |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 90 | mActiveSubIdx = 0; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 91 | return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_NULL_POINTER, |
| 92 | "noActiveEffctFound"); |
| 93 | } |
| 94 | |
Shunkai Yao | 4fe6644 | 2023-07-25 21:51:24 +0000 | [diff] [blame] | 95 | mActiveSubIdx = std::distance(mSubEffects.begin(), itor); |
Shunkai Yao | 849ba4c | 2023-07-11 18:10:18 +0000 | [diff] [blame] | 96 | ALOGI("%s: active %soffload sub-effect %zu descriptor: %s", __func__, |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 97 | offload->isOffload ? "" : "non-", mActiveSubIdx, |
| 98 | ::android::audio::utils::toString(mSubEffects[mActiveSubIdx].descriptor.common.id.uuid) |
| 99 | .c_str()); |
Shunkai Yao | 849ba4c | 2023-07-11 18:10:18 +0000 | [diff] [blame] | 100 | return runWithAllSubEffects([&](std::shared_ptr<IEffect>& effect) { |
| 101 | return effect->setParameter(Parameter::make<Parameter::offload>(offload->isOffload)); |
| 102 | }); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // EffectProxy go over sub-effects and call IEffect interfaces |
| 106 | ndk::ScopedAStatus EffectProxy::open(const Parameter::Common& common, |
| 107 | const std::optional<Parameter::Specific>& specific, |
| 108 | IEffect::OpenEffectReturn* ret __unused) { |
Shunkai Yao | e67f872 | 2024-01-02 20:24:54 +0000 | [diff] [blame] | 109 | ndk::ScopedAStatus status = |
| 110 | ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_STATE, "nullEffectHandle"); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 111 | for (auto& sub : mSubEffects) { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 112 | IEffect::OpenEffectReturn openReturn; |
| 113 | if (!sub.handle || !(status = sub.handle->open(common, specific, &openReturn)).isOk()) { |
| 114 | ALOGE("%s: failed to open %p UUID %s", __func__, sub.handle.get(), |
| 115 | ::android::audio::utils::toString(sub.descriptor.common.id.uuid).c_str()); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 116 | break; |
| 117 | } |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 118 | sub.effectMq.statusQ = std::make_shared<StatusMQ>(openReturn.statusMQ); |
| 119 | sub.effectMq.inputQ = std::make_shared<DataMQ>(openReturn.inputDataMQ); |
| 120 | sub.effectMq.outputQ = std::make_shared<DataMQ>(openReturn.outputDataMQ); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // close all opened effects if failure |
| 124 | if (!status.isOk()) { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 125 | ALOGE("%s: closing all sub-effects with error %s", __func__, |
| 126 | status.getDescription().c_str()); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 127 | close(); |
| 128 | } |
| 129 | |
| 130 | return status; |
| 131 | } |
| 132 | |
Shunkai Yao | e67f872 | 2024-01-02 20:24:54 +0000 | [diff] [blame] | 133 | ndk::ScopedAStatus EffectProxy::reopen(OpenEffectReturn* ret __unused) { |
| 134 | ndk::ScopedAStatus status = |
| 135 | ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_STATE, "nullEffectHandle"); |
| 136 | for (auto& sub : mSubEffects) { |
| 137 | IEffect::OpenEffectReturn openReturn; |
| 138 | if (!sub.handle || !(status = sub.handle->reopen(&openReturn)).isOk()) { |
| 139 | ALOGE("%s: failed to open %p UUID %s", __func__, sub.handle.get(), |
| 140 | ::android::audio::utils::toString(sub.descriptor.common.id.uuid).c_str()); |
| 141 | break; |
| 142 | } |
| 143 | sub.effectMq.statusQ = std::make_shared<StatusMQ>(openReturn.statusMQ); |
| 144 | sub.effectMq.inputQ = std::make_shared<DataMQ>(openReturn.inputDataMQ); |
| 145 | sub.effectMq.outputQ = std::make_shared<DataMQ>(openReturn.outputDataMQ); |
| 146 | } |
| 147 | |
| 148 | // close all opened effects if failure |
| 149 | if (!status.isOk()) { |
| 150 | ALOGE("%s: closing all sub-effects with error %s", __func__, |
| 151 | status.getDescription().c_str()); |
| 152 | close(); |
| 153 | } |
| 154 | |
| 155 | return status; |
| 156 | } |
| 157 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 158 | ndk::ScopedAStatus EffectProxy::close() { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 159 | return runWithAllSubEffects([&](std::shared_ptr<IEffect>& effect) { |
| 160 | return effect->close(); |
| 161 | }); |
| 162 | } |
| 163 | |
| 164 | ndk::ScopedAStatus EffectProxy::getDescriptor(Descriptor* desc) { |
Shunkai Yao | df7bd8b | 2023-07-13 23:25:38 +0000 | [diff] [blame] | 165 | *desc = mSubEffects[mActiveSubIdx].descriptor; |
| 166 | desc->common.id.uuid = desc->common.id.proxy.value(); |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 167 | return ndk::ScopedAStatus::ok(); |
| 168 | } |
| 169 | |
| 170 | ndk::ScopedAStatus EffectProxy::buildDescriptor(const AudioUuid& uuid, |
| 171 | const std::vector<Descriptor>& subEffectDescs, |
| 172 | Descriptor* desc) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 173 | if (!desc) { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 174 | ALOGE("%s: null descriptor pointer", __func__); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 175 | return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_NULL_POINTER, "nullptr"); |
| 176 | } |
| 177 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 178 | if (subEffectDescs.size() < 2) { |
| 179 | ALOGE("%s: proxy need at least 2 sub-effects, got %zu", __func__, subEffectDescs.size()); |
| 180 | return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT, |
| 181 | "needMoreSubEffects"); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 184 | desc->common = buildDescriptorCommon(uuid, subEffectDescs); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 185 | return ndk::ScopedAStatus::ok(); |
| 186 | } |
| 187 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 188 | Descriptor::Common EffectProxy::buildDescriptorCommon( |
| 189 | const AudioUuid& uuid, const std::vector<Descriptor>& subEffectDescs) { |
Shunkai Yao | ff5eb3c | 2023-11-10 23:50:57 +0000 | [diff] [blame] | 190 | // initial flag values before we know which sub-effect to active (with setOffloadParam) |
| 191 | // align to HIDL EffectProxy flags |
| 192 | Descriptor::Common common = {.flags = {.type = Flags::Type::INSERT, |
| 193 | .insert = Flags::Insert::LAST, |
| 194 | .volume = Flags::Volume::CTRL}}; |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 195 | |
| 196 | for (const auto& desc : subEffectDescs) { |
| 197 | if (desc.common.flags.hwAcceleratorMode == Flags::HardwareAccelerator::TUNNEL) { |
| 198 | common.flags.hwAcceleratorMode = Flags::HardwareAccelerator::TUNNEL; |
| 199 | } |
| 200 | |
| 201 | // set indication if any sub-effect indication was set |
| 202 | common.flags.offloadIndication |= desc.common.flags.offloadIndication; |
| 203 | common.flags.deviceIndication |= desc.common.flags.deviceIndication; |
| 204 | common.flags.audioModeIndication |= desc.common.flags.audioModeIndication; |
| 205 | common.flags.audioSourceIndication |= desc.common.flags.audioSourceIndication; |
Shunkai Yao | ff5eb3c | 2023-11-10 23:50:57 +0000 | [diff] [blame] | 206 | // Set to NONE if any sub-effect not supporting any Volume command |
| 207 | if (desc.common.flags.volume == Flags::Volume::NONE) { |
| 208 | common.flags.volume = Flags::Volume::NONE; |
| 209 | } |
Jaideep Sharma | 2dcfadd | 2024-03-05 13:22:18 +0530 | [diff] [blame] | 210 | // set to AUXILIARY if any sub-effect is of AUXILIARY type |
| 211 | if (desc.common.flags.type == Flags::Type::AUXILIARY) { |
| 212 | common.flags.type = Flags::Type::AUXILIARY; |
| 213 | } |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 216 | // copy type UUID from any of sub-effects, all sub-effects should have same type |
| 217 | common.id.type = subEffectDescs[0].common.id.type; |
| 218 | // replace implementation UUID with proxy UUID. |
| 219 | common.id.uuid = uuid; |
| 220 | common.id.proxy = std::nullopt; |
| 221 | common.name = "Proxy"; |
| 222 | common.implementor = "AOSP"; |
| 223 | return common; |
| 224 | } |
| 225 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 226 | // Handle with active sub-effect first, only send to other sub-effects when success |
| 227 | ndk::ScopedAStatus EffectProxy::command(CommandId id) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 228 | return runWithActiveSubEffectThenOthers( |
| 229 | [&](const std::shared_ptr<IEffect>& effect) -> ndk::ScopedAStatus { |
| 230 | return effect->command(id); |
| 231 | }); |
| 232 | } |
| 233 | |
| 234 | // Return the active sub-effect state |
| 235 | ndk::ScopedAStatus EffectProxy::getState(State* state) { |
| 236 | return runWithActiveSubEffect( |
| 237 | [&](const std::shared_ptr<IEffect>& effect) -> ndk::ScopedAStatus { |
| 238 | return effect->getState(state); |
| 239 | }); |
| 240 | } |
| 241 | |
| 242 | // Handle with active sub-effect first, only send to other sub-effects when success |
| 243 | ndk::ScopedAStatus EffectProxy::setParameter(const Parameter& param) { |
| 244 | return runWithActiveSubEffectThenOthers( |
| 245 | [&](const std::shared_ptr<IEffect>& effect) -> ndk::ScopedAStatus { |
| 246 | return effect->setParameter(param); |
| 247 | }); |
| 248 | } |
| 249 | |
| 250 | // Return the active sub-effect parameter |
| 251 | ndk::ScopedAStatus EffectProxy::getParameter(const Parameter::Id& id, Parameter* param) { |
| 252 | return runWithActiveSubEffect( |
| 253 | [&](const std::shared_ptr<IEffect>& effect) -> ndk::ScopedAStatus { |
| 254 | return effect->getParameter(id, param); |
| 255 | }); |
| 256 | } |
| 257 | |
| 258 | ndk::ScopedAStatus EffectProxy::runWithActiveSubEffectThenOthers( |
| 259 | std::function<ndk::ScopedAStatus(const std::shared_ptr<IEffect>&)> const& func) { |
| 260 | ndk::ScopedAStatus status = runWithActiveSubEffect(func); |
| 261 | if (!status.isOk()) { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 262 | ALOGE("%s active sub-effect return error %s", __func__, status.getDescription().c_str()); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 265 | // proceed with others |
Jaideep Sharma | d823104 | 2023-08-14 13:03:18 +0530 | [diff] [blame] | 266 | for (size_t i = 0; i < mSubEffects.size(); i++) { |
| 267 | if (i == mActiveSubIdx) { |
| 268 | continue; |
| 269 | } |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 270 | if (!mSubEffects[i].handle) { |
| 271 | ALOGE("%s null sub-effect interface for %s", __func__, |
| 272 | mSubEffects[i].descriptor.common.id.uuid.toString().c_str()); |
| 273 | continue; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 274 | } |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 275 | func(mSubEffects[i].handle); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 276 | } |
| 277 | return status; |
| 278 | } |
| 279 | |
| 280 | ndk::ScopedAStatus EffectProxy::runWithActiveSubEffect( |
| 281 | std::function<ndk::ScopedAStatus(const std::shared_ptr<IEffect>&)> const& func) { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 282 | if (!mSubEffects[mActiveSubIdx].handle) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 283 | ALOGE("%s null active sub-effect interface, active %s", __func__, |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 284 | mSubEffects[mActiveSubIdx].descriptor.toString().c_str()); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 285 | return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_NULL_POINTER, |
| 286 | "activeSubEffectNull"); |
| 287 | } |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 288 | return func(mSubEffects[mActiveSubIdx].handle); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | ndk::ScopedAStatus EffectProxy::runWithAllSubEffects( |
| 292 | std::function<ndk::ScopedAStatus(std::shared_ptr<IEffect>&)> const& func) { |
| 293 | ndk::ScopedAStatus status = ndk::ScopedAStatus::ok(); |
| 294 | // proceed with others if active sub-effect success |
| 295 | for (auto& sub : mSubEffects) { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 296 | if (!sub.handle) { |
| 297 | ALOGW("%s null sub-effect interface %s", __func__, sub.descriptor.toString().c_str()); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 298 | continue; |
| 299 | } |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 300 | ndk::ScopedAStatus temp = func(sub.handle); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 301 | if (!temp.isOk()) { |
| 302 | status = ndk::ScopedAStatus::fromStatus(temp.getStatus()); |
| 303 | } |
| 304 | } |
| 305 | return status; |
| 306 | } |
| 307 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 308 | bool EffectProxy::isBypassing() const { |
| 309 | return mSubEffects[mActiveSubIdx].descriptor.common.flags.bypass; |
| 310 | } |
| 311 | |
Shunkai Yao | 1399323 | 2023-09-14 22:49:41 +0000 | [diff] [blame] | 312 | bool EffectProxy::isTunnel() const { |
| 313 | return mSubEffects[mActiveSubIdx].descriptor.common.flags.hwAcceleratorMode == |
| 314 | Flags::HardwareAccelerator::TUNNEL; |
Shunkai Yao | 0a04798 | 2023-09-13 16:55:26 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 317 | binder_status_t EffectProxy::dump(int fd, const char** args, uint32_t numArgs) { |
| 318 | const std::string dumpString = toString(); |
| 319 | write(fd, dumpString.c_str(), dumpString.size()); |
| 320 | |
| 321 | return runWithAllSubEffects([&](std::shared_ptr<IEffect>& effect) { |
| 322 | return ndk::ScopedAStatus::fromStatus(effect->dump(fd, args, numArgs)); |
| 323 | }) |
| 324 | .getStatus(); |
| 325 | } |
| 326 | |
| 327 | std::string EffectProxy::toString(size_t level) const { |
| 328 | std::string prefixSpace(level, ' '); |
| 329 | std::string ss = prefixSpace + "EffectProxy:\n"; |
| 330 | prefixSpace += " "; |
| 331 | base::StringAppendF(&ss, "%sDescriptorCommon: %s\n", prefixSpace.c_str(), |
| 332 | mDescriptorCommon.toString().c_str()); |
| 333 | base::StringAppendF(&ss, "%sActiveSubIdx: %zu\n", prefixSpace.c_str(), mActiveSubIdx); |
| 334 | base::StringAppendF(&ss, "%sAllSubEffects:\n", prefixSpace.c_str()); |
| 335 | for (size_t i = 0; i < mSubEffects.size(); i++) { |
| 336 | base::StringAppendF(&ss, "%s[%zu] - Handle: %p, %s\n", prefixSpace.c_str(), i, |
| 337 | mSubEffects[i].handle.get(), |
| 338 | mSubEffects[i].descriptor.toString().c_str()); |
| 339 | } |
| 340 | return ss; |
| 341 | } |
| 342 | |
| 343 | } // namespace android::effect |