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 | |
| 17 | #define LOG_TAG "EffectHalAidl" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 20 | #include <error/expected_utils.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 21 | #include <media/AidlConversionCppNdk.h> |
Shunkai Yao | a03533e | 2023-01-25 06:38:10 +0000 | [diff] [blame^] | 22 | #include <media/AidlConversionEffect.h> |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 23 | #include <media/AidlConversionUtil.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 24 | #include <media/EffectsFactoryApi.h> |
| 25 | #include <mediautils/TimeCheck.h> |
| 26 | #include <utils/Log.h> |
| 27 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 28 | #include <system/audio_effects/effect_aec.h> |
| 29 | #include <system/audio_effects/effect_downmix.h> |
| 30 | #include <system/audio_effects/effect_dynamicsprocessing.h> |
| 31 | #include <system/audio_effects/effect_hapticgenerator.h> |
| 32 | #include <system/audio_effects/effect_ns.h> |
| 33 | #include <system/audio_effects/effect_spatializer.h> |
| 34 | #include <system/audio_effects/effect_visualizer.h> |
| 35 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 36 | #include "EffectHalAidl.h" |
| 37 | |
| 38 | #include <system/audio.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 39 | #include <aidl/android/hardware/audio/effect/IEffect.h> |
| 40 | |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 41 | using ::aidl::android::aidl_utils::statusTFromBinderStatus; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 42 | using ::aidl::android::hardware::audio::effect::CommandId; |
| 43 | using ::aidl::android::hardware::audio::effect::Descriptor; |
| 44 | using ::aidl::android::hardware::audio::effect::IEffect; |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 45 | using ::aidl::android::hardware::audio::effect::IFactory; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 46 | using ::aidl::android::hardware::audio::effect::Parameter; |
| 47 | |
| 48 | namespace android { |
| 49 | namespace effect { |
| 50 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 51 | EffectHalAidl::EffectHalAidl( |
| 52 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory, |
| 53 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect, |
| 54 | uint64_t effectId, int32_t sessionId, int32_t ioId, |
| 55 | const ::aidl::android::hardware::audio::effect::Descriptor& desc) |
| 56 | : EffectConversionHelperAidl(effect, sessionId, ioId, desc), |
| 57 | mFactory(factory), |
| 58 | mEffect(effect), |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 59 | mEffectId(effectId), |
| 60 | mSessionId(sessionId), |
| 61 | mIoId(ioId), |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 62 | mDesc(desc) {} |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 63 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 64 | EffectHalAidl::~EffectHalAidl() { |
| 65 | if (mFactory) { |
| 66 | mFactory->destroyEffect(mEffect); |
| 67 | } |
| 68 | } |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 69 | |
| 70 | status_t EffectHalAidl::setInBuffer(const sp<EffectBufferHalInterface>& buffer) { |
| 71 | if (buffer == nullptr) { |
| 72 | return BAD_VALUE; |
| 73 | } |
| 74 | ALOGW("%s not implemented yet", __func__); |
| 75 | return OK; |
| 76 | } |
| 77 | |
| 78 | status_t EffectHalAidl::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) { |
| 79 | if (buffer == nullptr) { |
| 80 | return BAD_VALUE; |
| 81 | } |
| 82 | ALOGW("%s not implemented yet", __func__); |
| 83 | return OK; |
| 84 | } |
| 85 | |
| 86 | status_t EffectHalAidl::process() { |
| 87 | ALOGW("%s not implemented yet", __func__); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 88 | // write to input FMQ here, and wait for statusMQ STATUS_OK |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 89 | return OK; |
| 90 | } |
| 91 | |
| 92 | // TODO: no one using, maybe deprecate this interface |
| 93 | status_t EffectHalAidl::processReverse() { |
| 94 | ALOGW("%s not implemented yet", __func__); |
| 95 | return OK; |
| 96 | } |
| 97 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 98 | status_t EffectHalAidl::command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, |
| 99 | uint32_t* replySize, void* pReplyData) { |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 100 | return handleCommand(cmdCode, cmdSize, pCmdData, replySize, pReplyData); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | status_t EffectHalAidl::getDescriptor(effect_descriptor_t* pDescriptor) { |
| 104 | ALOGW("%s %p", __func__, pDescriptor); |
| 105 | if (pDescriptor == nullptr) { |
| 106 | return BAD_VALUE; |
| 107 | } |
| 108 | Descriptor aidlDesc; |
Mikhail Naganov | 5e406ba | 2023-01-13 00:27:22 +0000 | [diff] [blame] | 109 | RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getDescriptor(&aidlDesc))); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 110 | |
| 111 | *pDescriptor = VALUE_OR_RETURN_STATUS( |
| 112 | ::aidl::android::aidl2legacy_Descriptor_effect_descriptor(aidlDesc)); |
| 113 | return OK; |
| 114 | } |
| 115 | |
| 116 | status_t EffectHalAidl::close() { |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 117 | return statusTFromBinderStatus(mEffect->close()); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | status_t EffectHalAidl::dump(int fd) { |
| 121 | ALOGW("%s not implemented yet, fd %d", __func__, fd); |
| 122 | return OK; |
| 123 | } |
| 124 | |
| 125 | } // namespace effect |
| 126 | } // namespace android |