MythTV  master
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
VideoSync Class Referenceabstract

Virtual base class for all video synchronization classes. More...

#include <vsync.h>

Inheritance diagram for VideoSync:
Inheritance graph
[legend]
Collaboration diagram for VideoSync:
Collaboration graph
[legend]

Public Member Functions

 VideoSync (MythVideoOutput *, int refreshint)
 Used by BestMethod(VideoOutput*,uint) to initialize video synchronization method. More...
 
virtual ~VideoSync ()=default
 
virtual QString getName (void) const =0
 Returns name of instanciated VSync method. More...
 
virtual bool TryInit (void)=0
 Tries to initialize VSync method. More...
 
virtual void Start (void)
 Start VSync; must be called from main thread. More...
 
virtual int WaitForFrame (int nominal_frame_interval, int extra_delay)=0
 Waits for next a frame or field. More...
 
int getRefreshInterval (void) const
 Returns the (minimum) refresh interval of the output device. More...
 
void setRefreshInterval (int ri)
 Sets the refresh interval of the output device. More...
 
virtual void Stop (void)
 Stops VSync; must be called from main thread. More...
 

Static Public Member Functions

static VideoSyncBestMethod (MythVideoOutput *, uint refresh_interval)
 Returns the most sophisticated video sync method available. More...
 

Protected Member Functions

int CalcDelay (int nominal_frame_interval)
 Calculates the delay to the next frame. More...
 

Static Protected Member Functions

static int64_t GetTime (void)
 

Protected Attributes

MythVideoOutputm_video_output {nullptr}
 
int m_refresh_interval
 
int64_t m_nexttrigger {0}
 
int m_delay {-1}
 

Static Protected Attributes

static int s_forceskip = 0
 

Detailed Description

Virtual base class for all video synchronization classes.

This set of classes implements a variety of algorithms for synching video frames to a display. The better algorithms synchronize to the display's refresh rate, and also attempt to maintain phase with respect to the vertical retrace. The poorer algorithms simply try to display frames at a regular interval.

The factory method BestMethod tries subclasses in roughly quality order until one succeeds.

A/V sync methods may supply the nominal delay per frame. Other than that, video timing is entirely up to these classes. When WaitForFrame returns, it is time to show the frame.

Definition at line 45 of file vsync.h.

Constructor & Destructor Documentation

◆ VideoSync()

VideoSync::VideoSync ( MythVideoOutput video_output,
int  refreshint 
)

Used by BestMethod(VideoOutput*,uint) to initialize video synchronization method.

Definition at line 104 of file vsync.cpp.

◆ ~VideoSync()

virtual VideoSync::~VideoSync ( )
virtualdefault

Member Function Documentation

◆ getName()

virtual QString VideoSync::getName ( void  ) const
pure virtual

Returns name of instanciated VSync method.

Implemented in DummyVideoSync, USleepVideoSync, and BusyWaitVideoSync.

Referenced by MythPlayer::InitAVSync().

◆ TryInit()

virtual bool VideoSync::TryInit ( void  )
pure virtual

Tries to initialize VSync method.

Implemented in DummyVideoSync, USleepVideoSync, and BusyWaitVideoSync.

◆ Start()

void VideoSync::Start ( void  )
virtual

Start VSync; must be called from main thread.

Start(void), WaitForFrame(void), and Stop(void) should always be called from same thread, to prevent bad interactions with threads.

Definition at line 116 of file vsync.cpp.

Referenced by MythPlayer::DisplayPauseFrame(), MythPlayer::InitAVSync(), MythPlayer::PrebufferEnoughFrames(), and MythPlayer::VideoStart().

◆ WaitForFrame()

virtual int VideoSync::WaitForFrame ( int  nominal_frame_interval,
int  extra_delay 
)
pure virtual

Waits for next a frame or field.

Returns delay to real frame timing in usec

Start(void), WaitForFrame(void), and Stop(void) should always be called from same thread, to prevent bad interactions with threads.

Parameters
nominal_frame_intervalthe frame interval normally expected
extra_delayextra time beyond nominal until the desired frame or field
See also
CalcDelay(int), KeepPhase(void)

Implemented in DummyVideoSync, USleepVideoSync, and BusyWaitVideoSync.

Referenced by MythPlayer::AVSync().

◆ getRefreshInterval()

int VideoSync::getRefreshInterval ( void  ) const
inline

Returns the (minimum) refresh interval of the output device.

Definition at line 79 of file vsync.h.

Referenced by MythPlayer::CanSupportDoubleRate(), and MythPlayer::ReinitVideo().

◆ setRefreshInterval()

void VideoSync::setRefreshInterval ( int  ri)
inline

Sets the refresh interval of the output device.

Definition at line 81 of file vsync.h.

Referenced by MythPlayer::ReinitVideo().

◆ Stop()

virtual void VideoSync::Stop ( void  )
inlinevirtual

Stops VSync; must be called from main thread.

Start(void), WaitForFrame(void), and Stop(void) should always be called from same thread, to prevent bad interactions with threads.

Definition at line 89 of file vsync.h.

◆ BestMethod()

VideoSync * VideoSync::BestMethod ( MythVideoOutput video_output,
uint  refresh_interval 
)
static

Returns the most sophisticated video sync method available.

Definition at line 69 of file vsync.cpp.

Referenced by MythPlayer::VideoStart().

◆ GetTime()

int64_t VideoSync::GetTime ( void  )
staticprotected

Definition at line 109 of file vsync.cpp.

Referenced by CalcDelay(), and Start().

◆ CalcDelay()

int VideoSync::CalcDelay ( int  nominal_frame_interval)
protected

Calculates the delay to the next frame.

Regardless of the timing method, if delay is greater than four full frames (could be greater than 20 or greater than 200), we don't want to freeze while waiting for a huge delay. Instead, contine playing video at half speed and continue to read new audio and video frames from the file until the sync is 'in the ballpark'. Also prevent the nexttrigger from falling too far in the past in case we are trying to speed up video output faster than possible.

Definition at line 132 of file vsync.cpp.

Referenced by BusyWaitVideoSync::WaitForFrame(), and USleepVideoSync::WaitForFrame().

Member Data Documentation

◆ m_video_output

MythVideoOutput* VideoSync::m_video_output {nullptr}
protected

Definition at line 98 of file vsync.h.

◆ m_refresh_interval

int VideoSync::m_refresh_interval
protected

Definition at line 99 of file vsync.h.

Referenced by CalcDelay(), getRefreshInterval(), and setRefreshInterval().

◆ m_nexttrigger

int64_t VideoSync::m_nexttrigger {0}
protected

◆ m_delay

int VideoSync::m_delay {-1}
protected

Definition at line 101 of file vsync.h.

Referenced by BusyWaitVideoSync::WaitForFrame(), and USleepVideoSync::WaitForFrame().

◆ s_forceskip

int VideoSync::s_forceskip = 0
staticprotected

Definition at line 103 of file vsync.h.


The documentation for this class was generated from the following files: