blob: 54b88d0a67bb80d14ec5fdb46c263adc811c884b [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 Hung55a74fd2023-07-13 19:54:47 -070018#pragma once
19
20namespace android {
21
22class DeviceEffectManagerCallback;
Eric Laurentb82e6b72019-11-22 17:25:04 -080023
24// DeviceEffectManager is concealed within AudioFlinger, their lifetimes are the same.
Vlad Popa5161f8a2022-10-10 16:17:20 +020025class DeviceEffectManager : public PatchCommandThread::PatchCommandListener {
Eric Laurentb82e6b72019-11-22 17:25:04 -080026public:
Andy Hung55a74fd2023-07-13 19:54:47 -070027 explicit DeviceEffectManager(AudioFlinger& audioFlinger);
Eric Laurentb82e6b72019-11-22 17:25:04 -080028
Andy Hung55a74fd2023-07-13 19:54:47 -070029 void onFirstRef() override;
Eric Laurentb82e6b72019-11-22 17:25:04 -080030
Andy Hung6ac17eb2023-06-20 18:56:17 -070031 sp<IAfEffectHandle> createEffect_l(effect_descriptor_t *descriptor,
Eric Laurentb82e6b72019-11-22 17:25:04 -080032 const AudioDeviceTypeAddr& device,
Andy Hung59867e42023-06-27 17:05:02 -070033 const sp<Client>& client,
Ytai Ben-Tsvi9cd89812020-07-01 17:12:06 -070034 const sp<media::IEffectClient>& effectClient,
Andy Hung8e6b62a2023-07-13 18:11:33 -070035 const std::map<audio_patch_handle_t, IAfPatchPanel::Patch>& patches,
Eric Laurentb82e6b72019-11-22 17:25:04 -080036 int *enabled,
Eric Laurent2fe0acd2020-03-13 14:30:46 -070037 status_t *status,
Eric Laurentde8caf42021-08-11 17:19:25 +020038 bool probe,
39 bool notifyFramesProcessed);
Eric Laurentb82e6b72019-11-22 17:25:04 -080040
Andy Hung6ac17eb2023-06-20 18:56:17 -070041 size_t removeEffect(const sp<IAfDeviceEffectProxy>& effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -080042 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
43 int32_t sessionId, int32_t deviceId,
44 sp<EffectHalInterface> *effect);
Mikhail Naganovd2c7f852023-06-14 18:00:13 -070045 status_t addEffectToHal(const struct audio_port_config *device,
Andy Hung55a74fd2023-07-13 19:54:47 -070046 const sp<EffectHalInterface>& effect);
Mikhail Naganovd2c7f852023-06-14 18:00:13 -070047 status_t removeEffectFromHal(const struct audio_port_config *device,
Andy Hung55a74fd2023-07-13 19:54:47 -070048 const sp<EffectHalInterface>& effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -080049
50 AudioFlinger& audioFlinger() const { return mAudioFlinger; }
51
52 void dump(int fd);
53
Vlad Popa5161f8a2022-10-10 16:17:20 +020054 // PatchCommandThread::PatchCommandListener implementation
55
56 void onCreateAudioPatch(audio_patch_handle_t handle,
Andy Hung55a74fd2023-07-13 19:54:47 -070057 const IAfPatchPanel::Patch& patch) final;
58 void onReleaseAudioPatch(audio_patch_handle_t handle) final;
François Gaffie58e73af2023-02-15 11:47:24 +010059 void onUpdateAudioPatch(audio_patch_handle_t oldHandle,
60 audio_patch_handle_t newHandle,
Andy Hung55a74fd2023-07-13 19:54:47 -070061 const IAfPatchPanel::Patch& patch) final;
Vlad Popa5161f8a2022-10-10 16:17:20 +020062
Eric Laurentb82e6b72019-11-22 17:25:04 -080063private:
Eric Laurentb82e6b72019-11-22 17:25:04 -080064 status_t checkEffectCompatibility(const effect_descriptor_t *desc);
65
66 Mutex mLock;
Eric Laurentb82e6b72019-11-22 17:25:04 -080067 AudioFlinger &mAudioFlinger;
68 const sp<DeviceEffectManagerCallback> mMyCallback;
François Gaffie0f660582023-06-27 15:15:26 +020069 std::map<AudioDeviceTypeAddr, std::vector<sp<IAfDeviceEffectProxy>>> mDeviceEffects;
Eric Laurentb82e6b72019-11-22 17:25:04 -080070};
71
Vlad Popa5161f8a2022-10-10 16:17:20 +020072class DeviceEffectManagerCallback : public EffectCallbackInterface {
Eric Laurentb82e6b72019-11-22 17:25:04 -080073public:
Andy Hung920f6572022-10-06 12:09:49 -070074 explicit DeviceEffectManagerCallback(DeviceEffectManager& manager)
Vlad Popa5161f8a2022-10-10 16:17:20 +020075 : mManager(manager) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -080076
77 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
78 int32_t sessionId, int32_t deviceId,
79 sp<EffectHalInterface> *effect) override {
80 return mManager.createEffectHal(pEffectUuid, sessionId, deviceId, effect);
81 }
82 status_t allocateHalBuffer(size_t size __unused,
83 sp<EffectBufferHalInterface>* buffer __unused) override { return NO_ERROR; }
Andy Hung6ac17eb2023-06-20 18:56:17 -070084 bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect __unused) override {
85 return false;
86 }
Eric Laurentb82e6b72019-11-22 17:25:04 -080087
88 audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; }
89 bool isOutput() const override { return false; }
90 bool isOffload() const override { return false; }
91 bool isOffloadOrDirect() const override { return false; }
92 bool isOffloadOrMmap() const override { return false; }
Eric Laurentb62d0362021-10-26 17:40:18 +020093 bool isSpatializer() const override { return false; }
Eric Laurentb82e6b72019-11-22 17:25:04 -080094
95 uint32_t sampleRate() const override { return 0; }
Eric Laurentf1f22e72021-07-13 14:04:14 +020096 audio_channel_mask_t inChannelMask(int id __unused) const override {
97 return AUDIO_CHANNEL_NONE;
98 }
99 uint32_t inChannelCount(int id __unused) const override { return 0; }
100 audio_channel_mask_t outChannelMask() const override { return AUDIO_CHANNEL_NONE; }
101 uint32_t outChannelCount() const override { return 0; }
102
jiabineb3bda02020-06-30 14:07:03 -0700103 audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800104 size_t frameCount() const override { return 0; }
105 uint32_t latency() const override { return 0; }
106
Andy Hung920f6572022-10-06 12:09:49 -0700107 status_t addEffectToHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800108 return NO_ERROR;
109 }
Andy Hung920f6572022-10-06 12:09:49 -0700110 status_t removeEffectFromHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800111 return NO_ERROR;
112 }
113
Andy Hung6ac17eb2023-06-20 18:56:17 -0700114 bool disconnectEffectHandle(IAfEffectHandle *handle, bool unpinIfLast) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800115 void setVolumeForOutput(float left __unused, float right __unused) const override {}
116
117 // check if effects should be suspended or restored when a given effect is enable or disabled
Andy Hung6ac17eb2023-06-20 18:56:17 -0700118 void checkSuspendOnEffectEnabled(const sp<IAfEffectBase>& effect __unused,
Eric Laurentb82e6b72019-11-22 17:25:04 -0800119 bool enabled __unused, bool threadLocked __unused) override {}
120 void resetVolume() override {}
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800121 product_strategy_t strategy() const override { return static_cast<product_strategy_t>(0); }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800122 int32_t activeTrackCnt() const override { return 0; }
Andy Hung6ac17eb2023-06-20 18:56:17 -0700123 void onEffectEnable(const sp<IAfEffectBase>& effect __unused) override {}
124 void onEffectDisable(const sp<IAfEffectBase>& effect __unused) override {}
Eric Laurentb82e6b72019-11-22 17:25:04 -0800125
Andy Hung6ac17eb2023-06-20 18:56:17 -0700126 wp<IAfEffectChain> chain() const override { return nullptr; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800127
Andy Hung55a74fd2023-07-13 19:54:47 -0700128 bool isAudioPolicyReady() const final;
Eric Laurentd66d7a12021-07-13 13:35:32 +0200129
Andy Hung55a74fd2023-07-13 19:54:47 -0700130 int newEffectId() const;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800131
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700132 status_t addEffectToHal(const struct audio_port_config *device,
133 const sp<EffectHalInterface>& effect) {
134 return mManager.addEffectToHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -0800135 }
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700136 status_t removeEffectFromHal(const struct audio_port_config *device,
137 const sp<EffectHalInterface>& effect) {
138 return mManager.removeEffectFromHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -0800139 }
140private:
141 DeviceEffectManager& mManager;
142};
Andy Hung55a74fd2023-07-13 19:54:47 -0700143
144} // namespace android