Loading media/libstagefright/AwesomePlayer.cpp +22 −4 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/timedtext/TimedTextDriver.h> #include <media/stagefright/AudioPlayer.h> #include <media/stagefright/ClockEstimator.h> #include <media/stagefright/DataSource.h> #include <media/stagefright/FileSource.h> #include <media/stagefright/MediaBuffer.h> Loading Loading @@ -228,6 +229,8 @@ AwesomePlayer::AwesomePlayer() &AwesomePlayer::onAudioTearDownEvent); mAudioTearDownEventPending = false; mClockEstimator = new WindowedLinearFitEstimator(); reset(); } Loading Loading @@ -1859,21 +1862,27 @@ void AwesomePlayer::onVideoEvent() { TimeSource *ts = ((mFlags & AUDIO_AT_EOS) || !(mFlags & AUDIOPLAYER_STARTED)) ? &mSystemTimeSource : mTimeSource; int64_t systemTimeUs = mSystemTimeSource.getRealTimeUs(); if (mFlags & FIRST_FRAME) { modifyFlags(FIRST_FRAME, CLEAR); mSinceLastDropped = 0; mTimeSourceDeltaUs = ts->getRealTimeUs() - timeUs; mClockEstimator->reset(); mTimeSourceDeltaUs = estimateRealTimeUs(ts, systemTimeUs) - timeUs; } int64_t realTimeUs, mediaTimeUs; if (!(mFlags & AUDIO_AT_EOS) && mAudioPlayer != NULL && mAudioPlayer->getMediaTimeMapping(&realTimeUs, &mediaTimeUs)) { ALOGV("updating TSdelta (%" PRId64 " => %" PRId64 " change %" PRId64 ")", mTimeSourceDeltaUs, realTimeUs - mediaTimeUs, mTimeSourceDeltaUs - (realTimeUs - mediaTimeUs)); ATRACE_INT("TS delta change (ms)", (mTimeSourceDeltaUs - (realTimeUs - mediaTimeUs)) / 1E3); mTimeSourceDeltaUs = realTimeUs - mediaTimeUs; } if (wasSeeking == SEEK_VIDEO_ONLY) { int64_t nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs; int64_t nowUs = estimateRealTimeUs(ts, systemTimeUs) - mTimeSourceDeltaUs; int64_t latenessUs = nowUs - timeUs; Loading @@ -1887,7 +1896,7 @@ void AwesomePlayer::onVideoEvent() { if (wasSeeking == NO_SEEK) { // Let's display the first frame after seeking right away. int64_t nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs; int64_t nowUs = estimateRealTimeUs(ts, systemTimeUs) - mTimeSourceDeltaUs; int64_t latenessUs = nowUs - timeUs; Loading Loading @@ -2009,7 +2018,8 @@ void AwesomePlayer::onVideoEvent() { int64_t nextTimeUs; CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &nextTimeUs)); int64_t delayUs = nextTimeUs - ts->getRealTimeUs() + mTimeSourceDeltaUs; systemTimeUs = mSystemTimeSource.getRealTimeUs(); int64_t delayUs = nextTimeUs - estimateRealTimeUs(ts, systemTimeUs) + mTimeSourceDeltaUs; ATRACE_INT("Frame delta (ms)", (nextTimeUs - timeUs) / 1E3); ALOGV("next frame in %" PRId64, delayUs); // try to schedule at least 12ms before due time, or just on time Loading @@ -2020,6 +2030,14 @@ void AwesomePlayer::onVideoEvent() { postVideoEvent_l(); } int64_t AwesomePlayer::estimateRealTimeUs(TimeSource *ts, int64_t systemTimeUs) { if (ts == &mSystemTimeSource) { return systemTimeUs; } else { return (int64_t)mClockEstimator->estimate(systemTimeUs, ts->getRealTimeUs()); } } void AwesomePlayer::postVideoEvent_l(int64_t delayUs) { ATRACE_CALL(); Loading media/libstagefright/include/AwesomePlayer.h +3 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ namespace android { struct AudioPlayer; struct ClockEstimator; struct DataSource; struct MediaBuffer; struct MediaExtractor; Loading Loading @@ -234,6 +235,7 @@ private: MediaBuffer *mVideoBuffer; sp<ClockEstimator> mClockEstimator; sp<HTTPBase> mConnectingDataSource; sp<NuCachedSource2> mCachedSource; Loading Loading @@ -293,6 +295,7 @@ private: bool getBitrate(int64_t *bitrate); int64_t estimateRealTimeUs(TimeSource *ts, int64_t systemTimeUs); void finishSeekIfNecessary(int64_t videoTimeUs); void ensureCacheIsFetching_l(); Loading Loading
media/libstagefright/AwesomePlayer.cpp +22 −4 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/timedtext/TimedTextDriver.h> #include <media/stagefright/AudioPlayer.h> #include <media/stagefright/ClockEstimator.h> #include <media/stagefright/DataSource.h> #include <media/stagefright/FileSource.h> #include <media/stagefright/MediaBuffer.h> Loading Loading @@ -228,6 +229,8 @@ AwesomePlayer::AwesomePlayer() &AwesomePlayer::onAudioTearDownEvent); mAudioTearDownEventPending = false; mClockEstimator = new WindowedLinearFitEstimator(); reset(); } Loading Loading @@ -1859,21 +1862,27 @@ void AwesomePlayer::onVideoEvent() { TimeSource *ts = ((mFlags & AUDIO_AT_EOS) || !(mFlags & AUDIOPLAYER_STARTED)) ? &mSystemTimeSource : mTimeSource; int64_t systemTimeUs = mSystemTimeSource.getRealTimeUs(); if (mFlags & FIRST_FRAME) { modifyFlags(FIRST_FRAME, CLEAR); mSinceLastDropped = 0; mTimeSourceDeltaUs = ts->getRealTimeUs() - timeUs; mClockEstimator->reset(); mTimeSourceDeltaUs = estimateRealTimeUs(ts, systemTimeUs) - timeUs; } int64_t realTimeUs, mediaTimeUs; if (!(mFlags & AUDIO_AT_EOS) && mAudioPlayer != NULL && mAudioPlayer->getMediaTimeMapping(&realTimeUs, &mediaTimeUs)) { ALOGV("updating TSdelta (%" PRId64 " => %" PRId64 " change %" PRId64 ")", mTimeSourceDeltaUs, realTimeUs - mediaTimeUs, mTimeSourceDeltaUs - (realTimeUs - mediaTimeUs)); ATRACE_INT("TS delta change (ms)", (mTimeSourceDeltaUs - (realTimeUs - mediaTimeUs)) / 1E3); mTimeSourceDeltaUs = realTimeUs - mediaTimeUs; } if (wasSeeking == SEEK_VIDEO_ONLY) { int64_t nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs; int64_t nowUs = estimateRealTimeUs(ts, systemTimeUs) - mTimeSourceDeltaUs; int64_t latenessUs = nowUs - timeUs; Loading @@ -1887,7 +1896,7 @@ void AwesomePlayer::onVideoEvent() { if (wasSeeking == NO_SEEK) { // Let's display the first frame after seeking right away. int64_t nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs; int64_t nowUs = estimateRealTimeUs(ts, systemTimeUs) - mTimeSourceDeltaUs; int64_t latenessUs = nowUs - timeUs; Loading Loading @@ -2009,7 +2018,8 @@ void AwesomePlayer::onVideoEvent() { int64_t nextTimeUs; CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &nextTimeUs)); int64_t delayUs = nextTimeUs - ts->getRealTimeUs() + mTimeSourceDeltaUs; systemTimeUs = mSystemTimeSource.getRealTimeUs(); int64_t delayUs = nextTimeUs - estimateRealTimeUs(ts, systemTimeUs) + mTimeSourceDeltaUs; ATRACE_INT("Frame delta (ms)", (nextTimeUs - timeUs) / 1E3); ALOGV("next frame in %" PRId64, delayUs); // try to schedule at least 12ms before due time, or just on time Loading @@ -2020,6 +2030,14 @@ void AwesomePlayer::onVideoEvent() { postVideoEvent_l(); } int64_t AwesomePlayer::estimateRealTimeUs(TimeSource *ts, int64_t systemTimeUs) { if (ts == &mSystemTimeSource) { return systemTimeUs; } else { return (int64_t)mClockEstimator->estimate(systemTimeUs, ts->getRealTimeUs()); } } void AwesomePlayer::postVideoEvent_l(int64_t delayUs) { ATRACE_CALL(); Loading
media/libstagefright/include/AwesomePlayer.h +3 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ namespace android { struct AudioPlayer; struct ClockEstimator; struct DataSource; struct MediaBuffer; struct MediaExtractor; Loading Loading @@ -234,6 +235,7 @@ private: MediaBuffer *mVideoBuffer; sp<ClockEstimator> mClockEstimator; sp<HTTPBase> mConnectingDataSource; sp<NuCachedSource2> mCachedSource; Loading Loading @@ -293,6 +295,7 @@ private: bool getBitrate(int64_t *bitrate); int64_t estimateRealTimeUs(TimeSource *ts, int64_t systemTimeUs); void finishSeekIfNecessary(int64_t videoTimeUs); void ensureCacheIsFetching_l(); Loading