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> |
| 26 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 27 | #include "EffectConversionHelperAidl.h" |
| 28 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 29 | namespace android { |
| 30 | namespace effect { |
| 31 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 32 | class EffectHalAidl : public EffectHalInterface { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 33 | public: |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame^] | 34 | using StatusMQ = ::android::AidlMessageQueue< |
| 35 | ::aidl::android::hardware::audio::effect::IEffect::Status, |
| 36 | ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>; |
| 37 | using DataMQ = ::android::AidlMessageQueue< |
| 38 | float, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>; |
| 39 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 40 | // Set the input buffer. |
| 41 | status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer) override; |
| 42 | |
| 43 | // Set the output buffer. |
| 44 | status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer) override; |
| 45 | |
| 46 | // Effect process function. |
| 47 | status_t process() override; |
| 48 | |
| 49 | // Process reverse stream function. This function is used to pass |
| 50 | // a reference stream to the effect engine. |
| 51 | status_t processReverse() override; |
| 52 | |
| 53 | // Send a command and receive a response to/from effect engine. |
| 54 | status_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize, |
| 55 | void* pReplyData) override; |
| 56 | |
| 57 | // Returns the effect descriptor. |
| 58 | status_t getDescriptor(effect_descriptor_t *pDescriptor) override; |
| 59 | |
| 60 | // Free resources on the remote side. |
| 61 | status_t close() override; |
| 62 | |
| 63 | // Whether it's a local implementation. |
| 64 | bool isLocal() const override { return false; } |
| 65 | |
| 66 | status_t dump(int fd) override; |
| 67 | |
| 68 | uint64_t effectId() const override { return mEffectId; } |
| 69 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 70 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> getIEffect() const { |
| 71 | return mEffect; |
| 72 | } |
| 73 | |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame^] | 74 | // for TIME_CHECK |
| 75 | const std::string getClassName() const { return "EffectHalAidl"; } |
| 76 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 77 | private: |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 78 | friend class sp<EffectHalAidl>; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 79 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 80 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory; |
| 81 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 82 | const uint64_t mEffectId; |
| 83 | const int32_t mSessionId; |
| 84 | const int32_t mIoId; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 85 | const ::aidl::android::hardware::audio::effect::Descriptor mDesc; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 86 | std::unique_ptr<EffectConversionHelperAidl> mConversion; |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame^] | 87 | std::unique_ptr<StatusMQ> mStatusQ; |
| 88 | std::unique_ptr<DataMQ> mInputQ, mOutputQ; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 89 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 90 | sp<EffectBufferHalInterface> mInBuffer, mOutBuffer; |
| 91 | effect_config_t mConfig; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 92 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame] | 93 | status_t createAidlConversion( |
| 94 | std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect, |
| 95 | int32_t sessionId, int32_t ioId, |
| 96 | const ::aidl::android::hardware::audio::effect::Descriptor& desc); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 97 | // Can not be constructed directly by clients. |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 98 | EffectHalAidl( |
| 99 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory, |
| 100 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect, |
| 101 | uint64_t effectId, int32_t sessionId, int32_t ioId, |
| 102 | const ::aidl::android::hardware::audio::effect::Descriptor& desc); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 103 | bool setEffectReverse(bool reverse); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 104 | |
| 105 | // The destructor automatically releases the effect. |
| 106 | virtual ~EffectHalAidl(); |
| 107 | }; |
| 108 | |
| 109 | } // namespace effect |
| 110 | } // namespace android |