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

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: 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 client_(client), 124 client_(client),
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 decryptor_(proxy_.get(), client, frame) { 134 decryptor_(proxy_.get(), client, frame),
135 starting_(false) {
135 media_log_->AddEvent( 136 media_log_->AddEvent(
136 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); 137 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED));
137 138
138 MessageLoop* pipeline_message_loop = 139 MessageLoop* pipeline_message_loop =
139 message_loop_factory_->GetMessageLoop("PipelineThread"); 140 message_loop_factory_->GetMessageLoop("PipelineThread");
140 pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_); 141 pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_);
141 142
142 // Let V8 know we started new thread if we did not did it yet. 143 // Let V8 know we started new thread if we did not did it yet.
143 // Made separate task to avoid deletion of player currently being created. 144 // Made separate task to avoid deletion of player currently being created.
144 // Also, delaying GC until after player starts gets rid of starting lag -- 145 // Also, delaying GC until after player starts gets rid of starting lag --
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 303 }
303 304
304 bool WebMediaPlayerImpl::supportsSave() const { 305 bool WebMediaPlayerImpl::supportsSave() const {
305 DCHECK_EQ(main_loop_, MessageLoop::current()); 306 DCHECK_EQ(main_loop_, MessageLoop::current());
306 return true; 307 return true;
307 } 308 }
308 309
309 void WebMediaPlayerImpl::seek(float seconds) { 310 void WebMediaPlayerImpl::seek(float seconds) {
310 DCHECK_EQ(main_loop_, MessageLoop::current()); 311 DCHECK_EQ(main_loop_, MessageLoop::current());
311 312
312 if (seeking_) { 313 if (starting_ || seeking_) {
313 pending_seek_ = true; 314 pending_seek_ = true;
314 pending_seek_seconds_ = seconds; 315 pending_seek_seconds_ = seconds;
315 proxy_->DemuxerCancelPendingSeek(); 316 proxy_->DemuxerCancelPendingSeek();
316 return; 317 return;
317 } 318 }
318 319
319 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds)); 320 media_log_->AddEvent(media_log_->CreateSeekEvent(seconds));
320 321
321 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds); 322 base::TimeDelta seek_time = ConvertSecondsToTimestamp(seconds);
322 323
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 Destroy(); 754 Destroy();
754 main_loop_ = NULL; 755 main_loop_ = NULL;
755 } 756 }
756 757
757 void WebMediaPlayerImpl::Repaint() { 758 void WebMediaPlayerImpl::Repaint() {
758 DCHECK_EQ(main_loop_, MessageLoop::current()); 759 DCHECK_EQ(main_loop_, MessageLoop::current());
759 GetClient()->repaint(); 760 GetClient()->repaint();
760 } 761 }
761 762
762 void WebMediaPlayerImpl::OnPipelineInitialize(PipelineStatus status) { 763 void WebMediaPlayerImpl::OnPipelineInitialize(PipelineStatus status) {
764 starting_ = false;
Ami GONE FROM CHROMIUM 2012/08/15 18:00:08 put below DCHECK below.
acolwell GONE FROM CHROMIUM 2012/08/15 23:21:15 Done.
765
763 DCHECK_EQ(main_loop_, MessageLoop::current()); 766 DCHECK_EQ(main_loop_, MessageLoop::current());
764 if (status != media::PIPELINE_OK) { 767 if (status != media::PIPELINE_OK) {
765 // Any error that occurs before the pipeline can initialize should be 768 // Any error that occurs before the pipeline can initialize should be
766 // considered a format error. 769 // considered a format error.
767 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); 770 SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
768 // Repaint to trigger UI update. 771 // Repaint to trigger UI update.
769 Repaint(); 772 Repaint();
770 return; 773 return;
771 } 774 }
772 775
773 if (!hasVideo()) 776 if (!hasVideo())
774 GetClient()->disableAcceleratedCompositing(); 777 GetClient()->disableAcceleratedCompositing();
775 778
776 if (is_local_source_) 779 if (is_local_source_)
777 SetNetworkState(WebMediaPlayer::NetworkStateLoaded); 780 SetNetworkState(WebMediaPlayer::NetworkStateLoaded);
778 781
779 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); 782 if (!pending_seek_)
780 // Fire canplaythrough immediately after playback begins because of 783 return;
781 // crbug.com/106480.
782 // TODO(vrk): set ready state to HaveFutureData when bug above is fixed.
783 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
784 784
785 // Repaint to trigger UI update. 785 pending_seek_ = false;
786 Repaint(); 786 seek(pending_seek_seconds_);
787 } 787 }
788 788
789 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) { 789 void WebMediaPlayerImpl::OnPipelineSeek(PipelineStatus status) {
790 DCHECK_EQ(main_loop_, MessageLoop::current()); 790 DCHECK_EQ(main_loop_, MessageLoop::current());
791 seeking_ = false; 791 seeking_ = false;
792 if (pending_seek_) { 792 if (pending_seek_) {
793 pending_seek_ = false; 793 pending_seek_ = false;
794 seek(pending_seek_seconds_); 794 seek(pending_seek_seconds_);
795 return; 795 return;
796 } 796 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 858
859 case media::PIPELINE_STATUS_MAX: 859 case media::PIPELINE_STATUS_MAX:
860 NOTREACHED() << "PIPELINE_STATUS_MAX isn't a real error!"; 860 NOTREACHED() << "PIPELINE_STATUS_MAX isn't a real error!";
861 break; 861 break;
862 } 862 }
863 863
864 // Repaint to trigger UI update. 864 // Repaint to trigger UI update.
865 Repaint(); 865 Repaint();
866 } 866 }
867 867
868 void WebMediaPlayerImpl::OnPipelineReadyState(
869 media::Pipeline::ReadyState readyState) {
870 DVLOG(1) << "OnPipelineReadyState(" << readyState << ")";
871
872 switch(readyState) {
873 case media::Pipeline::HaveMetadata:
874 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata);
875 break;
876 case media::Pipeline::HaveEnoughData:
877 // Fire canplaythrough immediately after playback begins because of
878 // crbug.com/106480.
879 // TODO(vrk): set ready state to HaveFutureData when bug above is fixed.
880 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
881 break;
882 }
883
884 // Repaint to trigger UI update.
885 Repaint();
886 }
887
868 void WebMediaPlayerImpl::OnDemuxerOpened() { 888 void WebMediaPlayerImpl::OnDemuxerOpened() {
869 DCHECK_EQ(main_loop_, MessageLoop::current()); 889 DCHECK_EQ(main_loop_, MessageLoop::current());
870 890
871 GetClient()->sourceOpened(); 891 GetClient()->sourceOpened();
872 } 892 }
873 893
874 void WebMediaPlayerImpl::OnKeyAdded(const std::string& key_system, 894 void WebMediaPlayerImpl::OnKeyAdded(const std::string& key_system,
875 const std::string& session_id) { 895 const std::string& session_id) {
876 DCHECK_EQ(main_loop_, MessageLoop::current()); 896 DCHECK_EQ(main_loop_, MessageLoop::current());
877 897
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 SetNetworkState(WebMediaPlayer::NetworkStateIdle); 972 SetNetworkState(WebMediaPlayer::NetworkStateIdle);
953 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle) 973 else if (is_downloading && network_state_ == WebMediaPlayer::NetworkStateIdle)
954 SetNetworkState(WebMediaPlayer::NetworkStateLoading); 974 SetNetworkState(WebMediaPlayer::NetworkStateLoading);
955 media_log_->AddEvent( 975 media_log_->AddEvent(
956 media_log_->CreateBooleanEvent( 976 media_log_->CreateBooleanEvent(
957 media::MediaLogEvent::NETWORK_ACTIVITY_SET, 977 media::MediaLogEvent::NETWORK_ACTIVITY_SET,
958 "is_downloading_data", is_downloading)); 978 "is_downloading_data", is_downloading));
959 } 979 }
960 980
961 void WebMediaPlayerImpl::StartPipeline() { 981 void WebMediaPlayerImpl::StartPipeline() {
982 starting_ = true;
962 pipeline_->Start( 983 pipeline_->Start(
963 filter_collection_.Pass(), 984 filter_collection_.Pass(),
964 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), 985 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()),
965 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), 986 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()),
966 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, 987 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback,
988 proxy_.get()),
989 base::Bind(&WebMediaPlayerProxy::PipelineReadyStateCallback,
967 proxy_.get())); 990 proxy_.get()));
968 } 991 }
969 992
970 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { 993 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) {
971 DCHECK_EQ(main_loop_, MessageLoop::current()); 994 DCHECK_EQ(main_loop_, MessageLoop::current());
972 DVLOG(1) << "SetNetworkState: " << state; 995 DVLOG(1) << "SetNetworkState: " << state;
973 network_state_ = state; 996 network_state_ = state;
974 // Always notify to ensure client has the latest value. 997 // Always notify to ensure client has the latest value.
975 GetClient()->networkStateChanged(); 998 GetClient()->networkStateChanged();
976 } 999 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 return audio_source_provider_; 1049 return audio_source_provider_;
1027 } 1050 }
1028 1051
1029 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { 1052 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() {
1030 DCHECK_EQ(main_loop_, MessageLoop::current()); 1053 DCHECK_EQ(main_loop_, MessageLoop::current());
1031 incremented_externally_allocated_memory_ = true; 1054 incremented_externally_allocated_memory_ = true;
1032 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); 1055 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory);
1033 } 1056 }
1034 1057
1035 } // namespace webkit_media 1058 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698