Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f65f5a75 authored by Andy Hung's avatar Andy Hung
Browse files

Effects: Update to audio_utils mutex

Test: atest AudioTrackTest AudioRecordTest
Test: atest AAudioTests AudioTrackOffloadTest
Test: atest AudioPlaybackCaptureTest
Test: Camera YouTube
Bug: 298534151
Change-Id: I2ff0b2748110b56da238db7dd74b3c6692ffce39
parent 0169fbcb
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4446,7 +4446,7 @@ status_t AudioFlinger::moveEffectChain_l(audio_session_t sessionId,
        // If we do not take the dstChain lock, it is possible that processing is ongoing
        // while we are starting the effect.  This can cause glitches with volume,
        // see b/202360137.
        dstChain->lock();
        dstChain->mutex().lock();
        for (const auto& effect : removed) {
            if (effect->state() == IAfEffectModule::ACTIVE ||
                    effect->state() == IAfEffectModule::STOPPING) {
@@ -4454,7 +4454,7 @@ status_t AudioFlinger::moveEffectChain_l(audio_session_t sessionId,
                effect->start();
            }
        }
        dstChain->unlock();
        dstChain->mutex().unlock();
    }

    if (status != NO_ERROR) {
+8 −8
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ void DeviceEffectManager::onCreateAudioPatch(audio_patch_handle_t handle,
    ALOGV("%s handle %d mHalHandle %d device sink %08x",
            __func__, handle, patch.mHalHandle,
            patch.mAudioPatch.num_sinks > 0 ? patch.mAudioPatch.sinks[0].ext.device.type : 0);
    Mutex::Autolock _l(mLock);
    audio_utils::lock_guard _l(mutex());
    for (auto& effectProxies : mDeviceEffects) {
        for (auto& effect : effectProxies.second) {
            const status_t status = effect->onCreatePatch(handle, patch);
@@ -71,7 +71,7 @@ void DeviceEffectManager::onCreateAudioPatch(audio_patch_handle_t handle,

void DeviceEffectManager::onReleaseAudioPatch(audio_patch_handle_t handle) {
    ALOGV("%s", __func__);
    Mutex::Autolock _l(mLock);
    audio_utils::lock_guard _l(mutex());
    for (auto& effectProxies : mDeviceEffects) {
        for (auto& effect : effectProxies.second) {
            effect->onReleasePatch(handle);
@@ -84,7 +84,7 @@ void DeviceEffectManager::onUpdateAudioPatch(audio_patch_handle_t oldHandle,
    ALOGV("%s oldhandle %d newHandle %d mHalHandle %d device sink %08x",
            __func__, oldHandle, newHandle, patch.mHalHandle,
            patch.mAudioPatch.num_sinks > 0 ? patch.mAudioPatch.sinks[0].ext.device.type : 0);
    Mutex::Autolock _l(mLock);
    audio_utils::lock_guard _l(mutex());
    for (auto& effectProxies : mDeviceEffects) {
        for (auto& effect : effectProxies.second) {
            const status_t status = effect->onUpdatePatch(oldHandle, newHandle, patch);
@@ -94,7 +94,7 @@ void DeviceEffectManager::onUpdateAudioPatch(audio_patch_handle_t oldHandle,
    }
}

// DeviceEffectManager::createEffect_l() must be called with AudioFlinger::mLock held
// DeviceEffectManager::createEffect_l() must be called with AudioFlinger::mutex() held
sp<IAfEffectHandle> DeviceEffectManager::createEffect_l(
        effect_descriptor_t *descriptor,
        const AudioDeviceTypeAddr& device,
@@ -117,7 +117,7 @@ sp<IAfEffectHandle> DeviceEffectManager::createEffect_l(
    }

    {
        Mutex::Autolock _l(mLock);
        audio_utils::lock_guard _l(mutex());
        auto iter = mDeviceEffects.find(device);
        if (iter != mDeviceEffects.end()) {
            effectsForDevice = iter->second;
@@ -203,7 +203,7 @@ status_t DeviceEffectManager::createEffectHal(
void DeviceEffectManager::dump(int fd)
NO_THREAD_SAFETY_ANALYSIS  // conditional try lock
{
    const bool locked = afutils::dumpTryLock(mLock);
    const bool locked = afutils::dumpTryLock(mutex());
    if (!locked) {
        String8 result("DeviceEffectManager may be deadlocked\n");
        write(fd, result.c_str(), result.size());
@@ -222,13 +222,13 @@ NO_THREAD_SAFETY_ANALYSIS // conditional try lock
    }

    if (locked) {
        mLock.unlock();
        mutex().unlock();
    }
}

size_t DeviceEffectManager::removeEffect(const sp<IAfDeviceEffectProxy>& effect)
{
    Mutex::Autolock _l(mLock);
    audio_utils::lock_guard _l(mutex());
    const auto& iter = mDeviceEffects.find(effect->device());
    if (iter != mDeviceEffects.end()) {
        const auto& iterEffect = std::find_if(
+2 −3
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@
#include "IAfEffect.h"
#include "PatchCommandThread.h"

#include <utils/Mutex.h>  // avoid transitive dependency

namespace android {

class IAfDeviceEffectManagerCallback : public virtual RefBase {
@@ -80,7 +78,8 @@ public:
private:
    status_t checkEffectCompatibility(const effect_descriptor_t *desc);

    Mutex mLock;
    audio_utils::mutex& mutex() const { return mMutex; }
    mutable audio_utils::mutex mMutex;
    const sp<IAfDeviceEffectManagerCallback> mAfDeviceEffectManagerCallback;
    const sp<DeviceEffectManagerCallback> mMyCallback;
    std::map<AudioDeviceTypeAddr, std::vector<sp<IAfDeviceEffectProxy>>> mDeviceEffects;
+71 −71

File changed.

Preview size limit exceeded, changes collapsed.

+19 −19

File changed.

Preview size limit exceeded, changes collapsed.

Loading