blob: 162ffd31bd5e54f1a7c03e36d7dd1c8c9199bed3 [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
Andy Hungdf397962023-07-13 19:54:47 -070018#pragma once
19
20namespace android {
21
Andy Hung13e99b32023-07-17 13:45:55 -070022class IAfDeviceEffectManagerCallback : public virtual RefBase {
23public:
24 virtual bool isAudioPolicyReady() const = 0;
25 virtual audio_unique_id_t nextUniqueId(audio_unique_id_use_t use) = 0;
26 virtual const sp<PatchCommandThread>& getPatchCommandThread() = 0;
27 virtual status_t addEffectToHal(
28 const struct audio_port_config* device, const sp<EffectHalInterface>& effect) = 0;
29 virtual status_t removeEffectFromHal(
30 const struct audio_port_config* device, const sp<EffectHalInterface>& effect) = 0;
31};
32
Andy Hungdf397962023-07-13 19:54:47 -070033class DeviceEffectManagerCallback;
Eric Laurentb82e6b72019-11-22 17:25:04 -080034
35// DeviceEffectManager is concealed within AudioFlinger, their lifetimes are the same.
Vlad Popa5161f8a2022-10-10 16:17:20 +020036class DeviceEffectManager : public PatchCommandThread::PatchCommandListener {
Eric Laurentb82e6b72019-11-22 17:25:04 -080037public:
Andy Hung13e99b32023-07-17 13:45:55 -070038 explicit DeviceEffectManager(
39 const sp<IAfDeviceEffectManagerCallback>& afDeviceEffectManagerCallback);
Eric Laurentb82e6b72019-11-22 17:25:04 -080040
Andy Hungdf397962023-07-13 19:54:47 -070041 void onFirstRef() override;
Eric Laurentb82e6b72019-11-22 17:25:04 -080042
Andy Hung116bc262023-06-20 18:56:17 -070043 sp<IAfEffectHandle> createEffect_l(effect_descriptor_t *descriptor,
Eric Laurentb82e6b72019-11-22 17:25:04 -080044 const AudioDeviceTypeAddr& device,
Andy Hung88035ac2023-06-27 17:05:02 -070045 const sp<Client>& client,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -070046 const sp<media::IEffectClient>& effectClient,
Andy Hungc0ab56b2023-07-13 18:11:33 -070047 const std::map<audio_patch_handle_t, IAfPatchPanel::Patch>& patches,
Eric Laurentb82e6b72019-11-22 17:25:04 -080048 int *enabled,
Eric Laurent2fe0acd2020-03-13 14:30:46 -070049 status_t *status,
Eric Laurentde8caf42021-08-11 17:19:25 +020050 bool probe,
51 bool notifyFramesProcessed);
Eric Laurentb82e6b72019-11-22 17:25:04 -080052
Andy Hung116bc262023-06-20 18:56:17 -070053 size_t removeEffect(const sp<IAfDeviceEffectProxy>& effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -080054 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
55 int32_t sessionId, int32_t deviceId,
56 sp<EffectHalInterface> *effect);
Mikhail Naganovd2c7f852023-06-14 18:00:13 -070057 status_t addEffectToHal(const struct audio_port_config *device,
Andy Hungdf397962023-07-13 19:54:47 -070058 const sp<EffectHalInterface>& effect);
Mikhail Naganovd2c7f852023-06-14 18:00:13 -070059 status_t removeEffectFromHal(const struct audio_port_config *device,
Andy Hungdf397962023-07-13 19:54:47 -070060 const sp<EffectHalInterface>& effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -080061
Andy Hung13e99b32023-07-17 13:45:55 -070062 const auto& afDeviceEffectManagerCallback() const { return mAfDeviceEffectManagerCallback; }
Eric Laurentb82e6b72019-11-22 17:25:04 -080063
64 void dump(int fd);
65
Vlad Popa5161f8a2022-10-10 16:17:20 +020066 // PatchCommandThread::PatchCommandListener implementation
67
68 void onCreateAudioPatch(audio_patch_handle_t handle,
Andy Hungdf397962023-07-13 19:54:47 -070069 const IAfPatchPanel::Patch& patch) final;
70 void onReleaseAudioPatch(audio_patch_handle_t handle) final;
Vlad Popa5161f8a2022-10-10 16:17:20 +020071
Eric Laurentb82e6b72019-11-22 17:25:04 -080072private:
Eric Laurentb82e6b72019-11-22 17:25:04 -080073 status_t checkEffectCompatibility(const effect_descriptor_t *desc);
74
75 Mutex mLock;
Andy Hung13e99b32023-07-17 13:45:55 -070076 const sp<IAfDeviceEffectManagerCallback> mAfDeviceEffectManagerCallback;
Eric Laurentb82e6b72019-11-22 17:25:04 -080077 const sp<DeviceEffectManagerCallback> mMyCallback;
Andy Hung116bc262023-06-20 18:56:17 -070078 std::map<AudioDeviceTypeAddr, sp<IAfDeviceEffectProxy>> mDeviceEffects;
Eric Laurentb82e6b72019-11-22 17:25:04 -080079};
80
Vlad Popa5161f8a2022-10-10 16:17:20 +020081class DeviceEffectManagerCallback : public EffectCallbackInterface {
Eric Laurentb82e6b72019-11-22 17:25:04 -080082public:
Andy Hung920f6572022-10-06 12:09:49 -070083 explicit DeviceEffectManagerCallback(DeviceEffectManager& manager)
Vlad Popa5161f8a2022-10-10 16:17:20 +020084 : mManager(manager) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -080085
86 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
87 int32_t sessionId, int32_t deviceId,
88 sp<EffectHalInterface> *effect) override {
89 return mManager.createEffectHal(pEffectUuid, sessionId, deviceId, effect);
90 }
91 status_t allocateHalBuffer(size_t size __unused,
92 sp<EffectBufferHalInterface>* buffer __unused) override { return NO_ERROR; }
Andy Hung116bc262023-06-20 18:56:17 -070093 bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect __unused) override {
94 return false;
95 }
Eric Laurentb82e6b72019-11-22 17:25:04 -080096
97 audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; }
98 bool isOutput() const override { return false; }
99 bool isOffload() const override { return false; }
100 bool isOffloadOrDirect() const override { return false; }
101 bool isOffloadOrMmap() const override { return false; }
Eric Laurentb62d0362021-10-26 17:40:18 +0200102 bool isSpatializer() const override { return false; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800103
104 uint32_t sampleRate() const override { return 0; }
Eric Laurentf1f22e72021-07-13 14:04:14 +0200105 audio_channel_mask_t inChannelMask(int id __unused) const override {
106 return AUDIO_CHANNEL_NONE;
107 }
108 uint32_t inChannelCount(int id __unused) const override { return 0; }
109 audio_channel_mask_t outChannelMask() const override { return AUDIO_CHANNEL_NONE; }
110 uint32_t outChannelCount() const override { return 0; }
111
jiabineb3bda02020-06-30 14:07:03 -0700112 audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800113 size_t frameCount() const override { return 0; }
114 uint32_t latency() const override { return 0; }
115
Andy Hung920f6572022-10-06 12:09:49 -0700116 status_t addEffectToHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800117 return NO_ERROR;
118 }
Andy Hung920f6572022-10-06 12:09:49 -0700119 status_t removeEffectFromHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800120 return NO_ERROR;
121 }
122
Andy Hung116bc262023-06-20 18:56:17 -0700123 bool disconnectEffectHandle(IAfEffectHandle *handle, bool unpinIfLast) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800124 void setVolumeForOutput(float left __unused, float right __unused) const override {}
125
126 // check if effects should be suspended or restored when a given effect is enable or disabled
Andy Hung116bc262023-06-20 18:56:17 -0700127 void checkSuspendOnEffectEnabled(const sp<IAfEffectBase>& effect __unused,
Eric Laurentb82e6b72019-11-22 17:25:04 -0800128 bool enabled __unused, bool threadLocked __unused) override {}
129 void resetVolume() override {}
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800130 product_strategy_t strategy() const override { return static_cast<product_strategy_t>(0); }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800131 int32_t activeTrackCnt() const override { return 0; }
Andy Hung116bc262023-06-20 18:56:17 -0700132 void onEffectEnable(const sp<IAfEffectBase>& effect __unused) override {}
133 void onEffectDisable(const sp<IAfEffectBase>& effect __unused) override {}
Eric Laurentb82e6b72019-11-22 17:25:04 -0800134
Andy Hung116bc262023-06-20 18:56:17 -0700135 wp<IAfEffectChain> chain() const override { return nullptr; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800136
Andy Hungdf397962023-07-13 19:54:47 -0700137 bool isAudioPolicyReady() const final;
Eric Laurentd66d7a12021-07-13 13:35:32 +0200138
Andy Hungdf397962023-07-13 19:54:47 -0700139 int newEffectId() const;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800140
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 Hungdf397962023-07-13 19:54:47 -0700152
153} // namespace android