| 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 // fail like they would if we had known the file size at the beginning. | 409 // fail like they would if we had known the file size at the beginning. |
| 410 total_bytes_ = reader_->Tell(); | 410 total_bytes_ = reader_->Tell(); |
| 411 if (total_bytes_ != kPositionNotSpecified) | 411 if (total_bytes_ != kPositionNotSpecified) |
| 412 host_->SetTotalBytes(total_bytes_); | 412 host_->SetTotalBytes(total_bytes_); |
| 413 } | 413 } |
| 414 | 414 |
| 415 ReadOperation::Run(std::move(read_op_), bytes_read); | 415 ReadOperation::Run(std::move(read_op_), bytes_read); |
| 416 } else { | 416 } else { |
| 417 reader_->Wait(1, base::Bind(&MultibufferDataSource::ReadTask, | 417 reader_->Wait(1, base::Bind(&MultibufferDataSource::ReadTask, |
| 418 weak_factory_.GetWeakPtr())); | 418 weak_factory_.GetWeakPtr())); |
| 419 UpdateLoadingState_Locked(false); | |
| 420 } | 419 } |
| 420 UpdateLoadingState_Locked(false); |
| 421 } | 421 } |
| 422 | 422 |
| 423 void MultibufferDataSource::StopInternal_Locked() { | 423 void MultibufferDataSource::StopInternal_Locked() { |
| 424 lock_.AssertAcquired(); | 424 lock_.AssertAcquired(); |
| 425 if (stop_signal_received_) | 425 if (stop_signal_received_) |
| 426 return; | 426 return; |
| 427 | 427 |
| 428 stop_signal_received_ = true; | 428 stop_signal_received_ = true; |
| 429 | 429 |
| 430 // Initialize() isn't part of the DataSource interface so don't call it in | 430 // Initialize() isn't part of the DataSource interface so don't call it in |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 UpdateLoadingState_Locked(false); | 531 UpdateLoadingState_Locked(false); |
| 532 } | 532 } |
| 533 | 533 |
| 534 void MultibufferDataSource::UpdateLoadingState_Locked(bool force_loading) { | 534 void MultibufferDataSource::UpdateLoadingState_Locked(bool force_loading) { |
| 535 DVLOG(1) << __func__; | 535 DVLOG(1) << __func__; |
| 536 lock_.AssertAcquired(); | 536 lock_.AssertAcquired(); |
| 537 if (assume_fully_buffered()) | 537 if (assume_fully_buffered()) |
| 538 return; | 538 return; |
| 539 // Update loading state. | 539 // Update loading state. |
| 540 bool is_loading = !!reader_ && reader_->IsLoading(); | 540 bool is_loading = !!reader_ && reader_->IsLoading(); |
| 541 if (read_op_) | |
| 542 is_loading = true; | |
| 543 if (force_loading || is_loading != loading_) { | 541 if (force_loading || is_loading != loading_) { |
| 544 loading_ = is_loading || force_loading; | 542 bool loading = is_loading || force_loading; |
| 545 | 543 |
| 546 if (!loading_ && cancel_on_defer_) { | 544 if (!loading && cancel_on_defer_) { |
| 545 if (read_op_) { |
| 546 // We can't destroy the reader if a read operation is pending. |
| 547 // UpdateLoadingState_Locked will be called again when the read |
| 548 // operation is done. |
| 549 return; |
| 550 } |
| 547 reader_.reset(nullptr); | 551 reader_.reset(nullptr); |
| 548 } | 552 } |
| 549 | 553 |
| 554 loading_ = loading; |
| 555 |
| 550 // Callback could kill us, be sure to call it last. | 556 // Callback could kill us, be sure to call it last. |
| 551 downloading_cb_.Run(loading_); | 557 downloading_cb_.Run(loading_); |
| 552 } | 558 } |
| 553 } | 559 } |
| 554 | 560 |
| 555 void MultibufferDataSource::UpdateBufferSizes() { | 561 void MultibufferDataSource::UpdateBufferSizes() { |
| 556 DVLOG(1) << __func__; | 562 DVLOG(1) << __func__; |
| 557 if (!reader_) | 563 if (!reader_) |
| 558 return; | 564 return; |
| 559 | 565 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); | 607 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); |
| 602 | 608 |
| 603 if (preload_ == METADATA) { | 609 if (preload_ == METADATA) { |
| 604 reader_->SetPreload(0, 0); | 610 reader_->SetPreload(0, 0); |
| 605 } else { | 611 } else { |
| 606 reader_->SetPreload(preload_high, preload); | 612 reader_->SetPreload(preload_high, preload); |
| 607 } | 613 } |
| 608 } | 614 } |
| 609 | 615 |
| 610 } // namespace media | 616 } // namespace media |
| OLD | NEW |