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

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

Issue 16823003: Replace erroneous use of base::Time with base::TimeTicks throughout media code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/PresubmitPromptWarning/PresubmitPromptOrNotify/ Created 7 years, 6 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/clock.h ('k') | media/base/clock_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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/clock.h" 5 #include "media/base/clock.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/time/clock.h" 10 #include "base/time/tick_clock.h"
11 #include "media/base/buffers.h" 11 #include "media/base/buffers.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 Clock::Clock(base::Clock* clock) : clock_(clock) { 15 Clock::Clock(base::TickClock* clock) : clock_(clock) {
16 DCHECK(clock_); 16 DCHECK(clock_);
17 Reset(); 17 Reset();
18 } 18 }
19 19
20 Clock::~Clock() {} 20 Clock::~Clock() {}
21 21
22 bool Clock::IsPlaying() const { 22 bool Clock::IsPlaying() const {
23 return playing_; 23 return playing_;
24 } 24 }
25 25
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 void Clock::SetDuration(base::TimeDelta duration) { 83 void Clock::SetDuration(base::TimeDelta duration) {
84 DCHECK(duration > base::TimeDelta()); 84 DCHECK(duration > base::TimeDelta());
85 duration_ = duration; 85 duration_ = duration;
86 86
87 media_time_ = ClampToValidTimeRange(media_time_); 87 media_time_ = ClampToValidTimeRange(media_time_);
88 if (max_time_ != kNoTimestamp()) 88 if (max_time_ != kNoTimestamp())
89 max_time_ = ClampToValidTimeRange(max_time_); 89 max_time_ = ClampToValidTimeRange(max_time_);
90 } 90 }
91 91
92 base::TimeDelta Clock::ElapsedViaProvidedTime(const base::Time& time) const { 92 base::TimeDelta Clock::ElapsedViaProvidedTime(
93 const base::TimeTicks& time) const {
93 // TODO(scherkus): floating point badness scaling time by playback rate. 94 // TODO(scherkus): floating point badness scaling time by playback rate.
94 int64 now_us = (time - reference_).InMicroseconds(); 95 int64 now_us = (time - reference_).InMicroseconds();
95 now_us = static_cast<int64>(now_us * playback_rate_); 96 now_us = static_cast<int64>(now_us * playback_rate_);
96 return media_time_ + base::TimeDelta::FromMicroseconds(now_us); 97 return media_time_ + base::TimeDelta::FromMicroseconds(now_us);
97 } 98 }
98 99
99 base::TimeDelta Clock::ClampToValidTimeRange(base::TimeDelta time) const { 100 base::TimeDelta Clock::ClampToValidTimeRange(base::TimeDelta time) const {
100 if (duration_ == kNoTimestamp()) 101 if (duration_ == kNoTimestamp())
101 return base::TimeDelta(); 102 return base::TimeDelta();
102 return std::max(std::min(time, duration_), base::TimeDelta()); 103 return std::max(std::min(time, duration_), base::TimeDelta());
103 } 104 }
104 105
105 void Clock::EndOfStream() { 106 void Clock::EndOfStream() {
106 Pause(); 107 Pause();
107 SetTime(Duration(), Duration()); 108 SetTime(Duration(), Duration());
108 } 109 }
109 110
110 base::TimeDelta Clock::Duration() const { 111 base::TimeDelta Clock::Duration() const {
111 if (duration_ == kNoTimestamp()) 112 if (duration_ == kNoTimestamp())
112 return base::TimeDelta(); 113 return base::TimeDelta();
113 return duration_; 114 return duration_;
114 } 115 }
115 116
116 void Clock::UpdateReferencePoints() { 117 void Clock::UpdateReferencePoints() {
117 UpdateReferencePoints(Elapsed()); 118 UpdateReferencePoints(Elapsed());
118 } 119 }
119 120
120 void Clock::UpdateReferencePoints(base::TimeDelta current_time) { 121 void Clock::UpdateReferencePoints(base::TimeDelta current_time) {
121 media_time_ = ClampToValidTimeRange(current_time); 122 media_time_ = ClampToValidTimeRange(current_time);
122 reference_ = clock_->Now(); 123 reference_ = clock_->NowTicks();
123 } 124 }
124 125
125 base::TimeDelta Clock::EstimatedElapsedTime() { 126 base::TimeDelta Clock::EstimatedElapsedTime() {
126 return ClampToValidTimeRange(ElapsedViaProvidedTime(clock_->Now())); 127 return ClampToValidTimeRange(ElapsedViaProvidedTime(clock_->NowTicks()));
127 } 128 }
128 129
129 void Clock::Reset() { 130 void Clock::Reset() {
130 playing_ = false; 131 playing_ = false;
131 playback_rate_ = 1.0f; 132 playback_rate_ = 1.0f;
132 max_time_ = kNoTimestamp(); 133 max_time_ = kNoTimestamp();
133 duration_ = kNoTimestamp(); 134 duration_ = kNoTimestamp();
134 media_time_ = base::TimeDelta(); 135 media_time_ = base::TimeDelta();
135 reference_ = base::Time(); 136 reference_ = base::TimeTicks();
136 underflow_ = false; 137 underflow_ = false;
137 } 138 }
138 139
139 } // namespace media 140 } // namespace media
OLDNEW
« no previous file with comments | « media/base/clock.h ('k') | media/base/clock_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698