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

Side by Side Diff: media/blink/buffered_data_source.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.h" 5 #include "media/blink/buffered_data_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 15 matching lines...) Expand all
26 26
27 // The number of milliseconds to wait before retrying a failed load. 27 // The number of milliseconds to wait before retrying a failed load.
28 const int kLoaderFailedRetryDelayMs = 250; 28 const int kLoaderFailedRetryDelayMs = 250;
29 29
30 } // namespace 30 } // namespace
31 31
32 namespace media { 32 namespace media {
33 33
34 class BufferedDataSource::ReadOperation { 34 class BufferedDataSource::ReadOperation {
35 public: 35 public:
36 ReadOperation(int64 position, int size, uint8* data, 36 ReadOperation(int64_t position,
37 int size,
38 uint8_t* data,
37 const DataSource::ReadCB& callback); 39 const DataSource::ReadCB& callback);
38 ~ReadOperation(); 40 ~ReadOperation();
39 41
40 // Runs |callback_| with the given |result|, deleting the operation 42 // Runs |callback_| with the given |result|, deleting the operation
41 // afterwards. 43 // afterwards.
42 static void Run(scoped_ptr<ReadOperation> read_op, int result); 44 static void Run(scoped_ptr<ReadOperation> read_op, int result);
43 45
44 // State for the number of times this read operation has been retried. 46 // State for the number of times this read operation has been retried.
45 int retries() { return retries_; } 47 int retries() { return retries_; }
46 void IncrementRetries() { ++retries_; } 48 void IncrementRetries() { ++retries_; }
47 49
48 int64 position() { return position_; } 50 int64_t position() { return position_; }
49 int size() { return size_; } 51 int size() { return size_; }
50 uint8* data() { return data_; } 52 uint8_t* data() { return data_; }
51 53
52 private: 54 private:
53 int retries_; 55 int retries_;
54 56
55 const int64 position_; 57 const int64_t position_;
56 const int size_; 58 const int size_;
57 uint8* data_; 59 uint8_t* data_;
58 DataSource::ReadCB callback_; 60 DataSource::ReadCB callback_;
59 61
60 DISALLOW_IMPLICIT_CONSTRUCTORS(ReadOperation); 62 DISALLOW_IMPLICIT_CONSTRUCTORS(ReadOperation);
61 }; 63 };
62 64
63 BufferedDataSource::ReadOperation::ReadOperation( 65 BufferedDataSource::ReadOperation::ReadOperation(
64 int64 position, int size, uint8* data, 66 int64_t position,
67 int size,
68 uint8_t* data,
65 const DataSource::ReadCB& callback) 69 const DataSource::ReadCB& callback)
66 : retries_(0), 70 : retries_(0),
67 position_(position), 71 position_(position),
68 size_(size), 72 size_(size),
69 data_(data), 73 data_(data),
70 callback_(callback) { 74 callback_(callback) {
71 DCHECK(!callback_.is_null()); 75 DCHECK(!callback_.is_null());
72 } 76 }
73 77
74 BufferedDataSource::ReadOperation::~ReadOperation() { 78 BufferedDataSource::ReadOperation::~ReadOperation() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 125 }
122 126
123 bool BufferedDataSource::assume_fully_buffered() { 127 bool BufferedDataSource::assume_fully_buffered() {
124 return !url_.SchemeIsHTTPOrHTTPS(); 128 return !url_.SchemeIsHTTPOrHTTPS();
125 } 129 }
126 130
127 // A factory method to create BufferedResourceLoader using the read parameters. 131 // A factory method to create BufferedResourceLoader using the read parameters.
128 // This method can be overridden to inject mock BufferedResourceLoader object 132 // This method can be overridden to inject mock BufferedResourceLoader object
129 // for testing purpose. 133 // for testing purpose.
130 BufferedResourceLoader* BufferedDataSource::CreateResourceLoader( 134 BufferedResourceLoader* BufferedDataSource::CreateResourceLoader(
131 int64 first_byte_position, int64 last_byte_position) { 135 int64_t first_byte_position,
136 int64_t last_byte_position) {
132 DCHECK(render_task_runner_->BelongsToCurrentThread()); 137 DCHECK(render_task_runner_->BelongsToCurrentThread());
133 138
134 BufferedResourceLoader::DeferStrategy strategy = preload_ == METADATA ? 139 BufferedResourceLoader::DeferStrategy strategy = preload_ == METADATA ?
135 BufferedResourceLoader::kReadThenDefer : 140 BufferedResourceLoader::kReadThenDefer :
136 BufferedResourceLoader::kCapacityDefer; 141 BufferedResourceLoader::kCapacityDefer;
137 142
138 return new BufferedResourceLoader(url_, 143 return new BufferedResourceLoader(url_,
139 cors_mode_, 144 cors_mode_,
140 first_byte_position, 145 first_byte_position,
141 last_byte_position, 146 last_byte_position,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 DCHECK(render_task_runner_->BelongsToCurrentThread()); 251 DCHECK(render_task_runner_->BelongsToCurrentThread());
247 if (loader_ && preload_ == METADATA && !media_has_played_ && !IsStreaming()) 252 if (loader_ && preload_ == METADATA && !media_has_played_ && !IsStreaming())
248 loader_->CancelUponDeferral(); 253 loader_->CancelUponDeferral();
249 } 254 }
250 255
251 int64_t BufferedDataSource::GetMemoryUsage() const { 256 int64_t BufferedDataSource::GetMemoryUsage() const {
252 DCHECK(render_task_runner_->BelongsToCurrentThread()); 257 DCHECK(render_task_runner_->BelongsToCurrentThread());
253 return loader_ ? loader_->GetMemoryUsage() : 0; 258 return loader_ ? loader_->GetMemoryUsage() : 0;
254 } 259 }
255 260
256 void BufferedDataSource::Read( 261 void BufferedDataSource::Read(int64_t position,
257 int64 position, int size, uint8* data, 262 int size,
258 const DataSource::ReadCB& read_cb) { 263 uint8_t* data,
264 const DataSource::ReadCB& read_cb) {
259 DVLOG(1) << "Read: " << position << " offset, " << size << " bytes"; 265 DVLOG(1) << "Read: " << position << " offset, " << size << " bytes";
260 DCHECK(!read_cb.is_null()); 266 DCHECK(!read_cb.is_null());
261 267
262 { 268 {
263 base::AutoLock auto_lock(lock_); 269 base::AutoLock auto_lock(lock_);
264 DCHECK(!read_op_); 270 DCHECK(!read_op_);
265 271
266 if (stop_signal_received_) { 272 if (stop_signal_received_) {
267 read_cb.Run(kReadError); 273 read_cb.Run(kReadError);
268 return; 274 return;
269 } 275 }
270 276
271 read_op_.reset(new ReadOperation(position, size, data, read_cb)); 277 read_op_.reset(new ReadOperation(position, size, data, read_cb));
272 } 278 }
273 279
274 render_task_runner_->PostTask( 280 render_task_runner_->PostTask(
275 FROM_HERE, 281 FROM_HERE,
276 base::Bind(&BufferedDataSource::ReadTask, weak_factory_.GetWeakPtr())); 282 base::Bind(&BufferedDataSource::ReadTask, weak_factory_.GetWeakPtr()));
277 } 283 }
278 284
279 bool BufferedDataSource::GetSize(int64* size_out) { 285 bool BufferedDataSource::GetSize(int64_t* size_out) {
280 if (total_bytes_ != kPositionNotSpecified) { 286 if (total_bytes_ != kPositionNotSpecified) {
281 *size_out = total_bytes_; 287 *size_out = total_bytes_;
282 return true; 288 return true;
283 } 289 }
284 *size_out = 0; 290 *size_out = 0;
285 return false; 291 return false;
286 } 292 }
287 293
288 bool BufferedDataSource::IsStreaming() { 294 bool BufferedDataSource::IsStreaming() {
289 return streaming_; 295 return streaming_;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 DCHECK(loader_.get()); 329 DCHECK(loader_.get());
324 330
325 bitrate_ = bitrate; 331 bitrate_ = bitrate;
326 loader_->SetBitrate(bitrate); 332 loader_->SetBitrate(bitrate);
327 } 333 }
328 334
329 // This method is the place where actual read happens, |loader_| must be valid 335 // This method is the place where actual read happens, |loader_| must be valid
330 // prior to make this method call. 336 // prior to make this method call.
331 void BufferedDataSource::ReadInternal() { 337 void BufferedDataSource::ReadInternal() {
332 DCHECK(render_task_runner_->BelongsToCurrentThread()); 338 DCHECK(render_task_runner_->BelongsToCurrentThread());
333 int64 position = 0; 339 int64_t position = 0;
334 int size = 0; 340 int size = 0;
335 { 341 {
336 base::AutoLock auto_lock(lock_); 342 base::AutoLock auto_lock(lock_);
337 if (stop_signal_received_) 343 if (stop_signal_received_)
338 return; 344 return;
339 345
340 position = read_op_->position(); 346 position = read_op_->position();
341 size = read_op_->size(); 347 size = read_op_->size();
342 } 348 }
343 349
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 // we should consider changing DownloadingCB to also propagate loading 553 // we should consider changing DownloadingCB to also propagate loading
548 // state. For example there isn't any signal today to notify the client that 554 // state. For example there isn't any signal today to notify the client that
549 // loading has failed (we only get errors on subsequent reads). 555 // loading has failed (we only get errors on subsequent reads).
550 case BufferedResourceLoader::kLoadingFailed: 556 case BufferedResourceLoader::kLoadingFailed:
551 return; 557 return;
552 } 558 }
553 559
554 downloading_cb_.Run(is_downloading_data); 560 downloading_cb_.Run(is_downloading_data);
555 } 561 }
556 562
557 void BufferedDataSource::ProgressCallback(int64 position) { 563 void BufferedDataSource::ProgressCallback(int64_t position) {
558 DCHECK(render_task_runner_->BelongsToCurrentThread()); 564 DCHECK(render_task_runner_->BelongsToCurrentThread());
559 565
560 if (assume_fully_buffered()) 566 if (assume_fully_buffered())
561 return; 567 return;
562 568
563 // TODO(scherkus): we shouldn't have to lock to signal host(), see 569 // TODO(scherkus): we shouldn't have to lock to signal host(), see
564 // http://crbug.com/113712 for details. 570 // http://crbug.com/113712 for details.
565 base::AutoLock auto_lock(lock_); 571 base::AutoLock auto_lock(lock_);
566 if (stop_signal_received_) 572 if (stop_signal_received_)
567 return; 573 return;
(...skipping 23 matching lines...) Expand all
591 } 597 }
592 598
593 // If media is currently playing or the page indicated preload=auto or the 599 // If media is currently playing or the page indicated preload=auto or the
594 // the server does not support the byte range request or we do not want to go 600 // the server does not support the byte range request or we do not want to go
595 // too far ahead of the read head, use threshold strategy to enable/disable 601 // too far ahead of the read head, use threshold strategy to enable/disable
596 // deferring when the buffer is full/depleted. 602 // deferring when the buffer is full/depleted.
597 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); 603 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer);
598 } 604 }
599 605
600 } // namespace media 606 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698