| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 37 #include "v8/include/v8.h" | 37 #include "v8/include/v8.h" |
| 38 #include "webkit/compositor_bindings/web_layer_impl.h" | 38 #include "webkit/compositor_bindings/web_layer_impl.h" |
| 39 #include "webkit/media/buffered_data_source.h" | 39 #include "webkit/media/buffered_data_source.h" |
| 40 #include "webkit/media/filter_helpers.h" | 40 #include "webkit/media/filter_helpers.h" |
| 41 #include "webkit/media/webaudiosourceprovider_impl.h" | 41 #include "webkit/media/webaudiosourceprovider_impl.h" |
| 42 #include "webkit/media/webmediaplayer_delegate.h" | 42 #include "webkit/media/webmediaplayer_delegate.h" |
| 43 #include "webkit/media/webmediaplayer_params.h" | 43 #include "webkit/media/webmediaplayer_params.h" |
| 44 #include "webkit/media/webmediaplayer_util.h" | 44 #include "webkit/media/webmediaplayer_util.h" |
| 45 #include "webkit/media/webmediasourceclient_impl.h" | 45 #include "webkit/media/webmediasourceclient_impl.h" |
| 46 #include "webkit/media/webvideoframe_impl.h" | |
| 47 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | 46 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
| 48 | 47 |
| 49 using WebKit::WebCanvas; | 48 using WebKit::WebCanvas; |
| 50 using WebKit::WebMediaPlayer; | 49 using WebKit::WebMediaPlayer; |
| 51 using WebKit::WebRect; | 50 using WebKit::WebRect; |
| 52 using WebKit::WebSize; | 51 using WebKit::WebSize; |
| 53 using WebKit::WebString; | 52 using WebKit::WebString; |
| 54 using media::PipelineStatus; | 53 using media::PipelineStatus; |
| 55 | 54 |
| 56 namespace { | 55 namespace { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 scoped_ptr<media::AudioRenderer> audio_renderer( | 211 scoped_ptr<media::AudioRenderer> audio_renderer( |
| 213 new media::AudioRendererImpl( | 212 new media::AudioRendererImpl( |
| 214 media_thread_.message_loop_proxy(), | 213 media_thread_.message_loop_proxy(), |
| 215 audio_source_provider_, | 214 audio_source_provider_, |
| 216 audio_decoders.Pass(), | 215 audio_decoders.Pass(), |
| 217 set_decryptor_ready_cb)); | 216 set_decryptor_ready_cb)); |
| 218 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); | 217 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); |
| 219 } | 218 } |
| 220 | 219 |
| 221 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 220 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
| 222 #ifdef REMOVE_WEBVIDEOFRAME | |
| 223 SetVideoFrameProviderClient(NULL); | 221 SetVideoFrameProviderClient(NULL); |
| 224 GetClient()->setWebLayer(NULL); | 222 GetClient()->setWebLayer(NULL); |
| 225 #endif | |
| 226 | 223 |
| 227 DCHECK(main_loop_->BelongsToCurrentThread()); | 224 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 228 Destroy(); | 225 Destroy(); |
| 229 media_log_->AddEvent( | 226 media_log_->AddEvent( |
| 230 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); | 227 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
| 231 | 228 |
| 232 if (delegate_) | 229 if (delegate_) |
| 233 delegate_->PlayerGone(this); | 230 delegate_->PlayerGone(this); |
| 234 | 231 |
| 235 // Remove destruction observer if we're being destroyed but the main thread is | 232 // Remove destruction observer if we're being destroyed but the main thread is |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 return stats.audio_bytes_decoded; | 659 return stats.audio_bytes_decoded; |
| 663 } | 660 } |
| 664 | 661 |
| 665 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { | 662 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { |
| 666 DCHECK(main_loop_->BelongsToCurrentThread()); | 663 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 667 | 664 |
| 668 media::PipelineStatistics stats = pipeline_->GetStatistics(); | 665 media::PipelineStatistics stats = pipeline_->GetStatistics(); |
| 669 return stats.video_bytes_decoded; | 666 return stats.video_bytes_decoded; |
| 670 } | 667 } |
| 671 | 668 |
| 672 #ifndef REMOVE_WEBVIDEOFRAME | |
| 673 WebKit::WebVideoFrame* WebMediaPlayerImpl::getCurrentFrame() { | |
| 674 base::AutoLock auto_lock(lock_); | |
| 675 if (current_frame_) | |
| 676 return new WebVideoFrameImpl(current_frame_); | |
| 677 return NULL; | |
| 678 } | |
| 679 | |
| 680 void WebMediaPlayerImpl::putCurrentFrame( | |
| 681 WebKit::WebVideoFrame* web_video_frame) { | |
| 682 if (!accelerated_compositing_reported_) { | |
| 683 accelerated_compositing_reported_ = true; | |
| 684 DCHECK(frame_->view()->isAcceleratedCompositingActive()); | |
| 685 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true); | |
| 686 } | |
| 687 delete web_video_frame; | |
| 688 } | |
| 689 #else | |
| 690 void WebMediaPlayerImpl::SetVideoFrameProviderClient( | 669 void WebMediaPlayerImpl::SetVideoFrameProviderClient( |
| 691 cc::VideoFrameProvider::Client* client) { | 670 cc::VideoFrameProvider::Client* client) { |
| 692 // This is called from both the main renderer thread and the compositor | 671 // This is called from both the main renderer thread and the compositor |
| 693 // thread (when the main thread is blocked). | 672 // thread (when the main thread is blocked). |
| 694 if (video_frame_provider_client_) | 673 if (video_frame_provider_client_) |
| 695 video_frame_provider_client_->StopUsingProvider(); | 674 video_frame_provider_client_->StopUsingProvider(); |
| 696 video_frame_provider_client_ = client; | 675 video_frame_provider_client_ = client; |
| 697 } | 676 } |
| 698 | 677 |
| 699 scoped_refptr<media::VideoFrame> WebMediaPlayerImpl::GetCurrentFrame() { | 678 scoped_refptr<media::VideoFrame> WebMediaPlayerImpl::GetCurrentFrame() { |
| 700 base::AutoLock auto_lock(lock_); | 679 base::AutoLock auto_lock(lock_); |
| 701 return current_frame_; | 680 return current_frame_; |
| 702 } | 681 } |
| 703 | 682 |
| 704 void WebMediaPlayerImpl::PutCurrentFrame( | 683 void WebMediaPlayerImpl::PutCurrentFrame( |
| 705 const scoped_refptr<media::VideoFrame>& frame) { | 684 const scoped_refptr<media::VideoFrame>& frame) { |
| 706 if (!accelerated_compositing_reported_) { | 685 if (!accelerated_compositing_reported_) { |
| 707 accelerated_compositing_reported_ = true; | 686 accelerated_compositing_reported_ = true; |
| 708 DCHECK(frame_->view()->isAcceleratedCompositingActive()); | 687 DCHECK(frame_->view()->isAcceleratedCompositingActive()); |
| 709 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true); | 688 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true); |
| 710 } | 689 } |
| 711 } | 690 } |
| 712 #endif | |
| 713 | 691 |
| 714 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( | 692 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( |
| 715 WebKit::WebGraphicsContext3D* web_graphics_context, | 693 WebKit::WebGraphicsContext3D* web_graphics_context, |
| 716 unsigned int texture, | 694 unsigned int texture, |
| 717 unsigned int level, | 695 unsigned int level, |
| 718 unsigned int internal_format, | 696 unsigned int internal_format, |
| 719 bool premultiply_alpha, | 697 bool premultiply_alpha, |
| 720 bool flip_y) { | 698 bool flip_y) { |
| 721 scoped_refptr<media::VideoFrame> video_frame; | 699 scoped_refptr<media::VideoFrame> video_frame; |
| 722 { | 700 { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 } | 972 } |
| 995 | 973 |
| 996 void WebMediaPlayerImpl::OnPipelineBufferingState( | 974 void WebMediaPlayerImpl::OnPipelineBufferingState( |
| 997 media::Pipeline::BufferingState buffering_state) { | 975 media::Pipeline::BufferingState buffering_state) { |
| 998 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; | 976 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; |
| 999 | 977 |
| 1000 switch (buffering_state) { | 978 switch (buffering_state) { |
| 1001 case media::Pipeline::kHaveMetadata: | 979 case media::Pipeline::kHaveMetadata: |
| 1002 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 980 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 1003 | 981 |
| 1004 #ifdef REMOVE_WEBVIDEOFRAME | |
| 1005 if (hasVideo() && GetClient()->needsWebLayerForVideo()) { | 982 if (hasVideo() && GetClient()->needsWebLayerForVideo()) { |
| 1006 DCHECK(!video_weblayer_); | 983 DCHECK(!video_weblayer_); |
| 1007 video_weblayer_.reset( | 984 video_weblayer_.reset( |
| 1008 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); | 985 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); |
| 1009 GetClient()->setWebLayer(video_weblayer_.get()); | 986 GetClient()->setWebLayer(video_weblayer_.get()); |
| 1010 } | 987 } |
| 1011 #endif | |
| 1012 break; | 988 break; |
| 1013 case media::Pipeline::kPrerollCompleted: | 989 case media::Pipeline::kPrerollCompleted: |
| 1014 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 990 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 1015 break; | 991 break; |
| 1016 } | 992 } |
| 1017 | 993 |
| 1018 // Repaint to trigger UI update. | 994 // Repaint to trigger UI update. |
| 1019 Repaint(); | 995 Repaint(); |
| 1020 } | 996 } |
| 1021 | 997 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 DVLOG(1) << "SetNetworkState: " << state; | 1130 DVLOG(1) << "SetNetworkState: " << state; |
| 1155 network_state_ = state; | 1131 network_state_ = state; |
| 1156 // Always notify to ensure client has the latest value. | 1132 // Always notify to ensure client has the latest value. |
| 1157 GetClient()->networkStateChanged(); | 1133 GetClient()->networkStateChanged(); |
| 1158 } | 1134 } |
| 1159 | 1135 |
| 1160 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { | 1136 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { |
| 1161 DCHECK(main_loop_->BelongsToCurrentThread()); | 1137 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 1162 DVLOG(1) << "SetReadyState: " << state; | 1138 DVLOG(1) << "SetReadyState: " << state; |
| 1163 | 1139 |
| 1164 #ifndef REMOVE_WEBVIDEOFRAME | |
| 1165 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing && | |
| 1166 state >= WebMediaPlayer::ReadyStateHaveMetadata) { | |
| 1167 if (!hasVideo()) | |
| 1168 GetClient()->disableAcceleratedCompositing(); | |
| 1169 } else | |
| 1170 #endif | |
| 1171 if (state == WebMediaPlayer::ReadyStateHaveEnoughData && | 1140 if (state == WebMediaPlayer::ReadyStateHaveEnoughData && |
| 1172 is_local_source_ && | 1141 is_local_source_ && |
| 1173 network_state_ == WebMediaPlayer::NetworkStateLoading) | 1142 network_state_ == WebMediaPlayer::NetworkStateLoading) |
| 1174 SetNetworkState(WebMediaPlayer::NetworkStateLoaded); | 1143 SetNetworkState(WebMediaPlayer::NetworkStateLoaded); |
| 1175 | 1144 |
| 1176 ready_state_ = state; | 1145 ready_state_ = state; |
| 1177 // Always notify to ensure client has the latest value. | 1146 // Always notify to ensure client has the latest value. |
| 1178 GetClient()->readyStateChanged(); | 1147 GetClient()->readyStateChanged(); |
| 1179 } | 1148 } |
| 1180 | 1149 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 | 1217 |
| 1249 if (pending_repaint_) | 1218 if (pending_repaint_) |
| 1250 return; | 1219 return; |
| 1251 | 1220 |
| 1252 pending_repaint_ = true; | 1221 pending_repaint_ = true; |
| 1253 main_loop_->PostTask(FROM_HERE, base::Bind( | 1222 main_loop_->PostTask(FROM_HERE, base::Bind( |
| 1254 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); | 1223 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); |
| 1255 } | 1224 } |
| 1256 | 1225 |
| 1257 } // namespace webkit_media | 1226 } // namespace webkit_media |
| OLD | NEW |