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 CdmFactory* cdm_factory, | |
25 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) | 26 mojo::InterfaceRequest<mojo::ContentDecryptionModule> request) |
26 : binding_(this, request.Pass()), | 27 : binding_(this, request.Pass()), |
27 context_(context), | 28 context_(context), |
29 cdm_factory_(cdm_factory), | |
28 cdm_id_(CdmContext::kInvalidCdmId), | 30 cdm_id_(CdmContext::kInvalidCdmId), |
29 weak_factory_(this) { | 31 weak_factory_(this) { |
32 DCHECK(context_); | |
33 DCHECK(cdm_factory_); | |
30 } | 34 } |
31 | 35 |
32 MojoCdmService::~MojoCdmService() { | 36 MojoCdmService::~MojoCdmService() { |
33 if (cdm_id_ != CdmContext::kInvalidCdmId) | 37 if (cdm_id_ != CdmContext::kInvalidCdmId) |
34 context_->UnregisterCdm(cdm_id_); | 38 context_->UnregisterCdm(cdm_id_); |
35 } | 39 } |
36 | 40 |
37 void MojoCdmService::SetClient(mojo::ContentDecryptionModuleClientPtr client) { | 41 void MojoCdmService::SetClient(mojo::ContentDecryptionModuleClientPtr client) { |
38 client_ = client.Pass(); | 42 client_ = client.Pass(); |
39 } | 43 } |
40 | 44 |
41 void MojoCdmService::Initialize( | 45 void MojoCdmService::Initialize( |
42 const mojo::String& key_system, | 46 const mojo::String& key_system, |
43 const mojo::String& security_origin, | 47 const mojo::String& security_origin, |
44 int32_t cdm_id, | 48 int32_t cdm_id, |
45 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { | 49 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { |
46 DVLOG(1) << __FUNCTION__ << ": " << key_system; | 50 DVLOG(1) << __FUNCTION__ << ": " << key_system; |
47 DCHECK(!cdm_); | 51 DCHECK(!cdm_); |
48 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id); | 52 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id); |
49 | 53 |
50 SimpleMojoCdmPromise promise(callback); | 54 base::WeakPtr<MojoCdmService> weak_this = weak_factory_.GetWeakPtr(); |
ddorwin
2015/07/09 18:13:03
Totally optional, but I wonder if "auto" makes sen
xhwang
2015/07/09 21:16:31
Done.
| |
51 | 55 cdm_factory_->Create( |
52 // Only AesDecryptor is supported. | 56 key_system, GURL(security_origin), CdmConfig(), |
ddorwin
2015/07/09 18:13:03
TODO: Something about the config?
xhwang
2015/07/09 21:16:31
This will be fixed this week: https://codereview.c
| |
53 // TODO(xhwang): Use a CdmFactory to create the CDM here. See | 57 base::Bind(&MojoCdmService::OnSessionMessage, weak_this), |
54 // http://crbug.com/495273 | 58 base::Bind(&MojoCdmService::OnSessionClosed, weak_this), |
55 if (CanUseAesDecryptor(key_system)) { | 59 base::Bind(&MojoCdmService::OnLegacySessionError, weak_this), |
56 base::WeakPtr<MojoCdmService> weak_this = weak_factory_.GetWeakPtr(); | 60 base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this), |
57 cdm_.reset(new AesDecryptor( | 61 base::Bind(&MojoCdmService::OnSessionExpirationUpdate, weak_this), |
58 GURL::EmptyGURL(), | 62 base::Bind( |
59 base::Bind(&MojoCdmService::OnSessionMessage, weak_this), | 63 &MojoCdmService::OnCdmCreated, weak_this, cdm_id, |
60 base::Bind(&MojoCdmService::OnSessionClosed, weak_this), | 64 base::Passed(make_scoped_ptr(new SimpleMojoCdmPromise(callback))))); |
61 base::Bind(&MojoCdmService::OnSessionKeysChange, weak_this))); | |
62 cdm_id_ = cdm_id; | |
63 context_->RegisterCdm(cdm_id_, this); | |
64 promise.resolve(); | |
65 } else { | |
66 // TODO(xhwang): This should not happen when KeySystemInfo is properly | |
67 // populated. See http://crbug.com/469366 | |
68 promise.reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not supported."); | |
69 } | |
70 } | 65 } |
71 | 66 |
72 // mojo::MediaRenderer implementation. | 67 // mojo::MediaRenderer implementation. |
73 void MojoCdmService::SetServerCertificate( | 68 void MojoCdmService::SetServerCertificate( |
74 mojo::Array<uint8_t> certificate_data, | 69 mojo::Array<uint8_t> certificate_data, |
75 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { | 70 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { |
76 DVLOG(2) << __FUNCTION__; | 71 DVLOG(2) << __FUNCTION__; |
77 cdm_->SetServerCertificate( | 72 cdm_->SetServerCertificate( |
78 certificate_data.storage(), | 73 certificate_data.storage(), |
79 make_scoped_ptr(new SimpleMojoCdmPromise(callback))); | 74 make_scoped_ptr(new SimpleMojoCdmPromise(callback))); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 | 126 |
132 void MojoCdmService::GetDecryptor( | 127 void MojoCdmService::GetDecryptor( |
133 mojo::InterfaceRequest<mojo::Decryptor> decryptor) { | 128 mojo::InterfaceRequest<mojo::Decryptor> decryptor) { |
134 NOTIMPLEMENTED(); | 129 NOTIMPLEMENTED(); |
135 } | 130 } |
136 | 131 |
137 CdmContext* MojoCdmService::GetCdmContext() { | 132 CdmContext* MojoCdmService::GetCdmContext() { |
138 return cdm_->GetCdmContext(); | 133 return cdm_->GetCdmContext(); |
139 } | 134 } |
140 | 135 |
136 void MojoCdmService::OnCdmCreated(int cdm_id, | |
137 scoped_ptr<SimpleMojoCdmPromise> promise, | |
138 scoped_ptr<MediaKeys> cdm, | |
139 const std::string& error_message) { | |
140 // TODO(xhwang): This should not happen when KeySystemInfo is properly | |
141 // populated. See http://crbug.com/469366 | |
142 if (!cdm) { | |
143 promise->reject(MediaKeys::NOT_SUPPORTED_ERROR, 0, error_message); | |
144 return; | |
145 } | |
146 | |
147 cdm_ = cdm.Pass(); | |
148 cdm_id_ = cdm_id; | |
149 context_->RegisterCdm(cdm_id_, this); | |
150 promise->resolve(); | |
151 } | |
152 | |
141 void MojoCdmService::OnSessionMessage(const std::string& session_id, | 153 void MojoCdmService::OnSessionMessage(const std::string& session_id, |
142 MediaKeys::MessageType message_type, | 154 MediaKeys::MessageType message_type, |
143 const std::vector<uint8_t>& message, | 155 const std::vector<uint8_t>& message, |
144 const GURL& legacy_destination_url) { | 156 const GURL& legacy_destination_url) { |
145 DVLOG(2) << __FUNCTION__; | 157 DVLOG(2) << __FUNCTION__; |
146 client_->OnSessionMessage(session_id, | 158 client_->OnSessionMessage(session_id, |
147 static_cast<mojo::CdmMessageType>(message_type), | 159 static_cast<mojo::CdmMessageType>(message_type), |
148 mojo::Array<uint8_t>::From(message), | 160 mojo::Array<uint8_t>::From(message), |
149 mojo::String::From(legacy_destination_url)); | 161 mojo::String::From(legacy_destination_url)); |
150 } | 162 } |
(...skipping 26 matching lines...) Expand all Loading... | |
177 MediaKeys::Exception exception, | 189 MediaKeys::Exception exception, |
178 uint32_t system_code, | 190 uint32_t system_code, |
179 const std::string& error_message) { | 191 const std::string& error_message) { |
180 DVLOG(2) << __FUNCTION__; | 192 DVLOG(2) << __FUNCTION__; |
181 client_->OnLegacySessionError(session_id, | 193 client_->OnLegacySessionError(session_id, |
182 static_cast<mojo::CdmException>(exception), | 194 static_cast<mojo::CdmException>(exception), |
183 system_code, error_message); | 195 system_code, error_message); |
184 } | 196 } |
185 | 197 |
186 } // namespace media | 198 } // namespace media |
OLD | NEW |