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

Side by Side Diff: media/mojo/clients/mojo_cdm.cc

Issue 2411573002: media: Use new wrapper types for media mojo interfaces (Closed)
Patch Set: comments addressed Created 4 years, 2 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
« no previous file with comments | « media/mojo/clients/mojo_cdm.h ('k') | media/mojo/clients/mojo_decryptor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/mojo/clients/mojo_cdm.h" 5 #include "media/mojo/clients/mojo_cdm.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 "Mojo CDM creation failed."); 133 "Mojo CDM creation failed.");
134 pending_init_promise_.reset(); 134 pending_init_promise_.reset();
135 } 135 }
136 136
137 void MojoCdm::SetServerCertificate(const std::vector<uint8_t>& certificate, 137 void MojoCdm::SetServerCertificate(const std::vector<uint8_t>& certificate,
138 std::unique_ptr<SimpleCdmPromise> promise) { 138 std::unique_ptr<SimpleCdmPromise> promise) {
139 DVLOG(2) << __FUNCTION__; 139 DVLOG(2) << __FUNCTION__;
140 DCHECK(thread_checker_.CalledOnValidThread()); 140 DCHECK(thread_checker_.CalledOnValidThread());
141 141
142 remote_cdm_->SetServerCertificate( 142 remote_cdm_->SetServerCertificate(
143 mojo::Array<uint8_t>::From(certificate), 143 certificate, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult,
144 base::Bind(&MojoCdm::OnPromiseResult<>, base::Unretained(this), 144 base::Unretained(this), base::Passed(&promise)));
145 base::Passed(&promise)));
146 } 145 }
147 146
148 void MojoCdm::CreateSessionAndGenerateRequest( 147 void MojoCdm::CreateSessionAndGenerateRequest(
149 SessionType session_type, 148 SessionType session_type,
150 EmeInitDataType init_data_type, 149 EmeInitDataType init_data_type,
151 const std::vector<uint8_t>& init_data, 150 const std::vector<uint8_t>& init_data,
152 std::unique_ptr<NewSessionCdmPromise> promise) { 151 std::unique_ptr<NewSessionCdmPromise> promise) {
153 DVLOG(2) << __FUNCTION__; 152 DVLOG(2) << __FUNCTION__;
154 DCHECK(thread_checker_.CalledOnValidThread()); 153 DCHECK(thread_checker_.CalledOnValidThread());
155 154
156 remote_cdm_->CreateSessionAndGenerateRequest( 155 remote_cdm_->CreateSessionAndGenerateRequest(
157 static_cast<mojom::ContentDecryptionModule::SessionType>(session_type), 156 static_cast<mojom::ContentDecryptionModule::SessionType>(session_type),
158 static_cast<mojom::ContentDecryptionModule::InitDataType>(init_data_type), 157 static_cast<mojom::ContentDecryptionModule::InitDataType>(init_data_type),
159 mojo::Array<uint8_t>::From(init_data), 158 init_data, base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult,
160 base::Bind(&MojoCdm::OnPromiseResult<std::string>, base::Unretained(this), 159 base::Unretained(this), base::Passed(&promise)));
161 base::Passed(&promise)));
162 } 160 }
163 161
164 void MojoCdm::LoadSession(SessionType session_type, 162 void MojoCdm::LoadSession(SessionType session_type,
165 const std::string& session_id, 163 const std::string& session_id,
166 std::unique_ptr<NewSessionCdmPromise> promise) { 164 std::unique_ptr<NewSessionCdmPromise> promise) {
167 DVLOG(2) << __FUNCTION__; 165 DVLOG(2) << __FUNCTION__;
168 DCHECK(thread_checker_.CalledOnValidThread()); 166 DCHECK(thread_checker_.CalledOnValidThread());
169 167
170 remote_cdm_->LoadSession( 168 remote_cdm_->LoadSession(
171 static_cast<mojom::ContentDecryptionModule::SessionType>(session_type), 169 static_cast<mojom::ContentDecryptionModule::SessionType>(session_type),
172 session_id, base::Bind(&MojoCdm::OnPromiseResult<std::string>, 170 session_id, base::Bind(&MojoCdm::OnNewSessionCdmPromiseResult,
173 base::Unretained(this), base::Passed(&promise))); 171 base::Unretained(this), base::Passed(&promise)));
174 } 172 }
175 173
176 void MojoCdm::UpdateSession(const std::string& session_id, 174 void MojoCdm::UpdateSession(const std::string& session_id,
177 const std::vector<uint8_t>& response, 175 const std::vector<uint8_t>& response,
178 std::unique_ptr<SimpleCdmPromise> promise) { 176 std::unique_ptr<SimpleCdmPromise> promise) {
179 DVLOG(2) << __FUNCTION__; 177 DVLOG(2) << __FUNCTION__;
180 DCHECK(thread_checker_.CalledOnValidThread()); 178 DCHECK(thread_checker_.CalledOnValidThread());
181 179
182 remote_cdm_->UpdateSession( 180 remote_cdm_->UpdateSession(
183 session_id, mojo::Array<uint8_t>::From(response), 181 session_id, response,
184 base::Bind(&MojoCdm::OnPromiseResult<>, base::Unretained(this), 182 base::Bind(&MojoCdm::OnSimpleCdmPromiseResult, base::Unretained(this),
185 base::Passed(&promise))); 183 base::Passed(&promise)));
186 } 184 }
187 185
188 void MojoCdm::CloseSession(const std::string& session_id, 186 void MojoCdm::CloseSession(const std::string& session_id,
189 std::unique_ptr<SimpleCdmPromise> promise) { 187 std::unique_ptr<SimpleCdmPromise> promise) {
190 DVLOG(2) << __FUNCTION__; 188 DVLOG(2) << __FUNCTION__;
191 DCHECK(thread_checker_.CalledOnValidThread()); 189 DCHECK(thread_checker_.CalledOnValidThread());
192 190
193 remote_cdm_->CloseSession( 191 remote_cdm_->CloseSession(
194 session_id, base::Bind(&MojoCdm::OnPromiseResult<>, 192 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult,
195 base::Unretained(this), base::Passed(&promise))); 193 base::Unretained(this), base::Passed(&promise)));
196 } 194 }
197 195
198 void MojoCdm::RemoveSession(const std::string& session_id, 196 void MojoCdm::RemoveSession(const std::string& session_id,
199 std::unique_ptr<SimpleCdmPromise> promise) { 197 std::unique_ptr<SimpleCdmPromise> promise) {
200 DVLOG(2) << __FUNCTION__; 198 DVLOG(2) << __FUNCTION__;
201 DCHECK(thread_checker_.CalledOnValidThread()); 199 DCHECK(thread_checker_.CalledOnValidThread());
202 200
203 remote_cdm_->RemoveSession( 201 remote_cdm_->RemoveSession(
204 session_id, base::Bind(&MojoCdm::OnPromiseResult<>, 202 session_id, base::Bind(&MojoCdm::OnSimpleCdmPromiseResult,
205 base::Unretained(this), base::Passed(&promise))); 203 base::Unretained(this), base::Passed(&promise)));
206 } 204 }
207 205
208 CdmContext* MojoCdm::GetCdmContext() { 206 CdmContext* MojoCdm::GetCdmContext() {
209 DVLOG(2) << __FUNCTION__; 207 DVLOG(2) << __FUNCTION__;
210 return this; 208 return this;
211 } 209 }
212 210
213 media::Decryptor* MojoCdm::GetDecryptor() { 211 media::Decryptor* MojoCdm::GetDecryptor() {
214 base::AutoLock auto_lock(lock_); 212 base::AutoLock auto_lock(lock_);
(...skipping 14 matching lines...) Expand all
229 return decryptor_.get(); 227 return decryptor_.get();
230 } 228 }
231 229
232 int MojoCdm::GetCdmId() const { 230 int MojoCdm::GetCdmId() const {
233 base::AutoLock auto_lock(lock_); 231 base::AutoLock auto_lock(lock_);
234 // Can be called on a different thread. 232 // Can be called on a different thread.
235 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id_); 233 DCHECK_NE(CdmContext::kInvalidCdmId, cdm_id_);
236 return cdm_id_; 234 return cdm_id_;
237 } 235 }
238 236
239 void MojoCdm::OnSessionMessage(const mojo::String& session_id, 237 void MojoCdm::OnSessionMessage(const std::string& session_id,
240 mojom::CdmMessageType message_type, 238 mojom::CdmMessageType message_type,
241 mojo::Array<uint8_t> message) { 239 const std::vector<uint8_t>& message) {
242 DVLOG(2) << __FUNCTION__; 240 DVLOG(2) << __FUNCTION__;
243 DCHECK(thread_checker_.CalledOnValidThread()); 241 DCHECK(thread_checker_.CalledOnValidThread());
244 242
245 session_message_cb_.Run(session_id, 243 session_message_cb_.Run(
246 static_cast<MediaKeys::MessageType>(message_type), 244 session_id, static_cast<MediaKeys::MessageType>(message_type), message);
247 message.storage());
248 } 245 }
249 246
250 void MojoCdm::OnSessionClosed(const mojo::String& session_id) { 247 void MojoCdm::OnSessionClosed(const std::string& session_id) {
251 DVLOG(2) << __FUNCTION__; 248 DVLOG(2) << __FUNCTION__;
252 DCHECK(thread_checker_.CalledOnValidThread()); 249 DCHECK(thread_checker_.CalledOnValidThread());
253 250
254 session_closed_cb_.Run(session_id); 251 session_closed_cb_.Run(session_id);
255 } 252 }
256 253
257 void MojoCdm::OnSessionKeysChange( 254 void MojoCdm::OnSessionKeysChange(
258 const mojo::String& session_id, 255 const std::string& session_id,
259 bool has_additional_usable_key, 256 bool has_additional_usable_key,
260 mojo::Array<mojom::CdmKeyInformationPtr> keys_info) { 257 std::vector<mojom::CdmKeyInformationPtr> keys_info) {
261 DVLOG(2) << __FUNCTION__; 258 DVLOG(2) << __FUNCTION__;
262 DCHECK(thread_checker_.CalledOnValidThread()); 259 DCHECK(thread_checker_.CalledOnValidThread());
263 260
264 // TODO(jrummell): Handling resume playback should be done in the media 261 // TODO(jrummell): Handling resume playback should be done in the media
265 // player, not in the Decryptors. http://crbug.com/413413. 262 // player, not in the Decryptors. http://crbug.com/413413.
266 if (has_additional_usable_key) { 263 if (has_additional_usable_key) {
267 base::AutoLock auto_lock(lock_); 264 base::AutoLock auto_lock(lock_);
268 if (decryptor_) { 265 if (decryptor_) {
269 DCHECK(decryptor_task_runner_); 266 DCHECK(decryptor_task_runner_);
270 decryptor_task_runner_->PostTask( 267 decryptor_task_runner_->PostTask(
271 FROM_HERE, 268 FROM_HERE,
272 base::Bind(&MojoCdm::OnKeyAdded, weak_factory_.GetWeakPtr())); 269 base::Bind(&MojoCdm::OnKeyAdded, weak_factory_.GetWeakPtr()));
273 } 270 }
274 } 271 }
275 272
276 media::CdmKeysInfo key_data; 273 media::CdmKeysInfo key_data;
277 key_data.reserve(keys_info.size()); 274 key_data.reserve(keys_info.size());
278 for (size_t i = 0; i < keys_info.size(); ++i) { 275 for (size_t i = 0; i < keys_info.size(); ++i) {
279 key_data.push_back( 276 key_data.push_back(
280 keys_info[i].To<std::unique_ptr<media::CdmKeyInformation>>().release()); 277 keys_info[i].To<std::unique_ptr<media::CdmKeyInformation>>().release());
281 } 278 }
282 session_keys_change_cb_.Run(session_id, has_additional_usable_key, 279 session_keys_change_cb_.Run(session_id, has_additional_usable_key,
283 std::move(key_data)); 280 std::move(key_data));
284 } 281 }
285 282
286 void MojoCdm::OnSessionExpirationUpdate(const mojo::String& session_id, 283 void MojoCdm::OnSessionExpirationUpdate(const std::string& session_id,
287 double new_expiry_time_sec) { 284 double new_expiry_time_sec) {
288 DVLOG(2) << __FUNCTION__; 285 DVLOG(2) << __FUNCTION__;
289 DCHECK(thread_checker_.CalledOnValidThread()); 286 DCHECK(thread_checker_.CalledOnValidThread());
290 287
291 session_expiration_update_cb_.Run( 288 session_expiration_update_cb_.Run(
292 session_id, base::Time::FromDoubleT(new_expiry_time_sec)); 289 session_id, base::Time::FromDoubleT(new_expiry_time_sec));
293 } 290 }
294 291
295 void MojoCdm::OnCdmInitialized(mojom::CdmPromiseResultPtr result, 292 void MojoCdm::OnCdmInitialized(mojom::CdmPromiseResultPtr result,
296 int cdm_id, 293 int cdm_id,
(...skipping 21 matching lines...) Expand all
318 void MojoCdm::OnKeyAdded() { 315 void MojoCdm::OnKeyAdded() {
319 base::AutoLock auto_lock(lock_); 316 base::AutoLock auto_lock(lock_);
320 317
321 DCHECK(decryptor_task_runner_); 318 DCHECK(decryptor_task_runner_);
322 DCHECK(decryptor_task_runner_->BelongsToCurrentThread()); 319 DCHECK(decryptor_task_runner_->BelongsToCurrentThread());
323 DCHECK(decryptor_); 320 DCHECK(decryptor_);
324 321
325 decryptor_->OnKeyAdded(); 322 decryptor_->OnKeyAdded();
326 } 323 }
327 324
325 void MojoCdm::OnSimpleCdmPromiseResult(
326 std::unique_ptr<SimpleCdmPromise> promise,
327 mojom::CdmPromiseResultPtr result) {
328 if (result->success)
329 promise->resolve();
330 else
331 RejectPromise(std::move(promise), std::move(result));
332 }
333
334 void MojoCdm::OnNewSessionCdmPromiseResult(
335 std::unique_ptr<NewSessionCdmPromise> promise,
336 mojom::CdmPromiseResultPtr result,
337 const std::string& session_id) {
338 if (result->success)
339 promise->resolve(session_id);
340 else
341 RejectPromise(std::move(promise), std::move(result));
342 }
343
328 } // namespace media 344 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/clients/mojo_cdm.h ('k') | media/mojo/clients/mojo_decryptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698