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 "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/android/content_view_core_impl.h" | 10 #include "content/browser/android/content_view_core_impl.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "content/public/browser/storage_partition.h" | 24 #include "content/public/browser/storage_partition.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_delegate.h" | 26 #include "content/public/browser/web_contents_delegate.h" |
27 #include "content/public/common/content_client.h" | 27 #include "content/public/common/content_client.h" |
28 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
29 #include "media/base/android/media_player_bridge.h" | 29 #include "media/base/android/media_player_bridge.h" |
30 #include "media/base/android/media_source_player.h" | 30 #include "media/base/android/media_source_player.h" |
31 #include "media/base/cdm_factory.h" | 31 #include "media/base/cdm_factory.h" |
32 #include "media/base/media_switches.h" | 32 #include "media/base/media_switches.h" |
33 | 33 |
34 using media::MediaKeys; | 34 using media::MediaDrmBridge; |
35 using media::MediaPlayerAndroid; | 35 using media::MediaPlayerAndroid; |
36 using media::MediaPlayerBridge; | 36 using media::MediaPlayerBridge; |
37 using media::MediaPlayerManager; | 37 using media::MediaPlayerManager; |
38 using media::MediaSourcePlayer; | 38 using media::MediaSourcePlayer; |
39 | 39 |
40 namespace content { | 40 namespace content { |
41 | 41 |
42 // Threshold on the number of media players per renderer before we start | 42 // Threshold on the number of media players per renderer before we start |
43 // attempting to release inactive media players. | 43 // attempting to release inactive media players. |
44 const int kMediaPlayerThreshold = 1; | 44 const int kMediaPlayerThreshold = 1; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 310 |
311 MediaPlayerAndroid* BrowserMediaPlayerManager::GetPlayer(int player_id) { | 311 MediaPlayerAndroid* BrowserMediaPlayerManager::GetPlayer(int player_id) { |
312 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); | 312 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); |
313 it != players_.end(); ++it) { | 313 it != players_.end(); ++it) { |
314 if ((*it)->player_id() == player_id) | 314 if ((*it)->player_id() == player_id) |
315 return *it; | 315 return *it; |
316 } | 316 } |
317 return NULL; | 317 return NULL; |
318 } | 318 } |
319 | 319 |
320 MediaKeys* BrowserMediaPlayerManager::GetCdm(int cdm_id) { | 320 MediaDrmBridge* BrowserMediaPlayerManager::GetCdm(int cdm_id) { |
321 CdmMap::const_iterator iter = cdm_map_.find(cdm_id); | 321 CdmMap::const_iterator iter = cdm_map_.find(cdm_id); |
322 return (iter == cdm_map_.end()) ? NULL : iter->second; | 322 return (iter == cdm_map_.end()) ? NULL : iter->second; |
323 } | 323 } |
324 | 324 |
325 void BrowserMediaPlayerManager::DestroyAllMediaPlayers() { | 325 void BrowserMediaPlayerManager::DestroyAllMediaPlayers() { |
326 players_.clear(); | 326 players_.clear(); |
327 STLDeleteValues(&cdm_map_); | 327 STLDeleteValues(&cdm_map_); |
328 if (fullscreen_player_id_ != -1) { | 328 if (fullscreen_player_id_ != -1) { |
329 video_view_.reset(); | 329 video_view_.reset(); |
330 fullscreen_player_id_ = -1; | 330 fullscreen_player_id_ = -1; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 NOTREACHED(); | 605 NOTREACHED(); |
606 return; | 606 return; |
607 } | 607 } |
608 | 608 |
609 if (CommandLine::ForCurrentProcess() | 609 if (CommandLine::ForCurrentProcess() |
610 ->HasSwitch(switches::kDisableInfobarForProtectedMediaIdentifier)) { | 610 ->HasSwitch(switches::kDisableInfobarForProtectedMediaIdentifier)) { |
611 CreateSessionIfPermitted(cdm_id, session_id, mime_type, init_data, true); | 611 CreateSessionIfPermitted(cdm_id, session_id, mime_type, init_data, true); |
612 return; | 612 return; |
613 } | 613 } |
614 | 614 |
615 MediaKeys* cdm = GetCdm(cdm_id); | 615 MediaDrmBridge* cdm = GetCdm(cdm_id); |
616 if (!cdm) { | 616 if (!cdm) { |
617 DLOG(WARNING) << "No CDM for ID " << cdm_id << " found"; | 617 DLOG(WARNING) << "No CDM for ID " << cdm_id << " found"; |
618 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 618 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
619 return; | 619 return; |
620 } | 620 } |
621 | 621 |
622 BrowserContext* context = | 622 BrowserContext* context = |
623 web_contents()->GetRenderProcessHost()->GetBrowserContext(); | 623 web_contents()->GetRenderProcessHost()->GetBrowserContext(); |
624 | 624 |
625 std::map<int, GURL>::const_iterator iter = | 625 std::map<int, GURL>::const_iterator iter = |
(...skipping 15 matching lines...) Expand all Loading... |
641 cdm_id, | 641 cdm_id, |
642 session_id, | 642 session_id, |
643 mime_type, | 643 mime_type, |
644 init_data)); | 644 init_data)); |
645 } | 645 } |
646 | 646 |
647 void BrowserMediaPlayerManager::OnUpdateSession( | 647 void BrowserMediaPlayerManager::OnUpdateSession( |
648 int cdm_id, | 648 int cdm_id, |
649 uint32 session_id, | 649 uint32 session_id, |
650 const std::vector<uint8>& response) { | 650 const std::vector<uint8>& response) { |
651 MediaKeys* cdm = GetCdm(cdm_id); | 651 MediaDrmBridge* cdm = GetCdm(cdm_id); |
652 if (!cdm) { | 652 if (!cdm) { |
653 DLOG(WARNING) << "No CDM for ID " << cdm_id << " found"; | 653 DLOG(WARNING) << "No CDM for ID " << cdm_id << " found"; |
654 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 654 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
655 return; | 655 return; |
656 } | 656 } |
657 | 657 |
658 if (response.size() > kMaxSessionResponseLength) { | 658 if (response.size() > kMaxSessionResponseLength) { |
659 LOG(WARNING) << "Response for ID " << cdm_id | 659 LOG(WARNING) << "Response for ID " << cdm_id |
660 << " is too long: " << response.size(); | 660 << " is too long: " << response.size(); |
661 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 661 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
662 return; | 662 return; |
663 } | 663 } |
664 | 664 |
665 cdm->UpdateSession(session_id, &response[0], response.size()); | 665 cdm->UpdateSession(session_id, &response[0], response.size()); |
666 | 666 |
667 CdmToPlayerMap::const_iterator iter = cdm_to_player_map_.find(cdm_id); | 667 CdmToPlayerMap::const_iterator iter = cdm_to_player_map_.find(cdm_id); |
668 if (iter == cdm_to_player_map_.end()) | 668 if (iter == cdm_to_player_map_.end()) |
669 return; | 669 return; |
670 | 670 |
671 int player_id = iter->second; | 671 int player_id = iter->second; |
672 MediaPlayerAndroid* player = GetPlayer(player_id); | 672 MediaPlayerAndroid* player = GetPlayer(player_id); |
673 if (player) | 673 if (player) |
674 player->OnKeyAdded(); | 674 player->OnKeyAdded(); |
675 } | 675 } |
676 | 676 |
677 void BrowserMediaPlayerManager::OnReleaseSession(int cdm_id, | 677 void BrowserMediaPlayerManager::OnReleaseSession(int cdm_id, |
678 uint32 session_id) { | 678 uint32 session_id) { |
679 MediaKeys* cdm = GetCdm(cdm_id); | 679 MediaDrmBridge* cdm = GetCdm(cdm_id); |
680 if (!cdm) { | 680 if (!cdm) { |
681 DLOG(WARNING) << "No CDM for ID " << cdm_id << " found"; | 681 DLOG(WARNING) << "No CDM for ID " << cdm_id << " found"; |
682 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 682 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
683 return; | 683 return; |
684 } | 684 } |
685 | 685 |
686 cdm->ReleaseSession(session_id); | 686 cdm->ReleaseSession(session_id); |
687 } | 687 } |
688 | 688 |
689 void BrowserMediaPlayerManager::OnDestroyCdm(int cdm_id) { | 689 void BrowserMediaPlayerManager::OnDestroyCdm(int cdm_id) { |
690 MediaKeys* cdm = GetCdm(cdm_id); | 690 MediaDrmBridge* cdm = GetCdm(cdm_id); |
691 if (!cdm) | 691 if (!cdm) |
692 return; | 692 return; |
693 | 693 |
694 CancelAllPendingSessionCreations(cdm_id); | 694 CancelAllPendingSessionCreations(cdm_id); |
695 RemoveCdm(cdm_id); | 695 RemoveCdm(cdm_id); |
696 } | 696 } |
697 | 697 |
698 void BrowserMediaPlayerManager::CancelAllPendingSessionCreations(int cdm_id) { | 698 void BrowserMediaPlayerManager::CancelAllPendingSessionCreations(int cdm_id) { |
699 BrowserContext* context = | 699 BrowserContext* context = |
700 web_contents()->GetRenderProcessHost()->GetBrowserContext(); | 700 web_contents()->GetRenderProcessHost()->GetBrowserContext(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 return scoped_ptr<media::MediaPlayerAndroid>(previous_player); | 741 return scoped_ptr<media::MediaPlayerAndroid>(previous_player); |
742 } | 742 } |
743 | 743 |
744 void BrowserMediaPlayerManager::AddCdm(int cdm_id, | 744 void BrowserMediaPlayerManager::AddCdm(int cdm_id, |
745 const std::string& key_system, | 745 const std::string& key_system, |
746 const GURL& security_origin) { | 746 const GURL& security_origin) { |
747 DCHECK(!GetCdm(cdm_id)); | 747 DCHECK(!GetCdm(cdm_id)); |
748 base::WeakPtr<BrowserMediaPlayerManager> weak_this = | 748 base::WeakPtr<BrowserMediaPlayerManager> weak_this = |
749 weak_ptr_factory_.GetWeakPtr(); | 749 weak_ptr_factory_.GetWeakPtr(); |
750 | 750 |
751 scoped_ptr<MediaKeys> cdm(media::CreateBrowserCdm( | 751 scoped_ptr<MediaDrmBridge> cdm(media::CreateBrowserCdm( |
752 key_system, | 752 key_system, |
753 base::Bind( | 753 base::Bind( |
754 &BrowserMediaPlayerManager::OnSessionCreated, weak_this, cdm_id), | 754 &BrowserMediaPlayerManager::OnSessionCreated, weak_this, cdm_id), |
755 base::Bind( | 755 base::Bind( |
756 &BrowserMediaPlayerManager::OnSessionMessage, weak_this, cdm_id), | 756 &BrowserMediaPlayerManager::OnSessionMessage, weak_this, cdm_id), |
757 base::Bind( | 757 base::Bind( |
758 &BrowserMediaPlayerManager::OnSessionReady, weak_this, cdm_id), | 758 &BrowserMediaPlayerManager::OnSessionReady, weak_this, cdm_id), |
759 base::Bind( | 759 base::Bind( |
760 &BrowserMediaPlayerManager::OnSessionClosed, weak_this, cdm_id), | 760 &BrowserMediaPlayerManager::OnSessionClosed, weak_this, cdm_id), |
761 base::Bind( | 761 base::Bind( |
(...skipping 19 matching lines...) Expand all Loading... |
781 if (iter != cdm_map_.end()) { | 781 if (iter != cdm_map_.end()) { |
782 delete iter->second; | 782 delete iter->second; |
783 cdm_map_.erase(iter); | 783 cdm_map_.erase(iter); |
784 } | 784 } |
785 cdm_to_player_map_.erase(cdm_id); | 785 cdm_to_player_map_.erase(cdm_id); |
786 cdm_security_origin_map_.erase(cdm_id); | 786 cdm_security_origin_map_.erase(cdm_id); |
787 } | 787 } |
788 | 788 |
789 void BrowserMediaPlayerManager::OnSetCdm(int player_id, int cdm_id) { | 789 void BrowserMediaPlayerManager::OnSetCdm(int player_id, int cdm_id) { |
790 MediaPlayerAndroid* player = GetPlayer(player_id); | 790 MediaPlayerAndroid* player = GetPlayer(player_id); |
791 MediaKeys* cdm = GetCdm(cdm_id); | 791 MediaDrmBridge* cdm = GetCdm(cdm_id); |
792 if (!cdm || !player) { | 792 if (!cdm || !player) { |
793 DVLOG(1) << "Cannot set CDM on the specified player."; | 793 DVLOG(1) << "Cannot set CDM on the specified player."; |
794 return; | 794 return; |
795 } | 795 } |
796 | 796 |
797 // TODO(qinmin): add the logic to decide whether we should create the | 797 // TODO(qinmin): add the logic to decide whether we should create the |
798 // fullscreen surface for EME lv1. | 798 // fullscreen surface for EME lv1. |
799 player->SetCdm(cdm); | 799 player->SetCdm(cdm); |
800 // Do now support setting one CDM on multiple players. | 800 // Do now support setting one CDM on multiple players. |
801 | 801 |
(...skipping 17 matching lines...) Expand all Loading... |
819 int cdm_id, | 819 int cdm_id, |
820 uint32 session_id, | 820 uint32 session_id, |
821 const std::string& content_type, | 821 const std::string& content_type, |
822 const std::vector<uint8>& init_data, | 822 const std::vector<uint8>& init_data, |
823 bool permitted) { | 823 bool permitted) { |
824 if (!permitted) { | 824 if (!permitted) { |
825 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 825 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
826 return; | 826 return; |
827 } | 827 } |
828 | 828 |
829 MediaKeys* cdm = GetCdm(cdm_id); | 829 MediaDrmBridge* cdm = GetCdm(cdm_id); |
830 if (!cdm) { | 830 if (!cdm) { |
831 DLOG(WARNING) << "No CDM for ID: " << cdm_id << " found"; | 831 DLOG(WARNING) << "No CDM for ID: " << cdm_id << " found"; |
832 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 832 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
833 return; | 833 return; |
834 } | 834 } |
835 | 835 |
836 // This could fail, in which case a SessionError will be fired. | 836 // This could fail, in which case a SessionError will be fired. |
837 cdm->CreateSession(session_id, content_type, &init_data[0], init_data.size()); | 837 cdm->CreateSession(session_id, content_type, &init_data[0], init_data.size()); |
838 } | 838 } |
839 | 839 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 #if defined(VIDEO_HOLE) | 874 #if defined(VIDEO_HOLE) |
875 MediaPlayerAndroid* player = GetPlayer(player_id); | 875 MediaPlayerAndroid* player = GetPlayer(player_id); |
876 if (player && player->IsSurfaceInUse()) | 876 if (player && player->IsSurfaceInUse()) |
877 return; | 877 return; |
878 if (external_video_surface_container_) | 878 if (external_video_surface_container_) |
879 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); | 879 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); |
880 #endif // defined(VIDEO_HOLE) | 880 #endif // defined(VIDEO_HOLE) |
881 } | 881 } |
882 | 882 |
883 } // namespace content | 883 } // namespace content |
OLD | NEW |