blob: a775337d8614a5d53375b13955c23f0f3f718093 [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 Yao5c718342023-02-23 23:49:51 +000075 const bool mIsProxyEffect;
Shunkai Yaob82d0d62024-09-17 17:57:39 +000076 const int32_t mHalVersion;
77 // Audio effect HAL v2+ changes flag to kEventFlagDataMqNotEmpty to avoid conflict from using
78 // kEventFlagNotEmpty
79 const uint32_t mEventFlagDataMqNotEmpty;
Shunkai Yao57b93392024-04-26 04:12:21 +000080 bool mIsHapticGenerator = false;
Shunkai Yao688613e2024-09-12 23:57:55 +000081 std::string mEffectName;
Shunkai Yao5c718342023-02-23 23:49:51 +000082
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,
Mikhail Naganov89c22e42023-06-14 15:49:59 -070095 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
Shunkai Yao688613e2024-09-12 23:57:55 +0000101 status_t maybeReopen(const std::shared_ptr<android::hardware::EventFlag>& efGroup) const;
102 void writeHapticGeneratorData(size_t totalSamples, float* const outputRawBuffer,
103 float* const fmqOutputBuffer) const;
104 size_t writeToHalInputFmqAndSignal(
105 const std::shared_ptr<android::hardware::EventFlag>& efGroup) const;
106 status_t waitHalStatusFmq(size_t samplesWritten) const;
107 status_t readFromHalOutputFmq(size_t samplesWritten) const;
108
Shunkai Yao51202502022-12-12 06:11:46 +0000109 // The destructor automatically releases the effect.
110 virtual ~EffectHalAidl();
111};
112
113} // namespace effect
114} // namespace android