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