| 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 "media/blink/resource_multibuffer_data_provider.h" | 5 #include "media/blink/resource_multibuffer_data_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 bool ResourceMultiBufferDataProvider::Available() const { | 123 bool ResourceMultiBufferDataProvider::Available() const { |
| 124 if (fifo_.empty()) | 124 if (fifo_.empty()) |
| 125 return false; | 125 return false; |
| 126 if (fifo_.back()->end_of_stream()) | 126 if (fifo_.back()->end_of_stream()) |
| 127 return true; | 127 return true; |
| 128 if (fifo_.front()->data_size() == block_size()) | 128 if (fifo_.front()->data_size() == block_size()) |
| 129 return true; | 129 return true; |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 | 132 |
| 133 int64_t ResourceMultiBufferDataProvider::AvailableBytes() const { |
| 134 int64_t bytes = 0; |
| 135 for (const auto i : fifo_) { |
| 136 if (i->end_of_stream()) |
| 137 break; |
| 138 bytes += i->data_size(); |
| 139 } |
| 140 return bytes; |
| 141 } |
| 142 |
| 133 scoped_refptr<DataBuffer> ResourceMultiBufferDataProvider::Read() { | 143 scoped_refptr<DataBuffer> ResourceMultiBufferDataProvider::Read() { |
| 134 DCHECK(Available()); | 144 DCHECK(Available()); |
| 135 scoped_refptr<DataBuffer> ret = fifo_.front(); | 145 scoped_refptr<DataBuffer> ret = fifo_.front(); |
| 136 fifo_.pop_front(); | 146 fifo_.pop_front(); |
| 137 ++pos_; | 147 ++pos_; |
| 138 return ret; | 148 return ret; |
| 139 } | 149 } |
| 140 | 150 |
| 141 void ResourceMultiBufferDataProvider::SetDeferred(bool deferred) { | 151 void ResourceMultiBufferDataProvider::SetDeferred(bool deferred) { |
| 142 if (!active_loader_ || active_loader_->deferred() == deferred) | 152 if (!active_loader_ || active_loader_->deferred() == deferred) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 356 } |
| 347 int last_block_size = fifo_.back()->data_size(); | 357 int last_block_size = fifo_.back()->data_size(); |
| 348 int to_append = std::min<int>(data_length, block_size() - last_block_size); | 358 int to_append = std::min<int>(data_length, block_size() - last_block_size); |
| 349 DCHECK_GT(to_append, 0); | 359 DCHECK_GT(to_append, 0); |
| 350 memcpy(fifo_.back()->writable_data() + last_block_size, data, to_append); | 360 memcpy(fifo_.back()->writable_data() + last_block_size, data, to_append); |
| 351 data += to_append; | 361 data += to_append; |
| 352 fifo_.back()->set_data_size(last_block_size + to_append); | 362 fifo_.back()->set_data_size(last_block_size + to_append); |
| 353 data_length -= to_append; | 363 data_length -= to_append; |
| 354 } | 364 } |
| 355 | 365 |
| 356 if (Available()) | 366 url_data_->multibuffer()->OnDataProviderEvent(this); |
| 357 url_data_->multibuffer()->OnDataProviderEvent(this); | |
| 358 | 367 |
| 359 // Beware, this object might be deleted here. | 368 // Beware, this object might be deleted here. |
| 360 } | 369 } |
| 361 | 370 |
| 362 void ResourceMultiBufferDataProvider::didDownloadData(WebURLLoader* loader, | 371 void ResourceMultiBufferDataProvider::didDownloadData(WebURLLoader* loader, |
| 363 int dataLength, | 372 int dataLength, |
| 364 int encoded_data_length) { | 373 int encoded_data_length) { |
| 365 NOTIMPLEMENTED(); | 374 NOTIMPLEMENTED(); |
| 366 } | 375 } |
| 367 | 376 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 } | 520 } |
| 512 | 521 |
| 513 if (byte_pos() != first_byte_position) { | 522 if (byte_pos() != first_byte_position) { |
| 514 return false; | 523 return false; |
| 515 } | 524 } |
| 516 | 525 |
| 517 return true; | 526 return true; |
| 518 } | 527 } |
| 519 | 528 |
| 520 } // namespace media | 529 } // namespace media |
| OLD | NEW |