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

Commit 4536eaa7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add RWLock when accessing tee patches." into main am: 05a3308f

parents 8ff37c0d 05a3308f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <audio_utils/mutex.h>
#include <audio_utils/LinearMap.h>
#include <binder/AppOpsManager.h>
#include <utils/RWLock.h>

namespace android {

@@ -352,6 +353,7 @@ private:
    // Must hold thread lock to access tee patches
    template <class F>
    void                forEachTeePatchTrack_l(F f) {
        RWLock::AutoRLock readLock(mTeePatchesRWLock);
        for (auto& tp : mTeePatches) { f(tp.patchTrack); }
    };

@@ -387,6 +389,7 @@ private:
    audio_output_flags_t mFlags;
    TeePatches mTeePatches;
    std::optional<TeePatches> mTeePatchesToUpdate;
    RWLock              mTeePatchesRWLock;
    const float         mSpeed;
    const bool          mIsSpatialized;
    const bool          mIsBitPerfect;
+12 −3
Original line number Diff line number Diff line
@@ -1081,7 +1081,13 @@ void Track::interceptBuffer(
        // Additionally PatchProxyBufferProvider::obtainBuffer (called by PathTrack::getNextBuffer)
        // does not allow 0 frame size request contrary to getNextBuffer
    }
    for (auto& teePatch : mTeePatches) {
    TeePatches teePatches;
    if (mTeePatchesRWLock.tryReadLock() == NO_ERROR) {
        // Cache a copy of tee patches in case it is updated while using.
        teePatches = mTeePatches;
        mTeePatchesRWLock.unlock();
    }
    for (auto& teePatch : teePatches) {
        IAfPatchRecord* patchRecord = teePatch.patchRecord.get();
        const size_t framesWritten = patchRecord->writeFrames(
                sourceBuffer.i8, frameCount, mFrameSize);
@@ -1094,7 +1100,7 @@ void Track::interceptBuffer(
    using namespace std::chrono_literals;
    // Average is ~20us per track, this should virtually never be logged (Logging takes >200us)
    ALOGD_IF(spent > 500us, "%s: took %lldus to intercept %zu tracks", __func__,
             spent.count(), mTeePatches.size());
             spent.count(), teePatches.size());
}

// ExtendedAudioBufferProvider interface
@@ -1616,7 +1622,10 @@ void Track::copyMetadataTo(MetadataInserter& backInserter) const
void Track::updateTeePatches_l() {
    if (mTeePatchesToUpdate.has_value()) {
        forEachTeePatchTrack_l([](const auto& patchTrack) { patchTrack->destroy(); });
        mTeePatches = mTeePatchesToUpdate.value();
        {
            RWLock::AutoWLock writeLock(mTeePatchesRWLock);
            mTeePatches = std::move(mTeePatchesToUpdate.value());
        }
        if (mState == TrackBase::ACTIVE || mState == TrackBase::RESUMING ||
                mState == TrackBase::STOPPING_1) {
            forEachTeePatchTrack_l([](const auto& patchTrack) { patchTrack->start(); });