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/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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // we should consider changing DownloadingCB to also propagate loading | 486 // we should consider changing DownloadingCB to also propagate loading |
487 // state. For example there isn't any signal today to notify the client that | 487 // state. For example there isn't any signal today to notify the client that |
488 // loading has failed (we only get errors on subsequent reads). | 488 // loading has failed (we only get errors on subsequent reads). |
489 case BufferedResourceLoader::kLoadingFailed: | 489 case BufferedResourceLoader::kLoadingFailed: |
490 return; | 490 return; |
491 } | 491 } |
492 | 492 |
493 downloading_cb_.Run(is_downloading_data); | 493 downloading_cb_.Run(is_downloading_data); |
494 } | 494 } |
495 | 495 |
496 void BufferedDataSource::ProgressCallback(int64 position) { | 496 void BufferedDataSource::ProgressCallback(int64 earliest_position, |
| 497 int64 position) { |
497 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 498 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
498 | 499 |
499 if (assume_fully_buffered()) | 500 if (assume_fully_buffered()) |
500 return; | 501 return; |
501 | 502 |
502 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 503 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
503 // http://crbug.com/113712 for details. | 504 // http://crbug.com/113712 for details. |
504 base::AutoLock auto_lock(lock_); | 505 base::AutoLock auto_lock(lock_); |
505 if (stop_signal_received_) | 506 if (stop_signal_received_) |
506 return; | 507 return; |
507 | 508 |
508 host_->AddBufferedByteRange(loader_->first_byte_position(), position); | 509 host_->AddBufferedByteRange(loader_->first_byte_position(), position); |
| 510 host_->RemoveBufferedByteRange(earliest_position); |
509 } | 511 } |
510 | 512 |
511 void BufferedDataSource::UpdateDeferStrategy(bool paused) { | 513 void BufferedDataSource::UpdateDeferStrategy(bool paused) { |
512 // No need to aggressively buffer when we are assuming the resource is fully | 514 // No need to aggressively buffer when we are assuming the resource is fully |
513 // buffered. | 515 // buffered. |
514 if (assume_fully_buffered()) { | 516 if (assume_fully_buffered()) { |
515 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); | 517 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
516 return; | 518 return; |
517 } | 519 } |
518 | 520 |
519 // If the playback has started (at which point the preload value is ignored) | 521 // If the playback has started (at which point the preload value is ignored) |
520 // and we're paused, then try to load as much as possible (the loader will | 522 // and we're paused, then try to load as much as possible (the loader will |
521 // fall back to kCapacityDefer if it knows the current response won't be | 523 // fall back to kCapacityDefer if it knows the current response won't be |
522 // useful from the cache in the future). | 524 // useful from the cache in the future). |
523 if (media_has_played_ && paused && loader_->range_supported()) { | 525 if (media_has_played_ && paused && loader_->range_supported()) { |
524 loader_->UpdateDeferStrategy(BufferedResourceLoader::kNeverDefer); | 526 loader_->UpdateDeferStrategy(BufferedResourceLoader::kNeverDefer); |
525 return; | 527 return; |
526 } | 528 } |
527 | 529 |
528 // If media is currently playing or the page indicated preload=auto or the | 530 // 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 | 531 // 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 | 532 // too far ahead of the read head, use threshold strategy to enable/disable |
531 // deferring when the buffer is full/depleted. | 533 // deferring when the buffer is full/depleted. |
532 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); | 534 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
533 } | 535 } |
534 | 536 |
535 } // namespace media | 537 } // namespace media |
OLD | NEW |