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