Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Unified Diff: media/cast/cast_ntp_tick_clock.cc

Issue 34623008: Change to calculate the real NTP in TimeTicks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/cast/cast_ntp_tick_clock.cc
diff --git a/media/cast/cast_ntp_tick_clock.cc b/media/cast/cast_ntp_tick_clock.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2ce77b5c08571b891131d5342e4503ac2b1e6746
--- /dev/null
+++ b/media/cast/cast_ntp_tick_clock.cc
@@ -0,0 +1,43 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/cast/cast_ntp_tick_clock.h"
+
+namespace media {
+namespace cast {
+
+// Network Time Protocol (NTP), which is in seconds relative to 0h UTC on
+// 1 January 1900.
+static const int64 kNtpEpochDeltaSeconds = GG_INT64_C(9435484800);
+
+// January 1970, in NTP seconds.
+// Network Time Protocol (NTP), which is in seconds relative to 0h UTC on
+// 1 January 1900.
+static const int64 kUnixEpochInNtpSeconds = GG_INT64_C(2208988800);
+
+
+CastNtpTickClock::CastNtpTickClock() {
+ SetTickClock(&default_tick_clock_);
+}
+
+CastNtpTickClock::~CastNtpTickClock() {}
+
+void CastNtpTickClock::SetTickClock(base::TickClock* tick_clock) {
+ tick_clock_ = tick_clock;
+}
+
+// Ticks relative to 0h UTC on 1 January 1900.
+base::TimeTicks CastNtpTickClock::NowTicks() {
+ base::TimeDelta ticks_and_time_offset_at_unix_epoch =
+ base::TimeTicks::UnixEpoch() - base::TimeTicks();
+ base::TimeTicks elapsed_since_unix_epoch = tick_clock_->NowTicks() -
+ ticks_and_time_offset_at_unix_epoch;
+
+ return elapsed_since_unix_epoch +
+ base::TimeDelta::FromSeconds(kUnixEpochInNtpSeconds);
+}
+
+} // namespace cast
+} // namespace media
+

Powered by Google App Engine
This is Rietveld 408576698