blob: e7d081f6fc7124b49f531929ad792810ac8e8fd4 [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
Shunkai Yao6afc8552022-10-26 22:47:20 +000018#include <cstdlib>
19#include <memory>
Shunkai Yao6afc8552022-10-26 22:47:20 +000020
Shraddha Basantwanif627d802022-11-08 14:45:07 +053021#include <aidl/android/hardware/audio/effect/BnEffect.h>
22#include <fmq/AidlMessageQueue.h>
23
24#include "EffectContext.h"
25#include "EffectThread.h"
Shunkai Yao6afc8552022-10-26 22:47:20 +000026#include "EffectTypes.h"
27#include "effect-impl/EffectContext.h"
Shraddha Basantwanif627d802022-11-08 14:45:07 +053028#include "effect-impl/EffectThread.h"
Shunkai Yao6afc8552022-10-26 22:47:20 +000029#include "effect-impl/EffectTypes.h"
Shunkai Yao6afc8552022-10-26 22:47:20 +000030
Shunkai Yaoc12e0822022-12-12 07:13:58 +000031extern "C" binder_exception_t destroyEffect(
32 const std::shared_ptr<aidl::android::hardware::audio::effect::IEffect>& instanceSp);
33
Shunkai Yao6afc8552022-10-26 22:47:20 +000034namespace aidl::android::hardware::audio::effect {
35
Shraddha Basantwanif627d802022-11-08 14:45:07 +053036class EffectImpl : public BnEffect, public EffectThread {
Shunkai Yao6afc8552022-10-26 22:47:20 +000037 public:
Shunkai Yao812d5b42022-11-16 18:08:50 +000038 EffectImpl() = default;
39 virtual ~EffectImpl() = default;
Shunkai Yao6afc8552022-10-26 22:47:20 +000040
Shunkai Yao6afc8552022-10-26 22:47:20 +000041 virtual ndk::ScopedAStatus open(const Parameter::Common& common,
42 const std::optional<Parameter::Specific>& specific,
43 OpenEffectReturn* ret) override;
44 virtual ndk::ScopedAStatus close() override;
45 virtual ndk::ScopedAStatus command(CommandId id) override;
Shunkai Yao6afc8552022-10-26 22:47:20 +000046
47 virtual ndk::ScopedAStatus getState(State* state) override;
48 virtual ndk::ScopedAStatus setParameter(const Parameter& param) override;
49 virtual ndk::ScopedAStatus getParameter(const Parameter::Id& id, Parameter* param) override;
Shunkai Yao6afc8552022-10-26 22:47:20 +000050
51 virtual ndk::ScopedAStatus setParameterCommon(const Parameter& param);
52 virtual ndk::ScopedAStatus getParameterCommon(const Parameter::Tag& tag, Parameter* param);
53
54 /* Methods MUST be implemented by each effect instances */
55 virtual ndk::ScopedAStatus getDescriptor(Descriptor* desc) = 0;
56 virtual ndk::ScopedAStatus setParameterSpecific(const Parameter::Specific& specific) = 0;
57 virtual ndk::ScopedAStatus getParameterSpecific(const Parameter::Id& id,
58 Parameter::Specific* specific) = 0;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053059
60 virtual std::string getEffectName() = 0;
61 virtual IEffect::Status effectProcessImpl(float* in, float* out, int samples) override;
62
63 /**
64 * Effect context methods must be implemented by each effect.
65 * Each effect can derive from EffectContext and define its own context, but must upcast to
66 * EffectContext for EffectImpl to use.
67 */
Shunkai Yao6afc8552022-10-26 22:47:20 +000068 virtual std::shared_ptr<EffectContext> createContext(const Parameter::Common& common) = 0;
Shraddha Basantwanif627d802022-11-08 14:45:07 +053069 virtual std::shared_ptr<EffectContext> getContext() = 0;
Shunkai Yao6afc8552022-10-26 22:47:20 +000070 virtual RetCode releaseContext() = 0;
71
72 protected:
Shraddha Basantwanif627d802022-11-08 14:45:07 +053073 State mState = State::INIT;
Shunkai Yao6afc8552022-10-26 22:47:20 +000074
75 IEffect::Status status(binder_status_t status, size_t consumed, size_t produced);
Shunkai Yao812d5b42022-11-16 18:08:50 +000076 void cleanUp();
Shunkai Yao6afc8552022-10-26 22:47:20 +000077
Shraddha Basantwanif627d802022-11-08 14:45:07 +053078 /**
79 * Optional CommandId handling methods for effects to override.
80 * For CommandId::START, EffectImpl call commandImpl before starting the EffectThread
81 * processing.
82 * For CommandId::STOP and CommandId::RESET, EffectImpl call commandImpl after stop the
83 * EffectThread processing.
84 */
85 virtual ndk::ScopedAStatus commandImpl(CommandId id);
Shunkai Yao6afc8552022-10-26 22:47:20 +000086};
87} // namespace aidl::android::hardware::audio::effect