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

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

Issue 8399023: Fire canplaythrough event at the proper time for audio/video (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month 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
« no previous file with comments | « webkit/media/webmediaplayer_impl.h ('k') | webkit/media/webmediaplayer_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/webmediaplayer_impl.h" 5 #include "webkit/media/webmediaplayer_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 24 matching lines...) Expand all
35 #include "webkit/media/simple_data_source.h" 35 #include "webkit/media/simple_data_source.h"
36 #include "webkit/media/video_renderer_impl.h" 36 #include "webkit/media/video_renderer_impl.h"
37 #include "webkit/media/web_video_renderer.h" 37 #include "webkit/media/web_video_renderer.h"
38 #include "webkit/media/webmediaplayer_delegate.h" 38 #include "webkit/media/webmediaplayer_delegate.h"
39 #include "webkit/media/webmediaplayer_proxy.h" 39 #include "webkit/media/webmediaplayer_proxy.h"
40 #include "webkit/media/webvideoframe_impl.h" 40 #include "webkit/media/webvideoframe_impl.h"
41 41
42 using WebKit::WebCanvas; 42 using WebKit::WebCanvas;
43 using WebKit::WebRect; 43 using WebKit::WebRect;
44 using WebKit::WebSize; 44 using WebKit::WebSize;
45 using media::NetworkEvent;
45 using media::PipelineStatus; 46 using media::PipelineStatus;
46 47
47 namespace { 48 namespace {
48 49
49 // Amount of extra memory used by each player instance reported to V8. 50 // Amount of extra memory used by each player instance reported to V8.
50 // It is not exact number -- first, it differs on different platforms, 51 // It is not exact number -- first, it differs on different platforms,
51 // and second, it is very hard to calculate. Instead, use some arbitrary 52 // and second, it is very hard to calculate. Instead, use some arbitrary
52 // value that will cause garbage collection from time to time. We don't want 53 // value that will cause garbage collection from time to time. We don't want
53 // it to happen on every allocation, but don't want 5k players to sit in memory 54 // it to happen on every allocation, but don't want 5k players to sit in memory
54 // either. Looks that chosen constant achieves both goals, at least for audio 55 // either. Looks that chosen constant achieves both goals, at least for audio
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 pending_seek_ = true; 371 pending_seek_ = true;
371 pending_seek_seconds_ = seconds; 372 pending_seek_seconds_ = seconds;
372 return; 373 return;
373 } 374 }
374 375
375 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds)); 376 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds));
376 377
377 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); 378 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds);
378 379
379 // Update our paused time. 380 // Update our paused time.
380 if (paused_) { 381 if (paused_)
381 paused_time_ = seek_time; 382 paused_time_ = seek_time;
382 }
383 383
384 seeking_ = true; 384 seeking_ = true;
385 385
386 proxy_->DemuxerFlush(); 386 proxy_->DemuxerFlush();
387 387
388 // Kick off the asynchronous seek! 388 // Kick off the asynchronous seek!
389 pipeline_->Seek( 389 pipeline_->Seek(
390 seek_time, 390 seek_time,
391 base::Bind(&WebMediaPlayerProxy::PipelineSeekCallback, 391 base::Bind(&WebMediaPlayerProxy::PipelineSeekCallback,
392 proxy_.get())); 392 proxy_.get()));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 DCHECK_EQ(main_loop_, MessageLoop::current()); 493 DCHECK_EQ(main_loop_, MessageLoop::current());
494 494
495 base::TimeDelta duration = pipeline_->GetMediaDuration(); 495 base::TimeDelta duration = pipeline_->GetMediaDuration();
496 if (duration.InMicroseconds() == media::Limits::kMaxTimeInMicroseconds) 496 if (duration.InMicroseconds() == media::Limits::kMaxTimeInMicroseconds)
497 return std::numeric_limits<float>::infinity(); 497 return std::numeric_limits<float>::infinity();
498 return static_cast<float>(duration.InSecondsF()); 498 return static_cast<float>(duration.InSecondsF());
499 } 499 }
500 500
501 float WebMediaPlayerImpl::currentTime() const { 501 float WebMediaPlayerImpl::currentTime() const {
502 DCHECK_EQ(main_loop_, MessageLoop::current()); 502 DCHECK_EQ(main_loop_, MessageLoop::current());
503 if (paused_) { 503 if (paused_)
504 return static_cast<float>(paused_time_.InSecondsF()); 504 return static_cast<float>(paused_time_.InSecondsF());
505 }
506 return static_cast<float>(pipeline_->GetCurrentTime().InSecondsF()); 505 return static_cast<float>(pipeline_->GetCurrentTime().InSecondsF());
507 } 506 }
508 507
509 int WebMediaPlayerImpl::dataRate() const { 508 int WebMediaPlayerImpl::dataRate() const {
510 DCHECK_EQ(main_loop_, MessageLoop::current()); 509 DCHECK_EQ(main_loop_, MessageLoop::current());
511 510
512 // TODO(hclam): Add this method call if pipeline has it in the interface. 511 // TODO(hclam): Add this method call if pipeline has it in the interface.
513 return 0; 512 return 0;
514 } 513 }
515 514
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 new_buffered[0].start = 0.0f; 740 new_buffered[0].start = 0.0f;
742 new_buffered[0].end = 741 new_buffered[0].end =
743 static_cast<float>(pipeline_->GetMediaDuration().InSecondsF()); 742 static_cast<float>(pipeline_->GetMediaDuration().InSecondsF());
744 buffered_.swap(new_buffered); 743 buffered_.swap(new_buffered);
745 744
746 if (hasVideo()) { 745 if (hasVideo()) {
747 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", 746 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive",
748 is_accelerated_compositing_active_); 747 is_accelerated_compositing_active_);
749 } 748 }
750 749
751 if (pipeline_->IsLoaded()) { 750 if (pipeline_->IsLoaded())
752 SetNetworkState(WebKit::WebMediaPlayer::Loaded); 751 SetNetworkState(WebKit::WebMediaPlayer::Loaded);
753 }
754 752
755 // Since we have initialized the pipeline, say we have everything otherwise
756 // we'll remain either loading/idle.
757 // TODO(hclam): change this to report the correct status.
758 SetReadyState(WebKit::WebMediaPlayer::HaveMetadata); 753 SetReadyState(WebKit::WebMediaPlayer::HaveMetadata);
759 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData); 754 SetReadyState(WebKit::WebMediaPlayer::HaveFutureData);
760 } else { 755 } else {
761 // TODO(hclam): should use |status| to determine the state 756 // TODO(hclam): should use |status| to determine the state
762 // properly and reports error using MediaError. 757 // properly and reports error using MediaError.
763 // WebKit uses FormatError to indicate an error for bogus URL or bad file. 758 // WebKit uses FormatError to indicate an error for bogus URL or bad file.
764 // Since we are at the initialization stage we can safely treat every error 759 // Since we are at the initialization stage we can safely treat every error
765 // as format error. Should post a task to call to |webmediaplayer_|. 760 // as format error. Should post a task to call to |webmediaplayer_|.
766 SetNetworkState(WebKit::WebMediaPlayer::FormatError); 761 SetNetworkState(WebKit::WebMediaPlayer::FormatError);
767 } 762 }
768 763
769 // Repaint to trigger UI update. 764 // Repaint to trigger UI update.
770 Repaint(); 765 Repaint();
771 } 766 }
772 767
773 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) { 768 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) {
774 DCHECK_EQ(main_loop_, MessageLoop::current()); 769 DCHECK_EQ(main_loop_, MessageLoop::current());
775 seeking_ = false; 770 seeking_ = false;
776 if (pending_seek_) { 771 if (pending_seek_) {
777 pending_seek_ = false; 772 pending_seek_ = false;
778 seek(pending_seek_seconds_); 773 seek(pending_seek_seconds_);
779 return; 774 return;
780 } 775 }
781 776
782 if (status == media::PIPELINE_OK) { 777 if (status == media::PIPELINE_OK) {
783 // Update our paused time. 778 // Update our paused time.
784 if (paused_) { 779 if (paused_)
785 paused_time_ = pipeline_->GetCurrentTime(); 780 paused_time_ = pipeline_->GetCurrentTime();
786 }
787 781
788 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData);
789 GetClient()->timeChanged(); 782 GetClient()->timeChanged();
790 } 783 }
791 } 784 }
792 785
793 void WebMediaPlayerImpl::OnPipelineEnded(PipelineStatus status) { 786 void WebMediaPlayerImpl::OnPipelineEnded(PipelineStatus status) {
794 DCHECK_EQ(main_loop_, MessageLoop::current()); 787 DCHECK_EQ(main_loop_, MessageLoop::current());
795 if (status == media::PIPELINE_OK) { 788 if (status == media::PIPELINE_OK)
796 GetClient()->timeChanged(); 789 GetClient()->timeChanged();
797 }
798 } 790 }
799 791
800 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { 792 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) {
801 DCHECK_EQ(main_loop_, MessageLoop::current()); 793 DCHECK_EQ(main_loop_, MessageLoop::current());
802 switch (error) { 794 switch (error) {
803 case media::PIPELINE_OK: 795 case media::PIPELINE_OK:
804 LOG(DFATAL) << "PIPELINE_OK isn't an error!"; 796 LOG(DFATAL) << "PIPELINE_OK isn't an error!";
805 break; 797 break;
806 798
807 case media::PIPELINE_ERROR_NETWORK: 799 case media::PIPELINE_ERROR_NETWORK:
(...skipping 23 matching lines...) Expand all
831 case media::PIPELINE_ERROR_INVALID_STATE: 823 case media::PIPELINE_ERROR_INVALID_STATE:
832 // Decode error. 824 // Decode error.
833 SetNetworkState(WebMediaPlayer::DecodeError); 825 SetNetworkState(WebMediaPlayer::DecodeError);
834 break; 826 break;
835 } 827 }
836 828
837 // Repaint to trigger UI update. 829 // Repaint to trigger UI update.
838 Repaint(); 830 Repaint();
839 } 831 }
840 832
841 void WebMediaPlayerImpl::OnNetworkEvent(bool is_downloading_data) { 833 void WebMediaPlayerImpl::OnNetworkEvent(NetworkEvent type) {
842 DCHECK_EQ(main_loop_, MessageLoop::current()); 834 DCHECK_EQ(main_loop_, MessageLoop::current());
843 if (is_downloading_data) 835 switch(type) {
844 SetNetworkState(WebKit::WebMediaPlayer::Loading); 836 case media::DOWNLOAD_CONTINUED:
845 else 837 SetNetworkState(WebKit::WebMediaPlayer::Loading);
846 SetNetworkState(WebKit::WebMediaPlayer::Idle); 838 break;
839 case media::DOWNLOAD_PAUSED:
840 SetNetworkState(WebKit::WebMediaPlayer::Idle);
841 break;
842 case media::CAN_PLAY_THROUGH:
843 SetReadyState(WebKit::WebMediaPlayer::HaveEnoughData);
844 break;
845 default:
846 NOTREACHED();
847 }
847 } 848 }
848 849
849 void WebMediaPlayerImpl::OnDemuxerOpened() { 850 void WebMediaPlayerImpl::OnDemuxerOpened() {
850 DCHECK_EQ(main_loop_, MessageLoop::current()); 851 DCHECK_EQ(main_loop_, MessageLoop::current());
851 852
852 GetClient()->sourceOpened(); 853 GetClient()->sourceOpened();
853 } 854 }
854 855
855 void WebMediaPlayerImpl::SetNetworkState( 856 void WebMediaPlayerImpl::SetNetworkState(
856 WebKit::WebMediaPlayer::NetworkState state) { 857 WebKit::WebMediaPlayer::NetworkState state) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 return client_; 909 return client_;
909 } 910 }
910 911
911 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 912 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
912 DCHECK_EQ(main_loop_, MessageLoop::current()); 913 DCHECK_EQ(main_loop_, MessageLoop::current());
913 incremented_externally_allocated_memory_ = true; 914 incremented_externally_allocated_memory_ = true;
914 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 915 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
915 } 916 }
916 917
917 } // namespace webkit_media 918 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/webmediaplayer_impl.h ('k') | webkit/media/webmediaplayer_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698