OLD | NEW |
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/mojo/services/mojo_cdm_service.h" | 5 #include "media/mojo/services/mojo_cdm_service.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 // static | 75 // static |
76 scoped_refptr<MediaKeys> MojoCdmService::LegacyGetCdm(int cdm_id) { | 76 scoped_refptr<MediaKeys> MojoCdmService::LegacyGetCdm(int cdm_id) { |
77 DVLOG(1) << __FUNCTION__ << ": " << cdm_id; | 77 DVLOG(1) << __FUNCTION__ << ": " << cdm_id; |
78 return g_cdm_manager.Get().GetCdm(cdm_id); | 78 return g_cdm_manager.Get().GetCdm(cdm_id); |
79 } | 79 } |
80 | 80 |
81 MojoCdmService::MojoCdmService( | 81 MojoCdmService::MojoCdmService( |
82 base::WeakPtr<MojoCdmServiceContext> context, | 82 base::WeakPtr<MojoCdmServiceContext> context, |
83 CdmFactory* cdm_factory, | 83 CdmFactory* cdm_factory, |
84 mojo::InterfaceRequest<interfaces::ContentDecryptionModule> request) | 84 mojo::InterfaceRequest<mojom::ContentDecryptionModule> request) |
85 : binding_(this, std::move(request)), | 85 : binding_(this, std::move(request)), |
86 context_(context), | 86 context_(context), |
87 cdm_factory_(cdm_factory), | 87 cdm_factory_(cdm_factory), |
88 cdm_id_(CdmContext::kInvalidCdmId), | 88 cdm_id_(CdmContext::kInvalidCdmId), |
89 weak_factory_(this) { | 89 weak_factory_(this) { |
90 DCHECK(context_); | 90 DCHECK(context_); |
91 DCHECK(cdm_factory_); | 91 DCHECK(cdm_factory_); |
92 } | 92 } |
93 | 93 |
94 MojoCdmService::~MojoCdmService() { | 94 MojoCdmService::~MojoCdmService() { |
95 if (cdm_id_ == CdmContext::kInvalidCdmId) | 95 if (cdm_id_ == CdmContext::kInvalidCdmId) |
96 return; | 96 return; |
97 | 97 |
98 g_cdm_manager.Get().UnregisterCdm(cdm_id_); | 98 g_cdm_manager.Get().UnregisterCdm(cdm_id_); |
99 | 99 |
100 if (context_) | 100 if (context_) |
101 context_->UnregisterCdm(cdm_id_); | 101 context_->UnregisterCdm(cdm_id_); |
102 } | 102 } |
103 | 103 |
104 void MojoCdmService::SetClient( | 104 void MojoCdmService::SetClient(mojom::ContentDecryptionModuleClientPtr client) { |
105 interfaces::ContentDecryptionModuleClientPtr client) { | |
106 client_ = std::move(client); | 105 client_ = std::move(client); |
107 } | 106 } |
108 | 107 |
109 void MojoCdmService::Initialize(const mojo::String& key_system, | 108 void MojoCdmService::Initialize(const mojo::String& key_system, |
110 const mojo::String& security_origin, | 109 const mojo::String& security_origin, |
111 interfaces::CdmConfigPtr cdm_config, | 110 mojom::CdmConfigPtr cdm_config, |
112 const InitializeCallback& callback) { | 111 const InitializeCallback& callback) { |
113 DVLOG(1) << __FUNCTION__ << ": " << key_system; | 112 DVLOG(1) << __FUNCTION__ << ": " << key_system; |
114 DCHECK(!cdm_); | 113 DCHECK(!cdm_); |
115 | 114 |
116 auto weak_this = weak_factory_.GetWeakPtr(); | 115 auto weak_this = weak_factory_.GetWeakPtr(); |
117 cdm_factory_->Create( | 116 cdm_factory_->Create( |
118 key_system, GURL(security_origin.get()), cdm_config.To<CdmConfig>(), | 117 key_system, GURL(security_origin.get()), cdm_config.To<CdmConfig>(), |
119 base::Bind(&MojoCdmService::OnSessionMessage, weak_this), | 118 base::Bind(&MojoCdmService::OnSessionMessage, weak_this), |
120 base::Bind(&MojoCdmService::OnSessionClosed, weak_this), | 119 base::Bind(&MojoCdmService::OnSessionClosed, weak_this), |
121 base::Bind(&MojoCdmService::OnLegacySessionError, weak_this), | 120 base::Bind(&MojoCdmService::OnLegacySessionError, weak_this), |
122 base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this), | 121 base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this), |
123 base::Bind(&MojoCdmService::OnSessionExpirationUpdate, weak_this), | 122 base::Bind(&MojoCdmService::OnSessionExpirationUpdate, weak_this), |
124 base::Bind(&MojoCdmService::OnCdmCreated, weak_this, callback)); | 123 base::Bind(&MojoCdmService::OnCdmCreated, weak_this, callback)); |
125 } | 124 } |
126 | 125 |
127 void MojoCdmService::SetServerCertificate( | 126 void MojoCdmService::SetServerCertificate( |
128 mojo::Array<uint8_t> certificate_data, | 127 mojo::Array<uint8_t> certificate_data, |
129 const mojo::Callback<void(interfaces::CdmPromiseResultPtr)>& callback) { | 128 const mojo::Callback<void(mojom::CdmPromiseResultPtr)>& callback) { |
130 DVLOG(2) << __FUNCTION__; | 129 DVLOG(2) << __FUNCTION__; |
131 cdm_->SetServerCertificate( | 130 cdm_->SetServerCertificate( |
132 certificate_data.storage(), | 131 certificate_data.storage(), |
133 base::WrapUnique(new SimpleMojoCdmPromise(callback))); | 132 base::WrapUnique(new SimpleMojoCdmPromise(callback))); |
134 } | 133 } |
135 | 134 |
136 void MojoCdmService::CreateSessionAndGenerateRequest( | 135 void MojoCdmService::CreateSessionAndGenerateRequest( |
137 interfaces::ContentDecryptionModule::SessionType session_type, | 136 mojom::ContentDecryptionModule::SessionType session_type, |
138 interfaces::ContentDecryptionModule::InitDataType init_data_type, | 137 mojom::ContentDecryptionModule::InitDataType init_data_type, |
139 mojo::Array<uint8_t> init_data, | 138 mojo::Array<uint8_t> init_data, |
140 const mojo::Callback<void(interfaces::CdmPromiseResultPtr, mojo::String)>& | 139 const mojo::Callback<void(mojom::CdmPromiseResultPtr, mojo::String)>& |
141 callback) { | 140 callback) { |
142 DVLOG(2) << __FUNCTION__; | 141 DVLOG(2) << __FUNCTION__; |
143 cdm_->CreateSessionAndGenerateRequest( | 142 cdm_->CreateSessionAndGenerateRequest( |
144 static_cast<MediaKeys::SessionType>(session_type), | 143 static_cast<MediaKeys::SessionType>(session_type), |
145 static_cast<EmeInitDataType>(init_data_type), init_data.storage(), | 144 static_cast<EmeInitDataType>(init_data_type), init_data.storage(), |
146 base::WrapUnique(new NewSessionMojoCdmPromise(callback))); | 145 base::WrapUnique(new NewSessionMojoCdmPromise(callback))); |
147 } | 146 } |
148 | 147 |
149 void MojoCdmService::LoadSession( | 148 void MojoCdmService::LoadSession( |
150 interfaces::ContentDecryptionModule::SessionType session_type, | 149 mojom::ContentDecryptionModule::SessionType session_type, |
151 const mojo::String& session_id, | 150 const mojo::String& session_id, |
152 const mojo::Callback<void(interfaces::CdmPromiseResultPtr, mojo::String)>& | 151 const mojo::Callback<void(mojom::CdmPromiseResultPtr, mojo::String)>& |
153 callback) { | 152 callback) { |
154 DVLOG(2) << __FUNCTION__; | 153 DVLOG(2) << __FUNCTION__; |
155 cdm_->LoadSession(static_cast<MediaKeys::SessionType>(session_type), | 154 cdm_->LoadSession(static_cast<MediaKeys::SessionType>(session_type), |
156 session_id.To<std::string>(), | 155 session_id.To<std::string>(), |
157 base::WrapUnique(new NewSessionMojoCdmPromise(callback))); | 156 base::WrapUnique(new NewSessionMojoCdmPromise(callback))); |
158 } | 157 } |
159 | 158 |
160 void MojoCdmService::UpdateSession( | 159 void MojoCdmService::UpdateSession( |
161 const mojo::String& session_id, | 160 const mojo::String& session_id, |
162 mojo::Array<uint8_t> response, | 161 mojo::Array<uint8_t> response, |
163 const mojo::Callback<void(interfaces::CdmPromiseResultPtr)>& callback) { | 162 const mojo::Callback<void(mojom::CdmPromiseResultPtr)>& callback) { |
164 DVLOG(2) << __FUNCTION__; | 163 DVLOG(2) << __FUNCTION__; |
165 cdm_->UpdateSession( | 164 cdm_->UpdateSession( |
166 session_id.To<std::string>(), response.storage(), | 165 session_id.To<std::string>(), response.storage(), |
167 std::unique_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); | 166 std::unique_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); |
168 } | 167 } |
169 | 168 |
170 void MojoCdmService::CloseSession( | 169 void MojoCdmService::CloseSession( |
171 const mojo::String& session_id, | 170 const mojo::String& session_id, |
172 const mojo::Callback<void(interfaces::CdmPromiseResultPtr)>& callback) { | 171 const mojo::Callback<void(mojom::CdmPromiseResultPtr)>& callback) { |
173 DVLOG(2) << __FUNCTION__; | 172 DVLOG(2) << __FUNCTION__; |
174 cdm_->CloseSession(session_id.To<std::string>(), | 173 cdm_->CloseSession(session_id.To<std::string>(), |
175 base::WrapUnique(new SimpleMojoCdmPromise(callback))); | 174 base::WrapUnique(new SimpleMojoCdmPromise(callback))); |
176 } | 175 } |
177 | 176 |
178 void MojoCdmService::RemoveSession( | 177 void MojoCdmService::RemoveSession( |
179 const mojo::String& session_id, | 178 const mojo::String& session_id, |
180 const mojo::Callback<void(interfaces::CdmPromiseResultPtr)>& callback) { | 179 const mojo::Callback<void(mojom::CdmPromiseResultPtr)>& callback) { |
181 DVLOG(2) << __FUNCTION__; | 180 DVLOG(2) << __FUNCTION__; |
182 cdm_->RemoveSession(session_id.To<std::string>(), | 181 cdm_->RemoveSession(session_id.To<std::string>(), |
183 base::WrapUnique(new SimpleMojoCdmPromise(callback))); | 182 base::WrapUnique(new SimpleMojoCdmPromise(callback))); |
184 } | 183 } |
185 | 184 |
186 scoped_refptr<MediaKeys> MojoCdmService::GetCdm() { | 185 scoped_refptr<MediaKeys> MojoCdmService::GetCdm() { |
187 return cdm_; | 186 return cdm_; |
188 } | 187 } |
189 | 188 |
190 void MojoCdmService::OnCdmCreated(const InitializeCallback& callback, | 189 void MojoCdmService::OnCdmCreated(const InitializeCallback& callback, |
191 const scoped_refptr<MediaKeys>& cdm, | 190 const scoped_refptr<MediaKeys>& cdm, |
192 const std::string& error_message) { | 191 const std::string& error_message) { |
193 interfaces::CdmPromiseResultPtr cdm_promise_result( | 192 mojom::CdmPromiseResultPtr cdm_promise_result(mojom::CdmPromiseResult::New()); |
194 interfaces::CdmPromiseResult::New()); | |
195 | 193 |
196 // TODO(xhwang): This should not happen when KeySystemInfo is properly | 194 // TODO(xhwang): This should not happen when KeySystemInfo is properly |
197 // populated. See http://crbug.com/469366 | 195 // populated. See http://crbug.com/469366 |
198 if (!cdm || !context_) { | 196 if (!cdm || !context_) { |
199 cdm_promise_result->success = false; | 197 cdm_promise_result->success = false; |
200 cdm_promise_result->exception = | 198 cdm_promise_result->exception = mojom::CdmException::NOT_SUPPORTED_ERROR; |
201 interfaces::CdmException::NOT_SUPPORTED_ERROR; | |
202 cdm_promise_result->system_code = 0; | 199 cdm_promise_result->system_code = 0; |
203 cdm_promise_result->error_message = error_message; | 200 cdm_promise_result->error_message = error_message; |
204 callback.Run(std::move(cdm_promise_result), 0, nullptr); | 201 callback.Run(std::move(cdm_promise_result), 0, nullptr); |
205 return; | 202 return; |
206 } | 203 } |
207 | 204 |
208 cdm_ = cdm; | 205 cdm_ = cdm; |
209 cdm_id_ = next_cdm_id_++; | 206 cdm_id_ = next_cdm_id_++; |
210 | 207 |
211 context_->RegisterCdm(cdm_id_, this); | 208 context_->RegisterCdm(cdm_id_, this); |
212 g_cdm_manager.Get().RegisterCdm(cdm_id_, cdm); | 209 g_cdm_manager.Get().RegisterCdm(cdm_id_, cdm); |
213 | 210 |
214 // If |cdm| has a decryptor, create the MojoDecryptorService | 211 // If |cdm| has a decryptor, create the MojoDecryptorService |
215 // and pass the connection back to the client. | 212 // and pass the connection back to the client. |
216 interfaces::DecryptorPtr decryptor_service; | 213 mojom::DecryptorPtr decryptor_service; |
217 CdmContext* const cdm_context = cdm_->GetCdmContext(); | 214 CdmContext* const cdm_context = cdm_->GetCdmContext(); |
218 if (cdm_context && cdm_context->GetDecryptor()) { | 215 if (cdm_context && cdm_context->GetDecryptor()) { |
219 // MojoDecryptorService takes a reference to the CDM, but it is still owned | 216 // MojoDecryptorService takes a reference to the CDM, but it is still owned |
220 // by |this|. | 217 // by |this|. |
221 decryptor_.reset(new MojoDecryptorService( | 218 decryptor_.reset(new MojoDecryptorService( |
222 cdm_, GetProxy(&decryptor_service), | 219 cdm_, GetProxy(&decryptor_service), |
223 base::Bind(&MojoCdmService::OnDecryptorConnectionError, weak_this_))); | 220 base::Bind(&MojoCdmService::OnDecryptorConnectionError, weak_this_))); |
224 } | 221 } |
225 | 222 |
226 DVLOG(1) << __FUNCTION__ << ": CDM successfully created with ID " << cdm_id_; | 223 DVLOG(1) << __FUNCTION__ << ": CDM successfully created with ID " << cdm_id_; |
227 cdm_promise_result->success = true; | 224 cdm_promise_result->success = true; |
228 callback.Run(std::move(cdm_promise_result), cdm_id_, | 225 callback.Run(std::move(cdm_promise_result), cdm_id_, |
229 std::move(decryptor_service)); | 226 std::move(decryptor_service)); |
230 } | 227 } |
231 | 228 |
232 void MojoCdmService::OnSessionMessage(const std::string& session_id, | 229 void MojoCdmService::OnSessionMessage(const std::string& session_id, |
233 MediaKeys::MessageType message_type, | 230 MediaKeys::MessageType message_type, |
234 const std::vector<uint8_t>& message, | 231 const std::vector<uint8_t>& message, |
235 const GURL& legacy_destination_url) { | 232 const GURL& legacy_destination_url) { |
236 DVLOG(2) << __FUNCTION__ << "(" << message_type << ")"; | 233 DVLOG(2) << __FUNCTION__ << "(" << message_type << ")"; |
237 client_->OnSessionMessage( | 234 client_->OnSessionMessage(session_id, |
238 session_id, static_cast<interfaces::CdmMessageType>(message_type), | 235 static_cast<mojom::CdmMessageType>(message_type), |
239 mojo::Array<uint8_t>::From(message), | 236 mojo::Array<uint8_t>::From(message), |
240 mojo::String::From(legacy_destination_url)); | 237 mojo::String::From(legacy_destination_url)); |
241 } | 238 } |
242 | 239 |
243 void MojoCdmService::OnSessionKeysChange(const std::string& session_id, | 240 void MojoCdmService::OnSessionKeysChange(const std::string& session_id, |
244 bool has_additional_usable_key, | 241 bool has_additional_usable_key, |
245 CdmKeysInfo keys_info) { | 242 CdmKeysInfo keys_info) { |
246 DVLOG(2) << __FUNCTION__ | 243 DVLOG(2) << __FUNCTION__ |
247 << " has_additional_usable_key=" << has_additional_usable_key; | 244 << " has_additional_usable_key=" << has_additional_usable_key; |
248 | 245 |
249 mojo::Array<interfaces::CdmKeyInformationPtr> keys_data; | 246 mojo::Array<mojom::CdmKeyInformationPtr> keys_data; |
250 for (const auto& key : keys_info) | 247 for (const auto& key : keys_info) |
251 keys_data.push_back(interfaces::CdmKeyInformation::From(*key)); | 248 keys_data.push_back(mojom::CdmKeyInformation::From(*key)); |
252 client_->OnSessionKeysChange(session_id, has_additional_usable_key, | 249 client_->OnSessionKeysChange(session_id, has_additional_usable_key, |
253 std::move(keys_data)); | 250 std::move(keys_data)); |
254 } | 251 } |
255 | 252 |
256 void MojoCdmService::OnSessionExpirationUpdate( | 253 void MojoCdmService::OnSessionExpirationUpdate( |
257 const std::string& session_id, | 254 const std::string& session_id, |
258 const base::Time& new_expiry_time_sec) { | 255 const base::Time& new_expiry_time_sec) { |
259 DVLOG(2) << __FUNCTION__ << " expiry=" << new_expiry_time_sec; | 256 DVLOG(2) << __FUNCTION__ << " expiry=" << new_expiry_time_sec; |
260 client_->OnSessionExpirationUpdate(session_id, | 257 client_->OnSessionExpirationUpdate(session_id, |
261 new_expiry_time_sec.ToDoubleT()); | 258 new_expiry_time_sec.ToDoubleT()); |
262 } | 259 } |
263 | 260 |
264 void MojoCdmService::OnSessionClosed(const std::string& session_id) { | 261 void MojoCdmService::OnSessionClosed(const std::string& session_id) { |
265 DVLOG(2) << __FUNCTION__; | 262 DVLOG(2) << __FUNCTION__; |
266 client_->OnSessionClosed(session_id); | 263 client_->OnSessionClosed(session_id); |
267 } | 264 } |
268 | 265 |
269 void MojoCdmService::OnLegacySessionError(const std::string& session_id, | 266 void MojoCdmService::OnLegacySessionError(const std::string& session_id, |
270 MediaKeys::Exception exception, | 267 MediaKeys::Exception exception, |
271 uint32_t system_code, | 268 uint32_t system_code, |
272 const std::string& error_message) { | 269 const std::string& error_message) { |
273 DVLOG(2) << __FUNCTION__ << "(" << exception << ") " << error_message; | 270 DVLOG(2) << __FUNCTION__ << "(" << exception << ") " << error_message; |
274 client_->OnLegacySessionError( | 271 client_->OnLegacySessionError(session_id, |
275 session_id, static_cast<interfaces::CdmException>(exception), system_code, | 272 static_cast<mojom::CdmException>(exception), |
276 error_message); | 273 system_code, error_message); |
277 } | 274 } |
278 | 275 |
279 void MojoCdmService::OnDecryptorConnectionError() { | 276 void MojoCdmService::OnDecryptorConnectionError() { |
280 DVLOG(2) << __FUNCTION__; | 277 DVLOG(2) << __FUNCTION__; |
281 | 278 |
282 // MojoDecryptorService has lost connectivity to it's client, so it can be | 279 // MojoDecryptorService has lost connectivity to it's client, so it can be |
283 // freed. | 280 // freed. |
284 decryptor_.reset(); | 281 decryptor_.reset(); |
285 } | 282 } |
286 | 283 |
287 } // namespace media | 284 } // namespace media |
OLD | NEW |