#include <vsync.h>

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 VideoSync * | BestMethod (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 | |
| VideoOutput * | m_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 |
| VideoSync::VideoSync | ( | VideoOutput * | video_output, | |
| int | fi, | |||
| int | ri, | |||
| bool | intr | |||
| ) |
Used by BestMethod(VideoOutput*,uint,uint,bool) to initialize video synchronization method.
| 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.
| sync_delay | time until the desired frame or field |
Implemented in DRMVideoSync, nVidiaVideoSync, OpenGLVideoSync, RTCVideoSync, BusyWaitVideoSync, and USleepVideoSync.
Referenced by NuppelVideoPlayer::AVSync().
| virtual void VideoSync::AdvanceTrigger | ( | void | ) | [pure virtual] |
Use the next frame or field for CalcDelay(void) and WaitForFrame(int).
Implemented in DRMVideoSync, nVidiaVideoSync, OpenGLVideoSync, RTCVideoSync, BusyWaitVideoSync, and USleepVideoSync.
Referenced by NuppelVideoPlayer::AVSync().
| void VideoSync::SetFrameInterval | ( | int | fi, | |
| bool | interlaced | |||
| ) |
Change frame interval and interlacing attributes.
Definition at line 135 of file vsync.cpp.
Referenced by NuppelVideoPlayer::DoPause(), NuppelVideoPlayer::DoPlay(), NuppelVideoPlayer::FallbackDeint(), NuppelVideoPlayer::OutputVideoLoop(), and NuppelVideoPlayer::SetScanType().
| 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.
| 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] |
Definition at line 146 of file vsync.cpp.
Referenced by CalcDelay(), KeepPhase(), UpdateNexttrigger(), USleepVideoSync::WaitForFrame(), BusyWaitVideoSync::WaitForFrame(), RTCVideoSync::WaitForFrame(), OpenGLVideoSync::WaitForFrame(), nVidiaVideoSync::WaitForFrame(), and DRMVideoSync::WaitForFrame().
| 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().
VideoOutput* VideoSync::m_video_output [protected] |
Definition at line 118 of file vsync.h.
Referenced by OpenGLVideoSync::Start(), OpenGLVideoSync::TryInit(), OpenGLVideoSync::WaitForFrame(), and OpenGLVideoSync::~OpenGLVideoSync().
int VideoSync::m_frame_interval [protected] |
Definition at line 119 of file vsync.h.
Referenced by CalcDelay(), SetFrameInterval(), UpdateNexttrigger(), and VideoSync().
int VideoSync::m_refresh_interval [protected] |
Definition at line 120 of file vsync.h.
Referenced by KeepPhase(), SetFrameInterval(), VideoSync(), OpenGLVideoSync::WaitForFrame(), nVidiaVideoSync::WaitForFrame(), and DRMVideoSync::WaitForFrame().
bool VideoSync::m_interlaced [protected] |
Definition at line 121 of file vsync.h.
Referenced by CalcDelay(), SetFrameInterval(), UpdateNexttrigger(), UsesFieldInterval(), UsesFrameInterval(), and VideoSync().
struct timeval VideoSync::m_nexttrigger [read, protected] |
Definition at line 122 of file vsync.h.
Referenced by CalcDelay(), KeepPhase(), Start(), UpdateNexttrigger(), USleepVideoSync::WaitForFrame(), BusyWaitVideoSync::WaitForFrame(), RTCVideoSync::WaitForFrame(), OpenGLVideoSync::WaitForFrame(), nVidiaVideoSync::WaitForFrame(), and DRMVideoSync::WaitForFrame().
int VideoSync::m_delay [protected] |
Definition at line 123 of file vsync.h.
Referenced by KeepPhase(), USleepVideoSync::WaitForFrame(), BusyWaitVideoSync::WaitForFrame(), RTCVideoSync::WaitForFrame(), OpenGLVideoSync::WaitForFrame(), nVidiaVideoSync::WaitForFrame(), and DRMVideoSync::WaitForFrame().
int VideoSync::m_forceskip = 0 [static, protected] |
1.5.5