blob: 1b7a3d61666ac3a91160197d91ea6013ed73317e [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
Shunkai Yao51202502022-12-12 06:11:46 +000059 status_t dump(int fd) override;
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 Yaoc6308712023-02-22 17:53:04 +000065 // for TIME_CHECK
66 const std::string getClassName() const { return "EffectHalAidl"; }
67
Shunkai Yao51202502022-12-12 06:11:46 +000068 private:
Shunkai Yao284bb0d2023-01-10 00:42:36 +000069 friend class sp<EffectHalAidl>;
Shunkai Yao51202502022-12-12 06:11:46 +000070
Shunkai Yao44bdbad2023-01-14 05:11:58 +000071 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory;
72 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect;
Shunkai Yao51202502022-12-12 06:11:46 +000073 const int32_t mSessionId;
74 const int32_t mIoId;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000075 const ::aidl::android::hardware::audio::effect::Descriptor mDesc;
Shunkai Yao5c718342023-02-23 23:49:51 +000076 const bool mIsProxyEffect;
77
Shunkai Yaodba8ba32023-01-27 17:02:21 +000078 std::unique_ptr<EffectConversionHelperAidl> mConversion;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000079
Shunkai Yao51202502022-12-12 06:11:46 +000080 sp<EffectBufferHalInterface> mInBuffer, mOutBuffer;
Shunkai Yao51202502022-12-12 06:11:46 +000081
Shunkai Yaodba8ba32023-01-27 17:02:21 +000082 status_t createAidlConversion(
83 std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect,
84 int32_t sessionId, int32_t ioId,
85 const ::aidl::android::hardware::audio::effect::Descriptor& desc);
Shunkai Yao51202502022-12-12 06:11:46 +000086 // Can not be constructed directly by clients.
Shunkai Yao44bdbad2023-01-14 05:11:58 +000087 EffectHalAidl(
88 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory,
89 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect,
Mikhail Naganov89c22e42023-06-14 15:49:59 -070090 int32_t sessionId, int32_t ioId,
Shunkai Yao5c718342023-02-23 23:49:51 +000091 const ::aidl::android::hardware::audio::effect::Descriptor& desc,
92 bool isProxyEffect);
Shunkai Yao284bb0d2023-01-10 00:42:36 +000093 bool setEffectReverse(bool reverse);
Shunkai Yao5c718342023-02-23 23:49:51 +000094 bool needUpdateReturnParam(uint32_t cmdCode);
Shunkai Yao51202502022-12-12 06:11:46 +000095
96 // The destructor automatically releases the effect.
97 virtual ~EffectHalAidl();
98};
99
100} // namespace effect
101} // namespace android