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 #pragma once
18 
19 #include <aidl/android/hardware/audio/effect/BnEffect.h>
20 #include <aidl/android/hardware/audio/effect/Range.h>
21 #include <fmq/AidlMessageQueue.h>
22 #include <cstdlib>
23 #include <memory>
24 
25 #include "effect-impl/EffectImpl.h"
26 
27 namespace aidl::android::hardware::audio::effect {
28 
29 class AcousticEchoCancelerSwContext final : public EffectContext {
30   public:
AcousticEchoCancelerSwContext(int statusDepth,const Parameter::Common & common)31     AcousticEchoCancelerSwContext(int statusDepth, const Parameter::Common& common)
32         : EffectContext(statusDepth, common) {
33         LOG(DEBUG) << __func__;
34     }
35 
36     RetCode setEchoDelay(int echoDelayUs);
getEchoDelay()37     int getEchoDelay() const { return mEchoDelayUs; }
38 
39   private:
40     int mEchoDelayUs = 0;
41 };
42 
43 class AcousticEchoCancelerSw final : public EffectImpl {
44   public:
45     static const std::string kEffectName;
46     static const Capability kCapability;
47     static const Descriptor kDescriptor;
AcousticEchoCancelerSw()48     AcousticEchoCancelerSw() { LOG(DEBUG) << __func__; }
~AcousticEchoCancelerSw()49     ~AcousticEchoCancelerSw() {
50         cleanUp();
51         LOG(DEBUG) << __func__;
52     }
53 
54     ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
55     ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific)
56             REQUIRES(mImplMutex) override;
57     ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific)
58             REQUIRES(mImplMutex) override;
59 
60     std::shared_ptr<EffectContext> createContext(const Parameter::Common& common)
61             REQUIRES(mImplMutex) override;
62     RetCode releaseContext() REQUIRES(mImplMutex) override;
63 
getEffectName()64     std::string getEffectName() override { return kEffectName; };
65     IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
66 
67   private:
68     static const std::vector<Range::AcousticEchoCancelerRange> kRanges;
69     std::shared_ptr<AcousticEchoCancelerSwContext> mContext GUARDED_BY(mImplMutex);
70     ndk::ScopedAStatus getParameterAcousticEchoCanceler(const AcousticEchoCanceler::Tag& tag,
71                                                         Parameter::Specific* specific)
72             REQUIRES(mImplMutex);
73 };
74 }  // namespace aidl::android::hardware::audio::effect
75