Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +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 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 19 | #include <cstddef> |
| 20 | #include <memory> |
| 21 | #include <mutex> |
| 22 | |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame] | 23 | #include <aidl/android/hardware/audio/effect/IFactory.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 24 | #include <android-base/thread_annotations.h> |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 25 | #include <media/audiohal/EffectsFactoryHalInterface.h> |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 26 | #include <system/thread_defs.h> |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 27 | |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame^] | 28 | #include "EffectProxy.h" |
| 29 | |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 30 | namespace android { |
| 31 | namespace effect { |
| 32 | |
| 33 | using namespace aidl::android::hardware::audio::effect; |
| 34 | |
| 35 | class EffectsFactoryHalAidl final : public EffectsFactoryHalInterface { |
| 36 | public: |
| 37 | explicit EffectsFactoryHalAidl(std::shared_ptr<IFactory> effectsFactory); |
| 38 | |
| 39 | // Returns the number of different effects in all loaded libraries. |
| 40 | status_t queryNumberEffects(uint32_t *pNumEffects) override; |
| 41 | |
| 42 | // Returns a descriptor of the next available effect. |
| 43 | status_t getDescriptor(uint32_t index, effect_descriptor_t* pDescriptor) override; |
| 44 | |
| 45 | status_t getDescriptor(const effect_uuid_t* pEffectUuid, |
| 46 | effect_descriptor_t* pDescriptor) override; |
| 47 | |
| 48 | status_t getDescriptors(const effect_uuid_t* pEffectType, |
| 49 | std::vector<effect_descriptor_t>* descriptors) override; |
| 50 | |
| 51 | // Creates an effect engine of the specified type. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 52 | // To release the effect engine, it is necessary to release references to the returned effect |
| 53 | // object. |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 54 | status_t createEffect(const effect_uuid_t* pEffectUuid, int32_t sessionId, int32_t ioId, |
| 55 | int32_t deviceId, sp<EffectHalInterface>* effect) override; |
| 56 | |
| 57 | status_t dumpEffects(int fd) override; |
| 58 | |
| 59 | status_t allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) override; |
| 60 | status_t mirrorBuffer(void* external, size_t size, |
| 61 | sp<EffectBufferHalInterface>* buffer) override; |
| 62 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 63 | detail::AudioHalVersionInfo getHalVersion() const override; |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 64 | |
| 65 | private: |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 66 | const std::shared_ptr<IFactory> mFactory; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 67 | const detail::AudioHalVersionInfo mHalVersion; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame^] | 68 | // Full list of HAL effect descriptors |
| 69 | const std::vector<Descriptor> mHalDescList; |
| 70 | // Map of proxy UUID (key) to the proxy object |
| 71 | const std::map<::aidl::android::media::audio::common::AudioUuid /* proxy impl UUID */, |
| 72 | std::shared_ptr<EffectProxy>> |
| 73 | mUuidProxyMap; |
| 74 | // List of effect proxy, initialize after mUuidProxyMap because it need to have all sub-effects |
| 75 | const std::vector<Descriptor> mProxyDescList; |
| 76 | // List of non-proxy effects |
| 77 | const std::vector<Descriptor> mNonProxyDescList; |
| 78 | // total number of effects including proxy effects |
| 79 | const size_t mEffectCount; |
| 80 | |
| 81 | std::mutex mLock; |
| 82 | uint64_t mEffectIdCounter GUARDED_BY(mLock) = 0; // Align with HIDL (0 is INVALID_ID) |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 83 | |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 84 | virtual ~EffectsFactoryHalAidl() = default; |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame^] | 85 | status_t getHalDescriptorWithImplUuid( |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 86 | const aidl::android::media::audio::common::AudioUuid& uuid, |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame^] | 87 | effect_descriptor_t* pDescriptor); |
| 88 | |
| 89 | status_t getHalDescriptorWithTypeUuid( |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 90 | const aidl::android::media::audio::common::AudioUuid& type, |
Shunkai Yao | 5c71834 | 2023-02-23 23:49:51 +0000 | [diff] [blame^] | 91 | std::vector<effect_descriptor_t>* descriptors); |
| 92 | |
| 93 | bool isProxyEffect(const aidl::android::media::audio::common::AudioUuid& uuid) const; |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | } // namespace effect |
| 97 | } // namespace android |