Ticket #13383: 20190206_1447_catchup.patch

File 20190206_1447_catchup.patch, 2.1 KB (added by Peter Bennett, 20 months ago)

Next iteration, hopefully the last. Eliminates the judder after a jump and successfully discards excess audio that was causing irritating artifacts. Also works with speedup.

  • mythtv/libs/libmythtv/mythplayer.cpp

    diff --git a/mythtv/libs/libmythtv/mythplayer.cpp b/mythtv/libs/libmythtv/mythplayer.cpp
    index 5b80c452a3b..5ac7e5e06da 100644
    a b void wait_for_time(int64_t framedue) 
    21702170        QThread::usleep(delay);
    21712171}
    21722172
    2173 #define AVSYNC_MAX_LATE 1000000
     2173#define AVSYNC_MAX_LATE 10000000
    21742174void MythPlayer::AVSync2(VideoFrame *buffer)
    21752175{
    21762176    if (videoOutput->IsErrored())
    void MythPlayer::AVSync2(VideoFrame *buffer) 
    22442244        if (lateness > 30000)
    22452245            dropframe = !FlagIsSet(kMusicChoice) && numdroppedframes < 10;
    22462246
    2247         if (lateness <= 30000 && audiotimecode > 0 && normal_speed && !FlagIsSet(kMusicChoice))
     2247        if (audiotimecode > 0 && normal_speed && !FlagIsSet(kMusicChoice))
    22482248        {
    22492249            // Get video in sync with audio
    22502250            audio_adjustment = audiotimecode - videotimecode;
     2251            // If there is excess audio - throw it away.
     2252            if (audio_adjustment < -200)
     2253            {
     2254                audio.Reset();
     2255                audio_adjustment = 0;
     2256            }
    22512257            int sign = audio_adjustment < 0 ? -1 : 1;
     2258            int64_t fix_amount = avsync2adjustms;
     2259            // Faster catch-up when off by more than 200 ms
     2260            if (audio_adjustment * sign > 200)
     2261            {
     2262                // fix the sync within 15 - 20 frames
     2263                fix_amount = audio_adjustment * sign / 15;
     2264                if (fix_amount < avsync2adjustms)
     2265                    fix_amount = avsync2adjustms;
     2266            }
    22522267            if (audio_adjustment * sign > 40)
    22532268            {
    22542269                // adjust by AVSyncIncrementMS milliseconds at a time (range 1-40)
    2255                 rtcbase -= (int64_t)1000000 * avsync2adjustms * sign / playspeed1000;
     2270                int64_t speedup1000 = (float)1000 * play_speed;
     2271                rtcbase -= (int64_t)1000000 * fix_amount * sign / speedup1000;
    22562272                LOG(VB_PLAYBACK, LOG_INFO, LOC +
    22572273                    QString("AV Sync, audio ahead by %1 ms").arg(audio_adjustment));
    22582274            }