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

Side by Side Diff: content/browser/media/android/browser_media_player_manager.cc

Issue 714643002: Pause EME player whose external surface is stolen by another player (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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/browser/media/android/browser_media_player_manager.h" 5 #include "content/browser/media/android/browser_media_player_manager.h"
6 6
7 #include "base/android/scoped_java_ref.h" 7 #include "base/android/scoped_java_ref.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "content/browser/android/content_view_core_impl.h" 9 #include "content/browser/android/content_view_core_impl.h"
10 #include "content/browser/media/android/browser_demuxer_android.h" 10 #include "content/browser/media/android/browser_demuxer_android.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 331
332 if (is_request) { 332 if (is_request) {
333 OnRequestExternalSurface(player_id, rect); 333 OnRequestExternalSurface(player_id, rect);
334 } 334 }
335 if (external_video_surface_container_) { 335 if (external_video_surface_container_) {
336 external_video_surface_container_->OnExternalVideoSurfacePositionChanged( 336 external_video_surface_container_->OnExternalVideoSurfacePositionChanged(
337 player_id, rect); 337 player_id, rect);
338 } 338 }
339 } 339 }
340 340
341 void BrowserMediaPlayerManager::ReleasePlayerOfExternalVideoSurfaceIfNeeded(
342 int future_player) {
343 int current_player = ExternalVideoSurfaceContainer::kInvalidPlayerId;
344
345 if (external_video_surface_container_)
346 current_player = external_video_surface_container_->GetCurrentPlayerId();
347
348 if (current_player == ExternalVideoSurfaceContainer::kInvalidPlayerId)
349 return;
350
351 if (current_player != future_player)
352 OnMediaInterrupted(current_player);
353 }
354
341 void BrowserMediaPlayerManager::OnRequestExternalSurface( 355 void BrowserMediaPlayerManager::OnRequestExternalSurface(
342 int player_id, const gfx::RectF& rect) { 356 int player_id, const gfx::RectF& rect) {
343 if (!external_video_surface_container_) { 357 if (!external_video_surface_container_) {
344 ContentBrowserClient* client = GetContentClient()->browser(); 358 ContentBrowserClient* client = GetContentClient()->browser();
345 external_video_surface_container_.reset( 359 external_video_surface_container_.reset(
346 client->OverrideCreateExternalVideoSurfaceContainer(web_contents_)); 360 client->OverrideCreateExternalVideoSurfaceContainer(web_contents_));
347 } 361 }
348 // It's safe to use base::Unretained(this), because the callbacks will not 362 // It's safe to use base::Unretained(this), because the callbacks will not
349 // be called after running ReleaseExternalVideoSurface(). 363 // be called after running ReleaseExternalVideoSurface().
350 if (external_video_surface_container_) { 364 if (external_video_surface_container_) {
365 // In case we're stealing the external surface from another player.
366 ReleasePlayerOfExternalVideoSurfaceIfNeeded(player_id);
351 external_video_surface_container_->RequestExternalVideoSurface( 367 external_video_surface_container_->RequestExternalVideoSurface(
352 player_id, 368 player_id,
353 base::Bind(&BrowserMediaPlayerManager::AttachExternalVideoSurface, 369 base::Bind(&BrowserMediaPlayerManager::AttachExternalVideoSurface,
354 base::Unretained(this)), 370 base::Unretained(this)),
355 base::Bind(&BrowserMediaPlayerManager::DetachExternalVideoSurface, 371 base::Bind(&BrowserMediaPlayerManager::DetachExternalVideoSurface,
356 base::Unretained(this))); 372 base::Unretained(this)));
357 } 373 }
358 } 374 }
359 #endif // defined(VIDEO_HOLE) 375 #endif // defined(VIDEO_HOLE)
360 376
361 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { 377 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) {
362 DCHECK_EQ(fullscreen_player_id_, -1); 378 DCHECK_EQ(fullscreen_player_id_, -1);
363 #if defined(VIDEO_HOLE) 379 #if defined(VIDEO_HOLE)
380 // If this fullscreen player is started when another player
381 // uses the external surface, release that other player.
382 ReleasePlayerOfExternalVideoSurfaceIfNeeded(player_id);
364 if (external_video_surface_container_) 383 if (external_video_surface_container_)
365 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); 384 external_video_surface_container_->ReleaseExternalVideoSurface(player_id);
366 #endif // defined(VIDEO_HOLE) 385 #endif // defined(VIDEO_HOLE)
367 if (video_view_.get()) { 386 if (video_view_.get()) {
368 fullscreen_player_id_ = player_id; 387 fullscreen_player_id_ = player_id;
369 video_view_->OpenVideo(); 388 video_view_->OpenVideo();
370 return; 389 return;
371 } else if (!ContentVideoView::GetInstance()) { 390 } else if (!ContentVideoView::GetInstance()) {
372 // In Android WebView, two ContentViewCores could both try to enter 391 // In Android WebView, two ContentViewCores could both try to enter
373 // fullscreen video, we just ignore the second one. 392 // fullscreen video, we just ignore the second one.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); 576 external_video_surface_container_->ReleaseExternalVideoSurface(player_id);
558 #endif // defined(VIDEO_HOLE) 577 #endif // defined(VIDEO_HOLE)
559 } 578 }
560 579
561 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) { 580 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) {
562 player->Release(); 581 player->Release();
563 ReleaseMediaResources(player->player_id()); 582 ReleaseMediaResources(player->player_id());
564 } 583 }
565 584
566 } // namespace content 585 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698