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

Side by Side Diff: media/base/wall_clock_time_source.cc

Issue 1094783002: Switch to double for time calculations using playback rate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Making changes at chromecast side to fix trybots Created 5 years, 8 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
« no previous file with comments | « media/base/wall_clock_time_source.h ('k') | media/blink/buffered_data_source.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/wall_clock_time_source.h" 5 #include "media/base/wall_clock_time_source.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/time/default_tick_clock.h" 8 #include "base/time/default_tick_clock.h"
9 9
10 namespace media { 10 namespace media {
11 11
12 WallClockTimeSource::WallClockTimeSource() 12 WallClockTimeSource::WallClockTimeSource()
13 : tick_clock_(new base::DefaultTickClock()), 13 : tick_clock_(new base::DefaultTickClock()),
14 ticking_(false), 14 ticking_(false),
15 playback_rate_(1.0f) { 15 playback_rate_(1.0) {
16 } 16 }
17 17
18 WallClockTimeSource::~WallClockTimeSource() { 18 WallClockTimeSource::~WallClockTimeSource() {
19 } 19 }
20 20
21 void WallClockTimeSource::StartTicking() { 21 void WallClockTimeSource::StartTicking() {
22 DVLOG(1) << __FUNCTION__; 22 DVLOG(1) << __FUNCTION__;
23 base::AutoLock auto_lock(lock_); 23 base::AutoLock auto_lock(lock_);
24 DCHECK(!ticking_); 24 DCHECK(!ticking_);
25 ticking_ = true; 25 ticking_ = true;
26 reference_wall_ticks_ = tick_clock_->NowTicks(); 26 reference_wall_ticks_ = tick_clock_->NowTicks();
27 } 27 }
28 28
29 void WallClockTimeSource::StopTicking() { 29 void WallClockTimeSource::StopTicking() {
30 DVLOG(1) << __FUNCTION__; 30 DVLOG(1) << __FUNCTION__;
31 base::AutoLock auto_lock(lock_); 31 base::AutoLock auto_lock(lock_);
32 DCHECK(ticking_); 32 DCHECK(ticking_);
33 base_time_ = CurrentMediaTime_Locked(); 33 base_time_ = CurrentMediaTime_Locked();
34 ticking_ = false; 34 ticking_ = false;
35 reference_wall_ticks_ = tick_clock_->NowTicks(); 35 reference_wall_ticks_ = tick_clock_->NowTicks();
36 } 36 }
37 37
38 void WallClockTimeSource::SetPlaybackRate(float playback_rate) { 38 void WallClockTimeSource::SetPlaybackRate(double playback_rate) {
39 DVLOG(1) << __FUNCTION__ << "(" << playback_rate << ")"; 39 DVLOG(1) << __FUNCTION__ << "(" << playback_rate << ")";
40 base::AutoLock auto_lock(lock_); 40 base::AutoLock auto_lock(lock_);
41 // Estimate current media time using old rate to use as a new base time for 41 // Estimate current media time using old rate to use as a new base time for
42 // the new rate. 42 // the new rate.
43 if (ticking_) { 43 if (ticking_) {
44 base_time_ = CurrentMediaTime_Locked(); 44 base_time_ = CurrentMediaTime_Locked();
45 reference_wall_ticks_ = tick_clock_->NowTicks(); 45 reference_wall_ticks_ = tick_clock_->NowTicks();
46 } 46 }
47 47
48 playback_rate_ = playback_rate; 48 playback_rate_ = playback_rate;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 if (!ticking_ || playback_rate_ == 0.0) 81 if (!ticking_ || playback_rate_ == 0.0)
82 return base_time_; 82 return base_time_;
83 83
84 base::TimeTicks now = tick_clock_->NowTicks(); 84 base::TimeTicks now = tick_clock_->NowTicks();
85 return base_time_ + 85 return base_time_ +
86 base::TimeDelta::FromMicroseconds( 86 base::TimeDelta::FromMicroseconds(
87 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_); 87 (now - reference_wall_ticks_).InMicroseconds() * playback_rate_);
88 } 88 }
89 89
90 } // namespace media 90 } // namespace media
OLDNEW
« no previous file with comments | « media/base/wall_clock_time_source.h ('k') | media/blink/buffered_data_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698