OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/media/webmediaplayer_impl.h" | 5 #include "content/renderer/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> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 143 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
144 const WebMediaPlayerParams& params) | 144 const WebMediaPlayerParams& params) |
145 : frame_(frame), | 145 : frame_(frame), |
146 network_state_(WebMediaPlayer::NetworkStateEmpty), | 146 network_state_(WebMediaPlayer::NetworkStateEmpty), |
147 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 147 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
148 main_loop_(base::MessageLoopProxy::current()), | 148 main_loop_(base::MessageLoopProxy::current()), |
149 media_loop_( | 149 media_loop_( |
150 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy()), | 150 RenderThreadImpl::current()->GetMediaThreadMessageLoopProxy()), |
151 media_log_(new RenderMediaLog()), | 151 media_log_(new RenderMediaLog()), |
152 pipeline_(media_loop_, media_log_.get()), | 152 pipeline_(media_loop_, media_log_.get()), |
153 pipeline_metadata_(), | |
scherkus (not reviewing)
2014/03/21 22:26:10
nit: no need -- C++ initializer lists will call th
sandersd (OOO until July 31)
2014/03/21 23:30:35
Done.
| |
153 paused_(true), | 154 paused_(true), |
154 seeking_(false), | 155 seeking_(false), |
155 playback_rate_(0.0f), | 156 playback_rate_(0.0f), |
156 pending_seek_(false), | 157 pending_seek_(false), |
157 pending_seek_seconds_(0.0f), | 158 pending_seek_seconds_(0.0f), |
158 client_(client), | 159 client_(client), |
159 delegate_(delegate), | 160 delegate_(delegate), |
160 defer_load_cb_(params.defer_load_cb()), | 161 defer_load_cb_(params.defer_load_cb()), |
161 accelerated_compositing_reported_(false), | 162 accelerated_compositing_reported_(false), |
162 incremented_externally_allocated_memory_(false), | 163 incremented_externally_allocated_memory_(false), |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { | 430 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { |
430 DCHECK(main_loop_->BelongsToCurrentThread()); | 431 DCHECK(main_loop_->BelongsToCurrentThread()); |
431 | 432 |
432 if (data_source_) | 433 if (data_source_) |
433 data_source_->SetPreload(static_cast<content::Preload>(preload)); | 434 data_source_->SetPreload(static_cast<content::Preload>(preload)); |
434 } | 435 } |
435 | 436 |
436 bool WebMediaPlayerImpl::hasVideo() const { | 437 bool WebMediaPlayerImpl::hasVideo() const { |
437 DCHECK(main_loop_->BelongsToCurrentThread()); | 438 DCHECK(main_loop_->BelongsToCurrentThread()); |
438 | 439 |
439 return pipeline_.HasVideo(); | 440 return pipeline_metadata_.has_video_; |
440 } | 441 } |
441 | 442 |
442 bool WebMediaPlayerImpl::hasAudio() const { | 443 bool WebMediaPlayerImpl::hasAudio() const { |
443 DCHECK(main_loop_->BelongsToCurrentThread()); | 444 DCHECK(main_loop_->BelongsToCurrentThread()); |
444 | 445 |
445 return pipeline_.HasAudio(); | 446 return pipeline_metadata_.has_audio_; |
446 } | 447 } |
447 | 448 |
448 blink::WebSize WebMediaPlayerImpl::naturalSize() const { | 449 blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
449 DCHECK(main_loop_->BelongsToCurrentThread()); | 450 DCHECK(main_loop_->BelongsToCurrentThread()); |
450 | 451 |
451 return blink::WebSize(natural_size_); | 452 return blink::WebSize(pipeline_metadata_.natural_size_); |
452 } | 453 } |
453 | 454 |
454 bool WebMediaPlayerImpl::paused() const { | 455 bool WebMediaPlayerImpl::paused() const { |
455 DCHECK(main_loop_->BelongsToCurrentThread()); | 456 DCHECK(main_loop_->BelongsToCurrentThread()); |
456 | 457 |
457 return pipeline_.GetPlaybackRate() == 0.0f; | 458 return pipeline_.GetPlaybackRate() == 0.0f; |
458 } | 459 } |
459 | 460 |
460 bool WebMediaPlayerImpl::seeking() const { | 461 bool WebMediaPlayerImpl::seeking() const { |
461 DCHECK(main_loop_->BelongsToCurrentThread()); | 462 DCHECK(main_loop_->BelongsToCurrentThread()); |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 SetNetworkState(PipelineErrorToNetworkState(error)); | 962 SetNetworkState(PipelineErrorToNetworkState(error)); |
962 | 963 |
963 if (error == media::PIPELINE_ERROR_DECRYPT) | 964 if (error == media::PIPELINE_ERROR_DECRYPT) |
964 EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1); | 965 EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1); |
965 | 966 |
966 // TODO(scherkus): This should be handled by HTMLMediaElement and controls | 967 // TODO(scherkus): This should be handled by HTMLMediaElement and controls |
967 // should know when to invalidate themselves http://crbug.com/337015 | 968 // should know when to invalidate themselves http://crbug.com/337015 |
968 InvalidateOnMainThread(); | 969 InvalidateOnMainThread(); |
969 } | 970 } |
970 | 971 |
971 void WebMediaPlayerImpl::OnPipelineBufferingState( | 972 void WebMediaPlayerImpl::OnPipelineHaveMetadata( |
972 media::Pipeline::BufferingState buffering_state) { | 973 media::PipelineMetadata metadata) { |
973 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; | 974 DVLOG(1) << "OnPipelineHaveMetadata"; |
974 | 975 |
975 switch (buffering_state) { | 976 pipeline_metadata_ = metadata; |
976 case media::Pipeline::kHaveMetadata: | |
977 // TODO(scherkus): Would be better to have a metadata changed callback | |
978 // that contained the size information as well whether audio/video is | |
979 // present. Doing so would let us remove more methods off Pipeline. | |
980 natural_size_ = pipeline_.GetInitialNaturalSize(); | |
981 | 977 |
982 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 978 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
983 | 979 |
984 if (hasVideo() && client_->needsWebLayerForVideo()) { | 980 if (hasVideo() && client_->needsWebLayerForVideo()) { |
985 DCHECK(!video_weblayer_); | 981 DCHECK(!video_weblayer_); |
986 video_weblayer_.reset( | 982 video_weblayer_.reset( |
987 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); | 983 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); |
988 client_->setWebLayer(video_weblayer_.get()); | 984 client_->setWebLayer(video_weblayer_.get()); |
989 } | |
990 break; | |
991 case media::Pipeline::kPrerollCompleted: | |
992 // Only transition to ReadyStateHaveEnoughData if we don't have | |
993 // any pending seeks because the transition can cause Blink to | |
994 // report that the most recent seek has completed. | |
995 if (!pending_seek_) | |
996 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | |
997 break; | |
998 } | 985 } |
999 | 986 |
1000 // TODO(scherkus): This should be handled by HTMLMediaElement and controls | 987 // TODO(scherkus): This should be handled by HTMLMediaElement and controls |
1001 // should know when to invalidate themselves http://crbug.com/337015 | 988 // should know when to invalidate themselves http://crbug.com/337015 |
1002 InvalidateOnMainThread(); | 989 InvalidateOnMainThread(); |
1003 } | 990 } |
1004 | 991 |
992 void WebMediaPlayerImpl::OnPipelinePrerollCompleted() { | |
993 DVLOG(1) << "OnPipelinePrerollCompleted"; | |
994 | |
995 // Only transition to ReadyStateHaveEnoughData if we don't have | |
996 // any pending seeks because the transition can cause Blink to | |
997 // report that the most recent seek has completed. | |
998 if (!pending_seek_) { | |
999 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | |
1000 | |
1001 // TODO(scherkus): This should be handled by HTMLMediaElement and controls | |
1002 // should know when to invalidate themselves http://crbug.com/337015 | |
1003 InvalidateOnMainThread(); | |
1004 } | |
1005 } | |
1006 | |
1005 void WebMediaPlayerImpl::OnDemuxerOpened() { | 1007 void WebMediaPlayerImpl::OnDemuxerOpened() { |
1006 DCHECK(main_loop_->BelongsToCurrentThread()); | 1008 DCHECK(main_loop_->BelongsToCurrentThread()); |
1007 client_->mediaSourceOpened(new WebMediaSourceImpl( | 1009 client_->mediaSourceOpened(new WebMediaSourceImpl( |
1008 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_))); | 1010 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_))); |
1009 } | 1011 } |
1010 | 1012 |
1011 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) { | 1013 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) { |
1012 DCHECK(main_loop_->BelongsToCurrentThread()); | 1014 DCHECK(main_loop_->BelongsToCurrentThread()); |
1013 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 1015 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
1014 client_->keyAdded( | 1016 client_->keyAdded( |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1213 filter_collection->SetTextRenderer(text_renderer.Pass()); | 1215 filter_collection->SetTextRenderer(text_renderer.Pass()); |
1214 } | 1216 } |
1215 | 1217 |
1216 // ... and we're ready to go! | 1218 // ... and we're ready to go! |
1217 starting_ = true; | 1219 starting_ = true; |
1218 pipeline_.Start( | 1220 pipeline_.Start( |
1219 filter_collection.Pass(), | 1221 filter_collection.Pass(), |
1220 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), | 1222 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), |
1221 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), | 1223 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), |
1222 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), | 1224 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), |
1223 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingState), | 1225 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineHaveMetadata), |
1226 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelinePrerollCompleted), | |
1224 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange)); | 1227 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange)); |
1225 } | 1228 } |
1226 | 1229 |
1227 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 1230 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
1228 DCHECK(main_loop_->BelongsToCurrentThread()); | 1231 DCHECK(main_loop_->BelongsToCurrentThread()); |
1229 DVLOG(1) << "SetNetworkState: " << state; | 1232 DVLOG(1) << "SetNetworkState: " << state; |
1230 network_state_ = state; | 1233 network_state_ = state; |
1231 // Always notify to ensure client has the latest value. | 1234 // Always notify to ensure client has the latest value. |
1232 client_->networkStateChanged(); | 1235 client_->networkStateChanged(); |
1233 } | 1236 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1275 client_->durationChanged(); | 1278 client_->durationChanged(); |
1276 } | 1279 } |
1277 | 1280 |
1278 void WebMediaPlayerImpl::OnNaturalSizeChange(gfx::Size size) { | 1281 void WebMediaPlayerImpl::OnNaturalSizeChange(gfx::Size size) { |
1279 DCHECK(main_loop_->BelongsToCurrentThread()); | 1282 DCHECK(main_loop_->BelongsToCurrentThread()); |
1280 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); | 1283 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
1281 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); | 1284 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); |
1282 | 1285 |
1283 media_log_->AddEvent( | 1286 media_log_->AddEvent( |
1284 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); | 1287 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); |
1285 natural_size_ = size; | 1288 pipeline_metadata_.natural_size_ = size; |
1286 | 1289 |
1287 client_->sizeChanged(); | 1290 client_->sizeChanged(); |
1288 } | 1291 } |
1289 | 1292 |
1290 void WebMediaPlayerImpl::FrameReady( | 1293 void WebMediaPlayerImpl::FrameReady( |
1291 const scoped_refptr<media::VideoFrame>& frame) { | 1294 const scoped_refptr<media::VideoFrame>& frame) { |
1292 // TODO(scherkus): Today we always invalidate on the main thread even when | 1295 // TODO(scherkus): Today we always invalidate on the main thread even when |
1293 // compositing is available, which is less efficient and involves more | 1296 // compositing is available, which is less efficient and involves more |
1294 // thread hops. Refer to http://crbug.com/335345 for details. | 1297 // thread hops. Refer to http://crbug.com/335345 for details. |
1295 painter_.UpdateCurrentFrame(frame); | 1298 painter_.UpdateCurrentFrame(frame); |
(...skipping 27 matching lines...) Expand all Loading... | |
1323 | 1326 |
1324 if (web_cdm_) { | 1327 if (web_cdm_) { |
1325 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1328 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); |
1326 return; | 1329 return; |
1327 } | 1330 } |
1328 | 1331 |
1329 decryptor_ready_cb_ = decryptor_ready_cb; | 1332 decryptor_ready_cb_ = decryptor_ready_cb; |
1330 } | 1333 } |
1331 | 1334 |
1332 } // namespace content | 1335 } // namespace content |
OLD | NEW |