Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a1f432f authored by Lajos Molnar's avatar Lajos Molnar Committed by Steve Kondik
Browse files

Smooth out AwesomePlayer

Use clock estimator to smooth out audio time stamps.

Change-Id: Iec1ff30c011069d06ff8051fc4839d00895463d6
parent 3f3e48aa
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@
#include <media/stagefright/TunnelPlayer.h>
#endif
#endif
#include <media/stagefright/ClockEstimator.h>
#include <media/stagefright/DataSource.h>
#include <media/stagefright/FileSource.h>
#include <media/stagefright/MediaBuffer.h>
@@ -260,6 +261,8 @@ AwesomePlayer::AwesomePlayer()
    mDurationUs = -1;
    mAudioTearDownPosition = 0;

    mClockEstimator = new WindowedLinearFitEstimator();

    reset();
#ifdef QCOM_DIRECTTRACK
    mIsTunnelAudio = false;
@@ -2329,11 +2332,14 @@ 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;

        {
            Mutex::Autolock autoLock(mStatsLock);
@@ -2348,11 +2354,15 @@ void AwesomePlayer::onVideoEvent() {
    int64_t realTimeUs, mediaTimeUs, nowUs = 0, latenessUs = 0;
    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) {
        nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs;
        nowUs = estimateRealTimeUs(ts, systemTimeUs) - mTimeSourceDeltaUs;

        latenessUs = nowUs - timeUs;

@@ -2366,7 +2376,7 @@ void AwesomePlayer::onVideoEvent() {
    if (wasSeeking == NO_SEEK) {
        // Let's display the first frame after seeking right away.

        nowUs = ts->getRealTimeUs() - mTimeSourceDeltaUs;
        nowUs = estimateRealTimeUs(ts, systemTimeUs) - mTimeSourceDeltaUs;

        latenessUs = nowUs - timeUs;

@@ -2524,7 +2534,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("Video postDelay", delayUs < 0 ? 1 : delayUs);
        postVideoEvent_l(delayUs > 10000 ? 10000 : delayUs < 0 ? 0 : delayUs);
        return;
@@ -2533,6 +2544,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();

+3 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
namespace android {

struct AudioPlayer;
struct ClockEstimator;
struct DataSource;
struct MediaBuffer;
struct MediaExtractor;
@@ -247,6 +248,7 @@ private:

    MediaBuffer *mVideoBuffer;

    sp<ClockEstimator> mClockEstimator;
    sp<HTTPBase> mConnectingDataSource;
    sp<NuCachedSource2> mCachedSource;

@@ -306,6 +308,7 @@ private:

    bool getBitrate(int64_t *bitrate);

    int64_t estimateRealTimeUs(TimeSource *ts, int64_t systemTimeUs);
    void finishSeekIfNecessary(int64_t videoTimeUs);
    void ensureCacheIsFetching_l();