37 #ifndef RTPTIMEUTILITIES_H
39 #define RTPTIMEUTILITIES_H
41 #include "rtpconfig.h"
48 #include <sys/timeb.h>
49 #endif // _WIN32_WINCE
52 #define RTP_NTPTIMEOFFSET 2208988800UL
65 uint32_t
GetMSW()
const {
return msw; }
68 uint32_t
GetLSW()
const {
return lsw; }
100 RTPTime(uint32_t seconds,uint32_t microseconds) { sec = seconds; microsec = microseconds; }
109 double GetDouble()
const {
return (((
double)sec)+(((
double)microsec)/1000000.0)); }
116 bool operator<(
const RTPTime &t)
const;
117 bool operator>(
const RTPTime &t)
const;
118 bool operator<=(
const RTPTime &t)
const;
119 bool operator>=(
const RTPTime &t)
const;
121 uint32_t sec,microsec;
128 double t2 = t-((double)sec);
130 microsec = (uint32_t)t2;
135 if (ntptime.
GetMSW() < RTP_NTPTIMEOFFSET)
142 sec = ntptime.
GetMSW() - RTP_NTPTIMEOFFSET;
144 double x = (double)ntptime.
GetLSW();
145 x /= (65536.0*65536.0);
147 microsec = (uint32_t)x;
151 #if (defined(WIN32) || defined(_WIN32_WCE))
155 static int inited = 0;
156 static unsigned __int64 microseconds, initmicroseconds;
157 static LARGE_INTEGER performancefrequency;
159 unsigned __int64 emulate_microseconds, microdiff;
160 SYSTEMTIME systemtime;
163 LARGE_INTEGER performancecount;
165 QueryPerformanceCounter(&performancecount);
169 QueryPerformanceFrequency(&performancefrequency);
170 GetSystemTime(&systemtime);
171 SystemTimeToFileTime(&systemtime,&filetime);
172 microseconds = ( ((
unsigned __int64)(filetime.dwHighDateTime) << 32) + (
unsigned __int64)(filetime.dwLowDateTime) ) / 10ui64;
173 microseconds-= 11644473600000000ui64;
174 initmicroseconds = ( ( performancecount.QuadPart * 1000000ui64 ) / performancefrequency.QuadPart );
177 emulate_microseconds = ( ( performancecount.QuadPart * 1000000ui64 ) / performancefrequency.QuadPart );
179 microdiff = emulate_microseconds - initmicroseconds;
181 return RTPTime((uint32_t)((microseconds + microdiff) / 1000000ui64),((uint32_t)((microseconds + microdiff) % 1000000ui64)));
192 class RTPTimeInitializer
195 RTPTimeInitializer();
196 void Dummy() { dummy++; }
201 extern RTPTimeInitializer timeinit;
210 return RTPTime((uint32_t)tv.tv_sec,(uint32_t)tv.tv_usec);
215 struct timespec req,rem;
217 req.tv_sec = (time_t)delay.sec;
218 req.tv_nsec = ((
long)delay.microsec)*1000;
219 nanosleep(&req,&rem);
227 if (t.microsec > microsec)
232 microsec -= t.microsec;
239 microsec += t.microsec;
240 if (microsec >= 1000000)
250 uint32_t msw = sec+RTP_NTPTIMEOFFSET;
254 x = microsec/1000000.0;
255 x *= (65536.0*65536.0);
261 inline bool RTPTime::operator<(
const RTPTime &t)
const
267 if (microsec < t.microsec)
272 inline bool RTPTime::operator>(
const RTPTime &t)
const
278 if (microsec > t.microsec)
283 inline bool RTPTime::operator<=(
const RTPTime &t)
const
289 if (microsec <= t.microsec)
294 inline bool RTPTime::operator>=(
const RTPTime &t)
const
300 if (microsec >= t.microsec)
304 #endif // RTPTIMEUTILITIES_H
uint32_t GetLSW() const
Returns the least significant word.
Definition: rtptimeutilities.h:68
RTPNTPTime(uint32_t m, uint32_t l)
This constructor creates and instance with MSW m and LSW l.
Definition: rtptimeutilities.h:62
This class is used to specify wallclock time, delay intervals etc.
Definition: rtptimeutilities.h:77
RTPTime(uint32_t seconds, uint32_t microseconds)
Creates an instance corresponding to seconds and microseconds.
Definition: rtptimeutilities.h:100
RTPNTPTime GetNTPTime() const
Returns the NTP time corresponding to the time stored in this instance.
Definition: rtptimeutilities.h:248
uint32_t GetMSW() const
Returns the most significant word.
Definition: rtptimeutilities.h:65
double GetDouble() const
Returns the time stored in this instance, expressed in units of seconds.
Definition: rtptimeutilities.h:109
RTPTime(double t)
Creates an RTPTime instance representing t, which is expressed in units of seconds.
Definition: rtptimeutilities.h:124
uint32_t GetMicroSeconds() const
Returns the number of microseconds stored in this instance.
Definition: rtptimeutilities.h:106
static void Wait(const RTPTime &delay)
This function waits the amount of time specified in delay.
Definition: rtptimeutilities.h:213
static RTPTime CurrentTime()
Returns an RTPTime instance representing the current wallclock time.
Definition: rtptimeutilities.h:205
This is a simple wrapper for the most significant word (MSW) and least significant word (LSW) of an N...
Definition: rtptimeutilities.h:58
uint32_t GetSeconds() const
Returns the number of seconds stored in this instance.
Definition: rtptimeutilities.h:103