00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef VSYNC_H_INCLUDED
00020 #define VSYNC_H_INCLUDED
00021
00022 #include <sys/time.h>
00023 #include <time.h>
00024
00025 class VideoOutput;
00026
00027 typedef unsigned long GLXDrawable;
00028 #ifdef USING_OPENGL
00029 typedef struct __GLXcontextRec *GLXContext;
00030 #else
00031 typedef void *GLXContext;
00032 #endif
00033
00034 extern bool tryingVideoSync;
00035
00058 class VideoSync
00059
00060 {
00061 public:
00062 VideoSync(VideoOutput*, int fi, int ri, bool intr);
00063 virtual ~VideoSync() {}
00064
00066 virtual QString getName(void) const = 0;
00068 virtual bool TryInit(void) = 0;
00069
00076 virtual void Start(void);
00077
00087 virtual void WaitForFrame(int sync_delay) = 0;
00088
00091 virtual void AdvanceTrigger(void) = 0;
00092
00093 void SetFrameInterval(int fi, bool interlaced);
00094
00096 bool UsesFieldInterval(void) const { return m_interlaced; }
00098 bool UsesFrameInterval(void) const { return !m_interlaced; }
00099
00106 virtual void Stop(void) {}
00107
00108
00109 static VideoSync *BestMethod(VideoOutput*,
00110 uint frame_interval, uint refresh_interval,
00111 bool interlaced);
00112 protected:
00113 static void OffsetTimeval(struct timeval& tv, int offset);
00114 void UpdateNexttrigger(void);
00115 int CalcDelay(void);
00116 void KeepPhase(void);
00117
00118 VideoOutput *m_video_output;
00119 int m_frame_interval;
00120 int m_refresh_interval;
00121 bool m_interlaced;
00122 struct timeval m_nexttrigger;
00123 int m_delay;
00124
00125 static int m_forceskip;
00126 };
00127
00128 #ifndef _WIN32
00129
00135 class DRMVideoSync : public VideoSync
00136 {
00137 public:
00138 DRMVideoSync(VideoOutput*,
00139 int frame_interval, int refresh_interval, bool interlaced);
00140 ~DRMVideoSync();
00141
00142 QString getName(void) const { return QString("DRM"); }
00143 bool TryInit(void);
00144 void Start(void);
00145 void WaitForFrame(int sync_delay);
00146 void AdvanceTrigger(void);
00147
00148 private:
00149 int m_dri_fd;
00150 static char *sm_dri_dev;
00151
00152 };
00153 #endif // !_WIN32
00154
00155 #ifndef _WIN32
00156
00163 class nVidiaVideoSync : public VideoSync
00164 {
00165 public:
00166 nVidiaVideoSync(VideoOutput*,
00167 int frame_interval, int refresh_interval, bool interlaced);
00168 ~nVidiaVideoSync();
00169
00170 QString getName(void) const { return QString("nVidia polling"); }
00171 bool TryInit(void);
00172 void Start(void);
00173 void WaitForFrame(int sync_delay);
00174 void AdvanceTrigger(void);
00175
00176 private:
00177 bool dopoll(void) const;
00178 int m_nvidia_fd;
00179 static char *sm_nvidia_dev;
00180 };
00181 #endif // !_WIN32
00182
00183 #ifndef _WIN32
00184
00205 class OpenGLVideoSync : public VideoSync
00206 {
00207 public:
00208 OpenGLVideoSync(VideoOutput*,
00209 int frame_interval, int refresh_interval, bool interlaced);
00210 ~OpenGLVideoSync();
00211
00212 QString getName(void) const { return QString("SGI OpenGL"); }
00213 bool TryInit(void);
00214 void Start(void);
00215 void WaitForFrame(int sync_delay);
00216 void AdvanceTrigger(void);
00217
00218 private:
00219 GLXDrawable m_drawable;
00220 GLXContext m_context;
00221
00222 private:
00223 QMutex m_lock;
00224 };
00225 #endif // !_WIN32
00226
00227 #ifdef __linux__
00228
00238 class RTCVideoSync : public VideoSync
00239 {
00240 public:
00241 RTCVideoSync(VideoOutput*,
00242 int frame_interval, int refresh_interval, bool interlaced);
00243 ~RTCVideoSync();
00244
00245 QString getName(void) const { return QString("RTC"); }
00246 bool TryInit(void);
00247 void WaitForFrame(int sync_delay);
00248 void AdvanceTrigger(void);
00249
00250 private:
00251 int m_rtcfd;
00252 };
00253 #endif
00254
00265 class BusyWaitVideoSync : public VideoSync
00266 {
00267 public:
00268 BusyWaitVideoSync(VideoOutput*,
00269 int frame_interval, int refresh_interval,
00270 bool interlaced);
00271 ~BusyWaitVideoSync();
00272
00273 QString getName(void) const { return QString("USleep with busy wait"); }
00274 bool TryInit(void);
00275 void WaitForFrame(int sync_delay);
00276 void AdvanceTrigger(void);
00277
00278 private:
00279 int m_cheat;
00280 int m_fudge;
00281 };
00282
00293 class USleepVideoSync : public VideoSync
00294 {
00295 public:
00296 USleepVideoSync(VideoOutput*,
00297 int frame_interval, int refresh_interval,
00298 bool interlaced);
00299 ~USleepVideoSync();
00300
00301 QString getName(void) const { return QString("USleep"); }
00302 bool TryInit(void);
00303 void WaitForFrame(int sync_delay);
00304 void AdvanceTrigger(void);
00305 };
00306 #endif