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

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

Issue 10854151: Allow transitioning to HAVE_METADATA before pipeline initialization completes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address CR comments and fix tests. Created 8 years, 4 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <vector> 9 #include <vector>
10 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 proxy_(new WebMediaPlayerProxy(main_loop_->message_loop_proxy(), this)), 125 proxy_(new WebMediaPlayerProxy(main_loop_->message_loop_proxy(), this)),
126 delegate_(delegate), 126 delegate_(delegate),
127 media_stream_client_(media_stream_client), 127 media_stream_client_(media_stream_client),
128 media_log_(media_log), 128 media_log_(media_log),
129 accelerated_compositing_reported_(false), 129 accelerated_compositing_reported_(false),
130 incremented_externally_allocated_memory_(false), 130 incremented_externally_allocated_memory_(false),
131 audio_source_provider_(audio_source_provider), 131 audio_source_provider_(audio_source_provider),
132 audio_renderer_sink_(audio_renderer_sink), 132 audio_renderer_sink_(audio_renderer_sink),
133 is_local_source_(false), 133 is_local_source_(false),
134 supports_save_(true), 134 supports_save_(true),
135 decryptor_(proxy_.get(), client, frame) { 135 decryptor_(proxy_.get(), client, frame),
136 starting_(false) {
136 media_log_->AddEvent( 137 media_log_->AddEvent(
137 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); 138 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED));
138 139
139 scoped_refptr<base::MessageLoopProxy> pipeline_message_loop = 140 scoped_refptr<base::MessageLoopProxy> pipeline_message_loop =
140 message_loop_factory_->GetMessageLoop( 141 message_loop_factory_->GetMessageLoop(
141 media::MessageLoopFactory::kPipeline); 142 media::MessageLoopFactory::kPipeline);
142 pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_); 143 pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_);
143 144
144 // Let V8 know we started new thread if we did not did it yet. 145 // Let V8 know we started new thread if we did not did it yet.
145 // Made separate task to avoid deletion of player currently being created. 146 // Made separate task to avoid deletion of player currently being created.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 307 }
307 308
308 bool WebMediaPlayerImpl::supportsSave() const { 309 bool WebMediaPlayerImpl::supportsSave() const {
309 DCHECK_EQ(main_loop_, MessageLoop::current()); 310 DCHECK_EQ(main_loop_, MessageLoop::current());
310 return supports_save_; 311 return supports_save_;
311 } 312 }
312 313
313 void WebMediaPlayerImpl::seek(float seconds) { 314 void WebMediaPlayerImpl::seek(float seconds) {
314 DCHECK_EQ(main_loop_, MessageLoop::current()); 315 DCHECK_EQ(main_loop_, MessageLoop::current());
315 316
316 if (seeking_) { 317 if (starting_ || seeking_) {
317 pending_seek_ = true; 318 pending_seek_ = true;
318 pending_seek_seconds_ = seconds; 319 pending_seek_seconds_ = seconds;
319 proxy_->DemuxerCancelPendingSeek(); 320 proxy_->DemuxerCancelPendingSeek();
320 return; 321 return;
321 } 322 }
322 323
323 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds)); 324 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds));
324 325
325 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); 326 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds);
326 327
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { 759 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() {
759 Destroy(); 760 Destroy();
760 main_loop_ = NULL; 761 main_loop_ = NULL;
761 } 762 }
762 763
763 void WebMediaPlayerImpl::Repaint() { 764 void WebMediaPlayerImpl::Repaint() {
764 DCHECK_EQ(main_loop_, MessageLoop::current()); 765 DCHECK_EQ(main_loop_, MessageLoop::current());
765 GetClient()->repaint(); 766 GetClient()->repaint();
766 } 767 }
767 768
768 void WebMediaPlayerImpl::OnPipelineInitialize(PipelineStatus status) {
769 DCHECK_EQ(main_loop_, MessageLoop::current());
770 if (status != media::PIPELINE_OK) {
771 // Any error that occurs before the pipeline can initialize should be
772 // considered a format error.
773 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
774 // Repaint to trigger UI update.
775 Repaint();
776 return;
777 }
778
779 if (!hasVideo())
780 GetClient()->disableAcceleratedCompositing();
781
782 if (is_local_source_)
783 SetNetworkState(WebMediaPlayer::NetworkStateLoaded);
784
785 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata);
786 // Fire canplaythrough immediately after playback begins because of
787 // crbug.com/106480.
788 // TODO(vrk): set ready state to HaveFutureData when bug above is fixed.
789 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
790
791 // Repaint to trigger UI update.
792 Repaint();
793 }
794
795 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) { 769 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) {
796 DCHECK_EQ(main_loop_, MessageLoop::current()); 770 DCHECK_EQ(main_loop_, MessageLoop::current());
771 starting_ = false;
797 seeking_ = false; 772 seeking_ = false;
798 if (pending_seek_) { 773 if (pending_seek_) {
799 pending_seek_ = false; 774 pending_seek_ = false;
800 seek(pending_seek_seconds_); 775 seek(pending_seek_seconds_);
801 return; 776 return;
802 } 777 }
803 778
804 if (status != media::PIPELINE_OK) { 779 if (status != media::PIPELINE_OK) {
805 OnPipelineError(status); 780 OnPipelineError(status);
806 return; 781 return;
(...skipping 10 matching lines...) Expand all
817 DCHECK_EQ(main_loop_, MessageLoop::current()); 792 DCHECK_EQ(main_loop_, MessageLoop::current());
818 if (status != media::PIPELINE_OK) { 793 if (status != media::PIPELINE_OK) {
819 OnPipelineError(status); 794 OnPipelineError(status);
820 return; 795 return;
821 } 796 }
822 GetClient()->timeChanged(); 797 GetClient()->timeChanged();
823 } 798 }
824 799
825 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) { 800 void WebMediaPlayerImpl::OnPipelineError(PipelineStatus error) {
826 DCHECK_EQ(main_loop_, MessageLoop::current()); 801 DCHECK_EQ(main_loop_, MessageLoop::current());
802
803 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) {
804 // Any error that occurs before reaching ReadyStateHaveMetadata should
805 // be considered a format error.
806 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
scherkus (not reviewing) 2012/08/15 23:43:16 does this impact any layout tests? do we have lay
acolwell GONE FROM CHROMIUM 2012/08/16 00:54:18 This does not break any existing tests if that is
807 Repaint();
808 return;
809 }
810
827 switch (error) { 811 switch (error) {
828 case media::PIPELINE_OK: 812 case media::PIPELINE_OK:
829 NOTREACHED() << "PIPELINE_OK isn't an error!"; 813 NOTREACHED() << "PIPELINE_OK isn't an error!";
830 break; 814 break;
831 815
832 case media::PIPELINE_ERROR_NETWORK: 816 case media::PIPELINE_ERROR_NETWORK:
833 case media::PIPELINE_ERROR_READ: 817 case media::PIPELINE_ERROR_READ:
834 SetNetworkState(WebMediaPlayer::NetworkStateNetworkError); 818 SetNetworkState(WebMediaPlayer::NetworkStateNetworkError);
835 break; 819 break;
836 820
(...skipping 27 matching lines...) Expand all
864 848
865 case media::PIPELINE_STATUS_MAX: 849 case media::PIPELINE_STATUS_MAX:
866 NOTREACHED() << "PIPELINE_STATUS_MAX isn't a real error!"; 850 NOTREACHED() << "PIPELINE_STATUS_MAX isn't a real error!";
867 break; 851 break;
868 } 852 }
869 853
870 // Repaint to trigger UI update. 854 // Repaint to trigger UI update.
871 Repaint(); 855 Repaint();
872 } 856 }
873 857
858 void WebMediaPlayerImpl::OnPipelineReadyState(
859 media::Pipeline::ReadyState readyState) {
scherkus (not reviewing) 2012/08/15 23:43:16 unix_hacker
acolwell GONE FROM CHROMIUM 2012/08/16 00:54:18 Done.
860 DVLOG(1) << "OnPipelineReadyState(" << readyState << ")";
861
862 switch (readyState) {
863 case media::Pipeline::kHaveMetadata:
864 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata);
865 break;
866 case media::Pipeline::kHaveEnoughData:
867 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
868 break;
869 }
870
871 // Repaint to trigger UI update.
872 Repaint();
873 }
874
874 void WebMediaPlayerImpl::OnDemuxerOpened() { 875 void WebMediaPlayerImpl::OnDemuxerOpened() {
875 DCHECK_EQ(main_loop_, MessageLoop::current()); 876 DCHECK_EQ(main_loop_, MessageLoop::current());
876 877
877 GetClient()->sourceOpened(); 878 GetClient()->sourceOpened();
878 } 879 }
879 880
880 void WebMediaPlayerImpl::OnKeyAdded(const std::string& key_system, 881 void WebMediaPlayerImpl::OnKeyAdded(const std::string& key_system,
881 const std::string& session_id) { 882 const std::string& session_id) {
882 DCHECK_EQ(main_loop_, MessageLoop::current()); 883 DCHECK_EQ(main_loop_, MessageLoop::current());
883 884
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 SetNetworkState(WebMediaPlayer::NetworkStateIdle); 959 SetNetworkState(WebMediaPlayer::NetworkStateIdle);
959 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) 960 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle)
960 SetNetworkState(WebMediaPlayer::NetworkStateLoading); 961 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
961 media_log_->AddEvent( 962 media_log_->AddEvent(
962 media_log_->CreateBooleanEvent( 963 media_log_->CreateBooleanEvent(
963 media::MediaLogEvent::NETWORK_ACTIVITY_SET, 964 media::MediaLogEvent::NETWORK_ACTIVITY_SET,
964 "is_downloading_data", is_downloading)); 965 "is_downloading_data", is_downloading));
965 } 966 }
966 967
967 void WebMediaPlayerImpl::StartPipeline() { 968 void WebMediaPlayerImpl::StartPipeline() {
969 starting_ = true;
968 pipeline_->Start( 970 pipeline_->Start(
969 filter_collection_.Pass(), 971 filter_collection_.Pass(),
970 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), 972 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()),
971 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), 973 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()),
972 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, 974 base::Bind(&WebMediaPlayerProxy::PipelineSeekCallback, proxy_.get()),
975 base::Bind(&WebMediaPlayerProxy::PipelineReadyStateCallback,
973 proxy_.get())); 976 proxy_.get()));
974 } 977 }
975 978
976 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { 979 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) {
977 DCHECK_EQ(main_loop_, MessageLoop::current()); 980 DCHECK_EQ(main_loop_, MessageLoop::current());
978 DVLOG(1) << "SetNetworkState: " << state; 981 DVLOG(1) << "SetNetworkState: " << state;
979 network_state_ = state; 982 network_state_ = state;
980 // Always notify to ensure client has the latest value. 983 // Always notify to ensure client has the latest value.
981 GetClient()->networkStateChanged(); 984 GetClient()->networkStateChanged();
982 } 985 }
983 986
984 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { 987 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) {
985 DCHECK_EQ(main_loop_, MessageLoop::current()); 988 DCHECK_EQ(main_loop_, MessageLoop::current());
986 DVLOG(1) << "SetReadyState: " << state; 989 DVLOG(1) << "SetReadyState: " << state;
990
991 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing &&
992 state == WebMediaPlayer::ReadyStateHaveMetadata) {
scherkus (not reviewing) 2012/08/15 23:43:16 this assumes we always set to metadata at some poi
acolwell GONE FROM CHROMIUM 2012/08/16 00:54:18 Good point. Changed to >=
993 if (!hasVideo())
994 GetClient()->disableAcceleratedCompositing();
995 } else if (state == WebMediaPlayer::ReadyStateHaveEnoughData) {
996 if (is_local_source_ &&
997 network_state_ == WebMediaPlayer::NetworkStateLoading)
998 SetNetworkState(WebMediaPlayer::NetworkStateLoaded);
scherkus (not reviewing) 2012/08/15 23:43:16 {} for if statements >1 line
acolwell GONE FROM CHROMIUM 2012/08/16 00:54:18 Done.
999 }
1000
987 ready_state_ = state; 1001 ready_state_ = state;
988 // Always notify to ensure client has the latest value. 1002 // Always notify to ensure client has the latest value.
989 GetClient()->readyStateChanged(); 1003 GetClient()->readyStateChanged();
990 } 1004 }
991 1005
992 void WebMediaPlayerImpl::Destroy() { 1006 void WebMediaPlayerImpl::Destroy() {
993 DCHECK_EQ(main_loop_, MessageLoop::current()); 1007 DCHECK_EQ(main_loop_, MessageLoop::current());
994 1008
995 // Tell the data source to abort any pending reads so that the pipeline is 1009 // Tell the data source to abort any pending reads so that the pipeline is
996 // not blocked when issuing stop commands to the other filters. 1010 // not blocked when issuing stop commands to the other filters.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 return audio_source_provider_; 1046 return audio_source_provider_;
1033 } 1047 }
1034 1048
1035 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 1049 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
1036 DCHECK_EQ(main_loop_, MessageLoop::current()); 1050 DCHECK_EQ(main_loop_, MessageLoop::current());
1037 incremented_externally_allocated_memory_ = true; 1051 incremented_externally_allocated_memory_ = true;
1038 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 1052 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
1039 } 1053 }
1040 1054
1041 } // namespace webkit_media 1055 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698