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

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

Issue 1766783003: Expand suspension of idle media players to all platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notify_pause
Patch Set: Fixup API comments. 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
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_ms.h" 5 #include "content/renderer/media/webmediaplayer_ms.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 media_task_runner_(media_task_runner), 60 media_task_runner_(media_task_runner),
61 worker_task_runner_(worker_task_runner), 61 worker_task_runner_(worker_task_runner),
62 gpu_factories_(gpu_factories), 62 gpu_factories_(gpu_factories),
63 compositor_task_runner_(compositor_task_runner), 63 compositor_task_runner_(compositor_task_runner),
64 initial_audio_output_device_id_(sink_id.utf8()), 64 initial_audio_output_device_id_(sink_id.utf8()),
65 initial_security_origin_(security_origin.isNull() 65 initial_security_origin_(security_origin.isNull()
66 ? url::Origin() 66 ? url::Origin()
67 : url::Origin(security_origin)), 67 : url::Origin(security_origin)),
68 volume_(1.0), 68 volume_(1.0),
69 volume_multiplier_(1.0), 69 volume_multiplier_(1.0),
70 paused_on_hidden_(false) { 70 should_play_upon_shown_(false) {
71 DVLOG(1) << __FUNCTION__; 71 DVLOG(1) << __FUNCTION__;
72 DCHECK(client); 72 DCHECK(client);
73 if (delegate_) 73 if (delegate_)
74 delegate_id_ = delegate_->AddObserver(this); 74 delegate_id_ = delegate_->AddObserver(this);
75 75
76 media_log_->AddEvent( 76 media_log_->AddEvent(
77 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); 77 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED));
78 } 78 }
79 79
80 WebMediaPlayerMS::~WebMediaPlayerMS() { 80 WebMediaPlayerMS::~WebMediaPlayerMS() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 DCHECK(thread_checker_.CalledOnValidThread()); 157 DCHECK(thread_checker_.CalledOnValidThread());
158 158
159 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY)); 159 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY));
160 if (!paused_) 160 if (!paused_)
161 return; 161 return;
162 162
163 #if defined(OS_ANDROID) 163 #if defined(OS_ANDROID)
164 // Don't allow rendering to start while hidden; for either video or audio 164 // Don't allow rendering to start while hidden; for either video or audio
165 // since this may steal focus from a foreground player. 165 // since this may steal focus from a foreground player.
166 if (delegate_ && delegate_->IsHidden()) { 166 if (delegate_ && delegate_->IsHidden()) {
167 paused_on_hidden_ = true; 167 should_play_upon_shown_ = true;
168 return; 168 return;
169 } 169 }
170 #endif 170 #endif
171 171
172 if (video_frame_provider_) 172 if (video_frame_provider_)
173 video_frame_provider_->Play(); 173 video_frame_provider_->Play();
174 174
175 compositor_->StartRendering(); 175 compositor_->StartRendering();
176 176
177 if (audio_renderer_) 177 if (audio_renderer_)
178 audio_renderer_->Play(); 178 audio_renderer_->Play();
179 179
180 if (delegate_) { 180 if (delegate_) {
181 delegate_->DidPlay(delegate_id_, hasVideo(), hasAudio(), false, 181 delegate_->DidPlay(delegate_id_, hasVideo(), hasAudio(), false,
182 media::kInfiniteDuration()); 182 media::kInfiniteDuration());
183 } 183 }
184 184
185 paused_on_hidden_ = false; 185 should_play_upon_shown_ = false;
186 paused_ = false; 186 paused_ = false;
187 } 187 }
188 188
189 void WebMediaPlayerMS::pause() { 189 void WebMediaPlayerMS::pause() {
190 DVLOG(1) << __FUNCTION__; 190 DVLOG(1) << __FUNCTION__;
191 DCHECK(thread_checker_.CalledOnValidThread()); 191 DCHECK(thread_checker_.CalledOnValidThread());
192 192
193 // Always clear |paused_on_hidden_| since manual pause() should clear it and 193 should_play_upon_shown_ = false;
194 // an OnHidden() pause will set it appropriately after this call.
195 paused_on_hidden_ = false;
196 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE)); 194 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE));
197 if (paused_) 195 if (paused_)
198 return; 196 return;
199 197
200 if (video_frame_provider_) 198 if (video_frame_provider_)
201 video_frame_provider_->Pause(); 199 video_frame_provider_->Pause();
202 200
203 compositor_->StopRendering(); 201 compositor_->StopRendering();
204 compositor_->ReplaceCurrentFrameWithACopy(); 202 compositor_->ReplaceCurrentFrameWithACopy();
205 203
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 NOTIMPLEMENTED(); 371 NOTIMPLEMENTED();
374 return 0; 372 return 0;
375 } 373 }
376 374
377 size_t WebMediaPlayerMS::videoDecodedByteCount() const { 375 size_t WebMediaPlayerMS::videoDecodedByteCount() const {
378 DCHECK(thread_checker_.CalledOnValidThread()); 376 DCHECK(thread_checker_.CalledOnValidThread());
379 NOTIMPLEMENTED(); 377 NOTIMPLEMENTED();
380 return 0; 378 return 0;
381 } 379 }
382 380
383 void WebMediaPlayerMS::OnHidden(bool must_suspend) { 381 void WebMediaPlayerMS::OnHidden() {
384 #if defined(OS_ANDROID) 382 #if defined(OS_ANDROID)
385 DCHECK(thread_checker_.CalledOnValidThread()); 383 DCHECK(thread_checker_.CalledOnValidThread());
386 384
387 // Method called when the RenderFrame is sent to background and suspended 385 // Method called when the RenderFrame is sent to background and suspended
388 // (android). Substitute the displayed VideoFrame with a copy to avoid 386 // (android). Substitute the displayed VideoFrame with a copy to avoid
389 // holding on to it unnecessarily. 387 // holding on to it unnecessarily.
390 // 388 //
391 // During undoable tab closures OnHidden() may be called back to back, so we 389 // During undoable tab closures OnHidden() may be called back to back, so we
392 // can't rely on |render_frame_suspended_| being false here. 390 // can't rely on |render_frame_suspended_| being false here.
393 391
394 render_frame_suspended_ = true; 392 render_frame_suspended_ = true;
395 if (must_suspend) { 393 if (!paused_)
396 if (!paused_) {
397 pause();
398 paused_on_hidden_ = true;
399 }
400
401 if (delegate_)
402 delegate_->PlayerGone(delegate_id_);
403 } else if (!paused_) {
404 // pause() will make its own copy in the block above otherwise.
405 compositor_->ReplaceCurrentFrameWithACopy(); 394 compositor_->ReplaceCurrentFrameWithACopy();
406 }
407 #endif // defined(OS_ANDROID) 395 #endif // defined(OS_ANDROID)
408 } 396 }
409 397
410 void WebMediaPlayerMS::OnShown() { 398 void WebMediaPlayerMS::OnShown() {
411 #if defined(OS_ANDROID) 399 #if defined(OS_ANDROID)
412 DCHECK(thread_checker_.CalledOnValidThread()); 400 DCHECK(thread_checker_.CalledOnValidThread());
413 401
414 render_frame_suspended_ = false; 402 render_frame_suspended_ = false;
415 403
416 // Resume playback on visibility. play() clears |paused_on_hidden_|. 404 // Resume playback on visibility. play() clears |should_play_upon_shown_|.
417 if (paused_on_hidden_) 405 if (should_play_upon_shown_)
418 play(); 406 play();
419 #endif // defined(OS_ANDROID) 407 #endif // defined(OS_ANDROID)
420 } 408 }
421 409
410 void WebMediaPlayerMS::OnSuspendRequested(bool must_suspend) {
411 #if defined(OS_ANDROID)
412 if (!must_suspend)
413 return;
414
415 if (!paused_) {
416 pause();
417 should_play_upon_shown_ = true;
418 }
419
420 if (delegate_)
421 delegate_->PlayerGone(delegate_id_);
422
423 render_frame_suspended_ = true;
424 #endif
425 }
426
422 void WebMediaPlayerMS::OnPlay() { 427 void WebMediaPlayerMS::OnPlay() {
423 play(); 428 play();
424 client_->playbackStateChanged(); 429 client_->playbackStateChanged();
425 } 430 }
426 431
427 void WebMediaPlayerMS::OnPause() { 432 void WebMediaPlayerMS::OnPause() {
428 const bool was_playing = !paused_ || paused_on_hidden_; 433 const bool was_playing = !paused_ || should_play_upon_shown_;
429 pause(); 434 pause();
430 client_->playbackStateChanged(); 435 client_->playbackStateChanged();
431 436
432 // MediaSession may suspend the background player if a foreground player 437 // MediaSession may suspend the background player if a foreground player
433 // starts playing audio, in this case we want to track this so that when 438 // starts playing audio, in this case we want to track this so that when
434 // OnShown() is called, we resume into the right state. 439 // OnShown() is called, we resume into the right state.
435 if (was_playing && delegate_ && delegate_->IsHidden()) 440 if (was_playing && delegate_ && delegate_->IsHidden())
436 paused_on_hidden_ = true; 441 should_play_upon_shown_ = true;
437 } 442 }
438 443
439 void WebMediaPlayerMS::OnVolumeMultiplierUpdate(double multiplier) { 444 void WebMediaPlayerMS::OnVolumeMultiplierUpdate(double multiplier) {
440 volume_multiplier_ = multiplier; 445 volume_multiplier_ = multiplier;
441 setVolume(volume_); 446 setVolume(volume_);
442 } 447 }
443 448
444 bool WebMediaPlayerMS::copyVideoTextureToPlatformTexture( 449 bool WebMediaPlayerMS::copyVideoTextureToPlatformTexture(
445 blink::WebGraphicsContext3D* web_graphics_context, 450 blink::WebGraphicsContext3D* web_graphics_context,
446 unsigned int texture, 451 unsigned int texture,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 media::SkCanvasVideoRenderer* WebMediaPlayerMS::GetSkCanvasVideoRenderer() { 546 media::SkCanvasVideoRenderer* WebMediaPlayerMS::GetSkCanvasVideoRenderer() {
542 return &video_renderer_; 547 return &video_renderer_;
543 } 548 }
544 549
545 void WebMediaPlayerMS::ResetCanvasCache() { 550 void WebMediaPlayerMS::ResetCanvasCache() {
546 DCHECK(thread_checker_.CalledOnValidThread()); 551 DCHECK(thread_checker_.CalledOnValidThread());
547 video_renderer_.ResetCache(); 552 video_renderer_.ResetCache();
548 } 553 }
549 554
550 } // namespace content 555 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webmediaplayer_ms.h ('k') | content/renderer/media/webmediaplayer_ms_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698