Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: media/blink/multibuffer_data_source.cc

Issue 1954493002: Tweak multibuffer buffering strategy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/blink/multibuffer_reader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // magnitude and clamp to prevent overflow. 560 // magnitude and clamp to prevent overflow.
561 double playback_rate = playback_rate_; 561 double playback_rate = playback_rate_;
562 562
563 playback_rate = std::max(playback_rate, 1.0); 563 playback_rate = std::max(playback_rate, 1.0);
564 playback_rate = std::min(playback_rate, kMaxPlaybackRate); 564 playback_rate = std::min(playback_rate, kMaxPlaybackRate);
565 565
566 int64_t bytes_per_second = (bitrate / 8.0) * playback_rate; 566 int64_t bytes_per_second = (bitrate / 8.0) * playback_rate;
567 567
568 int64_t preload = clamp(kTargetSecondsBufferedAhead * bytes_per_second, 568 int64_t preload = clamp(kTargetSecondsBufferedAhead * bytes_per_second,
569 kMinBufferPreload, kMaxBufferPreload); 569 kMinBufferPreload, kMaxBufferPreload);
570 int64_t preload_high = preload + kPreloadHighExtra;
571
572 // Assert that kMaxBufferSize is big enough that the subtraction on the next
573 // line cannot go negative.
574 static_assert(kMaxBufferSize > kMaxBufferPreload + kPreloadHighExtra,
575 "kMaxBufferSize too small to contain preload.");
570 int64_t back_buffer = clamp(kTargetSecondsBufferedBehind * bytes_per_second, 576 int64_t back_buffer = clamp(kTargetSecondsBufferedBehind * bytes_per_second,
571 kMinBufferPreload, kMaxBufferPreload); 577 kMinBufferPreload, kMaxBufferSize - preload_high);
572 int64_t pin_forwards = kMaxBufferSize - back_buffer; 578 int64_t buffer_size =
573 DCHECK_LE(preload + kPreloadHighExtra, pin_forwards); 579 std::min((kTargetSecondsBufferedAhead + kTargetSecondsBufferedBehind) *
574 reader_->SetMaxBuffer(back_buffer, preload + kPreloadHighExtra); 580 bytes_per_second,
581 kMaxBufferSize);
582 reader_->SetMaxBuffer(buffer_size);
583 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra);
575 584
576 if (preload_ == METADATA) { 585 if (preload_ == METADATA) {
577 reader_->SetPreload(0, 0); 586 reader_->SetPreload(0, 0);
578 } else { 587 } else {
579 reader_->SetPreload(preload + kPreloadHighExtra, preload); 588 reader_->SetPreload(preload_high, preload);
580 } 589 }
581 } 590 }
582 591
583 } // namespace media 592 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/blink/multibuffer_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698