blob: 83b644bc331a5eaf942fdb0a6242a09b512c7a0d [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
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>
Shunkai Yaodba8ba32023-01-27 17:02:21 +000023#include <memory>
Shunkai Yao51202502022-12-12 06:11:46 +000024
Shunkai Yao284bb0d2023-01-10 00:42:36 +000025#include "EffectConversionHelperAidl.h"
26
Shunkai Yao51202502022-12-12 06:11:46 +000027namespace android {
28namespace effect {
29
Shunkai Yaodba8ba32023-01-27 17:02:21 +000030class EffectHalAidl : public EffectHalInterface {
Shunkai Yao51202502022-12-12 06:11:46 +000031 public:
32 // Set the input buffer.
33 status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer) override;
34
35 // Set the output buffer.
36 status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer) override;
37
38 // Effect process function.
39 status_t process() override;
40
41 // Process reverse stream function. This function is used to pass
42 // a reference stream to the effect engine.
43 status_t processReverse() override;
44
45 // Send a command and receive a response to/from effect engine.
46 status_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize,
47 void* pReplyData) override;
48
49 // Returns the effect descriptor.
50 status_t getDescriptor(effect_descriptor_t *pDescriptor) override;
51
52 // Free resources on the remote side.
53 status_t close() override;
54
55 // Whether it's a local implementation.
56 bool isLocal() const override { return false; }
57
58 status_t dump(int fd) override;
59
60 uint64_t effectId() const override { return mEffectId; }
61
Shunkai Yao284bb0d2023-01-10 00:42:36 +000062 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> getIEffect() const {
63 return mEffect;
64 }
65
Shunkai Yao51202502022-12-12 06:11:46 +000066 private:
Shunkai Yao284bb0d2023-01-10 00:42:36 +000067 friend class sp<EffectHalAidl>;
Shunkai Yao51202502022-12-12 06:11:46 +000068
Shunkai Yao44bdbad2023-01-14 05:11:58 +000069 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory;
70 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect;
Shunkai Yao51202502022-12-12 06:11:46 +000071 const uint64_t mEffectId;
72 const int32_t mSessionId;
73 const int32_t mIoId;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000074 const ::aidl::android::hardware::audio::effect::Descriptor mDesc;
Shunkai Yaodba8ba32023-01-27 17:02:21 +000075 std::unique_ptr<EffectConversionHelperAidl> mConversion;
Shunkai Yao284bb0d2023-01-10 00:42:36 +000076
Shunkai Yao51202502022-12-12 06:11:46 +000077 sp<EffectBufferHalInterface> mInBuffer, mOutBuffer;
78 effect_config_t mConfig;
Shunkai Yao51202502022-12-12 06:11:46 +000079
Shunkai Yaodba8ba32023-01-27 17:02:21 +000080 status_t createAidlConversion(
81 std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect,
82 int32_t sessionId, int32_t ioId,
83 const ::aidl::android::hardware::audio::effect::Descriptor& desc);
Shunkai Yao51202502022-12-12 06:11:46 +000084 // Can not be constructed directly by clients.
Shunkai Yao44bdbad2023-01-14 05:11:58 +000085 EffectHalAidl(
86 const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory,
87 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect,
88 uint64_t effectId, int32_t sessionId, int32_t ioId,
89 const ::aidl::android::hardware::audio::effect::Descriptor& desc);
Shunkai Yao284bb0d2023-01-10 00:42:36 +000090 bool setEffectReverse(bool reverse);
Shunkai Yao51202502022-12-12 06:11:46 +000091
92 // The destructor automatically releases the effect.
93 virtual ~EffectHalAidl();
94};
95
96} // namespace effect
97} // namespace android