| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/browser/android/content_view_core_impl.h" | 8 #include "content/browser/android/content_view_core_impl.h" |
| 9 #include "content/browser/media/android/browser_demuxer_android.h" | 9 #include "content/browser/media/android/browser_demuxer_android.h" |
| 10 #include "content/browser/media/android/media_resource_getter_impl.h" | 10 #include "content/browser/media/android/media_resource_getter_impl.h" |
| 11 #include "content/browser/renderer_host/render_view_host_impl.h" | 11 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 12 #include "content/browser/web_contents/web_contents_view_android.h" | 12 #include "content/browser/web_contents/web_contents_view_android.h" |
| 13 #include "content/common/media/media_player_messages_android.h" | 13 #include "content/common/media/media_player_messages_android.h" |
| 14 #include "content/public/browser/android/content_view_core.h" | 14 #include "content/public/browser/android/content_view_core.h" |
| 15 #include "content/public/browser/android/external_video_surface_container.h" |
| 15 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| 17 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
| 18 #include "content/public/browser/storage_partition.h" | 19 #include "content/public/browser/storage_partition.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_delegate.h" | 21 #include "content/public/browser/web_contents_delegate.h" |
| 21 #include "content/public/common/content_client.h" | 22 #include "content/public/common/content_client.h" |
| 22 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 23 #include "media/base/android/media_drm_bridge.h" | 24 #include "media/base/android/media_drm_bridge.h" |
| 24 #include "media/base/android/media_player_bridge.h" | 25 #include "media/base/android/media_player_bridge.h" |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 if ((*it)->IsPlayerReady() && !(*it)->IsPlaying() && | 320 if ((*it)->IsPlayerReady() && !(*it)->IsPlaying() && |
| 320 fullscreen_player_id_ != (*it)->player_id()) { | 321 fullscreen_player_id_ != (*it)->player_id()) { |
| 321 (*it)->Release(); | 322 (*it)->Release(); |
| 322 Send(new MediaPlayerMsg_MediaPlayerReleased( | 323 Send(new MediaPlayerMsg_MediaPlayerReleased( |
| 323 routing_id(), (*it)->player_id())); | 324 routing_id(), (*it)->player_id())); |
| 324 } | 325 } |
| 325 } | 326 } |
| 326 } | 327 } |
| 327 | 328 |
| 328 void BrowserMediaPlayerManager::ReleaseMediaResources(int player_id) { | 329 void BrowserMediaPlayerManager::ReleaseMediaResources(int player_id) { |
| 329 // Nothing needs to be done. | 330 #if defined(VIDEO_HOLE) |
| 331 ExternalVideoSurfaceContainer* surface_container = |
| 332 ExternalVideoSurfaceContainer::FromWebContents(web_contents_); |
| 333 if (surface_container) |
| 334 surface_container->ReleaseExternalVideoSurface(player_id); |
| 335 #endif // defined(VIDEO_HOLE) |
| 330 } | 336 } |
| 331 | 337 |
| 332 media::MediaResourceGetter* | 338 media::MediaResourceGetter* |
| 333 BrowserMediaPlayerManager::GetMediaResourceGetter() { | 339 BrowserMediaPlayerManager::GetMediaResourceGetter() { |
| 334 if (!media_resource_getter_.get()) { | 340 if (!media_resource_getter_.get()) { |
| 335 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); | 341 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); |
| 336 BrowserContext* context = host->GetBrowserContext(); | 342 BrowserContext* context = host->GetBrowserContext(); |
| 337 StoragePartition* partition = host->GetStoragePartition(); | 343 StoragePartition* partition = host->GetStoragePartition(); |
| 338 fileapi::FileSystemContext* file_system_context = | 344 fileapi::FileSystemContext* file_system_context = |
| 339 partition ? partition->GetFileSystemContext() : NULL; | 345 partition ? partition->GetFileSystemContext() : NULL; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 MediaPlayerAndroid* player = GetPlayer(player_id); | 463 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 458 if (player) | 464 if (player) |
| 459 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 465 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
| 460 } | 466 } |
| 461 | 467 |
| 462 void BrowserMediaPlayerManager::OnNotifyExternalSurface( | 468 void BrowserMediaPlayerManager::OnNotifyExternalSurface( |
| 463 int player_id, bool is_request, const gfx::RectF& rect) { | 469 int player_id, bool is_request, const gfx::RectF& rect) { |
| 464 if (!web_contents_) | 470 if (!web_contents_) |
| 465 return; | 471 return; |
| 466 | 472 |
| 467 WebContentsViewAndroid* view = | 473 ExternalVideoSurfaceContainer::CreateForWebContents(web_contents_); |
| 468 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | 474 ExternalVideoSurfaceContainer* surface_container = |
| 469 if (view) | 475 ExternalVideoSurfaceContainer::FromWebContents(web_contents_); |
| 470 view->NotifyExternalSurface(player_id, is_request, rect); | 476 if (!surface_container) |
| 477 return; |
| 478 |
| 479 if (is_request) { |
| 480 // It's safe to use base::Unretained(this), because the callbacks will not |
| 481 // be called after running ReleaseExternalVideoSurface(). |
| 482 surface_container->RequestExternalVideoSurface( |
| 483 player_id, |
| 484 base::Bind(&BrowserMediaPlayerManager::AttachExternalVideoSurface, |
| 485 base::Unretained(this)), |
| 486 base::Bind(&BrowserMediaPlayerManager::DetachExternalVideoSurface, |
| 487 base::Unretained(this))); |
| 488 } |
| 489 surface_container->OnExternalVideoSurfacePositionChanged(player_id, rect); |
| 471 } | 490 } |
| 472 #endif // defined(VIDEO_HOLE) | 491 #endif // defined(VIDEO_HOLE) |
| 473 | 492 |
| 474 void BrowserMediaPlayerManager::DisableFullscreenEncryptedMediaPlayback() { | 493 void BrowserMediaPlayerManager::DisableFullscreenEncryptedMediaPlayback() { |
| 475 if (fullscreen_player_id_ == -1) | 494 if (fullscreen_player_id_ == -1) |
| 476 return; | 495 return; |
| 477 | 496 |
| 478 // If the fullscreen player is not playing back encrypted video, do nothing. | 497 // If the fullscreen player is not playing back encrypted video, do nothing. |
| 479 MediaDrmBridge* drm_bridge = GetDrmBridge(fullscreen_player_id_); | 498 MediaDrmBridge* drm_bridge = GetDrmBridge(fullscreen_player_id_); |
| 480 if (!drm_bridge) | 499 if (!drm_bridge) |
| 481 return; | 500 return; |
| 482 | 501 |
| 483 // Exit fullscreen. | 502 // Exit fullscreen. |
| 484 pending_fullscreen_player_id_ = fullscreen_player_id_; | 503 pending_fullscreen_player_id_ = fullscreen_player_id_; |
| 485 OnExitFullscreen(fullscreen_player_id_); | 504 OnExitFullscreen(fullscreen_player_id_); |
| 486 } | 505 } |
| 487 | 506 |
| 488 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { | 507 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { |
| 489 DCHECK_EQ(fullscreen_player_id_, -1); | 508 DCHECK_EQ(fullscreen_player_id_, -1); |
| 490 if (media_keys_ids_pending_approval_.find(player_id) != | 509 if (media_keys_ids_pending_approval_.find(player_id) != |
| 491 media_keys_ids_pending_approval_.end()) { | 510 media_keys_ids_pending_approval_.end()) { |
| 492 return; | 511 return; |
| 493 } | 512 } |
| 494 | 513 |
| 514 #if defined(VIDEO_HOLE) |
| 515 ExternalVideoSurfaceContainer* surface_container = |
| 516 ExternalVideoSurfaceContainer::FromWebContents(web_contents_); |
| 517 if (surface_container) |
| 518 surface_container->ReleaseExternalVideoSurface(player_id); |
| 519 #endif // defined(VIDEO_HOLE) |
| 495 if (video_view_.get()) { | 520 if (video_view_.get()) { |
| 496 fullscreen_player_id_ = player_id; | 521 fullscreen_player_id_ = player_id; |
| 497 video_view_->OpenVideo(); | 522 video_view_->OpenVideo(); |
| 498 } else if (!ContentVideoView::GetInstance()) { | 523 } else if (!ContentVideoView::GetInstance()) { |
| 499 // In Android WebView, two ContentViewCores could both try to enter | 524 // In Android WebView, two ContentViewCores could both try to enter |
| 500 // fullscreen video, we just ignore the second one. | 525 // fullscreen video, we just ignore the second one. |
| 501 fullscreen_player_id_ = player_id; | 526 fullscreen_player_id_ = player_id; |
| 502 video_view_.reset(new ContentVideoView(this)); | 527 video_view_.reset(new ContentVideoView(this)); |
| 503 } | 528 } |
| 504 } | 529 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 void BrowserMediaPlayerManager::OnSetPoster(int player_id, const GURL& url) { | 588 void BrowserMediaPlayerManager::OnSetPoster(int player_id, const GURL& url) { |
| 564 // To be overridden by subclasses. | 589 // To be overridden by subclasses. |
| 565 } | 590 } |
| 566 | 591 |
| 567 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { | 592 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { |
| 568 MediaPlayerAndroid* player = GetPlayer(player_id); | 593 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 569 if (player) | 594 if (player) |
| 570 player->Release(); | 595 player->Release(); |
| 571 if (player_id == fullscreen_player_id_) | 596 if (player_id == fullscreen_player_id_) |
| 572 fullscreen_player_is_released_ = true; | 597 fullscreen_player_is_released_ = true; |
| 573 | |
| 574 #if defined(VIDEO_HOLE) | |
| 575 WebContentsViewAndroid* view = | |
| 576 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | |
| 577 if (view) | |
| 578 view->NotifyExternalSurface(player_id, false, gfx::RectF()); | |
| 579 #endif // defined(VIDEO_HOLE) | |
| 580 } | 598 } |
| 581 | 599 |
| 582 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { | 600 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { |
| 583 RemovePlayer(player_id); | 601 RemovePlayer(player_id); |
| 584 if (fullscreen_player_id_ == player_id) | 602 if (fullscreen_player_id_ == player_id) |
| 585 fullscreen_player_id_ = -1; | 603 fullscreen_player_id_ = -1; |
| 586 } | 604 } |
| 587 | 605 |
| 588 void BrowserMediaPlayerManager::OnInitializeCDM( | 606 void BrowserMediaPlayerManager::OnInitializeCDM( |
| 589 int media_keys_id, | 607 int media_keys_id, |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 if (player->IsPlaying()) | 876 if (player->IsPlaying()) |
| 859 OnProtectedSurfaceRequested(media_keys_id); | 877 OnProtectedSurfaceRequested(media_keys_id); |
| 860 } | 878 } |
| 861 | 879 |
| 862 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer( | 880 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer( |
| 863 MediaPlayerAndroid* player) { | 881 MediaPlayerAndroid* player) { |
| 864 player->Release(); | 882 player->Release(); |
| 865 } | 883 } |
| 866 | 884 |
| 867 } // namespace content | 885 } // namespace content |
| OLD | NEW |