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 extern bool tryingVideoSync;
00028
00045 class VideoSync
00046
00047 {
00048 public:
00049 VideoSync(VideoOutput*, int fi, int ri, bool intr);
00050 virtual ~VideoSync() {}
00051
00053 virtual QString getName(void) const = 0;
00055 virtual bool TryInit(void) = 0;
00056
00063 virtual void Start(void);
00064
00075 virtual int WaitForFrame(int sync_delay) = 0;
00076
00078 int getRefreshInterval(void) const { return m_refresh_interval; }
00080 void setRefreshInterval(int ri) { m_refresh_interval = ri; }
00081
00082 virtual void setFrameInterval(int fi) { m_frame_interval = fi; };
00083
00090 virtual void Stop(void) {}
00091
00092
00093 static VideoSync *BestMethod(VideoOutput*,
00094 uint frame_interval, uint refresh_interval,
00095 bool interlaced);
00096 protected:
00097 int64_t GetTime(void);
00098 int CalcDelay(void);
00099 void KeepPhase(void);
00100
00101 VideoOutput *m_video_output;
00102 int m_frame_interval;
00103 int m_refresh_interval;
00104 bool m_interlaced;
00105 int64_t m_nexttrigger;
00106 int m_delay;
00107
00108 static int m_forceskip;
00109 };
00110
00111 #ifndef _WIN32
00112
00118 class DRMVideoSync : public VideoSync
00119 {
00120 public:
00121 DRMVideoSync(VideoOutput*,
00122 int frame_interval, int refresh_interval, bool interlaced);
00123 ~DRMVideoSync();
00124
00125 QString getName(void) const { return QString("DRM"); }
00126 bool TryInit(void);
00127 void Start(void);
00128 int WaitForFrame(int sync_delay);
00129
00130 private:
00131 int m_dri_fd;
00132 static const char *sm_dri_dev;
00133
00134 };
00135 #endif // !_WIN32
00136
00137 #ifdef __linux__
00138
00148 class RTCVideoSync : public VideoSync
00149 {
00150 public:
00151 RTCVideoSync(VideoOutput*,
00152 int frame_interval, int refresh_interval, bool interlaced);
00153 ~RTCVideoSync();
00154
00155 QString getName(void) const { return QString("RTC"); }
00156 bool TryInit(void);
00157 int WaitForFrame(int sync_delay);
00158
00159 private:
00160 int m_rtcfd;
00161 };
00162 #endif
00163
00174 class BusyWaitVideoSync : public VideoSync
00175 {
00176 public:
00177 BusyWaitVideoSync(VideoOutput*,
00178 int frame_interval, int refresh_interval,
00179 bool interlaced);
00180 ~BusyWaitVideoSync();
00181
00182 QString getName(void) const { return QString("USleep with busy wait"); }
00183 bool TryInit(void);
00184 int WaitForFrame(int sync_delay);
00185
00186 private:
00187 int m_cheat;
00188 int m_fudge;
00189 };
00190
00201 class USleepVideoSync : public VideoSync
00202 {
00203 public:
00204 USleepVideoSync(VideoOutput*,
00205 int frame_interval, int refresh_interval,
00206 bool interlaced);
00207 ~USleepVideoSync();
00208
00209 QString getName(void) const { return QString("USleep"); }
00210 bool TryInit(void);
00211 int WaitForFrame(int sync_delay);
00212 };
00213
00214 class DummyVideoSync : public VideoSync
00215 {
00216 public:
00217 DummyVideoSync(VideoOutput* vo, int fr, int ri, bool intl)
00218 : VideoSync(vo, fr, ri, intl) { }
00219 ~DummyVideoSync() { }
00220
00221 QString getName(void) const { return QString("Dummy"); }
00222 bool TryInit(void) { return true; }
00223 int WaitForFrame(int sync_delay) { return 0; }
00224 };
00225 #endif