OLD | NEW |
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 "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 UpdateReferencePoints(); | 74 UpdateReferencePoints(); |
75 max_time_ = ClampToValidTimeRange(max_time); | 75 max_time_ = ClampToValidTimeRange(max_time); |
76 | 76 |
77 underflow_ = media_time_ > max_time_; | 77 underflow_ = media_time_ > max_time_; |
78 if (underflow_) | 78 if (underflow_) |
79 media_time_ = max_time_; | 79 media_time_ = max_time_; |
80 } | 80 } |
81 | 81 |
82 void Clock::SetDuration(base::TimeDelta duration) { | 82 void Clock::SetDuration(base::TimeDelta duration) { |
83 DCHECK(duration_ == kNoTimestamp() || duration_ == kInfiniteDuration()); | |
84 DCHECK(duration > base::TimeDelta()); | 83 DCHECK(duration > base::TimeDelta()); |
85 duration_ = duration; | 84 duration_ = duration; |
| 85 |
| 86 media_time_ = ClampToValidTimeRange(media_time_); |
| 87 if (max_time_ != kNoTimestamp()) |
| 88 max_time_ = ClampToValidTimeRange(max_time_); |
86 } | 89 } |
87 | 90 |
88 base::TimeDelta Clock::ElapsedViaProvidedTime(const base::Time& time) const { | 91 base::TimeDelta Clock::ElapsedViaProvidedTime(const base::Time& time) const { |
89 // TODO(scherkus): floating point badness scaling time by playback rate. | 92 // TODO(scherkus): floating point badness scaling time by playback rate. |
90 int64 now_us = (time - reference_).InMicroseconds(); | 93 int64 now_us = (time - reference_).InMicroseconds(); |
91 now_us = static_cast<int64>(now_us * playback_rate_); | 94 now_us = static_cast<int64>(now_us * playback_rate_); |
92 return media_time_ + base::TimeDelta::FromMicroseconds(now_us); | 95 return media_time_ + base::TimeDelta::FromMicroseconds(now_us); |
93 } | 96 } |
94 | 97 |
95 base::Time Clock::GetTimeFromProvider() const { | 98 base::Time Clock::GetTimeFromProvider() const { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 playing_ = false; | 136 playing_ = false; |
134 playback_rate_ = 1.0f; | 137 playback_rate_ = 1.0f; |
135 max_time_ = kNoTimestamp(); | 138 max_time_ = kNoTimestamp(); |
136 duration_ = kNoTimestamp(); | 139 duration_ = kNoTimestamp(); |
137 media_time_ = base::TimeDelta(); | 140 media_time_ = base::TimeDelta(); |
138 reference_ = base::Time(); | 141 reference_ = base::Time(); |
139 underflow_ = false; | 142 underflow_ = false; |
140 } | 143 } |
141 | 144 |
142 } // namespace media | 145 } // namespace media |
OLD | NEW |