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 "content/renderer/media/buffered_data_source.h" | 5 #include "content/renderer/media/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/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 if (playback_rate < 0.0f) | 194 if (playback_rate < 0.0f) |
| 195 return; | 195 return; |
| 196 | 196 |
| 197 playback_rate_ = playback_rate; | 197 playback_rate_ = playback_rate; |
| 198 loader_->SetPlaybackRate(playback_rate); | 198 loader_->SetPlaybackRate(playback_rate); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void BufferedDataSource::MediaIsPlaying() { | 201 void BufferedDataSource::MediaIsPlaying() { |
| 202 DCHECK(render_loop_->BelongsToCurrentThread()); | 202 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 203 media_has_played_ = true; | 203 media_has_played_ = true; |
| 204 UpdateDeferStrategy(false); | 204 // is_local_resource does not matter while playing, so send false. |
| 205 UpdateDeferStrategy(false, false); | |
| 205 } | 206 } |
| 206 | 207 |
| 207 void BufferedDataSource::MediaIsPaused() { | 208 void BufferedDataSource::MediaIsPaused(bool is_local_resource) { |
| 208 DCHECK(render_loop_->BelongsToCurrentThread()); | 209 DCHECK(render_loop_->BelongsToCurrentThread()); |
| 209 UpdateDeferStrategy(true); | 210 UpdateDeferStrategy(true, is_local_resource); |
| 210 } | 211 } |
| 211 | 212 |
| 212 ///////////////////////////////////////////////////////////////////////////// | 213 ///////////////////////////////////////////////////////////////////////////// |
| 213 // media::DataSource implementation. | 214 // media::DataSource implementation. |
| 214 void BufferedDataSource::Stop(const base::Closure& closure) { | 215 void BufferedDataSource::Stop(const base::Closure& closure) { |
| 215 { | 216 { |
| 216 base::AutoLock auto_lock(lock_); | 217 base::AutoLock auto_lock(lock_); |
| 217 StopInternal_Locked(); | 218 StopInternal_Locked(); |
| 218 } | 219 } |
| 219 closure.Run(); | 220 closure.Run(); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 | 507 |
| 507 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 508 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
| 508 // http://crbug.com/113712 for details. | 509 // http://crbug.com/113712 for details. |
| 509 base::AutoLock auto_lock(lock_); | 510 base::AutoLock auto_lock(lock_); |
| 510 if (stop_signal_received_) | 511 if (stop_signal_received_) |
| 511 return; | 512 return; |
| 512 | 513 |
| 513 host_->AddBufferedByteRange(loader_->first_byte_position(), position); | 514 host_->AddBufferedByteRange(loader_->first_byte_position(), position); |
| 514 } | 515 } |
| 515 | 516 |
| 516 void BufferedDataSource::UpdateDeferStrategy(bool paused) { | 517 void BufferedDataSource::UpdateDeferStrategy(bool paused, |
| 518 bool is_local_resource) { | |
| 517 // 200 responses end up not being reused to satisfy future range requests, | 519 // 200 responses end up not being reused to satisfy future range requests, |
| 518 // and we don't want to get too far ahead of the read-head (and thus require | 520 // and we don't want to get too far ahead of the read-head (and thus require |
| 519 // a restart), so keep to the thresholds. | 521 // a restart), so keep to the thresholds. |
| 520 if (!loader_->range_supported()) { | 522 if (!loader_->range_supported()) { |
| 521 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); | 523 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
| 522 return; | 524 return; |
| 523 } | 525 } |
| 524 | 526 |
| 525 // If the playback has started (at which point the preload value is ignored) | 527 // If the playback has started (at which point the preload value is ignored) |
| 526 // and we're paused, then try to load as much as possible (the loader will | 528 // and we're paused, then try to load as much as possible (the loader will |
| 527 // fall back to kCapacityDefer if it knows the current response won't be | 529 // fall back to kCapacityDefer if it knows the current response won't be |
| 528 // useful from the cache in the future). | 530 // useful from the cache in the future) for external resources. Loading data |
| 531 // in buffer is not necessary while the player is paused. | |
|
AmoghBihani
2014/05/27 14:17:30
Oh I am sorry, I will change this statement to "Lo
| |
| 529 if (media_has_played_ && paused) { | 532 if (media_has_played_ && paused) { |
| 533 if (is_local_resource) { | |
| 534 loader_->UpdateDeferStrategy(BufferedResourceLoader::kReadThenDefer); | |
| 535 return; | |
| 536 } | |
| 530 loader_->UpdateDeferStrategy(BufferedResourceLoader::kNeverDefer); | 537 loader_->UpdateDeferStrategy(BufferedResourceLoader::kNeverDefer); |
| 531 return; | 538 return; |
| 532 } | 539 } |
| 533 | 540 |
| 534 // If media is currently playing or the page indicated preload=auto, | 541 // If media is currently playing or the page indicated preload=auto, |
| 535 // use threshold strategy to enable/disable deferring when the buffer | 542 // use threshold strategy to enable/disable deferring when the buffer |
| 536 // is full/depleted. | 543 // is full/depleted. |
| 537 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); | 544 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
| 538 } | 545 } |
| 539 | 546 |
| 540 } // namespace content | 547 } // namespace content |
| OLD | NEW |