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

Unified Diff: media/base/wall_clock_time_source.cc

Issue 379343005: Introduce media::TimeSource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Timesource Created 6 years, 5 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
« no previous file with comments | « media/base/wall_clock_time_source.h ('k') | media/base/wall_clock_time_source_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/wall_clock_time_source.cc
diff --git a/media/base/wall_clock_time_source.cc b/media/base/wall_clock_time_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..67b16f717952c29dc1d8e7fe5abb174a0ec60bef
--- /dev/null
+++ b/media/base/wall_clock_time_source.cc
@@ -0,0 +1,65 @@
+// Copyright 2014 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/base/wall_clock_time_source.h"
+
+#include "base/logging.h"
+#include "base/time/default_tick_clock.h"
+
+namespace media {
+
+WallClockTimeSource::WallClockTimeSource()
+ : tick_clock_(new base::DefaultTickClock()),
+ ticking_(false),
+ playback_rate_(1.0f) {
+}
+
+WallClockTimeSource::~WallClockTimeSource() {
+}
+
+void WallClockTimeSource::StartTicking() {
+ DCHECK(!ticking_);
+ ticking_ = true;
+ reference_wall_ticks_ = tick_clock_->NowTicks();
+}
+
+void WallClockTimeSource::StopTicking() {
+ DCHECK(ticking_);
+ base_time_ = CurrentMediaTime();
+ ticking_ = false;
+ reference_wall_ticks_ = tick_clock_->NowTicks();
+}
+
+void WallClockTimeSource::SetPlaybackRate(float playback_rate) {
+ // Estimate current media time using old rate to use as a new base time for
+ // the new rate.
+ if (ticking_) {
+ base_time_ = CurrentMediaTime();
+ reference_wall_ticks_ = tick_clock_->NowTicks();
+ }
+
+ playback_rate_ = playback_rate;
+}
+
+void WallClockTimeSource::SetMediaTime(base::TimeDelta time) {
+ CHECK(!ticking_);
+ base_time_ = time;
+}
+
+base::TimeDelta WallClockTimeSource::CurrentMediaTime() {
+ if (!ticking_)
+ return base_time_;
+
+ base::TimeTicks now = tick_clock_->NowTicks();
+ return base_time_ +
+ base::TimeDelta::FromMicroseconds(
+ (now - reference_wall_ticks_).InMicroseconds() * playback_rate_);
+}
+
+void WallClockTimeSource::SetTickClockForTesting(
+ scoped_ptr<base::TickClock> tick_clock) {
+ tick_clock_.swap(tick_clock);
+}
+
+} // namespace media
« no previous file with comments | « media/base/wall_clock_time_source.h ('k') | media/base/wall_clock_time_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698