blob: a101c59decbe29d131cc45020c0bdf2ca1148412 [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"
25#include "effect-impl/EffectUUID.h"
26
27namespace aidl::android::hardware::audio::effect {
28
Shunkai Yao6755d762022-11-02 00:21:02 +000029class VolumeSwContext final : public EffectContext {
Shunkai Yao6afc8552022-10-26 22:47:20 +000030 public:
31 VolumeSwContext(int statusDepth, const Parameter::Common& common)
32 : EffectContext(statusDepth, common) {
33 LOG(DEBUG) << __func__;
34 }
Sham Rathod1b6c1f02022-11-22 17:39:22 +053035
36 RetCode setVolLevel(int level) {
37 if (level < Volume::MIN_LEVEL_DB || level > Volume::MAX_LEVEL_DB) {
38 LOG(ERROR) << __func__ << " invalid level " << level;
39 return RetCode::ERROR_ILLEGAL_PARAMETER;
40 }
41 // TODO : Add implementation to apply new level
42 mLevel = level;
43 return RetCode::SUCCESS;
44 }
45
46 int getVolLevel() const { return mLevel; }
47
48 RetCode setVolMute(bool mute) {
49 // TODO : Add implementation to modify mute
50 mMute = mute;
51 return RetCode::SUCCESS;
52 }
53
54 bool getVolMute() const { return mMute; }
55
56 private:
57 int mLevel = 0;
58 bool mMute = false;
Shunkai Yao6afc8552022-10-26 22:47:20 +000059};
60
Shunkai Yao6755d762022-11-02 00:21:02 +000061class VolumeSw final : public EffectImpl {
Shunkai Yao6afc8552022-10-26 22:47:20 +000062 public:
Shunkai Yaoc12e0822022-12-12 07:13:58 +000063 static const std::string kEffectName;
64 static const Volume::Capability kCapability;
65 static const Descriptor kDescriptor;
Shunkai Yao6afc8552022-10-26 22:47:20 +000066 VolumeSw() { LOG(DEBUG) << __func__; }
67 ~VolumeSw() {
Shunkai Yao812d5b42022-11-16 18:08:50 +000068 cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +000069 LOG(DEBUG) << __func__;
Shunkai Yao6afc8552022-10-26 22:47:20 +000070 }
71
72 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
73 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override;
74 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id,
75 Parameter::Specific* specific) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053076
Shunkai Yao6afc8552022-10-26 22:47:20 +000077 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053078 std::shared_ptr<EffectContext> getContext() override;
Shunkai Yao6afc8552022-10-26 22:47:20 +000079 RetCode releaseContext() override;
80
Shraddha Basantwanif627d802022-11-08 14:45:07 +053081 IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
82 std::string getEffectName() override { return kEffectName; }
83
Shunkai Yao6afc8552022-10-26 22:47:20 +000084 private:
85 std::shared_ptr<VolumeSwContext> mContext;
Sham Rathod1b6c1f02022-11-22 17:39:22 +053086
87 ndk::ScopedAStatus getParameterVolume(const Volume::Tag& tag, Parameter::Specific* specific);
Shunkai Yao6afc8552022-10-26 22:47:20 +000088};
89} // namespace aidl::android::hardware::audio::effect