blob: 1432b2be0d9879807eba3ac8211c33f78e63e192 [file] [log] [blame]
Shunkai Yao6afc8552022-10-26 22:47:20 +00001/*
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"
Shunkai Yao6afc8552022-10-26 22:47:20 +000025
26namespace aidl::android::hardware::audio::effect {
27
Shunkai Yao6755d762022-11-02 00:21:02 +000028class VolumeSwContext final : public EffectContext {
Shunkai Yao6afc8552022-10-26 22:47:20 +000029 public:
30 VolumeSwContext(int statusDepth, const Parameter::Common& common)
31 : EffectContext(statusDepth, common) {
32 LOG(DEBUG) << __func__;
33 }
Sham Rathod1b6c1f02022-11-22 17:39:22 +053034
Sham Rathod85793d82022-12-22 19:09:10 +053035 RetCode setVolLevel(int level);
Sham Rathod1b6c1f02022-11-22 17:39:22 +053036
37 int getVolLevel() const { return mLevel; }
38
Sham Rathod85793d82022-12-22 19:09:10 +053039 RetCode setVolMute(bool mute);
Sham Rathod1b6c1f02022-11-22 17:39:22 +053040
41 bool getVolMute() const { return mMute; }
42
43 private:
44 int mLevel = 0;
45 bool mMute = false;
Shunkai Yao6afc8552022-10-26 22:47:20 +000046};
47
Shunkai Yao6755d762022-11-02 00:21:02 +000048class VolumeSw final : public EffectImpl {
Shunkai Yao6afc8552022-10-26 22:47:20 +000049 public:
Shunkai Yaoc12e0822022-12-12 07:13:58 +000050 static const std::string kEffectName;
Shunkai Yao87811022023-02-13 17:40:37 +000051 static const Capability kCapability;
Shunkai Yaoc12e0822022-12-12 07:13:58 +000052 static const Descriptor kDescriptor;
Shunkai Yao6afc8552022-10-26 22:47:20 +000053 VolumeSw() { LOG(DEBUG) << __func__; }
54 ~VolumeSw() {
Shunkai Yao812d5b42022-11-16 18:08:50 +000055 cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +000056 LOG(DEBUG) << __func__;
Shunkai Yao6afc8552022-10-26 22:47:20 +000057 }
58
59 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
60 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override;
61 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id,
62 Parameter::Specific* specific) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053063
Shunkai Yao6afc8552022-10-26 22:47:20 +000064 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053065 std::shared_ptr<EffectContext> getContext() override;
Shunkai Yao6afc8552022-10-26 22:47:20 +000066 RetCode releaseContext() override;
67
Shraddha Basantwanif627d802022-11-08 14:45:07 +053068 IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
69 std::string getEffectName() override { return kEffectName; }
70
Shunkai Yao6afc8552022-10-26 22:47:20 +000071 private:
Shunkai Yao87811022023-02-13 17:40:37 +000072 static const std::vector<Range::VolumeRange> kRanges;
Shunkai Yao6afc8552022-10-26 22:47:20 +000073 std::shared_ptr<VolumeSwContext> mContext;
Sham Rathod1b6c1f02022-11-22 17:39:22 +053074
75 ndk::ScopedAStatus getParameterVolume(const Volume::Tag& tag, Parameter::Specific* specific);
Shunkai Yao6afc8552022-10-26 22:47:20 +000076};
77} // namespace aidl::android::hardware::audio::effect