Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +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 | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 17 | #include <cstddef> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 18 | #define LOG_TAG "EffectHalAidl" |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 21 | #include <memory> |
| 22 | |
Shunkai Yao | 919b73f | 2024-03-13 00:52:08 +0000 | [diff] [blame] | 23 | #include <audio_utils/primitives.h> |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 24 | #include <error/expected_utils.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 25 | #include <media/AidlConversionCppNdk.h> |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 26 | #include <media/AidlConversionEffect.h> |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 27 | #include <media/AidlConversionUtil.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 28 | #include <media/EffectsFactoryApi.h> |
| 29 | #include <mediautils/TimeCheck.h> |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 30 | #include <system/audio.h> |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 31 | #include <system/audio_effects/effect_uuid.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 32 | #include <utils/Log.h> |
| 33 | |
| 34 | #include "EffectHalAidl.h" |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 35 | #include "EffectProxy.h" |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 36 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 37 | #include <aidl/android/hardware/audio/effect/IEffect.h> |
| 38 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 39 | #include "effectsAidlConversion/AidlConversionAec.h" |
Shunkai Yao | 61ce957 | 2023-02-28 23:55:33 +0000 | [diff] [blame] | 40 | #include "effectsAidlConversion/AidlConversionAgc1.h" |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 41 | #include "effectsAidlConversion/AidlConversionAgc2.h" |
| 42 | #include "effectsAidlConversion/AidlConversionBassBoost.h" |
| 43 | #include "effectsAidlConversion/AidlConversionDownmix.h" |
| 44 | #include "effectsAidlConversion/AidlConversionDynamicsProcessing.h" |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 45 | #include "effectsAidlConversion/AidlConversionEnvReverb.h" |
| 46 | #include "effectsAidlConversion/AidlConversionEq.h" |
| 47 | #include "effectsAidlConversion/AidlConversionHapticGenerator.h" |
| 48 | #include "effectsAidlConversion/AidlConversionLoudnessEnhancer.h" |
| 49 | #include "effectsAidlConversion/AidlConversionNoiseSuppression.h" |
| 50 | #include "effectsAidlConversion/AidlConversionPresetReverb.h" |
| 51 | #include "effectsAidlConversion/AidlConversionSpatializer.h" |
| 52 | #include "effectsAidlConversion/AidlConversionVendorExtension.h" |
| 53 | #include "effectsAidlConversion/AidlConversionVirtualizer.h" |
| 54 | #include "effectsAidlConversion/AidlConversionVisualizer.h" |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 55 | |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 56 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 57 | using ::aidl::android::hardware::audio::effect::Descriptor; |
| 58 | using ::aidl::android::hardware::audio::effect::IEffect; |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 59 | using ::aidl::android::hardware::audio::effect::IFactory; |
Shunkai Yao | e910bfd | 2024-04-18 04:36:42 +0000 | [diff] [blame^] | 60 | using ::aidl::android::hardware::audio::effect::kEventFlagDataMqNotEmpty; |
Shunkai Yao | 1afb46c | 2024-01-09 20:40:45 +0000 | [diff] [blame] | 61 | using ::aidl::android::hardware::audio::effect::kEventFlagDataMqUpdate; |
Shunkai Yao | e910bfd | 2024-04-18 04:36:42 +0000 | [diff] [blame^] | 62 | using ::aidl::android::hardware::audio::effect::kEventFlagNotEmpty; |
Shunkai Yao | e317e33 | 2024-02-06 00:39:49 +0000 | [diff] [blame] | 63 | using ::aidl::android::hardware::audio::effect::kReopenSupportedVersion; |
Shunkai Yao | 26689d9 | 2023-08-01 23:06:13 +0000 | [diff] [blame] | 64 | using ::aidl::android::hardware::audio::effect::State; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 65 | |
| 66 | namespace android { |
| 67 | namespace effect { |
| 68 | |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 69 | EffectHalAidl::EffectHalAidl(const std::shared_ptr<IFactory>& factory, |
Shunkai Yao | e317e33 | 2024-02-06 00:39:49 +0000 | [diff] [blame] | 70 | const std::shared_ptr<IEffect>& effect, int32_t sessionId, |
| 71 | int32_t ioId, const Descriptor& desc, bool isProxyEffect) |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 72 | : mFactory(factory), |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 73 | mEffect(effect), |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 74 | mSessionId(sessionId), |
| 75 | mIoId(ioId), |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 76 | mIsProxyEffect(isProxyEffect) { |
Shunkai Yao | e317e33 | 2024-02-06 00:39:49 +0000 | [diff] [blame] | 77 | assert(mFactory != nullptr); |
| 78 | assert(mEffect != nullptr); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 79 | createAidlConversion(effect, sessionId, ioId, desc); |
| 80 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 81 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 82 | EffectHalAidl::~EffectHalAidl() { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 83 | if (mEffect) { |
Shunkai Yao | 79f9874 | 2023-05-03 23:54:43 +0000 | [diff] [blame] | 84 | if (mIsProxyEffect) { |
| 85 | std::static_pointer_cast<EffectProxy>(mEffect)->destroy(); |
| 86 | } else if (mFactory) { |
| 87 | mFactory->destroyEffect(mEffect); |
| 88 | } |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 91 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 92 | status_t EffectHalAidl::createAidlConversion( |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 93 | std::shared_ptr<IEffect> effect, |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 94 | int32_t sessionId, int32_t ioId, |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 95 | const Descriptor& desc) { |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 96 | const auto& typeUuid = desc.common.id.type; |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 97 | ALOGI("%s create UUID %s", __func__, typeUuid.toString().c_str()); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 98 | if (typeUuid == |
| 99 | ::aidl::android::hardware::audio::effect::getEffectTypeUuidAcousticEchoCanceler()) { |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 100 | mConversion = std::make_unique<android::effect::AidlConversionAec>(effect, sessionId, ioId, |
| 101 | desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 102 | } else if (typeUuid == ::aidl::android::hardware::audio::effect:: |
| 103 | getEffectTypeUuidAutomaticGainControlV1()) { |
Shunkai Yao | 61ce957 | 2023-02-28 23:55:33 +0000 | [diff] [blame] | 104 | mConversion = std::make_unique<android::effect::AidlConversionAgc1>(effect, sessionId, ioId, |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 105 | desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 106 | } else if (typeUuid == ::aidl::android::hardware::audio::effect:: |
| 107 | getEffectTypeUuidAutomaticGainControlV2()) { |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 108 | mConversion = std::make_unique<android::effect::AidlConversionAgc2>(effect, sessionId, ioId, |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 109 | desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 110 | } else if (typeUuid == ::aidl::android::hardware::audio::effect::getEffectTypeUuidBassBoost()) { |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 111 | mConversion = std::make_unique<android::effect::AidlConversionBassBoost>( |
| 112 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 113 | } else if (typeUuid == ::aidl::android::hardware::audio::effect::getEffectTypeUuidDownmix()) { |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 114 | mConversion = std::make_unique<android::effect::AidlConversionDownmix>( |
| 115 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 116 | } else if (typeUuid == |
| 117 | ::aidl::android::hardware::audio::effect::getEffectTypeUuidDynamicsProcessing()) { |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 118 | mConversion = std::make_unique<android::effect::AidlConversionDp>(effect, sessionId, ioId, |
| 119 | desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 120 | } else if (typeUuid == ::aidl::android::hardware::audio::effect::getEffectTypeUuidEnvReverb()) { |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 121 | mConversion = std::make_unique<android::effect::AidlConversionEnvReverb>( |
| 122 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 123 | } else if (typeUuid == ::aidl::android::hardware::audio::effect::getEffectTypeUuidEqualizer()) { |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 124 | mConversion = std::make_unique<android::effect::AidlConversionEq>(effect, sessionId, ioId, |
| 125 | desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 126 | } else if (typeUuid == |
| 127 | ::aidl::android::hardware::audio::effect::getEffectTypeUuidHapticGenerator()) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 128 | mConversion = std::make_unique<android::effect::AidlConversionHapticGenerator>( |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 129 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 130 | } else if (typeUuid == |
| 131 | ::aidl::android::hardware::audio::effect::getEffectTypeUuidLoudnessEnhancer()) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 132 | mConversion = std::make_unique<android::effect::AidlConversionLoudnessEnhancer>( |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 133 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 134 | } else if (typeUuid == |
| 135 | ::aidl::android::hardware::audio::effect::getEffectTypeUuidNoiseSuppression()) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 136 | mConversion = std::make_unique<android::effect::AidlConversionNoiseSuppression>( |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 137 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 138 | } else if (typeUuid == |
| 139 | ::aidl::android::hardware::audio::effect::getEffectTypeUuidPresetReverb()) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 140 | mConversion = std::make_unique<android::effect::AidlConversionPresetReverb>( |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 141 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 142 | } else if (typeUuid == |
| 143 | ::aidl::android::hardware::audio::effect::getEffectTypeUuidSpatializer()) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 144 | mConversion = std::make_unique<android::effect::AidlConversionSpatializer>( |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 145 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 146 | } else if (typeUuid == |
| 147 | ::aidl::android::hardware::audio::effect::getEffectTypeUuidVirtualizer()) { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 148 | mConversion = std::make_unique<android::effect::AidlConversionVirtualizer>( |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 149 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | 399be68 | 2023-03-06 18:54:18 +0000 | [diff] [blame] | 150 | } else if (typeUuid == |
| 151 | ::aidl::android::hardware::audio::effect::getEffectTypeUuidVisualizer()) { |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 152 | mConversion = std::make_unique<android::effect::AidlConversionVisualizer>( |
| 153 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 154 | } else { |
Shunkai Yao | 242521c | 2023-01-29 18:08:09 +0000 | [diff] [blame] | 155 | // For unknown UUID, use vendor extension implementation |
| 156 | mConversion = std::make_unique<android::effect::AidlConversionVendorExtension>( |
Shunkai Yao | 323273d | 2023-05-24 00:45:43 +0000 | [diff] [blame] | 157 | effect, sessionId, ioId, desc, mIsProxyEffect); |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 158 | } |
| 159 | return OK; |
| 160 | } |
| 161 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 162 | status_t EffectHalAidl::setInBuffer(const sp<EffectBufferHalInterface>& buffer) { |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 163 | mInBuffer = buffer; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 164 | return OK; |
| 165 | } |
| 166 | |
| 167 | status_t EffectHalAidl::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) { |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 168 | mOutBuffer = buffer; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 169 | return OK; |
| 170 | } |
| 171 | |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 172 | // write to input FMQ here, wait for statusMQ STATUS_OK, and read from output FMQ |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 173 | status_t EffectHalAidl::process() { |
Shunkai Yao | 1afb46c | 2024-01-09 20:40:45 +0000 | [diff] [blame] | 174 | const std::string effectName = mConversion->getDescriptor().common.name; |
Shunkai Yao | 26689d9 | 2023-08-01 23:06:13 +0000 | [diff] [blame] | 175 | State state = State::INIT; |
| 176 | if (mConversion->isBypassing() || !mEffect->getState(&state).isOk() || |
| 177 | state != State::PROCESSING) { |
Shunkai Yao | 1afb46c | 2024-01-09 20:40:45 +0000 | [diff] [blame] | 178 | ALOGI("%s skipping %s process because it's %s", __func__, effectName.c_str(), |
Shunkai Yao | 26689d9 | 2023-08-01 23:06:13 +0000 | [diff] [blame] | 179 | mConversion->isBypassing() |
| 180 | ? "bypassing" |
| 181 | : aidl::android::hardware::audio::effect::toString(state).c_str()); |
Jaideep Sharma | bd9b0d3 | 2023-09-20 11:50:25 +0530 | [diff] [blame] | 182 | return -ENODATA; |
Shunkai Yao | 26689d9 | 2023-08-01 23:06:13 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Shunkai Yao | 1afb46c | 2024-01-09 20:40:45 +0000 | [diff] [blame] | 185 | // check if the DataMq needs any update, timeout at 1ns to avoid being blocked |
| 186 | auto efGroup = mConversion->getEventFlagGroup(); |
| 187 | if (!efGroup) { |
| 188 | ALOGE("%s invalid efGroup", __func__); |
| 189 | return INVALID_OPERATION; |
| 190 | } |
| 191 | |
Shunkai Yao | e317e33 | 2024-02-06 00:39:49 +0000 | [diff] [blame] | 192 | // use IFactory HAL version because IEffect can be an EffectProxy instance |
| 193 | static const int halVersion = [&]() { |
| 194 | int version = 0; |
| 195 | return mFactory->getInterfaceVersion(&version).isOk() ? version : 0; |
| 196 | }(); |
| 197 | |
| 198 | if (uint32_t efState = 0; halVersion >= kReopenSupportedVersion && |
| 199 | ::android::OK == efGroup->wait(kEventFlagDataMqUpdate, &efState, |
| 200 | 1 /* ns */, true /* retry */) && |
| 201 | efState & kEventFlagDataMqUpdate) { |
Shunkai Yao | ac61ee9 | 2024-03-14 21:57:46 +0000 | [diff] [blame] | 202 | ALOGV("%s %s V%d receive dataMQUpdate eventFlag from HAL", __func__, effectName.c_str(), |
Shunkai Yao | e317e33 | 2024-02-06 00:39:49 +0000 | [diff] [blame] | 203 | halVersion); |
Shunkai Yao | e910bfd | 2024-04-18 04:36:42 +0000 | [diff] [blame^] | 204 | |
Shunkai Yao | 1afb46c | 2024-01-09 20:40:45 +0000 | [diff] [blame] | 205 | mConversion->reopen(); |
| 206 | } |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 207 | auto statusQ = mConversion->getStatusMQ(); |
| 208 | auto inputQ = mConversion->getInputMQ(); |
| 209 | auto outputQ = mConversion->getOutputMQ(); |
| 210 | if (!statusQ || !statusQ->isValid() || !inputQ || !inputQ->isValid() || !outputQ || |
Shunkai Yao | 1afb46c | 2024-01-09 20:40:45 +0000 | [diff] [blame] | 211 | !outputQ->isValid()) { |
| 212 | ALOGE("%s invalid FMQ [Status %d I %d O %d]", __func__, statusQ ? statusQ->isValid() : 0, |
| 213 | inputQ ? inputQ->isValid() : 0, outputQ ? outputQ->isValid() : 0); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 214 | return INVALID_OPERATION; |
| 215 | } |
| 216 | |
| 217 | size_t available = inputQ->availableToWrite(); |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 218 | size_t floatsToWrite = std::min(available, mInBuffer->getSize() / sizeof(float)); |
| 219 | if (floatsToWrite == 0) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 220 | ALOGE("%s not able to write, floats in buffer %zu, space in FMQ %zu", __func__, |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 221 | mInBuffer->getSize() / sizeof(float), available); |
| 222 | return INVALID_OPERATION; |
| 223 | } |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 224 | if (!mInBuffer->audioBuffer() || |
| 225 | !inputQ->write((float*)mInBuffer->audioBuffer()->f32, floatsToWrite)) { |
| 226 | ALOGE("%s failed to write %zu floats from audiobuffer %p to inputQ [avail %zu]", __func__, |
| 227 | floatsToWrite, mInBuffer->audioBuffer(), inputQ->availableToWrite()); |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 228 | return INVALID_OPERATION; |
| 229 | } |
Shunkai Yao | e910bfd | 2024-04-18 04:36:42 +0000 | [diff] [blame^] | 230 | |
| 231 | // for V2 audio effect HAL, expect different EventFlag to avoid bit conflict with FMQ_NOT_EMPTY |
| 232 | efGroup->wake(halVersion >= kReopenSupportedVersion ? kEventFlagDataMqNotEmpty |
| 233 | : kEventFlagNotEmpty); |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 234 | |
| 235 | IEffect::Status retStatus{}; |
Shunkai Yao | e910bfd | 2024-04-18 04:36:42 +0000 | [diff] [blame^] | 236 | if (!statusQ->readBlocking(&retStatus, 1)) { |
| 237 | ALOGE("%s %s V%d read status from status FMQ failed", __func__, effectName.c_str(), |
| 238 | halVersion); |
| 239 | return INVALID_OPERATION; |
| 240 | } |
| 241 | if (retStatus.status != OK || (size_t)retStatus.fmqConsumed != floatsToWrite || |
| 242 | retStatus.fmqProduced == 0) { |
| 243 | ALOGE("%s read status failed: %s, consumed %d (of %zu) produced %d", __func__, |
| 244 | retStatus.toString().c_str(), retStatus.fmqConsumed, floatsToWrite, |
| 245 | retStatus.fmqProduced); |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 246 | return INVALID_OPERATION; |
| 247 | } |
| 248 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 249 | available = outputQ->availableToRead(); |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 250 | size_t floatsToRead = std::min(available, mOutBuffer->getSize() / sizeof(float)); |
| 251 | if (floatsToRead == 0) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 252 | ALOGE("%s not able to read, buffer space %zu, floats in FMQ %zu", __func__, |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 253 | mOutBuffer->getSize() / sizeof(float), available); |
| 254 | return INVALID_OPERATION; |
| 255 | } |
Shunkai Yao | 919b73f | 2024-03-13 00:52:08 +0000 | [diff] [blame] | 256 | |
| 257 | float *outputRawBuffer = mOutBuffer->audioBuffer()->f32; |
| 258 | std::vector<float> tempBuffer; |
| 259 | if (mConversion->mOutputAccessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { |
| 260 | tempBuffer.resize(floatsToRead); |
| 261 | outputRawBuffer = tempBuffer.data(); |
| 262 | } |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 263 | // always read floating point data for AIDL |
Shunkai Yao | 919b73f | 2024-03-13 00:52:08 +0000 | [diff] [blame] | 264 | if (!outputQ->read(outputRawBuffer, floatsToRead)) { |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 265 | ALOGE("%s failed to read %zu from outputQ to audioBuffer %p", __func__, floatsToRead, |
| 266 | mOutBuffer->audioBuffer()); |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 267 | return INVALID_OPERATION; |
| 268 | } |
Shunkai Yao | 919b73f | 2024-03-13 00:52:08 +0000 | [diff] [blame] | 269 | if (mConversion->mOutputAccessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { |
| 270 | accumulate_float(mOutBuffer->audioBuffer()->f32, outputRawBuffer, floatsToRead); |
| 271 | } |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 272 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 273 | return OK; |
| 274 | } |
| 275 | |
| 276 | // TODO: no one using, maybe deprecate this interface |
| 277 | status_t EffectHalAidl::processReverse() { |
| 278 | ALOGW("%s not implemented yet", __func__); |
| 279 | return OK; |
| 280 | } |
| 281 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 282 | status_t EffectHalAidl::command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, |
| 283 | uint32_t* replySize, void* pReplyData) { |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 284 | TIME_CHECK(); |
| 285 | if (!mConversion) { |
| 286 | ALOGE("%s can not handle command %d when conversion not exist", __func__, cmdCode); |
| 287 | return INVALID_OPERATION; |
| 288 | } |
| 289 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 290 | return mConversion->handleCommand(cmdCode, cmdSize, pCmdData, replySize, pReplyData); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | status_t EffectHalAidl::getDescriptor(effect_descriptor_t* pDescriptor) { |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 294 | TIME_CHECK(); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 295 | if (pDescriptor == nullptr) { |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 296 | ALOGE("%s null descriptor pointer", __func__); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 297 | return BAD_VALUE; |
| 298 | } |
| 299 | Descriptor aidlDesc; |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 300 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getDescriptor(&aidlDesc))); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 301 | |
| 302 | *pDescriptor = VALUE_OR_RETURN_STATUS( |
| 303 | ::aidl::android::aidl2legacy_Descriptor_effect_descriptor(aidlDesc)); |
| 304 | return OK; |
| 305 | } |
| 306 | |
| 307 | status_t EffectHalAidl::close() { |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 308 | TIME_CHECK(); |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 309 | return statusTFromBinderStatus(mEffect->close()); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | status_t EffectHalAidl::dump(int fd) { |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 313 | TIME_CHECK(); |
| 314 | return mEffect->dump(fd, nullptr, 0); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | } // namespace effect |
| 318 | } // namespace android |