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 |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 18 | #include <cstdlib> |
| 19 | #include <memory> |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 20 | |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 21 | #include <aidl/android/hardware/audio/effect/BnEffect.h> |
| 22 | #include <fmq/AidlMessageQueue.h> |
| 23 | |
| 24 | #include "EffectContext.h" |
| 25 | #include "EffectThread.h" |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 26 | #include "EffectTypes.h" |
| 27 | #include "effect-impl/EffectContext.h" |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 28 | #include "effect-impl/EffectThread.h" |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 29 | #include "effect-impl/EffectTypes.h" |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 30 | |
| 31 | namespace aidl::android::hardware::audio::effect { |
| 32 | |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 33 | class EffectImpl : public BnEffect, public EffectThread { |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 34 | public: |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 35 | EffectImpl() = default; |
| 36 | virtual ~EffectImpl() = default; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 37 | |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 38 | virtual ndk::ScopedAStatus open(const Parameter::Common& common, |
| 39 | const std::optional<Parameter::Specific>& specific, |
| 40 | OpenEffectReturn* ret) override; |
| 41 | virtual ndk::ScopedAStatus close() override; |
| 42 | virtual ndk::ScopedAStatus command(CommandId id) override; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 43 | |
| 44 | virtual ndk::ScopedAStatus getState(State* state) override; |
| 45 | virtual ndk::ScopedAStatus setParameter(const Parameter& param) override; |
| 46 | virtual ndk::ScopedAStatus getParameter(const Parameter::Id& id, Parameter* param) override; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 47 | |
| 48 | virtual ndk::ScopedAStatus setParameterCommon(const Parameter& param); |
| 49 | virtual ndk::ScopedAStatus getParameterCommon(const Parameter::Tag& tag, Parameter* param); |
| 50 | |
| 51 | /* Methods MUST be implemented by each effect instances */ |
| 52 | virtual ndk::ScopedAStatus getDescriptor(Descriptor* desc) = 0; |
| 53 | virtual ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) = 0; |
| 54 | virtual ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id, |
| 55 | Parameter::Specific* specific) = 0; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 56 | |
| 57 | virtual std::string getEffectName() = 0; |
| 58 | virtual IEffect::Status effectProcessImpl(float* in, float* out, int samples) override; |
| 59 | |
| 60 | /** |
| 61 | * Effect context methods must be implemented by each effect. |
| 62 | * Each effect can derive from EffectContext and define its own context, but must upcast to |
| 63 | * EffectContext for EffectImpl to use. |
| 64 | */ |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 65 | virtual std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) = 0; |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 66 | virtual std::shared_ptr<EffectContext> getContext() = 0; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 67 | virtual RetCode releaseContext() = 0; |
| 68 | |
| 69 | protected: |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 70 | State mState = State::INIT; |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 71 | |
| 72 | IEffect::Status status(binder_status_t status, size_t consumed, size_t produced); |
Shunkai Yao | 812d5b4 | 2022-11-16 18:08:50 +0000 | [diff] [blame] | 73 | void cleanUp(); |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 74 | |
Shraddha Basantwani | f627d80 | 2022-11-08 14:45:07 +0530 | [diff] [blame] | 75 | /** |
| 76 | * Optional CommandId handling methods for effects to override. |
| 77 | * For CommandId::START, EffectImpl call commandImpl before starting the EffectThread |
| 78 | * processing. |
| 79 | * For CommandId::STOP and CommandId::RESET, EffectImpl call commandImpl after stop the |
| 80 | * EffectThread processing. |
| 81 | */ |
| 82 | virtual ndk::ScopedAStatus commandImpl(CommandId id); |
Shunkai Yao | 6afc855 | 2022-10-26 22:47:20 +0000 | [diff] [blame] | 83 | }; |
| 84 | } // namespace aidl::android::hardware::audio::effect |