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/pipeline.h" | 5 #include "media/base/pipeline.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 TimeDelta Pipeline::GetCurrentTime_Locked() const { | 197 TimeDelta Pipeline::GetCurrentTime_Locked() const { |
198 lock_.AssertAcquired(); | 198 lock_.AssertAcquired(); |
199 return clock_->Elapsed(); | 199 return clock_->Elapsed(); |
200 } | 200 } |
201 | 201 |
202 Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() { | 202 Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() { |
203 base::AutoLock auto_lock(lock_); | 203 base::AutoLock auto_lock(lock_); |
204 Ranges<TimeDelta> time_ranges; | 204 Ranges<TimeDelta> time_ranges; |
205 if (clock_->Duration() == TimeDelta() || total_bytes_ == 0) | 205 if (clock_->Duration() == TimeDelta() || total_bytes_ == 0) |
206 return time_ranges; | 206 return time_ranges; |
207 TimeDelta current_time = GetCurrentTime_Locked(); | |
207 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) { | 208 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) { |
208 TimeDelta start = TimeForByteOffset_Locked(buffered_byte_ranges_.start(i)); | 209 TimeDelta start = TimeForByteOffset_Locked(buffered_byte_ranges_.start(i)); |
209 TimeDelta end = TimeForByteOffset_Locked(buffered_byte_ranges_.end(i)); | 210 TimeDelta end = TimeForByteOffset_Locked(buffered_byte_ranges_.end(i)); |
210 // Cap approximated buffered time at the length of the video. | 211 // Cap approximated buffered time at the length of the video. |
211 end = std::min(end, clock_->Duration()); | 212 end = std::min(end, clock_->Duration()); |
213 // HACK: Extend the last range preceding the current time to include the | |
214 // current time, to avoid disappearing/reappearing buffered bar. | |
215 // TODO(fischman): remove this HACK when we have time-based buffered-range | |
216 // tracking (http://crbug.com/133588). | |
217 if ((i + 1 == buffered_byte_ranges_.size()) || | |
scherkus (not reviewing)
2012/06/21 01:10:38
brackets around (i + 1) for warm fuzzy feeling ple
| |
218 (current_time > start && current_time < | |
219 TimeForByteOffset_Locked((buffered_byte_ranges_.start(i + 1))))) { | |
220 end = std::max(end, current_time + TimeDelta::FromSeconds(1)); | |
221 } | |
212 time_ranges.Add(start, end); | 222 time_ranges.Add(start, end); |
213 } | 223 } |
214 | 224 |
215 return time_ranges; | 225 return time_ranges; |
216 } | 226 } |
217 | 227 |
218 TimeDelta Pipeline::GetMediaDuration() const { | 228 TimeDelta Pipeline::GetMediaDuration() const { |
219 base::AutoLock auto_lock(lock_); | 229 base::AutoLock auto_lock(lock_); |
220 return clock_->Duration(); | 230 return clock_->Duration(); |
221 } | 231 } |
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1276 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { | 1286 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { |
1277 lock_.AssertAcquired(); | 1287 lock_.AssertAcquired(); |
1278 if (!waiting_for_clock_update_) | 1288 if (!waiting_for_clock_update_) |
1279 return; | 1289 return; |
1280 | 1290 |
1281 waiting_for_clock_update_ = false; | 1291 waiting_for_clock_update_ = false; |
1282 clock_->Play(); | 1292 clock_->Play(); |
1283 } | 1293 } |
1284 | 1294 |
1285 } // namespace media | 1295 } // namespace media |
OLD | NEW |