Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "content/renderer/media/buffered_data_source_host_impl.h" | |
| 6 | |
| 7 namespace content { | |
| 8 | |
| 9 BufferedDataSourceHostImpl::BufferedDataSourceHostImpl() | |
| 10 : total_bytes_(0), | |
| 11 did_loading_progress_(0) { | |
|
scherkus (not reviewing)
2014/04/08 22:45:21
s/0/false/ seeing as it's a bool
| |
| 12 } | |
| 13 | |
| 14 void BufferedDataSourceHostImpl::SetTotalBytes(int64 total_bytes) { | |
| 15 total_bytes_ = total_bytes; | |
| 16 } | |
| 17 | |
| 18 void BufferedDataSourceHostImpl::AddBufferedByteRange(int64 start, int64 end) { | |
| 19 buffered_byte_ranges_.Add(start, end); | |
| 20 did_loading_progress_ = true; | |
| 21 } | |
| 22 | |
| 23 static base::TimeDelta TimeForByteOffset( | |
| 24 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) { | |
| 25 double position = static_cast<double>(byte_offset) / total_bytes; | |
| 26 // Snap to the beginning/end where the approximation can look especially bad. | |
| 27 if (position < 0.01) | |
| 28 return base::TimeDelta(); | |
| 29 if (position > 0.99) | |
| 30 return duration; | |
| 31 return base::TimeDelta::FromMilliseconds( | |
| 32 static_cast<int64>(position * duration.InMilliseconds())); | |
| 33 } | |
| 34 | |
| 35 void BufferedDataSourceHostImpl::AddBufferedTimeRanges( | |
| 36 media::Ranges<base::TimeDelta>* buffered_time_ranges, | |
| 37 base::TimeDelta media_duration) { | |
| 38 if (total_bytes_ && buffered_byte_ranges_.size()) { | |
| 39 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) { | |
| 40 int64 start = buffered_byte_ranges_.start(i); | |
| 41 int64 end = buffered_byte_ranges_.end(i); | |
| 42 buffered_time_ranges->Add( | |
| 43 TimeForByteOffset(start, total_bytes_, media_duration), | |
| 44 TimeForByteOffset(end, total_bytes_, media_duration)); | |
| 45 } | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 bool BufferedDataSourceHostImpl::DidLoadingProgress() const { | |
| 50 bool ret = did_loading_progress_; | |
| 51 did_loading_progress_ = false; | |
| 52 return ret; | |
| 53 } | |
| 54 | |
| 55 } // namespace content | |
| OLD | NEW |