blob: 8966363ac7995942612f7d432f39f0529a614693 [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
Shunkai Yao51202502022-12-12 06:11:46 +000035 // Set the input buffer.
36 status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer) override;
37
38 // Set the output buffer.
39 status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer) override;
40
41 // Effect process function.
42 status_t process() override;
43
44 // Process reverse stream function. This function is used to pass
45 // a reference stream to the effect engine.
46 status_t processReverse() override;
47
48 // Send a command and receive a response to/from effect engine.
49 status_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize,
50 void* pReplyData) override;
51
52 // Returns the effect descriptor.
53 status_t getDescriptor(effect_descriptor_t *pDescriptor) override;
54
55 // Free resources on the remote side.
56 status_t close() override;
57
58 // Whether it's a local implementation.
59 bool isLocal() const override { return false; }
60
61 status_t dump(int fd) override;
62
63 uint64_t effectId() const override { return mEffectId; }
64
Shunkai Yao284bb0d2023-01-10 00:42:36 +000065 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> getIEffect() const {
66 return mEffect;
67 }
68
Shunkai Yaoc6308712023-02-22 17:53:04 +000069 // for TIME_CHECK
70 const std::string getClassName() const { return "EffectHalAidl"; }
71
Shunkai Yao51202502022-12-12 06:11:46 +000072 private:
Shunkai Yao284bb0d2023-01-10 00:42:36 +000073 friend class sp<EffectHalAidl>;
Shunkai Yao51202502022-12-12 06:11:46 +000074
Shunkai Yao44bdbad2023-01-14 05:11:58 +000075 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory;
76 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect;
Shunkai Yao51202502022-12-12 06:11:46 +000077 const uint64_t mEffectId;
78 const int32_t mSessionId;
79 const int32_t mIoId;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000080 const ::aidl::android::hardware::audio::effect::Descriptor mDesc;
Shunkai Yao5c718342023-02-23 23:49:51 +000081 const bool mIsProxyEffect;
82
Shunkai Yaodba8ba32023-01-27 17:02:21 +000083 std::unique_ptr<EffectConversionHelperAidl> mConversion;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000084
Shunkai Yao51202502022-12-12 06:11:46 +000085 sp<EffectBufferHalInterface> mInBuffer, mOutBuffer;
Shunkai Yao51202502022-12-12 06:11:46 +000086
Shunkai Yaodba8ba32023-01-27 17:02:21 +000087 status_t createAidlConversion(
88 std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect,
89 int32_t sessionId, int32_t ioId,
90 const ::aidl::android::hardware::audio::effect::Descriptor& desc);
Shunkai Yao51202502022-12-12 06:11:46 +000091 // Can not be constructed directly by clients.
Shunkai Yao44bdbad2023-01-14 05:11:58 +000092 EffectHalAidl(
93 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory,
94 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect,
95 uint64_t effectId, int32_t sessionId, int32_t ioId,
Shunkai Yao5c718342023-02-23 23:49:51 +000096 const ::aidl::android::hardware::audio::effect::Descriptor& desc,
97 bool isProxyEffect);
Shunkai Yao284bb0d2023-01-10 00:42:36 +000098 bool setEffectReverse(bool reverse);
Shunkai Yao5c718342023-02-23 23:49:51 +000099 bool needUpdateReturnParam(uint32_t cmdCode);
Shunkai Yao51202502022-12-12 06:11:46 +0000100
101 // The destructor automatically releases the effect.
102 virtual ~EffectHalAidl();
103};
104
105} // namespace effect
106} // namespace android