blob: 47049d7775660ac6ce329848176748227c8eb755 [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>
Shunkai Yaofb79da92023-04-10 17:09:57 +000026#include <system/audio_effects/aidl_effects_utils.h>
Shunkai Yao51202502022-12-12 06:11:46 +000027
Shunkai Yao284bb0d2023-01-10 00:42:36 +000028#include "EffectConversionHelperAidl.h"
29
Shunkai Yao51202502022-12-12 06:11:46 +000030namespace android {
31namespace effect {
32
Shunkai Yaodba8ba32023-01-27 17:02:21 +000033class EffectHalAidl : public EffectHalInterface {
Shunkai Yao51202502022-12-12 06:11:46 +000034 public:
Shunkai Yaoc6308712023-02-22 17:53:04 +000035
Shunkai Yao51202502022-12-12 06:11:46 +000036 // Set the input buffer.
37 status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer) override;
38
39 // Set the output buffer.
40 status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer) override;
41
42 // Effect process function.
43 status_t process() override;
44
45 // Process reverse stream function. This function is used to pass
46 // a reference stream to the effect engine.
47 status_t processReverse() override;
48
49 // Send a command and receive a response to/from effect engine.
50 status_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize,
51 void* pReplyData) override;
52
53 // Returns the effect descriptor.
54 status_t getDescriptor(effect_descriptor_t *pDescriptor) override;
55
56 // Free resources on the remote side.
57 status_t close() override;
58
59 // Whether it's a local implementation.
60 bool isLocal() const override { return false; }
61
62 status_t dump(int fd) override;
63
64 uint64_t effectId() const override { return mEffectId; }
65
Shunkai Yao284bb0d2023-01-10 00:42:36 +000066 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> getIEffect() const {
67 return mEffect;
68 }
69
Shunkai Yaoc6308712023-02-22 17:53:04 +000070 // for TIME_CHECK
71 const std::string getClassName() const { return "EffectHalAidl"; }
72
Shunkai Yao51202502022-12-12 06:11:46 +000073 private:
Shunkai Yao284bb0d2023-01-10 00:42:36 +000074 friend class sp<EffectHalAidl>;
Shunkai Yao51202502022-12-12 06:11:46 +000075
Shunkai Yao44bdbad2023-01-14 05:11:58 +000076 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory;
77 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect;
Shunkai Yao51202502022-12-12 06:11:46 +000078 const uint64_t mEffectId;
79 const int32_t mSessionId;
80 const int32_t mIoId;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000081 const ::aidl::android::hardware::audio::effect::Descriptor mDesc;
Shunkai Yao5c718342023-02-23 23:49:51 +000082 const bool mIsProxyEffect;
83
Shunkai Yaodba8ba32023-01-27 17:02:21 +000084 std::unique_ptr<EffectConversionHelperAidl> mConversion;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000085
Shunkai Yao51202502022-12-12 06:11:46 +000086 sp<EffectBufferHalInterface> mInBuffer, mOutBuffer;
Shunkai Yao51202502022-12-12 06:11:46 +000087
Shunkai Yaodba8ba32023-01-27 17:02:21 +000088 status_t createAidlConversion(
89 std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect,
90 int32_t sessionId, int32_t ioId,
91 const ::aidl::android::hardware::audio::effect::Descriptor& desc);
Shunkai Yao51202502022-12-12 06:11:46 +000092 // Can not be constructed directly by clients.
Shunkai Yao44bdbad2023-01-14 05:11:58 +000093 EffectHalAidl(
94 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory,
95 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect,
96 uint64_t effectId, int32_t sessionId, int32_t ioId,
Shunkai Yao5c718342023-02-23 23:49:51 +000097 const ::aidl::android::hardware::audio::effect::Descriptor& desc,
98 bool isProxyEffect);
Shunkai Yao284bb0d2023-01-10 00:42:36 +000099 bool setEffectReverse(bool reverse);
Shunkai Yao5c718342023-02-23 23:49:51 +0000100 bool needUpdateReturnParam(uint32_t cmdCode);
Shunkai Yao51202502022-12-12 06:11:46 +0000101
102 // The destructor automatically releases the effect.
103 virtual ~EffectHalAidl();
104};
105
106} // namespace effect
107} // namespace android