Bug 978239 - Synchronize WindowsRealTimeClock to unmess RTCP timestamps. r=jesup
authorJan-Ivar Bruaroey <jib@mozilla.com>
Fri, 28 Feb 2014 15:42:24 -0500
changeset 171884 978b9e3f1f679d410e512f80a4248a072bb93616
parent 171883 23fd17482127f1f14cdcc1929007ce96077312fa
child 171885 2040ee2eff0f003dcde97d9357a0d740b228619d
child 171908 9024f38e38092c649f3a5bcd9eaee5ebf20e2c59
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersjesup
bugs978239
milestone30.0a1
Bug 978239 - Synchronize WindowsRealTimeClock to unmess RTCP timestamps. r=jesup
media/webrtc/trunk/webrtc/system_wrappers/source/clock.cc
--- a/media/webrtc/trunk/webrtc/system_wrappers/source/clock.cc
+++ b/media/webrtc/trunk/webrtc/system_wrappers/source/clock.cc
@@ -228,22 +228,36 @@ class UnixRealTimeClock : public RealTim
 };
 #endif
 
 
 #if defined(_WIN32)
 // Keeps the global state for the Windows implementation of RtpRtcpClock.
 // Note that this is a POD. Only PODs are allowed to have static storage
 // duration according to the Google Style guide.
-static WindowsHelpTimer global_help_timer = {0, 0, {{ 0, 0}, 0}, 0};
+//
+// Note that on Windows, GetSystemTimeAsFileTime has poorer (up to 15 ms)
+// resolution than the media timers, hence the WindowsHelpTimer context
+// object and Synchronize API.
+//
+// We only sync up once, which means that on Windows, our realtime clock
+// wont respond to system time/date changes without a program restart.
+// TODO: We could attempt to detect 1+ minute jumps and resync for parity
+// with other platforms.
+
+static WindowsHelpTimer *SyncGlobalHelpTimer() {
+  static WindowsHelpTimer global_help_timer = {0, 0, {{ 0, 0}, 0}, 0};
+  Synchronize(&global_help_timer);
+  return &global_help_timer;
+}
 #endif
 
 Clock* Clock::GetRealTimeClock() {
 #if defined(_WIN32)
-  static WindowsRealTimeClock clock(&global_help_timer);
+  static WindowsRealTimeClock clock(SyncGlobalHelpTimer());
   return &clock;
 #elif ((defined WEBRTC_LINUX) || (defined WEBRTC_BSD) || (defined WEBRTC_MAC))
   static UnixRealTimeClock clock;
   return &clock;
 #else
   return NULL;
 #endif
 }