blob: 3a33a713d135c7747df5271860b8c26b4ea8987f [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
Andy Hung6ac17eb2023-06-20 18:56:17 -070033 sp<IAfEffectHandle> createEffect_l(effect_descriptor_t *descriptor,
Eric Laurentb82e6b72019-11-22 17:25:04 -080034 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
Andy Hung6ac17eb2023-06-20 18:56:17 -070043 size_t removeEffect(const sp<IAfDeviceEffectProxy>& effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -080044 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
45 int32_t sessionId, int32_t deviceId,
46 sp<EffectHalInterface> *effect);
Mikhail Naganovd2c7f852023-06-14 18:00:13 -070047 status_t addEffectToHal(const struct audio_port_config *device,
Andy Hung920f6572022-10-06 12:09:49 -070048 const sp<EffectHalInterface>& effect) {
Mikhail Naganovd2c7f852023-06-14 18:00:13 -070049 return mAudioFlinger.addEffectToHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -080050 };
Mikhail Naganovd2c7f852023-06-14 18:00:13 -070051 status_t removeEffectFromHal(const struct audio_port_config *device,
Andy Hung920f6572022-10-06 12:09:49 -070052 const sp<EffectHalInterface>& effect) {
Mikhail Naganovd2c7f852023-06-14 18:00:13 -070053 return mAudioFlinger.removeEffectFromHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -080054 };
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;
Andy Hung6ac17eb2023-06-20 18:56:17 -070072 std::map<AudioDeviceTypeAddr, sp<IAfDeviceEffectProxy>> mDeviceEffects;
Eric Laurentb82e6b72019-11-22 17:25:04 -080073};
74
Andy Hung6ac17eb2023-06-20 18:56:17 -070075public: // TODO(b/288339104) extract inner class.
Vlad Popa5161f8a2022-10-10 16:17:20 +020076class DeviceEffectManagerCallback : public EffectCallbackInterface {
Eric Laurentb82e6b72019-11-22 17:25:04 -080077public:
Andy Hung920f6572022-10-06 12:09:49 -070078 explicit DeviceEffectManagerCallback(DeviceEffectManager& manager)
Vlad Popa5161f8a2022-10-10 16:17:20 +020079 : mManager(manager) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -080080
81 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
82 int32_t sessionId, int32_t deviceId,
83 sp<EffectHalInterface> *effect) override {
84 return mManager.createEffectHal(pEffectUuid, sessionId, deviceId, effect);
85 }
86 status_t allocateHalBuffer(size_t size __unused,
87 sp<EffectBufferHalInterface>* buffer __unused) override { return NO_ERROR; }
Andy Hung6ac17eb2023-06-20 18:56:17 -070088 bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect __unused) override {
89 return false;
90 }
Eric Laurentb82e6b72019-11-22 17:25:04 -080091
92 audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; }
93 bool isOutput() const override { return false; }
94 bool isOffload() const override { return false; }
95 bool isOffloadOrDirect() const override { return false; }
96 bool isOffloadOrMmap() const override { return false; }
Eric Laurentb62d0362021-10-26 17:40:18 +020097 bool isSpatializer() const override { return false; }
Eric Laurentb82e6b72019-11-22 17:25:04 -080098
99 uint32_t sampleRate() const override { return 0; }
Eric Laurentf1f22e72021-07-13 14:04:14 +0200100 audio_channel_mask_t inChannelMask(int id __unused) const override {
101 return AUDIO_CHANNEL_NONE;
102 }
103 uint32_t inChannelCount(int id __unused) const override { return 0; }
104 audio_channel_mask_t outChannelMask() const override { return AUDIO_CHANNEL_NONE; }
105 uint32_t outChannelCount() const override { return 0; }
106
jiabineb3bda02020-06-30 14:07:03 -0700107 audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800108 size_t frameCount() const override { return 0; }
109 uint32_t latency() const override { return 0; }
110
Andy Hung920f6572022-10-06 12:09:49 -0700111 status_t addEffectToHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800112 return NO_ERROR;
113 }
Andy Hung920f6572022-10-06 12:09:49 -0700114 status_t removeEffectFromHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800115 return NO_ERROR;
116 }
117
Andy Hung6ac17eb2023-06-20 18:56:17 -0700118 bool disconnectEffectHandle(IAfEffectHandle *handle, bool unpinIfLast) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800119 void setVolumeForOutput(float left __unused, float right __unused) const override {}
120
121 // check if effects should be suspended or restored when a given effect is enable or disabled
Andy Hung6ac17eb2023-06-20 18:56:17 -0700122 void checkSuspendOnEffectEnabled(const sp<IAfEffectBase>& effect __unused,
Eric Laurentb82e6b72019-11-22 17:25:04 -0800123 bool enabled __unused, bool threadLocked __unused) override {}
124 void resetVolume() override {}
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800125 product_strategy_t strategy() const override { return static_cast<product_strategy_t>(0); }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800126 int32_t activeTrackCnt() const override { return 0; }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700127 void onEffectEnable(const sp<IAfEffectBase>& effect __unused) override {}
128 void onEffectDisable(const sp<IAfEffectBase>& effect __unused) override {}
Eric Laurentb82e6b72019-11-22 17:25:04 -0800129
Andy Hung6ac17eb2023-06-20 18:56:17 -0700130 wp<IAfEffectChain> chain() const override { return nullptr; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800131
Eric Laurentd66d7a12021-07-13 13:35:32 +0200132 bool isAudioPolicyReady() const override {
133 return mManager.audioFlinger().isAudioPolicyReady();
134 }
135
Eric Laurentb82e6b72019-11-22 17:25:04 -0800136 int newEffectId() { return mManager.audioFlinger().nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT); }
137
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700138 status_t addEffectToHal(const struct audio_port_config *device,
139 const sp<EffectHalInterface>& effect) {
140 return mManager.addEffectToHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -0800141 }
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700142 status_t removeEffectFromHal(const struct audio_port_config *device,
143 const sp<EffectHalInterface>& effect) {
144 return mManager.removeEffectFromHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -0800145 }
146private:
147 DeviceEffectManager& mManager;
148};
Andy Hung6ac17eb2023-06-20 18:56:17 -0700149private: