Loading services/audioflinger/PlaybackTracks.h +3 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <audio_utils/mutex.h> #include <audio_utils/LinearMap.h> #include <binder/AppOpsManager.h> #include <utils/RWLock.h> namespace android { Loading Loading @@ -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); } }; Loading Loading @@ -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; Loading services/audioflinger/Tracks.cpp +12 −3 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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 Loading Loading @@ -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(); }); Loading Loading
services/audioflinger/PlaybackTracks.h +3 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include <audio_utils/mutex.h> #include <audio_utils/LinearMap.h> #include <binder/AppOpsManager.h> #include <utils/RWLock.h> namespace android { Loading Loading @@ -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); } }; Loading Loading @@ -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; Loading
services/audioflinger/Tracks.cpp +12 −3 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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 Loading Loading @@ -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(); }); Loading