OLD | NEW |
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/multibuffer_data_source.h" | 5 #include "media/blink/multibuffer_data_source.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 FROM_HERE, base::Bind(&MultibufferDataSource::ReadTask, weak_ptr_)); | 223 FROM_HERE, base::Bind(&MultibufferDataSource::ReadTask, weak_ptr_)); |
224 } else { | 224 } else { |
225 reader_->Wait(1, | 225 reader_->Wait(1, |
226 base::Bind(&MultibufferDataSource::ReadTask, weak_ptr_)); | 226 base::Bind(&MultibufferDataSource::ReadTask, weak_ptr_)); |
227 } | 227 } |
228 } | 228 } |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 void MultibufferDataSource::SetPreload(Preload preload) { | 232 void MultibufferDataSource::SetPreload(Preload preload) { |
233 DVLOG(1) << __FUNCTION__ << "(" << preload << ")"; | 233 DVLOG(1) << __func__ << "(" << preload << ")"; |
234 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 234 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
235 preload_ = preload; | 235 preload_ = preload; |
236 UpdateBufferSizes(); | 236 UpdateBufferSizes(); |
237 } | 237 } |
238 | 238 |
239 void MultibufferDataSource::SetBufferingStrategy( | 239 void MultibufferDataSource::SetBufferingStrategy( |
240 BufferingStrategy buffering_strategy) { | 240 BufferingStrategy buffering_strategy) { |
241 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 241 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
242 buffering_strategy_ = buffering_strategy; | 242 buffering_strategy_ = buffering_strategy; |
243 UpdateBufferSizes(); | 243 UpdateBufferSizes(); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 502 |
503 render_task_runner_->PostTask( | 503 render_task_runner_->PostTask( |
504 FROM_HERE, base::Bind(base::ResetAndReturn(&init_cb_), success)); | 504 FROM_HERE, base::Bind(base::ResetAndReturn(&init_cb_), success)); |
505 | 505 |
506 // Even if data is cached, say that we're loading at this point for | 506 // Even if data is cached, say that we're loading at this point for |
507 // compatibility. | 507 // compatibility. |
508 UpdateLoadingState(true); | 508 UpdateLoadingState(true); |
509 } | 509 } |
510 | 510 |
511 void MultibufferDataSource::ProgressCallback(int64_t begin, int64_t end) { | 511 void MultibufferDataSource::ProgressCallback(int64_t begin, int64_t end) { |
512 DVLOG(1) << __FUNCTION__ << "(" << begin << ", " << end << ")"; | 512 DVLOG(1) << __func__ << "(" << begin << ", " << end << ")"; |
513 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 513 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
514 | 514 |
515 if (assume_fully_buffered()) | 515 if (assume_fully_buffered()) |
516 return; | 516 return; |
517 | 517 |
518 if (end > begin) { | 518 if (end > begin) { |
519 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 519 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
520 // http://crbug.com/113712 for details. | 520 // http://crbug.com/113712 for details. |
521 base::AutoLock auto_lock(lock_); | 521 base::AutoLock auto_lock(lock_); |
522 if (stop_signal_received_) | 522 if (stop_signal_received_) |
523 return; | 523 return; |
524 | 524 |
525 host_->AddBufferedByteRange(begin, end); | 525 host_->AddBufferedByteRange(begin, end); |
526 } | 526 } |
527 | 527 |
528 UpdateLoadingState(false); | 528 UpdateLoadingState(false); |
529 } | 529 } |
530 | 530 |
531 void MultibufferDataSource::UpdateLoadingState(bool force_loading) { | 531 void MultibufferDataSource::UpdateLoadingState(bool force_loading) { |
532 DVLOG(1) << __FUNCTION__; | 532 DVLOG(1) << __func__; |
533 if (assume_fully_buffered()) | 533 if (assume_fully_buffered()) |
534 return; | 534 return; |
535 // Update loading state. | 535 // Update loading state. |
536 bool is_loading = !!reader_ && reader_->IsLoading(); | 536 bool is_loading = !!reader_ && reader_->IsLoading(); |
537 if (force_loading || is_loading != loading_) { | 537 if (force_loading || is_loading != loading_) { |
538 loading_ = is_loading || force_loading; | 538 loading_ = is_loading || force_loading; |
539 | 539 |
540 if (!loading_ && cancel_on_defer_) { | 540 if (!loading_ && cancel_on_defer_) { |
541 reader_.reset(nullptr); | 541 reader_.reset(nullptr); |
542 } | 542 } |
543 | 543 |
544 // Callback could kill us, be sure to call it last. | 544 // Callback could kill us, be sure to call it last. |
545 downloading_cb_.Run(loading_); | 545 downloading_cb_.Run(loading_); |
546 } | 546 } |
547 } | 547 } |
548 | 548 |
549 void MultibufferDataSource::UpdateBufferSizes() { | 549 void MultibufferDataSource::UpdateBufferSizes() { |
550 DVLOG(1) << __FUNCTION__; | 550 DVLOG(1) << __func__; |
551 if (!reader_) | 551 if (!reader_) |
552 return; | 552 return; |
553 | 553 |
554 if (!assume_fully_buffered()) { | 554 if (!assume_fully_buffered()) { |
555 // If the playback has started and the strategy is aggressive, then try to | 555 // If the playback has started and the strategy is aggressive, then try to |
556 // load as much as possible, assuming that the file is cacheable. (If not, | 556 // load as much as possible, assuming that the file is cacheable. (If not, |
557 // why bother?) | 557 // why bother?) |
558 bool aggressive = (buffering_strategy_ == BUFFERING_STRATEGY_AGGRESSIVE); | 558 bool aggressive = (buffering_strategy_ == BUFFERING_STRATEGY_AGGRESSIVE); |
559 if (media_has_played_ && aggressive && url_data_ && | 559 if (media_has_played_ && aggressive && url_data_ && |
560 url_data_->range_supported() && url_data_->cacheable()) { | 560 url_data_->range_supported() && url_data_->cacheable()) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); | 595 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); |
596 | 596 |
597 if (preload_ == METADATA) { | 597 if (preload_ == METADATA) { |
598 reader_->SetPreload(0, 0); | 598 reader_->SetPreload(0, 0); |
599 } else { | 599 } else { |
600 reader_->SetPreload(preload_high, preload); | 600 reader_->SetPreload(preload_high, preload); |
601 } | 601 } |
602 } | 602 } |
603 | 603 |
604 } // namespace media | 604 } // namespace media |
OLD | NEW |