From e7d0c712f1c9fa0b0e413b8eb729049995290aee Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Fri, 9 Mar 2012 10:34:37 -0800 Subject: Improve AudioPlayer position reporting The latency was not taken into account when updating mPositionTimeRealUs inside of the fillBuffer hook, contrary to what the getRealTimeUsLocked() method does. This caused the realTimeOffset calculated in the getMediaTimeUs to always be negative, causing the reported position to always be equal to mPositionTimeMediaUs, which is updated infrequently. With this change, the reported position is updated more frequently, allowing apps to perform smoother UI updates. Change-Id: I61e05c1a8b53d46b9091afb0d18a6289d13a7a5e --- media/libstagefright/AudioPlayer.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'media') diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp index 650b6c4..2b3cb1a 100644 --- a/media/libstagefright/AudioPlayer.cpp +++ b/media/libstagefright/AudioPlayer.cpp @@ -437,8 +437,11 @@ size_t AudioPlayer::fillBuffer(void *data, size_t size) { kKeyTime, &mPositionTimeMediaUs)); mPositionTimeRealUs = - ((mNumFramesPlayed + size_done / mFrameSize) * 1000000) + -mLatencyUs + ((mNumFramesPlayed + size_done / mFrameSize) * 1000000) / mSampleRate; + if (mPositionTimeRealUs < 0) { + mPositionTimeRealUs = 0; + } ALOGV("buffer->size() = %d, " "mPositionTimeMediaUs=%.2f mPositionTimeRealUs=%.2f", @@ -493,7 +496,9 @@ int64_t AudioPlayer::getRealTimeUs() { int64_t AudioPlayer::getRealTimeUsLocked() const { CHECK(mStarted); CHECK_NE(mSampleRate, 0); - return -mLatencyUs + (mNumFramesPlayed * 1000000) / mSampleRate; + int64_t t = -mLatencyUs + (mNumFramesPlayed * 1000000) / mSampleRate; + if (t < 0) return 0; + return t; } int64_t AudioPlayer::getMediaTimeUs() { -- cgit v1.1