Chromium Code Reviews| Index: content/renderer/media/buffered_data_source_host_impl.cc |
| diff --git a/content/renderer/media/buffered_data_source_host_impl.cc b/content/renderer/media/buffered_data_source_host_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..160befe8fa69b943586717dcbf816bb49547c76d |
| --- /dev/null |
| +++ b/content/renderer/media/buffered_data_source_host_impl.cc |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/media/buffered_data_source_host_impl.h" |
| + |
| +namespace content { |
| + |
| +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.
|
| + |
| +void BufferedDataSourceHostImpl::SetTotalBytes(int64 total_bytes) { |
| + total_bytes_ = total_bytes; |
| +} |
| + |
| +void BufferedDataSourceHostImpl::AddBufferedByteRange(int64 start, int64 end) { |
| + buffered_byte_ranges_.Add(start, end); |
| + did_loading_progress_ = true; |
| +} |
| + |
| +static base::TimeDelta TimeForByteOffset( |
| + int64 byte_offset, int64 total_bytes, base::TimeDelta duration) { |
| + double position = static_cast<double>(byte_offset) / total_bytes; |
| + // Snap to the beginning/end where the approximation can look especially bad. |
| + if (position < 0.01) |
| + return base::TimeDelta(); |
| + if (position > 0.99) |
| + return duration; |
| + return base::TimeDelta::FromMilliseconds( |
| + static_cast<int64>(position * duration.InMilliseconds())); |
| +} |
| + |
| +const blink::WebTimeRanges& BufferedDataSourceHostImpl::BufferedTimeRanges() { |
| + media::Ranges<base::TimeDelta> buffered_time_ranges = |
| + pipeline_.GetBufferedTimeRanges(); |
| + if (total_bytes_ && buffered_byte_ranges_.size()) { |
| + base::TimeDelta duration = pipeline_.GetMediaDuration(); |
| + for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) { |
| + int64 start = buffered_byte_ranges_.start(i); |
| + int64 end = buffered_byte_ranges_.end(i); |
| + buffered_time_ranges.Add(TimeForByteOffset(start, total_bytes_, duration), |
| + TimeForByteOffset(end, total_bytes_, duration)); |
| + } |
| + } |
| + blink::WebTimeRanges buffered(ConvertToWebTimeRanges(buffered_time_ranges)); |
| + buffered_.swap(buffered); |
| + return buffered_; |
| +} |
| + |
| +bool BufferedDataSourceHostImpl::didLoadingProgress() const { |
| + bool merged = pipeline_.DidLoadingProgress() || did_loading_progress_; |
| + did_loading_progress_ = false; |
| + return merged; |
| +} |
| + |
| +} // namespace content |