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

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: 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 matadata is available.
DaleCurtis 2016/03/21 19:54:34 What happens during a seek? Do we transition to ha
sandersd (OOO until July 31) 2016/03/21 19:59:43 During seek, we set the state to ReadyStateHaveMet
1069 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata)
1070 return;
1071
1069 // Don't suspend players which only have audio and have not completed 1072 // 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. 1073 // playback. The user can still control these players via the MediaSession UI.
1071 // If the player has never started playback, OnSuspendRequested() will handle 1074 // If the player has never started playback, OnSuspendRequested() will handle
1072 // release of any idle resources. 1075 // release of any idle resources.
1073 if (!hasVideo() && !paused_ && !ended_) 1076 if (!hasVideo() && !paused_ && !ended_)
1074 return; 1077 return;
1075 1078
1076 // Always reset the buffering strategy to normal when suspending for hidden to 1079 // Always reset the buffering strategy to normal when suspending for hidden to
1077 // prevent an idle network connection from lingering. 1080 // prevent an idle network connection from lingering.
1078 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal); 1081 setBufferingStrategy(WebMediaPlayer::BufferingStrategy::Normal);
1079 pipeline_controller_.Suspend(); 1082 pipeline_controller_.Suspend();
1080 if (delegate_) 1083 if (delegate_)
1081 delegate_->PlayerGone(delegate_id_); 1084 delegate_->PlayerGone(delegate_id_);
1082 } 1085 }
1083 1086
1084 void WebMediaPlayerImpl::OnShown() { 1087 void WebMediaPlayerImpl::OnShown() {
1085 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1088 DCHECK(main_task_runner_->BelongsToCurrentThread());
1086 if (!IsSuspendUponHiddenEnabled()) 1089 if (!IsSuspendUponHiddenEnabled())
1087 return; 1090 return;
1088 1091
1089 #if defined(OS_ANDROID) // WMPI_CAST 1092 #if defined(OS_ANDROID) // WMPI_CAST
1090 // If we're remote, the pipeline should stay suspended. 1093 // If we're remote, the pipeline should stay suspended.
1091 if (isRemote()) 1094 if (isRemote())
1092 return; 1095 return;
1093 #endif 1096 #endif
1094 1097
1095 if (!ended_ && !paused_) 1098 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata ||
DaleCurtis 2016/03/21 20:04:50 We want to resume when it's less than have metadat
sandersd (OOO until July 31) 2016/03/21 20:12:26 Yes. I added a comment to explain.
1099 (!ended_ && !paused_)) {
1096 pipeline_controller_.Resume(); 1100 pipeline_controller_.Resume();
1101 }
1097 } 1102 }
1098 1103
1099 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { 1104 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) {
1100 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1105 DCHECK(main_task_runner_->BelongsToCurrentThread());
1101 1106
1102 #if defined(OS_ANDROID) // WMPI_CAST 1107 #if defined(OS_ANDROID) // WMPI_CAST
1103 // If we're remote, the pipeline should already be suspended. 1108 // If we're remote, the pipeline should already be suspended.
1104 if (isRemote()) 1109 if (isRemote())
1105 return; 1110 return;
1106 #endif 1111 #endif
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 bool WebMediaPlayerImpl::IsAutomaticResumeAllowed() { 1517 bool WebMediaPlayerImpl::IsAutomaticResumeAllowed() {
1513 #if defined(OS_ANDROID) 1518 #if defined(OS_ANDROID)
1514 return !hasVideo() || (delegate_ && !delegate_->IsHidden()); 1519 return !hasVideo() || (delegate_ && !delegate_->IsHidden());
1515 #else 1520 #else
1516 // On non-Android platforms Resume() is always allowed. 1521 // On non-Android platforms Resume() is always allowed.
1517 return true; 1522 return true;
1518 #endif 1523 #endif
1519 } 1524 }
1520 1525
1521 } // namespace media 1526 } // 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