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