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 <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 "media/blink/buffered_data_source_host_impl.h" | 15 #include "media/blink/buffered_data_source_host_impl.h" |
16 #include "media/blink/multibuffer_reader.h" | 16 #include "media/blink/multibuffer_reader.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 | 18 |
19 using blink::WebFrame; | 19 using blink::WebFrame; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Minimum preload buffer. | 23 // Minimum preload buffer. |
24 const int64_t kMinBufferPreload = 2 << 20; // 2 Mb | 24 const int64_t kMinBufferPreload = 2 << 20; // 2 Mb |
25 // Maxmimum preload buffer. | 25 // Maxmimum preload buffer. |
26 const int64_t kMaxBufferPreload = 20 << 20; // 20 Mb | 26 const int64_t kMaxBufferPreload = 50 << 20; // 50 Mb |
27 | 27 |
28 // Preload this much extra, then stop preloading until we fall below the | 28 // Preload this much extra, then stop preloading until we fall below the |
29 // kTargetSecondsBufferedAhead. | 29 // kTargetSecondsBufferedAhead. |
30 const int64_t kPreloadHighExtra = 1 << 20; // 1 Mb | 30 const int64_t kPreloadHighExtra = 1 << 20; // 1 Mb |
31 | 31 |
32 // Total size of the pinned region in the cache. | 32 // Total size of the pinned region in the cache. |
33 // Note that we go over this if preload is calculated high enough. | |
33 const int64_t kMaxBufferSize = 25 << 20; // 25 Mb | 34 const int64_t kMaxBufferSize = 25 << 20; // 25 Mb |
34 | 35 |
35 // If bitrate is not known, use this. | 36 // If bitrate is not known, use this. |
36 const int64_t kDefaultBitrate = 200 * 8 << 10; // 200 Kbps. | 37 const int64_t kDefaultBitrate = 200 * 8 << 10; // 200 Kbps. |
37 | 38 |
38 // Maximum bitrate for buffer calculations. | 39 // Maximum bitrate for buffer calculations. |
39 const int64_t kMaxBitrate = 20 * 8 << 20; // 20 Mbps. | 40 const int64_t kMaxBitrate = 20 * 8 << 20; // 20 Mbps. |
40 | 41 |
41 // Maximum playback rate for buffer calculations. | 42 // Maximum playback rate for buffer calculations. |
42 const double kMaxPlaybackRate = 25.0; | 43 const double kMaxPlaybackRate = 25.0; |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 | 597 |
597 playback_rate = std::max(playback_rate, 1.0); | 598 playback_rate = std::max(playback_rate, 1.0); |
598 playback_rate = std::min(playback_rate, kMaxPlaybackRate); | 599 playback_rate = std::min(playback_rate, kMaxPlaybackRate); |
599 | 600 |
600 int64_t bytes_per_second = (bitrate / 8.0) * playback_rate; | 601 int64_t bytes_per_second = (bitrate / 8.0) * playback_rate; |
601 | 602 |
602 int64_t preload = clamp(kTargetSecondsBufferedAhead * bytes_per_second, | 603 int64_t preload = clamp(kTargetSecondsBufferedAhead * bytes_per_second, |
603 kMinBufferPreload, kMaxBufferPreload); | 604 kMinBufferPreload, kMaxBufferPreload); |
604 int64_t preload_high = preload + kPreloadHighExtra; | 605 int64_t preload_high = preload + kPreloadHighExtra; |
605 | 606 |
606 // Assert that kMaxBufferSize is big enough that the subtraction on the next | 607 // Make sure that kMaxBufferSize is big enough that the subtraction on the |
607 // line cannot go negative. | 608 // next line cannot go negative. |
608 static_assert(kMaxBufferSize > kMaxBufferPreload + kPreloadHighExtra, | 609 int64_t max_buffer_size = |
609 "kMaxBufferSize too small to contain preload."); | 610 std::max(kMaxBufferSize, kMaxBufferPreload + kPreloadHighExtra); |
watk
2016/11/03 21:09:18
Drive by: It's confusing to me that kMaxBufferSize
hubbe
2016/11/03 23:11:59
You're right, and that's not how I wanted it to wo
| |
610 int64_t back_buffer = clamp(kTargetSecondsBufferedBehind * bytes_per_second, | 611 int64_t back_buffer = |
611 kMinBufferPreload, kMaxBufferSize - preload_high); | 612 clamp(kTargetSecondsBufferedBehind * bytes_per_second, kMinBufferPreload, |
613 max_buffer_size - preload_high); | |
612 int64_t buffer_size = | 614 int64_t buffer_size = |
613 std::min((kTargetSecondsBufferedAhead + kTargetSecondsBufferedBehind) * | 615 std::min((kTargetSecondsBufferedAhead + kTargetSecondsBufferedBehind) * |
614 bytes_per_second, | 616 bytes_per_second, |
615 kMaxBufferSize); | 617 max_buffer_size); |
616 reader_->SetMaxBuffer(buffer_size); | 618 reader_->SetMaxBuffer(buffer_size); |
617 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); | 619 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); |
618 | 620 |
619 if (preload_ == METADATA) { | 621 if (preload_ == METADATA) { |
620 reader_->SetPreload(0, 0); | 622 reader_->SetPreload(0, 0); |
621 } else { | 623 } else { |
622 reader_->SetPreload(preload_high, preload); | 624 reader_->SetPreload(preload_high, preload); |
623 } | 625 } |
624 } | 626 } |
625 | 627 |
626 } // namespace media | 628 } // namespace media |
OLD | NEW |