| 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(false); | 419 UpdateLoadingState_Locked(false); |
| 420 } | 420 } |
| 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 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 DidPassCORSAccessCheck()); | 500 DidPassCORSAccessCheck()); |
| 501 media_log_->SetBooleanProperty("range_header_supported", | 501 media_log_->SetBooleanProperty("range_header_supported", |
| 502 url_data_->range_supported()); | 502 url_data_->range_supported()); |
| 503 } | 503 } |
| 504 | 504 |
| 505 render_task_runner_->PostTask( | 505 render_task_runner_->PostTask( |
| 506 FROM_HERE, base::Bind(base::ResetAndReturn(&init_cb_), success)); | 506 FROM_HERE, base::Bind(base::ResetAndReturn(&init_cb_), success)); |
| 507 | 507 |
| 508 // Even if data is cached, say that we're loading at this point for | 508 // Even if data is cached, say that we're loading at this point for |
| 509 // compatibility. | 509 // compatibility. |
| 510 UpdateLoadingState(true); | 510 UpdateLoadingState_Locked(true); |
| 511 } | 511 } |
| 512 | 512 |
| 513 void MultibufferDataSource::ProgressCallback(int64_t begin, int64_t end) { | 513 void MultibufferDataSource::ProgressCallback(int64_t begin, int64_t end) { |
| 514 DVLOG(1) << __func__ << "(" << begin << ", " << end << ")"; | 514 DVLOG(1) << __func__ << "(" << begin << ", " << end << ")"; |
| 515 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 515 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
| 516 | 516 |
| 517 if (assume_fully_buffered()) | 517 if (assume_fully_buffered()) |
| 518 return; | 518 return; |
| 519 | 519 |
| 520 base::AutoLock auto_lock(lock_); |
| 521 |
| 520 if (end > begin) { | 522 if (end > begin) { |
| 521 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 523 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
| 522 // http://crbug.com/113712 for details. | 524 // http://crbug.com/113712 for details. |
| 523 base::AutoLock auto_lock(lock_); | |
| 524 if (stop_signal_received_) | 525 if (stop_signal_received_) |
| 525 return; | 526 return; |
| 526 | 527 |
| 527 host_->AddBufferedByteRange(begin, end); | 528 host_->AddBufferedByteRange(begin, end); |
| 528 } | 529 } |
| 529 | 530 |
| 530 UpdateLoadingState(false); | 531 UpdateLoadingState_Locked(false); |
| 531 } | 532 } |
| 532 | 533 |
| 533 void MultibufferDataSource::UpdateLoadingState(bool force_loading) { | 534 void MultibufferDataSource::UpdateLoadingState_Locked(bool force_loading) { |
| 534 DVLOG(1) << __func__; | 535 DVLOG(1) << __func__; |
| 536 lock_.AssertAcquired(); |
| 535 if (assume_fully_buffered()) | 537 if (assume_fully_buffered()) |
| 536 return; | 538 return; |
| 537 // Update loading state. | 539 // Update loading state. |
| 538 bool is_loading = !!reader_ && reader_->IsLoading(); | 540 bool is_loading = !!reader_ && reader_->IsLoading(); |
| 541 if (read_op_) |
| 542 is_loading = true; |
| 539 if (force_loading || is_loading != loading_) { | 543 if (force_loading || is_loading != loading_) { |
| 540 loading_ = is_loading || force_loading; | 544 loading_ = is_loading || force_loading; |
| 541 | 545 |
| 542 if (!loading_ && cancel_on_defer_) { | 546 if (!loading_ && cancel_on_defer_) { |
| 543 reader_.reset(nullptr); | 547 reader_.reset(nullptr); |
| 544 } | 548 } |
| 545 | 549 |
| 546 // Callback could kill us, be sure to call it last. | 550 // Callback could kill us, be sure to call it last. |
| 547 downloading_cb_.Run(loading_); | 551 downloading_cb_.Run(loading_); |
| 548 } | 552 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); | 601 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); |
| 598 | 602 |
| 599 if (preload_ == METADATA) { | 603 if (preload_ == METADATA) { |
| 600 reader_->SetPreload(0, 0); | 604 reader_->SetPreload(0, 0); |
| 601 } else { | 605 } else { |
| 602 reader_->SetPreload(preload_high, preload); | 606 reader_->SetPreload(preload_high, preload); |
| 603 } | 607 } |
| 604 } | 608 } |
| 605 | 609 |
| 606 } // namespace media | 610 } // namespace media |
| OLD | NEW |