Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: media/blink/buffered_data_source_host_impl.cc

Issue 495353003: Move WebMediaPlayerImpl and its dependencies to media/blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/buffered_data_source_host_impl.h" 5 #include "media/blink/buffered_data_source_host_impl.h"
6 6
7 namespace content { 7 namespace media {
8 8
9 BufferedDataSourceHostImpl::BufferedDataSourceHostImpl() 9 BufferedDataSourceHostImpl::BufferedDataSourceHostImpl()
10 : total_bytes_(0), 10 : total_bytes_(0),
11 did_loading_progress_(false) { } 11 did_loading_progress_(false) { }
12 12
13 BufferedDataSourceHostImpl::~BufferedDataSourceHostImpl() { } 13 BufferedDataSourceHostImpl::~BufferedDataSourceHostImpl() { }
14 14
15 void BufferedDataSourceHostImpl::SetTotalBytes(int64 total_bytes) { 15 void BufferedDataSourceHostImpl::SetTotalBytes(int64 total_bytes) {
16 total_bytes_ = total_bytes; 16 total_bytes_ = total_bytes;
17 } 17 }
18 18
19 void BufferedDataSourceHostImpl::AddBufferedByteRange(int64 start, int64 end) { 19 void BufferedDataSourceHostImpl::AddBufferedByteRange(int64 start, int64 end) {
20 buffered_byte_ranges_.Add(start, end); 20 buffered_byte_ranges_.Add(start, end);
21 did_loading_progress_ = true; 21 did_loading_progress_ = true;
22 } 22 }
23 23
24 static base::TimeDelta TimeForByteOffset( 24 static base::TimeDelta TimeForByteOffset(
25 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) { 25 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) {
26 double position = static_cast<double>(byte_offset) / total_bytes; 26 double position = static_cast<double>(byte_offset) / total_bytes;
27 // Snap to the beginning/end where the approximation can look especially bad. 27 // Snap to the beginning/end where the approximation can look especially bad.
28 if (position < 0.01) 28 if (position < 0.01)
29 return base::TimeDelta(); 29 return base::TimeDelta();
30 if (position > 0.99) 30 if (position > 0.99)
31 return duration; 31 return duration;
32 return base::TimeDelta::FromMilliseconds( 32 return base::TimeDelta::FromMilliseconds(
33 static_cast<int64>(position * duration.InMilliseconds())); 33 static_cast<int64>(position * duration.InMilliseconds()));
34 } 34 }
35 35
36 void BufferedDataSourceHostImpl::AddBufferedTimeRanges( 36 void BufferedDataSourceHostImpl::AddBufferedTimeRanges(
37 media::Ranges<base::TimeDelta>* buffered_time_ranges, 37 Ranges<base::TimeDelta>* buffered_time_ranges,
38 base::TimeDelta media_duration) const { 38 base::TimeDelta media_duration) const {
39 DCHECK(media_duration != media::kNoTimestamp()); 39 DCHECK(media_duration != kNoTimestamp());
40 DCHECK(media_duration != media::kInfiniteDuration()); 40 DCHECK(media_duration != kInfiniteDuration());
41 if (total_bytes_ && buffered_byte_ranges_.size()) { 41 if (total_bytes_ && buffered_byte_ranges_.size()) {
42 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) { 42 for (size_t i = 0; i < buffered_byte_ranges_.size(); ++i) {
43 int64 start = buffered_byte_ranges_.start(i); 43 int64 start = buffered_byte_ranges_.start(i);
44 int64 end = buffered_byte_ranges_.end(i); 44 int64 end = buffered_byte_ranges_.end(i);
45 buffered_time_ranges->Add( 45 buffered_time_ranges->Add(
46 TimeForByteOffset(start, total_bytes_, media_duration), 46 TimeForByteOffset(start, total_bytes_, media_duration),
47 TimeForByteOffset(end, total_bytes_, media_duration)); 47 TimeForByteOffset(end, total_bytes_, media_duration));
48 } 48 }
49 } 49 }
50 } 50 }
51 51
52 bool BufferedDataSourceHostImpl::DidLoadingProgress() { 52 bool BufferedDataSourceHostImpl::DidLoadingProgress() {
53 bool ret = did_loading_progress_; 53 bool ret = did_loading_progress_;
54 did_loading_progress_ = false; 54 did_loading_progress_ = false;
55 return ret; 55 return ret;
56 } 56 }
57 57
58 } // namespace content 58 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/buffered_data_source_host_impl.h ('k') | media/blink/buffered_data_source_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698