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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { | 429 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { |
430 DCHECK(main_loop_->BelongsToCurrentThread()); | 430 DCHECK(main_loop_->BelongsToCurrentThread()); |
431 | 431 |
432 if (data_source_) | 432 if (data_source_) |
433 data_source_->SetPreload(static_cast<content::Preload>(preload)); | 433 data_source_->SetPreload(static_cast<content::Preload>(preload)); |
434 } | 434 } |
435 | 435 |
436 bool WebMediaPlayerImpl::hasVideo() const { | 436 bool WebMediaPlayerImpl::hasVideo() const { |
437 DCHECK(main_loop_->BelongsToCurrentThread()); | 437 DCHECK(main_loop_->BelongsToCurrentThread()); |
438 | 438 |
439 return pipeline_.HasVideo(); | 439 return pipeline_metadata_.has_video; |
440 } | 440 } |
441 | 441 |
442 bool WebMediaPlayerImpl::hasAudio() const { | 442 bool WebMediaPlayerImpl::hasAudio() const { |
443 DCHECK(main_loop_->BelongsToCurrentThread()); | 443 DCHECK(main_loop_->BelongsToCurrentThread()); |
444 | 444 |
445 return pipeline_.HasAudio(); | 445 return pipeline_metadata_.has_audio; |
446 } | 446 } |
447 | 447 |
448 blink::WebSize WebMediaPlayerImpl::naturalSize() const { | 448 blink::WebSize WebMediaPlayerImpl::naturalSize() const { |
449 DCHECK(main_loop_->BelongsToCurrentThread()); | 449 DCHECK(main_loop_->BelongsToCurrentThread()); |
450 | 450 |
451 return blink::WebSize(natural_size_); | 451 return blink::WebSize(pipeline_metadata_.natural_size); |
452 } | 452 } |
453 | 453 |
454 bool WebMediaPlayerImpl::paused() const { | 454 bool WebMediaPlayerImpl::paused() const { |
455 DCHECK(main_loop_->BelongsToCurrentThread()); | 455 DCHECK(main_loop_->BelongsToCurrentThread()); |
456 | 456 |
457 return pipeline_.GetPlaybackRate() == 0.0f; | 457 return pipeline_.GetPlaybackRate() == 0.0f; |
458 } | 458 } |
459 | 459 |
460 bool WebMediaPlayerImpl::seeking() const { | 460 bool WebMediaPlayerImpl::seeking() const { |
461 DCHECK(main_loop_->BelongsToCurrentThread()); | 461 DCHECK(main_loop_->BelongsToCurrentThread()); |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 SetNetworkState(PipelineErrorToNetworkState(error)); | 936 SetNetworkState(PipelineErrorToNetworkState(error)); |
937 | 937 |
938 if (error == media::PIPELINE_ERROR_DECRYPT) | 938 if (error == media::PIPELINE_ERROR_DECRYPT) |
939 EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1); | 939 EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1); |
940 | 940 |
941 // TODO(scherkus): This should be handled by HTMLMediaElement and controls | 941 // TODO(scherkus): This should be handled by HTMLMediaElement and controls |
942 // should know when to invalidate themselves http://crbug.com/337015 | 942 // should know when to invalidate themselves http://crbug.com/337015 |
943 InvalidateOnMainThread(); | 943 InvalidateOnMainThread(); |
944 } | 944 } |
945 | 945 |
946 void WebMediaPlayerImpl::OnPipelineBufferingState( | 946 void WebMediaPlayerImpl::OnPipelineMetadata( |
947 media::Pipeline::BufferingState buffering_state) { | 947 media::PipelineMetadata metadata) { |
948 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; | 948 DVLOG(1) << "OnPipelineMetadata"; |
949 | 949 |
950 switch (buffering_state) { | 950 pipeline_metadata_ = metadata; |
951 case media::Pipeline::kHaveMetadata: | |
952 // TODO(scherkus): Would be better to have a metadata changed callback | |
953 // that contained the size information as well whether audio/video is | |
954 // present. Doing so would let us remove more methods off Pipeline. | |
955 natural_size_ = pipeline_.GetInitialNaturalSize(); | |
956 | 951 |
957 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 952 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
958 | 953 |
959 if (hasVideo()) { | 954 if (hasVideo()) { |
960 DCHECK(!video_weblayer_); | 955 DCHECK(!video_weblayer_); |
961 video_weblayer_.reset(new webkit::WebLayerImpl( | 956 video_weblayer_.reset(new webkit::WebLayerImpl( |
962 cc::VideoLayer::Create(compositor_.GetVideoFrameProvider()))); | 957 cc::VideoLayer::Create(compositor_.GetVideoFrameProvider()))); |
963 client_->setWebLayer(video_weblayer_.get()); | 958 client_->setWebLayer(video_weblayer_.get()); |
964 } | |
965 break; | |
966 case media::Pipeline::kPrerollCompleted: | |
967 // Only transition to ReadyStateHaveEnoughData if we don't have | |
968 // any pending seeks because the transition can cause Blink to | |
969 // report that the most recent seek has completed. | |
970 if (!pending_seek_) | |
971 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | |
972 break; | |
973 } | 959 } |
974 | 960 |
975 // TODO(scherkus): This should be handled by HTMLMediaElement and controls | 961 // TODO(scherkus): This should be handled by HTMLMediaElement and controls |
976 // should know when to invalidate themselves http://crbug.com/337015 | 962 // should know when to invalidate themselves http://crbug.com/337015 |
977 InvalidateOnMainThread(); | 963 InvalidateOnMainThread(); |
978 } | 964 } |
979 | 965 |
| 966 void WebMediaPlayerImpl::OnPipelinePrerollCompleted() { |
| 967 DVLOG(1) << "OnPipelinePrerollCompleted"; |
| 968 |
| 969 // Only transition to ReadyStateHaveEnoughData if we don't have |
| 970 // any pending seeks because the transition can cause Blink to |
| 971 // report that the most recent seek has completed. |
| 972 if (!pending_seek_) { |
| 973 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 974 |
| 975 // TODO(scherkus): This should be handled by HTMLMediaElement and controls |
| 976 // should know when to invalidate themselves http://crbug.com/337015 |
| 977 InvalidateOnMainThread(); |
| 978 } |
| 979 } |
| 980 |
980 void WebMediaPlayerImpl::OnDemuxerOpened() { | 981 void WebMediaPlayerImpl::OnDemuxerOpened() { |
981 DCHECK(main_loop_->BelongsToCurrentThread()); | 982 DCHECK(main_loop_->BelongsToCurrentThread()); |
982 client_->mediaSourceOpened(new WebMediaSourceImpl( | 983 client_->mediaSourceOpened(new WebMediaSourceImpl( |
983 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_))); | 984 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_))); |
984 } | 985 } |
985 | 986 |
986 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) { | 987 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) { |
987 DCHECK(main_loop_->BelongsToCurrentThread()); | 988 DCHECK(main_loop_->BelongsToCurrentThread()); |
988 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 989 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
989 client_->keyAdded( | 990 client_->keyAdded( |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 filter_collection->SetTextRenderer(text_renderer.Pass()); | 1189 filter_collection->SetTextRenderer(text_renderer.Pass()); |
1189 } | 1190 } |
1190 | 1191 |
1191 // ... and we're ready to go! | 1192 // ... and we're ready to go! |
1192 starting_ = true; | 1193 starting_ = true; |
1193 pipeline_.Start( | 1194 pipeline_.Start( |
1194 filter_collection.Pass(), | 1195 filter_collection.Pass(), |
1195 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), | 1196 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), |
1196 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), | 1197 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), |
1197 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), | 1198 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), |
1198 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingState), | 1199 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineMetadata), |
| 1200 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelinePrerollCompleted), |
1199 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange)); | 1201 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange)); |
1200 } | 1202 } |
1201 | 1203 |
1202 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 1204 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
1203 DCHECK(main_loop_->BelongsToCurrentThread()); | 1205 DCHECK(main_loop_->BelongsToCurrentThread()); |
1204 DVLOG(1) << "SetNetworkState: " << state; | 1206 DVLOG(1) << "SetNetworkState: " << state; |
1205 network_state_ = state; | 1207 network_state_ = state; |
1206 // Always notify to ensure client has the latest value. | 1208 // Always notify to ensure client has the latest value. |
1207 client_->networkStateChanged(); | 1209 client_->networkStateChanged(); |
1208 } | 1210 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 client_->durationChanged(); | 1252 client_->durationChanged(); |
1251 } | 1253 } |
1252 | 1254 |
1253 void WebMediaPlayerImpl::OnNaturalSizeChange(gfx::Size size) { | 1255 void WebMediaPlayerImpl::OnNaturalSizeChange(gfx::Size size) { |
1254 DCHECK(main_loop_->BelongsToCurrentThread()); | 1256 DCHECK(main_loop_->BelongsToCurrentThread()); |
1255 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); | 1257 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
1256 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); | 1258 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); |
1257 | 1259 |
1258 media_log_->AddEvent( | 1260 media_log_->AddEvent( |
1259 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); | 1261 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); |
1260 natural_size_ = size; | 1262 pipeline_metadata_.natural_size = size; |
1261 | 1263 |
1262 client_->sizeChanged(); | 1264 client_->sizeChanged(); |
1263 } | 1265 } |
1264 | 1266 |
1265 void WebMediaPlayerImpl::FrameReady( | 1267 void WebMediaPlayerImpl::FrameReady( |
1266 const scoped_refptr<media::VideoFrame>& frame) { | 1268 const scoped_refptr<media::VideoFrame>& frame) { |
1267 compositor_.UpdateCurrentFrame(frame); | 1269 compositor_.UpdateCurrentFrame(frame); |
1268 } | 1270 } |
1269 | 1271 |
1270 void WebMediaPlayerImpl::SetDecryptorReadyCB( | 1272 void WebMediaPlayerImpl::SetDecryptorReadyCB( |
(...skipping 24 matching lines...) Expand all Loading... |
1295 | 1297 |
1296 if (web_cdm_) { | 1298 if (web_cdm_) { |
1297 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1299 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); |
1298 return; | 1300 return; |
1299 } | 1301 } |
1300 | 1302 |
1301 decryptor_ready_cb_ = decryptor_ready_cb; | 1303 decryptor_ready_cb_ = decryptor_ready_cb; |
1302 } | 1304 } |
1303 | 1305 |
1304 } // namespace content | 1306 } // namespace content |
OLD | NEW |