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

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

Issue 1954493002: Tweak multibuffer buffering strategy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.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.h" 9 #include "base/message_loop/message_loop.h"
10 #include "media/blink/multibuffer_reader.h" 10 #include "media/blink/multibuffer_reader.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 MultiBufferReader::MultiBufferReader( 15 MultiBufferReader::MultiBufferReader(
16 MultiBuffer* multibuffer, 16 MultiBuffer* multibuffer,
17 int64_t start, 17 int64_t start,
18 int64_t end, 18 int64_t end,
19 const base::Callback<void(int64_t, int64_t)>& progress_callback) 19 const base::Callback<void(int64_t, int64_t)>& progress_callback)
20 : multibuffer_(multibuffer), 20 : multibuffer_(multibuffer),
21 // If end is -1, we use a very large (but still supported) value instead. 21 // If end is -1, we use a very large (but still supported) value instead.
22 end_(end == -1LL ? (1LL << (multibuffer->block_size_shift() + 30)) : end), 22 end_(end == -1LL ? (1LL << (multibuffer->block_size_shift() + 30)) : end),
23 preload_high_(0), 23 preload_high_(0),
24 preload_low_(0), 24 preload_low_(0),
25 max_buffer_forward_(0), 25 max_buffer_forward_(0),
26 max_buffer_backward_(0), 26 max_buffer_backward_(0),
27 current_buffer_size_(0),
27 pinned_range_(0, 0), 28 pinned_range_(0, 0),
28 pos_(start), 29 pos_(start),
29 preload_pos_(-1), 30 preload_pos_(-1),
30 loading_(true), 31 loading_(true),
31 current_wait_size_(0), 32 current_wait_size_(0),
32 progress_callback_(progress_callback), 33 progress_callback_(progress_callback),
33 weak_factory_(this) { 34 weak_factory_(this) {
34 DCHECK_GE(start, 0); 35 DCHECK_GE(start, 0);
35 DCHECK_GE(end_, 0); 36 DCHECK_GE(end_, 0);
36 } 37 }
37 38
38 MultiBufferReader::~MultiBufferReader() { 39 MultiBufferReader::~MultiBufferReader() {
39 PinRange(0, 0); 40 PinRange(0, 0);
40 multibuffer_->RemoveReader(preload_pos_, this); 41 multibuffer_->RemoveReader(preload_pos_, this);
41 multibuffer_->IncrementMaxSize( 42 multibuffer_->IncrementMaxSize(-current_buffer_size_);
42 -block_ceil(max_buffer_forward_ + max_buffer_backward_));
43 multibuffer_->CleanupWriters(preload_pos_); 43 multibuffer_->CleanupWriters(preload_pos_);
44 } 44 }
45 45
46 void MultiBufferReader::Seek(int64_t pos) { 46 void MultiBufferReader::Seek(int64_t pos) {
47 DCHECK_GE(pos, 0); 47 DCHECK_GE(pos, 0);
48 if (pos == pos_) 48 if (pos == pos_)
49 return; 49 return;
50 PinRange(block(pos - max_buffer_backward_), 50 PinRange(block(pos - max_buffer_backward_),
51 block_ceil(pos + max_buffer_forward_)); 51 block_ceil(pos + max_buffer_forward_));
52 52
53 multibuffer_->RemoveReader(preload_pos_, this); 53 multibuffer_->RemoveReader(preload_pos_, this);
54 MultiBufferBlockId old_preload_pos = preload_pos_; 54 MultiBufferBlockId old_preload_pos = preload_pos_;
55 preload_pos_ = block(pos); 55 preload_pos_ = block(pos);
56 pos_ = pos; 56 pos_ = pos;
57 UpdateInternalState(); 57 UpdateInternalState();
58 multibuffer_->CleanupWriters(old_preload_pos); 58 multibuffer_->CleanupWriters(old_preload_pos);
59 } 59 }
60 60
61 void MultiBufferReader::SetMaxBuffer(int64_t backward, int64_t forward) { 61 void MultiBufferReader::SetMaxBuffer(int64_t buffer_size) {
62 // Safe, because we know this doesn't actually prune the cache right away. 62 // Safe, because we know this doesn't actually prune the cache right away.
63 multibuffer_->IncrementMaxSize( 63 int64_t new_buffer_size = block_ceil(buffer_size);
64 -block_ceil(max_buffer_forward_ + max_buffer_backward_)); 64 ;
DaleCurtis 2016/05/04 21:39:32 extra ;
hubbe 2016/05/04 21:55:06 Done.
65 multibuffer_->IncrementMaxSize(new_buffer_size - current_buffer_size_);
DaleCurtis 2016/05/04 21:39:32 dcheck cur <= new_buffer_size ?
hubbe 2016/05/04 21:55:06 Decreasing the buffer size is allowed. (As is call
66 current_buffer_size_ = new_buffer_size;
67 }
68
69 void MultiBufferReader::SetPinRange(int64_t backward, int64_t forward) {
70 // Safe, because we know this doesn't actually prune the cache right away.
65 max_buffer_backward_ = backward; 71 max_buffer_backward_ = backward;
66 max_buffer_forward_ = forward; 72 max_buffer_forward_ = forward;
67 PinRange(block(pos_ - max_buffer_backward_), 73 PinRange(block(pos_ - max_buffer_backward_),
68 block_ceil(pos_ + max_buffer_forward_)); 74 block_ceil(pos_ + max_buffer_forward_));
69
70 multibuffer_->IncrementMaxSize(
71 block_ceil(max_buffer_forward_ + max_buffer_backward_));
72 } 75 }
73 76
74 int64_t MultiBufferReader::Available() const { 77 int64_t MultiBufferReader::Available() const {
75 int64_t unavailable_byte_pos = 78 int64_t unavailable_byte_pos =
76 static_cast<int64_t>(multibuffer_->FindNextUnavailable(block(pos_))) 79 static_cast<int64_t>(multibuffer_->FindNextUnavailable(block(pos_)))
77 << multibuffer_->block_size_shift(); 80 << multibuffer_->block_size_shift();
78 return std::max<int64_t>(0, unavailable_byte_pos - pos_); 81 return std::max<int64_t>(0, unavailable_byte_pos - pos_);
79 } 82 }
80 83
81 int64_t MultiBufferReader::TryRead(uint8_t* data, int64_t len) { 84 int64_t MultiBufferReader::TryRead(uint8_t* data, int64_t len) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // Use a rangemap to compute the diff in pinning. 240 // Use a rangemap to compute the diff in pinning.
238 IntervalMap<MultiBuffer::BlockId, int32_t> tmp; 241 IntervalMap<MultiBuffer::BlockId, int32_t> tmp;
239 tmp.IncrementInterval(pinned_range_.begin, pinned_range_.end, -1); 242 tmp.IncrementInterval(pinned_range_.begin, pinned_range_.end, -1);
240 tmp.IncrementInterval(begin, end, 1); 243 tmp.IncrementInterval(begin, end, 1);
241 multibuffer_->PinRanges(tmp); 244 multibuffer_->PinRanges(tmp);
242 pinned_range_.begin = begin; 245 pinned_range_.begin = begin;
243 pinned_range_.end = end; 246 pinned_range_.end = end;
244 } 247 }
245 248
246 } // namespace media 249 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698