Chromium Code Reviews| 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" |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 << " too long: " << response.size(); | 660 << " 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 drm_bridge->UpdateSession(session_id, &response[0], response.size()); | 665 drm_bridge->UpdateSession(session_id, &response[0], response.size()); |
| 666 // In EME v0.1b MediaKeys lives in the media element. So the |cdm_id| | 666 |
| 667 // is the same as the |player_id|. | 667 DrmBridgePlayerMap::const_iterator iter = drm_bridge_player_map_.find(cdm_id); |
| 668 // TODO(xhwang): Separate |cdm_id| and |player_id|. | 668 if (iter == drm_bridge_player_map_.end()) |
| 669 MediaPlayerAndroid* player = GetPlayer(cdm_id); | 669 return; |
| 670 | |
| 671 int player_id = iter->second; | |
| 672 MediaPlayerAndroid* player = GetPlayer(player_id); | |
| 670 if (player) | 673 if (player) |
| 671 player->OnKeyAdded(); | 674 player->OnKeyAdded(); |
| 672 } | 675 } |
| 673 | 676 |
| 674 void BrowserMediaPlayerManager::OnReleaseSession(int cdm_id, | 677 void BrowserMediaPlayerManager::OnReleaseSession(int cdm_id, |
| 675 uint32 session_id) { | 678 uint32 session_id) { |
| 676 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); | 679 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); |
| 677 if (!drm_bridge) { | 680 if (!drm_bridge) { |
| 678 DLOG(WARNING) << "No MediaDrmBridge for ID: " << cdm_id << " found"; | 681 DLOG(WARNING) << "No MediaDrmBridge for ID: " << cdm_id << " found"; |
| 679 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 682 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 704 | 707 |
| 705 void BrowserMediaPlayerManager::RemovePlayer(int player_id) { | 708 void BrowserMediaPlayerManager::RemovePlayer(int player_id) { |
| 706 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); | 709 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); |
| 707 it != players_.end(); ++it) { | 710 it != players_.end(); ++it) { |
| 708 MediaPlayerAndroid* player = *it; | 711 MediaPlayerAndroid* player = *it; |
| 709 if (player->player_id() == player_id) { | 712 if (player->player_id() == player_id) { |
| 710 players_.erase(it); | 713 players_.erase(it); |
| 711 break; | 714 break; |
| 712 } | 715 } |
| 713 } | 716 } |
| 717 | |
| 718 for (DrmBridgePlayerMap::iterator it = drm_bridge_player_map_.begin(); | |
| 719 it != drm_bridge_player_map_.end(); ++it) { | |
| 720 if (it->second == player_id) { | |
| 721 drm_bridge_player_map_.erase(it); | |
| 722 break; | |
| 723 } | |
| 724 } | |
| 714 } | 725 } |
| 715 | 726 |
| 716 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer( | 727 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer( |
| 717 int player_id, media::MediaPlayerAndroid* player) { | 728 int player_id, media::MediaPlayerAndroid* player) { |
| 718 media::MediaPlayerAndroid* previous_player = NULL; | 729 media::MediaPlayerAndroid* previous_player = NULL; |
| 719 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); | 730 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); |
| 720 it != players_.end(); ++it) { | 731 it != players_.end(); ++it) { |
| 721 if ((*it)->player_id() == player_id) { | 732 if ((*it)->player_id() == player_id) { |
| 722 previous_player = *it; | 733 previous_player = *it; |
| 723 players_.weak_erase(it); | 734 players_.weak_erase(it); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 751 } | 762 } |
| 752 if (!drm_bridge->SetSecurityLevel(security_level)) { | 763 if (!drm_bridge->SetSecurityLevel(security_level)) { |
| 753 DVLOG(1) << "failed to set security level " << security_level; | 764 DVLOG(1) << "failed to set security level " << security_level; |
| 754 return; | 765 return; |
| 755 } | 766 } |
| 756 | 767 |
| 757 drm_bridges_.push_back(drm_bridge.release()); | 768 drm_bridges_.push_back(drm_bridge.release()); |
| 758 } | 769 } |
| 759 | 770 |
| 760 void BrowserMediaPlayerManager::RemoveDrmBridge(int cdm_id) { | 771 void BrowserMediaPlayerManager::RemoveDrmBridge(int cdm_id) { |
| 772 // TODO(xhwang): Detach DrmBridge from the player it's set to. In prefixed | |
| 773 // EME implementation the current code is fine because we always destroy the | |
| 774 // player before we destroy the DrmBridge. This will not always be the case | |
| 775 // in unprefixed EME implementation. | |
| 761 for (ScopedVector<MediaDrmBridge>::iterator it = drm_bridges_.begin(); | 776 for (ScopedVector<MediaDrmBridge>::iterator it = drm_bridges_.begin(); |
| 762 it != drm_bridges_.end(); ++it) { | 777 it != drm_bridges_.end(); ++it) { |
| 763 if ((*it)->cdm_id() == cdm_id) { | 778 if ((*it)->cdm_id() == cdm_id) { |
| 764 drm_bridges_.erase(it); | 779 drm_bridges_.erase(it); |
| 780 drm_bridge_player_map_.erase(cdm_id); | |
| 765 break; | 781 break; |
| 766 } | 782 } |
| 767 } | 783 } |
| 768 } | 784 } |
| 769 | 785 |
| 770 void BrowserMediaPlayerManager::OnSetCdm(int player_id, int cdm_id) { | 786 void BrowserMediaPlayerManager::OnSetCdm(int player_id, int cdm_id) { |
| 771 MediaPlayerAndroid* player = GetPlayer(player_id); | 787 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 772 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); | 788 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); |
| 773 if (!drm_bridge || !player) { | 789 if (!drm_bridge || !player) { |
| 774 DVLOG(1) << "Cannot set CDM on the specified player."; | 790 DVLOG(1) << "Cannot set CDM on the specified player."; |
| 775 return; | 791 return; |
| 776 } | 792 } |
| 777 | 793 |
| 778 // TODO(qinmin): add the logic to decide whether we should create the | 794 // TODO(qinmin): add the logic to decide whether we should create the |
| 779 // fullscreen surface for EME lv1. | 795 // fullscreen surface for EME lv1. |
| 780 player->SetDrmBridge(drm_bridge); | 796 player->SetDrmBridge(drm_bridge); |
| 797 drm_bridge_player_map_[cdm_id] = player_id; | |
|
qinmin
2014/05/02 18:48:58
do we need a dcheck that drm_bridge_player_map_.fi
| |
| 781 } | 798 } |
| 782 | 799 |
| 783 void BrowserMediaPlayerManager::CreateSessionIfPermitted( | 800 void BrowserMediaPlayerManager::CreateSessionIfPermitted( |
| 784 int cdm_id, | 801 int cdm_id, |
| 785 uint32 session_id, | 802 uint32 session_id, |
| 786 const std::string& content_type, | 803 const std::string& content_type, |
| 787 const std::vector<uint8>& init_data, | 804 const std::vector<uint8>& init_data, |
| 788 bool permitted) { | 805 bool permitted) { |
| 789 if (!permitted) { | 806 if (!permitted) { |
| 790 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); | 807 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 #if defined(VIDEO_HOLE) | 857 #if defined(VIDEO_HOLE) |
| 841 MediaPlayerAndroid* player = GetPlayer(player_id); | 858 MediaPlayerAndroid* player = GetPlayer(player_id); |
| 842 if (player && player->IsSurfaceInUse()) | 859 if (player && player->IsSurfaceInUse()) |
| 843 return; | 860 return; |
| 844 if (external_video_surface_container_) | 861 if (external_video_surface_container_) |
| 845 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); | 862 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); |
| 846 #endif // defined(VIDEO_HOLE) | 863 #endif // defined(VIDEO_HOLE) |
| 847 } | 864 } |
| 848 | 865 |
| 849 } // namespace content | 866 } // namespace content |
| OLD | NEW |