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

Side by Side Diff: media/blink/webmediaplayer_impl.cc

Issue 1823643003: Don't suspend before there is metadata. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Typo Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 || 978 if (pipeline_metadata_.video_rotation == VIDEO_ROTATION_90 ||
979 pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) { 979 pipeline_metadata_.video_rotation == VIDEO_ROTATION_270) {
980 gfx::Size size = pipeline_metadata_.natural_size; 980 gfx::Size size = pipeline_metadata_.natural_size;
981 pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width()); 981 pipeline_metadata_.natural_size = gfx::Size(size.height(), size.width());
982 } 982 }
983 983
984 video_weblayer_.reset(new cc_blink::WebLayerImpl(layer)); 984 video_weblayer_.reset(new cc_blink::WebLayerImpl(layer));
985 video_weblayer_->layer()->SetContentsOpaque(opaque_); 985 video_weblayer_->layer()->SetContentsOpaque(opaque_);
986 video_weblayer_->SetContentsOpaqueIsFixed(true); 986 video_weblayer_->SetContentsOpaqueIsFixed(true);
987 client_->setWebLayer(video_weblayer_.get()); 987 client_->setWebLayer(video_weblayer_.get());
988
989 // If there is video and the frame is hidden, then it may be time to suspend
990 // playback.
991 if (delegate_ && delegate_->IsHidden())
992 OnHidden();
993 } 988 }
994 989
995 // Tell the delegate we can now be safely suspended due to inactivity if a 990 // Tell the delegate we can now be safely suspended due to inactivity if a
996 // subsequent play event does not occur. 991 // subsequent play event does not occur.
997 if (paused_) 992 if (paused_)
998 NotifyPlaybackPaused(); 993 NotifyPlaybackPaused();
994
995 // If the frame is hidden, it may be time to suspend playback.
996 if (delegate_ && delegate_->IsHidden())
997 OnHidden();
999 } 998 }
1000 999
1001 void WebMediaPlayerImpl::OnPipelineBufferingStateChanged( 1000 void WebMediaPlayerImpl::OnPipelineBufferingStateChanged(
1002 BufferingState buffering_state) { 1001 BufferingState buffering_state) {
1003 DVLOG(1) << __FUNCTION__ << "(" << buffering_state << ")"; 1002 DVLOG(1) << __FUNCTION__ << "(" << buffering_state << ")";
1004 1003
1005 // Ignore buffering state changes until we've completed all outstanding 1004 // Ignore buffering state changes until we've completed all outstanding
1006 // operations. 1005 // operations.
1007 if (!pipeline_controller_.IsStable()) 1006 if (!pipeline_controller_.IsStable())
1008 return; 1007 return;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1058 DCHECK(main_task_runner_->BelongsToCurrentThread());
1060 if (!IsSuspendUponHiddenEnabled()) 1059 if (!IsSuspendUponHiddenEnabled())
1061 return; 1060 return;
1062 1061
1063 #if defined(OS_ANDROID) // WMPI_CAST 1062 #if defined(OS_ANDROID) // WMPI_CAST
1064 // If we're remote, the pipeline should already be suspended. 1063 // If we're remote, the pipeline should already be suspended.
1065 if (isRemote()) 1064 if (isRemote())
1066 return; 1065 return;
1067 #endif 1066 #endif
1068 1067
1068 // Don't suspend before metadata is available, as we don't know if there is a
1069 // video track yet.
1070 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata)
1071 return;
1072
1069 // Don't suspend players which only have audio and have not completed 1073 // Don't suspend players which only have audio and have not completed
1070 // playback. The user can still control these players via the MediaSession UI. 1074 // playback. The user can still control these players via the MediaSession UI.
1071 // If the player has never started playback, OnSuspendRequested() will handle 1075 // If the player has never started playback, OnSuspendRequested() will handle
1072 // release of any idle resources. 1076 // release of any idle resources.
1073 if (!hasVideo() && !paused_ && !ended_) 1077 if (!hasVideo() && !paused_ && !ended_)
1074 return; 1078 return;
1075 1079
1076 // Always reset the buffering strategy to normal when suspending for hidden to 1080 // Always reset the buffering strategy to normal when suspending for hidden to
1077 // prevent an idle network connection from lingering. 1081 // prevent an idle network connection from lingering.
1078 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal); 1082 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal);
1079 pipeline_controller_.Suspend(); 1083 pipeline_controller_.Suspend();
1080 if (delegate_) 1084 if (delegate_)
1081 delegate_->PlayerGone(delegate_id_); 1085 delegate_->PlayerGone(delegate_id_);
1082 } 1086 }
1083 1087
1084 void WebMediaPlayerImpl::OnShown() { 1088 void WebMediaPlayerImpl::OnShown() {
1085 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1089 DCHECK(main_task_runner_->BelongsToCurrentThread());
1086 if (!IsSuspendUponHiddenEnabled()) 1090 if (!IsSuspendUponHiddenEnabled())
1087 return; 1091 return;
1088 1092
1089 #if defined(OS_ANDROID) // WMPI_CAST 1093 #if defined(OS_ANDROID) // WMPI_CAST
1090 // If we're remote, the pipeline should stay suspended. 1094 // If we're remote, the pipeline should stay suspended.
1091 if (isRemote()) 1095 if (isRemote())
1092 return; 1096 return;
1093 #endif 1097 #endif
1094 1098
1095 if (!ended_ && !paused_) 1099 // If we do not yet have metadata, the only way we could have been suspended
1100 // is by a OnSuspendRequested() with |must_suspend| set. In that case we need
1101 // to resume, otherwise playback will be broken.
1102 //
1103 // Otherwise, resume if we should be playing.
1104 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata ||
1105 (!ended_ && !paused_)) {
1096 pipeline_controller_.Resume(); 1106 pipeline_controller_.Resume();
1107 }
1097 } 1108 }
1098 1109
1099 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { 1110 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) {
1100 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1111 DCHECK(main_task_runner_->BelongsToCurrentThread());
1101 1112
1102 #if defined(OS_ANDROID) // WMPI_CAST 1113 #if defined(OS_ANDROID) // WMPI_CAST
1103 // If we're remote, the pipeline should already be suspended. 1114 // If we're remote, the pipeline should already be suspended.
1104 if (isRemote()) 1115 if (isRemote())
1105 return; 1116 return;
1106 #endif 1117 #endif
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 bool WebMediaPlayerImpl::IsAutomaticResumeAllowed() { 1523 bool WebMediaPlayerImpl::IsAutomaticResumeAllowed() {
1513 #if defined(OS_ANDROID) 1524 #if defined(OS_ANDROID)
1514 return !hasVideo() || (delegate_ && !delegate_->IsHidden()); 1525 return !hasVideo() || (delegate_ && !delegate_->IsHidden());
1515 #else 1526 #else
1516 // On non-Android platforms Resume() is always allowed. 1527 // On non-Android platforms Resume() is always allowed.
1517 return true; 1528 return true;
1518 #endif 1529 #endif
1519 } 1530 }
1520 1531
1521 } // namespace media 1532 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698