| 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 <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" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "media/base/media_log.h" | 14 #include "media/base/media_log.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 | 16 |
| 17 using blink::WebFrame; | 17 using blink::WebFrame; |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // BufferedDataSource has an intermediate buffer, this value governs the initial | 21 // BufferedDataSource has an intermediate buffer, this value governs the initial |
| 22 // size of that buffer. It is set to 32KB because this is a typical read size | 22 // size of that buffer. It is set to 32KB because this is a typical read size |
| 23 // of FFmpeg. | 23 // of FFmpeg. |
| 24 const int kInitialReadBufferSize = 32768; | 24 const int kInitialReadBufferSize = 32768; |
| 25 | 25 |
| 26 // Number of cache misses or read failures we allow for a single Read() before | |
| 27 // signaling an error. | |
| 28 const int kLoaderRetries = 3; | |
| 29 | |
| 30 // The number of milliseconds to wait before retrying a failed load. | 26 // The number of milliseconds to wait before retrying a failed load. |
| 31 const int kLoaderFailedRetryDelayMs = 250; | 27 const int kLoaderFailedRetryDelayMs = 250; |
| 32 | 28 |
| 29 // Each retry, add this many MS to the delay. |
| 30 // total delay is: |
| 31 // (kLoaderPartialRetryDelayMs + |
| 32 // kAdditionalDelayPerRetryMs * (kMaxRetries - 1) / 2) * kLoaderRetries |
| 33 // = 29250 ms |
| 34 const int kAdditionalDelayPerRetryMs = 50; |
| 35 |
| 33 } // namespace | 36 } // namespace |
| 34 | 37 |
| 35 namespace media { | 38 namespace media { |
| 36 | 39 |
| 37 class BufferedDataSource::ReadOperation { | 40 class BufferedDataSource::ReadOperation { |
| 38 public: | 41 public: |
| 39 ReadOperation(int64_t position, | 42 ReadOperation(int64_t position, |
| 40 int size, | 43 int size, |
| 41 uint8_t* data, | 44 uint8_t* data, |
| 42 const DataSource::ReadCB& callback); | 45 const DataSource::ReadCB& callback); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 487 |
| 485 if (read_op_->retries() < kLoaderRetries) { | 488 if (read_op_->retries() < kLoaderRetries) { |
| 486 // Allow some resiliency against sporadic network failures or intentional | 489 // Allow some resiliency against sporadic network failures or intentional |
| 487 // cancellations due to a system suspend / resume. Here we treat failed | 490 // cancellations due to a system suspend / resume. Here we treat failed |
| 488 // reads as a cache miss so long as we haven't exceeded max retries. | 491 // reads as a cache miss so long as we haven't exceeded max retries. |
| 489 if (status == BufferedResourceLoader::kFailed) { | 492 if (status == BufferedResourceLoader::kFailed) { |
| 490 render_task_runner_->PostDelayedTask( | 493 render_task_runner_->PostDelayedTask( |
| 491 FROM_HERE, base::Bind(&BufferedDataSource::ReadCallback, | 494 FROM_HERE, base::Bind(&BufferedDataSource::ReadCallback, |
| 492 weak_factory_.GetWeakPtr(), | 495 weak_factory_.GetWeakPtr(), |
| 493 BufferedResourceLoader::kCacheMiss, 0), | 496 BufferedResourceLoader::kCacheMiss, 0), |
| 494 base::TimeDelta::FromMilliseconds(kLoaderFailedRetryDelayMs)); | 497 base::TimeDelta::FromMilliseconds(kLoaderFailedRetryDelayMs + |
| 498 read_op_->retries() * |
| 499 kAdditionalDelayPerRetryMs)); |
| 495 return; | 500 return; |
| 496 } | 501 } |
| 497 | 502 |
| 498 read_op_->IncrementRetries(); | 503 read_op_->IncrementRetries(); |
| 499 | 504 |
| 500 // Recreate a loader starting from where we last left off until the | 505 // Recreate a loader starting from where we last left off until the |
| 501 // end of the resource. | 506 // end of the resource. |
| 502 loader_.reset(CreateResourceLoader( | 507 loader_.reset(CreateResourceLoader( |
| 503 read_op_->position(), kPositionNotSpecified)); | 508 read_op_->position(), kPositionNotSpecified)); |
| 504 | 509 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 } | 605 } |
| 601 | 606 |
| 602 // If media is currently playing or the page indicated preload=auto or the | 607 // If media is currently playing or the page indicated preload=auto or the |
| 603 // the server does not support the byte range request or we do not want to go | 608 // the server does not support the byte range request or we do not want to go |
| 604 // too far ahead of the read head, use threshold strategy to enable/disable | 609 // too far ahead of the read head, use threshold strategy to enable/disable |
| 605 // deferring when the buffer is full/depleted. | 610 // deferring when the buffer is full/depleted. |
| 606 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); | 611 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
| 607 } | 612 } |
| 608 | 613 |
| 609 } // namespace media | 614 } // namespace media |
| OLD | NEW |