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 17 matching lines...) Expand all Loading... |
28 #include "media/filters/video_renderer_base.h" | 28 #include "media/filters/video_renderer_base.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
35 #include "v8/include/v8.h" | 35 #include "v8/include/v8.h" |
36 #include "webkit/media/buffered_data_source.h" | 36 #include "webkit/media/buffered_data_source.h" |
37 #include "webkit/media/filter_helpers.h" | 37 #include "webkit/media/filter_helpers.h" |
| 38 #include "webkit/media/media_switches.h" |
38 #include "webkit/media/webmediaplayer_delegate.h" | 39 #include "webkit/media/webmediaplayer_delegate.h" |
39 #include "webkit/media/webmediaplayer_proxy.h" | 40 #include "webkit/media/webmediaplayer_proxy.h" |
40 #include "webkit/media/webmediaplayer_util.h" | 41 #include "webkit/media/webmediaplayer_util.h" |
41 #include "webkit/media/webvideoframe_impl.h" | 42 #include "webkit/media/webvideoframe_impl.h" |
42 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | 43 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
43 | 44 |
44 using WebKit::WebCanvas; | 45 using WebKit::WebCanvas; |
45 using WebKit::WebMediaPlayer; | 46 using WebKit::WebMediaPlayer; |
46 using WebKit::WebRect; | 47 using WebKit::WebRect; |
47 using WebKit::WebSize; | 48 using WebKit::WebSize; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 proxy_(new WebMediaPlayerProxy(main_loop_->message_loop_proxy(), this)), | 145 proxy_(new WebMediaPlayerProxy(main_loop_->message_loop_proxy(), this)), |
145 delegate_(delegate), | 146 delegate_(delegate), |
146 media_stream_client_(media_stream_client), | 147 media_stream_client_(media_stream_client), |
147 media_log_(media_log), | 148 media_log_(media_log), |
148 accelerated_compositing_reported_(false), | 149 accelerated_compositing_reported_(false), |
149 incremented_externally_allocated_memory_(false), | 150 incremented_externally_allocated_memory_(false), |
150 audio_source_provider_(audio_source_provider), | 151 audio_source_provider_(audio_source_provider), |
151 audio_renderer_sink_(audio_renderer_sink), | 152 audio_renderer_sink_(audio_renderer_sink), |
152 is_local_source_(false), | 153 is_local_source_(false), |
153 supports_save_(true), | 154 supports_save_(true), |
154 decryptor_(message_loop_factory_->GetMessageLoop( | |
155 media::MessageLoopFactory::kPipeline), | |
156 proxy_.get(), | |
157 client, | |
158 frame), | |
159 starting_(false) { | 155 starting_(false) { |
160 media_log_->AddEvent( | 156 media_log_->AddEvent( |
161 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 157 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
162 | 158 |
163 scoped_refptr<base::MessageLoopProxy> pipeline_message_loop = | 159 scoped_refptr<base::MessageLoopProxy> pipeline_message_loop = |
164 message_loop_factory_->GetMessageLoop( | 160 message_loop_factory_->GetMessageLoop( |
165 media::MessageLoopFactory::kPipeline); | 161 media::MessageLoopFactory::kPipeline); |
166 pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_); | 162 pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_); |
167 | 163 |
168 // Let V8 know we started new thread if we did not did it yet. | 164 // Let V8 know we started new thread if we did not did it yet. |
(...skipping 15 matching lines...) Expand all Loading... |
184 new media::VideoRendererBase( | 180 new media::VideoRendererBase( |
185 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), | 181 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), |
186 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::SetOpaque), | 182 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::SetOpaque), |
187 true); | 183 true); |
188 filter_collection_->AddVideoRenderer(video_renderer); | 184 filter_collection_->AddVideoRenderer(video_renderer); |
189 proxy_->set_frame_provider(video_renderer); | 185 proxy_->set_frame_provider(video_renderer); |
190 | 186 |
191 // Create default audio renderer. | 187 // Create default audio renderer. |
192 filter_collection_->AddAudioRenderer( | 188 filter_collection_->AddAudioRenderer( |
193 new media::AudioRendererImpl(new media::NullAudioSink())); | 189 new media::AudioRendererImpl(new media::NullAudioSink())); |
| 190 |
| 191 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 192 if (cmd_line->HasSwitch(switches::kEnableEncryptedMedia)) { |
| 193 decryptor_.reset(new ProxyDecryptor(message_loop_factory_->GetMessageLoop( |
| 194 media::MessageLoopFactory::kPipeline), proxy_.get(), client, frame)); |
| 195 } |
194 } | 196 } |
195 | 197 |
196 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 198 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
197 DCHECK_EQ(main_loop_, MessageLoop::current()); | 199 DCHECK_EQ(main_loop_, MessageLoop::current()); |
198 Destroy(); | 200 Destroy(); |
199 media_log_->AddEvent( | 201 media_log_->AddEvent( |
200 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); | 202 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
201 | 203 |
202 if (delegate_) | 204 if (delegate_) |
203 delegate_->PlayerGone(this); | 205 delegate_->PlayerGone(this); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 270 |
269 // Media source pipelines can start immediately. | 271 // Media source pipelines can start immediately. |
270 if (!url.isEmpty() && url == GetClient()->sourceURL()) { | 272 if (!url.isEmpty() && url == GetClient()->sourceURL()) { |
271 chunk_demuxer_ = new media::ChunkDemuxer( | 273 chunk_demuxer_ = new media::ChunkDemuxer( |
272 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), | 274 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), |
273 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", "")); | 275 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", "")); |
274 | 276 |
275 BuildMediaSourceCollection(chunk_demuxer_, | 277 BuildMediaSourceCollection(chunk_demuxer_, |
276 message_loop_factory_.get(), | 278 message_loop_factory_.get(), |
277 filter_collection_.get(), | 279 filter_collection_.get(), |
278 &decryptor_); | 280 decryptor_.get()); |
279 supports_save_ = false; | 281 supports_save_ = false; |
280 StartPipeline(); | 282 StartPipeline(); |
281 return; | 283 return; |
282 } | 284 } |
283 | 285 |
284 // Otherwise it's a regular request which requires resolving the URL first. | 286 // Otherwise it's a regular request which requires resolving the URL first. |
285 proxy_->set_data_source( | 287 proxy_->set_data_source( |
286 new BufferedDataSource(main_loop_, frame_, media_log_, | 288 new BufferedDataSource(main_loop_, frame_, media_log_, |
287 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, | 289 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, |
288 AsWeakPtr()))); | 290 AsWeakPtr()))); |
289 proxy_->data_source()->Initialize( | 291 proxy_->data_source()->Initialize( |
290 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 292 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
291 base::Bind( | 293 base::Bind( |
292 &WebMediaPlayerImpl::DataSourceInitialized, | 294 &WebMediaPlayerImpl::DataSourceInitialized, |
293 AsWeakPtr(), gurl)); | 295 AsWeakPtr(), gurl)); |
294 | 296 |
295 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); | 297 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); |
296 | 298 |
297 BuildDefaultCollection(proxy_->data_source(), | 299 BuildDefaultCollection(proxy_->data_source(), |
298 message_loop_factory_.get(), | 300 message_loop_factory_.get(), |
299 filter_collection_.get(), | 301 filter_collection_.get(), |
300 &decryptor_); | 302 decryptor_.get()); |
301 } | 303 } |
302 | 304 |
303 void WebMediaPlayerImpl::cancelLoad() { | 305 void WebMediaPlayerImpl::cancelLoad() { |
304 DCHECK_EQ(main_loop_, MessageLoop::current()); | 306 DCHECK_EQ(main_loop_, MessageLoop::current()); |
305 } | 307 } |
306 | 308 |
307 void WebMediaPlayerImpl::play() { | 309 void WebMediaPlayerImpl::play() { |
308 DCHECK_EQ(main_loop_, MessageLoop::current()); | 310 DCHECK_EQ(main_loop_, MessageLoop::current()); |
309 | 311 |
310 paused_ = false; | 312 paused_ = false; |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 else if (key_system != current_key_system_) | 800 else if (key_system != current_key_system_) |
799 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 801 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
800 | 802 |
801 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " | 803 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " |
802 << std::string(reinterpret_cast<const char*>(init_data), | 804 << std::string(reinterpret_cast<const char*>(init_data), |
803 static_cast<size_t>(init_data_length)); | 805 static_cast<size_t>(init_data_length)); |
804 | 806 |
805 // TODO(xhwang): We assume all streams are from the same container (thus have | 807 // TODO(xhwang): We assume all streams are from the same container (thus have |
806 // the same "type") for now. In the future, the "type" should be passed down | 808 // the same "type") for now. In the future, the "type" should be passed down |
807 // from the application. | 809 // from the application. |
808 if (!decryptor_.GenerateKeyRequest(key_system.utf8(), | 810 if (!decryptor_->GenerateKeyRequest(key_system.utf8(), |
809 init_data_type_, | 811 init_data_type_, |
810 init_data, init_data_length)) { | 812 init_data, init_data_length)) { |
811 current_key_system_.reset(); | 813 current_key_system_.reset(); |
812 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 814 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
813 } | 815 } |
814 | 816 |
815 return WebMediaPlayer::MediaKeyExceptionNoError; | 817 return WebMediaPlayer::MediaKeyExceptionNoError; |
816 } | 818 } |
817 | 819 |
818 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( | 820 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( |
(...skipping 26 matching lines...) Expand all Loading... |
845 if (current_key_system_.isEmpty() || key_system != current_key_system_) | 847 if (current_key_system_.isEmpty() || key_system != current_key_system_) |
846 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 848 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
847 | 849 |
848 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " | 850 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " |
849 << std::string(reinterpret_cast<const char*>(key), | 851 << std::string(reinterpret_cast<const char*>(key), |
850 static_cast<size_t>(key_length)) << ", " | 852 static_cast<size_t>(key_length)) << ", " |
851 << std::string(reinterpret_cast<const char*>(init_data), | 853 << std::string(reinterpret_cast<const char*>(init_data), |
852 static_cast<size_t>(init_data_length)) | 854 static_cast<size_t>(init_data_length)) |
853 << " [" << session_id.utf8().data() << "]"; | 855 << " [" << session_id.utf8().data() << "]"; |
854 | 856 |
855 decryptor_.AddKey(key_system.utf8(), key, key_length, | 857 decryptor_->AddKey(key_system.utf8(), key, key_length, |
856 init_data, init_data_length, session_id.utf8()); | 858 init_data, init_data_length, session_id.utf8()); |
857 return WebMediaPlayer::MediaKeyExceptionNoError; | 859 return WebMediaPlayer::MediaKeyExceptionNoError; |
858 } | 860 } |
859 | 861 |
860 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( | 862 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( |
861 const WebString& key_system, | 863 const WebString& key_system, |
862 const WebString& session_id) { | 864 const WebString& session_id) { |
863 WebMediaPlayer::MediaKeyException e = | 865 WebMediaPlayer::MediaKeyException e = |
864 CancelKeyRequestInternal(key_system, session_id); | 866 CancelKeyRequestInternal(key_system, session_id); |
865 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); | 867 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); |
866 return e; | 868 return e; |
867 } | 869 } |
868 | 870 |
869 WebMediaPlayer::MediaKeyException | 871 WebMediaPlayer::MediaKeyException |
870 WebMediaPlayerImpl::CancelKeyRequestInternal( | 872 WebMediaPlayerImpl::CancelKeyRequestInternal( |
871 const WebString& key_system, | 873 const WebString& key_system, |
872 const WebString& session_id) { | 874 const WebString& session_id) { |
873 if (!IsSupportedKeySystem(key_system)) | 875 if (!IsSupportedKeySystem(key_system)) |
874 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 876 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
875 | 877 |
876 if (current_key_system_.isEmpty() || key_system != current_key_system_) | 878 if (current_key_system_.isEmpty() || key_system != current_key_system_) |
877 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 879 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
878 | 880 |
879 decryptor_.CancelKeyRequest(key_system.utf8(), session_id.utf8()); | 881 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8()); |
880 return WebMediaPlayer::MediaKeyExceptionNoError; | 882 return WebMediaPlayer::MediaKeyExceptionNoError; |
881 } | 883 } |
882 | 884 |
883 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { | 885 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { |
884 Destroy(); | 886 Destroy(); |
885 main_loop_ = NULL; | 887 main_loop_ = NULL; |
886 } | 888 } |
887 | 889 |
888 void WebMediaPlayerImpl::Repaint() { | 890 void WebMediaPlayerImpl::Repaint() { |
889 DCHECK_EQ(main_loop_, MessageLoop::current()); | 891 DCHECK_EQ(main_loop_, MessageLoop::current()); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 WebString::fromUTF8(session_id)); | 1020 WebString::fromUTF8(session_id)); |
1019 } | 1021 } |
1020 | 1022 |
1021 void WebMediaPlayerImpl::OnNeedKey(const std::string& key_system, | 1023 void WebMediaPlayerImpl::OnNeedKey(const std::string& key_system, |
1022 const std::string& session_id, | 1024 const std::string& session_id, |
1023 const std::string& type, | 1025 const std::string& type, |
1024 scoped_array<uint8> init_data, | 1026 scoped_array<uint8> init_data, |
1025 int init_data_size) { | 1027 int init_data_size) { |
1026 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1028 DCHECK_EQ(main_loop_, MessageLoop::current()); |
1027 | 1029 |
| 1030 // Do not fire NeedKey event if encrypted media is not enabled. |
| 1031 if (!decryptor_) |
| 1032 return; |
| 1033 |
1028 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); | 1034 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); |
1029 | 1035 |
1030 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); | 1036 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); |
1031 if (init_data_type_.empty()) | 1037 if (init_data_type_.empty()) |
1032 init_data_type_ = type; | 1038 init_data_type_ = type; |
1033 | 1039 |
1034 GetClient()->keyNeeded(WebString::fromUTF8(key_system), | 1040 GetClient()->keyNeeded(WebString::fromUTF8(key_system), |
1035 WebString::fromUTF8(session_id), | 1041 WebString::fromUTF8(session_id), |
1036 init_data.get(), | 1042 init_data.get(), |
1037 init_data_size); | 1043 init_data_size); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 return audio_source_provider_; | 1199 return audio_source_provider_; |
1194 } | 1200 } |
1195 | 1201 |
1196 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1202 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
1197 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1203 DCHECK_EQ(main_loop_, MessageLoop::current()); |
1198 incremented_externally_allocated_memory_ = true; | 1204 incremented_externally_allocated_memory_ = true; |
1199 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1205 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
1200 } | 1206 } |
1201 | 1207 |
1202 } // namespace webkit_media | 1208 } // namespace webkit_media |
OLD | NEW |