blob: 39beea275b43a9d6a1fa3ae6feb226930bfb16e5 [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 Yao0a51cf92023-05-10 22:42:56 +000024#include <aidl/android/hardware/audio/effect/Processing.h>
Shunkai Yao51202502022-12-12 06:11:46 +000025#include <android-base/thread_annotations.h>
Shunkai Yaodca65ce2022-12-02 05:35:41 +000026#include <media/audiohal/EffectsFactoryHalInterface.h>
Shunkai Yao51202502022-12-12 06:11:46 +000027#include <system/thread_defs.h>
Shunkai Yaodca65ce2022-12-02 05:35:41 +000028
Shunkai Yao5c718342023-02-23 23:49:51 +000029#include "EffectProxy.h"
30
Shunkai Yaodca65ce2022-12-02 05:35:41 +000031namespace android {
32namespace effect {
33
34using namespace aidl::android::hardware::audio::effect;
35
36class 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.
Shunkai Yao51202502022-12-12 06:11:46 +000053 // To release the effect engine, it is necessary to release references to the returned effect
54 // object.
Shunkai Yaodca65ce2022-12-02 05:35:41 +000055 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
Shunkai Yao51202502022-12-12 06:11:46 +000064 detail::AudioHalVersionInfo getHalVersion() const override;
Shunkai Yaodca65ce2022-12-02 05:35:41 +000065
Shunkai Yao8f6ad0f2023-04-18 23:14:25 +000066 std::shared_ptr<const effectsConfig::Processings> getProcessings() const override;
67
68 ::android::error::Result<size_t> getSkippedElements() const override;
69
Shunkai Yaodca65ce2022-12-02 05:35:41 +000070 private:
Shunkai Yao51202502022-12-12 06:11:46 +000071 const std::shared_ptr<IFactory> mFactory;
Shunkai Yao51202502022-12-12 06:11:46 +000072 const detail::AudioHalVersionInfo mHalVersion;
Shunkai Yao5c718342023-02-23 23:49:51 +000073 // Full list of HAL effect descriptors
74 const std::vector<Descriptor> mHalDescList;
75 // Map of proxy UUID (key) to the proxy object
76 const std::map<::aidl::android::media::audio::common::AudioUuid /* proxy impl UUID */,
77 std::shared_ptr<EffectProxy>>
78 mUuidProxyMap;
79 // List of effect proxy, initialize after mUuidProxyMap because it need to have all sub-effects
80 const std::vector<Descriptor> mProxyDescList;
81 // List of non-proxy effects
82 const std::vector<Descriptor> mNonProxyDescList;
83 // total number of effects including proxy effects
84 const size_t mEffectCount;
Shunkai Yao8f6ad0f2023-04-18 23:14:25 +000085 // Query result of pre and post processing from effect factory
Shunkai Yao0a51cf92023-05-10 22:42:56 +000086 const std::vector<Processing> mAidlProcessings;
Shunkai Yao5c718342023-02-23 23:49:51 +000087
88 std::mutex mLock;
89 uint64_t mEffectIdCounter GUARDED_BY(mLock) = 0; // Align with HIDL (0 is INVALID_ID)
Shunkai Yao51202502022-12-12 06:11:46 +000090
Shunkai Yaodca65ce2022-12-02 05:35:41 +000091 virtual ~EffectsFactoryHalAidl() = default;
Shunkai Yao5c718342023-02-23 23:49:51 +000092 status_t getHalDescriptorWithImplUuid(
Shunkai Yao51202502022-12-12 06:11:46 +000093 const aidl::android::media::audio::common::AudioUuid& uuid,
Shunkai Yao5c718342023-02-23 23:49:51 +000094 effect_descriptor_t* pDescriptor);
95
96 status_t getHalDescriptorWithTypeUuid(
Shunkai Yao51202502022-12-12 06:11:46 +000097 const aidl::android::media::audio::common::AudioUuid& type,
Shunkai Yao5c718342023-02-23 23:49:51 +000098 std::vector<effect_descriptor_t>* descriptors);
99
100 bool isProxyEffect(const aidl::android::media::audio::common::AudioUuid& uuid) const;
Shunkai Yaodca65ce2022-12-02 05:35:41 +0000101};
102
103} // namespace effect
104} // namespace android