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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "media/blink/multibuffer.h" | 7 #include "media/blink/multibuffer.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 | 10 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 } | 108 } |
| 109 | 109 |
| 110 // | 110 // |
| 111 // MultiBuffer | 111 // MultiBuffer |
| 112 // | 112 // |
| 113 MultiBuffer::MultiBuffer(int32_t block_size_shift, | 113 MultiBuffer::MultiBuffer(int32_t block_size_shift, |
| 114 const scoped_refptr<GlobalLRU>& global_lru) | 114 const scoped_refptr<GlobalLRU>& global_lru) |
| 115 : max_size_(0), block_size_shift_(block_size_shift), lru_(global_lru) {} | 115 : max_size_(0), block_size_shift_(block_size_shift), lru_(global_lru) {} |
| 116 | 116 |
| 117 MultiBuffer::~MultiBuffer() { | 117 MultiBuffer::~MultiBuffer() { |
| 118 DCHECK(pinned_.empty()); | |
| 119 DCHECK_EQ(max_size_, 0); | |
| 118 // Remove all blocks from the LRU. | 120 // Remove all blocks from the LRU. |
| 119 for (const auto& i : data_) { | 121 for (const auto& i : data_) { |
| 120 lru_->Remove(this, i.first); | 122 if (!pinned_[i.first]) { |
|
liberato (no reviews please)
2016/03/02 21:45:46
since |pinned_.empty()| from the dcheck, how could
hubbe
2016/03/02 22:10:15
This is the "suspenders and belt" part.
*if* there
liberato (no reviews please)
2016/03/02 22:13:33
i see. worth a UMA?
hubbe
2016/03/02 22:22:54
Hopefully the DCHECK will be sufficient.
DaleCurtis
2016/03/03 00:12:22
We don't DCHECK things that we have checks for. S
hubbe
2016/03/03 01:10:10
Done.
| |
| 123 lru_->Remove(this, i.first); | |
| 124 } | |
| 121 } | 125 } |
| 122 lru_->IncrementDataSize(-static_cast<int64_t>(data_.size())); | 126 lru_->IncrementDataSize(-static_cast<int64_t>(data_.size())); |
| 123 lru_->IncrementMaxSize(-max_size_); | 127 lru_->IncrementMaxSize(-max_size_); |
| 124 } | 128 } |
| 125 | 129 |
| 126 void MultiBuffer::AddReader(const BlockId& pos, Reader* reader) { | 130 void MultiBuffer::AddReader(const BlockId& pos, Reader* reader) { |
| 127 std::set<Reader*>* set_of_readers = &readers_[pos]; | 131 std::set<Reader*>* set_of_readers = &readers_[pos]; |
| 128 bool already_waited_for = !set_of_readers->empty(); | 132 bool already_waited_for = !set_of_readers->empty(); |
| 129 set_of_readers->insert(reader); | 133 set_of_readers->insert(reader); |
| 130 | 134 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 break; | 376 break; |
| 373 case ProviderStateDead: | 377 case ProviderStateDead: |
| 374 RemoveProvider(provider_tmp); | 378 RemoveProvider(provider_tmp); |
| 375 break; | 379 break; |
| 376 } | 380 } |
| 377 } | 381 } |
| 378 } | 382 } |
| 379 | 383 |
| 380 void MultiBuffer::MergeFrom(MultiBuffer* other) { | 384 void MultiBuffer::MergeFrom(MultiBuffer* other) { |
| 381 // Import data and update LRU. | 385 // Import data and update LRU. |
| 386 size_t data_size = data_.size(); | |
| 382 for (const auto& data : other->data_) { | 387 for (const auto& data : other->data_) { |
| 383 if (data_.insert(std::make_pair(data.first, data.second)).second) { | 388 if (data_.insert(std::make_pair(data.first, data.second)).second) { |
| 384 if (!pinned_[data.first]) { | 389 if (!pinned_[data.first]) { |
| 385 lru_->Insert(this, data.first); | 390 lru_->Insert(this, data.first); |
| 386 } | 391 } |
| 387 } | 392 } |
| 388 } | 393 } |
| 394 lru_->IncrementDataSize(static_cast<int64_t>(data_.size() - data_size)); | |
|
DaleCurtis
2016/03/03 00:12:22
Should lru_->Insert() automatically increase the l
hubbe
2016/03/03 01:10:10
No, the data size includes pinned data.
| |
| 389 // Update present_ | 395 // Update present_ |
| 390 for (const auto& r : other->present_) { | 396 for (const auto& r : other->present_) { |
| 391 if (r.second) { | 397 if (r.second) { |
| 392 present_.SetInterval(r.first.begin, r.first.end, 1); | 398 present_.SetInterval(r.first.begin, r.first.end, 1); |
| 393 } | 399 } |
| 394 } | 400 } |
| 395 // Notify existing readers. | 401 // Notify existing readers. |
| 396 auto last = present_.begin(); | 402 auto last = present_.begin(); |
| 397 for (const auto& r : other->present_) { | 403 for (const auto& r : other->present_) { |
| 398 if (r.second) { | 404 if (r.second) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 417 // transitioned in or out of the unlocked state. If so, we iterate over | 423 // transitioned in or out of the unlocked state. If so, we iterate over |
| 418 // all buffers in that range and add/remove them from the LRU as approperiate. | 424 // all buffers in that range and add/remove them from the LRU as approperiate. |
| 419 // We iterate *backwards* through the ranges, with the idea that data in a | 425 // We iterate *backwards* through the ranges, with the idea that data in a |
| 420 // continous range should be freed from the end first. | 426 // continous range should be freed from the end first. |
| 421 | 427 |
| 422 if (data_.empty()) | 428 if (data_.empty()) |
| 423 return; | 429 return; |
| 424 | 430 |
| 425 auto range = pinned_.find(to - 1); | 431 auto range = pinned_.find(to - 1); |
| 426 while (1) { | 432 while (1) { |
| 433 DCHECK_GE(range.value(), 0); | |
| 427 if (range.value() == 0 || range.value() == how_much) { | 434 if (range.value() == 0 || range.value() == how_much) { |
| 428 bool pin = range.value() == how_much; | 435 bool pin = range.value() == how_much; |
| 429 Interval<BlockId> transition_range = | 436 Interval<BlockId> transition_range = |
| 430 modified_range.Intersect(range.interval()); | 437 modified_range.Intersect(range.interval()); |
| 431 if (transition_range.Empty()) | 438 if (transition_range.Empty()) |
| 432 break; | 439 break; |
| 433 | 440 |
| 434 // For each range that has transitioned to/from a pinned state, | 441 // For each range that has transitioned to/from a pinned state, |
| 435 // we iterate over the corresponding ranges in |present_| to find | 442 // we iterate over the corresponding ranges in |present_| to find |
| 436 // the blocks that are actually in the multibuffer. | 443 // the blocks that are actually in the multibuffer. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 } | 478 } |
| 472 | 479 |
| 473 void MultiBuffer::IncrementMaxSize(int32_t size) { | 480 void MultiBuffer::IncrementMaxSize(int32_t size) { |
| 474 max_size_ += size; | 481 max_size_ += size; |
| 475 lru_->IncrementMaxSize(size); | 482 lru_->IncrementMaxSize(size); |
| 476 DCHECK_GE(max_size_, 0); | 483 DCHECK_GE(max_size_, 0); |
| 477 // Pruning only happens when blocks are added. | 484 // Pruning only happens when blocks are added. |
| 478 } | 485 } |
| 479 | 486 |
| 480 } // namespace media | 487 } // namespace media |
| OLD | NEW |