[Live-devel] Timestamp conversion in RTPSink.cpp
Ross Finlayson
finlayson at live555.com
Tue Nov 6 06:41:52 PST 2012
> Thank you very much for your answer. Your words make sense concerning the calculation!
> There were two different (independent) problems:
> 1 the underlined line returns 0 on Freescale's I.MX53 ARM cpu, the reason: "fTimestampFrequency*tv.tv_usec" is too large for 32bit. As the datatype of "timestampIncrement" is u_int32_t the calculation is performed with 32 bit width. On a 64bit PC this seems not to be a problem because it calculates automatically with 64bit. The fix for this is to use a u_int64_t
No, that shouldn't be necessary. The following should overcome the problem:
timestampIncrement += (u_int32_t)(fTimestampFrequency*(tv.tv_usec/1000000.0) + 0.5);
because the calculation will be done with floats, but then converted to a "u_int32_t" at the end - without any overflow.
(2.0*fTimestampFrequency*tv.tv_usec + 1000000.0)/2000000);
> 2 in the gettimeofday function in GroupSockHelper.cpp (line 700):
> Theres a define for WinCE, but unfortunately the WinCE version oft gettimeofday is not working properly, I assume that it wasn't tested?
I don't (and will never) use WinCE myself, so any contributions of WinCE-specific code - such as this - have come from other WinCErs. I have to trust that it works.
> You can find alot occurences of this problem in WinCE world. The problem is the "GetSystemTime()" call, which should fill the SYSTEMTIME struct, but it does not, at least not the milliseconds field (which is always 0). The solution I used:
>
> int gettimeofday(struct timeval* tp, int* /*tz*/) {
> #if defined(_WIN32_WCE)
> /* FILETIME of Jan 1 1970 00:00:00. */
> static const unsigned __int64 epoch = 116444736000000000LL;
> static Boolean isFirstCall = True;
> static LONGLONG unixStartTime = 0;
> static DWORD firstTickCount=0;
>
> if (isFirstCall) {
>
> FILETIME fileTime;
>
> GetSystemTimeAsFileTime(&fileTime);
>
> LARGE_INTEGER date;
> date.HighPart = fileTime.dwHighDateTime;
> date.LowPart = fileTime.dwLowDateTime;
>
> unixStartTime= (date.QuadPart - epoch) / 10000000L;
>
> firstTickCount = GetTickCount();
>
> tp->tv_sec=(long)unixStartTime;
> tp->tv_usec= 0L;
>
> isFirstCall = False; // for next time
>
> } else {
> // add elapsed seconds
> tp->tv_sec= (long)unixStartTime + (GetTickCount()-firstTickCount)/1000;
> tp->tv_usec=(GetTickCount()-firstTickCount)%1000 * 1000;
> }
>
> #else
OK, I'll make both these changes in the next release of the software.
Ross Finlayson
Live Networks, Inc.
http://www.live555.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20121106/cac2a692/attachment-0001.html>
More information about the live-devel
mailing list