blob: 6a1ec1c185616d05ce64b66a8d8e3f3a7af9eafe [file] [log] [blame]
Shunkai Yao51202502022-12-12 06:11:46 +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/IEffect.h>
Shunkai Yao44bdbad2023-01-14 05:11:58 +000020#include <aidl/android/hardware/audio/effect/IFactory.h>
Shunkai Yao51202502022-12-12 06:11:46 +000021#include <media/audiohal/EffectHalInterface.h>
22#include <system/audio_effect.h>
23
Shunkai Yao284bb0d2023-01-10 00:42:36 +000024#include "EffectConversionHelperAidl.h"
25
Shunkai Yao51202502022-12-12 06:11:46 +000026namespace android {
27namespace effect {
28
Shunkai Yao284bb0d2023-01-10 00:42:36 +000029class EffectHalAidl : public EffectHalInterface, public EffectConversionHelperAidl {
Shunkai Yao51202502022-12-12 06:11:46 +000030 public:
31 // Set the input buffer.
32 status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer) override;
33
34 // Set the output buffer.
35 status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer) override;
36
37 // Effect process function.
38 status_t process() override;
39
40 // Process reverse stream function. This function is used to pass
41 // a reference stream to the effect engine.
42 status_t processReverse() override;
43
44 // Send a command and receive a response to/from effect engine.
45 status_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize,
46 void* pReplyData) override;
47
48 // Returns the effect descriptor.
49 status_t getDescriptor(effect_descriptor_t *pDescriptor) override;
50
51 // Free resources on the remote side.
52 status_t close() override;
53
54 // Whether it's a local implementation.
55 bool isLocal() const override { return false; }
56
57 status_t dump(int fd) override;
58
59 uint64_t effectId() const override { return mEffectId; }
60
Shunkai Yao284bb0d2023-01-10 00:42:36 +000061 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> getIEffect() const {
62 return mEffect;
63 }
64
Shunkai Yao51202502022-12-12 06:11:46 +000065 private:
Shunkai Yao284bb0d2023-01-10 00:42:36 +000066 friend class sp<EffectHalAidl>;
Shunkai Yao51202502022-12-12 06:11:46 +000067
Shunkai Yao44bdbad2023-01-14 05:11:58 +000068 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory;
69 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect;
Shunkai Yao51202502022-12-12 06:11:46 +000070 const uint64_t mEffectId;
71 const int32_t mSessionId;
72 const int32_t mIoId;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000073 const ::aidl::android::hardware::audio::effect::Descriptor mDesc;
74
Shunkai Yao51202502022-12-12 06:11:46 +000075 sp<EffectBufferHalInterface> mInBuffer, mOutBuffer;
76 effect_config_t mConfig;
Shunkai Yao51202502022-12-12 06:11:46 +000077
78 // Can not be constructed directly by clients.
Shunkai Yao44bdbad2023-01-14 05:11:58 +000079 EffectHalAidl(
80 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory,
81 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect,
82 uint64_t effectId, int32_t sessionId, int32_t ioId,
83 const ::aidl::android::hardware::audio::effect::Descriptor& desc);
Shunkai Yao284bb0d2023-01-10 00:42:36 +000084 bool setEffectReverse(bool reverse);
Shunkai Yao51202502022-12-12 06:11:46 +000085
86 // The destructor automatically releases the effect.
87 virtual ~EffectHalAidl();
88};
89
90} // namespace effect
91} // namespace android