1 // Copyright 2014 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.
5 #include "content/renderer/media/buffered_data_source_host_impl.h"
9 BufferedDataSourceHostImpl::BufferedDataSourceHostImpl()
11 did_loading_progress_(false) { }
13 BufferedDataSourceHostImpl::~BufferedDataSourceHostImpl() { }
15 void BufferedDataSourceHostImpl::SetTotalBytes(int64 total_bytes) {
16 total_bytes_ = total_bytes;
19 void BufferedDataSourceHostImpl::AddBufferedByteRange(int64 start, int64 end) {
20 buffered_byte_ranges_.Add(start, end);
21 did_loading_progress_ = true;
24 static base::TimeDelta TimeForByteOffset(
25 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) {
26 double position = static_cast<double>(byte_offset) / total_bytes;
27 // Snap to the beginning/end where the approximation can look especially bad.
29 return base::TimeDelta();
32 return base::TimeDelta::FromMilliseconds(
33 static_cast<int64>(position * duration.InMilliseconds()));
36 void BufferedDataSourceHostImpl::AddBufferedTimeRanges(
37 media::Ranges<base::TimeDelta>* buffered_time_ranges,
38 base::TimeDelta media_duration) {
39 if (total_bytes_ && buffered_byte_ranges_.size()) {
40 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) {
41 int64 start = buffered_byte_ranges_.start(i);
42 int64 end = buffered_byte_ranges_.end(i);
43 buffered_time_ranges->Add(
44 TimeForByteOffset(start, total_bytes_, media_duration),
45 TimeForByteOffset(end, total_bytes_, media_duration));
50 bool BufferedDataSourceHostImpl::DidLoadingProgress() const {
51 bool ret = did_loading_progress_;
52 did_loading_progress_ = false;
56 } // namespace content