blob: 3c9e6d283c5226525794e656c3cd9bb099fd2aa5 [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>
Sham Rathod94aae5e2022-11-23 12:22:32 +053020#include <vector>
Shunkai Yao6afc8552022-10-26 22:47:20 +000021
22#include "effect-impl/EffectImpl.h"
23#include "effect-impl/EffectUUID.h"
24
25namespace aidl::android::hardware::audio::effect {
26
Shunkai Yao6755d762022-11-02 00:21:02 +000027class VisualizerSwContext final : public EffectContext {
Shunkai Yao6afc8552022-10-26 22:47:20 +000028 public:
Shunkai Yaoe39cd362022-12-22 00:23:34 +000029 static const int kMinCaptureSize = 0x80;
30 static const int kMaxCaptureSize = 0x400;
31 static const int kMaxLatencyMs = 3000;
32 static const int kMaxCaptureBufSize = 0xffff;
33 static const Visualizer::CaptureSamplesRange kCaptureSamplesRange;
Shunkai Yao6afc8552022-10-26 22:47:20 +000034 VisualizerSwContext(int statusDepth, const Parameter::Common& common)
35 : EffectContext(statusDepth, common) {
36 LOG(DEBUG) << __func__;
Shunkai Yaoe39cd362022-12-22 00:23:34 +000037 mCaptureSampleBuffer.resize(kMaxCaptureBufSize);
38 fill(mCaptureSampleBuffer.begin(), mCaptureSampleBuffer.end(), 0x80);
Shunkai Yao6afc8552022-10-26 22:47:20 +000039 }
Sham Rathod94aae5e2022-11-23 12:22:32 +053040
41 RetCode setVsCaptureSize(int captureSize) {
Shunkai Yaoe39cd362022-12-22 00:23:34 +000042 if (captureSize < kMinCaptureSize || captureSize > kMaxCaptureSize) {
Sham Rathod94aae5e2022-11-23 12:22:32 +053043 LOG(ERROR) << __func__ << " invalid captureSize " << captureSize;
44 return RetCode::ERROR_ILLEGAL_PARAMETER;
45 }
46 // TODO : Add implementation to apply new captureSize
47 mCaptureSize = captureSize;
48 return RetCode::SUCCESS;
49 }
50 int getVsCaptureSize() const { return mCaptureSize; }
51
52 RetCode setVsScalingMode(Visualizer::ScalingMode scalingMode) {
53 // TODO : Add implementation to apply new scalingMode
54 mScalingMode = scalingMode;
55 return RetCode::SUCCESS;
56 }
57 Visualizer::ScalingMode getVsScalingMode() const { return mScalingMode; }
58
59 RetCode setVsMeasurementMode(Visualizer::MeasurementMode measurementMode) {
60 // TODO : Add implementation to apply new measurementMode
61 mMeasurementMode = measurementMode;
62 return RetCode::SUCCESS;
63 }
64 Visualizer::MeasurementMode getVsMeasurementMode() const { return mMeasurementMode; }
65
66 RetCode setVsLatency(int latency) {
Shunkai Yaoe39cd362022-12-22 00:23:34 +000067 if (latency < 0 || latency > kMaxLatencyMs) {
Sham Rathod94aae5e2022-11-23 12:22:32 +053068 LOG(ERROR) << __func__ << " invalid latency " << latency;
69 return RetCode::ERROR_ILLEGAL_PARAMETER;
70 }
71 // TODO : Add implementation to modify latency
72 mLatency = latency;
73 return RetCode::SUCCESS;
74 }
75
76 Visualizer::GetOnlyParameters::Measurement getVsMeasurement() const { return mMeasurement; }
Shunkai Yaoe39cd362022-12-22 00:23:34 +000077 std::vector<uint8_t> getVsCaptureSampleBuffer() const { return mCaptureSampleBuffer; }
Sham Rathod94aae5e2022-11-23 12:22:32 +053078
79 private:
Shunkai Yaoe39cd362022-12-22 00:23:34 +000080 int mCaptureSize = kMaxCaptureSize;
Sham Rathod94aae5e2022-11-23 12:22:32 +053081 Visualizer::ScalingMode mScalingMode = Visualizer::ScalingMode::NORMALIZED;
82 Visualizer::MeasurementMode mMeasurementMode = Visualizer::MeasurementMode::NONE;
Sham Rathodd7c6f322022-12-26 11:17:10 +053083 int mLatency = 0;
Sham Rathod94aae5e2022-11-23 12:22:32 +053084 const Visualizer::GetOnlyParameters::Measurement mMeasurement = {0, 0};
Shunkai Yaoe39cd362022-12-22 00:23:34 +000085 std::vector<uint8_t> mCaptureSampleBuffer;
Shunkai Yao6afc8552022-10-26 22:47:20 +000086};
87
Shunkai Yao6755d762022-11-02 00:21:02 +000088class VisualizerSw final : public EffectImpl {
Shunkai Yao6afc8552022-10-26 22:47:20 +000089 public:
Shunkai Yaoc12e0822022-12-12 07:13:58 +000090 static const std::string kEffectName;
91 static const Visualizer::Capability kCapability;
92 static const Descriptor kDescriptor;
Shunkai Yao6afc8552022-10-26 22:47:20 +000093 VisualizerSw() { LOG(DEBUG) << __func__; }
94 ~VisualizerSw() {
Shunkai Yao812d5b42022-11-16 18:08:50 +000095 cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +000096 LOG(DEBUG) << __func__;
Shunkai Yao6afc8552022-10-26 22:47:20 +000097 }
98
99 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
100 ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override;
101 ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id,
102 Parameter::Specific* specific) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530103
Shunkai Yao6afc8552022-10-26 22:47:20 +0000104 std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override;
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530105 std::shared_ptr<EffectContext> getContext() override;
Shunkai Yao6afc8552022-10-26 22:47:20 +0000106 RetCode releaseContext() override;
107
Shraddha Basantwanif627d802022-11-08 14:45:07 +0530108 IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
109 std::string getEffectName() override { return kEffectName; }
110
Shunkai Yao6afc8552022-10-26 22:47:20 +0000111 private:
112 std::shared_ptr<VisualizerSwContext> mContext;
Sham Rathod94aae5e2022-11-23 12:22:32 +0530113
114 ndk::ScopedAStatus setSetOnlyParameterVisualizer(Visualizer::SetOnlyParameters setOnlyParam);
115 ndk::ScopedAStatus getParameterVisualizer(const Visualizer::Tag& tag,
116 Parameter::Specific* specific);
117 ndk::ScopedAStatus getGetOnlyParameterVisualizer(const Visualizer::GetOnlyParameters::Tag& tag,
118 Parameter::Specific* specific);
Shunkai Yao6afc8552022-10-26 22:47:20 +0000119};
120} // namespace aidl::android::hardware::audio::effect