VideoSync Class Reference

#include <vsync.h>

Inheritance diagram for VideoSync:

BusyWaitVideoSync DRMVideoSync nVidiaVideoSync OpenGLVideoSync RTCVideoSync USleepVideoSync

List of all members.


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 an additonal delay per frame. Other than that, video timing is entirely up to these classes. When WaitForFrame returns, it is time to show the frame.

There is some basic support for interlaced video timing where the fields need to be displayed sequentially. Passing true for the interlaced flags for the constructors, BestMethod, and SetFrameInterval will cause us to wait for half the specified frame interval, if the refresh rate is sufficient to do so.

Definition at line 58 of file vsync.h.


Public Member Functions

 VideoSync (VideoOutput *, int fi, int ri, bool intr)
 Used by BestMethod(VideoOutput*,uint,uint,bool) to initialize video synchronization method.
virtual ~VideoSync ()
virtual QString getName (void) const =0
 Returns name of instanciated VSync method.
virtual bool TryInit (void)=0
 Tries to initialize VSync method.
virtual void Start (void)
 Start VSync; must be called from main thread.
virtual void WaitForFrame (int sync_delay)=0
 Waits for next a frame or field.
virtual void AdvanceTrigger (void)=0
 Use the next frame or field for CalcDelay(void) and WaitForFrame(int).
void SetFrameInterval (int fi, bool interlaced)
 Change frame interval and interlacing attributes.
bool UsesFieldInterval (void) const
 Returns true AdvanceTrigger(void) advances a field at a time.
bool UsesFrameInterval (void) const
 Returns true AdvanceTrigger(void) advances a frame at a time.
virtual void Stop (void)
 Stops VSync; must be called from main thread.

Static Public Member Functions

static VideoSyncBestMethod (VideoOutput *, uint frame_interval, uint refresh_interval, bool interlaced)
 Returns the most sophisticated video sync method available.

Protected Member Functions

void UpdateNexttrigger (void)
 Internal method to tells video synchronization method to use the next frame (or field, if interlaced) for CalcDelay() and WaitForFrame().
int CalcDelay (void)
 Calculates the delay to the next frame.
void KeepPhase (void)
 Keep our nexttrigger from drifting too close to the exact retrace.

Static Protected Member Functions

static void OffsetTimeval (struct timeval &tv, int offset)

Protected Attributes

VideoOutputm_video_output
int m_frame_interval
int m_refresh_interval
bool m_interlaced
struct timeval m_nexttrigger
int m_delay

Static Protected Attributes

static int m_forceskip = 0

Constructor & Destructor Documentation

VideoSync::VideoSync ( VideoOutput video_output,
int  fi,
int  ri,
bool  intr 
)

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

Definition at line 114 of file vsync.cpp.

virtual VideoSync::~VideoSync (  )  [inline, virtual]

Definition at line 63 of file vsync.h.


Member Function Documentation

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

Returns name of instanciated VSync method.

Implemented in DRMVideoSync, nVidiaVideoSync, OpenGLVideoSync, RTCVideoSync, BusyWaitVideoSync, and USleepVideoSync.

Referenced by NuppelVideoPlayer::InitAVSync().

virtual bool VideoSync::TryInit ( void   )  [pure virtual]

Tries to initialize VSync method.

Implemented in DRMVideoSync, nVidiaVideoSync, OpenGLVideoSync, RTCVideoSync, BusyWaitVideoSync, and USleepVideoSync.

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 pthreads.

Reimplemented in DRMVideoSync, nVidiaVideoSync, and OpenGLVideoSync.

Definition at line 127 of file vsync.cpp.

Referenced by NuppelVideoPlayer::DisplayPauseFrame(), NuppelVideoPlayer::InitAVSync(), NuppelVideoPlayer::OutputVideoLoop(), NuppelVideoPlayer::PrebufferEnoughFrames(), OpenGLVideoSync::Start(), nVidiaVideoSync::Start(), and DRMVideoSync::Start().

virtual void VideoSync::WaitForFrame ( int  sync_delay  )  [pure virtual]

Waits for next a frame or field.

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

Parameters:
sync_delay time until the desired frame or field
See also:
CalcDelay(void), KeepPhase(void)

Implemented in DRMVideoSync, nVidiaVideoSync, OpenGLVideoSync, RTCVideoSync, BusyWaitVideoSync, and USleepVideoSync.

Referenced by NuppelVideoPlayer::AVSync().

virtual void VideoSync::AdvanceTrigger ( void   )  [pure virtual]

void VideoSync::SetFrameInterval ( int  fi,
bool  interlaced 
)

bool VideoSync::UsesFieldInterval ( void   )  const [inline]

Returns true AdvanceTrigger(void) advances a field at a time.

Definition at line 96 of file vsync.h.

Referenced by NuppelVideoPlayer::OutputVideoLoop(), and NuppelVideoPlayer::SetScanType().

bool VideoSync::UsesFrameInterval ( void   )  const [inline]

Returns true AdvanceTrigger(void) advances a frame at a time.

Definition at line 98 of file vsync.h.

virtual void VideoSync::Stop ( void   )  [inline, virtual]

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 pthreads.

Definition at line 106 of file vsync.h.

Referenced by OpenGLVideoSync::~OpenGLVideoSync().

VideoSync * VideoSync::BestMethod ( VideoOutput video_output,
uint  frame_interval,
uint  refresh_interval,
bool  interlaced 
) [static]

Returns the most sophisticated video sync method available.

Definition at line 73 of file vsync.cpp.

Referenced by NuppelVideoPlayer::OutputVideoLoop().

void VideoSync::OffsetTimeval ( struct timeval &  tv,
int  offset 
) [static, protected]

void VideoSync::UpdateNexttrigger ( void   )  [protected]

Internal method to tells video synchronization method to use the next frame (or field, if interlaced) for CalcDelay() and WaitForFrame().

Definition at line 166 of file vsync.cpp.

Referenced by USleepVideoSync::AdvanceTrigger(), BusyWaitVideoSync::AdvanceTrigger(), RTCVideoSync::AdvanceTrigger(), OpenGLVideoSync::AdvanceTrigger(), nVidiaVideoSync::AdvanceTrigger(), and DRMVideoSync::AdvanceTrigger().

int VideoSync::CalcDelay ( void   )  [protected]

Calculates the delay to the next frame.

Regardless of the timing method, if delay is greater than two 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'.

Definition at line 185 of file vsync.cpp.

Referenced by USleepVideoSync::WaitForFrame(), BusyWaitVideoSync::WaitForFrame(), RTCVideoSync::WaitForFrame(), OpenGLVideoSync::WaitForFrame(), nVidiaVideoSync::WaitForFrame(), and DRMVideoSync::WaitForFrame().

void VideoSync::KeepPhase ( void   )  [protected]

Keep our nexttrigger from drifting too close to the exact retrace.

If delay is near zero, some frames will be delay < 0 and others delay > 0 which would cause continous rapid fire stuttering. This method is only useful for those sync methods where WaitForFrame targets hardware retrace rather than targeting nexttrigger.

Definition at line 220 of file vsync.cpp.

Referenced by OpenGLVideoSync::AdvanceTrigger(), nVidiaVideoSync::AdvanceTrigger(), and DRMVideoSync::AdvanceTrigger().


Member Data Documentation

int VideoSync::m_frame_interval [protected]

Definition at line 119 of file vsync.h.

Referenced by CalcDelay(), SetFrameInterval(), UpdateNexttrigger(), and VideoSync().

struct timeval VideoSync::m_nexttrigger [read, protected]

int VideoSync::m_delay [protected]

int VideoSync::m_forceskip = 0 [static, protected]

Definition at line 125 of file vsync.h.

Referenced by BestMethod().


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

Generated on Sat Dec 18 05:16:14 2010 for MythTV by  doxygen 1.5.5