OLD | NEW |
---|---|
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 Loading... | |
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; | |
344 if (external_video_surface_container_) | |
345 current_player = external_video_surface_container_->GetCurrentPlayerId(); | |
346 if (current_player < 0) | |
347 return; | |
348 | |
349 if (current_player != future_player) | |
350 OnMediaInterrupted(current_player); | |
351 } | |
352 | |
341 void BrowserMediaPlayerManager::OnRequestExternalSurface( | 353 void BrowserMediaPlayerManager::OnRequestExternalSurface( |
342 int player_id, const gfx::RectF& rect) { | 354 int player_id, const gfx::RectF& rect) { |
343 if (!external_video_surface_container_) { | 355 if (!external_video_surface_container_) { |
344 ContentBrowserClient* client = GetContentClient()->browser(); | 356 ContentBrowserClient* client = GetContentClient()->browser(); |
345 external_video_surface_container_.reset( | 357 external_video_surface_container_.reset( |
346 client->OverrideCreateExternalVideoSurfaceContainer(web_contents_)); | 358 client->OverrideCreateExternalVideoSurfaceContainer(web_contents_)); |
347 } | 359 } |
348 // It's safe to use base::Unretained(this), because the callbacks will not | 360 // It's safe to use base::Unretained(this), because the callbacks will not |
349 // be called after running ReleaseExternalVideoSurface(). | 361 // be called after running ReleaseExternalVideoSurface(). |
350 if (external_video_surface_container_) { | 362 if (external_video_surface_container_) { |
363 // In case we're stealing the external surface from another player. | |
364 ReleasePlayerOfExternalVideoSurfaceIfNeeded(player_id); | |
351 external_video_surface_container_->RequestExternalVideoSurface( | 365 external_video_surface_container_->RequestExternalVideoSurface( |
352 player_id, | 366 player_id, |
353 base::Bind(&BrowserMediaPlayerManager::AttachExternalVideoSurface, | 367 base::Bind(&BrowserMediaPlayerManager::AttachExternalVideoSurface, |
354 base::Unretained(this)), | 368 base::Unretained(this)), |
355 base::Bind(&BrowserMediaPlayerManager::DetachExternalVideoSurface, | 369 base::Bind(&BrowserMediaPlayerManager::DetachExternalVideoSurface, |
356 base::Unretained(this))); | 370 base::Unretained(this))); |
357 } | 371 } |
358 } | 372 } |
359 #endif // defined(VIDEO_HOLE) | 373 #endif // defined(VIDEO_HOLE) |
360 | 374 |
361 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { | 375 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { |
362 DCHECK_EQ(fullscreen_player_id_, -1); | 376 DCHECK_EQ(fullscreen_player_id_, -1); |
363 #if defined(VIDEO_HOLE) | 377 #if defined(VIDEO_HOLE) |
378 // If this fullscreen player is started when another player | |
379 // uses the external surface, release that other player. | |
380 ReleasePlayerOfExternalVideoSurfaceIfNeeded(player_id); | |
364 if (external_video_surface_container_) | 381 if (external_video_surface_container_) |
365 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); | 382 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); |
boliu
2014/12/08 17:51:47
Shouldn't this be the player id of the one holding
Hugo Holgersson
2014/12/09 15:35:28
Yes, you are right about when entering fullscreen
boliu
2014/12/09 18:15:18
o_o
| |
366 #endif // defined(VIDEO_HOLE) | 383 #endif // defined(VIDEO_HOLE) |
367 if (video_view_.get()) { | 384 if (video_view_.get()) { |
368 fullscreen_player_id_ = player_id; | 385 fullscreen_player_id_ = player_id; |
369 video_view_->OpenVideo(); | 386 video_view_->OpenVideo(); |
370 return; | 387 return; |
371 } else if (!ContentVideoView::GetInstance()) { | 388 } else if (!ContentVideoView::GetInstance()) { |
372 // In Android WebView, two ContentViewCores could both try to enter | 389 // In Android WebView, two ContentViewCores could both try to enter |
373 // fullscreen video, we just ignore the second one. | 390 // fullscreen video, we just ignore the second one. |
374 video_view_.reset(new ContentVideoView(this)); | 391 video_view_.reset(new ContentVideoView(this)); |
375 base::android::ScopedJavaLocalRef<jobject> j_content_video_view = | 392 base::android::ScopedJavaLocalRef<jobject> j_content_video_view = |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); | 574 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); |
558 #endif // defined(VIDEO_HOLE) | 575 #endif // defined(VIDEO_HOLE) |
559 } | 576 } |
560 | 577 |
561 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) { | 578 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) { |
562 player->Release(); | 579 player->Release(); |
563 ReleaseMediaResources(player->player_id()); | 580 ReleaseMediaResources(player->player_id()); |
564 } | 581 } |
565 | 582 |
566 } // namespace content | 583 } // namespace content |
OLD | NEW |