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

Side by Side Diff: media/blink/cdm_session_adapter.cc

Issue 1070853004: media: CdmFactory creates CDM (MediaKeys) asynchronously. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase only Created 5 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "media/blink/cdm_session_adapter.h" 5 #include "media/blink/cdm_session_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "media/base/cdm_factory.h" 11 #include "media/base/cdm_factory.h"
12 #include "media/base/cdm_key_information.h" 12 #include "media/base/cdm_key_information.h"
13 #include "media/base/cdm_promise.h" 13 #include "media/base/cdm_promise.h"
14 #include "media/base/key_systems.h" 14 #include "media/base/key_systems.h"
15 #include "media/base/media_keys.h" 15 #include "media/base/media_keys.h"
16 #include "media/blink/webcontentdecryptionmodule_impl.h"
16 #include "media/blink/webcontentdecryptionmodulesession_impl.h" 17 #include "media/blink/webcontentdecryptionmodulesession_impl.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace media { 20 namespace media {
20 21
21 const char kMediaEME[] = "Media.EME."; 22 const char kMediaEME[] = "Media.EME.";
22 const char kDot[] = "."; 23 const char kDot[] = ".";
23 24
24 CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) { 25 CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) {
25 } 26 }
26 27
27 CdmSessionAdapter::~CdmSessionAdapter() {} 28 CdmSessionAdapter::~CdmSessionAdapter() {}
28 29
29 bool CdmSessionAdapter::Initialize(CdmFactory* cdm_factory, 30 void CdmSessionAdapter::CreateCdm(
30 const std::string& key_system, 31 CdmFactory* cdm_factory,
31 bool allow_distinctive_identifier, 32 const std::string& key_system,
32 bool allow_persistent_state, 33 bool allow_distinctive_identifier,
33 const GURL& security_origin) { 34 bool allow_persistent_state,
34 key_system_ = key_system; 35 const GURL& security_origin,
35 key_system_uma_prefix_ = 36 blink::WebContentDecryptionModuleResult result) {
36 kMediaEME + GetKeySystemNameForUMA(key_system) + kDot; 37 // Note: OnCdmCreated() is binded with |this| instead of |weak_this| to
37 38 // prevent |this| from being desctructed.
ddorwin 2015/04/10 00:59:43 Thanks for documenting this. Can you further expla
xhwang 2015/04/10 17:41:17 Done.
38 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); 39 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr();
39 media_keys_ = cdm_factory->Create( 40 cdm_factory->Create(
40 key_system, allow_distinctive_identifier, allow_persistent_state, 41 key_system, allow_distinctive_identifier, allow_persistent_state,
41 security_origin, 42 security_origin,
42 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), 43 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this),
43 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), 44 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this),
44 base::Bind(&CdmSessionAdapter::OnLegacySessionError, weak_this), 45 base::Bind(&CdmSessionAdapter::OnLegacySessionError, weak_this),
45 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), 46 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this),
46 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this)); 47 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this),
47 return media_keys_.get() != nullptr; 48 base::Bind(&CdmSessionAdapter::OnCdmCreated, this, key_system, result));
48 } 49 }
49 50
50 void CdmSessionAdapter::SetServerCertificate( 51 void CdmSessionAdapter::SetServerCertificate(
51 const uint8* server_certificate, 52 const uint8* server_certificate,
52 int server_certificate_length, 53 int server_certificate_length,
53 scoped_ptr<SimpleCdmPromise> promise) { 54 scoped_ptr<SimpleCdmPromise> promise) {
54 media_keys_->SetServerCertificate( 55 cdm_->SetServerCertificate(server_certificate, server_certificate_length,
55 server_certificate, server_certificate_length, promise.Pass()); 56 promise.Pass());
56 } 57 }
57 58
58 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() { 59 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() {
59 return new WebContentDecryptionModuleSessionImpl(this); 60 return new WebContentDecryptionModuleSessionImpl(this);
60 } 61 }
61 62
62 bool CdmSessionAdapter::RegisterSession( 63 bool CdmSessionAdapter::RegisterSession(
63 const std::string& session_id, 64 const std::string& session_id,
64 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session) { 65 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session) {
65 // If this session ID is already registered, don't register it again. 66 // If this session ID is already registered, don't register it again.
66 if (ContainsKey(sessions_, session_id)) 67 if (ContainsKey(sessions_, session_id))
67 return false; 68 return false;
68 69
69 sessions_[session_id] = session; 70 sessions_[session_id] = session;
70 return true; 71 return true;
71 } 72 }
72 73
73 void CdmSessionAdapter::UnregisterSession(const std::string& session_id) { 74 void CdmSessionAdapter::UnregisterSession(const std::string& session_id) {
74 DCHECK(ContainsKey(sessions_, session_id)); 75 DCHECK(ContainsKey(sessions_, session_id));
75 sessions_.erase(session_id); 76 sessions_.erase(session_id);
76 } 77 }
77 78
78 void CdmSessionAdapter::InitializeNewSession( 79 void CdmSessionAdapter::InitializeNewSession(
79 EmeInitDataType init_data_type, 80 EmeInitDataType init_data_type,
80 const uint8* init_data, 81 const uint8* init_data,
81 int init_data_length, 82 int init_data_length,
82 MediaKeys::SessionType session_type, 83 MediaKeys::SessionType session_type,
83 scoped_ptr<NewSessionCdmPromise> promise) { 84 scoped_ptr<NewSessionCdmPromise> promise) {
84 media_keys_->CreateSessionAndGenerateRequest(session_type, init_data_type, 85 cdm_->CreateSessionAndGenerateRequest(session_type, init_data_type, init_data,
85 init_data, init_data_length, 86 init_data_length, promise.Pass());
86 promise.Pass());
87 } 87 }
88 88
89 void CdmSessionAdapter::LoadSession(MediaKeys::SessionType session_type, 89 void CdmSessionAdapter::LoadSession(MediaKeys::SessionType session_type,
90 const std::string& session_id, 90 const std::string& session_id,
91 scoped_ptr<NewSessionCdmPromise> promise) { 91 scoped_ptr<NewSessionCdmPromise> promise) {
92 media_keys_->LoadSession(session_type, session_id, promise.Pass()); 92 cdm_->LoadSession(session_type, session_id, promise.Pass());
93 } 93 }
94 94
95 void CdmSessionAdapter::UpdateSession(const std::string& session_id, 95 void CdmSessionAdapter::UpdateSession(const std::string& session_id,
96 const uint8* response, 96 const uint8* response,
97 int response_length, 97 int response_length,
98 scoped_ptr<SimpleCdmPromise> promise) { 98 scoped_ptr<SimpleCdmPromise> promise) {
99 media_keys_->UpdateSession(session_id, response, response_length, 99 cdm_->UpdateSession(session_id, response, response_length, promise.Pass());
100 promise.Pass());
101 } 100 }
102 101
103 void CdmSessionAdapter::CloseSession(const std::string& session_id, 102 void CdmSessionAdapter::CloseSession(const std::string& session_id,
104 scoped_ptr<SimpleCdmPromise> promise) { 103 scoped_ptr<SimpleCdmPromise> promise) {
105 media_keys_->CloseSession(session_id, promise.Pass()); 104 cdm_->CloseSession(session_id, promise.Pass());
106 } 105 }
107 106
108 void CdmSessionAdapter::RemoveSession(const std::string& session_id, 107 void CdmSessionAdapter::RemoveSession(const std::string& session_id,
109 scoped_ptr<SimpleCdmPromise> promise) { 108 scoped_ptr<SimpleCdmPromise> promise) {
110 media_keys_->RemoveSession(session_id, promise.Pass()); 109 cdm_->RemoveSession(session_id, promise.Pass());
111 } 110 }
112 111
113 CdmContext* CdmSessionAdapter::GetCdmContext() { 112 CdmContext* CdmSessionAdapter::GetCdmContext() {
114 return media_keys_->GetCdmContext(); 113 return cdm_->GetCdmContext();
115 } 114 }
116 115
117 const std::string& CdmSessionAdapter::GetKeySystem() const { 116 const std::string& CdmSessionAdapter::GetKeySystem() const {
118 return key_system_; 117 return key_system_;
119 } 118 }
120 119
121 const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const { 120 const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const {
122 return key_system_uma_prefix_; 121 return key_system_uma_prefix_;
123 } 122 }
124 123
124 void CdmSessionAdapter::OnCdmCreated(
125 const std::string& key_system,
126 blink::WebContentDecryptionModuleResult result,
127 scoped_ptr<MediaKeys> cdm) {
128 DVLOG(2) << __FUNCTION__;
129 if (!cdm) {
130 result.completeWithError(
131 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
132 "Failed to create CDM.");
ddorwin 2015/04/10 00:59:43 s/CDM/{MediaKeys|CDM instance}/
xhwang 2015/04/10 17:41:17 Done.
133 return;
134 }
135
136 key_system_ = key_system;
137 key_system_uma_prefix_ =
138 kMediaEME + GetKeySystemNameForUMA(key_system) + kDot;
139 cdm_ = cdm.Pass();
140
141 result.completeWithContentDecryptionModule(
142 new WebContentDecryptionModuleImpl(this));
143 }
144
125 void CdmSessionAdapter::OnSessionMessage( 145 void CdmSessionAdapter::OnSessionMessage(
126 const std::string& session_id, 146 const std::string& session_id,
127 MediaKeys::MessageType message_type, 147 MediaKeys::MessageType message_type,
128 const std::vector<uint8>& message, 148 const std::vector<uint8>& message,
129 const GURL& /* legacy_destination_url */) { 149 const GURL& /* legacy_destination_url */) {
130 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); 150 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id);
131 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " 151 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session "
132 << session_id; 152 << session_id;
133 if (session) 153 if (session)
134 session->OnSessionMessage(message_type, message); 154 session->OnSessionMessage(message_type, message);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( 195 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession(
176 const std::string& session_id) { 196 const std::string& session_id) {
177 // Since session objects may get garbage collected, it is possible that there 197 // Since session objects may get garbage collected, it is possible that there
178 // are events coming back from the CDM and the session has been unregistered. 198 // are events coming back from the CDM and the session has been unregistered.
179 // We can not tell if the CDM is firing events at sessions that never existed. 199 // We can not tell if the CDM is firing events at sessions that never existed.
180 SessionMap::iterator session = sessions_.find(session_id); 200 SessionMap::iterator session = sessions_.find(session_id);
181 return (session != sessions_.end()) ? session->second.get() : NULL; 201 return (session != sessions_.end()) ? session->second.get() : NULL;
182 } 202 }
183 203
184 } // namespace media 204 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698