| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "media/base/cdm_config.h" |
| 9 #include "media/base/cdm_factory.h" |
| 8 #include "media/base/cdm_key_information.h" | 10 #include "media/base/cdm_key_information.h" |
| 9 #include "media/base/key_systems.h" | 11 #include "media/base/key_systems.h" |
| 10 #include "media/cdm/aes_decryptor.h" | |
| 11 #include "media/mojo/services/media_type_converters.h" | 12 #include "media/mojo/services/media_type_converters.h" |
| 12 #include "media/mojo/services/mojo_cdm_promise.h" | |
| 13 #include "media/mojo/services/mojo_cdm_service_context.h" | 13 #include "media/mojo/services/mojo_cdm_service_context.h" |
| 14 #include "mojo/common/common_type_converters.h" | 14 #include "mojo/common/common_type_converters.h" |
| 15 #include "mojo/common/url_type_converters.h" | 15 #include "mojo/common/url_type_converters.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 | 19 |
| 20 typedef MojoCdmPromise<> SimpleMojoCdmPromise; | 20 using NewSessionMojoCdmPromise = MojoCdmPromise<std::string>; |
| 21 typedef MojoCdmPromise<std::string> NewSessionMojoCdmPromise; | 21 using SimpleMojoCdmPromise = MojoCdmPromise<>; |
| 22 | 22 |
| 23 MojoCdmService::MojoCdmService( | 23 MojoCdmService::MojoCdmService( |
| 24 MojoCdmServiceContext* context, | 24 MojoCdmServiceContext* context, |
| 25 mojo::ServiceProvider* service_provider, | 25 mojo::ServiceProvider* service_provider, |
| 26 CdmFactory* cdm_factory, |
| 26 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) | 27 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) |
| 27 : binding_(this, request.Pass()), | 28 : binding_(this, request.Pass()), |
| 28 context_(context), | 29 context_(context), |
| 29 service_provider_(service_provider), | 30 service_provider_(service_provider), |
| 31 cdm_factory_(cdm_factory), |
| 30 cdm_id_(CdmContext::kInvalidCdmId), | 32 cdm_id_(CdmContext::kInvalidCdmId), |
| 31 weak_factory_(this) { | 33 weak_factory_(this) { |
| 34 DCHECK(context_); |
| 35 DCHECK(cdm_factory_); |
| 32 } | 36 } |
| 33 | 37 |
| 34 MojoCdmService::~MojoCdmService() { | 38 MojoCdmService::~MojoCdmService() { |
| 35 if (cdm_id_ != CdmContext::kInvalidCdmId) | 39 if (cdm_id_ != CdmContext::kInvalidCdmId) |
| 36 context_->UnregisterCdm(cdm_id_); | 40 context_->UnregisterCdm(cdm_id_); |
| 37 } | 41 } |
| 38 | 42 |
| 39 void MojoCdmService::SetClient(mojo::ContentDecryptionModuleClientPtr client) { | 43 void MojoCdmService::SetClient(mojo::ContentDecryptionModuleClientPtr client) { |
| 40 client_ = client.Pass(); | 44 client_ = client.Pass(); |
| 41 } | 45 } |
| 42 | 46 |
| 43 void MojoCdmService::Initialize( | 47 void MojoCdmService::Initialize( |
| 44 const mojo::String& key_system, | 48 const mojo::String& key_system, |
| 45 const mojo::String& security_origin, | 49 const mojo::String& security_origin, |
| 46 int32_t cdm_id, | 50 int32_t cdm_id, |
| 47 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { | 51 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { |
| 48 DVLOG(1) << __FUNCTION__ << ": " << key_system; | 52 DVLOG(1) << __FUNCTION__ << ": " << key_system; |
| 49 DCHECK(!cdm_); | 53 DCHECK(!cdm_); |
| 50 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id); | 54 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id); |
| 51 | 55 |
| 52 SimpleMojoCdmPromise promise(callback); | 56 auto weak_this = weak_factory_.GetWeakPtr(); |
| 53 | 57 cdm_factory_->Create( |
| 54 // Only AesDecryptor is supported. | 58 key_system, GURL(security_origin), CdmConfig(), |
| 55 // TODO(xhwang): Use a CdmFactory to create the CDM here. See | 59 base::Bind(&MojoCdmService::OnSessionMessage, weak_this), |
| 56 // http://crbug.com/495273 | 60 base::Bind(&MojoCdmService::OnSessionClosed, weak_this), |
| 57 if (CanUseAesDecryptor(key_system)) { | 61 base::Bind(&MojoCdmService::OnLegacySessionError, weak_this), |
| 58 base::WeakPtr<MojoCdmService> weak_this = weak_factory_.GetWeakPtr(); | 62 base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this), |
| 59 cdm_.reset(new AesDecryptor( | 63 base::Bind(&MojoCdmService::OnSessionExpirationUpdate, weak_this), |
| 60 GURL::EmptyGURL(), | 64 base::Bind( |
| 61 base::Bind(&MojoCdmService::OnSessionMessage, weak_this), | 65 &MojoCdmService::OnCdmCreated, weak_this, cdm_id, |
| 62 base::Bind(&MojoCdmService::OnSessionClosed, weak_this), | 66 base::Passed(make_scoped_ptr(new SimpleMojoCdmPromise(callback))))); |
| 63 base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this))); | |
| 64 cdm_id_ = cdm_id; | |
| 65 context_->RegisterCdm(cdm_id_, this); | |
| 66 promise.resolve(); | |
| 67 } else { | |
| 68 // TODO(xhwang): This should not happen when KeySystemInfo is properly | |
| 69 // populated. See http://crbug.com/469366 | |
| 70 promise.reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not supported."); | |
| 71 } | |
| 72 } | 67 } |
| 73 | 68 |
| 74 // mojo::MediaRenderer implementation. | 69 // mojo::MediaRenderer implementation. |
| 75 void MojoCdmService::SetServerCertificate( | 70 void MojoCdmService::SetServerCertificate( |
| 76 mojo::Array<uint8_t> certificate_data, | 71 mojo::Array<uint8_t> certificate_data, |
| 77 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { | 72 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { |
| 78 DVLOG(2) << __FUNCTION__; | 73 DVLOG(2) << __FUNCTION__; |
| 79 cdm_->SetServerCertificate( | 74 cdm_->SetServerCertificate( |
| 80 certificate_data.storage(), | 75 certificate_data.storage(), |
| 81 make_scoped_ptr(new SimpleMojoCdmPromise(callback))); | 76 make_scoped_ptr(new SimpleMojoCdmPromise(callback))); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 128 |
| 134 void MojoCdmService::GetDecryptor( | 129 void MojoCdmService::GetDecryptor( |
| 135 mojo::InterfaceRequest<mojo::Decryptor> decryptor) { | 130 mojo::InterfaceRequest<mojo::Decryptor> decryptor) { |
| 136 NOTIMPLEMENTED(); | 131 NOTIMPLEMENTED(); |
| 137 } | 132 } |
| 138 | 133 |
| 139 CdmContext* MojoCdmService::GetCdmContext() { | 134 CdmContext* MojoCdmService::GetCdmContext() { |
| 140 return cdm_->GetCdmContext(); | 135 return cdm_->GetCdmContext(); |
| 141 } | 136 } |
| 142 | 137 |
| 138 void MojoCdmService::OnCdmCreated(int cdm_id, |
| 139 scoped_ptr<SimpleMojoCdmPromise> promise, |
| 140 scoped_ptr<MediaKeys> cdm, |
| 141 const std::string& error_message) { |
| 142 // TODO(xhwang): This should not happen when KeySystemInfo is properly |
| 143 // populated. See http://crbug.com/469366 |
| 144 if (!cdm) { |
| 145 promise->reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, error_message); |
| 146 return; |
| 147 } |
| 148 |
| 149 cdm_ = cdm.Pass(); |
| 150 cdm_id_ = cdm_id; |
| 151 context_->RegisterCdm(cdm_id_, this); |
| 152 promise->resolve(); |
| 153 } |
| 154 |
| 143 void MojoCdmService::OnSessionMessage(const std::string& session_id, | 155 void MojoCdmService::OnSessionMessage(const std::string& session_id, |
| 144 MediaKeys::MessageType message_type, | 156 MediaKeys::MessageType message_type, |
| 145 const std::vector<uint8_t>& message, | 157 const std::vector<uint8_t>& message, |
| 146 const GURL& legacy_destination_url) { | 158 const GURL& legacy_destination_url) { |
| 147 DVLOG(2) << __FUNCTION__; | 159 DVLOG(2) << __FUNCTION__; |
| 148 client_->OnSessionMessage(session_id, | 160 client_->OnSessionMessage(session_id, |
| 149 static_cast<mojo::CdmMessageType>(message_type), | 161 static_cast<mojo::CdmMessageType>(message_type), |
| 150 mojo::Array<uint8_t>::From(message), | 162 mojo::Array<uint8_t>::From(message), |
| 151 mojo::String::From(legacy_destination_url)); | 163 mojo::String::From(legacy_destination_url)); |
| 152 } | 164 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 179 MediaKeys::Exception exception, | 191 MediaKeys::Exception exception, |
| 180 uint32_t system_code, | 192 uint32_t system_code, |
| 181 const std::string& error_message) { | 193 const std::string& error_message) { |
| 182 DVLOG(2) << __FUNCTION__; | 194 DVLOG(2) << __FUNCTION__; |
| 183 client_->OnLegacySessionError(session_id, | 195 client_->OnLegacySessionError(session_id, |
| 184 static_cast<mojo::CdmException>(exception), | 196 static_cast<mojo::CdmException>(exception), |
| 185 system_code, error_message); | 197 system_code, error_message); |
| 186 } | 198 } |
| 187 | 199 |
| 188 } // namespace media | 200 } // namespace media |
| OLD | NEW |