summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/Tracks.cpp
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2014-09-28 14:41:07 -0700
committerGlenn Kasten <gkasten@google.com>2014-10-02 16:50:26 -0700
commit4c053ea158b29fa2cdd4c6f39d3c8da4ee5a7a02 (patch)
tree129617d405d098b749beafbcd87c58321bf2b055 /services/audioflinger/Tracks.cpp
parent8b76b592be5bc162fb5a6d7e8c47812544b6b345 (diff)
downloadframeworks_av-4c053ea158b29fa2cdd4c6f39d3c8da4ee5a7a02.zip
frameworks_av-4c053ea158b29fa2cdd4c6f39d3c8da4ee5a7a02.tar.gz
frameworks_av-4c053ea158b29fa2cdd4c6f39d3c8da4ee5a7a02.tar.bz2
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: I9d50c8c6a5de55a3f4561ac40e20d497376c1257
Diffstat (limited to 'services/audioflinger/Tracks.cpp')
-rw-r--r--services/audioflinger/Tracks.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index 75190f3..b9308fa 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -898,7 +898,16 @@ 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;