[Live-devel] Timestamp conversion in RTPSink.cpp
Roehrl, Simon
simon.roehrl.ext at siemens.com
Thu Nov 8 08:04:11 PST 2012
The windows (not CE) implementation wasn't threadsafe, so I've changed that code too.
Find attached the new GroupsockHelper.cpp. This solution is ok for us, so I won't spend any further time in this topic
________________________________
From: live-devel-bounces at ns.live555.com [mailto:live-devel-bounces at ns.live555.com] On Behalf Of Ross Finlayson
Sent: Dienstag, 6. November 2012 16:00
To: LIVE555 Streaming Media - development & use
Subject: Re: [Live-devel] Timestamp conversion in RTPSink.cpp
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
Correction: On further thought, I don't want to make this change 'as is'. The problem is that it's possible for the "gettimeofday()" function to be called concurrently from multiple threads. (This is legal for LIVE555-based systems that use different "UsageEnvironment" and "TaskScheduler" objects for each thread.) So, the implementation needs to be 'thread safe'. If the "if" branch of the "if (isFirstCall)" statement gets executed concurrently by more than one thread, then "unixStartTime" and/or "firstTickCount" might get set to bad values.
So, please rewrite your implementation to ensure that the "if" branch of the code (i.e., the part of the code that sets static variables) is executed only once, even if the code is called by multiple threads. (Because this code is for WinCE only, it's OK to use some WinCE-specific locking mechanism, if necessary.)
(However, I'll make the change to the timestamp conversion code 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/20121108/02e8a588/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: GroupsockHelper.cpp
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20121108/02e8a588/attachment-0001.ksh>
More information about the live-devel
mailing list