| 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 NotifyAvailableRange(j.interval(), j.interval()); | 292 NotifyAvailableRange(j.interval(), j.interval()); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 if (data_.empty()) | 296 if (data_.empty()) |
| 297 OnEmpty(); | 297 OnEmpty(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void MultiBuffer::OnEmpty() {} | 300 void MultiBuffer::OnEmpty() {} |
| 301 | 301 |
| 302 void MultiBuffer::AddProvider(scoped_ptr<DataProvider> provider) { | 302 void MultiBuffer::AddProvider(std::unique_ptr<DataProvider> provider) { |
| 303 // If there is already a provider in the same location, we delete it. | 303 // If there is already a provider in the same location, we delete it. |
| 304 DCHECK(!provider->Available()); | 304 DCHECK(!provider->Available()); |
| 305 BlockId pos = provider->Tell(); | 305 BlockId pos = provider->Tell(); |
| 306 writer_index_[pos] = std::move(provider); | 306 writer_index_[pos] = std::move(provider); |
| 307 } | 307 } |
| 308 | 308 |
| 309 scoped_ptr<MultiBuffer::DataProvider> MultiBuffer::RemoveProvider( | 309 std::unique_ptr<MultiBuffer::DataProvider> MultiBuffer::RemoveProvider( |
| 310 DataProvider* provider) { | 310 DataProvider* provider) { |
| 311 BlockId pos = provider->Tell(); | 311 BlockId pos = provider->Tell(); |
| 312 auto iter = writer_index_.find(pos); | 312 auto iter = writer_index_.find(pos); |
| 313 DCHECK(iter != writer_index_.end()); | 313 DCHECK(iter != writer_index_.end()); |
| 314 DCHECK_EQ(iter->second.get(), provider); | 314 DCHECK_EQ(iter->second.get(), provider); |
| 315 scoped_ptr<DataProvider> ret = std::move(iter->second); | 315 std::unique_ptr<DataProvider> ret = std::move(iter->second); |
| 316 writer_index_.erase(iter); | 316 writer_index_.erase(iter); |
| 317 return ret; | 317 return ret; |
| 318 } | 318 } |
| 319 | 319 |
| 320 MultiBuffer::ProviderState MultiBuffer::SuggestProviderState( | 320 MultiBuffer::ProviderState MultiBuffer::SuggestProviderState( |
| 321 const BlockId& pos) const { | 321 const BlockId& pos) const { |
| 322 MultiBufferBlockId next_reader_pos = ClosestNextEntry(readers_, pos); | 322 MultiBufferBlockId next_reader_pos = ClosestNextEntry(readers_, pos); |
| 323 if (next_reader_pos != std::numeric_limits<MultiBufferBlockId>::max() && | 323 if (next_reader_pos != std::numeric_limits<MultiBufferBlockId>::max() && |
| 324 (next_reader_pos - pos <= kMaxWaitForWriterOffset || !RangeSupported())) { | 324 (next_reader_pos - pos <= kMaxWaitForWriterOffset || !RangeSupported())) { |
| 325 // Check if there is another writer between us and the next reader. | 325 // Check if there is another writer between us and the next reader. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 356 return true; | 356 return true; |
| 357 | 357 |
| 358 return false; | 358 return false; |
| 359 } | 359 } |
| 360 | 360 |
| 361 void MultiBuffer::Prune(size_t max_to_free) { | 361 void MultiBuffer::Prune(size_t max_to_free) { |
| 362 lru_->Prune(max_to_free); | 362 lru_->Prune(max_to_free); |
| 363 } | 363 } |
| 364 | 364 |
| 365 void MultiBuffer::OnDataProviderEvent(DataProvider* provider_tmp) { | 365 void MultiBuffer::OnDataProviderEvent(DataProvider* provider_tmp) { |
| 366 scoped_ptr<DataProvider> provider(RemoveProvider(provider_tmp)); | 366 std::unique_ptr<DataProvider> provider(RemoveProvider(provider_tmp)); |
| 367 BlockId start_pos = provider->Tell(); | 367 BlockId start_pos = provider->Tell(); |
| 368 BlockId pos = start_pos; | 368 BlockId pos = start_pos; |
| 369 bool eof = false; | 369 bool eof = false; |
| 370 int64_t blocks_before = data_.size(); | 370 int64_t blocks_before = data_.size(); |
| 371 | 371 |
| 372 while (!ProviderCollision(pos) && !eof) { | 372 while (!ProviderCollision(pos) && !eof) { |
| 373 if (!provider->Available()) { | 373 if (!provider->Available()) { |
| 374 AddProvider(std::move(provider)); | 374 AddProvider(std::move(provider)); |
| 375 break; | 375 break; |
| 376 } | 376 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 } | 512 } |
| 513 | 513 |
| 514 void MultiBuffer::IncrementMaxSize(int32_t size) { | 514 void MultiBuffer::IncrementMaxSize(int32_t size) { |
| 515 max_size_ += size; | 515 max_size_ += size; |
| 516 lru_->IncrementMaxSize(size); | 516 lru_->IncrementMaxSize(size); |
| 517 DCHECK_GE(max_size_, 0); | 517 DCHECK_GE(max_size_, 0); |
| 518 // Pruning only happens when blocks are added. | 518 // Pruning only happens when blocks are added. |
| 519 } | 519 } |
| 520 | 520 |
| 521 } // namespace media | 521 } // namespace media |
| OLD | NEW |