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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "cc/layers/video_layer.h" |
18 #include "gpu/GLES2/gl2extchromium.h" | 19 #include "gpu/GLES2/gl2extchromium.h" |
19 #include "media/audio/null_audio_sink.h" | 20 #include "media/audio/null_audio_sink.h" |
20 #include "media/base/bind_to_loop.h" | 21 #include "media/base/bind_to_loop.h" |
21 #include "media/base/filter_collection.h" | 22 #include "media/base/filter_collection.h" |
22 #include "media/base/limits.h" | 23 #include "media/base/limits.h" |
23 #include "media/base/media_log.h" | 24 #include "media/base/media_log.h" |
24 #include "media/base/pipeline.h" | 25 #include "media/base/pipeline.h" |
25 #include "media/base/video_frame.h" | 26 #include "media/base/video_frame.h" |
26 #include "media/filters/audio_renderer_impl.h" | 27 #include "media/filters/audio_renderer_impl.h" |
27 #include "media/filters/chunk_demuxer.h" | 28 #include "media/filters/chunk_demuxer.h" |
28 #include "media/filters/video_renderer_base.h" | 29 #include "media/filters/video_renderer_base.h" |
29 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
30 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
31 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 32 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
32 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 33 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
36 #include "v8/include/v8.h" | 37 #include "v8/include/v8.h" |
| 38 #include "webkit/compositor_bindings/web_layer_impl.h" |
37 #include "webkit/media/buffered_data_source.h" | 39 #include "webkit/media/buffered_data_source.h" |
38 #include "webkit/media/filter_helpers.h" | 40 #include "webkit/media/filter_helpers.h" |
39 #include "webkit/media/webaudiosourceprovider_impl.h" | 41 #include "webkit/media/webaudiosourceprovider_impl.h" |
40 #include "webkit/media/webmediaplayer_delegate.h" | 42 #include "webkit/media/webmediaplayer_delegate.h" |
41 #include "webkit/media/webmediaplayer_params.h" | 43 #include "webkit/media/webmediaplayer_params.h" |
42 #include "webkit/media/webmediaplayer_util.h" | 44 #include "webkit/media/webmediaplayer_util.h" |
43 #include "webkit/media/webmediasourceclient_impl.h" | 45 #include "webkit/media/webmediasourceclient_impl.h" |
44 #include "webkit/media/webvideoframe_impl.h" | 46 #include "webkit/media/webvideoframe_impl.h" |
45 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | 47 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
46 | 48 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 pending_seek_(false), | 140 pending_seek_(false), |
139 pending_seek_seconds_(0.0f), | 141 pending_seek_seconds_(0.0f), |
140 client_(client), | 142 client_(client), |
141 delegate_(delegate), | 143 delegate_(delegate), |
142 media_log_(params.media_log()), | 144 media_log_(params.media_log()), |
143 accelerated_compositing_reported_(false), | 145 accelerated_compositing_reported_(false), |
144 incremented_externally_allocated_memory_(false), | 146 incremented_externally_allocated_memory_(false), |
145 is_local_source_(false), | 147 is_local_source_(false), |
146 supports_save_(true), | 148 supports_save_(true), |
147 starting_(false), | 149 starting_(false), |
148 pending_repaint_(false) { | 150 pending_repaint_(false), |
| 151 video_frame_provider_client_(NULL) { |
149 media_log_->AddEvent( | 152 media_log_->AddEvent( |
150 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 153 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
151 | 154 |
152 CHECK(media_thread_.Start()); | 155 CHECK(media_thread_.Start()); |
153 pipeline_ = new media::Pipeline( | 156 pipeline_ = new media::Pipeline( |
154 media_thread_.message_loop_proxy(), media_log_); | 157 media_thread_.message_loop_proxy(), media_log_); |
155 | 158 |
156 // Let V8 know we started new thread if we did not do it yet. | 159 // Let V8 know we started new thread if we did not do it yet. |
157 // Made separate task to avoid deletion of player currently being created. | 160 // Made separate task to avoid deletion of player currently being created. |
158 // Also, delaying GC until after player starts gets rid of starting lag -- | 161 // Also, delaying GC until after player starts gets rid of starting lag -- |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 new media::NullAudioSink(media_thread_.message_loop_proxy())); | 207 new media::NullAudioSink(media_thread_.message_loop_proxy())); |
205 scoped_ptr<media::AudioRenderer> audio_renderer( | 208 scoped_ptr<media::AudioRenderer> audio_renderer( |
206 new media::AudioRendererImpl( | 209 new media::AudioRendererImpl( |
207 media_thread_.message_loop_proxy(), | 210 media_thread_.message_loop_proxy(), |
208 audio_source_provider_, | 211 audio_source_provider_, |
209 set_decryptor_ready_cb)); | 212 set_decryptor_ready_cb)); |
210 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); | 213 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); |
211 } | 214 } |
212 | 215 |
213 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 216 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
| 217 #ifdef REMOVE_WEBVIDEOFRAME |
| 218 SetVideoFrameProviderClient(NULL); |
| 219 GetClient()->setWebLayer(NULL); |
| 220 #endif |
| 221 |
214 DCHECK(main_loop_->BelongsToCurrentThread()); | 222 DCHECK(main_loop_->BelongsToCurrentThread()); |
215 Destroy(); | 223 Destroy(); |
216 media_log_->AddEvent( | 224 media_log_->AddEvent( |
217 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); | 225 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
218 | 226 |
219 if (delegate_) | 227 if (delegate_) |
220 delegate_->PlayerGone(this); | 228 delegate_->PlayerGone(this); |
221 | 229 |
222 // Remove destruction observer if we're being destroyed but the main thread is | 230 // Remove destruction observer if we're being destroyed but the main thread is |
223 // still running. | 231 // still running. |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 return stats.audio_bytes_decoded; | 657 return stats.audio_bytes_decoded; |
650 } | 658 } |
651 | 659 |
652 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { | 660 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { |
653 DCHECK(main_loop_->BelongsToCurrentThread()); | 661 DCHECK(main_loop_->BelongsToCurrentThread()); |
654 | 662 |
655 media::PipelineStatistics stats = pipeline_->GetStatistics(); | 663 media::PipelineStatistics stats = pipeline_->GetStatistics(); |
656 return stats.video_bytes_decoded; | 664 return stats.video_bytes_decoded; |
657 } | 665 } |
658 | 666 |
| 667 #ifndef REMOVE_WEBVIDEOFRAME |
659 WebKit::WebVideoFrame* WebMediaPlayerImpl::getCurrentFrame() { | 668 WebKit::WebVideoFrame* WebMediaPlayerImpl::getCurrentFrame() { |
660 base::AutoLock auto_lock(lock_); | 669 base::AutoLock auto_lock(lock_); |
661 if (current_frame_) | 670 if (current_frame_) |
662 return new WebVideoFrameImpl(current_frame_); | 671 return new WebVideoFrameImpl(current_frame_); |
663 return NULL; | 672 return NULL; |
664 } | 673 } |
665 | 674 |
666 void WebMediaPlayerImpl::putCurrentFrame( | 675 void WebMediaPlayerImpl::putCurrentFrame( |
667 WebKit::WebVideoFrame* web_video_frame) { | 676 WebKit::WebVideoFrame* web_video_frame) { |
668 if (!accelerated_compositing_reported_) { | 677 if (!accelerated_compositing_reported_) { |
669 accelerated_compositing_reported_ = true; | 678 accelerated_compositing_reported_ = true; |
670 DCHECK(frame_->view()->isAcceleratedCompositingActive()); | 679 DCHECK(frame_->view()->isAcceleratedCompositingActive()); |
671 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true); | 680 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true); |
672 } | 681 } |
673 delete web_video_frame; | 682 delete web_video_frame; |
674 } | 683 } |
| 684 #else |
| 685 void WebMediaPlayerImpl::SetVideoFrameProviderClient( |
| 686 cc::VideoFrameProvider::Client* client) { |
| 687 // This is called from both the main renderer thread and the compositor |
| 688 // thread (when the main thread is blocked). |
| 689 if (video_frame_provider_client_) |
| 690 video_frame_provider_client_->StopUsingProvider(); |
| 691 video_frame_provider_client_ = client; |
| 692 } |
| 693 |
| 694 scoped_refptr<media::VideoFrame> WebMediaPlayerImpl::GetCurrentFrame() { |
| 695 base::AutoLock auto_lock(lock_); |
| 696 return current_frame_; |
| 697 } |
| 698 |
| 699 void WebMediaPlayerImpl::PutCurrentFrame( |
| 700 const scoped_refptr<media::VideoFrame>& frame) { |
| 701 if (!accelerated_compositing_reported_) { |
| 702 accelerated_compositing_reported_ = true; |
| 703 DCHECK(frame_->view()->isAcceleratedCompositingActive()); |
| 704 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true); |
| 705 } |
| 706 } |
| 707 #endif |
675 | 708 |
676 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( | 709 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( |
677 WebKit::WebGraphicsContext3D* web_graphics_context, | 710 WebKit::WebGraphicsContext3D* web_graphics_context, |
678 unsigned int texture, | 711 unsigned int texture, |
679 unsigned int level, | 712 unsigned int level, |
680 unsigned int internal_format, | 713 unsigned int internal_format, |
681 bool premultiply_alpha, | 714 bool premultiply_alpha, |
682 bool flip_y) { | 715 bool flip_y) { |
683 scoped_refptr<media::VideoFrame> video_frame; | 716 scoped_refptr<media::VideoFrame> video_frame; |
684 { | 717 { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 Repaint(); | 988 Repaint(); |
956 } | 989 } |
957 | 990 |
958 void WebMediaPlayerImpl::OnPipelineBufferingState( | 991 void WebMediaPlayerImpl::OnPipelineBufferingState( |
959 media::Pipeline::BufferingState buffering_state) { | 992 media::Pipeline::BufferingState buffering_state) { |
960 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; | 993 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; |
961 | 994 |
962 switch (buffering_state) { | 995 switch (buffering_state) { |
963 case media::Pipeline::kHaveMetadata: | 996 case media::Pipeline::kHaveMetadata: |
964 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 997 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 998 |
| 999 #ifdef REMOVE_WEBVIDEOFRAME |
| 1000 if (hasVideo() && GetClient()->needsWebLayerForVideo()) { |
| 1001 DCHECK(!video_weblayer_); |
| 1002 video_weblayer_.reset( |
| 1003 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); |
| 1004 GetClient()->setWebLayer(video_weblayer_.get()); |
| 1005 } |
| 1006 #endif |
965 break; | 1007 break; |
966 case media::Pipeline::kPrerollCompleted: | 1008 case media::Pipeline::kPrerollCompleted: |
967 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 1009 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
968 break; | 1010 break; |
969 } | 1011 } |
970 | 1012 |
971 // Repaint to trigger UI update. | 1013 // Repaint to trigger UI update. |
972 Repaint(); | 1014 Repaint(); |
973 } | 1015 } |
974 | 1016 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 DVLOG(1) << "SetNetworkState: " << state; | 1149 DVLOG(1) << "SetNetworkState: " << state; |
1108 network_state_ = state; | 1150 network_state_ = state; |
1109 // Always notify to ensure client has the latest value. | 1151 // Always notify to ensure client has the latest value. |
1110 GetClient()->networkStateChanged(); | 1152 GetClient()->networkStateChanged(); |
1111 } | 1153 } |
1112 | 1154 |
1113 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { | 1155 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { |
1114 DCHECK(main_loop_->BelongsToCurrentThread()); | 1156 DCHECK(main_loop_->BelongsToCurrentThread()); |
1115 DVLOG(1) << "SetReadyState: " << state; | 1157 DVLOG(1) << "SetReadyState: " << state; |
1116 | 1158 |
| 1159 #ifndef REMOVE_WEBVIDEOFRAME |
1117 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing && | 1160 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing && |
1118 state >= WebMediaPlayer::ReadyStateHaveMetadata) { | 1161 state >= WebMediaPlayer::ReadyStateHaveMetadata) { |
1119 if (!hasVideo()) | 1162 if (!hasVideo()) |
1120 GetClient()->disableAcceleratedCompositing(); | 1163 GetClient()->disableAcceleratedCompositing(); |
1121 } else if (state == WebMediaPlayer::ReadyStateHaveEnoughData) { | 1164 } else |
1122 if (is_local_source_ && | 1165 #endif |
1123 network_state_ == WebMediaPlayer::NetworkStateLoading) { | 1166 if (state == WebMediaPlayer::ReadyStateHaveEnoughData && |
1124 SetNetworkState(WebMediaPlayer::NetworkStateLoaded); | 1167 is_local_source_ && |
1125 } | 1168 network_state_ == WebMediaPlayer::NetworkStateLoading) |
1126 } | 1169 SetNetworkState(WebMediaPlayer::NetworkStateLoaded); |
1127 | 1170 |
1128 ready_state_ = state; | 1171 ready_state_ = state; |
1129 // Always notify to ensure client has the latest value. | 1172 // Always notify to ensure client has the latest value. |
1130 GetClient()->readyStateChanged(); | 1173 GetClient()->readyStateChanged(); |
1131 } | 1174 } |
1132 | 1175 |
1133 void WebMediaPlayerImpl::Destroy() { | 1176 void WebMediaPlayerImpl::Destroy() { |
1134 DCHECK(main_loop_->BelongsToCurrentThread()); | 1177 DCHECK(main_loop_->BelongsToCurrentThread()); |
1135 | 1178 |
1136 // Abort any pending IO so stopping the pipeline doesn't get blocked. | 1179 // Abort any pending IO so stopping the pipeline doesn't get blocked. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 | 1243 |
1201 if (pending_repaint_) | 1244 if (pending_repaint_) |
1202 return; | 1245 return; |
1203 | 1246 |
1204 pending_repaint_ = true; | 1247 pending_repaint_ = true; |
1205 main_loop_->PostTask(FROM_HERE, base::Bind( | 1248 main_loop_->PostTask(FROM_HERE, base::Bind( |
1206 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); | 1249 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); |
1207 } | 1250 } |
1208 | 1251 |
1209 } // namespace webkit_media | 1252 } // namespace webkit_media |
OLD | NEW |