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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 DCHECK_GE(pos, 0); | 65 DCHECK_GE(pos, 0); |
66 } | 66 } |
67 | 67 |
68 void ResourceMultiBufferDataProvider::Start() { | 68 void ResourceMultiBufferDataProvider::Start() { |
69 // Prepare the request. | 69 // Prepare the request. |
70 WebURLRequest request(url_data_->url()); | 70 WebURLRequest request(url_data_->url()); |
71 // TODO(mkwst): Split this into video/audio. | 71 // TODO(mkwst): Split this into video/audio. |
72 request.setRequestContext(WebURLRequest::RequestContextVideo); | 72 request.setRequestContext(WebURLRequest::RequestContextVideo); |
73 | 73 |
74 DVLOG(1) << __FUNCTION__ << " @ " << byte_pos(); | 74 DVLOG(1) << __FUNCTION__ << " @ " << byte_pos(); |
75 if (url_data_->length() > 0) { | 75 if (url_data_->length() > 0 && byte_pos() >= url_data_->length()) { |
76 DCHECK_LT(byte_pos(), url_data_->length()) << " " << url_data_->url(); | 76 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 77 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Terminate, |
| 78 weak_factory_.GetWeakPtr())); |
| 79 return; |
77 } | 80 } |
78 | 81 |
79 request.setHTTPHeaderField( | 82 request.setHTTPHeaderField( |
80 WebString::fromUTF8(net::HttpRequestHeaders::kRange), | 83 WebString::fromUTF8(net::HttpRequestHeaders::kRange), |
81 WebString::fromUTF8( | 84 WebString::fromUTF8( |
82 net::HttpByteRange::RightUnbounded(byte_pos()).GetHeaderValue())); | 85 net::HttpByteRange::RightUnbounded(byte_pos()).GetHeaderValue())); |
83 | 86 |
84 url_data_->frame()->setReferrerForRequest(request, blink::WebURL()); | 87 url_data_->frame()->setReferrerForRequest(request, blink::WebURL()); |
85 | 88 |
86 // Disable compression, compression for audio/video doesn't make sense... | 89 // Disable compression, compression for audio/video doesn't make sense... |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 int64_t total_encoded_data_length) { | 399 int64_t total_encoded_data_length) { |
397 DVLOG(1) << "didFinishLoading"; | 400 DVLOG(1) << "didFinishLoading"; |
398 DCHECK(active_loader_.get()); | 401 DCHECK(active_loader_.get()); |
399 DCHECK(!Available()); | 402 DCHECK(!Available()); |
400 | 403 |
401 // We're done with the loader. | 404 // We're done with the loader. |
402 active_loader_.reset(); | 405 active_loader_.reset(); |
403 | 406 |
404 // If we didn't know the |instance_size_| we do now. | 407 // If we didn't know the |instance_size_| we do now. |
405 int64_t size = byte_pos(); | 408 int64_t size = byte_pos(); |
406 if (!fifo_.empty()) | |
407 size += fifo_.back()->data_size(); | |
408 | 409 |
409 // This request reports something smaller than what we've seen in the past, | 410 // This request reports something smaller than what we've seen in the past, |
410 // Maybe it's transient error? | 411 // Maybe it's transient error? |
411 if (url_data_->length() != kPositionNotSpecified && | 412 if (url_data_->length() != kPositionNotSpecified && |
412 size < url_data_->length()) { | 413 size < url_data_->length()) { |
413 if (retries_ < kMaxRetries) { | 414 if (retries_ < kMaxRetries) { |
414 DVLOG(1) << " Partial data received.... @ pos = " << size; | 415 DVLOG(1) << " Partial data received.... @ pos = " << size; |
415 retries_++; | 416 retries_++; |
416 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 417 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
417 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, | 418 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 } | 495 } |
495 if (*last_byte_position < *first_byte_position || | 496 if (*last_byte_position < *first_byte_position || |
496 (*instance_size != kPositionNotSpecified && | 497 (*instance_size != kPositionNotSpecified && |
497 *last_byte_position >= *instance_size)) { | 498 *last_byte_position >= *instance_size)) { |
498 return false; | 499 return false; |
499 } | 500 } |
500 | 501 |
501 return true; | 502 return true; |
502 } | 503 } |
503 | 504 |
| 505 void ResourceMultiBufferDataProvider::Terminate() { |
| 506 fifo_.push_back(DataBuffer::CreateEOSBuffer()); |
| 507 url_data_->multibuffer()->OnDataProviderEvent(this); |
| 508 } |
| 509 |
504 int64_t ResourceMultiBufferDataProvider::byte_pos() const { | 510 int64_t ResourceMultiBufferDataProvider::byte_pos() const { |
505 int64_t ret = pos_; | 511 int64_t ret = pos_; |
506 ret += fifo_.size(); | 512 ret += fifo_.size(); |
507 ret = ret << url_data_->multibuffer()->block_size_shift(); | 513 ret = ret << url_data_->multibuffer()->block_size_shift(); |
508 if (!fifo_.empty()) { | 514 if (!fifo_.empty()) { |
509 ret += fifo_.back()->data_size() - block_size(); | 515 ret += fifo_.back()->data_size() - block_size(); |
510 } | 516 } |
511 return ret; | 517 return ret; |
512 } | 518 } |
513 | 519 |
(...skipping 17 matching lines...) Expand all Loading... |
531 } | 537 } |
532 | 538 |
533 if (byte_pos() != first_byte_position) { | 539 if (byte_pos() != first_byte_position) { |
534 return false; | 540 return false; |
535 } | 541 } |
536 | 542 |
537 return true; | 543 return true; |
538 } | 544 } |
539 | 545 |
540 } // namespace media | 546 } // namespace media |
OLD | NEW |