OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
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 BufferedDataSourceHostImpl(media::Pipeline pipeline) : pipeline_(pipeline); | |
scherkus (not reviewing)
2014/04/07 22:03:25
we should try to minimize the # of dependencies th
sandersd (OOO until July 31)
2014/04/07 23:46:42
Done.
| |
10 | |
11 void BufferedDataSourceHostImpl::SetTotalBytes(int64 total_bytes) { | |
12 total_bytes_ = total_bytes; | |
13 } | |
14 | |
15 void BufferedDataSourceHostImpl::AddBufferedByteRange(int64 start, int64 end) { | |
16 buffered_byte_ranges_.Add(start, end); | |
17 did_loading_progress_ = true; | |
18 } | |
19 | |
20 static base::TimeDelta TimeForByteOffset( | |
21 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) { | |
22 double position = static_cast<double>(byte_offset) / total_bytes; | |
23 // Snap to the beginning/end where the approximation can look especially bad. | |
24 if (position < 0.01) | |
25 return base::TimeDelta(); | |
26 if (position > 0.99) | |
27 return duration; | |
28 return base::TimeDelta::FromMilliseconds( | |
29 static_cast<int64>(position * duration.InMilliseconds())); | |
30 } | |
31 | |
32 const blink::WebTimeRanges& BufferedDataSourceHostImpl::BufferedTimeRanges() { | |
33 media::Ranges<base::TimeDelta> buffered_time_ranges = | |
34 pipeline_.GetBufferedTimeRanges(); | |
35 if (total_bytes_ && buffered_byte_ranges_.size()) { | |
36 base::TimeDelta duration = pipeline_.GetMediaDuration(); | |
37 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) { | |
38 int64 start = buffered_byte_ranges_.start(i); | |
39 int64 end = buffered_byte_ranges_.end(i); | |
40 buffered_time_ranges.Add(TimeForByteOffset(start, total_bytes_, duration), | |
41 TimeForByteOffset(end, total_bytes_, duration)); | |
42 } | |
43 } | |
44 blink::WebTimeRanges buffered(ConvertToWebTimeRanges(buffered_time_ranges)); | |
45 buffered_.swap(buffered); | |
46 return buffered_; | |
47 } | |
48 | |
49 bool BufferedDataSourceHostImpl::didLoadingProgress() const { | |
50 bool merged = pipeline_.DidLoadingProgress() || did_loading_progress_; | |
51 did_loading_progress_ = false; | |
52 return merged; | |
53 } | |
54 | |
55 } // namespace content | |
OLD | NEW |