1 /*
2  * Copyright (C) 2023 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 SpatializerSwContext final : public EffectContext {
30   public:
31     SpatializerSwContext(int statusDepth, const Parameter::Common& common);
32     ~SpatializerSwContext();
33 
34     template <typename TAG>
35     std::optional<Spatializer> getParam(TAG tag);
36     template <typename TAG>
37     ndk::ScopedAStatus setParam(TAG tag, Spatializer spatializer);
38 
39     IEffect::Status process(float* in, float* out, int samples);
40 
41   private:
42     std::unordered_map<Spatializer::Tag, Spatializer> mParamsMap;
43 };
44 
45 class SpatializerSw final : public EffectImpl {
46   public:
47     static const std::string kEffectName;
48     static const Capability kCapability;
49     static const Descriptor kDescriptor;
50     ~SpatializerSw();
51 
52     ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
53     ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific)
54             REQUIRES(mImplMutex) override;
55     ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific)
56             REQUIRES(mImplMutex) override;
57 
58     std::shared_ptr<EffectContext> createContext(const Parameter::Common& common)
59             REQUIRES(mImplMutex) override;
60     RetCode releaseContext() REQUIRES(mImplMutex) override;
61 
getEffectName()62     std::string getEffectName() override { return kEffectName; };
63     IEffect::Status effectProcessImpl(float* in, float* out, int samples)
64             REQUIRES(mImplMutex) override;
65 
66   private:
67     static const std::vector<Range::SpatializerRange> kRanges;
68     std::shared_ptr<SpatializerSwContext> mContext GUARDED_BY(mImplMutex) = nullptr;
69 };
70 }  // namespace aidl::android::hardware::audio::effect
71