blob: b09de773c3648cce72e1ca7f94f2e7fb5c90106f [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
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 Hungdf397962023-07-13 19:54:47 -070027 explicit DeviceEffectManager(AudioFlinger& audioFlinger);
Eric Laurentb82e6b72019-11-22 17:25:04 -080028
Andy Hungdf397962023-07-13 19:54:47 -070029 void onFirstRef() override;
Eric Laurentb82e6b72019-11-22 17:25:04 -080030
Andy Hung116bc262023-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 Hung88035ac2023-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 Hungc0ab56b2023-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 Hung116bc262023-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 Hungdf397962023-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 Hungdf397962023-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 Hungdf397962023-07-13 19:54:47 -070057 const IAfPatchPanel::Patch& patch) final;
58 void onReleaseAudioPatch(audio_patch_handle_t handle) final;
Vlad Popa5161f8a2022-10-10 16:17:20 +020059
Eric Laurentb82e6b72019-11-22 17:25:04 -080060private:
Eric Laurentb82e6b72019-11-22 17:25:04 -080061 status_t checkEffectCompatibility(const effect_descriptor_t *desc);
62
63 Mutex mLock;
Eric Laurentb82e6b72019-11-22 17:25:04 -080064 AudioFlinger &mAudioFlinger;
65 const sp<DeviceEffectManagerCallback> mMyCallback;
Andy Hung116bc262023-06-20 18:56:17 -070066 std::map<AudioDeviceTypeAddr, sp<IAfDeviceEffectProxy>> mDeviceEffects;
Eric Laurentb82e6b72019-11-22 17:25:04 -080067};
68
Vlad Popa5161f8a2022-10-10 16:17:20 +020069class DeviceEffectManagerCallback : public EffectCallbackInterface {
Eric Laurentb82e6b72019-11-22 17:25:04 -080070public:
Andy Hung920f6572022-10-06 12:09:49 -070071 explicit DeviceEffectManagerCallback(DeviceEffectManager& manager)
Vlad Popa5161f8a2022-10-10 16:17:20 +020072 : mManager(manager) {}
Eric Laurentb82e6b72019-11-22 17:25:04 -080073
74 status_t createEffectHal(const effect_uuid_t *pEffectUuid,
75 int32_t sessionId, int32_t deviceId,
76 sp<EffectHalInterface> *effect) override {
77 return mManager.createEffectHal(pEffectUuid, sessionId, deviceId, effect);
78 }
79 status_t allocateHalBuffer(size_t size __unused,
80 sp<EffectBufferHalInterface>* buffer __unused) override { return NO_ERROR; }
Andy Hung116bc262023-06-20 18:56:17 -070081 bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect __unused) override {
82 return false;
83 }
Eric Laurentb82e6b72019-11-22 17:25:04 -080084
85 audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; }
86 bool isOutput() const override { return false; }
87 bool isOffload() const override { return false; }
88 bool isOffloadOrDirect() const override { return false; }
89 bool isOffloadOrMmap() const override { return false; }
Eric Laurentb62d0362021-10-26 17:40:18 +020090 bool isSpatializer() const override { return false; }
Eric Laurentb82e6b72019-11-22 17:25:04 -080091
92 uint32_t sampleRate() const override { return 0; }
Eric Laurentf1f22e72021-07-13 14:04:14 +020093 audio_channel_mask_t inChannelMask(int id __unused) const override {
94 return AUDIO_CHANNEL_NONE;
95 }
96 uint32_t inChannelCount(int id __unused) const override { return 0; }
97 audio_channel_mask_t outChannelMask() const override { return AUDIO_CHANNEL_NONE; }
98 uint32_t outChannelCount() const override { return 0; }
99
jiabineb3bda02020-06-30 14:07:03 -0700100 audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800101 size_t frameCount() const override { return 0; }
102 uint32_t latency() const override { return 0; }
103
Andy Hung920f6572022-10-06 12:09:49 -0700104 status_t addEffectToHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800105 return NO_ERROR;
106 }
Andy Hung920f6572022-10-06 12:09:49 -0700107 status_t removeEffectFromHal(const sp<EffectHalInterface>& /* effect */) override {
Eric Laurentb82e6b72019-11-22 17:25:04 -0800108 return NO_ERROR;
109 }
110
Andy Hung116bc262023-06-20 18:56:17 -0700111 bool disconnectEffectHandle(IAfEffectHandle *handle, bool unpinIfLast) override;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800112 void setVolumeForOutput(float left __unused, float right __unused) const override {}
113
114 // check if effects should be suspended or restored when a given effect is enable or disabled
Andy Hung116bc262023-06-20 18:56:17 -0700115 void checkSuspendOnEffectEnabled(const sp<IAfEffectBase>& effect __unused,
Eric Laurentb82e6b72019-11-22 17:25:04 -0800116 bool enabled __unused, bool threadLocked __unused) override {}
117 void resetVolume() override {}
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -0800118 product_strategy_t strategy() const override { return static_cast<product_strategy_t>(0); }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800119 int32_t activeTrackCnt() const override { return 0; }
Andy Hung116bc262023-06-20 18:56:17 -0700120 void onEffectEnable(const sp<IAfEffectBase>& effect __unused) override {}
121 void onEffectDisable(const sp<IAfEffectBase>& effect __unused) override {}
Eric Laurentb82e6b72019-11-22 17:25:04 -0800122
Andy Hung116bc262023-06-20 18:56:17 -0700123 wp<IAfEffectChain> chain() const override { return nullptr; }
Eric Laurentb82e6b72019-11-22 17:25:04 -0800124
Andy Hungdf397962023-07-13 19:54:47 -0700125 bool isAudioPolicyReady() const final;
Eric Laurentd66d7a12021-07-13 13:35:32 +0200126
Andy Hungdf397962023-07-13 19:54:47 -0700127 int newEffectId() const;
Eric Laurentb82e6b72019-11-22 17:25:04 -0800128
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700129 status_t addEffectToHal(const struct audio_port_config *device,
130 const sp<EffectHalInterface>& effect) {
131 return mManager.addEffectToHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -0800132 }
Mikhail Naganovd2c7f852023-06-14 18:00:13 -0700133 status_t removeEffectFromHal(const struct audio_port_config *device,
134 const sp<EffectHalInterface>& effect) {
135 return mManager.removeEffectFromHal(device, effect);
Eric Laurentb82e6b72019-11-22 17:25:04 -0800136 }
137private:
138 DeviceEffectManager& mManager;
139};
Andy Hungdf397962023-07-13 19:54:47 -0700140
141} // namespace android