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

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

    commit a1c66caba0bad8995e0ec6389d1b331ec971dd3d
    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..aa1195e90b 100644
    a b MythPlayer::MythPlayer(PlayerFlags flags)  
    270270        avsync2adjustms = 1;
    271271    if (avsync2adjustms > 40)
    272272        avsync2adjustms = 40;
     273    m_avTimer.start();
    273274}
    274275
    275276MythPlayer::~MythPlayer(void)
    void MythPlayer::AVSync(VideoFrame *buffer, bool limit_delay)  
    21672168    }
    21682169}
    21692170
    2170 static void wait_for_time(int64_t framedue);
    2171 
    2172 void wait_for_time(int64_t framedue)
     2171void MythPlayer::WaitForTime(int64_t framedue)
    21732172{
    2174     QDateTime now = QDateTime::currentDateTimeUtc();
    2175     int64_t unow = now.toMSecsSinceEpoch() * 1000;
     2173    int64_t unow = m_avTimer.nsecsElapsed() / 1000;
    21762174    int64_t delay = framedue - unow;
    2177     if (delay > 0)
    2178         QThread::usleep(delay);
     2175    while (delay > 0)
     2176    {
     2177        int64_t stepDelay = std::min(delay, (int64_t)2000);
     2178        QThread::usleep(stepDelay);
     2179        delay -= stepDelay;
     2180    }
    21792181}
    21802182
    21812183#define AVSYNC_MAX_LATE 10000000
    void MythPlayer::AVSync2(VideoFrame *buffer)  
    21942196    bool pause_audio = false;
    21952197    int64_t framedue = 0;
    21962198    int64_t audio_adjustment = 0;
    2197     QDateTime now;
    21982199    int64_t unow = 0;
    21992200    int64_t lateness = 0;
    22002201    int64_t playspeed1000 = (float)1000 / play_speed;
    void MythPlayer::AVSync2(VideoFrame *buffer)  
    22102211                videotimecode = maxtcval;
    22112212        }
    22122213
    2213         now = QDateTime::currentDateTimeUtc();
    2214         unow = now.toMSecsSinceEpoch() * 1000;
     2214        unow = m_avTimer.nsecsElapsed() / 1000;
    22152215
    22162216        if (!normal_speed || FlagIsSet(kMusicChoice))
    22172217        {
    void MythPlayer::AVSync2(VideoFrame *buffer)  
    23502350        // Don't wait for sync if this is a secondary PBP otherwise
    23512351        // the primary PBP will become out of sync
    23522352        if (!player_ctx->IsPBP() || player_ctx->IsPrimaryPBP())
    2353             wait_for_time(framedue);
     2353            WaitForTime(framedue);
    23542354        // get time codes for calculating difference next time
    23552355        prior_audiotimecode = audio.GetAudioTime();
    23562356        videoOutput->Show(ps);
    void MythPlayer::AVSync2(VideoFrame *buffer)  
    23812381            if (!player_ctx->IsPBP() || player_ctx->IsPrimaryPBP())
    23822382            {
    23832383                int64_t due = framedue + frame_interval / 2;
    2384                 wait_for_time(due);
     2384                WaitForTime(due);
    23852385            }
    23862386            videoOutput->Show(ps);
    23872387        }
    23882388    }
    23892389    else
    2390         wait_for_time(framedue);
     2390        WaitForTime(framedue);
    23912391
    23922392    LOG(VB_PLAYBACK | VB_TIMESTAMP, LOG_INFO, LOC +
    23932393        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