Ticket #13494: audio_frame_sync.patch

File audio_frame_sync.patch, 2.7 KB (added by madscientist159, 7 years ago)
  • mythtv/libs/libmythtv/mythplayer.cpp

    diff -ur mythtv/libs/libmythtv/mythplayer.cpp mythtv/libs/libmythtv/mythplayer.cpp
     
    620620                    .arg(videosync->getRefreshInterval())
    621621                    .arg(ri));
    622622                videosync->setRefreshInterval(ri);
     623                ApplyVideoPipelineFrameDelay(ri);
    623624             }
    624625        }
    625626
     
    17861787                                refreshrate);
    17871788}
    17881789
     1790void MythPlayer::ApplyVideoPipelineFrameDelay(int refreshrate)
     1791{
     1792    // apply VideoSyncDelayFrames if applicable
     1793    double output_rate = 1000000.0 / refreshrate;
     1794    LOG(VB_PLAYBACK, LOG_INFO, LOC +
     1795        QString("Using output refresh rate of %1 for pipelined video audio synchronization")
     1796        .arg(output_rate));
     1797
     1798    tc_wrap_frameoffset[TC_AUDIO] = ((1000.0 / output_rate)
     1799                * gCoreContext->GetNumSetting("VideoSyncDelayFrames", 0));
     1800    LOG(VB_PLAYBACK, LOG_INFO, LOC +
     1801        QString("Calculated delay: %1ms")
     1802        .arg(tc_wrap_frameoffset[TC_AUDIO]));
     1803
     1804    this->AdjustAudioTimecodeOffset(
     1805                0, gCoreContext->GetNumSetting("AudioSyncOffset", 0)
     1806                + tc_wrap_frameoffset[TC_AUDIO]);
     1807}
     1808
    17891809void MythPlayer::ResetAVSync(void)
    17901810{
    17911811    avsync_avg = 0;
     
    18371857
    18381858        SetFrameInterval(m_scan, 1.0 / (video_frame_rate * play_speed));
    18391859
     1860        ApplyVideoPipelineFrameDelay(refreshrate);
     1861
    18401862        // try to get preferential scheduling, but ignore if we fail to.
    18411863        myth_nice(-19);
    18421864    }
  • mythtv/libs/libmythtv/mythplayer.h

    diff -ur mythtv/libs/libmythtv/mythplayer.h mythtv/libs/libmythtv/mythplayer.h
     
    549549    // Time Code adjustment stuff
    550550    int64_t AdjustAudioTimecodeOffset(int64_t v, int newsync = -9999);
    551551    int64_t GetAudioTimecodeOffset(void) const
    552         { return tc_wrap[TC_AUDIO]; }
     552        { return tc_wrap[TC_AUDIO] - tc_wrap_frameoffset[TC_AUDIO]; }
    553553
    554554    // Playback (output) zoom automation
    555555    DetectLetterbox *detect_letter_box;
     
    613613    void  WrapTimecode(int64_t &timecode, TCTypes tc_type);
    614614    void  InitAVSync(void);
    615615    virtual void AVSync(VideoFrame *buffer, bool limit_delay = false);
     616    void ApplyVideoPipelineFrameDelay(int refreshrate);
    616617    void  ResetAVSync(void);
    617618    int64_t AVSyncGetAudiotime(void);
    618619    void  SetFrameInterval(FrameScanType scan, double speed);
     
    838839    int        prevtc;        ///< 32 bit timecode if last VideoFrame shown
    839840    int        prevrp;        ///< repeat_pict of last frame
    840841    int64_t    tc_wrap[TCTYPESMAX];
     842    int64_t    tc_wrap_frameoffset[TCTYPESMAX];
    841843    int64_t    tc_lastval[TCTYPESMAX];
    842844    int64_t    savedAudioTimecodeOffset;
    843845