blob: 7602f1224a532f13a7d60a1723eafcae19374b41 [file] [log] [blame]
Eric Laurentb82e6b72019-11-22 17:25:04 -08001/*
2**
3** Copyright 2019, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef INCLUDING_FROM_AUDIOFLINGER_H
19 #error This header file should only be included from AudioFlinger.h
20#endif
21
22// DeviceEffectManager is concealed within AudioFlinger, their lifetimes are the same.
Vlad Popa5161f8a2022-10-10 16:17:20 +020023class DeviceEffectManager : public PatchCommandThread::PatchCommandListener {
Eric Laurentb82e6b72019-11-22 17:25:04 -080024public:
Vlad Popa5161f8a2022-10-10 16:17:20 +020025 explicit DeviceEffectManager(AudioFlinger& audioFlinger)
26 : mAudioFlinger(audioFlinger),
27 mMyCallback(new DeviceEffectManagerCallback(*this)) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -080028
Vlad Popa5161f8a2022-10-10 16:17:20 +020029 void onFirstRef() override {
30 mAudioFlinger.mPatchCommandThread->addListener(this);
31 }
Eric Laurentb82e6b72019-11-22 17:25:04 -080032
33 sp<EffectHandle> createEffect_l(effect_descriptor_t *descriptor,
34 const AudioDeviceTypeAddr& device,
35 const sp<AudioFlinger::Client>& client,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -070036 const sp<media::IEffectClient>& effectClient,
Eric Laurentb82e6b72019-11-22 17:25:04 -080037 const std::map<audio_patch_handle_t, PatchPanel::Patch>& patches,
38 int *enabled,
Eric Laurent2fe0acd2020-03-13 14:30:46 -070039 status_t *status,
Eric Laurentde8caf42021-08-11 17:19:25 +020040 bool probe,
41 bool notifyFramesProcessed);
Eric Laurentb82e6b72019-11-22 17:25:04 -080042
43 size_t removeEffect(const sp<DeviceEffectProxy>& effect);
44 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
45 int32_t sessionId, int32_t deviceId,
46 sp<EffectHalInterface> *effect);
47 status_t addEffectToHal(audio_port_handle_t deviceId, audio_module_handle_t hwModuleId,
48 sp<EffectHalInterface> effect) {
49 return mAudioFlinger.addEffectToHal(deviceId, hwModuleId, effect);
50 };
51 status_t removeEffectFromHal(audio_port_handle_t deviceId, audio_module_handle_t hwModuleId,
52 sp<EffectHalInterface> effect) {
53 return mAudioFlinger.removeEffectFromHal(deviceId, hwModuleId, effect);
54 };
55
56 AudioFlinger& audioFlinger() const { return mAudioFlinger; }
57
58 void dump(int fd);
59
Vlad Popa5161f8a2022-10-10 16:17:20 +020060 // PatchCommandThread::PatchCommandListener implementation
61
62 void onCreateAudioPatch(audio_patch_handle_t handle,
63 const PatchPanel::Patch& patch) override;
64 void onReleaseAudioPatch(audio_patch_handle_t handle) override;
65
Eric Laurentb82e6b72019-11-22 17:25:04 -080066private:
Eric Laurentb82e6b72019-11-22 17:25:04 -080067 status_t checkEffectCompatibility(const effect_descriptor_t *desc);
68
69 Mutex mLock;
Eric Laurentb82e6b72019-11-22 17:25:04 -080070 AudioFlinger &mAudioFlinger;
71 const sp<DeviceEffectManagerCallback> mMyCallback;
72 std::map<AudioDeviceTypeAddr, sp<DeviceEffectProxy>> mDeviceEffects;
73};
74
Vlad Popa5161f8a2022-10-10 16:17:20 +020075class DeviceEffectManagerCallback : public EffectCallbackInterface {
Eric Laurentb82e6b72019-11-22 17:25:04 -080076public:
Vlad Popa5161f8a2022-10-10 16:17:20 +020077 DeviceEffectManagerCallback(DeviceEffectManager& manager)
78 : mManager(manager) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -080079
80 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
81 int32_t sessionId, int32_t deviceId,
82 sp<EffectHalInterface> *effect) override {
83 return mManager.createEffectHal(pEffectUuid, sessionId, deviceId, effect);
84 }
85 status_t allocateHalBuffer(size_t size __unused,
86 sp<EffectBufferHalInterface>* buffer __unused) override { return NO_ERROR; }
87 bool updateOrphanEffectChains(const sp<EffectBase>& effect __unused) override { return false; }
88
89 audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; }
90 bool isOutput() const override { return false; }
91 bool isOffload() const override { return false; }
92 bool isOffloadOrDirect() const override { return false; }
93 bool isOffloadOrMmap() const override { return false; }
Eric Laurentb62d0362021-10-26 17:40:18 +020094 bool isSpatializer() const override { return false; }
Eric Laurentb82e6b72019-11-22 17:25:04 -080095
96 uint32_t sampleRate() const override { return 0; }
Eric Laurentf1f22e72021-07-13 14:04:14 +020097 audio_channel_mask_t inChannelMask(int id __unused) const override {
98 return AUDIO_CHANNEL_NONE;
99 }
100 uint32_t inChannelCount(int id __unused) const override { return 0; }
101 audio_channel_mask_t outChannelMask() const override { return AUDIO_CHANNEL_NONE; }
102 uint32_t outChannelCount() const override { return 0; }
103
jiabineb3bda02020-06-30 14:07:03 -0700104 audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800105 size_t frameCount() const override { return 0; }
106 uint32_t latency() const override { return 0; }
107
108 status_t addEffectToHal(sp<EffectHalInterface> effect __unused) override {
109 return NO_ERROR;
110 }
111 status_t removeEffectFromHal(sp<EffectHalInterface> effect __unused) override {
112 return NO_ERROR;
113 }
114
115 bool disconnectEffectHandle(EffectHandle *handle, bool unpinIfLast) override;
116 void setVolumeForOutput(float left __unused, float right __unused) const override {}
117
118 // check if effects should be suspended or restored when a given effect is enable or disabled
119 void checkSuspendOnEffectEnabled(const sp<EffectBase>& effect __unused,
120 bool enabled __unused, bool threadLocked __unused) override {}
121 void resetVolume() override {}
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800122 product_strategy_t strategy() const override { return static_cast<product_strategy_t>(0); }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800123 int32_t activeTrackCnt() const override { return 0; }
124 void onEffectEnable(const sp<EffectBase>& effect __unused) override {}
125 void onEffectDisable(const sp<EffectBase>& effect __unused) override {}
126
127 wp<EffectChain> chain() const override { return nullptr; }
128
Eric Laurentd66d7a12021-07-13 13:35:32 +0200129 bool isAudioPolicyReady() const override {
130 return mManager.audioFlinger().isAudioPolicyReady();
131 }
132
Eric Laurentb82e6b72019-11-22 17:25:04 -0800133 int newEffectId() { return mManager.audioFlinger().nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT); }
134
135 status_t addEffectToHal(audio_port_handle_t deviceId,
136 audio_module_handle_t hwModuleId, sp<EffectHalInterface> effect) {
137 return mManager.addEffectToHal(deviceId, hwModuleId, effect);
138 }
139 status_t removeEffectFromHal(audio_port_handle_t deviceId,
140 audio_module_handle_t hwModuleId, sp<EffectHalInterface> effect) {
141 return mManager.removeEffectFromHal(deviceId, hwModuleId, effect);
142 }
143private:
144 DeviceEffectManager& mManager;
145};