Skip to content

Commit 1eb0e4a

Browse files
committed
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
1 parent aa6816a commit 1eb0e4a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

media/libstagefright/AudioPlayer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,11 @@ size_t AudioPlayer::fillBuffer(void *data, size_t size) {
437437
kKeyTime, &mPositionTimeMediaUs));
438438

439439
mPositionTimeRealUs =
440-
((mNumFramesPlayed + size_done / mFrameSize) * 1000000)
440+
-mLatencyUs + ((mNumFramesPlayed + size_done / mFrameSize) * 1000000)
441441
/ mSampleRate;
442+
if (mPositionTimeRealUs < 0) {
443+
mPositionTimeRealUs = 0;
444+
}
442445

443446
ALOGV("buffer->size() = %d, "
444447
"mPositionTimeMediaUs=%.2f mPositionTimeRealUs=%.2f",
@@ -493,7 +496,9 @@ int64_t AudioPlayer::getRealTimeUs() {
493496
int64_t AudioPlayer::getRealTimeUsLocked() const {
494497
CHECK(mStarted);
495498
CHECK_NE(mSampleRate, 0);
496-
return -mLatencyUs + (mNumFramesPlayed * 1000000) / mSampleRate;
499+
int64_t t = -mLatencyUs + (mNumFramesPlayed * 1000000) / mSampleRate;
500+
if (t < 0) return 0;
501+
return t;
497502
}
498503

499504
int64_t AudioPlayer::getMediaTimeUs() {

0 commit comments

Comments
 (0)