blob: 1016ffc920e52eb19b9f7c02f9d44b548835a841 [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 VirtualizerSwContext final : public EffectContext {
Shunkai Yao6afc8552022-10-26 22:47:20 +000030 public:
31 VirtualizerSwContext(int statusDepth, const Parameter::Common& common)
32 : EffectContext(statusDepth, common) {
33 LOG(DEBUG) << __func__;
34 }
Sham Rathode808b072022-12-27 11:56:30 +053035 RetCode setVrStrength(int strength);
Sham Rathod2d319dc2022-11-29 15:06:12 +053036 int getVrStrength() const { return mStrength; }
Shunkai Yao58aaf5b2023-02-06 07:25:09 +000037 RetCode setForcedDevice(
38 const ::aidl::android::media::audio::common::AudioDeviceDescription& device) {
39 mForceDevice = device;
40 return RetCode::SUCCESS;
41 }
42 aidl::android::media::audio::common::AudioDeviceDescription getForcedDevice() const {
43 return mForceDevice;
44 }
Sham Rathod2d319dc2022-11-29 15:06:12 +053045
46 private:
Sham Rathodd7c6f322022-12-26 11:17:10 +053047 int mStrength = 0;
Shunkai Yao58aaf5b2023-02-06 07:25:09 +000048 ::aidl::android::media::audio::common::AudioDeviceDescription mForceDevice;
Shunkai Yao6afc8552022-10-26 22:47:20 +000049};
50
Shunkai Yao6755d762022-11-02 00:21:02 +000051class VirtualizerSw final : public EffectImpl {
Shunkai Yao6afc8552022-10-26 22:47:20 +000052 public:
Shunkai Yaoc12e0822022-12-12 07:13:58 +000053 static const std::string kEffectName;
Sham Rathod2d319dc2022-11-29 15:06:12 +053054 static const bool kStrengthSupported;
Shunkai Yaoc12e0822022-12-12 07:13:58 +000055 static const Virtualizer::Capability kCapability;
56 static const Descriptor kDescriptor;
Shunkai Yao6afc8552022-10-26 22:47:20 +000057 VirtualizerSw() { LOG(DEBUG) << __func__; }
58 ~VirtualizerSw() {
Shunkai Yao812d5b42022-11-16 18:08:50 +000059 cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +000060 LOG(DEBUG) << __func__;
Shunkai Yao6afc8552022-10-26 22:47:20 +000061 }
62
63 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
64 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override;
65 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id,
66 Parameter::Specific* specific) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053067
Shunkai Yao6afc8552022-10-26 22:47:20 +000068 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053069 std::shared_ptr<EffectContext> getContext() override;
Shunkai Yao6afc8552022-10-26 22:47:20 +000070 RetCode releaseContext() override;
71
Shraddha Basantwanif627d802022-11-08 14:45:07 +053072 IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
73 std::string getEffectName() override { return kEffectName; }
74
Shunkai Yao6afc8552022-10-26 22:47:20 +000075 private:
76 std::shared_ptr<VirtualizerSwContext> mContext;
Sham Rathod2d319dc2022-11-29 15:06:12 +053077
78 ndk::ScopedAStatus getParameterVirtualizer(const Virtualizer::Tag& tag,
79 Parameter::Specific* specific);
Shunkai Yao58aaf5b2023-02-06 07:25:09 +000080 ndk::ScopedAStatus getSpeakerAngles(const Virtualizer::SpeakerAnglesPayload payload,
81 Parameter::Specific* specific);
Shunkai Yao6afc8552022-10-26 22:47:20 +000082};
83} // namespace aidl::android::hardware::audio::effect