Chromium Code Reviews| 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 "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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 | 168 |
| 169 // We're not allowed to call Wait() if data is already available. | 169 // We're not allowed to call Wait() if data is already available. |
| 170 if (reader_->Available()) { | 170 if (reader_->Available()) { |
| 171 render_task_runner_->PostTask( | 171 render_task_runner_->PostTask( |
| 172 FROM_HERE, | 172 FROM_HERE, |
| 173 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_)); | 173 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_)); |
| 174 } else { | 174 } else { |
| 175 reader_->Wait(1, | 175 reader_->Wait(1, |
| 176 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_)); | 176 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_)); |
| 177 } | 177 } |
| 178 UpdateLoadingState(); | |
| 179 } | 178 } |
| 180 | 179 |
| 181 void MultibufferDataSource::OnRedirect( | 180 void MultibufferDataSource::OnRedirect( |
| 182 const scoped_refptr<UrlData>& destination) { | 181 const scoped_refptr<UrlData>& destination) { |
| 183 if (!destination) { | 182 if (!destination) { |
| 184 // A failure occured. | 183 // A failure occured. |
| 185 if (!init_cb_.is_null()) { | 184 if (!init_cb_.is_null()) { |
| 186 render_task_runner_->PostTask( | 185 render_task_runner_->PostTask( |
| 187 FROM_HERE, | 186 FROM_HERE, |
| 188 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_)); | 187 base::Bind(&MultibufferDataSource::StartCallback, weak_ptr_)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 FROM_HERE, base::Bind(&MultibufferDataSource::ReadTask, weak_ptr_)); | 221 FROM_HERE, base::Bind(&MultibufferDataSource::ReadTask, weak_ptr_)); |
| 223 } else { | 222 } else { |
| 224 reader_->Wait(1, | 223 reader_->Wait(1, |
| 225 base::Bind(&MultibufferDataSource::ReadTask, weak_ptr_)); | 224 base::Bind(&MultibufferDataSource::ReadTask, weak_ptr_)); |
| 226 } | 225 } |
| 227 } | 226 } |
| 228 } | 227 } |
| 229 } | 228 } |
| 230 | 229 |
| 231 void MultibufferDataSource::SetPreload(Preload preload) { | 230 void MultibufferDataSource::SetPreload(Preload preload) { |
| 231 DVLOG(1) << __FUNCTION__ << "(" << preload << ")"; | |
| 232 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 232 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
| 233 preload_ = preload; | 233 preload_ = preload; |
| 234 UpdateBufferSizes(); | 234 UpdateBufferSizes(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 bool MultibufferDataSource::HasSingleOrigin() { | 237 bool MultibufferDataSource::HasSingleOrigin() { |
| 238 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 238 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
| 239 DCHECK(init_cb_.is_null() && reader_.get()) | 239 DCHECK(init_cb_.is_null() && reader_.get()) |
| 240 << "Initialize() must complete before calling HasSingleOrigin()"; | 240 << "Initialize() must complete before calling HasSingleOrigin()"; |
| 241 return single_origin_; | 241 return single_origin_; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 return; | 385 return; |
| 386 } | 386 } |
| 387 if (available) { | 387 if (available) { |
| 388 bytes_read = | 388 bytes_read = |
| 389 static_cast<int>(std::min<int64_t>(available, read_op_->size())); | 389 static_cast<int>(std::min<int64_t>(available, read_op_->size())); |
| 390 bytes_read = reader_->TryRead(read_op_->data(), bytes_read); | 390 bytes_read = reader_->TryRead(read_op_->data(), bytes_read); |
| 391 ReadOperation::Run(read_op_.Pass(), bytes_read); | 391 ReadOperation::Run(read_op_.Pass(), bytes_read); |
| 392 } else { | 392 } else { |
| 393 reader_->Wait(1, base::Bind(&MultibufferDataSource::ReadTask, | 393 reader_->Wait(1, base::Bind(&MultibufferDataSource::ReadTask, |
| 394 weak_factory_.GetWeakPtr())); | 394 weak_factory_.GetWeakPtr())); |
| 395 UpdateLoadingState(); | 395 UpdateLoadingState(false); |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 void MultibufferDataSource::StopInternal_Locked() { | 399 void MultibufferDataSource::StopInternal_Locked() { |
| 400 lock_.AssertAcquired(); | 400 lock_.AssertAcquired(); |
| 401 if (stop_signal_received_) | 401 if (stop_signal_received_) |
| 402 return; | 402 return; |
| 403 | 403 |
| 404 stop_signal_received_ = true; | 404 stop_signal_received_ = true; |
| 405 | 405 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 | 468 |
| 469 // Progress callback might be called after the start callback, | 469 // Progress callback might be called after the start callback, |
| 470 // make sure that we update single_origin_ now. | 470 // make sure that we update single_origin_ now. |
| 471 media_log_->SetBooleanProperty("single_origin", single_origin_); | 471 media_log_->SetBooleanProperty("single_origin", single_origin_); |
| 472 media_log_->SetBooleanProperty("passed_cors_access_check", | 472 media_log_->SetBooleanProperty("passed_cors_access_check", |
| 473 DidPassCORSAccessCheck()); | 473 DidPassCORSAccessCheck()); |
| 474 media_log_->SetBooleanProperty("range_header_supported", | 474 media_log_->SetBooleanProperty("range_header_supported", |
| 475 url_data_->range_supported()); | 475 url_data_->range_supported()); |
| 476 } | 476 } |
| 477 | 477 |
| 478 UpdateLoadingState(); | |
| 479 render_task_runner_->PostTask( | 478 render_task_runner_->PostTask( |
| 480 FROM_HERE, base::Bind(base::ResetAndReturn(&init_cb_), success)); | 479 FROM_HERE, base::Bind(base::ResetAndReturn(&init_cb_), success)); |
| 480 | |
| 481 // Even if data is cached, say that we're loading at this point for | |
| 482 // compatibility. | |
| 483 UpdateLoadingState(true); | |
| 481 } | 484 } |
| 482 | 485 |
| 483 void MultibufferDataSource::ProgressCallback(int64 begin, int64 end) { | 486 void MultibufferDataSource::ProgressCallback(int64 begin, int64 end) { |
| 487 DVLOG(1) << __FUNCTION__ << "(" << begin << ", " << end << ")"; | |
| 484 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 488 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
| 485 | 489 |
| 486 if (assume_fully_buffered()) | 490 if (assume_fully_buffered()) |
| 487 return; | 491 return; |
| 488 | 492 |
| 489 if (end > begin) { | 493 if (end > begin) { |
| 490 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 494 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
| 491 // http://crbug.com/113712 for details. | 495 // http://crbug.com/113712 for details. |
| 492 base::AutoLock auto_lock(lock_); | 496 base::AutoLock auto_lock(lock_); |
| 493 if (stop_signal_received_) | 497 if (stop_signal_received_) |
| 494 return; | 498 return; |
| 495 | 499 |
| 496 host_->AddBufferedByteRange(begin, end); | 500 host_->AddBufferedByteRange(begin, end); |
| 497 } | 501 } |
| 498 | 502 |
| 499 UpdateLoadingState(); | 503 UpdateLoadingState(false); |
| 500 } | 504 } |
| 501 | 505 |
| 502 void MultibufferDataSource::UpdateLoadingState() { | 506 void MultibufferDataSource::UpdateLoadingState(bool force_loading) { |
| 507 DVLOG(1) << __FUNCTION__; | |
| 508 if (assume_fully_buffered()) | |
| 509 return; | |
| 503 // Update loading state. | 510 // Update loading state. |
| 504 if ((!!reader_ && reader_->IsLoading()) != loading_) { | 511 bool is_loading = !!reader_ && reader_->IsLoading(); |
| 505 loading_ = !loading_; | 512 if (force_loading || is_loading != loading_) { |
| 513 loading_ = is_loading || force_loading; | |
|
liberato (no reviews please)
2015/12/08 21:59:33
if the reader reports !loading, how does loading_
hubbe
2015/12/08 22:25:59
Updated comment for |loading_|.
loading_ will be s
| |
| 506 | 514 |
| 507 if (!loading_ && cancel_on_defer_) { | 515 if (!loading_ && cancel_on_defer_) { |
|
liberato (no reviews please)
2015/12/08 21:59:33
this can happen on force_loading that wouldn't hav
hubbe
2015/12/08 22:25:59
if force_loading is true, then loading_ will be tr
| |
| 508 reader_.reset(nullptr); | 516 reader_.reset(nullptr); |
| 509 } | 517 } |
| 510 | 518 |
| 511 // Callback could kill us, be sure to call it last. | 519 // Callback could kill us, be sure to call it last. |
| 512 downloading_cb_.Run(loading_); | 520 downloading_cb_.Run(loading_); |
| 513 } | 521 } |
| 514 } | 522 } |
| 515 | 523 |
| 516 void MultibufferDataSource::UpdateBufferSizes() { | 524 void MultibufferDataSource::UpdateBufferSizes() { |
| 525 DVLOG(1) << __FUNCTION__; | |
| 517 if (!reader_) | 526 if (!reader_) |
| 518 return; | 527 return; |
| 519 | 528 |
| 520 if (!assume_fully_buffered()) { | 529 if (!assume_fully_buffered()) { |
| 521 // If the playback has started and we're paused, then try to load as much as | 530 // If the playback has started and we're paused, then try to load as much as |
| 522 // possible, assuming that the file is cacheable. (If not, why bother?) | 531 // possible, assuming that the file is cacheable. (If not, why bother?) |
| 523 if (media_has_played_ && paused_ && url_data_ && | 532 if (media_has_played_ && paused_ && url_data_ && |
| 524 url_data_->range_supported() && url_data_->cacheable()) { | 533 url_data_->range_supported() && url_data_->cacheable()) { |
| 525 reader_->SetPreload(1LL << 40, 1LL << 40); // 1 Tb | 534 reader_->SetPreload(1LL << 40, 1LL << 40); // 1 Tb |
| 526 return; | 535 return; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 550 reader_->SetMaxBuffer(back_buffer, pin_forwards); | 559 reader_->SetMaxBuffer(back_buffer, pin_forwards); |
| 551 | 560 |
| 552 if (preload_ == METADATA) { | 561 if (preload_ == METADATA) { |
| 553 reader_->SetPreload(0, 0); | 562 reader_->SetPreload(0, 0); |
| 554 } else { | 563 } else { |
| 555 reader_->SetPreload(preload + kPreloadHighExtra, preload); | 564 reader_->SetPreload(preload + kPreloadHighExtra, preload); |
| 556 } | 565 } |
| 557 } | 566 } |
| 558 | 567 |
| 559 } // namespace media | 568 } // namespace media |
| OLD | NEW |