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
This commit is contained in:
Marco Nelissen
2012-03-09 10:34:37 -08:00
parent aa6816a8a0
commit 1eb0e4a260

View File

@@ -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() {