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

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

Issue 9155003: Fix media timeline so that thumb never exceeds buffered data (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 11 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
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "media/base/buffers.h" 8 #include "media/base/buffers.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 27 matching lines...) Expand all
38 38
39 void Clock::SetPlaybackRate(float playback_rate) { 39 void Clock::SetPlaybackRate(float playback_rate) {
40 if (playing_) { 40 if (playing_) {
41 base::Time time = GetTimeFromProvider(); 41 base::Time time = GetTimeFromProvider();
42 media_time_ = ElapsedViaProvidedTime(time); 42 media_time_ = ElapsedViaProvidedTime(time);
43 reference_ = time; 43 reference_ = time;
44 } 44 }
45 playback_rate_ = playback_rate; 45 playback_rate_ = playback_rate;
46 } 46 }
47 47
48 void Clock::SetTime(const base::TimeDelta& time) { 48 void Clock::SetTime(base::TimeDelta current_time, base::TimeDelta max_time) {
49 if (time == kNoTimestamp) { 49 DCHECK_LE(current_time.ToInternalValue(), max_time.ToInternalValue());
acolwell GONE FROM CHROMIUM 2012/01/13 22:51:21 How about DCHECK(current_time <= max_time)? The To
vrk (LEFT CHROMIUM) 2012/01/21 00:54:14 Done.
50 if (current_time == kNoTimestamp) {
50 NOTREACHED(); 51 NOTREACHED();
51 return; 52 return;
52 } 53 }
53 if (playing_) { 54 if (playing_) {
54 reference_ = GetTimeFromProvider(); 55 reference_ = GetTimeFromProvider();
55 } 56 }
56 media_time_ = time; 57 media_time_ = current_time;
58 max_time_ = max_time;
57 } 59 }
58 60
59 base::TimeDelta Clock::Elapsed() const { 61 base::TimeDelta Clock::Elapsed() const {
60 if (!playing_) { 62 base::TimeDelta elapsed =
61 return media_time_; 63 playing_ ? ElapsedViaProvidedTime(GetTimeFromProvider()) : media_time_;
62 } 64
63 return ElapsedViaProvidedTime(GetTimeFromProvider()); 65 if (max_time_.ToInternalValue() > 0)
acolwell GONE FROM CHROMIUM 2012/01/13 22:51:21 How about using != kNoTimestamp instead of > 0?
vrk (LEFT CHROMIUM) 2012/01/21 00:54:14 Done.
66 elapsed = std::min(elapsed, max_time_);
67
68 if (duration_.ToInternalValue() > 0 && elapsed > duration_)
acolwell GONE FROM CHROMIUM 2012/01/13 22:51:21 How about using != kNoTimestamp instead of > 0?
vrk (LEFT CHROMIUM) 2012/01/21 00:54:14 Actually, I modified logic of this method to retur
69 return duration_;
70
71 return elapsed;
64 } 72 }
65 73
66 base::TimeDelta Clock::ElapsedViaProvidedTime(const base::Time& time) const { 74 base::TimeDelta Clock::ElapsedViaProvidedTime(const base::Time& time) const {
67 // TODO(scherkus): floating point badness scaling time by playback rate. 75 // TODO(scherkus): floating point badness scaling time by playback rate.
68 int64 now_us = (time - reference_).InMicroseconds(); 76 int64 now_us = (time - reference_).InMicroseconds();
69 now_us = static_cast<int64>(now_us * playback_rate_); 77 now_us = static_cast<int64>(now_us * playback_rate_);
70 return media_time_ + base::TimeDelta::FromMicroseconds(now_us); 78 return media_time_ + base::TimeDelta::FromMicroseconds(now_us);
71 } 79 }
72 80
73 base::Time Clock::GetTimeFromProvider() const { 81 base::Time Clock::GetTimeFromProvider() const {
74 if (time_provider_) { 82 if (time_provider_) {
75 return time_provider_(); 83 return time_provider_();
76 } 84 }
77 return base::Time(); 85 return base::Time();
78 } 86 }
79 87
80 } // namespace media 88 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698