| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 if ((*it)->IsPlayerReady() && !(*it)->IsPlaying() && | 327 if ((*it)->IsPlayerReady() && !(*it)->IsPlaying() && |
| 327 fullscreen_player_id_ != (*it)->player_id()) { | 328 fullscreen_player_id_ != (*it)->player_id()) { |
| 328 (*it)->Release(); | 329 (*it)->Release(); |
| 329 Send(new MediaPlayerMsg_MediaPlayerReleased( | 330 Send(new MediaPlayerMsg_MediaPlayerReleased( |
| 330 routing_id(), (*it)->player_id())); | 331 routing_id(), (*it)->player_id())); |
| 331 } | 332 } |
| 332 } | 333 } |
| 333 } | 334 } |
| 334 | 335 |
| 335 void BrowserMediaPlayerManager::ReleaseMediaResources(int player_id) { | 336 void BrowserMediaPlayerManager::ReleaseMediaResources(int player_id) { |
| 336 // Nothing needs to be done. | 337 #if defined(VIDEO_HOLE) |
| 338 ExternalVideoSurfaceContainer* surface_container = |
| 339 ExternalVideoSurfaceContainer::FromWebContents(web_contents_); |
| 340 if (surface_container) |
| 341 surface_container->ReleaseExternalVideoSurface(player_id); |
| 342 #endif // defined(VIDEO_HOLE) |
| 337 } | 343 } |
| 338 | 344 |
| 339 media::MediaResourceGetter* | 345 media::MediaResourceGetter* |
| 340 BrowserMediaPlayerManager::GetMediaResourceGetter() { | 346 BrowserMediaPlayerManager::GetMediaResourceGetter() { |
| 341 if (!media_resource_getter_.get()) { | 347 if (!media_resource_getter_.get()) { |
| 342 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); | 348 RenderProcessHost* host = web_contents()->GetRenderProcessHost(); |
| 343 BrowserContext* context = host->GetBrowserContext(); | 349 BrowserContext* context = host->GetBrowserContext(); |
| 344 StoragePartition* partition = host->GetStoragePartition(); | 350 StoragePartition* partition = host->GetStoragePartition(); |
| 345 fileapi::FileSystemContext* file_system_context = | 351 fileapi::FileSystemContext* file_system_context = |
| 346 partition ? partition->GetFileSystemContext() : NULL; | 352 partition ? partition->GetFileSystemContext() : NULL; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 MediaPlayerAndroid* player = GetPlayer(player_id); | 470 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 465 if (player) | 471 if (player) |
| 466 player->SetVideoSurface(gfx::ScopedJavaSurface()); | 472 player->SetVideoSurface(gfx::ScopedJavaSurface()); |
| 467 } | 473 } |
| 468 | 474 |
| 469 void BrowserMediaPlayerManager::OnNotifyExternalSurface( | 475 void BrowserMediaPlayerManager::OnNotifyExternalSurface( |
| 470 int player_id, bool is_request, const gfx::RectF& rect) { | 476 int player_id, bool is_request, const gfx::RectF& rect) { |
| 471 if (!web_contents_) | 477 if (!web_contents_) |
| 472 return; | 478 return; |
| 473 | 479 |
| 474 WebContentsViewAndroid* view = | 480 ExternalVideoSurfaceContainer::CreateForWebContents(web_contents_); |
| 475 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | 481 ExternalVideoSurfaceContainer* surface_container = |
| 476 if (view) | 482 ExternalVideoSurfaceContainer::FromWebContents(web_contents_); |
| 477 view->NotifyExternalSurface(player_id, is_request, rect); | 483 if (!surface_container) |
| 484 return; |
| 485 |
| 486 if (is_request) { |
| 487 // It's safe to use base::Unretained(this), because the callbacks will not |
| 488 // be called after running ReleaseExternalVideoSurface(). |
| 489 surface_container->RequestExternalVideoSurface( |
| 490 player_id, |
| 491 base::Bind(&BrowserMediaPlayerManager::AttachExternalVideoSurface, |
| 492 base::Unretained(this)), |
| 493 base::Bind(&BrowserMediaPlayerManager::DetachExternalVideoSurface, |
| 494 base::Unretained(this))); |
| 495 } |
| 496 surface_container->OnExternalVideoSurfacePositionChanged(player_id, rect); |
| 478 } | 497 } |
| 479 #endif // defined(VIDEO_HOLE) | 498 #endif // defined(VIDEO_HOLE) |
| 480 | 499 |
| 481 void BrowserMediaPlayerManager::DisableFullscreenEncryptedMediaPlayback() { | 500 void BrowserMediaPlayerManager::DisableFullscreenEncryptedMediaPlayback() { |
| 482 if (fullscreen_player_id_ == -1) | 501 if (fullscreen_player_id_ == -1) |
| 483 return; | 502 return; |
| 484 | 503 |
| 485 // If the fullscreen player is not playing back encrypted video, do nothing. | 504 // If the fullscreen player is not playing back encrypted video, do nothing. |
| 486 MediaDrmBridge* drm_bridge = GetDrmBridge(fullscreen_player_id_); | 505 MediaDrmBridge* drm_bridge = GetDrmBridge(fullscreen_player_id_); |
| 487 if (!drm_bridge) | 506 if (!drm_bridge) |
| 488 return; | 507 return; |
| 489 | 508 |
| 490 // Exit fullscreen. | 509 // Exit fullscreen. |
| 491 pending_fullscreen_player_id_ = fullscreen_player_id_; | 510 pending_fullscreen_player_id_ = fullscreen_player_id_; |
| 492 OnExitFullscreen(fullscreen_player_id_); | 511 OnExitFullscreen(fullscreen_player_id_); |
| 493 } | 512 } |
| 494 | 513 |
| 495 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { | 514 void BrowserMediaPlayerManager::OnEnterFullscreen(int player_id) { |
| 496 DCHECK_EQ(fullscreen_player_id_, -1); | 515 DCHECK_EQ(fullscreen_player_id_, -1); |
| 497 if (media_keys_ids_pending_approval_.find(player_id) != | 516 if (media_keys_ids_pending_approval_.find(player_id) != |
| 498 media_keys_ids_pending_approval_.end()) { | 517 media_keys_ids_pending_approval_.end()) { |
| 499 return; | 518 return; |
| 500 } | 519 } |
| 501 | 520 |
| 521 #if defined(VIDEO_HOLE) |
| 522 ExternalVideoSurfaceContainer* surface_container = |
| 523 ExternalVideoSurfaceContainer::FromWebContents(web_contents_); |
| 524 if (surface_container) |
| 525 surface_container->ReleaseExternalVideoSurface(player_id); |
| 526 #endif // defined(VIDEO_HOLE) |
| 502 if (video_view_.get()) { | 527 if (video_view_.get()) { |
| 503 fullscreen_player_id_ = player_id; | 528 fullscreen_player_id_ = player_id; |
| 504 video_view_->OpenVideo(); | 529 video_view_->OpenVideo(); |
| 505 } else if (!ContentVideoView::GetInstance()) { | 530 } else if (!ContentVideoView::GetInstance()) { |
| 506 // In Android WebView, two ContentViewCores could both try to enter | 531 // In Android WebView, two ContentViewCores could both try to enter |
| 507 // fullscreen video, we just ignore the second one. | 532 // fullscreen video, we just ignore the second one. |
| 508 fullscreen_player_id_ = player_id; | 533 fullscreen_player_id_ = player_id; |
| 509 video_view_.reset(new ContentVideoView(this)); | 534 video_view_.reset(new ContentVideoView(this)); |
| 510 } | 535 } |
| 511 } | 536 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { | 589 void BrowserMediaPlayerManager::OnSetVolume(int player_id, double volume) { |
| 565 MediaPlayerAndroid* player = GetPlayer(player_id); | 590 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 566 if (player) | 591 if (player) |
| 567 player->SetVolume(volume); | 592 player->SetVolume(volume); |
| 568 } | 593 } |
| 569 | 594 |
| 570 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { | 595 void BrowserMediaPlayerManager::OnReleaseResources(int player_id) { |
| 571 MediaPlayerAndroid* player = GetPlayer(player_id); | 596 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 572 if (player) | 597 if (player) |
| 573 player->Release(); | 598 player->Release(); |
| 574 | |
| 575 #if defined(VIDEO_HOLE) | |
| 576 WebContentsViewAndroid* view = | |
| 577 static_cast<WebContentsViewAndroid*>(web_contents_->GetView()); | |
| 578 if (view) | |
| 579 view->NotifyExternalSurface(player_id, false, gfx::RectF()); | |
| 580 #endif // defined(VIDEO_HOLE) | |
| 581 } | 599 } |
| 582 | 600 |
| 583 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { | 601 void BrowserMediaPlayerManager::OnDestroyPlayer(int player_id) { |
| 584 RemovePlayer(player_id); | 602 RemovePlayer(player_id); |
| 585 if (fullscreen_player_id_ == player_id) | 603 if (fullscreen_player_id_ == player_id) |
| 586 fullscreen_player_id_ = -1; | 604 fullscreen_player_id_ = -1; |
| 587 } | 605 } |
| 588 | 606 |
| 589 void BrowserMediaPlayerManager::OnInitializeCDM( | 607 void BrowserMediaPlayerManager::OnInitializeCDM( |
| 590 int media_keys_id, | 608 int media_keys_id, |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 if (player->IsPlaying()) | 870 if (player->IsPlaying()) |
| 853 OnProtectedSurfaceRequested(media_keys_id); | 871 OnProtectedSurfaceRequested(media_keys_id); |
| 854 } | 872 } |
| 855 | 873 |
| 856 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer( | 874 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer( |
| 857 MediaPlayerAndroid* player) { | 875 MediaPlayerAndroid* player) { |
| 858 player->Release(); | 876 player->Release(); |
| 859 } | 877 } |
| 860 | 878 |
| 861 } // namespace content | 879 } // namespace content |
| OLD | NEW |