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 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 } | 670 } |
671 | 671 |
672 if (response.size() > kMaxSessionResponseLength) { | 672 if (response.size() > kMaxSessionResponseLength) { |
673 LOG(WARNING) << "Response for ID: " << cdm_id | 673 LOG(WARNING) << "Response for ID: " << cdm_id |
674 << " too long: " << response.size(); | 674 << " too long: " << response.size(); |
675 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 675 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
676 return; | 676 return; |
677 } | 677 } |
678 | 678 |
679 drm_bridge->UpdateSession(session_id, &response[0], response.size()); | 679 drm_bridge->UpdateSession(session_id, &response[0], response.size()); |
680 // In EME v0.1b MediaKeys lives in the media element. So the |cdm_id| | 680 |
681 // is the same as the |player_id|. | 681 DrmBridgePlayerMap::const_iterator iter = drm_bridge_player_map_.find(cdm_id); |
682 // TODO(xhwang): Separate |cdm_id| and |player_id|. | 682 if (iter == drm_bridge_player_map_.end()) |
683 MediaPlayerAndroid* player = GetPlayer(cdm_id); | 683 return; |
| 684 |
| 685 int player_id = iter->second; |
| 686 MediaPlayerAndroid* player = GetPlayer(player_id); |
684 if (player) | 687 if (player) |
685 player->OnKeyAdded(); | 688 player->OnKeyAdded(); |
686 } | 689 } |
687 | 690 |
688 void BrowserMediaPlayerManager::OnReleaseSession(int cdm_id, | 691 void BrowserMediaPlayerManager::OnReleaseSession(int cdm_id, |
689 uint32 session_id) { | 692 uint32 session_id) { |
690 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); | 693 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); |
691 if (!drm_bridge) { | 694 if (!drm_bridge) { |
692 DLOG(WARNING) << "No MediaDrmBridge for ID: " << cdm_id << " found"; | 695 DLOG(WARNING) << "No MediaDrmBridge for ID: " << cdm_id << " found"; |
693 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 696 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
(...skipping 24 matching lines...) Expand all Loading... |
718 | 721 |
719 void BrowserMediaPlayerManager::RemovePlayer(int player_id) { | 722 void BrowserMediaPlayerManager::RemovePlayer(int player_id) { |
720 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); | 723 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); |
721 it != players_.end(); ++it) { | 724 it != players_.end(); ++it) { |
722 MediaPlayerAndroid* player = *it; | 725 MediaPlayerAndroid* player = *it; |
723 if (player->player_id() == player_id) { | 726 if (player->player_id() == player_id) { |
724 players_.erase(it); | 727 players_.erase(it); |
725 break; | 728 break; |
726 } | 729 } |
727 } | 730 } |
| 731 |
| 732 for (DrmBridgePlayerMap::iterator it = drm_bridge_player_map_.begin(); |
| 733 it != drm_bridge_player_map_.end(); ++it) { |
| 734 if (it->second == player_id) { |
| 735 drm_bridge_player_map_.erase(it); |
| 736 break; |
| 737 } |
| 738 } |
728 } | 739 } |
729 | 740 |
730 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer( | 741 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer( |
731 int player_id, media::MediaPlayerAndroid* player) { | 742 int player_id, media::MediaPlayerAndroid* player) { |
732 media::MediaPlayerAndroid* previous_player = NULL; | 743 media::MediaPlayerAndroid* previous_player = NULL; |
733 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); | 744 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); |
734 it != players_.end(); ++it) { | 745 it != players_.end(); ++it) { |
735 if ((*it)->player_id() == player_id) { | 746 if ((*it)->player_id() == player_id) { |
736 previous_player = *it; | 747 previous_player = *it; |
737 players_.weak_erase(it); | 748 players_.weak_erase(it); |
(...skipping 27 matching lines...) Expand all Loading... |
765 } | 776 } |
766 if (!drm_bridge->SetSecurityLevel(security_level)) { | 777 if (!drm_bridge->SetSecurityLevel(security_level)) { |
767 DVLOG(1) << "failed to set security level " << security_level; | 778 DVLOG(1) << "failed to set security level " << security_level; |
768 return; | 779 return; |
769 } | 780 } |
770 | 781 |
771 drm_bridges_.push_back(drm_bridge.release()); | 782 drm_bridges_.push_back(drm_bridge.release()); |
772 } | 783 } |
773 | 784 |
774 void BrowserMediaPlayerManager::RemoveDrmBridge(int cdm_id) { | 785 void BrowserMediaPlayerManager::RemoveDrmBridge(int cdm_id) { |
| 786 // TODO(xhwang): Detach DrmBridge from the player it's set to. In prefixed |
| 787 // EME implementation the current code is fine because we always destroy the |
| 788 // player before we destroy the DrmBridge. This will not always be the case |
| 789 // in unprefixed EME implementation. |
775 for (ScopedVector<MediaDrmBridge>::iterator it = drm_bridges_.begin(); | 790 for (ScopedVector<MediaDrmBridge>::iterator it = drm_bridges_.begin(); |
776 it != drm_bridges_.end(); ++it) { | 791 it != drm_bridges_.end(); ++it) { |
777 if ((*it)->cdm_id() == cdm_id) { | 792 if ((*it)->cdm_id() == cdm_id) { |
778 drm_bridges_.erase(it); | 793 drm_bridges_.erase(it); |
| 794 drm_bridge_player_map_.erase(cdm_id); |
779 break; | 795 break; |
780 } | 796 } |
781 } | 797 } |
782 } | 798 } |
783 | 799 |
784 void BrowserMediaPlayerManager::OnSetCdm(int player_id, int cdm_id) { | 800 void BrowserMediaPlayerManager::OnSetCdm(int player_id, int cdm_id) { |
785 MediaPlayerAndroid* player = GetPlayer(player_id); | 801 MediaPlayerAndroid* player = GetPlayer(player_id); |
786 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); | 802 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); |
787 if (!drm_bridge || !player) { | 803 if (!drm_bridge || !player) { |
788 DVLOG(1) << "Cannot set CDM on the specified player."; | 804 DVLOG(1) << "Cannot set CDM on the specified player."; |
789 return; | 805 return; |
790 } | 806 } |
791 | 807 |
792 // TODO(qinmin): add the logic to decide whether we should create the | 808 // TODO(qinmin): add the logic to decide whether we should create the |
793 // fullscreen surface for EME lv1. | 809 // fullscreen surface for EME lv1. |
794 player->SetDrmBridge(drm_bridge); | 810 player->SetDrmBridge(drm_bridge); |
| 811 // Do now support setting one CDM on multiple players. |
| 812 DCHECK(drm_bridge_player_map_.find(cdm_id) == drm_bridge_player_map_.end()); |
| 813 drm_bridge_player_map_[cdm_id] = player_id; |
795 } | 814 } |
796 | 815 |
797 void BrowserMediaPlayerManager::CreateSessionIfPermitted( | 816 void BrowserMediaPlayerManager::CreateSessionIfPermitted( |
798 int cdm_id, | 817 int cdm_id, |
799 uint32 session_id, | 818 uint32 session_id, |
800 const std::string& content_type, | 819 const std::string& content_type, |
801 const std::vector<uint8>& init_data, | 820 const std::vector<uint8>& init_data, |
802 bool permitted) { | 821 bool permitted) { |
803 if (!permitted) { | 822 if (!permitted) { |
804 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 823 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 #if defined(VIDEO_HOLE) | 873 #if defined(VIDEO_HOLE) |
855 MediaPlayerAndroid* player = GetPlayer(player_id); | 874 MediaPlayerAndroid* player = GetPlayer(player_id); |
856 if (player && player->IsSurfaceInUse()) | 875 if (player && player->IsSurfaceInUse()) |
857 return; | 876 return; |
858 if (external_video_surface_container_) | 877 if (external_video_surface_container_) |
859 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); | 878 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); |
860 #endif // defined(VIDEO_HOLE) | 879 #endif // defined(VIDEO_HOLE) |
861 } | 880 } |
862 | 881 |
863 } // namespace content | 882 } // namespace content |
OLD | NEW |