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 | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 17 | #include <memory> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 18 | #define LOG_TAG "EffectHalAidl" |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 21 | #include <error/expected_utils.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 22 | #include <media/AidlConversionCppNdk.h> |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame] | 23 | #include <media/AidlConversionEffect.h> |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 24 | #include <media/AidlConversionUtil.h> |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 25 | #include <media/audiohal/AudioEffectUuid.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 26 | #include <media/EffectsFactoryApi.h> |
| 27 | #include <mediautils/TimeCheck.h> |
| 28 | #include <utils/Log.h> |
| 29 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 30 | #include <system/audio_effects/effect_aec.h> |
| 31 | #include <system/audio_effects/effect_downmix.h> |
| 32 | #include <system/audio_effects/effect_dynamicsprocessing.h> |
| 33 | #include <system/audio_effects/effect_hapticgenerator.h> |
| 34 | #include <system/audio_effects/effect_ns.h> |
| 35 | #include <system/audio_effects/effect_spatializer.h> |
| 36 | #include <system/audio_effects/effect_visualizer.h> |
| 37 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 38 | #include "EffectHalAidl.h" |
| 39 | |
| 40 | #include <system/audio.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 41 | #include <aidl/android/hardware/audio/effect/IEffect.h> |
| 42 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 43 | #include "effectsAidlConversion/AidlConversionAec.h" |
| 44 | #include "effectsAidlConversion/AidlConversionAgc2.h" |
| 45 | #include "effectsAidlConversion/AidlConversionBassBoost.h" |
| 46 | #include "effectsAidlConversion/AidlConversionDownmix.h" |
| 47 | #include "effectsAidlConversion/AidlConversionDynamicsProcessing.h" |
| 48 | |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 49 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 50 | using ::aidl::android::hardware::audio::effect::CommandId; |
| 51 | using ::aidl::android::hardware::audio::effect::Descriptor; |
| 52 | using ::aidl::android::hardware::audio::effect::IEffect; |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 53 | using ::aidl::android::hardware::audio::effect::IFactory; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 54 | using ::aidl::android::hardware::audio::effect::Parameter; |
| 55 | |
| 56 | namespace android { |
| 57 | namespace effect { |
| 58 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 59 | EffectHalAidl::EffectHalAidl( |
| 60 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory, |
| 61 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect, |
| 62 | uint64_t effectId, int32_t sessionId, int32_t ioId, |
| 63 | const ::aidl::android::hardware::audio::effect::Descriptor& desc) |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 64 | : mFactory(factory), |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 65 | mEffect(effect), |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 66 | mEffectId(effectId), |
| 67 | mSessionId(sessionId), |
| 68 | mIoId(ioId), |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 69 | mDesc(desc) { |
| 70 | createAidlConversion(effect, sessionId, ioId, desc); |
| 71 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 72 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 73 | EffectHalAidl::~EffectHalAidl() { |
| 74 | if (mFactory) { |
| 75 | mFactory->destroyEffect(mEffect); |
| 76 | } |
| 77 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 78 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 79 | status_t EffectHalAidl::createAidlConversion( |
| 80 | std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect, |
| 81 | int32_t sessionId, int32_t ioId, |
| 82 | const ::aidl::android::hardware::audio::effect::Descriptor& desc) { |
| 83 | const auto& typeUuid = desc.common.id.type; |
| 84 | if (typeUuid == kAcousticEchoCancelerTypeUUID) { |
| 85 | mConversion = |
| 86 | std::make_unique<android::effect::AidlConversionAec>(effect, sessionId, ioId, desc); |
| 87 | } else if (typeUuid == kAutomaticGainControlTypeUUID) { |
| 88 | mConversion = std::make_unique<android::effect::AidlConversionAgc2>(effect, sessionId, ioId, |
| 89 | desc); |
| 90 | } else if (typeUuid == kBassBoostTypeUUID) { |
| 91 | mConversion = std::make_unique<android::effect::AidlConversionBassBoost>(effect, sessionId, |
| 92 | ioId, desc); |
| 93 | } else if (typeUuid == kDownmixTypeUUID) { |
| 94 | mConversion = std::make_unique<android::effect::AidlConversionDownmix>(effect, sessionId, |
| 95 | ioId, desc); |
| 96 | } else if (typeUuid == kDynamicsProcessingTypeUUID) { |
| 97 | mConversion = |
| 98 | std::make_unique<android::effect::AidlConversionDp>(effect, sessionId, ioId, desc); |
| 99 | } else { |
| 100 | ALOGE("%s effect not implemented yet, UUID type: %s", __func__, |
| 101 | typeUuid.toString().c_str()); |
| 102 | return BAD_VALUE; |
| 103 | } |
| 104 | return OK; |
| 105 | } |
| 106 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 107 | status_t EffectHalAidl::setInBuffer(const sp<EffectBufferHalInterface>& buffer) { |
| 108 | if (buffer == nullptr) { |
| 109 | return BAD_VALUE; |
| 110 | } |
| 111 | ALOGW("%s not implemented yet", __func__); |
| 112 | return OK; |
| 113 | } |
| 114 | |
| 115 | status_t EffectHalAidl::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) { |
| 116 | if (buffer == nullptr) { |
| 117 | return BAD_VALUE; |
| 118 | } |
| 119 | ALOGW("%s not implemented yet", __func__); |
| 120 | return OK; |
| 121 | } |
| 122 | |
| 123 | status_t EffectHalAidl::process() { |
| 124 | ALOGW("%s not implemented yet", __func__); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 125 | // write to input FMQ here, and wait for statusMQ STATUS_OK |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 126 | return OK; |
| 127 | } |
| 128 | |
| 129 | // TODO: no one using, maybe deprecate this interface |
| 130 | status_t EffectHalAidl::processReverse() { |
| 131 | ALOGW("%s not implemented yet", __func__); |
| 132 | return OK; |
| 133 | } |
| 134 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 135 | status_t EffectHalAidl::command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, |
| 136 | uint32_t* replySize, void* pReplyData) { |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 137 | return mConversion |
| 138 | ? mConversion->handleCommand(cmdCode, cmdSize, pCmdData, replySize, pReplyData) |
| 139 | : INVALID_OPERATION; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | status_t EffectHalAidl::getDescriptor(effect_descriptor_t* pDescriptor) { |
| 143 | ALOGW("%s %p", __func__, pDescriptor); |
| 144 | if (pDescriptor == nullptr) { |
| 145 | return BAD_VALUE; |
| 146 | } |
| 147 | Descriptor aidlDesc; |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 148 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getDescriptor(&aidlDesc))); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 149 | |
| 150 | *pDescriptor = VALUE_OR_RETURN_STATUS( |
| 151 | ::aidl::android::aidl2legacy_Descriptor_effect_descriptor(aidlDesc)); |
| 152 | return OK; |
| 153 | } |
| 154 | |
| 155 | status_t EffectHalAidl::close() { |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 156 | return statusTFromBinderStatus(mEffect->close()); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | status_t EffectHalAidl::dump(int fd) { |
| 160 | ALOGW("%s not implemented yet, fd %d", __func__, fd); |
| 161 | return OK; |
| 162 | } |
| 163 | |
| 164 | } // namespace effect |
| 165 | } // namespace android |