Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Side by Side Diff: content/renderer/media/webmediaplayer_impl.cc

Issue 206103004: Remove HasAudio(), HasVideo(), GetInitialNaturalSize() from media::Pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New names. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 SetNetworkState(PipelineErrorToNetworkState(error)); 958 SetNetworkState(PipelineErrorToNetworkState(error));
959 959
960 if (error == media::PIPELINE_ERROR_DECRYPT) 960 if (error == media::PIPELINE_ERROR_DECRYPT)
961 EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1); 961 EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1);
962 962
963 // TODO(scherkus): This should be handled by HTMLMediaElement and controls 963 // TODO(scherkus): This should be handled by HTMLMediaElement and controls
964 // should know when to invalidate themselves http://crbug.com/337015 964 // should know when to invalidate themselves http://crbug.com/337015
965 InvalidateOnMainThread(); 965 InvalidateOnMainThread();
966 } 966 }
967 967
968 void WebMediaPlayerImpl::OnPipelineBufferingState( 968 void WebMediaPlayerImpl::OnPipelineMetadata(
969 media::Pipeline::BufferingState buffering_state) { 969 media::PipelineMetadata metadata) {
970 DVLOG(1) << "OnPipelineBufferingState(" << buffering_state << ")"; 970 DVLOG(1) << "OnPipelineMetadata";
971 971
972 switch (buffering_state) { 972 pipeline_metadata_ = metadata;
973 case media::Pipeline::kHaveMetadata:
974 // TODO(scherkus): Would be better to have a metadata changed callback
975 // that contained the size information as well whether audio/video is
976 // present. Doing so would let us remove more methods off Pipeline.
977 natural_size_ = pipeline_.GetInitialNaturalSize();
978 973
979 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); 974 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata);
980 975
981 if (hasVideo() && client_->needsWebLayerForVideo()) { 976 if (hasVideo() && client_->needsWebLayerForVideo()) {
982 DCHECK(!video_weblayer_); 977 DCHECK(!video_weblayer_);
983 video_weblayer_.reset( 978 video_weblayer_.reset(
984 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); 979 new webkit::WebLayerImpl(cc::VideoLayer::Create(this)));
985 client_->setWebLayer(video_weblayer_.get()); 980 client_->setWebLayer(video_weblayer_.get());
986 }
987 break;
988 case media::Pipeline::kPrerollCompleted:
989 // Only transition to ReadyStateHaveEnoughData if we don't have
990 // any pending seeks because the transition can cause Blink to
991 // report that the most recent seek has completed.
992 if (!pending_seek_)
993 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
994 break;
995 } 981 }
996 982
997 // TODO(scherkus): This should be handled by HTMLMediaElement and controls 983 // TODO(scherkus): This should be handled by HTMLMediaElement and controls
998 // should know when to invalidate themselves http://crbug.com/337015 984 // should know when to invalidate themselves http://crbug.com/337015
999 InvalidateOnMainThread(); 985 InvalidateOnMainThread();
1000 } 986 }
1001 987
988 void WebMediaPlayerImpl::OnPipelinePrerollCompleted() {
989 DVLOG(1) << "OnPipelinePrerollCompleted";
990
991 // Only transition to ReadyStateHaveEnoughData if we don't have
992 // any pending seeks because the transition can cause Blink to
993 // report that the most recent seek has completed.
994 if (!pending_seek_) {
995 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData);
996
997 // TODO(scherkus): This should be handled by HTMLMediaElement and controls
998 // should know when to invalidate themselves http://crbug.com/337015
999 InvalidateOnMainThread();
1000 }
1001 }
1002
1002 void WebMediaPlayerImpl::OnDemuxerOpened() { 1003 void WebMediaPlayerImpl::OnDemuxerOpened() {
1003 DCHECK(main_loop_->BelongsToCurrentThread()); 1004 DCHECK(main_loop_->BelongsToCurrentThread());
1004 client_->mediaSourceOpened(new WebMediaSourceImpl( 1005 client_->mediaSourceOpened(new WebMediaSourceImpl(
1005 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_))); 1006 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_)));
1006 } 1007 }
1007 1008
1008 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) { 1009 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) {
1009 DCHECK(main_loop_->BelongsToCurrentThread()); 1010 DCHECK(main_loop_->BelongsToCurrentThread());
1010 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); 1011 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1);
1011 client_->keyAdded( 1012 client_->keyAdded(
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 filter_collection->SetTextRenderer(text_renderer.Pass()); 1211 filter_collection->SetTextRenderer(text_renderer.Pass());
1211 } 1212 }
1212 1213
1213 // ... and we're ready to go! 1214 // ... and we're ready to go!
1214 starting_ = true; 1215 starting_ = true;
1215 pipeline_.Start( 1216 pipeline_.Start(
1216 filter_collection.Pass(), 1217 filter_collection.Pass(),
1217 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), 1218 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded),
1218 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), 1219 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError),
1219 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), 1220 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek),
1220 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingState), 1221 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineMetadata),
1222 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelinePrerollCompleted),
1221 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange)); 1223 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDurationChange));
1222 } 1224 }
1223 1225
1224 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { 1226 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) {
1225 DCHECK(main_loop_->BelongsToCurrentThread()); 1227 DCHECK(main_loop_->BelongsToCurrentThread());
1226 DVLOG(1) << "SetNetworkState: " << state; 1228 DVLOG(1) << "SetNetworkState: " << state;
1227 network_state_ = state; 1229 network_state_ = state;
1228 // Always notify to ensure client has the latest value. 1230 // Always notify to ensure client has the latest value.
1229 client_->networkStateChanged(); 1231 client_->networkStateChanged();
1230 } 1232 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 client_->durationChanged(); 1274 client_->durationChanged();
1273 } 1275 }
1274 1276
1275 void WebMediaPlayerImpl::OnNaturalSizeChange(gfx::Size size) { 1277 void WebMediaPlayerImpl::OnNaturalSizeChange(gfx::Size size) {
1276 DCHECK(main_loop_->BelongsToCurrentThread()); 1278 DCHECK(main_loop_->BelongsToCurrentThread());
1277 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing); 1279 DCHECK_NE(ready_state_, WebMediaPlayer::ReadyStateHaveNothing);
1278 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged"); 1280 TRACE_EVENT0("media", "WebMediaPlayerImpl::OnNaturalSizeChanged");
1279 1281
1280 media_log_->AddEvent( 1282 media_log_->AddEvent(
1281 media_log_->CreateVideoSizeSetEvent(size.width(), size.height())); 1283 media_log_->CreateVideoSizeSetEvent(size.width(), size.height()));
1282 natural_size_ = size; 1284 pipeline_metadata_.natural_size = size;
1283 1285
1284 client_->sizeChanged(); 1286 client_->sizeChanged();
1285 } 1287 }
1286 1288
1287 void WebMediaPlayerImpl::FrameReady( 1289 void WebMediaPlayerImpl::FrameReady(
1288 const scoped_refptr<media::VideoFrame>& frame) { 1290 const scoped_refptr<media::VideoFrame>& frame) {
1289 // TODO(scherkus): Today we always invalidate on the main thread even when 1291 // TODO(scherkus): Today we always invalidate on the main thread even when
1290 // compositing is available, which is less efficient and involves more 1292 // compositing is available, which is less efficient and involves more
1291 // thread hops. Refer to http://crbug.com/335345 for details. 1293 // thread hops. Refer to http://crbug.com/335345 for details.
1292 painter_.UpdateCurrentFrame(frame); 1294 painter_.UpdateCurrentFrame(frame);
(...skipping 27 matching lines...) Expand all
1320 1322
1321 if (web_cdm_) { 1323 if (web_cdm_) {
1322 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); 1324 decryptor_ready_cb.Run(web_cdm_->GetDecryptor());
1323 return; 1325 return;
1324 } 1326 }
1325 1327
1326 decryptor_ready_cb_ = decryptor_ready_cb; 1328 decryptor_ready_cb_ = decryptor_ready_cb;
1327 } 1329 }
1328 1330
1329 } // namespace content 1331 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698