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

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

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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 "media/blink/buffered_data_source_host_impl.h" 5 #include "media/blink/buffered_data_source_host_impl.h"
6 6
7 #include "media/base/timestamp_constants.h" 7 #include "media/base/timestamp_constants.h"
8 8
9 namespace media { 9 namespace media {
10 10
11 BufferedDataSourceHostImpl::BufferedDataSourceHostImpl() 11 BufferedDataSourceHostImpl::BufferedDataSourceHostImpl()
12 : total_bytes_(0), 12 : total_bytes_(0),
13 did_loading_progress_(false) { } 13 did_loading_progress_(false) { }
14 14
15 BufferedDataSourceHostImpl::~BufferedDataSourceHostImpl() { } 15 BufferedDataSourceHostImpl::~BufferedDataSourceHostImpl() { }
16 16
17 void BufferedDataSourceHostImpl::SetTotalBytes(int64 total_bytes) { 17 void BufferedDataSourceHostImpl::SetTotalBytes(int64_t total_bytes) {
18 total_bytes_ = total_bytes; 18 total_bytes_ = total_bytes;
19 } 19 }
20 20
21 void BufferedDataSourceHostImpl::AddBufferedByteRange(int64 start, int64 end) { 21 void BufferedDataSourceHostImpl::AddBufferedByteRange(int64_t start,
22 int64_t end) {
22 const auto i = buffered_byte_ranges_.find(start); 23 const auto i = buffered_byte_ranges_.find(start);
23 if (i.value() && i.interval_end() >= end) { 24 if (i.value() && i.interval_end() >= end) {
24 // No change 25 // No change
25 return; 26 return;
26 } 27 }
27 buffered_byte_ranges_.SetInterval(start, end, 1); 28 buffered_byte_ranges_.SetInterval(start, end, 1);
28 did_loading_progress_ = true; 29 did_loading_progress_ = true;
29 } 30 }
30 31
31 static base::TimeDelta TimeForByteOffset( 32 static base::TimeDelta TimeForByteOffset(int64_t byte_offset,
32 int64 byte_offset, int64 total_bytes, base::TimeDelta duration) { 33 int64_t total_bytes,
34 base::TimeDelta duration) {
33 double position = static_cast<double>(byte_offset) / total_bytes; 35 double position = static_cast<double>(byte_offset) / total_bytes;
34 // Snap to the beginning/end where the approximation can look especially bad. 36 // Snap to the beginning/end where the approximation can look especially bad.
35 if (position < 0.01) 37 if (position < 0.01)
36 return base::TimeDelta(); 38 return base::TimeDelta();
37 if (position > 0.99) 39 if (position > 0.99)
38 return duration; 40 return duration;
39 return base::TimeDelta::FromMilliseconds( 41 return base::TimeDelta::FromMilliseconds(
40 static_cast<int64>(position * duration.InMilliseconds())); 42 static_cast<int64_t>(position * duration.InMilliseconds()));
41 } 43 }
42 44
43 void BufferedDataSourceHostImpl::AddBufferedTimeRanges( 45 void BufferedDataSourceHostImpl::AddBufferedTimeRanges(
44 Ranges<base::TimeDelta>* buffered_time_ranges, 46 Ranges<base::TimeDelta>* buffered_time_ranges,
45 base::TimeDelta media_duration) const { 47 base::TimeDelta media_duration) const {
46 DCHECK(media_duration != kNoTimestamp()); 48 DCHECK(media_duration != kNoTimestamp());
47 DCHECK(media_duration != kInfiniteDuration()); 49 DCHECK(media_duration != kInfiniteDuration());
48 if (total_bytes_ && !buffered_byte_ranges_.empty()) { 50 if (total_bytes_ && !buffered_byte_ranges_.empty()) {
49 for (const auto i : buffered_byte_ranges_) { 51 for (const auto i : buffered_byte_ranges_) {
50 if (i.second) { 52 if (i.second) {
51 int64 start = i.first.begin; 53 int64_t start = i.first.begin;
52 int64 end = i.first.end; 54 int64_t end = i.first.end;
53 buffered_time_ranges->Add( 55 buffered_time_ranges->Add(
54 TimeForByteOffset(start, total_bytes_, media_duration), 56 TimeForByteOffset(start, total_bytes_, media_duration),
55 TimeForByteOffset(end, total_bytes_, media_duration)); 57 TimeForByteOffset(end, total_bytes_, media_duration));
56 } 58 }
57 } 59 }
58 } 60 }
59 } 61 }
60 62
61 bool BufferedDataSourceHostImpl::DidLoadingProgress() { 63 bool BufferedDataSourceHostImpl::DidLoadingProgress() {
62 bool ret = did_loading_progress_; 64 bool ret = did_loading_progress_;
63 did_loading_progress_ = false; 65 did_loading_progress_ = false;
64 return ret; 66 return ret;
65 } 67 }
66 68
67 } // namespace media 69 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698