Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: content/browser/media/android/browser_media_player_manager.cc

Issue 276973005: BrowserMediaPlayerManager manages MediaKeys objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MEDIA_EXPORT Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "content/browser/android/content_view_core_impl.h" 10 #include "content/browser/android/content_view_core_impl.h"
10 #include "content/browser/media/android/browser_demuxer_android.h" 11 #include "content/browser/media/android/browser_demuxer_android.h"
11 #include "content/browser/media/android/media_resource_getter_impl.h" 12 #include "content/browser/media/android/media_resource_getter_impl.h"
12 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/browser/web_contents/web_contents_view_android.h" 14 #include "content/browser/web_contents/web_contents_view_android.h"
14 #include "content/common/media/cdm_messages.h" 15 #include "content/common/media/cdm_messages.h"
15 #include "content/common/media/media_player_messages_android.h" 16 #include "content/common/media/media_player_messages_android.h"
16 #include "content/public/browser/android/content_view_core.h" 17 #include "content/public/browser/android/content_view_core.h"
17 #include "content/public/browser/android/external_video_surface_container.h" 18 #include "content/public/browser/android/external_video_surface_container.h"
18 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/content_browser_client.h" 20 #include "content/public/browser/content_browser_client.h"
20 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/storage_partition.h" 23 #include "content/public/browser/storage_partition.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_contents_delegate.h" 25 #include "content/public/browser/web_contents_delegate.h"
25 #include "content/public/common/content_client.h" 26 #include "content/public/common/content_client.h"
26 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
27 #include "media/base/android/media_drm_bridge.h" 28 #include "media/base/android/cdm_factory.h"
28 #include "media/base/android/media_player_bridge.h" 29 #include "media/base/android/media_player_bridge.h"
29 #include "media/base/android/media_source_player.h" 30 #include "media/base/android/media_source_player.h"
30 #include "media/base/media_switches.h" 31 #include "media/base/media_switches.h"
31 32
32 using media::MediaDrmBridge; 33 using media::MediaKeys;
33 using media::MediaPlayerAndroid; 34 using media::MediaPlayerAndroid;
34 using media::MediaPlayerBridge; 35 using media::MediaPlayerBridge;
35 using media::MediaPlayerManager; 36 using media::MediaPlayerManager;
36 using media::MediaSourcePlayer; 37 using media::MediaSourcePlayer;
37 38
38 namespace content { 39 namespace content {
39 40
40 // Threshold on the number of media players per renderer before we start 41 // Threshold on the number of media players per renderer before we start
41 // attempting to release inactive media players. 42 // attempting to release inactive media players.
42 const int kMediaPlayerThreshold = 1; 43 const int kMediaPlayerThreshold = 1;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 336
336 MediaPlayerAndroid* BrowserMediaPlayerManager::GetPlayer(int player_id) { 337 MediaPlayerAndroid* BrowserMediaPlayerManager::GetPlayer(int player_id) {
337 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); 338 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin();
338 it != players_.end(); ++it) { 339 it != players_.end(); ++it) {
339 if ((*it)->player_id() == player_id) 340 if ((*it)->player_id() == player_id)
340 return *it; 341 return *it;
341 } 342 }
342 return NULL; 343 return NULL;
343 } 344 }
344 345
345 MediaDrmBridge* BrowserMediaPlayerManager::GetDrmBridge(int cdm_id) { 346 MediaKeys* BrowserMediaPlayerManager::GetCdm(int cdm_id) {
346 for (ScopedVector<MediaDrmBridge>::iterator it = drm_bridges_.begin(); 347 CdmMap::const_iterator iter = cdm_map_.find(cdm_id);
347 it != drm_bridges_.end(); ++it) { 348 return (iter == cdm_map_.end()) ? NULL : iter->second;
348 if ((*it)->cdm_id() == cdm_id)
349 return *it;
350 }
351 return NULL;
352 } 349 }
353 350
354 void BrowserMediaPlayerManager::DestroyAllMediaPlayers() { 351 void BrowserMediaPlayerManager::DestroyAllMediaPlayers() {
355 players_.clear(); 352 players_.clear();
356 drm_bridges_.clear(); 353 STLDeleteValues(&cdm_map_);
357 if (fullscreen_player_id_ != -1) { 354 if (fullscreen_player_id_ != -1) {
358 video_view_.reset(); 355 video_view_.reset();
359 fullscreen_player_id_ = -1; 356 fullscreen_player_id_ = -1;
360 } 357 }
361 } 358 }
362 359
363 void BrowserMediaPlayerManager::RequestFullScreen(int player_id) { 360 void BrowserMediaPlayerManager::RequestFullScreen(int player_id) {
364 if (fullscreen_player_id_ == player_id) 361 if (fullscreen_player_id_ == player_id)
365 return; 362 return;
366 363
(...skipping 20 matching lines...) Expand all
387 uint32 session_id, 384 uint32 session_id,
388 const std::string& web_session_id) { 385 const std::string& web_session_id) {
389 Send(new CdmMsg_SessionCreated( 386 Send(new CdmMsg_SessionCreated(
390 routing_id(), cdm_id, session_id, web_session_id)); 387 routing_id(), cdm_id, session_id, web_session_id));
391 } 388 }
392 389
393 void BrowserMediaPlayerManager::OnSessionMessage( 390 void BrowserMediaPlayerManager::OnSessionMessage(
394 int cdm_id, 391 int cdm_id,
395 uint32 session_id, 392 uint32 session_id,
396 const std::vector<uint8>& message, 393 const std::vector<uint8>& message,
397 const GURL& destination_url) { 394 const std::string& destination_url) {
395 GURL destination_gurl(destination_url);
396 if (!destination_gurl.is_valid() && !destination_gurl.is_empty()) {
397 DLOG(WARNING) << "SessionMessage destination_url is invalid : "
398 << destination_gurl.possibly_invalid_spec();
399 destination_gurl = GURL::EmptyGURL(); // Replace invalid destination_url.
400 }
401
398 Send(new CdmMsg_SessionMessage( 402 Send(new CdmMsg_SessionMessage(
399 routing_id(), cdm_id, session_id, message, destination_url)); 403 routing_id(), cdm_id, session_id, message, destination_gurl));
damienv1 2014/05/12 23:14:26 destination_gurl will be updated to a string once
ddorwin 2014/05/13 00:59:38 Why would we move away from GURL? Especially for I
xhwang 2014/05/14 16:42:06 See above. Added TODO to use GURL as much as we ca
xhwang 2014/05/14 16:42:06 ditto
400 } 404 }
401 405
402 void BrowserMediaPlayerManager::OnSessionReady(int cdm_id, uint32 session_id) { 406 void BrowserMediaPlayerManager::OnSessionReady(int cdm_id, uint32 session_id) {
403 Send(new CdmMsg_SessionReady(routing_id(), cdm_id, session_id)); 407 Send(new CdmMsg_SessionReady(routing_id(), cdm_id, session_id));
404 } 408 }
405 409
406 void BrowserMediaPlayerManager::OnSessionClosed(int cdm_id, uint32 session_id) { 410 void BrowserMediaPlayerManager::OnSessionClosed(int cdm_id, uint32 session_id) {
407 Send(new CdmMsg_SessionClosed(routing_id(), cdm_id, session_id)); 411 Send(new CdmMsg_SessionClosed(routing_id(), cdm_id, session_id));
408 } 412 }
409 413
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 RemovePlayer(player_id); 588 RemovePlayer(player_id);
585 if (fullscreen_player_id_ == player_id) 589 if (fullscreen_player_id_ == player_id)
586 fullscreen_player_id_ = -1; 590 fullscreen_player_id_ = -1;
587 } 591 }
588 592
589 void BrowserMediaPlayerManager::OnInitializeCdm(int cdm_id, 593 void BrowserMediaPlayerManager::OnInitializeCdm(int cdm_id,
590 const std::string& key_system, 594 const std::string& key_system,
591 const GURL& security_origin) { 595 const GURL& security_origin) {
592 if (key_system.size() > kMaxKeySystemLength) { 596 if (key_system.size() > kMaxKeySystemLength) {
593 // This failure will be discovered and reported by OnCreateSession() 597 // This failure will be discovered and reported by OnCreateSession()
594 // as GetDrmBridge() will return null. 598 // as GetCdm() will return null.
595 NOTREACHED() << "Invalid key system: " << key_system; 599 NOTREACHED() << "Invalid key system: " << key_system;
596 return; 600 return;
597 } 601 }
598 602
599 if (!MediaDrmBridge::IsKeySystemSupported(key_system)) { 603 AddCdm(cdm_id, key_system, security_origin);
600 NOTREACHED() << "Unsupported key system: " << key_system;
601 return;
602 }
603
604 AddDrmBridge(cdm_id, key_system, security_origin);
605 } 604 }
606 605
607 void BrowserMediaPlayerManager::OnCreateSession( 606 void BrowserMediaPlayerManager::OnCreateSession(
608 int cdm_id, 607 int cdm_id,
609 uint32 session_id, 608 uint32 session_id,
610 CdmHostMsg_CreateSession_ContentType content_type, 609 CdmHostMsg_CreateSession_ContentType content_type,
611 const std::vector<uint8>& init_data) { 610 const std::vector<uint8>& init_data) {
612 if (init_data.size() > kMaxInitDataLength) { 611 if (init_data.size() > kMaxInitDataLength) {
613 LOG(WARNING) << "InitData for ID: " << cdm_id 612 LOG(WARNING) << "InitData for ID: " << cdm_id
614 << " too long: " << init_data.size(); 613 << " too long: " << init_data.size();
(...skipping 17 matching lines...) Expand all
632 NOTREACHED(); 631 NOTREACHED();
633 return; 632 return;
634 } 633 }
635 634
636 if (CommandLine::ForCurrentProcess() 635 if (CommandLine::ForCurrentProcess()
637 ->HasSwitch(switches::kDisableInfobarForProtectedMediaIdentifier)) { 636 ->HasSwitch(switches::kDisableInfobarForProtectedMediaIdentifier)) {
638 CreateSessionIfPermitted(cdm_id, session_id, mime_type, init_data, true); 637 CreateSessionIfPermitted(cdm_id, session_id, mime_type, init_data, true);
639 return; 638 return;
640 } 639 }
641 640
642 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); 641 MediaKeys* cdm = GetCdm(cdm_id);
643 if (!drm_bridge) { 642 if (!cdm) {
644 DLOG(WARNING) << "No MediaDrmBridge for ID: " << cdm_id << " found"; 643 DLOG(WARNING) << "No CDMs for ID: " << cdm_id << " found";
ddorwin 2014/05/13 00:59:38 nit: s/CDMs/CDM/ nit: remove colon or move "found"
xhwang 2014/05/14 16:42:06 Done.
645 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); 644 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0);
646 return; 645 return;
647 } 646 }
648 647
649 BrowserContext* context = 648 BrowserContext* context =
650 web_contents()->GetRenderProcessHost()->GetBrowserContext(); 649 web_contents()->GetRenderProcessHost()->GetBrowserContext();
651 650
651 DCHECK(ContainsKey(security_origin_map_, cdm_id));
ddorwin 2014/05/13 00:59:38 If this fails, we crash at 658. Since this is the
xhwang 2014/05/14 16:42:06 Done.
652
652 context->RequestProtectedMediaIdentifierPermission( 653 context->RequestProtectedMediaIdentifierPermission(
653 web_contents()->GetRenderProcessHost()->GetID(), 654 web_contents()->GetRenderProcessHost()->GetID(),
654 web_contents()->GetRenderViewHost()->GetRoutingID(), 655 web_contents()->GetRenderViewHost()->GetRoutingID(),
655 static_cast<int>(session_id), 656 static_cast<int>(session_id),
656 cdm_id, 657 cdm_id,
657 drm_bridge->security_origin(), 658 security_origin_map_[cdm_id],
658 base::Bind(&BrowserMediaPlayerManager::CreateSessionIfPermitted, 659 base::Bind(&BrowserMediaPlayerManager::CreateSessionIfPermitted,
659 weak_ptr_factory_.GetWeakPtr(), 660 weak_ptr_factory_.GetWeakPtr(),
660 cdm_id, 661 cdm_id,
661 session_id, 662 session_id,
662 mime_type, 663 mime_type,
663 init_data)); 664 init_data));
damienv1 2014/05/12 21:37:53 All this part seems to be an internal detail of th
xhwang 2014/05/12 21:58:44 Well, I agree that the security origin should and
ddorwin 2014/05/13 00:59:38 When and whether to check permissions is CDM-speci
xhwang 2014/05/14 16:42:06 I can think of it in both ways. What if on some pl
664 } 665 }
665 666
666 void BrowserMediaPlayerManager::OnUpdateSession( 667 void BrowserMediaPlayerManager::OnUpdateSession(
667 int cdm_id, 668 int cdm_id,
668 uint32 session_id, 669 uint32 session_id,
669 const std::vector<uint8>& response) { 670 const std::vector<uint8>& response) {
670 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); 671 MediaKeys* cdm = GetCdm(cdm_id);
671 if (!drm_bridge) { 672 if (!cdm) {
672 DLOG(WARNING) << "No MediaDrmBridge for ID: " << cdm_id << " found"; 673 DLOG(WARNING) << "No CDM for ID: " << cdm_id << " found";
ddorwin 2014/05/13 00:59:38 ditto
xhwang 2014/05/14 16:42:06 Done.
673 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); 674 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0);
674 return; 675 return;
675 } 676 }
676 677
677 if (response.size() > kMaxSessionResponseLength) { 678 if (response.size() > kMaxSessionResponseLength) {
678 LOG(WARNING) << "Response for ID: " << cdm_id 679 LOG(WARNING) << "Response for ID: " << cdm_id
679 << " too long: " << response.size(); 680 << " too long: " << response.size();
680 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); 681 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0);
681 return; 682 return;
682 } 683 }
683 684
684 drm_bridge->UpdateSession(session_id, &response[0], response.size()); 685 cdm->UpdateSession(session_id, &response[0], response.size());
685 686
686 DrmBridgePlayerMap::const_iterator iter = drm_bridge_player_map_.find(cdm_id); 687 CdmToPlayerMap::const_iterator iter = cdm_to_player_map_.find(cdm_id);
687 if (iter == drm_bridge_player_map_.end()) 688 if (iter == cdm_to_player_map_.end())
damienv1 2014/05/12 21:37:53 I don't think that's the right way: we shouldn't n
xhwang 2014/05/12 21:58:44 Agreed. Since this is from the old code and we'll
xhwang 2014/05/14 16:42:06 I filed a bug (http://crbug.com/373327) and added
688 return; 689 return;
689 690
690 int player_id = iter->second; 691 int player_id = iter->second;
691 MediaPlayerAndroid* player = GetPlayer(player_id); 692 MediaPlayerAndroid* player = GetPlayer(player_id);
692 if (player) 693 if (player)
693 player->OnKeyAdded(); 694 player->OnKeyAdded();
694 } 695 }
695 696
696 void BrowserMediaPlayerManager::OnReleaseSession(int cdm_id, 697 void BrowserMediaPlayerManager::OnReleaseSession(int cdm_id,
697 uint32 session_id) { 698 uint32 session_id) {
698 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); 699 MediaKeys* cdm = GetCdm(cdm_id);
699 if (!drm_bridge) { 700 if (!cdm) {
700 DLOG(WARNING) << "No MediaDrmBridge for ID: " << cdm_id << " found"; 701 DLOG(WARNING) << "No MediaKeys for ID: " << cdm_id << " found";
ddorwin 2014/05/13 00:59:38 ditto
xhwang 2014/05/14 16:42:06 Done.
701 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); 702 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0);
702 return; 703 return;
703 } 704 }
704 705
705 drm_bridge->ReleaseSession(session_id); 706 cdm->ReleaseSession(session_id);
706 } 707 }
707 708
708 void BrowserMediaPlayerManager::OnDestroyCdm(int cdm_id) { 709 void BrowserMediaPlayerManager::OnDestroyCdm(int cdm_id) {
709 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); 710 MediaKeys* cdm = GetCdm(cdm_id);
710 if (!drm_bridge) return; 711 if (!cdm) return;
711 712
712 CancelAllPendingSessionCreations(cdm_id); 713 CancelAllPendingSessionCreations(cdm_id);
713 RemoveDrmBridge(cdm_id); 714 RemoveCdm(cdm_id);
714 } 715 }
715 716
716 void BrowserMediaPlayerManager::CancelAllPendingSessionCreations(int cdm_id) { 717 void BrowserMediaPlayerManager::CancelAllPendingSessionCreations(int cdm_id) {
717 BrowserContext* context = 718 BrowserContext* context =
718 web_contents()->GetRenderProcessHost()->GetBrowserContext(); 719 web_contents()->GetRenderProcessHost()->GetBrowserContext();
719 context->CancelProtectedMediaIdentifierPermissionRequests(cdm_id); 720 context->CancelProtectedMediaIdentifierPermissionRequests(cdm_id);
720 } 721 }
721 722
722 void BrowserMediaPlayerManager::AddPlayer(MediaPlayerAndroid* player) { 723 void BrowserMediaPlayerManager::AddPlayer(MediaPlayerAndroid* player) {
723 DCHECK(!GetPlayer(player->player_id())); 724 DCHECK(!GetPlayer(player->player_id()));
724 players_.push_back(player); 725 players_.push_back(player);
725 } 726 }
726 727
727 void BrowserMediaPlayerManager::RemovePlayer(int player_id) { 728 void BrowserMediaPlayerManager::RemovePlayer(int player_id) {
728 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); 729 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin();
729 it != players_.end(); ++it) { 730 it != players_.end(); ++it) {
730 MediaPlayerAndroid* player = *it; 731 MediaPlayerAndroid* player = *it;
731 if (player->player_id() == player_id) { 732 if (player->player_id() == player_id) {
732 players_.erase(it); 733 players_.erase(it);
733 break; 734 break;
734 } 735 }
735 } 736 }
736 737
737 for (DrmBridgePlayerMap::iterator it = drm_bridge_player_map_.begin(); 738 for (CdmToPlayerMap::iterator it = cdm_to_player_map_.begin();
738 it != drm_bridge_player_map_.end(); ++it) { 739 it != cdm_to_player_map_.end(); ++it) {
739 if (it->second == player_id) { 740 if (it->second == player_id) {
740 drm_bridge_player_map_.erase(it); 741 cdm_to_player_map_.erase(it);
741 break; 742 break;
742 } 743 }
743 } 744 }
744 } 745 }
745 746
746 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer( 747 scoped_ptr<media::MediaPlayerAndroid> BrowserMediaPlayerManager::SwapPlayer(
747 int player_id, media::MediaPlayerAndroid* player) { 748 int player_id, media::MediaPlayerAndroid* player) {
748 media::MediaPlayerAndroid* previous_player = NULL; 749 media::MediaPlayerAndroid* previous_player = NULL;
749 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); 750 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin();
750 it != players_.end(); ++it) { 751 it != players_.end(); ++it) {
751 if ((*it)->player_id() == player_id) { 752 if ((*it)->player_id() == player_id) {
752 previous_player = *it; 753 previous_player = *it;
753 players_.weak_erase(it); 754 players_.weak_erase(it);
754 players_.push_back(player); 755 players_.push_back(player);
755 break; 756 break;
756 } 757 }
757 } 758 }
758 return scoped_ptr<media::MediaPlayerAndroid>(previous_player); 759 return scoped_ptr<media::MediaPlayerAndroid>(previous_player);
759 } 760 }
760 761
761 void BrowserMediaPlayerManager::AddDrmBridge(int cdm_id, 762 void BrowserMediaPlayerManager::AddCdm(int cdm_id,
762 const std::string& key_system, 763 const std::string& key_system,
763 const GURL& security_origin) { 764 const GURL& security_origin) {
764 DCHECK(!GetDrmBridge(cdm_id)); 765 DCHECK(!GetCdm(cdm_id));
766 base::WeakPtr<BrowserMediaPlayerManager> weak_this =
767 weak_ptr_factory_.GetWeakPtr();
765 768
766 scoped_ptr<MediaDrmBridge> drm_bridge( 769 scoped_ptr<MediaKeys> cdm(media::CreateCdm(
767 MediaDrmBridge::Create(cdm_id, key_system, security_origin, this)); 770 key_system,
768 if (!drm_bridge) { 771 base::Bind(
772 &BrowserMediaPlayerManager::OnSessionCreated, weak_this, cdm_id),
773 base::Bind(
774 &BrowserMediaPlayerManager::OnSessionMessage, weak_this, cdm_id),
775 base::Bind(&BrowserMediaPlayerManager::OnSessionReady, weak_this, cdm_id),
776 base::Bind(
777 &BrowserMediaPlayerManager::OnSessionClosed, weak_this, cdm_id),
778 base::Bind(
779 &BrowserMediaPlayerManager::OnSessionError, weak_this, cdm_id)));
780
781 if (!cdm) {
769 // This failure will be discovered and reported by OnCreateSession() 782 // This failure will be discovered and reported by OnCreateSession()
770 // as GetDrmBridge() will return null. 783 // as GetCdm() will return null.
771 DVLOG(1) << "failed to create drm bridge."; 784 DVLOG(1) << "failed to create CDM.";
772 return; 785 return;
773 } 786 }
774 787
775 // TODO(xhwang/ddorwin): Pass the security level from key system. 788 cdm_map_[cdm_id] = cdm.release();
776 MediaDrmBridge::SecurityLevel security_level = 789 security_origin_map_[cdm_id] = security_origin;
777 MediaDrmBridge::SECURITY_LEVEL_3;
778 if (CommandLine::ForCurrentProcess()
779 ->HasSwitch(switches::kMediaDrmEnableNonCompositing)) {
780 security_level = MediaDrmBridge::SECURITY_LEVEL_1;
781 }
782 if (!drm_bridge->SetSecurityLevel(security_level)) {
783 DVLOG(1) << "failed to set security level " << security_level;
784 return;
785 }
786
787 drm_bridges_.push_back(drm_bridge.release());
788 } 790 }
789 791
790 void BrowserMediaPlayerManager::RemoveDrmBridge(int cdm_id) { 792 void BrowserMediaPlayerManager::RemoveCdm(int cdm_id) {
791 // TODO(xhwang): Detach DrmBridge from the player it's set to. In prefixed 793 // TODO(xhwang): Detach CDM from the player it's set to. In prefixed
792 // EME implementation the current code is fine because we always destroy the 794 // EME implementation the current code is fine because we always destroy the
793 // player before we destroy the DrmBridge. This will not always be the case 795 // player before we destroy the DrmBridge. This will not always be the case
794 // in unprefixed EME implementation. 796 // in unprefixed EME implementation.
795 for (ScopedVector<MediaDrmBridge>::iterator it = drm_bridges_.begin(); 797 CdmMap::iterator iter = cdm_map_.find(cdm_id);
796 it != drm_bridges_.end(); ++it) { 798 if (iter != cdm_map_.end()) {
797 if ((*it)->cdm_id() == cdm_id) { 799 delete iter->second;
798 drm_bridges_.erase(it); 800 cdm_map_.erase(iter);
799 drm_bridge_player_map_.erase(cdm_id);
800 break;
801 }
802 } 801 }
802 cdm_to_player_map_.erase(cdm_id);
803 security_origin_map_.erase(cdm_id);
803 } 804 }
804 805
805 void BrowserMediaPlayerManager::OnSetCdm(int player_id, int cdm_id) { 806 void BrowserMediaPlayerManager::OnSetCdm(int player_id, int cdm_id) {
806 MediaPlayerAndroid* player = GetPlayer(player_id); 807 MediaPlayerAndroid* player = GetPlayer(player_id);
807 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); 808 MediaKeys* cdm = GetCdm(cdm_id);
808 if (!drm_bridge || !player) { 809 if (!cdm || !player) {
809 DVLOG(1) << "Cannot set CDM on the specified player."; 810 DVLOG(1) << "Cannot set CDM on the specified player.";
810 return; 811 return;
811 } 812 }
812 813
813 // TODO(qinmin): add the logic to decide whether we should create the 814 // TODO(qinmin): add the logic to decide whether we should create the
814 // fullscreen surface for EME lv1. 815 // fullscreen surface for EME lv1.
815 player->SetDrmBridge(drm_bridge); 816 player->SetCdm(cdm);
816 // Do now support setting one CDM on multiple players. 817 // Do now support setting one CDM on multiple players.
817 DCHECK(drm_bridge_player_map_.find(cdm_id) == drm_bridge_player_map_.end()); 818 DCHECK(!ContainsKey(cdm_to_player_map_, cdm_id));
818 drm_bridge_player_map_[cdm_id] = player_id; 819 cdm_to_player_map_[cdm_id] = player_id;
819 } 820 }
820 821
821 void BrowserMediaPlayerManager::CreateSessionIfPermitted( 822 void BrowserMediaPlayerManager::CreateSessionIfPermitted(
822 int cdm_id, 823 int cdm_id,
823 uint32 session_id, 824 uint32 session_id,
824 const std::string& content_type, 825 const std::string& content_type,
825 const std::vector<uint8>& init_data, 826 const std::vector<uint8>& init_data,
826 bool permitted) { 827 bool permitted) {
827 if (!permitted) { 828 if (!permitted) {
828 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); 829 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0);
829 return; 830 return;
830 } 831 }
831 832
832 MediaDrmBridge* drm_bridge = GetDrmBridge(cdm_id); 833 MediaKeys* cdm = GetCdm(cdm_id);
833 if (!drm_bridge) { 834 if (!cdm) {
834 DLOG(WARNING) << "No MediaDrmBridge for ID: " << cdm_id << " found"; 835 DLOG(WARNING) << "No CDM for ID: " << cdm_id << " found";
835 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); 836 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0);
836 return; 837 return;
837 } 838 }
838 839
839 // This could fail, in which case a SessionError will be fired. 840 // This could fail, in which case a SessionError will be fired.
840 drm_bridge->CreateSession( 841 cdm->CreateSession(
841 session_id, content_type, &init_data[0], init_data.size()); 842 session_id, content_type, &init_data[0], init_data.size());
842 } 843 }
843 844
844 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer( 845 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer(
845 MediaPlayerAndroid* player) { 846 MediaPlayerAndroid* player) {
846 player->Release(); 847 player->Release();
847 } 848 }
848 849
849 void BrowserMediaPlayerManager::OnMediaResourcesRequested(int player_id) { 850 void BrowserMediaPlayerManager::OnMediaResourcesRequested(int player_id) {
850 int num_active_player = 0; 851 int num_active_player = 0;
(...skipping 27 matching lines...) Expand all
878 #if defined(VIDEO_HOLE) 879 #if defined(VIDEO_HOLE)
879 MediaPlayerAndroid* player = GetPlayer(player_id); 880 MediaPlayerAndroid* player = GetPlayer(player_id);
880 if (player && player->IsSurfaceInUse()) 881 if (player && player->IsSurfaceInUse())
881 return; 882 return;
882 if (external_video_surface_container_) 883 if (external_video_surface_container_)
883 external_video_surface_container_->ReleaseExternalVideoSurface(player_id); 884 external_video_surface_container_->ReleaseExternalVideoSurface(player_id);
884 #endif // defined(VIDEO_HOLE) 885 #endif // defined(VIDEO_HOLE)
885 } 886 }
886 887
887 } // namespace content 888 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698