From 3e1fbd44bc74e07ebacb6c80cccb61df7d9ea8a3 Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Fri, 28 Feb 2014 15:42:24 -0500 Subject: [PATCH] Bug 978239 - Synchronize WindowsRealTimeClock to unmess RTCP timestamps. r=jesup --- .../webrtc/system_wrappers/source/clock.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/media/webrtc/trunk/webrtc/system_wrappers/source/clock.cc b/media/webrtc/trunk/webrtc/system_wrappers/source/clock.cc index 6ae1e97480ed..a6fb280891d3 100644 --- a/media/webrtc/trunk/webrtc/system_wrappers/source/clock.cc +++ b/media/webrtc/trunk/webrtc/system_wrappers/source/clock.cc @@ -233,12 +233,26 @@ class UnixRealTimeClock : public RealTimeClock { // 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;