Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 1 | /* |
| 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 Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 20 | #include <vector> |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 21 | |
| 22 | #include "effect-impl/EffectImpl.h" |
| 23 | #include "effect-impl/EffectUUID.h" |
| 24 | |
| 25 | namespace aidl::android::hardware::audio::effect { |
| 26 | |
Shunkai Yao | 6755d76 | 2022-11-02 00:21:02 +0000 | [diff] [blame] | 27 | class VisualizerSwContext final : public EffectContext { |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 28 | public: |
Shunkai Yao | e39cd36 | 2022-12-22 00:23:34 +0000 | [diff] [blame] | 29 | 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 Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 34 | VisualizerSwContext(int statusDepth, const Parameter::Common& common) |
| 35 | : EffectContext(statusDepth, common) { |
| 36 | LOG(DEBUG) << __func__; |
Shunkai Yao | e39cd36 | 2022-12-22 00:23:34 +0000 | [diff] [blame] | 37 | mCaptureSampleBuffer.resize(kMaxCaptureBufSize); |
| 38 | fill(mCaptureSampleBuffer.begin(), mCaptureSampleBuffer.end(), 0x80); |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 39 | } |
Sham Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 40 | |
Sham Rathod | dc7bcc8 | 2022-12-27 18:16:10 +0530 | [diff] [blame] | 41 | RetCode setVsCaptureSize(int captureSize); |
Sham Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 42 | int getVsCaptureSize() const { return mCaptureSize; } |
| 43 | |
Sham Rathod | dc7bcc8 | 2022-12-27 18:16:10 +0530 | [diff] [blame] | 44 | RetCode setVsScalingMode(Visualizer::ScalingMode scalingMode); |
Sham Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 45 | Visualizer::ScalingMode getVsScalingMode() const { return mScalingMode; } |
| 46 | |
Sham Rathod | dc7bcc8 | 2022-12-27 18:16:10 +0530 | [diff] [blame] | 47 | RetCode setVsMeasurementMode(Visualizer::MeasurementMode measurementMode); |
Sham Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 48 | Visualizer::MeasurementMode getVsMeasurementMode() const { return mMeasurementMode; } |
| 49 | |
Sham Rathod | dc7bcc8 | 2022-12-27 18:16:10 +0530 | [diff] [blame] | 50 | RetCode setVsLatency(int latency); |
Sham Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 51 | |
| 52 | Visualizer::GetOnlyParameters::Measurement getVsMeasurement() const { return mMeasurement; } |
Shunkai Yao | e39cd36 | 2022-12-22 00:23:34 +0000 | [diff] [blame] | 53 | std::vector<uint8_t> getVsCaptureSampleBuffer() const { return mCaptureSampleBuffer; } |
Sham Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 54 | |
| 55 | private: |
Shunkai Yao | e39cd36 | 2022-12-22 00:23:34 +0000 | [diff] [blame] | 56 | int mCaptureSize = kMaxCaptureSize; |
Sham Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 57 | Visualizer::ScalingMode mScalingMode = Visualizer::ScalingMode::NORMALIZED; |
| 58 | Visualizer::MeasurementMode mMeasurementMode = Visualizer::MeasurementMode::NONE; |
Sham Rathod | d7c6f32 | 2022-12-26 11:17:10 +0530 | [diff] [blame] | 59 | int mLatency = 0; |
Sham Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 60 | const Visualizer::GetOnlyParameters::Measurement mMeasurement = {0, 0}; |
Shunkai Yao | e39cd36 | 2022-12-22 00:23:34 +0000 | [diff] [blame] | 61 | std::vector<uint8_t> mCaptureSampleBuffer; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
Shunkai Yao | 6755d76 | 2022-11-02 00:21:02 +0000 | [diff] [blame] | 64 | class VisualizerSw final : public EffectImpl { |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 65 | public: |
Shunkai Yao | c12e082 | 2022-12-12 07:13:58 +0000 | [diff] [blame] | 66 | static const std::string kEffectName; |
| 67 | static const Visualizer::Capability kCapability; |
| 68 | static const Descriptor kDescriptor; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 69 | VisualizerSw() { LOG(DEBUG) << __func__; } |
| 70 | ~VisualizerSw() { |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 71 | cleanUp(); |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 72 | LOG(DEBUG) << __func__; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override; |
| 76 | ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) override; |
| 77 | ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, |
| 78 | Parameter::Specific* specific) override; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 79 | |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 80 | std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) override; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 81 | std::shared_ptr<EffectContext> getContext() override; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 82 | RetCode releaseContext() override; |
| 83 | |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 84 | IEffect::Status effectProcessImpl(float* in, float* out, int samples) override; |
| 85 | std::string getEffectName() override { return kEffectName; } |
| 86 | |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 87 | private: |
| 88 | std::shared_ptr<VisualizerSwContext> mContext; |
Sham Rathod | 94aae5e | 2022-11-23 12:22:32 +0530 | [diff] [blame] | 89 | |
| 90 | ndk::ScopedAStatus setSetOnlyParameterVisualizer(Visualizer::SetOnlyParameters setOnlyParam); |
| 91 | ndk::ScopedAStatus getParameterVisualizer(const Visualizer::Tag& tag, |
| 92 | Parameter::Specific* specific); |
| 93 | ndk::ScopedAStatus getGetOnlyParameterVisualizer(const Visualizer::GetOnlyParameters::Tag& tag, |
| 94 | Parameter::Specific* specific); |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 95 | }; |
| 96 | } // namespace aidl::android::hardware::audio::effect |