summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/Tracks.cpp
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2014-10-01 02:26:48 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-10-01 02:26:48 +0000
commitac2a2239dfc86c70f7382bebdb85c8cc1a9f6119 (patch)
tree24de5fcceec00e55053623a9f9e79427b0a6ebde /services/audioflinger/Tracks.cpp
parent1e3aedd7d613708fb13f05cc343a229ed22ea266 (diff)
parent785da8f542120e49d29289947e69aba180c1724b (diff)
downloadframeworks_av-ac2a2239dfc86c70f7382bebdb85c8cc1a9f6119.zip
frameworks_av-ac2a2239dfc86c70f7382bebdb85c8cc1a9f6119.tar.gz
frameworks_av-ac2a2239dfc86c70f7382bebdb85c8cc1a9f6119.tar.bz2
am 785da8f5: am 955e24d3: Merge "Fix uncertainty of one normal mix buffer in AudioTrack::getTimestamp" into lmp-dev
* commit '785da8f542120e49d29289947e69aba180c1724b': Fix uncertainty of one normal mix buffer in AudioTrack::getTimestamp
Diffstat (limited to 'services/audioflinger/Tracks.cpp')
-rw-r--r--services/audioflinger/Tracks.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index 8793f4a..c6c0ac1 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -899,7 +899,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;