OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/media/buffered_data_source.h" | 5 #include "webkit/media/buffered_data_source.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "media/base/filter_host.h" | 8 #include "media/base/filter_host.h" |
9 #include "media/base/media_log.h" | 9 #include "media/base/media_log.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 return new WebDataSourceFactory(render_loop, frame, media_log, | 38 return new WebDataSourceFactory(render_loop, frame, media_log, |
39 &NewBufferedDataSource, build_observer); | 39 &NewBufferedDataSource, build_observer); |
40 } | 40 } |
41 | 41 |
42 BufferedDataSource::BufferedDataSource( | 42 BufferedDataSource::BufferedDataSource( |
43 MessageLoop* render_loop, | 43 MessageLoop* render_loop, |
44 WebFrame* frame, | 44 WebFrame* frame, |
45 media::MediaLog* media_log) | 45 media::MediaLog* media_log) |
46 : total_bytes_(kPositionNotSpecified), | 46 : total_bytes_(kPositionNotSpecified), |
47 buffered_bytes_(0), | 47 buffered_bytes_(0), |
48 loaded_(false), | |
49 streaming_(false), | 48 streaming_(false), |
50 frame_(frame), | 49 frame_(frame), |
51 loader_(NULL), | 50 loader_(NULL), |
52 is_downloading_data_(false), | 51 is_downloading_data_(false), |
53 read_position_(0), | 52 read_position_(0), |
54 read_size_(0), | 53 read_size_(0), |
55 read_buffer_(NULL), | 54 read_buffer_(NULL), |
56 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), | 55 intermediate_read_buffer_(new uint8[kInitialReadBufferSize]), |
57 intermediate_read_buffer_size_(kInitialReadBufferSize), | 56 intermediate_read_buffer_size_(kInitialReadBufferSize), |
58 render_loop_(render_loop), | 57 render_loop_(render_loop), |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 } | 423 } |
425 if (initialize_cb_is_null) { | 424 if (initialize_cb_is_null) { |
426 loader_->Stop(); | 425 loader_->Stop(); |
427 return; | 426 return; |
428 } | 427 } |
429 | 428 |
430 if (success) { | 429 if (success) { |
431 // TODO(hclam): Needs more thinking about supporting servers without range | 430 // TODO(hclam): Needs more thinking about supporting servers without range |
432 // request or their partial response is not complete. | 431 // request or their partial response is not complete. |
433 total_bytes_ = instance_size; | 432 total_bytes_ = instance_size; |
434 loaded_ = false; | |
435 streaming_ = (instance_size == kPositionNotSpecified) || | 433 streaming_ = (instance_size == kPositionNotSpecified) || |
436 !loader_->range_supported(); | 434 !loader_->range_supported(); |
437 } else { | 435 } else { |
438 // TODO(hclam): In case of failure, we can retry several times. | 436 // TODO(hclam): In case of failure, we can retry several times. |
439 loader_->Stop(); | 437 loader_->Stop(); |
440 } | 438 } |
441 | 439 |
442 if (error == net::ERR_INVALID_RESPONSE && using_range_request_) { | 440 if (error == net::ERR_INVALID_RESPONSE && using_range_request_) { |
443 // Assuming that the Range header was causing the problem. Retry without | 441 // Assuming that the Range header was causing the problem. Retry without |
444 // the Range header. | 442 // the Range header. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 loader_->Stop(); | 492 loader_->Stop(); |
495 return; | 493 return; |
496 } | 494 } |
497 | 495 |
498 int64 instance_size = loader_->instance_size(); | 496 int64 instance_size = loader_->instance_size(); |
499 bool success = error == net::OK && instance_size != kPositionNotSpecified; | 497 bool success = error == net::OK && instance_size != kPositionNotSpecified; |
500 | 498 |
501 if (success) { | 499 if (success) { |
502 total_bytes_ = instance_size; | 500 total_bytes_ = instance_size; |
503 buffered_bytes_ = total_bytes_; | 501 buffered_bytes_ = total_bytes_; |
504 loaded_ = true; | |
505 } else { | 502 } else { |
506 loader_->Stop(); | 503 loader_->Stop(); |
507 } | 504 } |
508 | 505 |
509 // Reference to prevent destruction while inside the |initialize_cb_| | 506 // Reference to prevent destruction while inside the |initialize_cb_| |
510 // call. This is a temporary fix to prevent crashes caused by holding the | 507 // call. This is a temporary fix to prevent crashes caused by holding the |
511 // lock and running the destructor. | 508 // lock and running the destructor. |
512 // TODO: Review locking in this class and figure out a way to run the callback | 509 // TODO: Review locking in this class and figure out a way to run the callback |
513 // w/o the lock. | 510 // w/o the lock. |
514 scoped_refptr<BufferedDataSource> destruction_guard(this); | 511 scoped_refptr<BufferedDataSource> destruction_guard(this); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 } | 606 } |
610 DoneRead_Locked(error); | 607 DoneRead_Locked(error); |
611 } | 608 } |
612 | 609 |
613 void BufferedDataSource::NetworkEventCallback() { | 610 void BufferedDataSource::NetworkEventCallback() { |
614 DCHECK(MessageLoop::current() == render_loop_); | 611 DCHECK(MessageLoop::current() == render_loop_); |
615 DCHECK(loader_.get()); | 612 DCHECK(loader_.get()); |
616 | 613 |
617 // In case of non-HTTP request we don't need to report network events, | 614 // In case of non-HTTP request we don't need to report network events, |
618 // so return immediately. | 615 // so return immediately. |
619 if (loaded_) | 616 if (!url_.SchemeIs(kHttpScheme) && !url_.SchemeIs(kHttpsScheme)) |
620 return; | 617 return; |
621 | 618 |
622 bool is_downloading_data = loader_->is_downloading_data(); | 619 bool is_downloading_data = loader_->is_downloading_data(); |
623 int64 buffered_position = loader_->GetBufferedPosition(); | 620 int64 buffered_position = loader_->GetBufferedPosition(); |
624 | 621 |
625 // If we get an unspecified value, return immediately. | 622 // If we get an unspecified value, return immediately. |
626 if (buffered_position == kPositionNotSpecified) | 623 if (buffered_position == kPositionNotSpecified) |
627 return; | 624 return; |
628 | 625 |
629 // We need to prevent calling to filter host and running the callback if | 626 // We need to prevent calling to filter host and running the callback if |
(...skipping 20 matching lines...) Expand all Loading... |
650 } | 647 } |
651 | 648 |
652 void BufferedDataSource::UpdateHostState_Locked() { | 649 void BufferedDataSource::UpdateHostState_Locked() { |
653 // Called from various threads, under lock. | 650 // Called from various threads, under lock. |
654 lock_.AssertAcquired(); | 651 lock_.AssertAcquired(); |
655 | 652 |
656 media::FilterHost* filter_host = host(); | 653 media::FilterHost* filter_host = host(); |
657 if (!filter_host) | 654 if (!filter_host) |
658 return; | 655 return; |
659 | 656 |
660 filter_host->SetLoaded(loaded_); | |
661 | |
662 if (streaming_) | |
663 filter_host->SetStreaming(true); | |
664 | |
665 if (total_bytes_ != kPositionNotSpecified) | 657 if (total_bytes_ != kPositionNotSpecified) |
666 filter_host->SetTotalBytes(total_bytes_); | 658 filter_host->SetTotalBytes(total_bytes_); |
667 filter_host->SetBufferedBytes(buffered_bytes_); | 659 filter_host->SetBufferedBytes(buffered_bytes_); |
668 } | 660 } |
669 | 661 |
670 } // namespace webkit_media | 662 } // namespace webkit_media |
OLD | NEW |