blob: 2c71195ba3279fd64d1221a6fa97de281e883a5e [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,
Andy Hung59867e42023-06-27 17:05:02 -070035 const sp<Client>& client,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -070036 const sp<media::IEffectClient>& effectClient,
Andy Hung8e6b62a2023-07-13 18:11:33 -070037 const std::map<audio_patch_handle_t, IAfPatchPanel::Patch>& patches,
Eric Laurentb82e6b72019-11-22 17:25:04 -080038 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,
Andy Hung8e6b62a2023-07-13 18:11:33 -070063 const IAfPatchPanel::Patch& patch) override;
Vlad Popa5161f8a2022-10-10 16:17:20 +020064 void onReleaseAudioPatch(audio_patch_handle_t handle) override;
François Gaffie58e73af2023-02-15 11:47:24 +010065 void onUpdateAudioPatch(audio_patch_handle_t oldHandle,
66 audio_patch_handle_t newHandle,
Andy Hung8e6b62a2023-07-13 18:11:33 -070067 const IAfPatchPanel::Patch& patch) override;
Vlad Popa5161f8a2022-10-10 16:17:20 +020068
Eric Laurentb82e6b72019-11-22 17:25:04 -080069private:
Eric Laurentb82e6b72019-11-22 17:25:04 -080070 status_t checkEffectCompatibility(const effect_descriptor_t *desc);
71
72 Mutex mLock;
Eric Laurentb82e6b72019-11-22 17:25:04 -080073 AudioFlinger &mAudioFlinger;
74 const sp<DeviceEffectManagerCallback> mMyCallback;
François Gaffie0f660582023-06-27 15:15:26 +020075 std::map<AudioDeviceTypeAddr, std::vector<sp<IAfDeviceEffectProxy>>> mDeviceEffects;
Eric Laurentb82e6b72019-11-22 17:25:04 -080076};
77
Andy Hung6ac17eb2023-06-20 18:56:17 -070078public: // TODO(b/288339104) extract inner class.
Vlad Popa5161f8a2022-10-10 16:17:20 +020079class DeviceEffectManagerCallback : public EffectCallbackInterface {
Eric Laurentb82e6b72019-11-22 17:25:04 -080080public:
Andy Hung920f6572022-10-06 12:09:49 -070081 explicit DeviceEffectManagerCallback(DeviceEffectManager& manager)
Vlad Popa5161f8a2022-10-10 16:17:20 +020082 : mManager(manager) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -080083
84 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
85 int32_t sessionId, int32_t deviceId,
86 sp<EffectHalInterface> *effect) override {
87 return mManager.createEffectHal(pEffectUuid, sessionId, deviceId, effect);
88 }
89 status_t allocateHalBuffer(size_t size __unused,
90 sp<EffectBufferHalInterface>* buffer __unused) override { return NO_ERROR; }
Andy Hung6ac17eb2023-06-20 18:56:17 -070091 bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect __unused) override {
92 return false;
93 }
Eric Laurentb82e6b72019-11-22 17:25:04 -080094
95 audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; }
96 bool isOutput() const override { return false; }
97 bool isOffload() const override { return false; }
98 bool isOffloadOrDirect() const override { return false; }
99 bool isOffloadOrMmap() const override { return false; }
Eric Laurentb62d0362021-10-26 17:40:18 +0200100 bool isSpatializer() const override { return false; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800101
102 uint32_t sampleRate() const override { return 0; }
Eric Laurentf1f22e72021-07-13 14:04:14 +0200103 audio_channel_mask_t inChannelMask(int id __unused) const override {
104 return AUDIO_CHANNEL_NONE;
105 }
106 uint32_t inChannelCount(int id __unused) const override { return 0; }
107 audio_channel_mask_t outChannelMask() const override { return AUDIO_CHANNEL_NONE; }
108 uint32_t outChannelCount() const override { return 0; }
109
jiabineb3bda02020-06-30 14:07:03 -0700110 audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800111 size_t frameCount() const override { return 0; }
112 uint32_t latency() const override { return 0; }
113
Andy Hung920f6572022-10-06 12:09:49 -0700114 status_t addEffectToHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800115 return NO_ERROR;
116 }
Andy Hung920f6572022-10-06 12:09:49 -0700117 status_t removeEffectFromHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800118 return NO_ERROR;
119 }
120
Andy Hung6ac17eb2023-06-20 18:56:17 -0700121 bool disconnectEffectHandle(IAfEffectHandle *handle, bool unpinIfLast) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800122 void setVolumeForOutput(float left __unused, float right __unused) const override {}
123
124 // check if effects should be suspended or restored when a given effect is enable or disabled
Andy Hung6ac17eb2023-06-20 18:56:17 -0700125 void checkSuspendOnEffectEnabled(const sp<IAfEffectBase>& effect __unused,
Eric Laurentb82e6b72019-11-22 17:25:04 -0800126 bool enabled __unused, bool threadLocked __unused) override {}
127 void resetVolume() override {}
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800128 product_strategy_t strategy() const override { return static_cast<product_strategy_t>(0); }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800129 int32_t activeTrackCnt() const override { return 0; }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700130 void onEffectEnable(const sp<IAfEffectBase>& effect __unused) override {}
131 void onEffectDisable(const sp<IAfEffectBase>& effect __unused) override {}
Eric Laurentb82e6b72019-11-22 17:25:04 -0800132
Andy Hung6ac17eb2023-06-20 18:56:17 -0700133 wp<IAfEffectChain> chain() const override { return nullptr; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800134
Eric Laurentd66d7a12021-07-13 13:35:32 +0200135 bool isAudioPolicyReady() const override {
136 return mManager.audioFlinger().isAudioPolicyReady();
137 }
138
Eric Laurentb82e6b72019-11-22 17:25:04 -0800139 int newEffectId() { return mManager.audioFlinger().nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT); }
140
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700141 status_t addEffectToHal(const struct audio_port_config *device,
142 const sp<EffectHalInterface>& effect) {
143 return mManager.addEffectToHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -0800144 }
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700145 status_t removeEffectFromHal(const struct audio_port_config *device,
146 const sp<EffectHalInterface>& effect) {
147 return mManager.removeEffectFromHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -0800148 }
149private:
150 DeviceEffectManager& mManager;
151};
Andy Hung6ac17eb2023-06-20 18:56:17 -0700152private: