blob: 1e85da902355d4d52675810fee3ee8aef78c1849 [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
23#include <android-base/thread_annotations.h>
Shunkai Yaodca65ce2022-12-02 05:35:41 +000024#include <media/audiohal/EffectsFactoryHalInterface.h>
Shunkai Yao51202502022-12-12 06:11:46 +000025#include <system/thread_defs.h>
Shunkai Yaodca65ce2022-12-02 05:35:41 +000026
27namespace android {
28namespace effect {
29
30using namespace aidl::android::hardware::audio::effect;
31
32class EffectsFactoryHalAidl final : public EffectsFactoryHalInterface {
33 public:
34 explicit EffectsFactoryHalAidl(std::shared_ptr<IFactory> effectsFactory);
35
36 // Returns the number of different effects in all loaded libraries.
37 status_t queryNumberEffects(uint32_t *pNumEffects) override;
38
39 // Returns a descriptor of the next available effect.
40 status_t getDescriptor(uint32_t index, effect_descriptor_t* pDescriptor) override;
41
42 status_t getDescriptor(const effect_uuid_t* pEffectUuid,
43 effect_descriptor_t* pDescriptor) override;
44
45 status_t getDescriptors(const effect_uuid_t* pEffectType,
46 std::vector<effect_descriptor_t>* descriptors) override;
47
48 // Creates an effect engine of the specified type.
Shunkai Yao51202502022-12-12 06:11:46 +000049 // To release the effect engine, it is necessary to release references to the returned effect
50 // object.
Shunkai Yaodca65ce2022-12-02 05:35:41 +000051 status_t createEffect(const effect_uuid_t* pEffectUuid, int32_t sessionId, int32_t ioId,
52 int32_t deviceId, sp<EffectHalInterface>* effect) override;
53
54 status_t dumpEffects(int fd) override;
55
56 status_t allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) override;
57 status_t mirrorBuffer(void* external, size_t size,
58 sp<EffectBufferHalInterface>* buffer) override;
59
Shunkai Yao51202502022-12-12 06:11:46 +000060 detail::AudioHalVersionInfo getHalVersion() const override;
Shunkai Yaodca65ce2022-12-02 05:35:41 +000061
62 private:
Shunkai Yao51202502022-12-12 06:11:46 +000063 std::mutex mLock;
64 const std::shared_ptr<IFactory> mFactory;
65 uint64_t mEffectIdCounter GUARDED_BY(mLock) = 0; // Align with HIDL (0 is INVALID_ID)
66 std::unique_ptr<std::vector<Descriptor>> mDescList GUARDED_BY(mLock) = nullptr;
67 const detail::AudioHalVersionInfo mHalVersion;
68
Shunkai Yaodca65ce2022-12-02 05:35:41 +000069 virtual ~EffectsFactoryHalAidl() = default;
Shunkai Yao51202502022-12-12 06:11:46 +000070 status_t queryEffectList_l() REQUIRES(mLock);
71 status_t getHalDescriptorWithImplUuid_l(
72 const aidl::android::media::audio::common::AudioUuid& uuid,
73 effect_descriptor_t* pDescriptor) REQUIRES(mLock);
74 status_t getHalDescriptorWithTypeUuid_l(
75 const aidl::android::media::audio::common::AudioUuid& type,
76 std::vector<effect_descriptor_t>* descriptors) REQUIRES(mLock);
Shunkai Yaodca65ce2022-12-02 05:35:41 +000077};
78
79} // namespace effect
80} // namespace android