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 | #define LOG_TAG "DeviceEffectManager" |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
| 20 | |
Andy Hung | 0a51b5c | 2023-07-18 20:54:44 -0700 | [diff] [blame] | 21 | #include "DeviceEffectManager.h" |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 22 | |
Andy Hung | ba8e52b | 2023-05-11 14:33:03 -0700 | [diff] [blame] | 23 | #include "EffectConfiguration.h" |
Andy Hung | 0a51b5c | 2023-07-18 20:54:44 -0700 | [diff] [blame] | 24 | |
Atneya Nair | f94040f | 2024-10-07 16:00:49 -0700 | [diff] [blame] | 25 | #include <afutils/FallibleLockGuard.h> |
Andy Hung | 0a51b5c | 2023-07-18 20:54:44 -0700 | [diff] [blame] | 26 | #include <audio_utils/primitives.h> |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 27 | #include <media/audiohal/EffectsFactoryHalInterface.h> |
Andy Hung | 0a51b5c | 2023-07-18 20:54:44 -0700 | [diff] [blame] | 28 | #include <utils/Log.h> |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 29 | |
| 30 | // ---------------------------------------------------------------------------- |
| 31 | |
| 32 | |
| 33 | namespace android { |
| 34 | |
Shunkai Yao | d7ea409 | 2022-12-12 00:44:33 +0000 | [diff] [blame] | 35 | using detail::AudioHalVersionInfo; |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 36 | using media::IEffectClient; |
| 37 | |
Andy Hung | 692f045 | 2023-07-17 13:45:55 -0700 | [diff] [blame] | 38 | DeviceEffectManager::DeviceEffectManager( |
| 39 | const sp<IAfDeviceEffectManagerCallback>& afDeviceEffectManagerCallback) |
| 40 | : mAfDeviceEffectManagerCallback(afDeviceEffectManagerCallback), |
Andy Hung | 3e07ef0 | 2023-09-06 17:37:34 -0700 | [diff] [blame] | 41 | mMyCallback(sp<DeviceEffectManagerCallback>::make(*this)) {} |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 42 | |
| 43 | void DeviceEffectManager::onFirstRef() { |
Andy Hung | 692f045 | 2023-07-17 13:45:55 -0700 | [diff] [blame] | 44 | mAfDeviceEffectManagerCallback->getPatchCommandThread()->addListener(this); |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | status_t DeviceEffectManager::addEffectToHal(const struct audio_port_config* device, |
| 48 | const sp<EffectHalInterface>& effect) { |
Andy Hung | 692f045 | 2023-07-17 13:45:55 -0700 | [diff] [blame] | 49 | return mAfDeviceEffectManagerCallback->addEffectToHal(device, effect); |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | status_t DeviceEffectManager::removeEffectFromHal(const struct audio_port_config* device, |
| 53 | const sp<EffectHalInterface>& effect) { |
Andy Hung | 692f045 | 2023-07-17 13:45:55 -0700 | [diff] [blame] | 54 | return mAfDeviceEffectManagerCallback->removeEffectFromHal(device, effect); |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | void DeviceEffectManager::onCreateAudioPatch(audio_patch_handle_t handle, |
Andy Hung | 8e6b62a | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 58 | const IAfPatchPanel::Patch& patch) { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 59 | ALOGV("%s handle %d mHalHandle %d device sink %08x", |
| 60 | __func__, handle, patch.mHalHandle, |
| 61 | patch.mAudioPatch.num_sinks > 0 ? patch.mAudioPatch.sinks[0].ext.device.type : 0); |
Andy Hung | f65f5a7 | 2023-08-29 12:19:17 -0700 | [diff] [blame] | 62 | audio_utils::lock_guard _l(mutex()); |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 63 | for (auto& effectProxies : mDeviceEffects) { |
| 64 | for (auto& effect : effectProxies.second) { |
Andy Hung | 8e6b62a | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 65 | const status_t status = effect->onCreatePatch(handle, patch); |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 66 | ALOGV("%s Effect onCreatePatch status %d", __func__, status); |
| 67 | ALOGW_IF(status == BAD_VALUE, "%s onCreatePatch error %d", __func__, status); |
| 68 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 72 | void DeviceEffectManager::onReleaseAudioPatch(audio_patch_handle_t handle) { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 73 | ALOGV("%s", __func__); |
François Gaffie | fce3b6c | 2024-05-23 13:52:23 +0200 | [diff] [blame] | 74 | // Keep a reference on disconnected handle to delay destruction without lock held. |
| 75 | std::vector<sp<IAfEffectHandle>> disconnectedHandles{}; |
Andy Hung | f65f5a7 | 2023-08-29 12:19:17 -0700 | [diff] [blame] | 76 | audio_utils::lock_guard _l(mutex()); |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 77 | for (auto& effectProxies : mDeviceEffects) { |
| 78 | for (auto& effect : effectProxies.second) { |
François Gaffie | fce3b6c | 2024-05-23 13:52:23 +0200 | [diff] [blame] | 79 | sp<IAfEffectHandle> disconnectedHandle = effect->onReleasePatch(handle); |
| 80 | if (disconnectedHandle != nullptr) { |
| 81 | disconnectedHandles.push_back(std::move(disconnectedHandle)); |
| 82 | } |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 83 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 87 | void DeviceEffectManager::onUpdateAudioPatch(audio_patch_handle_t oldHandle, |
Andy Hung | 8e6b62a | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 88 | audio_patch_handle_t newHandle, const IAfPatchPanel::Patch& patch) { |
François Gaffie | 58e73af | 2023-02-15 11:47:24 +0100 | [diff] [blame] | 89 | ALOGV("%s oldhandle %d newHandle %d mHalHandle %d device sink %08x", |
| 90 | __func__, oldHandle, newHandle, patch.mHalHandle, |
| 91 | patch.mAudioPatch.num_sinks > 0 ? patch.mAudioPatch.sinks[0].ext.device.type : 0); |
Andy Hung | f65f5a7 | 2023-08-29 12:19:17 -0700 | [diff] [blame] | 92 | audio_utils::lock_guard _l(mutex()); |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 93 | for (auto& effectProxies : mDeviceEffects) { |
| 94 | for (auto& effect : effectProxies.second) { |
Andy Hung | 8e6b62a | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 95 | const status_t status = effect->onUpdatePatch(oldHandle, newHandle, patch); |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 96 | ALOGV("%s Effect onUpdatePatch status %d", __func__, status); |
| 97 | ALOGW_IF(status != NO_ERROR, "%s onUpdatePatch error %d", __func__, status); |
| 98 | } |
François Gaffie | 58e73af | 2023-02-15 11:47:24 +0100 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
Andy Hung | f65f5a7 | 2023-08-29 12:19:17 -0700 | [diff] [blame] | 102 | // DeviceEffectManager::createEffect_l() must be called with AudioFlinger::mutex() held |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 103 | sp<IAfEffectHandle> DeviceEffectManager::createEffect_l( |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 104 | effect_descriptor_t *descriptor, |
| 105 | const AudioDeviceTypeAddr& device, |
Andy Hung | 59867e4 | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 106 | const sp<Client>& client, |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 107 | const sp<IEffectClient>& effectClient, |
Andy Hung | 8e6b62a | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 108 | const std::map<audio_patch_handle_t, IAfPatchPanel::Patch>& patches, |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 109 | int *enabled, |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 110 | status_t *status, |
Eric Laurent | de8caf4 | 2021-08-11 17:19:25 +0200 | [diff] [blame] | 111 | bool probe, |
| 112 | bool notifyFramesProcessed) { |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 113 | sp<IAfDeviceEffectProxy> effect; |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 114 | std::vector<sp<IAfDeviceEffectProxy>> effectsForDevice = {}; |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 115 | sp<IAfEffectHandle> handle; |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 116 | status_t lStatus; |
| 117 | |
| 118 | lStatus = checkEffectCompatibility(descriptor); |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 119 | if (probe || lStatus != NO_ERROR) { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 120 | *status = lStatus; |
| 121 | return handle; |
| 122 | } |
| 123 | |
| 124 | { |
Andy Hung | f65f5a7 | 2023-08-29 12:19:17 -0700 | [diff] [blame] | 125 | audio_utils::lock_guard _l(mutex()); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 126 | auto iter = mDeviceEffects.find(device); |
| 127 | if (iter != mDeviceEffects.end()) { |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 128 | effectsForDevice = iter->second; |
| 129 | for (const auto& iterEffect : effectsForDevice) { |
| 130 | if (memcmp(&iterEffect->desc().uuid, &descriptor->uuid, sizeof(effect_uuid_t)) == |
| 131 | 0) { |
| 132 | effect = iterEffect; |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | if (effect == nullptr) { |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 138 | effect = IAfDeviceEffectProxy::create(device, mMyCallback, |
Andy Hung | 692f045 | 2023-07-17 13:45:55 -0700 | [diff] [blame] | 139 | descriptor, |
| 140 | mAfDeviceEffectManagerCallback->nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT), |
Eric Laurent | de8caf4 | 2021-08-11 17:19:25 +0200 | [diff] [blame] | 141 | notifyFramesProcessed); |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 142 | effectsForDevice.push_back(effect); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 143 | } |
| 144 | // create effect handle and connect it to effect module |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 145 | handle = IAfEffectHandle::create( |
| 146 | effect, client, effectClient, 0 /*priority*/, notifyFramesProcessed); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 147 | lStatus = handle->initCheck(); |
| 148 | if (lStatus == NO_ERROR) { |
| 149 | lStatus = effect->addHandle(handle.get()); |
| 150 | if (lStatus == NO_ERROR) { |
Shunkai Yao | d125e40 | 2024-01-20 03:19:06 +0000 | [diff] [blame] | 151 | lStatus = effect->init_l(patches); |
Ram Mohan M | 2a05df2 | 2022-08-28 11:46:23 +0530 | [diff] [blame] | 152 | if (lStatus == NAME_NOT_FOUND) { |
| 153 | lStatus = NO_ERROR; |
| 154 | } |
| 155 | if (lStatus == NO_ERROR || lStatus == ALREADY_EXISTS) { |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 156 | mDeviceEffects.erase(device); |
| 157 | mDeviceEffects.emplace(device, effectsForDevice); |
Ram Mohan M | 2a05df2 | 2022-08-28 11:46:23 +0530 | [diff] [blame] | 158 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | } |
Vlad Popa | 5161f8a | 2022-10-10 16:17:20 +0200 | [diff] [blame] | 162 | if (enabled != nullptr) { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 163 | *enabled = (int)effect->isEnabled(); |
| 164 | } |
| 165 | *status = lStatus; |
| 166 | return handle; |
| 167 | } |
| 168 | |
Andy Hung | 3e07ef0 | 2023-09-06 17:37:34 -0700 | [diff] [blame] | 169 | /* static */ |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 170 | status_t DeviceEffectManager::checkEffectCompatibility( |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 171 | const effect_descriptor_t *desc) { |
Andy Hung | ba8e52b | 2023-05-11 14:33:03 -0700 | [diff] [blame] | 172 | const sp<EffectsFactoryHalInterface> effectsFactory = |
| 173 | audioflinger::EffectConfiguration::getEffectsFactoryHal(); |
Eric Laurent | 9289bde | 2020-08-18 12:49:17 -0700 | [diff] [blame] | 174 | if (effectsFactory == nullptr) { |
| 175 | return BAD_VALUE; |
| 176 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 177 | |
Andy Hung | ba8e52b | 2023-05-11 14:33:03 -0700 | [diff] [blame] | 178 | static const AudioHalVersionInfo sMinDeviceEffectHalVersion = |
Shunkai Yao | d7ea409 | 2022-12-12 00:44:33 +0000 | [diff] [blame] | 179 | AudioHalVersionInfo(AudioHalVersionInfo::Type::HIDL, 6, 0); |
Andy Hung | ba8e52b | 2023-05-11 14:33:03 -0700 | [diff] [blame] | 180 | static const AudioHalVersionInfo halVersion = |
| 181 | audioflinger::EffectConfiguration::getAudioHalVersionInfo(); |
Eric Laurent | 9289bde | 2020-08-18 12:49:17 -0700 | [diff] [blame] | 182 | |
Shunkai Yao | d7ea409 | 2022-12-12 00:44:33 +0000 | [diff] [blame] | 183 | // We can trust AIDL generated AudioHalVersionInfo comparison operator (based on std::tie) as |
| 184 | // long as the type, major and minor sequence doesn't change in the definition. |
Eric Laurent | 9289bde | 2020-08-18 12:49:17 -0700 | [diff] [blame] | 185 | if (((desc->flags & EFFECT_FLAG_TYPE_MASK) != EFFECT_FLAG_TYPE_PRE_PROC |
| 186 | && (desc->flags & EFFECT_FLAG_TYPE_MASK) != EFFECT_FLAG_TYPE_POST_PROC) |
| 187 | || halVersion < sMinDeviceEffectHalVersion) { |
Shunkai Yao | 489c5a9 | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 188 | ALOGW("%s() non pre/post processing device effect %s or incompatible API version %s", |
| 189 | __func__, desc->name, halVersion.toString().c_str()); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 190 | return BAD_VALUE; |
| 191 | } |
| 192 | |
| 193 | return NO_ERROR; |
| 194 | } |
| 195 | |
Andy Hung | 3e07ef0 | 2023-09-06 17:37:34 -0700 | [diff] [blame] | 196 | /* static */ |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 197 | status_t DeviceEffectManager::createEffectHal( |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 198 | const effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t deviceId, |
| 199 | sp<EffectHalInterface> *effect) { |
| 200 | status_t status = NO_INIT; |
Andy Hung | ba8e52b | 2023-05-11 14:33:03 -0700 | [diff] [blame] | 201 | const sp<EffectsFactoryHalInterface> effectsFactory = |
| 202 | audioflinger::EffectConfiguration::getEffectsFactoryHal(); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 203 | if (effectsFactory != 0) { |
| 204 | status = effectsFactory->createEffect( |
| 205 | pEffectUuid, sessionId, AUDIO_IO_HANDLE_NONE, deviceId, effect); |
| 206 | } |
| 207 | return status; |
| 208 | } |
| 209 | |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 210 | void DeviceEffectManager::dump(int fd) |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 211 | { |
Atneya Nair | f94040f | 2024-10-07 16:00:49 -0700 | [diff] [blame] | 212 | afutils::FallibleLockGuard l{mutex()}; |
| 213 | if (!l) { |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 214 | String8 result("DeviceEffectManager may be deadlocked\n"); |
Tomasz Wasilczyk | 833345b | 2023-08-15 20:59:35 +0000 | [diff] [blame] | 215 | write(fd, result.c_str(), result.size()); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Phil Burk | 651d0a5 | 2020-05-08 14:00:58 -0700 | [diff] [blame] | 218 | String8 heading("\nDevice Effects:\n"); |
Tomasz Wasilczyk | 833345b | 2023-08-15 20:59:35 +0000 | [diff] [blame] | 219 | write(fd, heading.c_str(), heading.size()); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 220 | for (const auto& iter : mDeviceEffects) { |
| 221 | String8 outStr; |
| 222 | outStr.appendFormat("%*sEffect for device %s address %s:\n", 2, "", |
| 223 | ::android::toString(iter.first.mType).c_str(), iter.first.getAddress()); |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 224 | for (const auto& effect : iter.second) { |
Tomasz Wasilczyk | 833345b | 2023-08-15 20:59:35 +0000 | [diff] [blame] | 225 | write(fd, outStr.c_str(), outStr.size()); |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 226 | effect->dump2(fd, 4); |
| 227 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 228 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 231 | size_t DeviceEffectManager::removeEffect(const sp<IAfDeviceEffectProxy>& effect) |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 232 | { |
Andy Hung | f65f5a7 | 2023-08-29 12:19:17 -0700 | [diff] [blame] | 233 | audio_utils::lock_guard _l(mutex()); |
François Gaffie | 0f66058 | 2023-06-27 15:15:26 +0200 | [diff] [blame] | 234 | const auto& iter = mDeviceEffects.find(effect->device()); |
| 235 | if (iter != mDeviceEffects.end()) { |
| 236 | const auto& iterEffect = std::find_if( |
| 237 | iter->second.begin(), iter->second.end(), [&effect](const auto& effectProxy) { |
| 238 | return memcmp(&effectProxy->desc().uuid, &effect->desc().uuid, |
| 239 | sizeof(effect_uuid_t)) == 0; |
| 240 | }); |
| 241 | if (iterEffect != iter->second.end()) { |
| 242 | iter->second.erase(iterEffect); |
| 243 | if (iter->second.empty()) { |
| 244 | mDeviceEffects.erase(effect->device()); |
| 245 | } |
| 246 | } |
| 247 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 248 | return mDeviceEffects.size(); |
| 249 | } |
| 250 | |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 251 | bool DeviceEffectManagerCallback::disconnectEffectHandle( |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 252 | IAfEffectHandle *handle, bool unpinIfLast) { |
| 253 | sp<IAfEffectBase> effectBase = handle->effect().promote(); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 254 | if (effectBase == nullptr) { |
| 255 | return false; |
| 256 | } |
| 257 | |
Andy Hung | 6ac17eb | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 258 | sp<IAfDeviceEffectProxy> effect = effectBase->asDeviceEffectProxy(); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 259 | if (effect == nullptr) { |
| 260 | return false; |
| 261 | } |
| 262 | // restore suspended effects if the disconnected handle was enabled and the last one. |
| 263 | bool remove = (effect->removeHandle(handle) == 0) && (!effect->isPinned() || unpinIfLast); |
| 264 | if (remove) { |
| 265 | mManager.removeEffect(effect); |
| 266 | if (handle->enabled()) { |
| 267 | effectBase->checkSuspendOnEffectEnabled(false, false /*threadLocked*/); |
| 268 | } |
| 269 | } |
| 270 | return true; |
| 271 | } |
| 272 | |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 273 | bool DeviceEffectManagerCallback::isAudioPolicyReady() const { |
Andy Hung | 692f045 | 2023-07-17 13:45:55 -0700 | [diff] [blame] | 274 | return mManager.afDeviceEffectManagerCallback()->isAudioPolicyReady(); |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | int DeviceEffectManagerCallback::newEffectId() const { |
Andy Hung | 692f045 | 2023-07-17 13:45:55 -0700 | [diff] [blame] | 278 | return mManager.afDeviceEffectManagerCallback()->nextUniqueId(AUDIO_UNIQUE_ID_USE_EFFECT); |
Andy Hung | 55a74fd | 2023-07-13 19:54:47 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 281 | } // namespace android |