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 | |
| 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 Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame^] | 23 | class DeviceEffectManager : public PatchCommandThread::PatchCommandListener { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 24 | public: |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame^] | 25 | explicit DeviceEffectManager(AudioFlinger& audioFlinger) |
| 26 | : mAudioFlinger(audioFlinger), |
| 27 | mMyCallback(new DeviceEffectManagerCallback(*this)) {} |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 28 | |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame^] | 29 | void onFirstRef() override { |
| 30 | mAudioFlinger.mPatchCommandThread->addListener(this); |
| 31 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 32 | |
| 33 | sp<EffectHandle> createEffect_l(effect_descriptor_t *descriptor, |
| 34 | const AudioDeviceTypeAddr& device, |
| 35 | const sp<AudioFlinger::Client>& client, |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 36 | const sp<media::IEffectClient>& effectClient, |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 37 | const std::map<audio_patch_handle_t, PatchPanel::Patch>& patches, |
| 38 | int *enabled, |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 39 | status_t *status, |
Eric Laurent | de8caf4 | 2021-08-11 17:19:25 +0200 | [diff] [blame] | 40 | bool probe, |
| 41 | bool notifyFramesProcessed); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 42 | |
| 43 | size_t removeEffect(const sp<DeviceEffectProxy>& effect); |
| 44 | status_t createEffectHal(const effect_uuid_t *pEffectUuid, |
| 45 | int32_t sessionId, int32_t deviceId, |
| 46 | sp<EffectHalInterface> *effect); |
| 47 | status_t addEffectToHal(audio_port_handle_t deviceId, audio_module_handle_t hwModuleId, |
| 48 | sp<EffectHalInterface> effect) { |
| 49 | return mAudioFlinger.addEffectToHal(deviceId, hwModuleId, effect); |
| 50 | }; |
| 51 | status_t removeEffectFromHal(audio_port_handle_t deviceId, audio_module_handle_t hwModuleId, |
| 52 | sp<EffectHalInterface> effect) { |
| 53 | return mAudioFlinger.removeEffectFromHal(deviceId, hwModuleId, effect); |
| 54 | }; |
| 55 | |
| 56 | AudioFlinger& audioFlinger() const { return mAudioFlinger; } |
| 57 | |
| 58 | void dump(int fd); |
| 59 | |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame^] | 60 | // PatchCommandThread::PatchCommandListener implementation |
| 61 | |
| 62 | void onCreateAudioPatch(audio_patch_handle_t handle, |
| 63 | const PatchPanel::Patch& patch) override; |
| 64 | void onReleaseAudioPatch(audio_patch_handle_t handle) override; |
| 65 | |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 66 | private: |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 67 | status_t checkEffectCompatibility(const effect_descriptor_t *desc); |
| 68 | |
| 69 | Mutex mLock; |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 70 | AudioFlinger &mAudioFlinger; |
| 71 | const sp<DeviceEffectManagerCallback> mMyCallback; |
| 72 | std::map<AudioDeviceTypeAddr, sp<DeviceEffectProxy>> mDeviceEffects; |
| 73 | }; |
| 74 | |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame^] | 75 | class DeviceEffectManagerCallback : public EffectCallbackInterface { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 76 | public: |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame^] | 77 | DeviceEffectManagerCallback(DeviceEffectManager& manager) |
| 78 | : mManager(manager) {} |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 79 | |
| 80 | status_t createEffectHal(const effect_uuid_t *pEffectUuid, |
| 81 | int32_t sessionId, int32_t deviceId, |
| 82 | sp<EffectHalInterface> *effect) override { |
| 83 | return mManager.createEffectHal(pEffectUuid, sessionId, deviceId, effect); |
| 84 | } |
| 85 | status_t allocateHalBuffer(size_t size __unused, |
| 86 | sp<EffectBufferHalInterface>* buffer __unused) override { return NO_ERROR; } |
| 87 | bool updateOrphanEffectChains(const sp<EffectBase>& effect __unused) override { return false; } |
| 88 | |
| 89 | audio_io_handle_t io() const override { return AUDIO_IO_HANDLE_NONE; } |
| 90 | bool isOutput() const override { return false; } |
| 91 | bool isOffload() const override { return false; } |
| 92 | bool isOffloadOrDirect() const override { return false; } |
| 93 | bool isOffloadOrMmap() const override { return false; } |
Eric Laurent | b62d036 | 2021-10-26 17:40:18 +0200 | [diff] [blame] | 94 | bool isSpatializer() const override { return false; } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 95 | |
| 96 | uint32_t sampleRate() const override { return 0; } |
Eric Laurent | f1f22e7 | 2021-07-13 14:04:14 +0200 | [diff] [blame] | 97 | audio_channel_mask_t inChannelMask(int id __unused) const override { |
| 98 | return AUDIO_CHANNEL_NONE; |
| 99 | } |
| 100 | uint32_t inChannelCount(int id __unused) const override { return 0; } |
| 101 | audio_channel_mask_t outChannelMask() const override { return AUDIO_CHANNEL_NONE; } |
| 102 | uint32_t outChannelCount() const override { return 0; } |
| 103 | |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 104 | audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 105 | size_t frameCount() const override { return 0; } |
| 106 | uint32_t latency() const override { return 0; } |
| 107 | |
| 108 | status_t addEffectToHal(sp<EffectHalInterface> effect __unused) override { |
| 109 | return NO_ERROR; |
| 110 | } |
| 111 | status_t removeEffectFromHal(sp<EffectHalInterface> effect __unused) override { |
| 112 | return NO_ERROR; |
| 113 | } |
| 114 | |
| 115 | bool disconnectEffectHandle(EffectHandle *handle, bool unpinIfLast) override; |
| 116 | void setVolumeForOutput(float left __unused, float right __unused) const override {} |
| 117 | |
| 118 | // check if effects should be suspended or restored when a given effect is enable or disabled |
| 119 | void checkSuspendOnEffectEnabled(const sp<EffectBase>& effect __unused, |
| 120 | bool enabled __unused, bool threadLocked __unused) override {} |
| 121 | void resetVolume() override {} |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 122 | 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] | 123 | int32_t activeTrackCnt() const override { return 0; } |
| 124 | void onEffectEnable(const sp<EffectBase>& effect __unused) override {} |
| 125 | void onEffectDisable(const sp<EffectBase>& effect __unused) override {} |
| 126 | |
| 127 | wp<EffectChain> chain() const override { return nullptr; } |
| 128 | |
Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 129 | bool isAudioPolicyReady() const override { |
| 130 | return mManager.audioFlinger().isAudioPolicyReady(); |
| 131 | } |
| 132 | |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 133 | int newEffectId() { return mManager.audioFlinger().nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT); } |
| 134 | |
| 135 | status_t addEffectToHal(audio_port_handle_t deviceId, |
| 136 | audio_module_handle_t hwModuleId, sp<EffectHalInterface> effect) { |
| 137 | return mManager.addEffectToHal(deviceId, hwModuleId, effect); |
| 138 | } |
| 139 | status_t removeEffectFromHal(audio_port_handle_t deviceId, |
| 140 | audio_module_handle_t hwModuleId, sp<EffectHalInterface> effect) { |
| 141 | return mManager.removeEffectFromHal(deviceId, hwModuleId, effect); |
| 142 | } |
| 143 | private: |
| 144 | DeviceEffectManager& mManager; |
| 145 | }; |