Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: webkit/media/buffered_data_source.cc

Issue 8661002: Fire CanPlayThrough immediately for local and streaming media files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix media/event-attributes.html Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 void BufferedDataSource::Initialize(const std::string& url, 98 void BufferedDataSource::Initialize(const std::string& url,
99 const media::PipelineStatusCB& callback) { 99 const media::PipelineStatusCB& callback) {
100 // Saves the url. 100 // Saves the url.
101 url_ = GURL(url); 101 url_ = GURL(url);
102 102
103 // This data source doesn't support data:// protocol so reject it. 103 // This data source doesn't support data:// protocol so reject it.
104 if (url_.SchemeIs(kDataScheme)) { 104 if (url_.SchemeIs(kDataScheme)) {
105 callback.Run(media::DATASOURCE_ERROR_URL_NOT_SUPPORTED); 105 callback.Run(media::DATASOURCE_ERROR_URL_NOT_SUPPORTED);
106 return; 106 return;
107 } 107 }
108 local_source_ = !url_.SchemeIs(kHttpScheme) && !url_.SchemeIs(kHttpsScheme);
108 109
109 DCHECK(!callback.is_null()); 110 DCHECK(!callback.is_null());
110 { 111 {
111 base::AutoLock auto_lock(lock_); 112 base::AutoLock auto_lock(lock_);
112 initialize_cb_ = callback; 113 initialize_cb_ = callback;
113 } 114 }
114 115
115 // Post a task to complete the initialization task. 116 // Post a task to complete the initialization task.
116 render_loop_->PostTask(FROM_HERE, 117 render_loop_->PostTask(FROM_HERE,
117 base::Bind(&BufferedDataSource::InitializeTask, this)); 118 base::Bind(&BufferedDataSource::InitializeTask, this));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 void BufferedDataSource::SetPreload(media::Preload preload) { 150 void BufferedDataSource::SetPreload(media::Preload preload) {
150 render_loop_->PostTask(FROM_HERE, base::Bind( 151 render_loop_->PostTask(FROM_HERE, base::Bind(
151 &BufferedDataSource::SetPreloadTask, this, preload)); 152 &BufferedDataSource::SetPreloadTask, this, preload));
152 } 153 }
153 154
154 void BufferedDataSource::SetBitrate(int bitrate) { 155 void BufferedDataSource::SetBitrate(int bitrate) {
155 render_loop_->PostTask(FROM_HERE, base::Bind( 156 render_loop_->PostTask(FROM_HERE, base::Bind(
156 &BufferedDataSource::SetBitrateTask, this, bitrate)); 157 &BufferedDataSource::SetBitrateTask, this, bitrate));
157 } 158 }
158 159
160 bool BufferedDataSource::IsLocalSource() {
161 return local_source_;
162 }
163
159 ///////////////////////////////////////////////////////////////////////////// 164 /////////////////////////////////////////////////////////////////////////////
160 // media::DataSource implementation. 165 // media::DataSource implementation.
161 void BufferedDataSource::Read( 166 void BufferedDataSource::Read(
162 int64 position, size_t size, uint8* data, 167 int64 position, size_t size, uint8* data,
163 const media::DataSource::ReadCallback& read_callback) { 168 const media::DataSource::ReadCallback& read_callback) {
164 VLOG(1) << "Read: " << position << " offset, " << size << " bytes"; 169 VLOG(1) << "Read: " << position << " offset, " << size << " bytes";
165 DCHECK(!read_callback.is_null()); 170 DCHECK(!read_callback.is_null());
166 171
167 { 172 {
168 base::AutoLock auto_lock(lock_); 173 base::AutoLock auto_lock(lock_);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 429 }
425 if (initialize_cb_is_null) { 430 if (initialize_cb_is_null) {
426 loader_->Stop(); 431 loader_->Stop();
427 return; 432 return;
428 } 433 }
429 434
430 if (success) { 435 if (success) {
431 // TODO(hclam): Needs more thinking about supporting servers without range 436 // TODO(hclam): Needs more thinking about supporting servers without range
432 // request or their partial response is not complete. 437 // request or their partial response is not complete.
433 total_bytes_ = instance_size; 438 total_bytes_ = instance_size;
434 loaded_ = false;
435 streaming_ = (instance_size == kPositionNotSpecified) || 439 streaming_ = (instance_size == kPositionNotSpecified) ||
436 !loader_->range_supported(); 440 !loader_->range_supported();
437 } else { 441 } else {
438 // TODO(hclam): In case of failure, we can retry several times. 442 // TODO(hclam): In case of failure, we can retry several times.
439 loader_->Stop(); 443 loader_->Stop();
440 } 444 }
441 445
442 if (error == net::ERR_INVALID_RESPONSE && using_range_request_) { 446 if (error == net::ERR_INVALID_RESPONSE && using_range_request_) {
443 // Assuming that the Range header was causing the problem. Retry without 447 // Assuming that the Range header was causing the problem. Retry without
444 // the Range header. 448 // the Range header.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 loader_->Stop(); 498 loader_->Stop();
495 return; 499 return;
496 } 500 }
497 501
498 int64 instance_size = loader_->instance_size(); 502 int64 instance_size = loader_->instance_size();
499 bool success = error == net::OK && instance_size != kPositionNotSpecified; 503 bool success = error == net::OK && instance_size != kPositionNotSpecified;
500 504
501 if (success) { 505 if (success) {
502 total_bytes_ = instance_size; 506 total_bytes_ = instance_size;
503 buffered_bytes_ = total_bytes_; 507 buffered_bytes_ = total_bytes_;
504 loaded_ = true;
505 } else { 508 } else {
506 loader_->Stop(); 509 loader_->Stop();
507 } 510 }
508 511
509 // Reference to prevent destruction while inside the |initialize_cb_| 512 // Reference to prevent destruction while inside the |initialize_cb_|
510 // call. This is a temporary fix to prevent crashes caused by holding the 513 // call. This is a temporary fix to prevent crashes caused by holding the
511 // lock and running the destructor. 514 // lock and running the destructor.
512 // TODO: Review locking in this class and figure out a way to run the callback 515 // TODO: Review locking in this class and figure out a way to run the callback
513 // w/o the lock. 516 // w/o the lock.
514 scoped_refptr<BufferedDataSource> destruction_guard(this); 517 scoped_refptr<BufferedDataSource> destruction_guard(this);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } 612 }
610 DoneRead_Locked(error); 613 DoneRead_Locked(error);
611 } 614 }
612 615
613 void BufferedDataSource::NetworkEventCallback() { 616 void BufferedDataSource::NetworkEventCallback() {
614 DCHECK(MessageLoop::current() == render_loop_); 617 DCHECK(MessageLoop::current() == render_loop_);
615 DCHECK(loader_.get()); 618 DCHECK(loader_.get());
616 619
617 // In case of non-HTTP request we don't need to report network events, 620 // In case of non-HTTP request we don't need to report network events,
618 // so return immediately. 621 // so return immediately.
619 if (loaded_) 622 if (local_source_)
620 return; 623 return;
621 624
622 bool is_downloading_data = loader_->is_downloading_data(); 625 bool is_downloading_data = loader_->is_downloading_data();
623 int64 buffered_position = loader_->GetBufferedPosition(); 626 int64 buffered_position = loader_->GetBufferedPosition();
624 627
625 // If we get an unspecified value, return immediately. 628 // If we get an unspecified value, return immediately.
626 if (buffered_position == kPositionNotSpecified) 629 if (buffered_position == kPositionNotSpecified)
627 return; 630 return;
628 631
629 // We need to prevent calling to filter host and running the callback if 632 // We need to prevent calling to filter host and running the callback if
(...skipping 20 matching lines...) Expand all
650 } 653 }
651 654
652 void BufferedDataSource::UpdateHostState_Locked() { 655 void BufferedDataSource::UpdateHostState_Locked() {
653 // Called from various threads, under lock. 656 // Called from various threads, under lock.
654 lock_.AssertAcquired(); 657 lock_.AssertAcquired();
655 658
656 media::FilterHost* filter_host = host(); 659 media::FilterHost* filter_host = host();
657 if (!filter_host) 660 if (!filter_host)
658 return; 661 return;
659 662
660 filter_host->SetLoaded(loaded_);
661
662 if (streaming_) 663 if (streaming_)
663 filter_host->SetStreaming(true); 664 filter_host->SetStreaming(true);
664 665
665 if (total_bytes_ != kPositionNotSpecified) 666 if (total_bytes_ != kPositionNotSpecified)
666 filter_host->SetTotalBytes(total_bytes_); 667 filter_host->SetTotalBytes(total_bytes_);
667 filter_host->SetBufferedBytes(buffered_bytes_); 668 filter_host->SetBufferedBytes(buffered_bytes_);
668 } 669 }
669 670
670 } // namespace webkit_media 671 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698