From 54464ba861aaafd11ee5645f5d1ecd1171c6e9fe Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Sun, 28 Sep 2014 14:41:07 -0700 Subject: Fix uncertainty of one normal mix buffer in AudioTrack::getTimestamp The per-thread timestamp latch was not synchronized with the per-track released frames. Now the value of each track's released frames is latched along with the timestamp. Bug: 17531839 Bug: 17669342 Change-Id: I96252782911bd42a2534cc4030521b7eeb99a7b9 --- services/audioflinger/Tracks.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'services/audioflinger/Tracks.cpp') diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp index c0a75b9..8c2bee4 100644 --- a/services/audioflinger/Tracks.cpp +++ b/services/audioflinger/Tracks.cpp @@ -894,7 +894,15 @@ status_t AudioFlinger::PlaybackThread::Track::getTimestamp(AudioTimestamp& times uint32_t unpresentedFrames = ((int64_t) playbackThread->mLatchQ.mUnpresentedFrames * mSampleRate) / playbackThread->mSampleRate; - uint32_t framesWritten = mAudioTrackServerProxy->framesReleased(); + // FIXME Since we're using a raw pointer as the key, it is theoretically possible + // for a brand new track to share the same address as a recently destroyed + // track, and thus for us to get the frames released of the wrong track. + // It is unlikely that we would be able to call getTimestamp() so quickly + // right after creating a new track. Nevertheless, the index here should + // be changed to something that is unique. Or use a completely different strategy. + ssize_t i = playbackThread->mLatchQ.mFramesReleased.indexOfKey(this); + uint32_t framesWritten = i >= 0 ? + playbackThread->mLatchQ.mFramesReleased[i] : mAudioTrackServerProxy->framesReleased(); bool checkPreviousTimestamp = mPreviousValid && framesWritten >= mPreviousFramesWritten; if (framesWritten < unpresentedFrames) { mPreviousValid = false; -- cgit v1.1