summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2012-05-14 16:25:13 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-05-14 16:25:13 -0700
commitdfa29ab13647f22b30b2de34d4830c9e815bf120 (patch)
tree04243eb5c37b342fc0bc5baf8e201d8d9dabb8fd /media
parent427eea9368eeb29d3ff888f6171c7f03d943684c (diff)
parente4451a91a61a341014f5eff61db356156c3ecb37 (diff)
downloadframeworks_av-dfa29ab13647f22b30b2de34d4830c9e815bf120.zip
frameworks_av-dfa29ab13647f22b30b2de34d4830c9e815bf120.tar.gz
frameworks_av-dfa29ab13647f22b30b2de34d4830c9e815bf120.tar.bz2
Merge "Smoothen audio "real" time by compensating with system_time()" into jb-dev
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/AudioPlayer.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp
index ca49782..f729a78 100644
--- a/media/libstagefright/AudioPlayer.cpp
+++ b/media/libstagefright/AudioPlayer.cpp
@@ -21,6 +21,7 @@
#include <binder/IPCThreadState.h>
#include <media/AudioTrack.h>
#include <media/stagefright/foundation/ADebug.h>
+#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/AudioPlayer.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
@@ -41,6 +42,7 @@ AudioPlayer::AudioPlayer(
mLatencyUs(0),
mFrameSize(0),
mNumFramesPlayed(0),
+ mNumFramesPlayedSysTimeUs(ALooper::GetNowUs()),
mPositionTimeMediaUs(-1),
mPositionTimeRealUs(-1),
mSeeking(false),
@@ -200,6 +202,7 @@ void AudioPlayer::pause(bool playPendingSamples) {
}
mNumFramesPlayed = 0;
+ mNumFramesPlayedSysTimeUs = ALooper::GetNowUs();
} else {
if (mAudioSink.get() != NULL) {
mAudioSink->pause();
@@ -260,6 +263,7 @@ void AudioPlayer::reset() {
IPCThreadState::self()->flushCommands();
mNumFramesPlayed = 0;
+ mNumFramesPlayedSysTimeUs = ALooper::GetNowUs();
mPositionTimeMediaUs = -1;
mPositionTimeRealUs = -1;
mSeeking = false;
@@ -485,6 +489,7 @@ size_t AudioPlayer::fillBuffer(void *data, size_t size) {
{
Mutex::Autolock autoLock(mLock);
mNumFramesPlayed += size_done / mFrameSize;
+ mNumFramesPlayedSysTimeUs = ALooper::GetNowUs();
}
if (postEOS) {
@@ -506,7 +511,14 @@ int64_t AudioPlayer::getRealTimeUs() {
int64_t AudioPlayer::getRealTimeUsLocked() const {
CHECK(mStarted);
CHECK_NE(mSampleRate, 0);
- return -mLatencyUs + (mNumFramesPlayed * 1000000) / mSampleRate;
+ int64_t result = -mLatencyUs + (mNumFramesPlayed * 1000000) / mSampleRate;
+
+ // Compensate for large audio buffers, updates of mNumFramesPlayed
+ // are less frequent, therefore to get a "smoother" notion of time we
+ // compensate using system time.
+ int64_t diffUs = ALooper::GetNowUs() - mNumFramesPlayedSysTimeUs;
+
+ return result + diffUs;
}
int64_t AudioPlayer::getMediaTimeUs() {
@@ -548,6 +560,7 @@ status_t AudioPlayer::seekTo(int64_t time_us) {
// Flush resets the number of played frames
mNumFramesPlayed = 0;
+ mNumFramesPlayedSysTimeUs = ALooper::GetNowUs();
if (mAudioSink != NULL) {
mAudioSink->flush();