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 | |
| 19 | #include <aidl/android/hardware/audio/effect/IEffect.h> |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 20 | #include <aidl/android/hardware/audio/effect/IFactory.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 21 | #include <media/audiohal/EffectHalInterface.h> |
| 22 | #include <system/audio_effect.h> |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 23 | #include <memory> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 24 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 25 | #include "EffectConversionHelperAidl.h" |
| 26 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace effect { |
| 29 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 30 | class EffectHalAidl : public EffectHalInterface { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 31 | 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 Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 62 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> getIEffect() const { |
| 63 | return mEffect; |
| 64 | } |
| 65 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 66 | private: |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 67 | friend class sp<EffectHalAidl>; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 68 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 69 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory; |
| 70 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 71 | const uint64_t mEffectId; |
| 72 | const int32_t mSessionId; |
| 73 | const int32_t mIoId; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 74 | const ::aidl::android::hardware::audio::effect::Descriptor mDesc; |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 75 | std::unique_ptr<EffectConversionHelperAidl> mConversion; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 76 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 77 | sp<EffectBufferHalInterface> mInBuffer, mOutBuffer; |
| 78 | effect_config_t mConfig; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 79 | |
Shunkai Yao | dba8ba3 | 2023-01-27 17:02:21 +0000 | [diff] [blame^] | 80 | 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 Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 84 | // Can not be constructed directly by clients. |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 85 | 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 Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 90 | bool setEffectReverse(bool reverse); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 91 | |
| 92 | // The destructor automatically releases the effect. |
| 93 | virtual ~EffectHalAidl(); |
| 94 | }; |
| 95 | |
| 96 | } // namespace effect |
| 97 | } // namespace android |