Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 1 | /* |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 2 | * Copyright (C) 2023 The Android Open Source Project |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 3 | * |
| 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 Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 19 | #include <memory> |
| 20 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 21 | #include <aidl/android/hardware/audio/effect/IEffect.h> |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 22 | #include <aidl/android/hardware/audio/effect/IFactory.h> |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 23 | #include <fmq/AidlMessageQueue.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 24 | #include <media/audiohal/EffectHalInterface.h> |
| 25 | #include <system/audio_effect.h> |
Shunkai Yao | fb79da9 | 2023-04-10 17:09:57 +0000 | [diff] [blame] | 26 | #include <system/audio_effects/aidl_effects_utils.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 27 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 28 | #include "EffectConversionHelperAidl.h" |
| 29 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 30 | namespace android { |
| 31 | namespace effect { |
| 32 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 33 | class EffectHalAidl : public EffectHalInterface { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 34 | public: |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 35 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 36 | // 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 Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 59 | status_t dump(int fd) override; |
| 60 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 61 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> getIEffect() const { |
| 62 | return mEffect; |
| 63 | } |
| 64 | |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 65 | // for TIME_CHECK |
| 66 | const std::string getClassName() const { return "EffectHalAidl"; } |
| 67 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 68 | private: |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 69 | friend class sp<EffectHalAidl>; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 70 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 71 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory; |
| 72 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 73 | const int32_t mSessionId; |
| 74 | const int32_t mIoId; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 75 | const bool mIsProxyEffect; |
Shunkai Yao | b82d0d6 | 2024-09-17 17:57:39 +0000 | [diff] [blame] | 76 | 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 Yao | 57b9339 | 2024-04-26 04:12:21 +0000 | [diff] [blame] | 80 | bool mIsHapticGenerator = false; |
Shunkai Yao | 688613e | 2024-09-12 23:57:55 +0000 | [diff] [blame] | 81 | std::string mEffectName; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 82 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 83 | std::unique_ptr<EffectConversionHelperAidl> mConversion; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 84 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 85 | sp<EffectBufferHalInterface> mInBuffer, mOutBuffer; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 86 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 87 | 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 Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 91 | // Can not be constructed directly by clients. |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 92 | 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 Naganov | 89c22e4 | 2023-06-14 15:49:59 -0700 | [diff] [blame] | 95 | int32_t sessionId, int32_t ioId, |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 96 | const ::aidl::android::hardware::audio::effect::Descriptor& desc, |
| 97 | bool isProxyEffect); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 98 | bool setEffectReverse(bool reverse); |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame] | 99 | bool needUpdateReturnParam(uint32_t cmdCode); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 100 | |
Shunkai Yao | 688613e | 2024-09-12 23:57:55 +0000 | [diff] [blame] | 101 | 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 Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 109 | // The destructor automatically releases the effect. |
| 110 | virtual ~EffectHalAidl(); |
| 111 | }; |
| 112 | |
| 113 | } // namespace effect |
| 114 | } // namespace android |