• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <fmq/AidlMessageQueue.h>
21 #include <cstdlib>
22 #include <memory>
23 
24 #include "effect-impl/EffectImpl.h"
25 
26 namespace aidl::android::hardware::audio::effect {
27 
28 class VolumeSwContext final : public EffectContext {
29   public:
VolumeSwContext(int statusDepth,const Parameter::Common & common)30     VolumeSwContext(int statusDepth, const Parameter::Common& common)
31         : EffectContext(statusDepth, common) {
32         LOG(DEBUG) << __func__;
33     }
34 
35     RetCode setVolLevel(int level);
36 
getVolLevel()37     int getVolLevel() const { return mLevel; }
38 
39     RetCode setVolMute(bool mute);
40 
getVolMute()41     bool getVolMute() const { return mMute; }
42 
43   private:
44     int mLevel = 0;
45     bool mMute = false;
46 };
47 
48 class VolumeSw final : public EffectImpl {
49   public:
50     static const std::string kEffectName;
51     static const Capability kCapability;
52     static const Descriptor kDescriptor;
VolumeSw()53     VolumeSw() { LOG(DEBUG) << __func__; }
~VolumeSw()54     ~VolumeSw() {
55         cleanUp();
56         LOG(DEBUG) << __func__;
57     }
58 
59     ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
60     ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific)
61             REQUIRES(mImplMutex) override;
62     ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific)
63             REQUIRES(mImplMutex) override;
64 
65     std::shared_ptr<EffectContext> createContext(const Parameter::Common& common)
66             REQUIRES(mImplMutex) override;
67     RetCode releaseContext() REQUIRES(mImplMutex) override;
68 
69     IEffect::Status effectProcessImpl(float* in, float* out, int samples)
70             REQUIRES(mImplMutex) override;
getEffectName()71     std::string getEffectName() override { return kEffectName; }
72 
73   private:
74     static const std::vector<Range::VolumeRange> kRanges;
75     std::shared_ptr<VolumeSwContext> mContext GUARDED_BY(mImplMutex);
76 
77     ndk::ScopedAStatus getParameterVolume(const Volume::Tag& tag, Parameter::Specific* specific)
78             REQUIRES(mImplMutex);
79 };
80 }  // namespace aidl::android::hardware::audio::effect
81