Don't use SystemTimeNanos() for current wallclock time on WINUWP

SystemTimeNanos() will soon be replaced with another implementation
when built with Chromium. This will break the assumption of
SystemTimeNanos() being relative to the NTP epoch. To avoid breaking
any UWP apps, call the TimeHelper::Ticks() function directly, which
is synchronized with the NTP epoch during initialization.

Bug: chromium:516700
Change-Id: I4e50cb3f88d06e1385e73b1a9ded52956501dc1f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/208520
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33324}
This commit is contained in:
Johannes Kron 2021-02-23 14:23:47 +01:00 committed by Commit Bot
parent d0844a80de
commit 373bb7bec4
4 changed files with 15 additions and 5 deletions

View file

@ -63,7 +63,7 @@ int64_t SystemTimeNanos() {
ticks = kNumNanosecsPerSec * static_cast<int64_t>(ts.tv_sec) + ticks = kNumNanosecsPerSec * static_cast<int64_t>(ts.tv_sec) +
static_cast<int64_t>(ts.tv_nsec); static_cast<int64_t>(ts.tv_nsec);
#elif defined(WINUWP) #elif defined(WINUWP)
ticks = TimeHelper::TicksNs(); ticks = WinUwpSystemTimeNanos();
#elif defined(WEBRTC_WIN) #elif defined(WEBRTC_WIN)
static volatile LONG last_timegettime = 0; static volatile LONG last_timegettime = 0;
static volatile int64_t num_wrap_timegettime = 0; static volatile int64_t num_wrap_timegettime = 0;

View file

@ -133,6 +133,10 @@ void SyncWithNtp(int64_t time_from_ntp_server_ms) {
TimeHelper::SyncWithNtp(time_from_ntp_server_ms); TimeHelper::SyncWithNtp(time_from_ntp_server_ms);
} }
int64_t WinUwpSystemTimeNanos() {
return TimeHelper::TicksNs();
}
#endif // defined(WINUWP) #endif // defined(WINUWP)
int64_t SystemTimeMillis() { int64_t SystemTimeMillis() {

View file

@ -62,6 +62,12 @@ RTC_EXPORT ClockInterface* GetClockForTesting();
// Synchronizes the current clock based upon an NTP server's epoch in // Synchronizes the current clock based upon an NTP server's epoch in
// milliseconds. // milliseconds.
void SyncWithNtp(int64_t time_from_ntp_server_ms); void SyncWithNtp(int64_t time_from_ntp_server_ms);
// Returns the current time in nanoseconds. The clock is synchonized with the
// system wall clock time upon instatiation. It may also be synchronized using
// the SyncWithNtp() function above. Please note that the clock will most likely
// drift away from the system wall clock time as time goes by.
int64_t WinUwpSystemTimeNanos();
#endif // defined(WINUWP) #endif // defined(WINUWP)
// Returns the actual system time, even if a clock is set for testing. // Returns the actual system time, even if a clock is set for testing.

View file

@ -90,10 +90,10 @@ class WinUwpRealTimeClock final : public RealTimeClock {
protected: protected:
timeval CurrentTimeVal() override { timeval CurrentTimeVal() override {
// The rtc::SystemTimeNanos() method is already time offset from a base // The rtc::WinUwpSystemTimeNanos() method is already time offset from a
// epoch value and might as be synchronized against an NTP time server as // base epoch value and might as be synchronized against an NTP time server
// an added bonus. // as an added bonus.
auto nanos = rtc::SystemTimeNanos(); auto nanos = rtc::WinUwpSystemTimeNanos();
struct timeval tv; struct timeval tv;