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" | |
45 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | 46 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
46 | 47 |
47 using WebKit::WebCanvas; | 48 using WebKit::WebCanvas; |
48 using WebKit::WebMediaPlayer; | 49 using WebKit::WebMediaPlayer; |
49 using WebKit::WebRect; | 50 using WebKit::WebRect; |
50 using WebKit::WebSize; | 51 using WebKit::WebSize; |
51 using WebKit::WebString; | 52 using WebKit::WebString; |
52 using media::PipelineStatus; | 53 using media::PipelineStatus; |
53 | 54 |
54 namespace { | 55 namespace { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 pending_seek_(false), | 139 pending_seek_(false), |
139 pending_seek_seconds_(0.0f), | 140 pending_seek_seconds_(0.0f), |
140 client_(client), | 141 client_(client), |
141 delegate_(delegate), | 142 delegate_(delegate), |
142 media_log_(params.media_log()), | 143 media_log_(params.media_log()), |
143 accelerated_compositing_reported_(false), | 144 accelerated_compositing_reported_(false), |
144 incremented_externally_allocated_memory_(false), | 145 incremented_externally_allocated_memory_(false), |
145 is_local_source_(false), | 146 is_local_source_(false), |
146 supports_save_(true), | 147 supports_save_(true), |
147 starting_(false), | 148 starting_(false), |
148 pending_repaint_(false) { | 149 pending_repaint_(false), |
| 150 video_frame_provider_client_(NULL) { |
149 media_log_->AddEvent( | 151 media_log_->AddEvent( |
150 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 152 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
151 | 153 |
152 CHECK(media_thread_.Start()); | 154 CHECK(media_thread_.Start()); |
153 pipeline_ = new media::Pipeline( | 155 pipeline_ = new media::Pipeline( |
154 media_thread_.message_loop_proxy(), media_log_); | 156 media_thread_.message_loop_proxy(), media_log_); |
155 | 157 |
156 // Let V8 know we started new thread if we did not do it yet. | 158 // 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. | 159 // Made separate task to avoid deletion of player currently being created. |
158 // Also, delaying GC until after player starts gets rid of starting lag -- | 160 // 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())); | 206 new media::NullAudioSink(media_thread_.message_loop_proxy())); |
205 scoped_ptr<media::AudioRenderer> audio_renderer( | 207 scoped_ptr<media::AudioRenderer> audio_renderer( |
206 new media::AudioRendererImpl( | 208 new media::AudioRendererImpl( |
207 media_thread_.message_loop_proxy(), | 209 media_thread_.message_loop_proxy(), |
208 audio_source_provider_, | 210 audio_source_provider_, |
209 set_decryptor_ready_cb)); | 211 set_decryptor_ready_cb)); |
210 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); | 212 filter_collection_->SetAudioRenderer(audio_renderer.Pass()); |
211 } | 213 } |
212 | 214 |
213 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 215 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
| 216 SetVideoFrameProviderClient(NULL); |
| 217 GetClient()->setWebLayer(NULL); |
| 218 |
214 DCHECK(main_loop_->BelongsToCurrentThread()); | 219 DCHECK(main_loop_->BelongsToCurrentThread()); |
215 Destroy(); | 220 Destroy(); |
216 media_log_->AddEvent( | 221 media_log_->AddEvent( |
217 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); | 222 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
218 | 223 |
219 if (delegate_) | 224 if (delegate_) |
220 delegate_->PlayerGone(this); | 225 delegate_->PlayerGone(this); |
221 | 226 |
222 // Remove destruction observer if we're being destroyed but the main thread is | 227 // Remove destruction observer if we're being destroyed but the main thread is |
223 // still running. | 228 // still running. |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 return stats.audio_bytes_decoded; | 654 return stats.audio_bytes_decoded; |
650 } | 655 } |
651 | 656 |
652 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { | 657 unsigned WebMediaPlayerImpl::videoDecodedByteCount() const { |
653 DCHECK(main_loop_->BelongsToCurrentThread()); | 658 DCHECK(main_loop_->BelongsToCurrentThread()); |
654 | 659 |
655 media::PipelineStatistics stats = pipeline_->GetStatistics(); | 660 media::PipelineStatistics stats = pipeline_->GetStatistics(); |
656 return stats.video_bytes_decoded; | 661 return stats.video_bytes_decoded; |
657 } | 662 } |
658 | 663 |
659 WebKit::WebVideoFrame* WebMediaPlayerImpl::getCurrentFrame() { | 664 void WebMediaPlayerImpl::SetVideoFrameProviderClient( |
660 base::AutoLock auto_lock(lock_); | 665 cc::VideoFrameProvider::Client* client) { |
661 if (current_frame_) | 666 // This is called from both the main renderer thread and the compositor |
662 return new WebVideoFrameImpl(current_frame_); | 667 // thread (when the main thread is blocked). |
663 return NULL; | 668 if (video_frame_provider_client_) |
| 669 video_frame_provider_client_->StopUsingProvider(); |
| 670 video_frame_provider_client_ = client; |
664 } | 671 } |
665 | 672 |
666 void WebMediaPlayerImpl::putCurrentFrame( | 673 scoped_refptr<media::VideoFrame> WebMediaPlayerImpl::GetCurrentFrame() { |
667 WebKit::WebVideoFrame* web_video_frame) { | 674 base::AutoLock auto_lock(lock_); |
| 675 return current_frame_; |
| 676 } |
| 677 |
| 678 void WebMediaPlayerImpl::PutCurrentFrame( |
| 679 const scoped_refptr<media::VideoFrame>& frame) { |
668 if (!accelerated_compositing_reported_) { | 680 if (!accelerated_compositing_reported_) { |
669 accelerated_compositing_reported_ = true; | 681 accelerated_compositing_reported_ = true; |
670 DCHECK(frame_->view()->isAcceleratedCompositingActive()); | 682 DCHECK(frame_->view()->isAcceleratedCompositingActive()); |
671 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true); | 683 UMA_HISTOGRAM_BOOLEAN("Media.AcceleratedCompositingActive", true); |
672 } | 684 } |
673 delete web_video_frame; | |
674 } | 685 } |
675 | 686 |
676 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( | 687 bool WebMediaPlayerImpl::copyVideoTextureToPlatformTexture( |
677 WebKit::WebGraphicsContext3D* web_graphics_context, | 688 WebKit::WebGraphicsContext3D* web_graphics_context, |
678 unsigned int texture, | 689 unsigned int texture, |
679 unsigned int level, | 690 unsigned int level, |
680 unsigned int internal_format, | 691 unsigned int internal_format, |
681 bool premultiply_alpha, | 692 bool premultiply_alpha, |
682 bool flip_y) { | 693 bool flip_y) { |
683 scoped_refptr<media::VideoFrame> video_frame; | 694 scoped_refptr<media::VideoFrame> video_frame; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 Repaint(); | 966 Repaint(); |
956 } | 967 } |
957 | 968 |
958 void WebMediaPlayerImpl::OnPipelineBufferingState( | 969 void WebMediaPlayerImpl::OnPipelineBufferingState( |
959 media::Pipeline::BufferingState buffering_state) { | 970 media::Pipeline::BufferingState buffering_state) { |
960 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; | 971 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; |
961 | 972 |
962 switch (buffering_state) { | 973 switch (buffering_state) { |
963 case media::Pipeline::kHaveMetadata: | 974 case media::Pipeline::kHaveMetadata: |
964 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 975 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 976 |
| 977 if (hasVideo() && GetClient()->needsWebLayer()) { |
| 978 DCHECK(!video_weblayer_); |
| 979 video_weblayer_.reset( |
| 980 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); |
| 981 GetClient()->setWebLayer(video_weblayer_.get()); |
| 982 } |
965 break; | 983 break; |
966 case media::Pipeline::kPrerollCompleted: | 984 case media::Pipeline::kPrerollCompleted: |
967 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 985 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
968 break; | 986 break; |
969 } | 987 } |
970 | 988 |
971 // Repaint to trigger UI update. | 989 // Repaint to trigger UI update. |
972 Repaint(); | 990 Repaint(); |
973 } | 991 } |
974 | 992 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 DVLOG(1) << "SetNetworkState: " << state; | 1125 DVLOG(1) << "SetNetworkState: " << state; |
1108 network_state_ = state; | 1126 network_state_ = state; |
1109 // Always notify to ensure client has the latest value. | 1127 // Always notify to ensure client has the latest value. |
1110 GetClient()->networkStateChanged(); | 1128 GetClient()->networkStateChanged(); |
1111 } | 1129 } |
1112 | 1130 |
1113 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { | 1131 void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { |
1114 DCHECK(main_loop_->BelongsToCurrentThread()); | 1132 DCHECK(main_loop_->BelongsToCurrentThread()); |
1115 DVLOG(1) << "SetReadyState: " << state; | 1133 DVLOG(1) << "SetReadyState: " << state; |
1116 | 1134 |
1117 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing && | 1135 if (state == WebMediaPlayer::ReadyStateHaveEnoughData && |
1118 state >= WebMediaPlayer::ReadyStateHaveMetadata) { | 1136 is_local_source_ && |
1119 if (!hasVideo()) | 1137 network_state_ == WebMediaPlayer::NetworkStateLoading) |
1120 GetClient()->disableAcceleratedCompositing(); | 1138 SetNetworkState(WebMediaPlayer::NetworkStateLoaded); |
1121 } else if (state == WebMediaPlayer::ReadyStateHaveEnoughData) { | |
1122 if (is_local_source_ && | |
1123 network_state_ == WebMediaPlayer::NetworkStateLoading) { | |
1124 SetNetworkState(WebMediaPlayer::NetworkStateLoaded); | |
1125 } | |
1126 } | |
1127 | 1139 |
1128 ready_state_ = state; | 1140 ready_state_ = state; |
1129 // Always notify to ensure client has the latest value. | 1141 // Always notify to ensure client has the latest value. |
1130 GetClient()->readyStateChanged(); | 1142 GetClient()->readyStateChanged(); |
1131 } | 1143 } |
1132 | 1144 |
1133 void WebMediaPlayerImpl::Destroy() { | 1145 void WebMediaPlayerImpl::Destroy() { |
1134 DCHECK(main_loop_->BelongsToCurrentThread()); | 1146 DCHECK(main_loop_->BelongsToCurrentThread()); |
1135 | 1147 |
1136 // Abort any pending IO so stopping the pipeline doesn't get blocked. | 1148 // 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 | 1212 |
1201 if (pending_repaint_) | 1213 if (pending_repaint_) |
1202 return; | 1214 return; |
1203 | 1215 |
1204 pending_repaint_ = true; | 1216 pending_repaint_ = true; |
1205 main_loop_->PostTask(FROM_HERE, base::Bind( | 1217 main_loop_->PostTask(FROM_HERE, base::Bind( |
1206 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); | 1218 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); |
1207 } | 1219 } |
1208 | 1220 |
1209 } // namespace webkit_media | 1221 } // namespace webkit_media |
OLD | NEW |