OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
scherkus (not reviewing)
2014/04/08 04:36:18
ditto
sandersd (OOO until July 31)
2014/04/08 22:42:14
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/media/buffered_data_source_host_impl.h" | |
6 | |
7 namespace content { | |
8 | |
9 void BufferedDataSourceHostImpl::SetTotalBytes(int64 total_bytes) { | |
10 total_bytes_ = total_bytes; | |
11 } | |
12 | |
13 void BufferedDataSourceHostImpl::AddBufferedByteRange(int64 start, int64 end) { | |
14 buffered_byte_ranges_.Add(start, end); | |
15 did_loading_progress_ = true; | |
16 } | |
17 | |
18 static base::TimeDelta TimeForByteOffset( | |
19 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) { | |
20 double position = static_cast<double>(byte_offset) / total_bytes; | |
21 // Snap to the beginning/end where the approximation can look especially bad. | |
22 if (position < 0.01) | |
23 return base::TimeDelta(); | |
24 if (position > 0.99) | |
25 return duration; | |
26 return base::TimeDelta::FromMilliseconds( | |
27 static_cast<int64>(position * duration.InMilliseconds())); | |
28 } | |
29 | |
30 void BufferedDataSourceHostImpl::AddBufferedTimeRanges( | |
31 media::Ranges<base::TimeDelta>* buffered_time_ranges, | |
32 base::TimeDelta media_duration) { | |
33 if (total_bytes_ && buffered_byte_ranges_.size()) { | |
34 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) { | |
35 int64 start = buffered_byte_ranges_.start(i); | |
36 int64 end = buffered_byte_ranges_.end(i); | |
37 buffered_time_ranges->Add( | |
38 TimeForByteOffset(start, total_bytes_, media_duration), | |
39 TimeForByteOffset(end, total_bytes_, media_duration)); | |
40 } | |
41 } | |
42 } | |
43 | |
44 bool BufferedDataSourceHostImpl::DidLoadingProgress() const { | |
45 bool ret = did_loading_progress_; | |
46 did_loading_progress_ = false; | |
47 return ret; | |
48 } | |
49 | |
50 } // namespace content | |
OLD | NEW |