| 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 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 const BlockId& to, | 453 const BlockId& to, |
| 454 int32_t how_much) { | 454 int32_t how_much) { |
| 455 DCHECK_NE(how_much, 0); | 455 DCHECK_NE(how_much, 0); |
| 456 DVLOG(3) << "PINRANGE [" << from << " - " << to << ") += " << how_much; | 456 DVLOG(3) << "PINRANGE [" << from << " - " << to << ") += " << how_much; |
| 457 pinned_.IncrementInterval(from, to, how_much); | 457 pinned_.IncrementInterval(from, to, how_much); |
| 458 Interval<BlockId> modified_range(from, to); | 458 Interval<BlockId> modified_range(from, to); |
| 459 | 459 |
| 460 // Iterate over all the modified ranges and check if any of them have | 460 // Iterate over all the modified ranges and check if any of them have |
| 461 // transitioned in or out of the unlocked state. If so, we iterate over | 461 // transitioned in or out of the unlocked state. If so, we iterate over |
| 462 // all buffers in that range and add/remove them from the LRU as approperiate. | 462 // all buffers in that range and add/remove them from the LRU as approperiate. |
| 463 // We iterate *backwards* through the ranges, with the idea that data in a | |
| 464 // continous range should be freed from the end first. | |
| 465 | 463 |
| 466 if (data_.empty()) | 464 if (data_.empty()) |
| 467 return; | 465 return; |
| 468 | 466 |
| 469 auto range = pinned_.find(to - 1); | 467 auto range = pinned_.find(to - 1); |
| 470 while (1) { | 468 while (1) { |
| 471 DCHECK_GE(range.value(), 0); | 469 DCHECK_GE(range.value(), 0); |
| 472 if (range.value() == 0 || range.value() == how_much) { | 470 if (range.value() == 0 || range.value() == how_much) { |
| 473 bool pin = range.value() == how_much; | 471 bool pin = range.value() == how_much; |
| 474 Interval<BlockId> transition_range = | 472 Interval<BlockId> transition_range = |
| 475 modified_range.Intersect(range.interval()); | 473 modified_range.Intersect(range.interval()); |
| 476 if (transition_range.Empty()) | 474 if (transition_range.Empty()) |
| 477 break; | 475 break; |
| 478 | 476 |
| 479 // For each range that has transitioned to/from a pinned state, | 477 // For each range that has transitioned to/from a pinned state, |
| 480 // we iterate over the corresponding ranges in |present_| to find | 478 // we iterate over the corresponding ranges in |present_| to find |
| 481 // the blocks that are actually in the multibuffer. | 479 // the blocks that are actually in the multibuffer. |
| 482 for (auto present_block_range = present_.find(transition_range.end - 1); | 480 for (auto present_block_range = present_.find(transition_range.begin); |
| 483 present_block_range != present_.begin(); --present_block_range) { | 481 present_block_range != present_.end(); ++present_block_range) { |
| 484 if (!present_block_range.value()) | 482 if (!present_block_range.value()) |
| 485 continue; | 483 continue; |
| 486 Interval<BlockId> present_transitioned_range = | 484 Interval<BlockId> present_transitioned_range = |
| 487 transition_range.Intersect(present_block_range.interval()); | 485 transition_range.Intersect(present_block_range.interval()); |
| 488 if (present_transitioned_range.Empty()) | 486 if (present_transitioned_range.Empty()) |
| 489 break; | 487 break; |
| 490 for (BlockId block = present_transitioned_range.end - 1; | 488 for (BlockId block = present_transitioned_range.begin; |
| 491 block >= present_transitioned_range.begin; --block) { | 489 block < present_transitioned_range.end; ++block) { |
| 492 DCHECK_GE(block, 0); | 490 DCHECK_GE(block, 0); |
| 493 DCHECK(data_.find(block) != data_.end()); | 491 DCHECK(data_.find(block) != data_.end()); |
| 494 if (pin) { | 492 if (pin) { |
| 495 DCHECK(pinned_[block]); | 493 DCHECK(pinned_[block]); |
| 496 lru_->Remove(this, block); | 494 lru_->Remove(this, block); |
| 497 } else { | 495 } else { |
| 498 DCHECK(!pinned_[block]); | 496 DCHECK(!pinned_[block]); |
| 499 lru_->Insert(this, block); | 497 lru_->Insert(this, block); |
| 500 } | 498 } |
| 501 } | 499 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 523 } | 521 } |
| 524 | 522 |
| 525 int64_t MultiBuffer::UncommittedBytesAt(const MultiBuffer::BlockId& block) { | 523 int64_t MultiBuffer::UncommittedBytesAt(const MultiBuffer::BlockId& block) { |
| 526 auto i = writer_index_.find(block); | 524 auto i = writer_index_.find(block); |
| 527 if (writer_index_.end() == i) | 525 if (writer_index_.end() == i) |
| 528 return 0; | 526 return 0; |
| 529 return i->second->AvailableBytes(); | 527 return i->second->AvailableBytes(); |
| 530 } | 528 } |
| 531 | 529 |
| 532 } // namespace media | 530 } // namespace media |
| OLD | NEW |