Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2022, 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 | // #define LOG_NDEBUG 0 |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 19 | #define LOG_TAG "MelReporter" |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 20 | |
Andy Hung | ba8b63b | 2023-07-18 18:55:52 -0700 | [diff] [blame] | 21 | #include "MelReporter.h" |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 22 | |
Vlad Popa | 63f047e | 2022-11-05 14:09:19 +0100 | [diff] [blame] | 23 | #include <android/media/ISoundDoseCallback.h> |
Vlad Popa | 2900c0a | 2022-10-24 13:38:00 +0200 | [diff] [blame] | 24 | #include <audio_utils/power.h> |
| 25 | #include <utils/Log.h> |
| 26 | |
Vlad Popa | debe0a7 | 2022-12-28 16:55:13 +0100 | [diff] [blame] | 27 | using aidl::android::hardware::audio::core::sounddose::ISoundDose; |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 28 | |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 29 | namespace android { |
| 30 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 31 | bool MelReporter::activateHalSoundDoseComputation(const std::string& module, |
Vlad Popa | 03bd5bc | 2023-01-17 16:16:51 +0100 | [diff] [blame] | 32 | const sp<DeviceHalInterface>& device) { |
Vlad Popa | 3d6d39d | 2022-12-21 18:59:16 +0100 | [diff] [blame] | 33 | if (mSoundDoseManager->forceUseFrameworkMel()) { |
| 34 | ALOGD("%s: Forcing use of internal MEL computation.", __func__); |
| 35 | activateInternalSoundDoseComputation(); |
| 36 | return false; |
| 37 | } |
| 38 | |
Vlad Popa | 03bd5bc | 2023-01-17 16:16:51 +0100 | [diff] [blame] | 39 | ndk::SpAIBinder soundDoseBinder; |
| 40 | if (device->getSoundDoseInterface(module, &soundDoseBinder) != OK) { |
| 41 | ALOGW("%s: HAL cannot provide sound dose interface for module %s, use internal MEL", |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 42 | __func__, module.c_str()); |
| 43 | activateInternalSoundDoseComputation(); |
| 44 | return false; |
| 45 | } |
| 46 | |
Vlad Popa | 03bd5bc | 2023-01-17 16:16:51 +0100 | [diff] [blame] | 47 | if (soundDoseBinder == nullptr) { |
| 48 | ALOGW("%s: HAL doesn't implement a sound dose interface for module %s, use internal MEL", |
| 49 | __func__, module.c_str()); |
| 50 | activateInternalSoundDoseComputation(); |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | std::shared_ptr<ISoundDose> soundDoseInterface = ISoundDose::fromBinder(soundDoseBinder); |
| 55 | |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 56 | if (!mSoundDoseManager->setHalSoundDoseInterface(soundDoseInterface)) { |
Vlad Popa | 3d6d39d | 2022-12-21 18:59:16 +0100 | [diff] [blame] | 57 | ALOGW("%s: cannot activate HAL MEL reporting for module %s", __func__, module.c_str()); |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 58 | activateInternalSoundDoseComputation(); |
| 59 | return false; |
| 60 | } |
| 61 | |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 62 | stopInternalMelComputation(); |
| 63 | return true; |
| 64 | } |
| 65 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 66 | void MelReporter::activateInternalSoundDoseComputation() { |
Vlad Popa | 3d6d39d | 2022-12-21 18:59:16 +0100 | [diff] [blame] | 67 | { |
| 68 | std::lock_guard _l(mLock); |
| 69 | if (!mUseHalSoundDoseInterface) { |
| 70 | // no need to start internal MEL on active patches |
| 71 | return; |
| 72 | } |
| 73 | mUseHalSoundDoseInterface = false; |
| 74 | } |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 75 | |
Vlad Popa | 3d6d39d | 2022-12-21 18:59:16 +0100 | [diff] [blame] | 76 | mSoundDoseManager->setHalSoundDoseInterface(nullptr); |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 79 | void MelReporter::onFirstRef() { |
Andy Hung | b60a2c8 | 2023-07-17 14:02:52 -0700 | [diff] [blame] | 80 | mAfMelReporterCallback->getPatchCommandThread()->addListener(this); |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 81 | |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 82 | mSoundDoseManager = sp<SoundDoseManager>::make(sp<IMelReporterCallback>::fromExisting(this)); |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 85 | void MelReporter::updateMetadataForCsd(audio_io_handle_t streamHandle, |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 86 | const std::vector<playback_track_metadata_v7_t>& metadataVec) { |
Vlad Popa | 617bbf0 | 2023-04-24 19:10:36 +0200 | [diff] [blame] | 87 | if (!mSoundDoseManager->isCsdEnabled()) { |
Vlad Popa | 2a06fca | 2023-02-06 16:45:45 +0100 | [diff] [blame] | 88 | ALOGV("%s csd is disabled", __func__); |
| 89 | return; |
| 90 | } |
| 91 | |
Andy Hung | b60a2c8 | 2023-07-17 14:02:52 -0700 | [diff] [blame] | 92 | std::lock_guard _laf(mAfMelReporterCallback->mutex()); |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 93 | std::lock_guard _l(mLock); |
| 94 | auto activeMelPatchId = activePatchStreamHandle_l(streamHandle); |
| 95 | if (!activeMelPatchId) { |
| 96 | ALOGV("%s stream handle %d does not have an active patch", __func__, streamHandle); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | bool shouldActivateCsd = false; |
| 101 | for (const auto& metadata : metadataVec) { |
| 102 | if (metadata.base.usage == AUDIO_USAGE_GAME || metadata.base.usage == AUDIO_USAGE_MEDIA) { |
| 103 | shouldActivateCsd = true; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | auto activeMelPatchIt = mActiveMelPatches.find(activeMelPatchId.value()); |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 108 | if (activeMelPatchIt != mActiveMelPatches.end()) { |
| 109 | if (shouldActivateCsd != activeMelPatchIt->second.csdActive) { |
| 110 | if (activeMelPatchIt->second.csdActive) { |
| 111 | ALOGV("%s should not compute CSD for stream handle %d", __func__, streamHandle); |
| 112 | stopMelComputationForPatch_l(activeMelPatchIt->second); |
| 113 | } else { |
| 114 | ALOGV("%s should compute CSD for stream handle %d", __func__, streamHandle); |
| 115 | startMelComputationForActivePatch_l(activeMelPatchIt->second); |
| 116 | } |
| 117 | activeMelPatchIt->second.csdActive = shouldActivateCsd; |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 118 | } |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 122 | void MelReporter::onCreateAudioPatch(audio_patch_handle_t handle, |
Andy Hung | 8e6b62a | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 123 | const IAfPatchPanel::Patch& patch) { |
Vlad Popa | 617bbf0 | 2023-04-24 19:10:36 +0200 | [diff] [blame] | 124 | if (!mSoundDoseManager->isCsdEnabled()) { |
Vlad Popa | 2a06fca | 2023-02-06 16:45:45 +0100 | [diff] [blame] | 125 | ALOGV("%s csd is disabled", __func__); |
| 126 | return; |
| 127 | } |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 128 | |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 129 | ALOGV("%s: handle %d mHalHandle %d device sink %08x", |
| 130 | __func__, handle, patch.mHalHandle, |
| 131 | patch.mAudioPatch.num_sinks > 0 ? patch.mAudioPatch.sinks[0].ext.device.type : 0); |
| 132 | if (patch.mAudioPatch.num_sources == 0 |
| 133 | || patch.mAudioPatch.sources[0].type != AUDIO_PORT_TYPE_MIX) { |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 134 | ALOGV("%s: patch does not contain any mix sources", __func__); |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | |
| 138 | audio_io_handle_t streamHandle = patch.mAudioPatch.sources[0].ext.mix.handle; |
| 139 | ActiveMelPatch newPatch; |
| 140 | newPatch.streamHandle = streamHandle; |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 141 | newPatch.csdActive = false; |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 142 | for (size_t i = 0; i < patch.mAudioPatch.num_sinks; ++i) { |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 143 | if (patch.mAudioPatch.sinks[i].type == AUDIO_PORT_TYPE_DEVICE && |
| 144 | mSoundDoseManager->shouldComputeCsdForDeviceType( |
| 145 | patch.mAudioPatch.sinks[i].ext.device.type)) { |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 146 | audio_port_handle_t deviceId = patch.mAudioPatch.sinks[i].id; |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 147 | bool shouldComputeCsd = mSoundDoseManager->shouldComputeCsdForDeviceWithAddress( |
| 148 | patch.mAudioPatch.sinks[i].ext.device.type, |
| 149 | patch.mAudioPatch.sinks[i].ext.device.address); |
| 150 | newPatch.deviceStates.push_back({deviceId, shouldComputeCsd}); |
| 151 | newPatch.csdActive |= shouldComputeCsd; |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 152 | AudioDeviceTypeAddr adt{patch.mAudioPatch.sinks[i].ext.device.type, |
| 153 | patch.mAudioPatch.sinks[i].ext.device.address}; |
| 154 | mSoundDoseManager->mapAddressToDeviceId(adt, deviceId); |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 158 | if (!newPatch.deviceStates.empty() && newPatch.csdActive) { |
Andy Hung | b60a2c8 | 2023-07-17 14:02:52 -0700 | [diff] [blame] | 159 | std::lock_guard _afl(mAfMelReporterCallback->mutex()); |
Vlad Popa | 1c2f7e1 | 2023-03-28 02:08:56 +0200 | [diff] [blame] | 160 | std::lock_guard _l(mLock); |
| 161 | ALOGV("%s add patch handle %d to active devices", __func__, handle); |
| 162 | startMelComputationForActivePatch_l(newPatch); |
Vlad Popa | 1c2f7e1 | 2023-03-28 02:08:56 +0200 | [diff] [blame] | 163 | mActiveMelPatches[handle] = newPatch; |
| 164 | } |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 167 | void MelReporter::startMelComputationForActivePatch_l(const ActiveMelPatch& patch) |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 168 | NO_THREAD_SAFETY_ANALYSIS // access of AudioFlinger::checkOutputThread_l |
| 169 | { |
Andy Hung | b60a2c8 | 2023-07-17 14:02:52 -0700 | [diff] [blame] | 170 | auto outputThread = mAfMelReporterCallback->checkOutputThread_l(patch.streamHandle); |
Vlad Popa | 6fbbfbf | 2023-02-22 15:05:43 +0100 | [diff] [blame] | 171 | if (outputThread == nullptr) { |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 172 | ALOGE("%s cannot find thread for stream handle %d", __func__, patch.streamHandle); |
| 173 | return; |
| 174 | } |
| 175 | |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 176 | for (const auto& device : patch.deviceStates) { |
| 177 | if (device.second) { |
| 178 | ++mActiveDevices[device.first]; |
| 179 | ALOGI("%s add stream %d that uses device %d for CSD, nr of streams: %d", __func__, |
| 180 | patch.streamHandle, device.first, mActiveDevices[device.first]); |
Vlad Popa | 6fbbfbf | 2023-02-22 15:05:43 +0100 | [diff] [blame] | 181 | |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 182 | if (outputThread != nullptr && !useHalSoundDoseInterface_l()) { |
| 183 | outputThread->startMelComputation_l( |
| 184 | mSoundDoseManager->getOrCreateProcessorForDevice( |
| 185 | device.first, |
| 186 | patch.streamHandle, |
| 187 | outputThread->sampleRate(), |
| 188 | outputThread->channelCount(), |
| 189 | outputThread->format())); |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | void MelReporter::startMelComputationForDeviceId(audio_port_handle_t deviceId) { |
| 196 | ALOGV("%s(%d)", __func__, deviceId); |
| 197 | std::lock_guard _laf(mAfMelReporterCallback->mutex()); |
| 198 | std::lock_guard _l(mLock); |
| 199 | |
| 200 | for (auto& activeMelPatch : mActiveMelPatches) { |
| 201 | bool csdActive = false; |
| 202 | for (auto& device: activeMelPatch.second.deviceStates) { |
| 203 | if (device.first == deviceId && !device.second) { |
| 204 | device.second = true; |
| 205 | } |
| 206 | csdActive |= device.second; |
| 207 | } |
| 208 | if (csdActive && !activeMelPatch.second.csdActive) { |
| 209 | activeMelPatch.second.csdActive = csdActive; |
| 210 | startMelComputationForActivePatch_l(activeMelPatch.second); |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 211 | } |
Vlad Popa | 6fbbfbf | 2023-02-22 15:05:43 +0100 | [diff] [blame] | 212 | } |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 213 | } |
| 214 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 215 | void MelReporter::onReleaseAudioPatch(audio_patch_handle_t handle) { |
Vlad Popa | 617bbf0 | 2023-04-24 19:10:36 +0200 | [diff] [blame] | 216 | if (!mSoundDoseManager->isCsdEnabled()) { |
Vlad Popa | 2a06fca | 2023-02-06 16:45:45 +0100 | [diff] [blame] | 217 | ALOGV("%s csd is disabled", __func__); |
| 218 | return; |
| 219 | } |
| 220 | |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 221 | ActiveMelPatch melPatch; |
| 222 | { |
| 223 | std::lock_guard _l(mLock); |
| 224 | |
| 225 | auto patchIt = mActiveMelPatches.find(handle); |
| 226 | if (patchIt == mActiveMelPatches.end()) { |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 227 | ALOGV("%s patch handle %d does not contain any mix sources with active MEL calculation", |
| 228 | __func__, handle); |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 229 | return; |
| 230 | } |
| 231 | |
| 232 | melPatch = patchIt->second; |
| 233 | mActiveMelPatches.erase(patchIt); |
| 234 | } |
| 235 | |
Andy Hung | b60a2c8 | 2023-07-17 14:02:52 -0700 | [diff] [blame] | 236 | std::lock_guard _afl(mAfMelReporterCallback->mutex()); |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 237 | std::lock_guard _l(mLock); |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 238 | if (melPatch.csdActive) { |
| 239 | // only need to stop if patch was active |
| 240 | melPatch.csdActive = false; |
| 241 | stopMelComputationForPatch_l(melPatch); |
| 242 | } |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 245 | void MelReporter::onUpdateAudioPatch(audio_patch_handle_t oldHandle, |
Andy Hung | 8e6b62a | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 246 | audio_patch_handle_t newHandle, const IAfPatchPanel::Patch& patch) { |
François Gaffie | 58e73af | 2023-02-15 11:47:24 +0100 | [diff] [blame] | 247 | onReleaseAudioPatch(oldHandle); |
| 248 | onCreateAudioPatch(newHandle, patch); |
| 249 | } |
| 250 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 251 | sp<media::ISoundDose> MelReporter::getSoundDoseInterface( |
Vlad Popa | 63f047e | 2022-11-05 14:09:19 +0100 | [diff] [blame] | 252 | const sp<media::ISoundDoseCallback>& callback) { |
Vlad Popa | e3fd1c2 | 2022-11-07 21:03:18 +0100 | [diff] [blame] | 253 | // no need to lock since getSoundDoseInterface is synchronized |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 254 | return mSoundDoseManager->getSoundDoseInterface(callback); |
| 255 | } |
| 256 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 257 | void MelReporter::stopInternalMelComputation() { |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 258 | ALOGV("%s", __func__); |
Vlad Popa | 870f6d6 | 2022-12-22 12:15:47 +0100 | [diff] [blame] | 259 | std::lock_guard _l(mLock); |
| 260 | mActiveMelPatches.clear(); |
| 261 | mUseHalSoundDoseInterface = true; |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 264 | void MelReporter::stopMelComputationForPatch_l(const ActiveMelPatch& patch) |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 265 | NO_THREAD_SAFETY_ANALYSIS // access of AudioFlinger::checkOutputThread_l |
| 266 | { |
Andy Hung | b60a2c8 | 2023-07-17 14:02:52 -0700 | [diff] [blame] | 267 | auto outputThread = mAfMelReporterCallback->checkOutputThread_l(patch.streamHandle); |
Vlad Popa | 6fbbfbf | 2023-02-22 15:05:43 +0100 | [diff] [blame] | 268 | |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 269 | ALOGV("%s: stop MEL for stream id: %d", __func__, patch.streamHandle); |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 270 | for (const auto& device : patch.deviceStates) { |
| 271 | if (mActiveDevices[device.first] > 0) { |
| 272 | --mActiveDevices[device.first]; |
| 273 | if (mActiveDevices[device.first] == 0) { |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 274 | // no stream is using deviceId anymore |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 275 | ALOGI("%s removing device %d from active CSD devices", __func__, device.first); |
| 276 | mSoundDoseManager->clearMapDeviceIdEntries(device.first); |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | } |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 280 | |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 281 | mSoundDoseManager->removeStreamProcessor(patch.streamHandle); |
Vlad Popa | 69fbbee | 2023-04-25 12:23:24 +0200 | [diff] [blame] | 282 | if (outputThread != nullptr && !useHalSoundDoseInterface_l()) { |
Vlad Popa | 6fbbfbf | 2023-02-22 15:05:43 +0100 | [diff] [blame] | 283 | outputThread->stopMelComputation_l(); |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 284 | } |
Vlad Popa | 63f047e | 2022-11-05 14:09:19 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Vlad Popa | f79f6ba | 2023-07-27 18:27:59 -0700 | [diff] [blame^] | 287 | void MelReporter::stopMelComputationForDeviceId(audio_port_handle_t deviceId) { |
| 288 | ALOGV("%s(%d)", __func__, deviceId); |
| 289 | std::lock_guard _laf(mAfMelReporterCallback->mutex()); |
| 290 | std::lock_guard _l(mLock); |
| 291 | |
| 292 | for (auto& activeMelPatch : mActiveMelPatches) { |
| 293 | bool csdActive = false; |
| 294 | for (auto& device: activeMelPatch.second.deviceStates) { |
| 295 | if (device.first == deviceId && device.second) { |
| 296 | device.second = false; |
| 297 | } |
| 298 | csdActive |= device.second; |
| 299 | } |
| 300 | |
| 301 | if (!csdActive && activeMelPatch.second.csdActive) { |
| 302 | activeMelPatch.second.csdActive = csdActive; |
| 303 | stopMelComputationForPatch_l(activeMelPatch.second); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | } |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 308 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 309 | std::optional<audio_patch_handle_t> MelReporter::activePatchStreamHandle_l( |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 310 | audio_io_handle_t streamHandle) { |
| 311 | for(const auto& patchIt : mActiveMelPatches) { |
| 312 | if (patchIt.second.streamHandle == streamHandle) { |
| 313 | return patchIt.first; |
| 314 | } |
| 315 | } |
| 316 | return std::nullopt; |
| 317 | } |
| 318 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 319 | bool MelReporter::useHalSoundDoseInterface_l() { |
Vlad Popa | 69fbbee | 2023-04-25 12:23:24 +0200 | [diff] [blame] | 320 | return !mSoundDoseManager->forceUseFrameworkMel() & mUseHalSoundDoseInterface; |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 321 | } |
| 322 | |
Andy Hung | ad2faf7 | 2023-07-13 20:00:50 -0700 | [diff] [blame] | 323 | std::string MelReporter::dump() { |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 324 | std::lock_guard _l(mLock); |
Vlad Popa | 2900c0a | 2022-10-24 13:38:00 +0200 | [diff] [blame] | 325 | std::string output("\nSound Dose:\n"); |
Vlad Popa | 1d5f0d5 | 2022-12-18 12:21:26 +0100 | [diff] [blame] | 326 | output.append(mSoundDoseManager->dump()); |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 327 | return output; |
| 328 | } |
| 329 | |
| 330 | } // namespace android |