Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 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> |
| 23 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 24 | #include "EffectConversionHelperAidl.h" |
| 25 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace effect { |
| 28 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 29 | class EffectHalAidl : public EffectHalInterface, public EffectConversionHelperAidl { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 30 | public: |
| 31 | // Set the input buffer. |
| 32 | status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer) override; |
| 33 | |
| 34 | // Set the output buffer. |
| 35 | status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer) override; |
| 36 | |
| 37 | // Effect process function. |
| 38 | status_t process() override; |
| 39 | |
| 40 | // Process reverse stream function. This function is used to pass |
| 41 | // a reference stream to the effect engine. |
| 42 | status_t processReverse() override; |
| 43 | |
| 44 | // Send a command and receive a response to/from effect engine. |
| 45 | status_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize, |
| 46 | void* pReplyData) override; |
| 47 | |
| 48 | // Returns the effect descriptor. |
| 49 | status_t getDescriptor(effect_descriptor_t *pDescriptor) override; |
| 50 | |
| 51 | // Free resources on the remote side. |
| 52 | status_t close() override; |
| 53 | |
| 54 | // Whether it's a local implementation. |
| 55 | bool isLocal() const override { return false; } |
| 56 | |
| 57 | status_t dump(int fd) override; |
| 58 | |
| 59 | uint64_t effectId() const override { return mEffectId; } |
| 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 | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 65 | private: |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 66 | friend class sp<EffectHalAidl>; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 67 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame^] | 68 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory; |
| 69 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 70 | const uint64_t mEffectId; |
| 71 | const int32_t mSessionId; |
| 72 | const int32_t mIoId; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 73 | const ::aidl::android::hardware::audio::effect::Descriptor mDesc; |
| 74 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 75 | sp<EffectBufferHalInterface> mInBuffer, mOutBuffer; |
| 76 | effect_config_t mConfig; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 77 | |
| 78 | // Can not be constructed directly by clients. |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame^] | 79 | EffectHalAidl( |
| 80 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory, |
| 81 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect, |
| 82 | uint64_t effectId, int32_t sessionId, int32_t ioId, |
| 83 | const ::aidl::android::hardware::audio::effect::Descriptor& desc); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 84 | bool setEffectReverse(bool reverse); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 85 | |
| 86 | // The destructor automatically releases the effect. |
| 87 | virtual ~EffectHalAidl(); |
| 88 | }; |
| 89 | |
| 90 | } // namespace effect |
| 91 | } // namespace android |