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: 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: Add Chromecast and remove unneeded JNI Created 6 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/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 = -1;
mkosiba (inactive) 2015/01/05 14:58:24 maybe explicitly initialize to kInvalidPlayerId ?
Hugo Holgersson 2015/01/05 16:02:24 Done.
344 if (external_video_surface_container_)
345 current_player = external_video_surface_container_->GetCurrentPlayerId();
346
347 if (current_player == ExternalVideoSurfaceContainer::kInvalidPlayerId)
348 return;
349
350 if (current_player != future_player)
351 OnMediaInterrupted(current_player);
352 }
353
341 void BrowserMediaPlayerManager::OnRequestExternalSurface( 354 void BrowserMediaPlayerManager::OnRequestExternalSurface(
342 int player_id, const gfx::RectF& rect) { 355 int player_id, const gfx::RectF& rect) {
343 if (!external_video_surface_container_) { 356 if (!external_video_surface_container_) {
344 ContentBrowserClient* client = GetContentClient()->browser(); 357 ContentBrowserClient* client = GetContentClient()->browser();
345 external_video_surface_container_.reset( 358 external_video_surface_container_.reset(
346 client->OverrideCreateExternalVideoSurfaceContainer(web_contents_)); 359 client->OverrideCreateExternalVideoSurfaceContainer(web_contents_));
347 } 360 }
348 // It's safe to use base::Unretained(this), because the callbacks will not 361 // It's safe to use base::Unretained(this), because the callbacks will not
349 // be called after running ReleaseExternalVideoSurface(). 362 // be called after running ReleaseExternalVideoSurface().
350 if (external_video_surface_container_) { 363 if (external_video_surface_container_) {
364 // In case we're stealing the external surface from another player.
365 ReleasePlayerOfExternalVideoSurfaceIfNeeded(player_id);
351 external_video_surface_container_->RequestExternalVideoSurface( 366 external_video_surface_container_->RequestExternalVideoSurface(
352 player_id, 367 player_id,
353 base::Bind(&BrowserMediaPlayerManager::AttachExternalVideoSurface, 368 base::Bind(&BrowserMediaPlayerManager::AttachExternalVideoSurface,
354 base::Unretained(this)), 369 base::Unretained(this)),
355 base::Bind(&BrowserMediaPlayerManager::DetachExternalVideoSurface, 370 base::Bind(&BrowserMediaPlayerManager::DetachExternalVideoSurface,
356 base::Unretained(this))); 371 base::Unretained(this)));
357 } 372 }
358 } 373 }
359 #endif // defined(VIDEO_HOLE) 374 #endif // defined(VIDEO_HOLE)
360 375
361 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { 376 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) {
362 DCHECK_EQ(fullscreen_player_id_, -1); 377 DCHECK_EQ(fullscreen_player_id_, -1);
363 #if defined(VIDEO_HOLE) 378 #if defined(VIDEO_HOLE)
379 // If this fullscreen player is started when another player
380 // uses the external surface, release that other player.
381 ReleasePlayerOfExternalVideoSurfaceIfNeeded(player_id);
364 if (external_video_surface_container_) 382 if (external_video_surface_container_)
365 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); 383 external_video_surface_container_->ReleaseExternalVideoSurface(player_id);
366 #endif // defined(VIDEO_HOLE) 384 #endif // defined(VIDEO_HOLE)
367 if (video_view_.get()) { 385 if (video_view_.get()) {
368 fullscreen_player_id_ = player_id; 386 fullscreen_player_id_ = player_id;
369 video_view_->OpenVideo(); 387 video_view_->OpenVideo();
370 return; 388 return;
371 } else if (!ContentVideoView::GetInstance()) { 389 } else if (!ContentVideoView::GetInstance()) {
372 // In Android WebView, two ContentViewCores could both try to enter 390 // In Android WebView, two ContentViewCores could both try to enter
373 // fullscreen video, we just ignore the second one. 391 // 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); 575 external_video_surface_container_->ReleaseExternalVideoSurface(player_id);
558 #endif // defined(VIDEO_HOLE) 576 #endif // defined(VIDEO_HOLE)
559 } 577 }
560 578
561 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) { 579 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) {
562 player->Release(); 580 player->Release();
563 ReleaseMediaResources(player->player_id()); 581 ReleaseMediaResources(player->player_id());
564 } 582 }
565 583
566 } // namespace content 584 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698