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

Commit bbe00005 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add RWLock when accessing tee patches." into main

parents 83287b46 73f9705e
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
@@ -1084,7 +1084,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);
@@ -1097,7 +1103,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
@@ -1629,7 +1635,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(); });