blob: 194150dc0f2f7af0db62055df96e1949bd86bc6f [file] [log] [blame]
Shunkai Yao51202502022-12-12 06:11:46 +00001/*
Shunkai Yaodba8ba32023-01-27 17:02:21 +00002 * Copyright (C) 2023 The Android Open Source Project
Shunkai Yao51202502022-12-12 06:11:46 +00003 *
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
Shunkai Yaoc6308712023-02-22 17:53:04 +000019#include <memory>
20
Shunkai Yao51202502022-12-12 06:11:46 +000021#include <aidl/android/hardware/audio/effect/IEffect.h>
Shunkai Yao44bdbad2023-01-14 05:11:58 +000022#include <aidl/android/hardware/audio/effect/IFactory.h>
Shunkai Yaoc6308712023-02-22 17:53:04 +000023#include <fmq/AidlMessageQueue.h>
Shunkai Yao51202502022-12-12 06:11:46 +000024#include <media/audiohal/EffectHalInterface.h>
25#include <system/audio_effect.h>
26
Shunkai Yao284bb0d2023-01-10 00:42:36 +000027#include "EffectConversionHelperAidl.h"
28
Shunkai Yao51202502022-12-12 06:11:46 +000029namespace android {
30namespace effect {
31
Shunkai Yaodba8ba32023-01-27 17:02:21 +000032class EffectHalAidl : public EffectHalInterface {
Shunkai Yao51202502022-12-12 06:11:46 +000033 public:
Shunkai Yaoc6308712023-02-22 17:53:04 +000034 using StatusMQ = ::android::AidlMessageQueue<
35 ::aidl::android::hardware::audio::effect::IEffect::Status,
36 ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>;
37 using DataMQ = ::android::AidlMessageQueue<
38 float, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>;
39
Shunkai Yao51202502022-12-12 06:11:46 +000040 // Set the input buffer.
41 status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer) override;
42
43 // Set the output buffer.
44 status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer) override;
45
46 // Effect process function.
47 status_t process() override;
48
49 // Process reverse stream function. This function is used to pass
50 // a reference stream to the effect engine.
51 status_t processReverse() override;
52
53 // Send a command and receive a response to/from effect engine.
54 status_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize,
55 void* pReplyData) override;
56
57 // Returns the effect descriptor.
58 status_t getDescriptor(effect_descriptor_t *pDescriptor) override;
59
60 // Free resources on the remote side.
61 status_t close() override;
62
63 // Whether it's a local implementation.
64 bool isLocal() const override { return false; }
65
66 status_t dump(int fd) override;
67
68 uint64_t effectId() const override { return mEffectId; }
69
Shunkai Yao284bb0d2023-01-10 00:42:36 +000070 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> getIEffect() const {
71 return mEffect;
72 }
73
Shunkai Yaoc6308712023-02-22 17:53:04 +000074 // for TIME_CHECK
75 const std::string getClassName() const { return "EffectHalAidl"; }
76
Shunkai Yao51202502022-12-12 06:11:46 +000077 private:
Shunkai Yao284bb0d2023-01-10 00:42:36 +000078 friend class sp<EffectHalAidl>;
Shunkai Yao51202502022-12-12 06:11:46 +000079
Shunkai Yao44bdbad2023-01-14 05:11:58 +000080 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory;
81 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect;
Shunkai Yao51202502022-12-12 06:11:46 +000082 const uint64_t mEffectId;
83 const int32_t mSessionId;
84 const int32_t mIoId;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000085 const ::aidl::android::hardware::audio::effect::Descriptor mDesc;
Shunkai Yaodba8ba32023-01-27 17:02:21 +000086 std::unique_ptr<EffectConversionHelperAidl> mConversion;
Shunkai Yaoc6308712023-02-22 17:53:04 +000087 std::unique_ptr<StatusMQ> mStatusQ;
88 std::unique_ptr<DataMQ> mInputQ, mOutputQ;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000089
Shunkai Yao51202502022-12-12 06:11:46 +000090 sp<EffectBufferHalInterface> mInBuffer, mOutBuffer;
91 effect_config_t mConfig;
Shunkai Yao51202502022-12-12 06:11:46 +000092
Shunkai Yaodba8ba32023-01-27 17:02:21 +000093 status_t createAidlConversion(
94 std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect,
95 int32_t sessionId, int32_t ioId,
96 const ::aidl::android::hardware::audio::effect::Descriptor& desc);
Shunkai Yao51202502022-12-12 06:11:46 +000097 // Can not be constructed directly by clients.
Shunkai Yao44bdbad2023-01-14 05:11:58 +000098 EffectHalAidl(
99 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory,
100 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect,
101 uint64_t effectId, int32_t sessionId, int32_t ioId,
102 const ::aidl::android::hardware::audio::effect::Descriptor& desc);
Shunkai Yao284bb0d2023-01-10 00:42:36 +0000103 bool setEffectReverse(bool reverse);
Shunkai Yao51202502022-12-12 06:11:46 +0000104
105 // The destructor automatically releases the effect.
106 virtual ~EffectHalAidl();
107};
108
109} // namespace effect
110} // namespace android