[Live-devel] minor bug on windows implementation ofgettimeofday()

Patrick White patbob at imoveinc.com
Thu Apr 2 10:32:04 PDT 2009


This will work, but time() only has resolution of 1 second, so your times 
reported by gettimeofday() will be consistently off by up to 1 full second 
from what they should really be.  If you do the same thing with ftime(), 
you'll be consistenly off by somewhere in the 10s of milliseconds.

It doesn't really matter, but if we go with the time() fix, someone down the 
road will probably notice the RR packet last-received times are off by a 
second and we'll be fixing it all over again :)

I've got other bugs to finish swatting today, but I'll post a proposed fix 
that uses ftime when I can.. if its still relevant and needed by then.

patbob




On Thursday 02 April 2009 1:51 am, I-McMahon, Andrew P wrote:
> A suggestion for this could be to intialise using time() to get UTC time,
> then use QueryPerformanceFrequency/QueryPerformanceCounter from then on,
> like this:
>
> int gettimeofday(struct timeval* tp, int* /*tz*/) {
>   static bool tickFrequencySet = false;
>   static unsigned __int64 tickFrequency = 0;
>   static unsigned __int64 timeOffset = 0;
>
>   unsigned __int64 tickNow;
>
>   if (tickFrequencySet == false) {
>    
> QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&tickFrequency))
>;
>
>     time_t t;
>     time(&t);
>
>     QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&tickNow));
>     tickNow /= tickFrequency;
>     timeOffset = t - tickNow;
>
>     tickFrequencySet = true;
>   }
>
>   QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&tickNow));
>   tp->tv_sec = static_cast<long>((tickNow / tickFrequency) + timeOffset);
>   tp->tv_usec = static_cast<long>(((tickNow % tickFrequency) * 1000000L) /
> tickFrequency);
>
>   return 0;
> }
>
> (better implementations of this are probably available ;))
>
> Andy M
>
> -----Original Message-----
> From: Sébastien Escudier [mailto:sebastien-devel at celeos.eu]
> Sent: 2009-04-02 07:58
> To: LIVE555 Streaming Media - development & use
> Subject: Re: [Live-devel] minor bug on windows implementation
> ofgettimeofday()
>
> Quoting Ross Finlayson <finlayson at live555.com>:
> > Unfortunately I'm not an expert on Windoze-specific API stuff.
>
> You may have a look at vlc times functions :
>
> http://git.videolan.org/gitweb.cgi?p=vlc.git;a=blob;f=src/misc/mtime.c;h=0d
>bb4df578308b38e6e3ff9487b0e9143f11853b;hb=HEAD
>
> or for a direct access to the file :
>
> http://git.videolan.org/gitweb.cgi?p=vlc.git;a=blob_plain;f=src/misc/mtime.
>c;hb=HEAD
>
> If you need a high precision clock, with a random epoch, look at mdate.
> If you need a constant epoch look at gettimeofday
>
> _______________________________________________
> live-devel mailing list
> live-devel at lists.live555.com
> http://lists.live555.com/mailman/listinfo/live-devel
> _______________________________________________
> live-devel mailing list
> live-devel at lists.live555.com
> http://lists.live555.com/mailman/listinfo/live-devel


More information about the live-devel mailing list