| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 lru_->Use(this, pos); | 382 lru_->Use(this, pos); |
| 383 ++pos; | 383 ++pos; |
| 384 } | 384 } |
| 385 int64_t blocks_after = data_.size(); | 385 int64_t blocks_after = data_.size(); |
| 386 int64_t blocks_added = blocks_after - blocks_before; | 386 int64_t blocks_added = blocks_after - blocks_before; |
| 387 | 387 |
| 388 if (pos > start_pos) { | 388 if (pos > start_pos) { |
| 389 present_.SetInterval(start_pos, pos, 1); | 389 present_.SetInterval(start_pos, pos, 1); |
| 390 Interval<BlockId> expanded_range = present_.find(start_pos).interval(); | 390 Interval<BlockId> expanded_range = present_.find(start_pos).interval(); |
| 391 NotifyAvailableRange(expanded_range, expanded_range); | 391 NotifyAvailableRange(expanded_range, expanded_range); |
| 392 | |
| 393 lru_->IncrementDataSize(blocks_added); | 392 lru_->IncrementDataSize(blocks_added); |
| 394 Prune(blocks_added * kMaxFreesPerAdd + 1); | 393 Prune(blocks_added * kMaxFreesPerAdd + 1); |
| 394 } else { |
| 395 // Make sure to give progress reports even when there |
| 396 // aren't any new blocks yet. |
| 397 NotifyAvailableRange(Interval<BlockId>(start_pos, start_pos + 1), |
| 398 Interval<BlockId>(start_pos, start_pos)); |
| 395 } | 399 } |
| 396 | 400 |
| 397 // Check that it's still there before we try to delete it. | 401 // Check that it's still there before we try to delete it. |
| 398 // In case of EOF or a collision, we might not have called AddProvider above. | 402 // In case of EOF or a collision, we might not have called AddProvider above. |
| 399 // Even if we did call AddProvider, calling NotifyAvailableRange can cause | 403 // Even if we did call AddProvider, calling NotifyAvailableRange can cause |
| 400 // readers to seek or self-destruct and clean up any associated writers. | 404 // readers to seek or self-destruct and clean up any associated writers. |
| 401 auto i = writer_index_.find(pos); | 405 auto i = writer_index_.find(pos); |
| 402 if (i != writer_index_.end() && i->second.get() == provider_tmp) { | 406 if (i != writer_index_.end() && i->second.get() == provider_tmp) { |
| 403 switch (SuggestProviderState(pos)) { | 407 switch (SuggestProviderState(pos)) { |
| 404 case ProviderStateLoad: | 408 case ProviderStateLoad: |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 } | 515 } |
| 512 } | 516 } |
| 513 | 517 |
| 514 void MultiBuffer::IncrementMaxSize(int32_t size) { | 518 void MultiBuffer::IncrementMaxSize(int32_t size) { |
| 515 max_size_ += size; | 519 max_size_ += size; |
| 516 lru_->IncrementMaxSize(size); | 520 lru_->IncrementMaxSize(size); |
| 517 DCHECK_GE(max_size_, 0); | 521 DCHECK_GE(max_size_, 0); |
| 518 // Pruning only happens when blocks are added. | 522 // Pruning only happens when blocks are added. |
| 519 } | 523 } |
| 520 | 524 |
| 525 int64_t MultiBuffer::UncommittedBytesAt(const MultiBuffer::BlockId& block) { |
| 526 auto i = writer_index_.find(block); |
| 527 if (writer_index_.end() == i) |
| 528 return 0; |
| 529 return i->second->AvailableBytes(); |
| 530 } |
| 531 |
| 521 } // namespace media | 532 } // namespace media |
| OLD | NEW |