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

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

Issue 594733004: BufferedDataSource: don't reallocate buffer unnecessarily (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: follow-up Created 6 years, 2 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
« no previous file with comments | « media/blink/buffered_data_source.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "media/base/media_log.h" 10 #include "media/base/media_log.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 83 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
84 WebFrame* frame, 84 WebFrame* frame,
85 MediaLog* media_log, 85 MediaLog* media_log,
86 BufferedDataSourceHost* host, 86 BufferedDataSourceHost* host,
87 const DownloadingCB& downloading_cb) 87 const DownloadingCB& downloading_cb)
88 : url_(url), 88 : url_(url),
89 cors_mode_(cors_mode), 89 cors_mode_(cors_mode),
90 total_bytes_(kPositionNotSpecified), 90 total_bytes_(kPositionNotSpecified),
91 streaming_(false), 91 streaming_(false),
92 frame_(frame), 92 frame_(frame),
93 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), 93 intermediate_read_buffer_(kInitialReadBufferSize),
94 intermediate_read_buffer_size_(kInitialReadBufferSize),
95 render_task_runner_(task_runner), 94 render_task_runner_(task_runner),
96 stop_signal_received_(false), 95 stop_signal_received_(false),
97 media_has_played_(false), 96 media_has_played_(false),
98 preload_(AUTO), 97 preload_(AUTO),
99 bitrate_(0), 98 bitrate_(0),
100 playback_rate_(0.0), 99 playback_rate_(0.0),
101 media_log_(media_log), 100 media_log_(media_log),
102 host_(host), 101 host_(host),
103 downloading_cb_(downloading_cb), 102 downloading_cb_(downloading_cb),
104 weak_factory_(this) { 103 weak_factory_(this) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 base::AutoLock auto_lock(lock_); 306 base::AutoLock auto_lock(lock_);
308 if (stop_signal_received_) 307 if (stop_signal_received_)
309 return; 308 return;
310 309
311 position = read_op_->position(); 310 position = read_op_->position();
312 size = read_op_->size(); 311 size = read_op_->size();
313 } 312 }
314 313
315 // First we prepare the intermediate read buffer for BufferedResourceLoader 314 // First we prepare the intermediate read buffer for BufferedResourceLoader
316 // to write to. 315 // to write to.
317 if (size > intermediate_read_buffer_size_) { 316 if (static_cast<int>(intermediate_read_buffer_.size()) < size)
318 intermediate_read_buffer_.reset(new uint8[size]); 317 intermediate_read_buffer_.resize(size);
319 }
320 318
321 // Perform the actual read with BufferedResourceLoader. 319 // Perform the actual read with BufferedResourceLoader.
320 DCHECK(!intermediate_read_buffer_.empty());
322 loader_->Read(position, 321 loader_->Read(position,
323 size, 322 size,
324 intermediate_read_buffer_.get(), 323 &intermediate_read_buffer_[0],
325 base::Bind(&BufferedDataSource::ReadCallback, 324 base::Bind(&BufferedDataSource::ReadCallback,
326 weak_factory_.GetWeakPtr())); 325 weak_factory_.GetWeakPtr()));
327 } 326 }
328 327
329 328
330 ///////////////////////////////////////////////////////////////////////////// 329 /////////////////////////////////////////////////////////////////////////////
331 // BufferedResourceLoader callback methods. 330 // BufferedResourceLoader callback methods.
332 void BufferedDataSource::StartCallback( 331 void BufferedDataSource::StartCallback(
333 BufferedResourceLoader::Status status) { 332 BufferedResourceLoader::Status status) {
334 DCHECK(render_task_runner_->BelongsToCurrentThread()); 333 DCHECK(render_task_runner_->BelongsToCurrentThread());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 base::Bind(&BufferedDataSource::ProgressCallback, weak_this), 440 base::Bind(&BufferedDataSource::ProgressCallback, weak_this),
442 frame_); 441 frame_);
443 return; 442 return;
444 } 443 }
445 444
446 ReadOperation::Run(read_op_.Pass(), kReadError); 445 ReadOperation::Run(read_op_.Pass(), kReadError);
447 return; 446 return;
448 } 447 }
449 448
450 if (bytes_read > 0) { 449 if (bytes_read > 0) {
451 memcpy(read_op_->data(), intermediate_read_buffer_.get(), bytes_read); 450 DCHECK(!intermediate_read_buffer_.empty());
451 memcpy(read_op_->data(), &intermediate_read_buffer_[0], bytes_read);
452 } else if (bytes_read == 0 && total_bytes_ == kPositionNotSpecified) { 452 } else if (bytes_read == 0 && total_bytes_ == kPositionNotSpecified) {
453 // We've reached the end of the file and we didn't know the total size 453 // We've reached the end of the file and we didn't know the total size
454 // before. Update the total size so Read()s past the end of the file will 454 // before. Update the total size so Read()s past the end of the file will
455 // fail like they would if we had known the file size at the beginning. 455 // fail like they would if we had known the file size at the beginning.
456 total_bytes_ = loader_->instance_size(); 456 total_bytes_ = loader_->instance_size();
457 457
458 if (total_bytes_ != kPositionNotSpecified) { 458 if (total_bytes_ != kPositionNotSpecified) {
459 host_->SetTotalBytes(total_bytes_); 459 host_->SetTotalBytes(total_bytes_);
460 host_->AddBufferedByteRange(loader_->first_byte_position(), 460 host_->AddBufferedByteRange(loader_->first_byte_position(),
461 total_bytes_); 461 total_bytes_);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 526 }
527 527
528 // If media is currently playing or the page indicated preload=auto or the 528 // If media is currently playing or the page indicated preload=auto or the
529 // the server does not support the byte range request or we do not want to go 529 // the server does not support the byte range request or we do not want to go
530 // too far ahead of the read head, use threshold strategy to enable/disable 530 // too far ahead of the read head, use threshold strategy to enable/disable
531 // deferring when the buffer is full/depleted. 531 // deferring when the buffer is full/depleted.
532 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); 532 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer);
533 } 533 }
534 534
535 } // namespace media 535 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/buffered_data_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698