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

Side by Side Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 2490783002: Refactor WebMediaPlayerDelegate interface. (Closed)
Patch Set: Update WMPA properly. Created 4 years 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/android/webmediaplayer_android.h" 5 #include "content/renderer/media/android/webmediaplayer_android.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 enable_texture_copy_(enable_texture_copy), 175 enable_texture_copy_(enable_texture_copy),
176 suppress_deleting_texture_(false), 176 suppress_deleting_texture_(false),
177 playback_completed_(false), 177 playback_completed_(false),
178 volume_(1.0), 178 volume_(1.0),
179 volume_multiplier_(1.0), 179 volume_multiplier_(1.0),
180 weak_factory_(this) { 180 weak_factory_(this) {
181 DCHECK(player_manager_); 181 DCHECK(player_manager_);
182 182
183 DCHECK(main_thread_checker_.CalledOnValidThread()); 183 DCHECK(main_thread_checker_.CalledOnValidThread());
184 184
185 if (delegate_) 185 if (delegate_) {
186 delegate_id_ = delegate_->AddObserver(this); 186 delegate_id_ = delegate_->AddObserver(this);
187 delegate_->SetIdle(delegate_id_, true);
188 }
187 189
188 player_id_ = player_manager_->RegisterMediaPlayer(this); 190 player_id_ = player_manager_->RegisterMediaPlayer(this);
189 191
190 TryCreateStreamTextureProxyIfNeeded(); 192 TryCreateStreamTextureProxyIfNeeded();
191 interpolator_.SetUpperBound(base::TimeDelta()); 193 interpolator_.SetUpperBound(base::TimeDelta());
192 } 194 }
193 195
194 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { 196 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() {
195 DCHECK(main_thread_checker_.CalledOnValidThread()); 197 DCHECK(main_thread_checker_.CalledOnValidThread());
196 SetVideoFrameProviderClient(NULL); 198 SetVideoFrameProviderClient(NULL);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return false; 290 return false;
289 } 291 }
290 292
291 void WebMediaPlayerAndroid::play() { 293 void WebMediaPlayerAndroid::play() {
292 DCHECK(main_thread_checker_.CalledOnValidThread()); 294 DCHECK(main_thread_checker_.CalledOnValidThread());
293 295
294 if (hasVideo() && player_manager_->render_frame()->IsHidden()) { 296 if (hasVideo() && player_manager_->render_frame()->IsHidden()) {
295 bool can_video_play_in_background = 297 bool can_video_play_in_background =
296 base::CommandLine::ForCurrentProcess()->HasSwitch( 298 base::CommandLine::ForCurrentProcess()->HasSwitch(
297 switches::kDisableMediaSuspend) || 299 switches::kDisableMediaSuspend) ||
298 (IsBackgroundVideoCandidate() && 300 (IsBackgroundVideoCandidate() && delegate_ &&
whywhat 2016/12/12 18:11:23 nit: isBackgroundVideoCandidate will already check
sandersd (OOO until July 31) 2017/01/05 23:12:21 Done.
299 delegate_ && delegate_->IsPlayingBackgroundVideo()); 301 delegate_->IsFrameHidden() && !delegate_->IsFrameClosed() &&
302 delegate_->IsBackgroundVideoPlaybackAllowed());
300 if (!can_video_play_in_background) { 303 if (!can_video_play_in_background) {
301 is_play_pending_ = true; 304 is_play_pending_ = true;
302 return; 305 return;
303 } 306 }
304 } 307 }
305 is_play_pending_ = false; 308 is_play_pending_ = false;
306 309
307 TryCreateStreamTextureProxyIfNeeded(); 310 TryCreateStreamTextureProxyIfNeeded();
308 // There is no need to establish the surface texture peer for fullscreen 311 // There is no need to establish the surface texture peer for fullscreen
309 // video. 312 // video.
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 819
817 // Lazily allocate compositing layer. 820 // Lazily allocate compositing layer.
818 if (!video_weblayer_) { 821 if (!video_weblayer_) {
819 video_weblayer_.reset(new cc_blink::WebLayerImpl( 822 video_weblayer_.reset(new cc_blink::WebLayerImpl(
820 cc::VideoLayer::Create(this, media::VIDEO_ROTATION_0))); 823 cc::VideoLayer::Create(this, media::VIDEO_ROTATION_0)));
821 client_->setWebLayer(video_weblayer_.get()); 824 client_->setWebLayer(video_weblayer_.get());
822 825
823 // If we're paused after we receive metadata for the first time, tell the 826 // If we're paused after we receive metadata for the first time, tell the
824 // delegate we can now be safely suspended due to inactivity if a subsequent 827 // delegate we can now be safely suspended due to inactivity if a subsequent
825 // play event does not occur. 828 // play event does not occur.
826 if (paused() && delegate_) 829 if (paused() && delegate_) {
827 delegate_->DidPause(delegate_id_, false); 830 delegate_->DidPause(delegate_id_);
831 delegate_->SetIdle(delegate_id_, true);
832 }
828 } 833 }
829 } 834 }
830 835
831 void WebMediaPlayerAndroid::OnTimeUpdate(base::TimeDelta current_timestamp, 836 void WebMediaPlayerAndroid::OnTimeUpdate(base::TimeDelta current_timestamp,
832 base::TimeTicks current_time_ticks) { 837 base::TimeTicks current_time_ticks) {
833 DCHECK(main_thread_checker_.CalledOnValidThread()); 838 DCHECK(main_thread_checker_.CalledOnValidThread());
834 839
835 if (seeking()) 840 if (seeking())
836 return; 841 return;
837 842
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 interpolator_.StartInterpolating(); 1197 interpolator_.StartInterpolating();
1193 else 1198 else
1194 interpolator_.StopInterpolating(); 1199 interpolator_.StopInterpolating();
1195 1200
1196 if (delegate_) { 1201 if (delegate_) {
1197 if (is_playing) { 1202 if (is_playing) {
1198 // We must specify either video or audio to the delegate, but neither may 1203 // We must specify either video or audio to the delegate, but neither may
1199 // be known at this point -- there are no video only containers, so only 1204 // be known at this point -- there are no video only containers, so only
1200 // send audio if we know for sure its audio. The browser side player will 1205 // send audio if we know for sure its audio. The browser side player will
1201 // fill in the correct value later for media sessions. 1206 // fill in the correct value later for media sessions.
1202 delegate_->DidPlay(delegate_id_, hasVideo(), !hasVideo(), isRemote(), 1207 if (isRemote()) {
1203 media::DurationToMediaContentType(duration_)); 1208 delegate_->PlayerGone(delegate_id_);
1209 } else {
1210 delegate_->DidPlay(delegate_id_, !hasVideo(), hasVideo(),
1211 media::DurationToMediaContentType(duration_));
1212 }
1213 delegate_->SetIdle(delegate_id_, false);
1204 } else { 1214 } else {
1205 // Even if OnPlaybackComplete() has not been called yet, Blink may have 1215 // Even if OnPlaybackComplete() has not been called yet, Blink may have
1206 // already fired the ended event based on current time relative to 1216 // already fired the ended event based on current time relative to
1207 // duration -- so we need to check both possibilities here. 1217 // duration -- so we need to check both possibilities here.
1208 delegate_->DidPause(delegate_id_, 1218 if (playback_completed_ || currentTime() >= duration()) {
1209 playback_completed_ || currentTime() >= duration()); 1219 delegate_->PlayerGone(delegate_id_);
1220 } else {
1221 delegate_->DidPause(delegate_id_);
1222 }
1223 delegate_->SetIdle(delegate_id_, true);
1210 } 1224 }
1211 } 1225 }
1212 } 1226 }
1213 1227
1214 void WebMediaPlayerAndroid::OnHidden() { 1228 void WebMediaPlayerAndroid::OnFrameHidden() {
1215 // Pause audible video preserving its session. 1229 // Pause audible video preserving its session.
1216 if (hasVideo() && IsBackgroundVideoCandidate() && !paused()) { 1230 if (hasVideo() && IsBackgroundVideoCandidate() && !paused()) {
1217 Pause(false); 1231 Pause(false);
1218 is_play_pending_ = true; 1232 is_play_pending_ = true;
1219 return; 1233 return;
1220 } 1234 }
1221 1235
1222 OnSuspendRequested(false); 1236 OnIdleTimeout();
1223 } 1237 }
1224 1238
1225 void WebMediaPlayerAndroid::OnShown() { 1239 void WebMediaPlayerAndroid::OnFrameClosed() {
1240 SuspendAndReleaseResources();
1241 }
1242
1243 void WebMediaPlayerAndroid::OnFrameShown() {
1226 if (is_play_pending_) 1244 if (is_play_pending_)
1227 play(); 1245 play();
1228 } 1246 }
1229 1247
1230 bool WebMediaPlayerAndroid::OnSuspendRequested(bool must_suspend) { 1248 bool WebMediaPlayerAndroid::OnIdleTimeout() {
1231 if (!must_suspend && 1249 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1232 base::CommandLine::ForCurrentProcess()->HasSwitch(
1233 switches::kDisableMediaSuspend)) { 1250 switches::kDisableMediaSuspend)) {
1234 return true; 1251 return true;
1235 } 1252 }
1236 1253
1237 // If we're idle or playing video, pause and release resources; audio only 1254 // If we're idle or playing video, pause and release resources; audio only
1238 // players are allowed to continue unless indicated otherwise by the call. 1255 // players are allowed to continue.
1239 if (must_suspend || (paused() && playback_completed_) || 1256 if ((paused() && playback_completed_) ||
1240 (hasVideo() && !IsBackgroundVideoCandidate())) { 1257 (hasVideo() && !IsBackgroundVideoCandidate())) {
1241 SuspendAndReleaseResources(); 1258 SuspendAndReleaseResources();
1242 } 1259 }
1243 1260
1244 return true; 1261 return true;
1245 } 1262 }
1246 1263
1247 void WebMediaPlayerAndroid::OnPlay() { 1264 void WebMediaPlayerAndroid::OnPlay() {
1248 play(); 1265 play();
1249 client_->playbackStateChanged(); 1266 client_->playbackStateChanged();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 1332
1316 bool WebMediaPlayerAndroid::IsBackgroundVideoCandidate() const { 1333 bool WebMediaPlayerAndroid::IsBackgroundVideoCandidate() const {
1317 DCHECK(hasVideo()); 1334 DCHECK(hasVideo());
1318 1335
1319 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1336 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1320 switches::kDisableMediaSuspend)) { 1337 switches::kDisableMediaSuspend)) {
1321 return false; 1338 return false;
1322 } 1339 }
1323 1340
1324 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && 1341 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) &&
1325 hasAudio() && !isRemote() && delegate_ && delegate_->IsHidden(); 1342 hasAudio() && !isRemote() && delegate_ && delegate_->IsFrameHidden() &&
1343 !delegate_->IsFrameClosed();
1326 } 1344 }
1327 1345
1328 } // namespace content 1346 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698