Chromium Code Reviews| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 | 121 |
| 122 WebMediaPlayerImpl::WebMediaPlayerImpl( | 122 WebMediaPlayerImpl::WebMediaPlayerImpl( |
| 123 WebKit::WebFrame* frame, | 123 WebKit::WebFrame* frame, |
| 124 WebKit::WebMediaPlayerClient* client, | 124 WebKit::WebMediaPlayerClient* client, |
| 125 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 125 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
| 126 media::FilterCollection* collection, | 126 media::FilterCollection* collection, |
| 127 WebKit::WebAudioSourceProvider* audio_source_provider, | 127 WebKit::WebAudioSourceProvider* audio_source_provider, |
| 128 media::AudioRendererSink* audio_renderer_sink, | 128 media::AudioRendererSink* audio_renderer_sink, |
| 129 media::MessageLoopFactory* message_loop_factory, | 129 media::MessageLoopFactory* message_loop_factory, |
| 130 MediaStreamClient* media_stream_client, | 130 MediaStreamClient* media_stream_client, |
| 131 bool encrypted_media_enabled, | |
| 131 media::MediaLog* media_log) | 132 media::MediaLog* media_log) |
| 132 : frame_(frame), | 133 : frame_(frame), |
| 133 network_state_(WebMediaPlayer::NetworkStateEmpty), | 134 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 134 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 135 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 135 main_loop_(MessageLoop::current()), | 136 main_loop_(MessageLoop::current()), |
| 136 filter_collection_(collection), | 137 filter_collection_(collection), |
| 137 message_loop_factory_(message_loop_factory), | 138 message_loop_factory_(message_loop_factory), |
| 138 paused_(true), | 139 paused_(true), |
| 139 seeking_(false), | 140 seeking_(false), |
| 140 playback_rate_(0.0f), | 141 playback_rate_(0.0f), |
| 141 pending_seek_(false), | 142 pending_seek_(false), |
| 142 pending_seek_seconds_(0.0f), | 143 pending_seek_seconds_(0.0f), |
| 143 client_(client), | 144 client_(client), |
| 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 if (encrypted_media_enabled) { | |
|
scherkus (not reviewing)
2012/11/27 23:17:43
I believe you can simplify a lot of this CL by:
xhwang
2012/11/29 02:24:14
Done.
| |
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 | 269 |
| 269 // Media source pipelines can start immediately. | 270 // Media source pipelines can start immediately. |
| 270 if (!url.isEmpty() && url == GetClient()->sourceURL()) { | 271 if (!url.isEmpty() && url == GetClient()->sourceURL()) { |
| 271 chunk_demuxer_ = new media::ChunkDemuxer( | 272 chunk_demuxer_ = new media::ChunkDemuxer( |
| 272 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), | 273 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), |
| 273 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", "")); | 274 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", "")); |
| 274 | 275 |
| 275 BuildMediaSourceCollection(chunk_demuxer_, | 276 BuildMediaSourceCollection(chunk_demuxer_, |
| 276 message_loop_factory_.get(), | 277 message_loop_factory_.get(), |
| 277 filter_collection_.get(), | 278 filter_collection_.get(), |
| 278 &decryptor_); | 279 decryptor_.get()); |
| 279 supports_save_ = false; | 280 supports_save_ = false; |
| 280 StartPipeline(); | 281 StartPipeline(); |
| 281 return; | 282 return; |
| 282 } | 283 } |
| 283 | 284 |
| 284 // Otherwise it's a regular request which requires resolving the URL first. | 285 // Otherwise it's a regular request which requires resolving the URL first. |
| 285 proxy_->set_data_source( | 286 proxy_->set_data_source( |
| 286 new BufferedDataSource(main_loop_, frame_, media_log_, | 287 new BufferedDataSource(main_loop_, frame_, media_log_, |
| 287 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, | 288 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, |
| 288 AsWeakPtr()))); | 289 AsWeakPtr()))); |
| 289 proxy_->data_source()->Initialize( | 290 proxy_->data_source()->Initialize( |
| 290 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 291 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
| 291 base::Bind( | 292 base::Bind( |
| 292 &WebMediaPlayerImpl::DataSourceInitialized, | 293 &WebMediaPlayerImpl::DataSourceInitialized, |
| 293 AsWeakPtr(), gurl)); | 294 AsWeakPtr(), gurl)); |
| 294 | 295 |
| 295 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); | 296 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); |
| 296 | 297 |
| 297 BuildDefaultCollection(proxy_->data_source(), | 298 BuildDefaultCollection(proxy_->data_source(), |
| 298 message_loop_factory_.get(), | 299 message_loop_factory_.get(), |
| 299 filter_collection_.get(), | 300 filter_collection_.get(), |
| 300 &decryptor_); | 301 decryptor_.get()); |
| 301 } | 302 } |
| 302 | 303 |
| 303 void WebMediaPlayerImpl::cancelLoad() { | 304 void WebMediaPlayerImpl::cancelLoad() { |
| 304 DCHECK_EQ(main_loop_, MessageLoop::current()); | 305 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 305 } | 306 } |
| 306 | 307 |
| 307 void WebMediaPlayerImpl::play() { | 308 void WebMediaPlayerImpl::play() { |
| 308 DCHECK_EQ(main_loop_, MessageLoop::current()); | 309 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 309 | 310 |
| 310 paused_ = false; | 311 paused_ = false; |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 else if (key_system != current_key_system_) | 799 else if (key_system != current_key_system_) |
| 799 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 800 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| 800 | 801 |
| 801 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " | 802 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " |
| 802 << std::string(reinterpret_cast<const char*>(init_data), | 803 << std::string(reinterpret_cast<const char*>(init_data), |
| 803 static_cast<size_t>(init_data_length)); | 804 static_cast<size_t>(init_data_length)); |
| 804 | 805 |
| 805 // TODO(xhwang): We assume all streams are from the same container (thus have | 806 // 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 | 807 // the same "type") for now. In the future, the "type" should be passed down |
| 807 // from the application. | 808 // from the application. |
| 808 if (!decryptor_.GenerateKeyRequest(key_system.utf8(), | 809 if (!decryptor_->GenerateKeyRequest(key_system.utf8(), |
| 809 init_data_type_, | 810 init_data_type_, |
| 810 init_data, init_data_length)) { | 811 init_data, init_data_length)) { |
| 811 current_key_system_.reset(); | 812 current_key_system_.reset(); |
| 812 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 813 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 813 } | 814 } |
| 814 | 815 |
| 815 return WebMediaPlayer::MediaKeyExceptionNoError; | 816 return WebMediaPlayer::MediaKeyExceptionNoError; |
| 816 } | 817 } |
| 817 | 818 |
| 818 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( | 819 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 845 if (current_key_system_.isEmpty() || key_system != current_key_system_) | 846 if (current_key_system_.isEmpty() || key_system != current_key_system_) |
| 846 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 847 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| 847 | 848 |
| 848 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " | 849 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " |
| 849 << std::string(reinterpret_cast<const char*>(key), | 850 << std::string(reinterpret_cast<const char*>(key), |
| 850 static_cast<size_t>(key_length)) << ", " | 851 static_cast<size_t>(key_length)) << ", " |
| 851 << std::string(reinterpret_cast<const char*>(init_data), | 852 << std::string(reinterpret_cast<const char*>(init_data), |
| 852 static_cast<size_t>(init_data_length)) | 853 static_cast<size_t>(init_data_length)) |
| 853 << " [" << session_id.utf8().data() << "]"; | 854 << " [" << session_id.utf8().data() << "]"; |
| 854 | 855 |
| 855 decryptor_.AddKey(key_system.utf8(), key, key_length, | 856 decryptor_->AddKey(key_system.utf8(), key, key_length, |
| 856 init_data, init_data_length, session_id.utf8()); | 857 init_data, init_data_length, session_id.utf8()); |
| 857 return WebMediaPlayer::MediaKeyExceptionNoError; | 858 return WebMediaPlayer::MediaKeyExceptionNoError; |
| 858 } | 859 } |
| 859 | 860 |
| 860 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( | 861 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( |
| 861 const WebString& key_system, | 862 const WebString& key_system, |
| 862 const WebString& session_id) { | 863 const WebString& session_id) { |
| 863 WebMediaPlayer::MediaKeyException e = | 864 WebMediaPlayer::MediaKeyException e = |
| 864 CancelKeyRequestInternal(key_system, session_id); | 865 CancelKeyRequestInternal(key_system, session_id); |
| 865 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); | 866 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); |
| 866 return e; | 867 return e; |
| 867 } | 868 } |
| 868 | 869 |
| 869 WebMediaPlayer::MediaKeyException | 870 WebMediaPlayer::MediaKeyException |
| 870 WebMediaPlayerImpl::CancelKeyRequestInternal( | 871 WebMediaPlayerImpl::CancelKeyRequestInternal( |
| 871 const WebString& key_system, | 872 const WebString& key_system, |
| 872 const WebString& session_id) { | 873 const WebString& session_id) { |
| 873 if (!IsSupportedKeySystem(key_system)) | 874 if (!IsSupportedKeySystem(key_system)) |
| 874 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 875 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 875 | 876 |
| 876 if (current_key_system_.isEmpty() || key_system != current_key_system_) | 877 if (current_key_system_.isEmpty() || key_system != current_key_system_) |
| 877 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 878 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| 878 | 879 |
| 879 decryptor_.CancelKeyRequest(key_system.utf8(), session_id.utf8()); | 880 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8()); |
| 880 return WebMediaPlayer::MediaKeyExceptionNoError; | 881 return WebMediaPlayer::MediaKeyExceptionNoError; |
| 881 } | 882 } |
| 882 | 883 |
| 883 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { | 884 void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { |
| 884 Destroy(); | 885 Destroy(); |
| 885 main_loop_ = NULL; | 886 main_loop_ = NULL; |
| 886 } | 887 } |
| 887 | 888 |
| 888 void WebMediaPlayerImpl::Repaint() { | 889 void WebMediaPlayerImpl::Repaint() { |
| 889 DCHECK_EQ(main_loop_, MessageLoop::current()); | 890 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1018 WebString::fromUTF8(session_id)); | 1019 WebString::fromUTF8(session_id)); |
| 1019 } | 1020 } |
| 1020 | 1021 |
| 1021 void WebMediaPlayerImpl::OnNeedKey(const std::string& key_system, | 1022 void WebMediaPlayerImpl::OnNeedKey(const std::string& key_system, |
| 1022 const std::string& session_id, | 1023 const std::string& session_id, |
| 1023 const std::string& type, | 1024 const std::string& type, |
| 1024 scoped_array<uint8> init_data, | 1025 scoped_array<uint8> init_data, |
| 1025 int init_data_size) { | 1026 int init_data_size) { |
| 1026 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1027 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 1027 | 1028 |
| 1029 // Do not fire NeedKey event if encrypted media is not enabled. | |
| 1030 if (!decryptor_) | |
| 1031 return; | |
| 1032 | |
| 1028 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); | 1033 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); |
| 1029 | 1034 |
| 1030 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); | 1035 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); |
| 1031 if (init_data_type_.empty()) | 1036 if (init_data_type_.empty()) |
| 1032 init_data_type_ = type; | 1037 init_data_type_ = type; |
| 1033 | 1038 |
| 1034 GetClient()->keyNeeded(WebString::fromUTF8(key_system), | 1039 GetClient()->keyNeeded(WebString::fromUTF8(key_system), |
| 1035 WebString::fromUTF8(session_id), | 1040 WebString::fromUTF8(session_id), |
| 1036 init_data.get(), | 1041 init_data.get(), |
| 1037 init_data_size); | 1042 init_data_size); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1193 return audio_source_provider_; | 1198 return audio_source_provider_; |
| 1194 } | 1199 } |
| 1195 | 1200 |
| 1196 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1201 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
| 1197 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1202 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 1198 incremented_externally_allocated_memory_ = true; | 1203 incremented_externally_allocated_memory_ = true; |
| 1199 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1204 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 1200 } | 1205 } |
| 1201 | 1206 |
| 1202 } // namespace webkit_media | 1207 } // namespace webkit_media |
| OLD | NEW |