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_metadata_.has_video; | 439 return pipeline_.HasVideo(); |
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_metadata_.has_audio; | 445 return pipeline_.HasAudio(); |
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(pipeline_metadata_.natural_size); | 451 return blink::WebSize(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::OnPipelineMetadata( | 946 void WebMediaPlayerImpl::OnPipelineBufferingState( |
947 media::PipelineMetadata metadata) { | 947 media::Pipeline::BufferingState buffering_state) { |
948 DVLOG(1) << "OnPipelineMetadata"; | 948 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; |
949 | 949 |
950 pipeline_metadata_ = metadata; | 950 switch (buffering_state) { |
| 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(); |
951 | 956 |
952 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 957 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
953 | 958 |
954 if (hasVideo()) { | 959 if (hasVideo()) { |
955 DCHECK(!video_weblayer_); | 960 DCHECK(!video_weblayer_); |
956 video_weblayer_.reset(new webkit::WebLayerImpl( | 961 video_weblayer_.reset(new webkit::WebLayerImpl( |
957 cc::VideoLayer::Create(compositor_.GetVideoFrameProvider()))); | 962 cc::VideoLayer::Create(compositor_.GetVideoFrameProvider()))); |
958 client_->setWebLayer(video_weblayer_.get()); | 963 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; |
959 } | 973 } |
960 | 974 |
961 // TODO(scherkus): This should be handled by HTMLMediaElement and controls | 975 // TODO(scherkus): This should be handled by HTMLMediaElement and controls |
962 // should know when to invalidate themselves http://crbug.com/337015 | 976 // should know when to invalidate themselves http://crbug.com/337015 |
963 InvalidateOnMainThread(); | 977 InvalidateOnMainThread(); |
964 } | 978 } |
965 | 979 |
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 | |
981 void WebMediaPlayerImpl::OnDemuxerOpened() { | 980 void WebMediaPlayerImpl::OnDemuxerOpened() { |
982 DCHECK(main_loop_->BelongsToCurrentThread()); | 981 DCHECK(main_loop_->BelongsToCurrentThread()); |
983 client_->mediaSourceOpened(new WebMediaSourceImpl( | 982 client_->mediaSourceOpened(new WebMediaSourceImpl( |
984 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_))); | 983 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_))); |
985 } | 984 } |
986 | 985 |
987 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) { | 986 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) { |
988 DCHECK(main_loop_->BelongsToCurrentThread()); | 987 DCHECK(main_loop_->BelongsToCurrentThread()); |
989 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 988 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
990 client_->keyAdded( | 989 client_->keyAdded( |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 filter_collection->SetTextRenderer(text_renderer.Pass()); | 1188 filter_collection->SetTextRenderer(text_renderer.Pass()); |
1190 } | 1189 } |
1191 | 1190 |
1192 // ... and we're ready to go! | 1191 // ... and we're ready to go! |
1193 starting_ = true; | 1192 starting_ = true; |
1194 pipeline_.Start( | 1193 pipeline_.Start( |
1195 filter_collection.Pass(), | 1194 filter_collection.Pass(), |
1196 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), | 1195 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), |
1197 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), | 1196 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), |
1198 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), | 1197 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), |
1199 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineMetadata), | 1198 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingState), |
1200 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelinePrerollCompleted), | |
1201 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange)); | 1199 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange)); |
1202 } | 1200 } |
1203 | 1201 |
1204 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 1202 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
1205 DCHECK(main_loop_->BelongsToCurrentThread()); | 1203 DCHECK(main_loop_->BelongsToCurrentThread()); |
1206 DVLOG(1) << "SetNetworkState: " << state; | 1204 DVLOG(1) << "SetNetworkState: " << state; |
1207 network_state_ = state; | 1205 network_state_ = state; |
1208 // Always notify to ensure client has the latest value. | 1206 // Always notify to ensure client has the latest value. |
1209 client_->networkStateChanged(); | 1207 client_->networkStateChanged(); |
1210 } | 1208 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 client_->durationChanged(); | 1250 client_->durationChanged(); |
1253 } | 1251 } |
1254 | 1252 |
1255 void WebMediaPlayerImpl::OnNaturalSizeChange(gfx::Size size) { | 1253 void WebMediaPlayerImpl::OnNaturalSizeChange(gfx::Size size) { |
1256 DCHECK(main_loop_->BelongsToCurrentThread()); | 1254 DCHECK(main_loop_->BelongsToCurrentThread()); |
1257 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); | 1255 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); |
1258 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); | 1256 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); |
1259 | 1257 |
1260 media_log_->AddEvent( | 1258 media_log_->AddEvent( |
1261 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); | 1259 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); |
1262 pipeline_metadata_.natural_size = size; | 1260 natural_size_ = size; |
1263 | 1261 |
1264 client_->sizeChanged(); | 1262 client_->sizeChanged(); |
1265 } | 1263 } |
1266 | 1264 |
1267 void WebMediaPlayerImpl::FrameReady( | 1265 void WebMediaPlayerImpl::FrameReady( |
1268 const scoped_refptr<media::VideoFrame>& frame) { | 1266 const scoped_refptr<media::VideoFrame>& frame) { |
1269 compositor_.UpdateCurrentFrame(frame); | 1267 compositor_.UpdateCurrentFrame(frame); |
1270 } | 1268 } |
1271 | 1269 |
1272 void WebMediaPlayerImpl::SetDecryptorReadyCB( | 1270 void WebMediaPlayerImpl::SetDecryptorReadyCB( |
(...skipping 24 matching lines...) Expand all Loading... |
1297 | 1295 |
1298 if (web_cdm_) { | 1296 if (web_cdm_) { |
1299 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1297 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); |
1300 return; | 1298 return; |
1301 } | 1299 } |
1302 | 1300 |
1303 decryptor_ready_cb_ = decryptor_ready_cb; | 1301 decryptor_ready_cb_ = decryptor_ready_cb; |
1304 } | 1302 } |
1305 | 1303 |
1306 } // namespace content | 1304 } // namespace content |
OLD | NEW |