xref: /aosp_15_r20/hardware/interfaces/audio/aidl/default/eraser/Eraser.h (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright (C) 2024 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 "effect-impl/EffectContext.h"
20 #include "effect-impl/EffectImpl.h"
21 
22 #include <fmq/AidlMessageQueue.h>
23 
24 #include <unordered_map>
25 #include <vector>
26 
27 namespace aidl::android::hardware::audio::effect {
28 
29 class EraserSwContext final : public EffectContext {
30   public:
31     EraserSwContext(int statusDepth, const Parameter::Common& common);
32     ~EraserSwContext() final;
33 
34     template <typename TAG>
35     std::optional<Eraser> getParam(TAG tag);
36     template <typename TAG>
37     ndk::ScopedAStatus setParam(TAG tag, Eraser eraser);
38 
39     IEffect::Status process(float* in, float* out, int samples);
40 
41   private:
42     std::unordered_map<Eraser::Tag, Eraser> mParamsMap;
43 };
44 
45 class EraserSw final : public EffectImpl {
46   public:
47     static const std::string kEffectName;
48     static const Capability kCapability;
49     static const Descriptor kDescriptor;
50     ~EraserSw() final;
51 
52     ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) final;
53     ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific)
54             REQUIRES(mImplMutex) final;
55     ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific)
56             REQUIRES(mImplMutex) final;
57 
58     std::shared_ptr<EffectContext> createContext(const Parameter::Common& common)
59             REQUIRES(mImplMutex) final;
60     RetCode releaseContext() REQUIRES(mImplMutex) final;
61 
getEffectName()62     std::string getEffectName() final { return kEffectName; };
63     IEffect::Status effectProcessImpl(float* in, float* out, int samples)
64             REQUIRES(mImplMutex) final;
65 
66     ndk::ScopedAStatus command(CommandId command) final;
67     void drainingComplete_l() REQUIRES(mImplMutex);
68 
69   private:
70     static const std::vector<Range::SpatializerRange> kRanges;
71     std::shared_ptr<EraserSwContext> mContext GUARDED_BY(mImplMutex);
72 };
73 }  // namespace aidl::android::hardware::audio::effect
74