blob: 9287838083b7e87073ecc1d249cf3e5547168ef2 [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 VirtualizerSwContext final : public EffectContext {
Shunkai Yao6afc8552022-10-26 22:47:20 +000029 public:
30 VirtualizerSwContext(int statusDepth, const Parameter::Common& common)
31 : EffectContext(statusDepth, common) {
32 LOG(DEBUG) << __func__;
33 }
Sham Rathode808b072022-12-27 11:56:30 +053034 RetCode setVrStrength(int strength);
Sham Rathod2d319dc2022-11-29 15:06:12 +053035 int getVrStrength() const { return mStrength; }
Shunkai Yao58aaf5b2023-02-06 07:25:09 +000036 RetCode setForcedDevice(
37 const ::aidl::android::media::audio::common::AudioDeviceDescription& device) {
38 mForceDevice = device;
39 return RetCode::SUCCESS;
40 }
41 aidl::android::media::audio::common::AudioDeviceDescription getForcedDevice() const {
42 return mForceDevice;
43 }
Sham Rathod2d319dc2022-11-29 15:06:12 +053044
45 private:
Sham Rathodd7c6f322022-12-26 11:17:10 +053046 int mStrength = 0;
Shunkai Yao58aaf5b2023-02-06 07:25:09 +000047 ::aidl::android::media::audio::common::AudioDeviceDescription mForceDevice;
Shunkai Yao6afc8552022-10-26 22:47:20 +000048};
49
Shunkai Yao6755d762022-11-02 00:21:02 +000050class VirtualizerSw final : public EffectImpl {
Shunkai Yao6afc8552022-10-26 22:47:20 +000051 public:
Shunkai Yaoc12e0822022-12-12 07:13:58 +000052 static const std::string kEffectName;
Shunkai Yao87811022023-02-13 17:40:37 +000053 static const Capability kCapability;
Shunkai Yaoc12e0822022-12-12 07:13:58 +000054 static const Descriptor kDescriptor;
Shunkai Yao6afc8552022-10-26 22:47:20 +000055 VirtualizerSw() { LOG(DEBUG) << __func__; }
56 ~VirtualizerSw() {
Shunkai Yao812d5b42022-11-16 18:08:50 +000057 cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +000058 LOG(DEBUG) << __func__;
Shunkai Yao6afc8552022-10-26 22:47:20 +000059 }
60
61 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
Shunkai Yao81bfcda2024-01-09 20:50:53 +000062 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific)
63 REQUIRES(mImplMutex) override;
64 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, Parameter::Specific* specific)
65 REQUIRES(mImplMutex) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053066
Shunkai Yao81bfcda2024-01-09 20:50:53 +000067 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common)
68 REQUIRES(mImplMutex) override;
69 RetCode releaseContext() REQUIRES(mImplMutex) override;
Shunkai Yao6afc8552022-10-26 22:47:20 +000070
Shraddha Basantwanif627d802022-11-08 14:45:07 +053071 IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
72 std::string getEffectName() override { return kEffectName; }
73
Shunkai Yao6afc8552022-10-26 22:47:20 +000074 private:
Shunkai Yao87811022023-02-13 17:40:37 +000075 static const std::vector<Range::VirtualizerRange> kRanges;
Shunkai Yao81bfcda2024-01-09 20:50:53 +000076 std::shared_ptr<VirtualizerSwContext> mContext GUARDED_BY(mImplMutex);
Sham Rathod2d319dc2022-11-29 15:06:12 +053077
78 ndk::ScopedAStatus getParameterVirtualizer(const Virtualizer::Tag& tag,
Shunkai Yao81bfcda2024-01-09 20:50:53 +000079 Parameter::Specific* specific) REQUIRES(mImplMutex);
Shunkai Yao58aaf5b2023-02-06 07:25:09 +000080 ndk::ScopedAStatus getSpeakerAngles(const Virtualizer::SpeakerAnglesPayload payload,
Shunkai Yao81bfcda2024-01-09 20:50:53 +000081 Parameter::Specific* specific) REQUIRES(mImplMutex);
Shunkai Yao6afc8552022-10-26 22:47:20 +000082};
83} // namespace aidl::android::hardware::audio::effect