blob: 58ad1dee1d4e0c0ab47dae5290ed953080a79967 [file] [log] [blame]
Shunkai Yaoea24c1a2022-09-28 17:39:23 +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>
20#include <fmq/AidlMessageQueue.h>
21#include <cstdlib>
22#include <memory>
23
24#include "effect-impl/EffectThread.h"
25
26namespace aidl::android::hardware::audio::effect {
27
28class EqualizerSwWorker : public EffectThread {
29 // EqualizerSwWorker(const std::string name){EffectThread(name)};
30 void process() override;
31};
32
33class EqualizerSw : public BnEffect {
34 public:
35 EqualizerSw() {
36 // create the worker
37 mWorker = std::make_unique<EqualizerSwWorker>();
38 LOG(DEBUG) << __func__;
39 };
40 ~EqualizerSw() {
41 cleanUp();
42 LOG(DEBUG) << __func__;
43 };
44 ndk::ScopedAStatus open(const Parameter::Common& common, const Parameter::Specific& specific,
45 OpenEffectReturn* _aidl_return) override;
46 ndk::ScopedAStatus close() override;
47 ndk::ScopedAStatus getDescriptor(Descriptor* _aidl_return) override;
48
49 ndk::ScopedAStatus getState(State* _aidl_return) override;
50 ndk::ScopedAStatus command(CommandId in_commandId) override;
51 ndk::ScopedAStatus setParameter(const Parameter& in_param) override;
52 ndk::ScopedAStatus getParameter(const Parameter::Id& in_paramId,
53 Parameter* _aidl_return) override;
54
55 private:
56 // effect processing thread.
57 std::unique_ptr<EqualizerSwWorker> mWorker;
58 // Effect descriptor.
59 const Descriptor mDesc = {
60 .common = {.id = {.type = EqualizerTypeUUID, .uuid = EqualizerSwImplUUID}}};
61
62 // Parameters.
63 Parameter::Common mCommonParam;
64 Equalizer mEqualizerParam; // TODO: the equalizer parameter needs to update
65
66 // Instance state INIT by default.
67 State mState = State::INIT;
68
69 typedef ::android::AidlMessageQueue<
70 Status, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>
71 StatusMQ;
72 typedef ::android::AidlMessageQueue<
73 int8_t, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>
74 DataMQ;
75
76 std::unique_ptr<StatusMQ> mStatusMQ;
77 std::unique_ptr<DataMQ> mInputMQ;
78 std::unique_ptr<DataMQ> mOutputMQ;
79
80 ndk::ScopedAStatus setCommonParameter(const Parameter::Common& common_param);
81 ndk::ScopedAStatus setSpecificParameter(const Parameter::Specific& specific);
82 bool createFmq(int statusDepth, int inBufferSize, int outBufferSize, OpenEffectReturn* ret);
83 void destroyFmq();
84 void cleanUp();
85};
86} // namespace aidl::android::hardware::audio::effect