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 | |
| 28 | namespace android { |
| 29 | namespace effect { |
| 30 | |
| 31 | using namespace aidl::android::hardware::audio::effect; |
| 32 | |
| 33 | class EffectsFactoryHalAidl final : public EffectsFactoryHalInterface { |
| 34 | public: |
| 35 | explicit EffectsFactoryHalAidl(std::shared_ptr<IFactory> effectsFactory); |
| 36 | |
| 37 | // Returns the number of different effects in all loaded libraries. |
| 38 | status_t queryNumberEffects(uint32_t *pNumEffects) override; |
| 39 | |
| 40 | // Returns a descriptor of the next available effect. |
| 41 | status_t getDescriptor(uint32_t index, effect_descriptor_t* pDescriptor) override; |
| 42 | |
| 43 | status_t getDescriptor(const effect_uuid_t* pEffectUuid, |
| 44 | effect_descriptor_t* pDescriptor) override; |
| 45 | |
| 46 | status_t getDescriptors(const effect_uuid_t* pEffectType, |
| 47 | std::vector<effect_descriptor_t>* descriptors) override; |
| 48 | |
| 49 | // Creates an effect engine of the specified type. |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 50 | // To release the effect engine, it is necessary to release references to the returned effect |
| 51 | // object. |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 52 | status_t createEffect(const effect_uuid_t* pEffectUuid, int32_t sessionId, int32_t ioId, |
| 53 | int32_t deviceId, sp<EffectHalInterface>* effect) override; |
| 54 | |
| 55 | status_t dumpEffects(int fd) override; |
| 56 | |
| 57 | status_t allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) override; |
| 58 | status_t mirrorBuffer(void* external, size_t size, |
| 59 | sp<EffectBufferHalInterface>* buffer) override; |
| 60 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 61 | detail::AudioHalVersionInfo getHalVersion() const override; |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 62 | |
Shunkai Yao | c630871 | 2023-02-22 17:53:04 +0000 | [diff] [blame^] | 63 | // for TIME_CHECK |
| 64 | const std::string getClassName() const { return "EffectHalAidl"; } |
| 65 | |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 66 | private: |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 67 | std::mutex mLock; |
| 68 | const std::shared_ptr<IFactory> mFactory; |
| 69 | uint64_t mEffectIdCounter GUARDED_BY(mLock) = 0; // Align with HIDL (0 is INVALID_ID) |
| 70 | std::unique_ptr<std::vector<Descriptor>> mDescList GUARDED_BY(mLock) = nullptr; |
| 71 | const detail::AudioHalVersionInfo mHalVersion; |
| 72 | |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 73 | virtual ~EffectsFactoryHalAidl() = default; |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 74 | status_t queryEffectList_l() REQUIRES(mLock); |
| 75 | status_t getHalDescriptorWithImplUuid_l( |
| 76 | const aidl::android::media::audio::common::AudioUuid& uuid, |
| 77 | effect_descriptor_t* pDescriptor) REQUIRES(mLock); |
| 78 | status_t getHalDescriptorWithTypeUuid_l( |
| 79 | const aidl::android::media::audio::common::AudioUuid& type, |
| 80 | std::vector<effect_descriptor_t>* descriptors) REQUIRES(mLock); |
Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // namespace effect |
| 84 | } // namespace android |