summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2012-03-09 10:34:37 -0800
committerMarco Nelissen <marcone@google.com>2012-03-09 12:27:06 -0800
commite7d0c712f1c9fa0b0e413b8eb729049995290aee (patch)
treedc6cbbe4c89a3a5ae33ca964690e6e7136402f13 /media
parent083c154162c88a9f63aeaa10a4b52dd454bda9ff (diff)
downloadframeworks_av-e7d0c712f1c9fa0b0e413b8eb729049995290aee.zip
frameworks_av-e7d0c712f1c9fa0b0e413b8eb729049995290aee.tar.gz
frameworks_av-e7d0c712f1c9fa0b0e413b8eb729049995290aee.tar.bz2
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
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/AudioPlayer.cpp9
1 files changed, 7 insertions, 2 deletions
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() {