OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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); |
| 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 Loading... |
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::OnPipelineBufferingState( |
| 859 media::Pipeline::BufferingState buffering_state) { |
| 860 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; |
| 861 |
| 862 switch (buffering_state) { |
| 863 case media::Pipeline::kHaveMetadata: |
| 864 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 865 break; |
| 866 case media::Pipeline::kPrerollCompleted: |
| 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 Loading... |
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::PipelineBufferingStateCallback, |
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) { |
| 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); |
| 999 } |
| 1000 } |
| 1001 |
987 ready_state_ = state; | 1002 ready_state_ = state; |
988 // Always notify to ensure client has the latest value. | 1003 // Always notify to ensure client has the latest value. |
989 GetClient()->readyStateChanged(); | 1004 GetClient()->readyStateChanged(); |
990 } | 1005 } |
991 | 1006 |
992 void WebMediaPlayerImpl::Destroy() { | 1007 void WebMediaPlayerImpl::Destroy() { |
993 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1008 DCHECK_EQ(main_loop_, MessageLoop::current()); |
994 | 1009 |
995 // Tell the data source to abort any pending reads so that the pipeline is | 1010 // 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. | 1011 // not blocked when issuing stop commands to the other filters. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 return audio_source_provider_; | 1047 return audio_source_provider_; |
1033 } | 1048 } |
1034 | 1049 |
1035 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1050 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
1036 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1051 DCHECK_EQ(main_loop_, MessageLoop::current()); |
1037 incremented_externally_allocated_memory_ = true; | 1052 incremented_externally_allocated_memory_ = true; |
1038 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1053 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
1039 } | 1054 } |
1040 | 1055 |
1041 } // namespace webkit_media | 1056 } // namespace webkit_media |
OLD | NEW |