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