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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/base/wall_clock_time_source.h"
6
7 #include "base/logging.h"
8 #include "base/time/default_tick_clock.h"
9
10 namespace media {
11
12 WallClockTimeSource::WallClockTimeSource()
13 : tick_clock_(new base::DefaultTickClock()),
14 ticking_(false),
15 playback_rate_(1.0f) {
16 }
17
18 WallClockTimeSource::~WallClockTimeSource() {
19 }
20
21 void WallClockTimeSource::StartTicking() {
22 DCHECK(!ticking_);
23 ticking_ = true;
24 reference_wall_ticks_ = tick_clock_->NowTicks();
25 }
26
27 void WallClockTimeSource::StopTicking() {
28 DCHECK(ticking_);
29 base_time_ = CurrentMediaTime();
30 ticking_ = false;
31 reference_wall_ticks_ = tick_clock_->NowTicks();
32 }
33
34 void WallClockTimeSource::SetPlaybackRate(float playback_rate) {
35 // Estimate current media time using old rate to use as a new base time for
36 // the new rate.
37 if (ticking_) {
38 base_time_ = CurrentMediaTime();
39 reference_wall_ticks_ = tick_clock_->NowTicks();
40 }
41
42 playback_rate_ = playback_rate;
43 }
44
45 void WallClockTimeSource::SetMediaTime(base::TimeDelta time) {
46 CHECK(!ticking_);
47 base_time_ = time;
48 }
49
50 base::TimeDelta WallClockTimeSource::CurrentMediaTime() {
51 if (!ticking_)
52 return base_time_;
53
54 base::TimeTicks now = tick_clock_->NowTicks();
55 return base_time_ +
56 base::TimeDelta::FromMicroseconds(
57 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_);
58 }
59
60 void WallClockTimeSource::SetTickClockForTesting(
61 scoped_ptr<base::TickClock> tick_clock) {
62 tick_clock_.swap(tick_clock);
63 }
64
65 } // namespace media
OLDNEW
« 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