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

Side by Side Diff: content/renderer/pepper/content_decryptor_delegate.cc

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cdm_promise template Created 6 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/pepper/content_decryptor_delegate.h" 5 #include "content/renderer/pepper/content_decryptor_delegate.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
11 #include "content/renderer/pepper/ppb_buffer_impl.h" 11 #include "content/renderer/pepper/ppb_buffer_impl.h"
12 #include "media/base/audio_buffer.h" 12 #include "media/base/audio_buffer.h"
13 #include "media/base/audio_decoder_config.h" 13 #include "media/base/audio_decoder_config.h"
14 #include "media/base/bind_to_current_loop.h" 14 #include "media/base/bind_to_current_loop.h"
15 #include "media/base/cdm_promise.h"
15 #include "media/base/channel_layout.h" 16 #include "media/base/channel_layout.h"
16 #include "media/base/data_buffer.h" 17 #include "media/base/data_buffer.h"
17 #include "media/base/decoder_buffer.h" 18 #include "media/base/decoder_buffer.h"
18 #include "media/base/decrypt_config.h" 19 #include "media/base/decrypt_config.h"
19 #include "media/base/video_decoder_config.h" 20 #include "media/base/video_decoder_config.h"
20 #include "media/base/video_frame.h" 21 #include "media/base/video_frame.h"
21 #include "media/base/video_util.h" 22 #include "media/base/video_util.h"
22 #include "ppapi/shared_impl/scoped_pp_resource.h" 23 #include "ppapi/shared_impl/scoped_pp_resource.h"
23 #include "ppapi/shared_impl/var.h" 24 #include "ppapi/shared_impl/var.h"
24 #include "ppapi/shared_impl/var_tracker.h" 25 #include "ppapi/shared_impl/var_tracker.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_S16: 239 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_S16:
239 return media::kSampleFormatPlanarS16; 240 return media::kSampleFormatPlanarS16;
240 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_F32: 241 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_F32:
241 return media::kSampleFormatPlanarF32; 242 return media::kSampleFormatPlanarF32;
242 default: 243 default:
243 NOTREACHED(); 244 NOTREACHED();
244 return media::kUnknownSampleFormat; 245 return media::kUnknownSampleFormat;
245 } 246 }
246 } 247 }
247 248
249 PP_SessionType MediaSessionTypeToPpSessionType(
250 media::MediaKeys::SessionType session_type) {
251 switch (session_type) {
252 case media::MediaKeys::SESSION_TYPE_TEMPORARY:
253 return PP_SESSIONTYPE_TEMPORARY;
254 case media::MediaKeys::SESSION_TYPE_PERSISTENT:
255 return PP_SESSIONTYPE_PERSISTENT;
256 default:
257 NOTREACHED();
258 return PP_SESSIONTYPE_TEMPORARY;
259 }
260 }
261
262 media::MediaKeys::MediaKeysException PpExceptionTypeToMediaException(
263 PP_ExceptionCodeType exception_code) {
264 switch (exception_code) {
265 case PP_EXCEPTIONCODETYPE_INDEXSIZEERROR:
266 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_INDEX_SIZE_ERROR;
267 case PP_EXCEPTIONCODETYPE_HIERARCHYREQUESTERROR:
268 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_HIERARCHY_REQUEST_ERROR;
269 case PP_EXCEPTIONCODETYPE_WRONGDOCUMENTERROR:
270 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_WRONG_DOCUMENT_ERROR;
271 case PP_EXCEPTIONCODETYPE_INVALIDCHARACTERERROR:
272 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_INVALID_CHARACTER_ERROR;
273 case PP_EXCEPTIONCODETYPE_NOMODIFICATIONALLOWEDERROR:
274 return media::MediaKeys::
275 MEDIA_KEYS_EXCEPTION_NO_MODIFICATION_ALLOWED_ERROR;
276 case PP_EXCEPTIONCODETYPE_NOTFOUNDERROR:
277 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_NOT_FOUND_ERROR;
278 case PP_EXCEPTIONCODETYPE_NOTSUPPORTEDERROR:
279 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_NOT_SUPPORTED_ERROR;
280 case PP_EXCEPTIONCODETYPE_INVALIDSTATEERROR:
281 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_INVALID_STATE_ERROR;
282 case PP_EXCEPTIONCODETYPE_SYNTAXERROR:
283 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_SYNTAX_ERROR;
284 case PP_EXCEPTIONCODETYPE_INVALIDMODIFICATIONERROR:
285 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_INVALID_MODIFICATION_ERROR;
286 case PP_EXCEPTIONCODETYPE_NAMESPACEERROR:
287 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_NAMESPACE_ERROR;
288 case PP_EXCEPTIONCODETYPE_INVALIDACCESSERROR:
289 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_INVALID_ACCESS_ERROR;
290 case PP_EXCEPTIONCODETYPE_SECURITYERROR:
291 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_SECURITY_ERROR;
292 case PP_EXCEPTIONCODETYPE_NETWORKERROR:
293 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_NETWORK_ERROR;
294 case PP_EXCEPTIONCODETYPE_ABORTERROR:
295 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_ABORT_ERROR;
296 case PP_EXCEPTIONCODETYPE_URLMISMATCHERROR:
297 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_URL_MISMATCH_ERROR;
298 case PP_EXCEPTIONCODETYPE_QUOTAEXCEEDEDERROR:
299 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_QUOTA_EXCEEDED_ERROR;
300 case PP_EXCEPTIONCODETYPE_TIMEOUTERROR:
301 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_TIMEOUT_ERROR;
302 case PP_EXCEPTIONCODETYPE_INVALIDNODETYPEERROR:
303 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_INVALID_NODE_TYPE_ERROR;
304 case PP_EXCEPTIONCODETYPE_DATACLONEERROR:
305 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_DATA_CLONE_ERROR;
306 case PP_EXCEPTIONCODETYPE_ENCODINGERROR:
307 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_ENCODING_ERROR;
308 case PP_EXCEPTIONCODETYPE_NOTREADABLEERROR:
309 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_NOT_READABLE_ERROR;
310 case PP_EXCEPTIONCODETYPE_DATAERROR:
311 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_DATA_ERROR;
312 case PP_EXCEPTIONCODETYPE_OPERATIONERROR:
313 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_OPERATION_ERROR;
314 case PP_EXCEPTIONCODETYPE_VERSIONERROR:
315 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_VERSION_ERROR;
316 case PP_EXCEPTIONCODETYPE_UNKNOWNERROR:
317 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_UNKNOWN_ERROR;
318 case PP_EXCEPTIONCODETYPE_CLIENTERROR:
319 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_CLIENT_ERROR;
320 case PP_EXCEPTIONCODETYPE_OUTPUTERROR:
321 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_OUTPUT_ERROR;
322 default:
323 NOTREACHED();
324 return media::MediaKeys::MEDIA_KEYS_EXCEPTION_SECURITY_ERROR;
325 }
326 }
327
248 } // namespace 328 } // namespace
249 329
250 ContentDecryptorDelegate::ContentDecryptorDelegate( 330 ContentDecryptorDelegate::ContentDecryptorDelegate(
251 PP_Instance pp_instance, 331 PP_Instance pp_instance,
252 const PPP_ContentDecryptor_Private* plugin_decryption_interface) 332 const PPP_ContentDecryptor_Private* plugin_decryption_interface)
253 : pp_instance_(pp_instance), 333 : pp_instance_(pp_instance),
254 plugin_decryption_interface_(plugin_decryption_interface), 334 plugin_decryption_interface_(plugin_decryption_interface),
255 next_decryption_request_id_(1), 335 next_decryption_request_id_(1),
256 audio_samples_per_second_(0), 336 audio_samples_per_second_(0),
257 audio_channel_count_(0), 337 audio_channel_count_(0),
258 audio_channel_layout_(media::CHANNEL_LAYOUT_NONE), 338 audio_channel_layout_(media::CHANNEL_LAYOUT_NONE),
339 next_promise_id_(0),
259 weak_ptr_factory_(this) { 340 weak_ptr_factory_(this) {
260 weak_this_ = weak_ptr_factory_.GetWeakPtr(); 341 weak_this_ = weak_ptr_factory_.GetWeakPtr();
261 } 342 }
262 343
263 ContentDecryptorDelegate::~ContentDecryptorDelegate() { 344 ContentDecryptorDelegate::~ContentDecryptorDelegate() {
264 SatisfyAllPendingCallbacksOnError(); 345 SatisfyAllPendingCallbacksOnError();
265 } 346 }
266 347
267 void ContentDecryptorDelegate::Initialize( 348 void ContentDecryptorDelegate::Initialize(
268 const std::string& key_system, 349 const std::string& key_system,
269 const media::SessionCreatedCB& session_created_cb,
270 const media::SessionMessageCB& session_message_cb, 350 const media::SessionMessageCB& session_message_cb,
271 const media::SessionReadyCB& session_ready_cb, 351 const media::SessionReadyCB& session_ready_cb,
272 const media::SessionClosedCB& session_closed_cb, 352 const media::SessionClosedCB& session_closed_cb,
273 const media::SessionErrorCB& session_error_cb, 353 const media::SessionErrorCB& session_error_cb,
274 const base::Closure& fatal_plugin_error_cb) { 354 const base::Closure& fatal_plugin_error_cb) {
275 DCHECK(!key_system.empty()); 355 DCHECK(!key_system.empty());
276 DCHECK(key_system_.empty()); 356 DCHECK(key_system_.empty());
277 key_system_ = key_system; 357 key_system_ = key_system;
278 358
279 session_created_cb_ = session_created_cb;
280 session_message_cb_ = session_message_cb; 359 session_message_cb_ = session_message_cb;
281 session_ready_cb_ = session_ready_cb; 360 session_ready_cb_ = session_ready_cb;
282 session_closed_cb_ = session_closed_cb; 361 session_closed_cb_ = session_closed_cb;
283 session_error_cb_ = session_error_cb; 362 session_error_cb_ = session_error_cb;
284 fatal_plugin_error_cb_ = fatal_plugin_error_cb; 363 fatal_plugin_error_cb_ = fatal_plugin_error_cb;
285 364
286 plugin_decryption_interface_->Initialize( 365 plugin_decryption_interface_->Initialize(
287 pp_instance_, StringVar::StringToPPVar(key_system_)); 366 pp_instance_, StringVar::StringToPPVar(key_system_));
288 } 367 }
289 368
290 void ContentDecryptorDelegate::InstanceCrashed() { 369 void ContentDecryptorDelegate::InstanceCrashed() {
291 fatal_plugin_error_cb_.Run(); 370 fatal_plugin_error_cb_.Run();
292 SatisfyAllPendingCallbacksOnError(); 371 SatisfyAllPendingCallbacksOnError();
293 } 372 }
294 373
295 bool ContentDecryptorDelegate::CreateSession(uint32 session_id, 374 void ContentDecryptorDelegate::CreateSession(
296 const std::string& content_type, 375 const std::string& init_data_type,
297 const uint8* init_data, 376 const uint8* init_data,
298 int init_data_length) { 377 int init_data_length,
378 media::MediaKeys::SessionType session_type,
379 scoped_ptr<media::CdmPromise<std::string> > promise) {
380 uint32_t promise_id = SaveSessionPromise(promise.Pass());
299 PP_Var init_data_array = 381 PP_Var init_data_array =
300 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( 382 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
301 init_data_length, init_data); 383 init_data_length, init_data);
302
303 plugin_decryption_interface_->CreateSession( 384 plugin_decryption_interface_->CreateSession(
304 pp_instance_, 385 pp_instance_,
305 session_id, 386 promise_id,
306 StringVar::StringToPPVar(content_type), 387 StringVar::StringToPPVar(init_data_type),
307 init_data_array); 388 init_data_array,
308 return true; 389 MediaSessionTypeToPpSessionType(session_type));
309 } 390 }
310 391
311 void ContentDecryptorDelegate::LoadSession(uint32 session_id, 392 void ContentDecryptorDelegate::LoadSession(
312 const std::string& web_session_id) { 393 const std::string& web_session_id,
394 scoped_ptr<media::CdmPromise<std::string> > promise) {
395 uint32_t promise_id = SaveSessionPromise(promise.Pass());
313 plugin_decryption_interface_->LoadSession( 396 plugin_decryption_interface_->LoadSession(
314 pp_instance_, session_id, StringVar::StringToPPVar(web_session_id)); 397 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id));
315 } 398 }
316 399
317 bool ContentDecryptorDelegate::UpdateSession(uint32 session_id, 400 void ContentDecryptorDelegate::UpdateSession(
318 const uint8* response, 401 const std::string& web_session_id,
319 int response_length) { 402 const uint8* response,
403 int response_length,
404 scoped_ptr<media::CdmPromise<void> > promise) {
405 uint32_t promise_id = SaveVoidPromise(promise.Pass());
320 PP_Var response_array = 406 PP_Var response_array =
321 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( 407 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
322 response_length, response); 408 response_length, response);
323 plugin_decryption_interface_->UpdateSession( 409 plugin_decryption_interface_->UpdateSession(
324 pp_instance_, session_id, response_array); 410 pp_instance_,
325 return true; 411 promise_id,
412 StringVar::StringToPPVar(web_session_id),
413 response_array);
326 } 414 }
327 415
328 bool ContentDecryptorDelegate::ReleaseSession(uint32 session_id) { 416 void ContentDecryptorDelegate::ReleaseSession(
329 plugin_decryption_interface_->ReleaseSession(pp_instance_, session_id); 417 const std::string& web_session_id,
330 return true; 418 scoped_ptr<media::CdmPromise<void> > promise) {
419 uint32_t promise_id = SaveVoidPromise(promise.Pass());
420 plugin_decryption_interface_->ReleaseSession(
421 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id));
331 } 422 }
332 423
333 // TODO(xhwang): Remove duplication of code in Decrypt(), 424 // TODO(xhwang): Remove duplication of code in Decrypt(),
334 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). 425 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo().
335 bool ContentDecryptorDelegate::Decrypt( 426 bool ContentDecryptorDelegate::Decrypt(
336 Decryptor::StreamType stream_type, 427 Decryptor::StreamType stream_type,
337 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, 428 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
338 const Decryptor::DecryptCB& decrypt_cb) { 429 const Decryptor::DecryptCB& decrypt_cb) {
339 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; 430 DVLOG(3) << "Decrypt() - stream_type: " << stream_type;
340 431
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 // buffer. 657 // buffer.
567 video_decode_cb_.Set(request_id, video_decode_cb); 658 video_decode_cb_.Set(request_id, video_decode_cb);
568 659
569 // TODO(tomfinegan): Need to get stream type from media stack. 660 // TODO(tomfinegan): Need to get stream type from media stack.
570 ScopedPPResource pp_resource(encrypted_resource.get()); 661 ScopedPPResource pp_resource(encrypted_resource.get());
571 plugin_decryption_interface_->DecryptAndDecode( 662 plugin_decryption_interface_->DecryptAndDecode(
572 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); 663 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info);
573 return true; 664 return true;
574 } 665 }
575 666
576 void ContentDecryptorDelegate::OnSessionCreated(uint32 session_id, 667 void ContentDecryptorDelegate::OnPromiseResolved(uint32 promise_id) {
577 PP_Var web_session_id_var) { 668 scoped_ptr<media::CdmPromise<void> > promise =
578 if (session_created_cb_.is_null()) 669 RetrieveVoidPromise(promise_id);
579 return; 670 promise->resolve();
580
581 StringVar* session_id_string = StringVar::FromPPVar(web_session_id_var);
582
583 if (!session_id_string) {
584 OnSessionError(session_id, media::MediaKeys::kUnknownError, 0);
585 return;
586 }
587
588 session_created_cb_.Run(session_id, session_id_string->value());
589 } 671 }
590 672
591 void ContentDecryptorDelegate::OnSessionMessage(uint32 session_id, 673 void ContentDecryptorDelegate::OnPromiseResolvedWithSession(
674 uint32 promise_id,
675 PP_Var web_session_id_var) {
676 scoped_ptr<media::CdmPromise<std::string> > promise =
677 RetrieveSessionPromise(promise_id);
678
679 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var);
680 DCHECK(web_session_id);
681
682 promise->resolve(web_session_id->value());
683 }
684
685 void ContentDecryptorDelegate::OnPromiseRejected(
686 uint32 promise_id,
687 PP_ExceptionCodeType exception_code,
688 uint32 system_code,
689 PP_Var error_description_var) {
690 StringVar* error_description = StringVar::FromPPVar(error_description_var);
691 DCHECK(error_description);
692
693 scoped_ptr<media::CdmPromise<std::string> > promise =
694 RetrieveSessionPromise(promise_id);
695 if (promise) {
696 promise->reject(PpExceptionTypeToMediaException(exception_code),
697 system_code,
698 error_description->value());
699 } else {
700 scoped_ptr<media::CdmPromise<void> > promise =
701 RetrieveVoidPromise(promise_id);
702 promise->reject(PpExceptionTypeToMediaException(exception_code),
703 system_code,
704 error_description->value());
705 }
706 }
707
708 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id_var,
592 PP_Var message_var, 709 PP_Var message_var,
593 PP_Var default_url_var) { 710 PP_Var destination_url_var) {
594 if (session_message_cb_.is_null()) 711 if (session_message_cb_.is_null())
595 return; 712 return;
596 713
714 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var);
715 DCHECK(web_session_id);
716
597 ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message_var); 717 ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message_var);
598
599 std::vector<uint8> message; 718 std::vector<uint8> message;
600 if (message_array_buffer) { 719 if (message_array_buffer) {
601 const uint8* data = static_cast<const uint8*>(message_array_buffer->Map()); 720 const uint8* data = static_cast<const uint8*>(message_array_buffer->Map());
602 message.assign(data, data + message_array_buffer->ByteLength()); 721 message.assign(data, data + message_array_buffer->ByteLength());
603 } 722 }
604 723
605 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); 724 StringVar* destination_url_string = StringVar::FromPPVar(destination_url_var);
725 DCHECK(destination_url_string);
606 726
607 if (!default_url_string) { 727 session_message_cb_.Run(
608 OnSessionError(session_id, media::MediaKeys::kUnknownError, 0); 728 web_session_id->value(), message, destination_url_string->value());
609 return;
610 }
611
612 session_message_cb_.Run(session_id, message, default_url_string->value());
613 } 729 }
614 730
615 void ContentDecryptorDelegate::OnSessionReady(uint32 session_id) { 731 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id_var) {
616 if (session_ready_cb_.is_null()) 732 if (session_ready_cb_.is_null())
617 return; 733 return;
618 734
619 session_ready_cb_.Run(session_id); 735 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var);
736 DCHECK(web_session_id);
737
738 session_ready_cb_.Run(web_session_id->value());
620 } 739 }
621 740
622 void ContentDecryptorDelegate::OnSessionClosed(uint32 session_id) { 741 void ContentDecryptorDelegate::OnSessionClosed(PP_Var web_session_id_var) {
623 if (session_closed_cb_.is_null()) 742 if (session_closed_cb_.is_null())
624 return; 743 return;
625 744
626 session_closed_cb_.Run(session_id); 745 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var);
746 DCHECK(web_session_id);
747
748 session_closed_cb_.Run(web_session_id->value());
627 } 749 }
628 750
629 void ContentDecryptorDelegate::OnSessionError(uint32 session_id, 751 void ContentDecryptorDelegate::OnSessionError(
630 int32_t media_error, 752 PP_Var web_session_id_var,
631 uint32_t system_code) { 753 PP_ExceptionCodeType exception_code,
754 uint32 system_code,
755 PP_Var error_description_var) {
632 if (session_error_cb_.is_null()) 756 if (session_error_cb_.is_null())
633 return; 757 return;
634 758
635 session_error_cb_.Run(session_id, 759 StringVar* web_session_id = StringVar::FromPPVar(web_session_id_var);
636 static_cast<media::MediaKeys::KeyError>(media_error), 760 DCHECK(web_session_id);
637 system_code); 761
762 StringVar* error_description = StringVar::FromPPVar(error_description_var);
763 DCHECK(error_description);
764
765 session_error_cb_.Run(web_session_id->value(),
766 PpExceptionTypeToMediaException(exception_code),
767 system_code,
768 error_description->value());
638 } 769 }
639 770
640 void ContentDecryptorDelegate::DecoderInitializeDone( 771 void ContentDecryptorDelegate::DecoderInitializeDone(
641 PP_DecryptorStreamType decoder_type, 772 PP_DecryptorStreamType decoder_type,
642 uint32_t request_id, 773 uint32_t request_id,
643 PP_Bool success) { 774 PP_Bool success) {
644 if (decoder_type == PP_DECRYPTORSTREAMTYPE_AUDIO) { 775 if (decoder_type == PP_DECRYPTORSTREAMTYPE_AUDIO) {
645 // If the request ID is not valid or does not match what's saved, do 776 // If the request ID is not valid or does not match what's saved, do
646 // nothing. 777 // nothing.
647 if (request_id == 0 || !audio_decoder_init_cb_.Matches(request_id)) 778 if (request_id == 0 || !audio_decoder_init_cb_.Matches(request_id))
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 frame_count)); 1162 frame_count));
1032 frames->push_back(frame); 1163 frames->push_back(frame);
1033 1164
1034 cur += frame_size; 1165 cur += frame_size;
1035 bytes_left -= frame_size; 1166 bytes_left -= frame_size;
1036 } while (bytes_left > 0); 1167 } while (bytes_left > 0);
1037 1168
1038 return true; 1169 return true;
1039 } 1170 }
1040 1171
1041 void ContentDecryptorDelegate::SatisfyAllPendingCallbacksOnError() { 1172 void ContentDecryptorDelegate::SatisfyAllPendingCallbacksOnError() {
jrummell 2014/05/08 23:37:46 Need to reject any pending promises here.
jrummell 2014/05/09 00:55:23 Done.
1042 if (!audio_decoder_init_cb_.is_null()) 1173 if (!audio_decoder_init_cb_.is_null())
1043 audio_decoder_init_cb_.ResetAndReturn().Run(false); 1174 audio_decoder_init_cb_.ResetAndReturn().Run(false);
1044 1175
1045 if (!video_decoder_init_cb_.is_null()) 1176 if (!video_decoder_init_cb_.is_null())
1046 video_decoder_init_cb_.ResetAndReturn().Run(false); 1177 video_decoder_init_cb_.ResetAndReturn().Run(false);
1047 1178
1048 audio_input_resource_ = NULL; 1179 audio_input_resource_ = NULL;
1049 video_input_resource_ = NULL; 1180 video_input_resource_ = NULL;
1050 1181
1051 if (!audio_decrypt_cb_.is_null()) 1182 if (!audio_decrypt_cb_.is_null())
1052 audio_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); 1183 audio_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL);
1053 1184
1054 if (!video_decrypt_cb_.is_null()) 1185 if (!video_decrypt_cb_.is_null())
1055 video_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); 1186 video_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL);
1056 1187
1057 if (!audio_decode_cb_.is_null()) { 1188 if (!audio_decode_cb_.is_null()) {
1058 const media::Decryptor::AudioBuffers empty_frames; 1189 const media::Decryptor::AudioBuffers empty_frames;
1059 audio_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, 1190 audio_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError,
1060 empty_frames); 1191 empty_frames);
1061 } 1192 }
1062 1193
1063 if (!video_decode_cb_.is_null()) 1194 if (!video_decode_cb_.is_null())
1064 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); 1195 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL);
1065 } 1196 }
1066 1197
1198 uint32_t ContentDecryptorDelegate::SaveVoidPromise(
1199 scoped_ptr<media::CdmPromise<void> > promise) {
1200 uint32_t promise_id = ++next_promise_id_;
1201 void_promises_.insert(std::make_pair(promise_id, promise.release()));
1202 return promise_id;
1203 }
1204
1205 scoped_ptr<media::CdmPromise<void> >
1206 ContentDecryptorDelegate::RetrieveVoidPromise(uint32_t promise_id) {
1207 std::map<uint32_t, media::CdmPromise<void>*>::iterator it =
1208 void_promises_.find(promise_id);
1209 if (it == void_promises_.end())
1210 return scoped_ptr<media::CdmPromise<void> >();
1211 scoped_ptr<media::CdmPromise<void> > result(it->second);
1212 void_promises_.erase(it);
1213 return result.Pass();
1214 }
1215
1216 uint32_t ContentDecryptorDelegate::SaveSessionPromise(
1217 scoped_ptr<media::CdmPromise<std::string> > promise) {
1218 uint32_t promise_id = ++next_promise_id_;
1219 session_promises_.insert(std::make_pair(promise_id, promise.release()));
1220 return promise_id;
1221 }
1222
1223 scoped_ptr<media::CdmPromise<std::string> >
1224 ContentDecryptorDelegate::RetrieveSessionPromise(uint32_t promise_id) {
1225 std::map<uint32_t, media::CdmPromise<std::string>*>::iterator it =
1226 session_promises_.find(promise_id);
1227 if (it == session_promises_.end())
1228 return scoped_ptr<media::CdmPromise<std::string> >();
1229 scoped_ptr<media::CdmPromise<std::string> > result(it->second);
1230 session_promises_.erase(it);
1231 return result.Pass();
1232 }
1233
1067 } // namespace content 1234 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698