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

Commit b8af7657 authored by Steve Kondik's avatar Steve Kondik
Browse files

AwesomePlayer: improve scheduling of video event to hit PTS

Change-Id: I7b19911acbde9b592b757b952d4ad63cd8efebed

AwesomePlayer: use PTS for queueBuffer

Change-Id: I1c14ad4784c799c46cf06a14b0f00c5e4d01f718
parent 94cd0217
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -93,7 +93,6 @@ static const size_t kHighWaterMarkBytes = 200000;
#ifdef QCOM_DIRECTTRACK
int AwesomePlayer::mTunnelAliveAP = 0;
#endif
static int64_t kVideoEarlyMarginUs = -10000LL;

// maximum time in paused state when offloading audio decompression. When elapsed, the AudioPlayer
// is destroyed to allow the audio DSP to power down.
@@ -2356,6 +2355,7 @@ void AwesomePlayer::onVideoEvent() {
        ((mFlags & AUDIO_AT_EOS) || !(mFlags & AUDIOPLAYER_STARTED))
            ? &mSystemTimeSource : mTimeSource;
    int64_t systemTimeUs = mSystemTimeSource.getRealTimeUs();
    int64_t looperTimeUs = ALooper::GetNowUs();

    if (mFlags & FIRST_FRAME) {
        modifyFlags(FIRST_FRAME, CLEAR);
@@ -2377,9 +2377,6 @@ 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;
    }
@@ -2479,15 +2476,14 @@ void AwesomePlayer::onVideoEvent() {
            }
        }

        if (latenessUs < -10000) {
            // We're more than 10ms early.
        if (latenessUs < -30000) {
            logOnTime(timeUs,nowUs,latenessUs);
            {
                Mutex::Autolock autoLock(mStatsLock);
                mStats.mConsecutiveFramesDropped = 0;
            }
            postVideoEvent_l((kVideoEarlyMarginUs - latenessUs) > 40000LL ?
                                40000LL : (kVideoEarlyMarginUs - latenessUs));
            // We're more than 30ms early, schedule at most 20 ms before time due
            postVideoEvent_l(latenessUs < -60000 ? 30000 : -latenessUs - 20000);
            return;
        }
    }
@@ -2506,6 +2502,8 @@ void AwesomePlayer::onVideoEvent() {
            mVSyncLocker->blockOnVSync();
        }

        mVideoBuffer->meta_data()->setInt64(kKeyTime, looperTimeUs - latenessUs);

        mVideoRenderer->render(mVideoBuffer);
        if (!mVideoRenderingStarted) {
            mVideoRenderingStarted = true;
@@ -2578,8 +2576,9 @@ void AwesomePlayer::onVideoEvent() {
        CHECK(mVideoBuffer->meta_data()->findInt64(kKeyTime, &nextTimeUs));
        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);
        ATRACE_INT("Frame delta (ms)", (nextTimeUs - timeUs) / 1E3);
        // try to schedule 30ms before time due
        postVideoEvent_l(delayUs > 60000 ? 30000 : (delayUs < 30000 ? 0 : delayUs - 30000));
        return;
    }