blob: 9c3643b8bc81a5813dbb082656374e9228679305 [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
28namespace android {
29namespace effect {
30
31using namespace aidl::android::hardware::audio::effect;
32
33class 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 Yao51202502022-12-12 06:11:46 +000050 // To release the effect engine, it is necessary to release references to the returned effect
51 // object.
Shunkai Yaodca65ce2022-12-02 05:35:41 +000052 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 Yao51202502022-12-12 06:11:46 +000061 detail::AudioHalVersionInfo getHalVersion() const override;
Shunkai Yaodca65ce2022-12-02 05:35:41 +000062
Shunkai Yaoc6308712023-02-22 17:53:04 +000063 // for TIME_CHECK
64 const std::string getClassName() const { return "EffectHalAidl"; }
65
Shunkai Yaodca65ce2022-12-02 05:35:41 +000066 private:
Shunkai Yao51202502022-12-12 06:11:46 +000067 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 Yaodca65ce2022-12-02 05:35:41 +000073 virtual ~EffectsFactoryHalAidl() = default;
Shunkai Yao51202502022-12-12 06:11:46 +000074 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 Yaodca65ce2022-12-02 05:35:41 +000081};
82
83} // namespace effect
84} // namespace android