Ticket #13416: monotonic-time-avsync2-20190303.patch

File monotonic-time-avsync2-20190303.patch, 3.4 KB (added by mspieth, 7 years ago)
  • mythtv/libs/libmythtv/mythplayer.cpp

    commit f7f468d5a36b2c2992b4a1828979bd18a444a634
    Author: Mark Spieth <mspieth@digivation.com.au>
    Date:   Sun Mar 3 08:43:07 2019 +1100
    
        Use monotonic time for avsync2 when possible
    
    diff --git a/mythtv/libs/libmythtv/mythplayer.cpp b/mythtv/libs/libmythtv/mythplayer.cpp
    index 84c903bf1c..837fd5ca2d 100644
    a b void MythPlayer::AVSync(VideoFrame *buffer, bool limit_delay)  
    21672167    }
    21682168}
    21692169
    2170 static void wait_for_time(int64_t framedue);
    2171 
    2172 void wait_for_time(int64_t framedue)
     2170void MythPlayer::WaitForTime(int64_t framedue)
    21732171{
    2174     QDateTime now = QDateTime::currentDateTimeUtc();
    2175     int64_t unow = now.toMSecsSinceEpoch() * 1000;
     2172    int64_t unow = m_avTimer.nsecsElapsed() / 1000;
    21762173    int64_t delay = framedue - unow;
    2177     if (delay > 0)
    2178         QThread::usleep(delay);
     2174    while (delay > 0)
     2175    {
     2176        int64_t stepDelay = std::min(delay, (int64_t)2000);
     2177        QThread::usleep(stepDelay);
     2178        delay -= stepDelay;
     2179    }
    21792180}
    21802181
    21812182#define AVSYNC_MAX_LATE 10000000
    void MythPlayer::AVSync2(VideoFrame *buffer)  
    21942195    bool pause_audio = false;
    21952196    int64_t framedue = 0;
    21962197    int64_t audio_adjustment = 0;
    2197     QDateTime now;
    21982198    int64_t unow = 0;
    21992199    int64_t lateness = 0;
    22002200    int64_t playspeed1000 = (float)1000 / play_speed;
    void MythPlayer::AVSync2(VideoFrame *buffer)  
    22102210                videotimecode = maxtcval;
    22112211        }
    22122212
    2213         now = QDateTime::currentDateTimeUtc();
    2214         unow = now.toMSecsSinceEpoch() * 1000;
     2213        unow = m_avTimer.nsecsElapsed() / 1000;
    22152214
    22162215        if (!normal_speed || FlagIsSet(kMusicChoice))
    22172216        {
    void MythPlayer::AVSync2(VideoFrame *buffer)  
    23502349        // Don't wait for sync if this is a secondary PBP otherwise
    23512350        // the primary PBP will become out of sync
    23522351        if (!player_ctx->IsPBP() || player_ctx->IsPrimaryPBP())
    2353             wait_for_time(framedue);
     2352            WaitForTime(framedue);
    23542353        // get time codes for calculating difference next time
    23552354        prior_audiotimecode = audio.GetAudioTime();
    23562355        videoOutput->Show(ps);
    void MythPlayer::AVSync2(VideoFrame *buffer)  
    23812380            if (!player_ctx->IsPBP() || player_ctx->IsPrimaryPBP())
    23822381            {
    23832382                int64_t due = framedue + frame_interval / 2;
    2384                 wait_for_time(due);
     2383                WaitForTime(due);
    23852384            }
    23862385            videoOutput->Show(ps);
    23872386        }
    23882387    }
    23892388    else
    2390         wait_for_time(framedue);
     2389        WaitForTime(framedue);
    23912390
    23922391    LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_INFO, LOC +
    23932392        QString("A/V timecodes audio=%1 video=%2 frameinterval=%3 "
  • mythtv/libs/libmythtv/mythplayer.h

    diff --git a/mythtv/libs/libmythtv/mythplayer.h b/mythtv/libs/libmythtv/mythplayer.h
    index 4b295af28f..0a54a25ca3 100644
    a b class MTV_PUBLIC MythPlayer  
    625625    int64_t AVSyncGetAudiotime(void);
    626626    void  SetFrameInterval(FrameScanType scan, double speed);
    627627    void  FallbackDeint(void);
     628    void WaitForTime(int64_t framedue);
    628629
    629630    // Private LiveTV stuff
    630631    void  SwitchToProgram(void);
    class MTV_PUBLIC MythPlayer  
    711712    int64_t   totalDuration;
    712713    long long rewindtime;
    713714    int64_t   m_latestVideoTimecode;
     715    QElapsedTimer m_avTimer;
    714716
    715717    // -- end state stuff --
    716718