Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 1 | /* |
| 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 Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 18 | #pragma once |
| 19 | |
| 20 | namespace android { |
| 21 | |
| 22 | class DeviceEffectManagerCallback; |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 23 | |
| 24 | // DeviceEffectManager is concealed within AudioFlinger, their lifetimes are the same. |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame] | 25 | class DeviceEffectManager : public PatchCommandThread::PatchCommandListener { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 26 | public: |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 27 | explicit DeviceEffectManager(AudioFlinger& audioFlinger); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 28 | |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 29 | void onFirstRef() override; |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 30 | |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 31 | sp<IAfEffectHandle> createEffect_l(effect_descriptor_t *descriptor, |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 32 | const AudioDeviceTypeAddr& device, |
Andy Hung | 59867e4 | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 33 | const sp<Client>& client, |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 34 | const sp<media::IEffectClient>& effectClient, |
Andy Hung | 8e6b62a | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 35 | const std::map<audio_patch_handle_t, IAfPatchPanel::Patch>& patches, |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 36 | int *enabled, |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 37 | status_t *status, |
Eric Laurent | de8caf4 | 2021-08-11 17:19:25 +0200 | [diff] [blame] | 38 | bool probe, |
| 39 | bool notifyFramesProcessed); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 40 | |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 41 | size_t removeEffect(const sp<IAfDeviceEffectProxy>& effect); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 42 | status_t createEffectHal(const effect_uuid_t *pEffectUuid, |
| 43 | int32_t sessionId, int32_t deviceId, |
| 44 | sp<EffectHalInterface> *effect); |
Mikhail Naganov | d2c7f85 | 2023-06-14 18:00:13 -0700 | [diff] [blame] | 45 | status_t addEffectToHal(const struct audio_port_config *device, |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 46 | const sp<EffectHalInterface>& effect); |
Mikhail Naganov | d2c7f85 | 2023-06-14 18:00:13 -0700 | [diff] [blame] | 47 | status_t removeEffectFromHal(const struct audio_port_config *device, |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 48 | const sp<EffectHalInterface>& effect); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 49 | |
| 50 | AudioFlinger& audioFlinger() const { return mAudioFlinger; } |
| 51 | |
| 52 | void dump(int fd); |
| 53 | |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame] | 54 | // PatchCommandThread::PatchCommandListener implementation |
| 55 | |
| 56 | void onCreateAudioPatch(audio_patch_handle_t handle, |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 57 | const IAfPatchPanel::Patch& patch) final; |
| 58 | void onReleaseAudioPatch(audio_patch_handle_t handle) final; |
François Gaffie | 58e73af | 2023-02-15 11:47:24 +0100 | [diff] [blame] | 59 | void onUpdateAudioPatch(audio_patch_handle_t oldHandle, |
| 60 | audio_patch_handle_t newHandle, |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 61 | const IAfPatchPanel::Patch& patch) final; |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame] | 62 | |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 63 | private: |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 64 | status_t checkEffectCompatibility(const effect_descriptor_t *desc); |
| 65 | |
| 66 | Mutex mLock; |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 67 | AudioFlinger &mAudioFlinger; |
| 68 | const sp<DeviceEffectManagerCallback> mMyCallback; |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 69 | std::map<AudioDeviceTypeAddr, std::vector<sp<IAfDeviceEffectProxy>>> mDeviceEffects; |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame] | 72 | class DeviceEffectManagerCallback : public EffectCallbackInterface { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 73 | public: |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 74 | explicit DeviceEffectManagerCallback(DeviceEffectManager& manager) |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame] | 75 | : mManager(manager) {} |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 76 | |
| 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 Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 84 | bool updateOrphanEffectChains(const sp<IAfEffectBase>& effect __unused) override { |
| 85 | return false; |
| 86 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 87 | |
| 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 Laurent | b62d036 | 2021-10-26 17:40:18 +0200 | [diff] [blame] | 93 | bool isSpatializer() const override { return false; } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 94 | |
| 95 | uint32_t sampleRate() const override { return 0; } |
Eric Laurent | f1f22e7 | 2021-07-13 14:04:14 +0200 | [diff] [blame] | 96 | 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 | |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 103 | audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 104 | size_t frameCount() const override { return 0; } |
| 105 | uint32_t latency() const override { return 0; } |
| 106 | |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 107 | status_t addEffectToHal(const sp<EffectHalInterface>& /* effect */) override { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 108 | return NO_ERROR; |
| 109 | } |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 110 | status_t removeEffectFromHal(const sp<EffectHalInterface>& /* effect */) override { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 111 | return NO_ERROR; |
| 112 | } |
| 113 | |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 114 | bool disconnectEffectHandle(IAfEffectHandle *handle, bool unpinIfLast) override; |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 115 | 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 Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 118 | void checkSuspendOnEffectEnabled(const sp<IAfEffectBase>& effect __unused, |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 119 | bool enabled __unused, bool threadLocked __unused) override {} |
| 120 | void resetVolume() override {} |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 121 | product_strategy_t strategy() const override { return static_cast<product_strategy_t>(0); } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 122 | int32_t activeTrackCnt() const override { return 0; } |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 123 | void onEffectEnable(const sp<IAfEffectBase>& effect __unused) override {} |
| 124 | void onEffectDisable(const sp<IAfEffectBase>& effect __unused) override {} |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 125 | |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 126 | wp<IAfEffectChain> chain() const override { return nullptr; } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 127 | |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 128 | bool isAudioPolicyReady() const final; |
Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 129 | |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 130 | int newEffectId() const; |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 131 | |
Mikhail Naganov | d2c7f85 | 2023-06-14 18:00:13 -0700 | [diff] [blame] | 132 | status_t addEffectToHal(const struct audio_port_config *device, |
| 133 | const sp<EffectHalInterface>& effect) { |
| 134 | return mManager.addEffectToHal(device, effect); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 135 | } |
Mikhail Naganov | d2c7f85 | 2023-06-14 18:00:13 -0700 | [diff] [blame] | 136 | status_t removeEffectFromHal(const struct audio_port_config *device, |
| 137 | const sp<EffectHalInterface>& effect) { |
| 138 | return mManager.removeEffectFromHal(device, effect); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 139 | } |
| 140 | private: |
| 141 | DeviceEffectManager& mManager; |
| 142 | }; |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame^] | 143 | |
| 144 | } // namespace android |