blob: 911689569b57efe65e75be2e6bcf000aa9bf16c5 [file] [log] [blame]
Shunkai Yaodca65ce2022-12-02 05:35:41 +00001/*
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 Yao51202502022-12-12 06:11:46 +000019#include <cstddef>
20#include <memory>
21#include <mutex>
22
Shunkai Yaoc6308712023-02-22 17:53:04 +000023#include <aidl/android/hardware/audio/effect/IFactory.h>
Shunkai Yao51202502022-12-12 06:11:46 +000024#include <android-base/thread_annotations.h>
Shunkai Yaodca65ce2022-12-02 05:35:41 +000025#include <media/audiohal/EffectsFactoryHalInterface.h>
Shunkai Yao51202502022-12-12 06:11:46 +000026#include <system/thread_defs.h>
Shunkai Yaodca65ce2022-12-02 05:35:41 +000027
Shunkai Yao5c718342023-02-23 23:49:51 +000028#include "EffectProxy.h"
29
Shunkai Yaodca65ce2022-12-02 05:35:41 +000030namespace android {
31namespace effect {
32
33using namespace aidl::android::hardware::audio::effect;
34
35class 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 Yao51202502022-12-12 06:11:46 +000052 // To release the effect engine, it is necessary to release references to the returned effect
53 // object.
Shunkai Yaodca65ce2022-12-02 05:35:41 +000054 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 Yao51202502022-12-12 06:11:46 +000063 detail::AudioHalVersionInfo getHalVersion() const override;
Shunkai Yaodca65ce2022-12-02 05:35:41 +000064
Shunkai Yaoe3e403d2023-04-18 23:14:25 +000065 const effectsConfig::EffectProcessings& getProcessings() const override;
66
Shunkai Yaodca65ce2022-12-02 05:35:41 +000067 private:
Shunkai Yao51202502022-12-12 06:11:46 +000068 const std::shared_ptr<IFactory> mFactory;
Shunkai Yao51202502022-12-12 06:11:46 +000069 const detail::AudioHalVersionInfo mHalVersion;
Shunkai Yao5c718342023-02-23 23:49:51 +000070 // Full list of HAL effect descriptors
71 const std::vector<Descriptor> mHalDescList;
72 // Map of proxy UUID (key) to the proxy object
73 const std::map<::aidl::android::media::audio::common::AudioUuid /* proxy impl UUID */,
74 std::shared_ptr<EffectProxy>>
75 mUuidProxyMap;
76 // List of effect proxy, initialize after mUuidProxyMap because it need to have all sub-effects
77 const std::vector<Descriptor> mProxyDescList;
78 // List of non-proxy effects
79 const std::vector<Descriptor> mNonProxyDescList;
80 // total number of effects including proxy effects
81 const size_t mEffectCount;
Shunkai Yaoe3e403d2023-04-18 23:14:25 +000082 // Query result and all processing from effect factory
83 const effectsConfig::EffectProcessings mEffectProcessings;
Shunkai Yao5c718342023-02-23 23:49:51 +000084
85 std::mutex mLock;
86 uint64_t mEffectIdCounter GUARDED_BY(mLock) = 0; // Align with HIDL (0 is INVALID_ID)
Shunkai Yao51202502022-12-12 06:11:46 +000087
Shunkai Yaodca65ce2022-12-02 05:35:41 +000088 virtual ~EffectsFactoryHalAidl() = default;
Shunkai Yao5c718342023-02-23 23:49:51 +000089 status_t getHalDescriptorWithImplUuid(
Shunkai Yao51202502022-12-12 06:11:46 +000090 const aidl::android::media::audio::common::AudioUuid& uuid,
Shunkai Yao5c718342023-02-23 23:49:51 +000091 effect_descriptor_t* pDescriptor);
92
93 status_t getHalDescriptorWithTypeUuid(
Shunkai Yao51202502022-12-12 06:11:46 +000094 const aidl::android::media::audio::common::AudioUuid& type,
Shunkai Yao5c718342023-02-23 23:49:51 +000095 std::vector<effect_descriptor_t>* descriptors);
96
97 bool isProxyEffect(const aidl::android::media::audio::common::AudioUuid& uuid) const;
Shunkai Yaodca65ce2022-12-02 05:35:41 +000098};
99
100} // namespace effect
101} // namespace android