| 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 | 26 // Number of cache misses or read failures we allow for a single Read() before |
| 27 // signaling an error. | 27 // signaling an error. |
| 28 const int kLoaderRetries = 3; | 28 // total delay is: |
| 29 // (kLoaderPartialRetryDelayMs + |
| 30 // kAdditionalDelayPerRetryMs * (kMaxRetries - 1) / 2) * kMaxretries = 29250 ms |
| 31 const int kLoaderRetries = 30; |
| 29 | 32 |
| 30 // The number of milliseconds to wait before retrying a failed load. | 33 // The number of milliseconds to wait before retrying a failed load. |
| 31 const int kLoaderFailedRetryDelayMs = 250; | 34 const int kLoaderFailedRetryDelayMs = 250; |
| 32 | 35 |
| 36 // Each retry, add this many MS to the delay. |
| 37 const int kAdditionalDelayPerRetryMs = 50; |
| 38 |
| 33 } // namespace | 39 } // namespace |
| 34 | 40 |
| 35 namespace media { | 41 namespace media { |
| 36 | 42 |
| 37 class BufferedDataSource::ReadOperation { | 43 class BufferedDataSource::ReadOperation { |
| 38 public: | 44 public: |
| 39 ReadOperation(int64_t position, | 45 ReadOperation(int64_t position, |
| 40 int size, | 46 int size, |
| 41 uint8_t* data, | 47 uint8_t* data, |
| 42 const DataSource::ReadCB& callback); | 48 const DataSource::ReadCB& callback); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 490 |
| 485 if (read_op_->retries() < kLoaderRetries) { | 491 if (read_op_->retries() < kLoaderRetries) { |
| 486 // Allow some resiliency against sporadic network failures or intentional | 492 // Allow some resiliency against sporadic network failures or intentional |
| 487 // cancellations due to a system suspend / resume. Here we treat failed | 493 // 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. | 494 // reads as a cache miss so long as we haven't exceeded max retries. |
| 489 if (status == BufferedResourceLoader::kFailed) { | 495 if (status == BufferedResourceLoader::kFailed) { |
| 490 render_task_runner_->PostDelayedTask( | 496 render_task_runner_->PostDelayedTask( |
| 491 FROM_HERE, base::Bind(&BufferedDataSource::ReadCallback, | 497 FROM_HERE, base::Bind(&BufferedDataSource::ReadCallback, |
| 492 weak_factory_.GetWeakPtr(), | 498 weak_factory_.GetWeakPtr(), |
| 493 BufferedResourceLoader::kCacheMiss, 0), | 499 BufferedResourceLoader::kCacheMiss, 0), |
| 494 base::TimeDelta::FromMilliseconds(kLoaderFailedRetryDelayMs)); | 500 base::TimeDelta::FromMilliseconds(kLoaderFailedRetryDelayMs + |
| 501 read_op_->retries() * |
| 502 kAdditionalDelayPerRetryMs)); |
| 495 return; | 503 return; |
| 496 } | 504 } |
| 497 | 505 |
| 498 read_op_->IncrementRetries(); | 506 read_op_->IncrementRetries(); |
| 499 | 507 |
| 500 // Recreate a loader starting from where we last left off until the | 508 // Recreate a loader starting from where we last left off until the |
| 501 // end of the resource. | 509 // end of the resource. |
| 502 loader_.reset(CreateResourceLoader( | 510 loader_.reset(CreateResourceLoader( |
| 503 read_op_->position(), kPositionNotSpecified)); | 511 read_op_->position(), kPositionNotSpecified)); |
| 504 | 512 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 } | 608 } |
| 601 | 609 |
| 602 // If media is currently playing or the page indicated preload=auto or the | 610 // 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 | 611 // 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 | 612 // too far ahead of the read head, use threshold strategy to enable/disable |
| 605 // deferring when the buffer is full/depleted. | 613 // deferring when the buffer is full/depleted. |
| 606 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); | 614 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
| 607 } | 615 } |
| 608 | 616 |
| 609 } // namespace media | 617 } // namespace media |
| OLD | NEW |