Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 pinned_range_(0, 0), | |
| 27 pos_(start), | 28 pos_(start), |
| 28 preload_pos_(-1), | 29 preload_pos_(-1), |
| 29 loading_(true), | 30 loading_(true), |
| 30 current_wait_size_(0), | 31 current_wait_size_(0), |
| 31 progress_callback_(progress_callback), | 32 progress_callback_(progress_callback), |
| 32 weak_factory_(this) { | 33 weak_factory_(this) { |
| 33 DCHECK_GE(start, 0); | 34 DCHECK_GE(start, 0); |
| 34 DCHECK_GE(end_, 0); | 35 DCHECK_GE(end_, 0); |
| 35 } | 36 } |
| 36 | 37 |
| 37 MultiBufferReader::~MultiBufferReader() { | 38 MultiBufferReader::~MultiBufferReader() { |
| 39 PinRange(0, 0); | |
| 38 multibuffer_->RemoveReader(preload_pos_, this); | 40 multibuffer_->RemoveReader(preload_pos_, this); |
| 39 multibuffer_->IncrementMaxSize( | 41 multibuffer_->IncrementMaxSize( |
| 40 -block_ceil(max_buffer_forward_ + max_buffer_backward_)); | 42 -block_ceil(max_buffer_forward_ + max_buffer_backward_)); |
| 41 multibuffer_->PinRange(block(pos_ - max_buffer_backward_), | |
| 42 block_ceil(pos_ + max_buffer_forward_), -1); | |
| 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 // Use a rangemap to compute the diff in pinning. | 50 PinRange(block(pos - max_buffer_backward_), |
| 51 IntervalMap<MultiBuffer::BlockId, int32_t> tmp; | 51 block_ceil(pos + max_buffer_forward_)); |
| 52 tmp.IncrementInterval(block(pos_ - max_buffer_backward_), | |
|
liberato (no reviews please)
2016/03/02 21:45:46
x -= y;
x += y;
// success! :)
hubbe
2016/03/02 22:10:15
que?
liberato (no reviews please)
2016/03/02 22:13:33
|pos_| vs |pos| . maybe time for me to increase t
hubbe
2016/03/02 22:22:54
Acknowledged.
| |
| 53 block_ceil(pos_ + max_buffer_forward_), -1); | |
| 54 tmp.IncrementInterval(block(pos - max_buffer_backward_), | |
| 55 block_ceil(pos + max_buffer_forward_), 1); | |
| 56 | |
| 57 multibuffer_->PinRanges(tmp); | |
| 58 | 52 |
| 59 multibuffer_->RemoveReader(preload_pos_, this); | 53 multibuffer_->RemoveReader(preload_pos_, this); |
| 60 MultiBufferBlockId old_preload_pos = preload_pos_; | 54 MultiBufferBlockId old_preload_pos = preload_pos_; |
| 61 preload_pos_ = block(pos); | 55 preload_pos_ = block(pos); |
| 62 pos_ = pos; | 56 pos_ = pos; |
| 63 UpdateInternalState(); | 57 UpdateInternalState(); |
| 64 multibuffer_->CleanupWriters(old_preload_pos); | 58 multibuffer_->CleanupWriters(old_preload_pos); |
| 65 } | 59 } |
| 66 | 60 |
| 67 void MultiBufferReader::SetMaxBuffer(int64_t backward, int64_t forward) { | 61 void MultiBufferReader::SetMaxBuffer(int64_t backward, int64_t forward) { |
| 68 // 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. |
| 69 multibuffer_->IncrementMaxSize( | 63 multibuffer_->IncrementMaxSize( |
| 70 -block_ceil(max_buffer_forward_ + max_buffer_backward_)); | 64 -block_ceil(max_buffer_forward_ + max_buffer_backward_)); |
| 71 // Use a rangemap to compute the diff in pinning. | |
| 72 IntervalMap<MultiBuffer::BlockId, int32_t> tmp; | |
| 73 tmp.IncrementInterval(block(pos_ - max_buffer_backward_), | |
| 74 block_ceil(pos_ + max_buffer_forward_), -1); | |
| 75 max_buffer_backward_ = backward; | 65 max_buffer_backward_ = backward; |
| 76 max_buffer_forward_ = forward; | 66 max_buffer_forward_ = forward; |
| 77 tmp.IncrementInterval(block(pos_ - max_buffer_backward_), | 67 PinRange(block(pos_ - max_buffer_backward_), |
| 78 block_ceil(pos_ + max_buffer_forward_), 1); | 68 block_ceil(pos_ + max_buffer_forward_)); |
| 79 multibuffer_->PinRanges(tmp); | |
| 80 | 69 |
| 81 multibuffer_->IncrementMaxSize( | 70 multibuffer_->IncrementMaxSize( |
| 82 block_ceil(max_buffer_forward_ + max_buffer_backward_)); | 71 block_ceil(max_buffer_forward_ + max_buffer_backward_)); |
| 83 } | 72 } |
| 84 | 73 |
| 85 int64_t MultiBufferReader::Available() const { | 74 int64_t MultiBufferReader::Available() const { |
| 86 int64_t unavailable_byte_pos = | 75 int64_t unavailable_byte_pos = |
| 87 static_cast<int64_t>(multibuffer_->FindNextUnavailable(block(pos_))) | 76 static_cast<int64_t>(multibuffer_->FindNextUnavailable(block(pos_))) |
| 88 << multibuffer_->block_size_shift(); | 77 << multibuffer_->block_size_shift(); |
| 89 return std::max<int64_t>(0, unavailable_byte_pos - pos_); | 78 return std::max<int64_t>(0, unavailable_byte_pos - pos_); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 loading_ = true; | 225 loading_ = true; |
| 237 multibuffer_->AddReader(preload_pos_, this); | 226 multibuffer_->AddReader(preload_pos_, this); |
| 238 } else if (multibuffer_->Contains(preload_pos_ - 1)) { | 227 } else if (multibuffer_->Contains(preload_pos_ - 1)) { |
| 239 --preload_pos_; | 228 --preload_pos_; |
| 240 multibuffer_->AddReader(preload_pos_, this); | 229 multibuffer_->AddReader(preload_pos_, this); |
| 241 } | 230 } |
| 242 } | 231 } |
| 243 CheckWait(); | 232 CheckWait(); |
| 244 } | 233 } |
| 245 | 234 |
| 235 void MultiBufferReader::PinRange(MultiBuffer::BlockId begin, | |
| 236 MultiBuffer::BlockId end) { | |
| 237 // Use a rangemap to compute the diff in pinning. | |
| 238 IntervalMap<MultiBuffer::BlockId, int32_t> tmp; | |
| 239 tmp.IncrementInterval(pinned_range_.begin, pinned_range_.end, -1); | |
| 240 tmp.IncrementInterval(begin, end, 1); | |
| 241 multibuffer_->PinRanges(tmp); | |
| 242 pinned_range_.begin = begin; | |
| 243 pinned_range_.end = end; | |
| 244 } | |
| 245 | |
| 246 } // namespace media | 246 } // namespace media |
| OLD | NEW |