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

Side by Side Diff: media/cdm/ppapi/cdm_adapter.cc

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: latest CDM_5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/cdm/ppapi/cdm_adapter.h" 5 #include "media/cdm/ppapi/cdm_adapter.h"
6 6
7 #include "media/base/media_keys.h"
7 #include "media/cdm/ppapi/cdm_file_io_impl.h" 8 #include "media/cdm/ppapi/cdm_file_io_impl.h"
8 #include "media/cdm/ppapi/cdm_helpers.h" 9 #include "media/cdm/ppapi/cdm_helpers.h"
9 #include "media/cdm/ppapi/cdm_logging.h" 10 #include "media/cdm/ppapi/cdm_logging.h"
10 #include "media/cdm/ppapi/supported_cdm_versions.h" 11 #include "media/cdm/ppapi/supported_cdm_versions.h"
11 #include "ppapi/c/ppb_console.h" 12 #include "ppapi/c/ppb_console.h"
12 #include "ppapi/cpp/private/uma_private.h" 13 #include "ppapi/cpp/private/uma_private.h"
13 14
14 #if defined(CHECK_DOCUMENT_URL) 15 #if defined(CHECK_DOCUMENT_URL)
15 #include "ppapi/cpp/dev/url_util_dev.h" 16 #include "ppapi/cpp/dev/url_util_dev.h"
16 #include "ppapi/cpp/instance_handle.h" 17 #include "ppapi/cpp/instance_handle.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 case PP_DECRYPTORSTREAMTYPE_AUDIO: 205 case PP_DECRYPTORSTREAMTYPE_AUDIO:
205 return cdm::kStreamTypeAudio; 206 return cdm::kStreamTypeAudio;
206 case PP_DECRYPTORSTREAMTYPE_VIDEO: 207 case PP_DECRYPTORSTREAMTYPE_VIDEO:
207 return cdm::kStreamTypeVideo; 208 return cdm::kStreamTypeVideo;
208 } 209 }
209 210
210 PP_NOTREACHED(); 211 PP_NOTREACHED();
211 return cdm::kStreamTypeVideo; 212 return cdm::kStreamTypeVideo;
212 } 213 }
213 214
215 cdm::SessionType PpSessionTypeToCdmSessionType(PP_SessionType session_type) {
216 switch (session_type) {
217 case PP_SESSIONTYPE_TEMPORARY:
218 return cdm::kTemporary;
219 case PP_SESSIONTYPE_PERSISTENT:
220 return cdm::kPersistent;
221 default:
222 PP_NOTREACHED();
223 return cdm::kTemporary;
224 }
225 }
226
227 PP_ExceptionCodeType CdmExceptionTypeToPpExceptionType(cdm::Error error) {
228 switch (error) {
229 case cdm::kNoModificationAllowedError:
230 return PP_EXCEPTIONCODETYPE_NOMODIFICATIONALLOWEDERROR;
231 case cdm::kNotFoundError:
232 return PP_EXCEPTIONCODETYPE_NOTFOUNDERROR;
233 case cdm::kNotSupportedError:
234 return PP_EXCEPTIONCODETYPE_NOTSUPPORTEDERROR;
235 case cdm::kInvalidStateError:
236 return PP_EXCEPTIONCODETYPE_INVALIDSTATEERROR;
237 case cdm::kSyntaxError:
ddorwin 2014/05/13 22:44:02 I missed that this was still in CDM.h. I don't thi
jrummell 2014/05/15 22:38:09 Do you want it removed from cdm.h?
ddorwin 2014/05/15 23:15:32 Yes, please.
238 return PP_EXCEPTIONCODETYPE_SYNTAXERROR;
239 case cdm::kInvalidModificationError:
240 return PP_EXCEPTIONCODETYPE_INVALIDMODIFICATIONERROR;
241 case cdm::kInvalidAccessError:
242 return PP_EXCEPTIONCODETYPE_INVALIDACCESSERROR;
243 case cdm::kSecurityError:
244 return PP_EXCEPTIONCODETYPE_SECURITYERROR;
245 case cdm::kAbortError:
246 return PP_EXCEPTIONCODETYPE_ABORTERROR;
247 case cdm::kQuotaExceededError:
248 return PP_EXCEPTIONCODETYPE_QUOTAEXCEEDEDERROR;
249 case cdm::kTimeoutError:
250 return PP_EXCEPTIONCODETYPE_TIMEOUTERROR;
251 case cdm::kNotReadableError:
252 return PP_EXCEPTIONCODETYPE_NOTREADABLEERROR;
253 case cdm::kDataError:
254 return PP_EXCEPTIONCODETYPE_DATAERROR;
255 case cdm::kOperationError:
256 return PP_EXCEPTIONCODETYPE_OPERATIONERROR;
257 case cdm::kVersionError:
258 return PP_EXCEPTIONCODETYPE_VERSIONERROR;
259 case cdm::kUnknownError:
260 return PP_EXCEPTIONCODETYPE_UNKNOWNERROR;
261 case cdm::kClientError:
262 return PP_EXCEPTIONCODETYPE_CLIENTERROR;
263 case cdm::kOutputError:
264 return PP_EXCEPTIONCODETYPE_OUTPUTERROR;
265 default:
266 NOTREACHED();
267 return PP_EXCEPTIONCODETYPE_UNKNOWNERROR;
268 }
269 }
270
214 } // namespace 271 } // namespace
215 272
216 namespace media { 273 namespace media {
217 274
218 CdmAdapter::CdmAdapter(PP_Instance instance, pp::Module* module) 275 CdmAdapter::CdmAdapter(PP_Instance instance, pp::Module* module)
219 : pp::Instance(instance), 276 : pp::Instance(instance),
220 pp::ContentDecryptor_Private(this), 277 pp::ContentDecryptor_Private(this),
221 #if defined(OS_CHROMEOS) 278 #if defined(OS_CHROMEOS)
222 output_protection_(this), 279 output_protection_(this),
223 platform_verification_(this), 280 platform_verification_(this),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 340 }
284 #endif // defined(CHECK_DOCUMENT_URL) 341 #endif // defined(CHECK_DOCUMENT_URL)
285 342
286 if (!cdm_ && !CreateCdmInstance(key_system)) 343 if (!cdm_ && !CreateCdmInstance(key_system))
287 return; 344 return;
288 345
289 PP_DCHECK(cdm_); 346 PP_DCHECK(cdm_);
290 key_system_ = key_system; 347 key_system_ = key_system;
291 } 348 }
292 349
293 void CdmAdapter::CreateSession(uint32_t session_id, 350 void CdmAdapter::CreateSession(uint32_t promise_id,
294 const std::string& content_type, 351 const std::string& init_data_type,
295 pp::VarArrayBuffer init_data) { 352 pp::VarArrayBuffer init_data,
353 PP_SessionType session_type) {
296 // Initialize() doesn't report an error, so CreateSession() can be called 354 // Initialize() doesn't report an error, so CreateSession() can be called
ddorwin 2014/05/13 22:44:02 This should all be prevented now that we have Medi
jrummell 2014/05/15 22:38:09 Added TODO.
297 // even if Initialize() failed. 355 // even if Initialize() failed.
298 if (!cdm_) { 356 if (!cdm_) {
299 OnSessionError(session_id, cdm::kUnknownError, 0); 357 RejectPromise(promise_id,
358 cdm::kInvalidStateError,
359 0,
360 "CDM has not been initialized.");
300 return; 361 return;
301 } 362 }
302 363
303 cdm_->CreateSession(session_id, 364 cdm_->CreateSession(promise_id,
304 content_type.data(), 365 init_data_type.data(),
305 content_type.size(), 366 init_data_type.size(),
306 static_cast<const uint8_t*>(init_data.Map()), 367 static_cast<const uint8_t*>(init_data.Map()),
307 init_data.ByteLength()); 368 init_data.ByteLength(),
369 PpSessionTypeToCdmSessionType(session_type));
308 } 370 }
309 371
310 void CdmAdapter::LoadSession(uint32_t session_id, 372 void CdmAdapter::LoadSession(uint32_t promise_id,
311 const std::string& web_session_id) { 373 const std::string& web_session_id) {
312 // Initialize() doesn't report an error, so LoadSession() can be called 374 // Initialize() doesn't report an error, so LoadSession() can be called
ddorwin 2014/05/13 22:44:02 ditto
jrummell 2014/05/15 22:38:09 Done.
313 // even if Initialize() failed. 375 // even if Initialize() failed.
314 if (!cdm_) { 376 if (!cdm_) {
315 OnSessionError(session_id, cdm::kUnknownError, 0); 377 RejectPromise(promise_id,
378 cdm::kInvalidStateError,
379 0,
380 "CDM has not been initialized.");
316 return; 381 return;
317 } 382 }
318 383
319 cdm_->LoadSession(session_id, web_session_id.data(), web_session_id.size()); 384 cdm_->LoadSession(promise_id, web_session_id.data(), web_session_id.size());
320 } 385 }
321 386
322 void CdmAdapter::UpdateSession(uint32_t session_id, 387 void CdmAdapter::UpdateSession(uint32_t promise_id,
388 const std::string& web_session_id,
323 pp::VarArrayBuffer response) { 389 pp::VarArrayBuffer response) {
324 const uint8_t* response_ptr = static_cast<const uint8_t*>(response.Map()); 390 const uint8_t* response_ptr = static_cast<const uint8_t*>(response.Map());
325 const uint32_t response_size = response.ByteLength(); 391 const uint32_t response_size = response.ByteLength();
326 392
393 PP_DCHECK(!web_session_id.empty());
394
327 if (!response_ptr || response_size <= 0) { 395 if (!response_ptr || response_size <= 0) {
ddorwin 2014/05/13 22:44:02 This really should not happen. We should try to PP
jrummell 2014/05/15 22:38:09 Converted to PP_DCHECKs.
328 OnSessionError(session_id, cdm::kUnknownError, 0); 396 RejectPromise(promise_id, cdm::kSyntaxError, 0, "response is empty.");
ddorwin 2014/05/13 22:44:02 Really this is an InvalidAccessError.
jrummell 2014/05/15 22:38:09 Removed.
329 return; 397 return;
330 } 398 }
331 cdm_->UpdateSession(session_id, response_ptr, response_size); 399
400 cdm_->UpdateSession(promise_id,
401 web_session_id.data(),
402 web_session_id.length(),
403 response_ptr,
404 response_size);
332 } 405 }
333 406
334 void CdmAdapter::ReleaseSession(uint32_t session_id) { 407 void CdmAdapter::ReleaseSession(uint32_t promise_id,
335 cdm_->ReleaseSession(session_id); 408 const std::string& web_session_id) {
409 cdm_->ReleaseSession(
410 promise_id, web_session_id.data(), web_session_id.length());
336 } 411 }
337 412
338 // Note: In the following decryption/decoding related functions, errors are NOT 413 // Note: In the following decryption/decoding related functions, errors are NOT
339 // reported via KeyError, but are reported via corresponding PPB calls. 414 // reported via KeyError, but are reported via corresponding PPB calls.
340 415
341 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer, 416 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer,
342 const PP_EncryptedBlockInfo& encrypted_block_info) { 417 const PP_EncryptedBlockInfo& encrypted_block_info) {
343 PP_DCHECK(!encrypted_buffer.is_null()); 418 PP_DCHECK(!encrypted_buffer.is_null());
344 419
345 // Release a buffer that the caller indicated it is finished with. 420 // Release a buffer that the caller indicated it is finished with.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 delay_ms, 597 delay_ms,
523 callback_factory_.NewCallback(&CdmAdapter::TimerExpired, context), 598 callback_factory_.NewCallback(&CdmAdapter::TimerExpired, context),
524 PP_OK); 599 PP_OK);
525 } 600 }
526 601
527 void CdmAdapter::TimerExpired(int32_t result, void* context) { 602 void CdmAdapter::TimerExpired(int32_t result, void* context) {
528 PP_DCHECK(result == PP_OK); 603 PP_DCHECK(result == PP_OK);
529 cdm_->TimerExpired(context); 604 cdm_->TimerExpired(context);
530 } 605 }
531 606
607 // cdm::Host_5 methods
608
609 cdm::Time CdmAdapter::GetCurrentTime() {
610 return pp::Module::Get()->core()->GetTime();
611 }
612
613 void CdmAdapter::OnResolvePromise(uint32_t promise_id) {
614 PostOnMain(callback_factory_.NewCallback(
615 &CdmAdapter::SendPromiseResolvedInternal, promise_id));
616 }
617
618 void CdmAdapter::OnResolveNewSessionPromise(uint32_t promise_id,
619 const char* web_session_id,
620 uint32_t web_session_id_length) {
621 PostOnMain(callback_factory_.NewCallback(
622 &CdmAdapter::SendPromiseResolvedWithSessionInternal,
623 promise_id,
624 std::string(web_session_id, web_session_id_length)));
625 }
626
627 void CdmAdapter::OnRejectPromise(uint32_t promise_id,
628 cdm::Error error,
629 uint32_t system_code,
630 const char* error_message,
631 uint32_t error_message_length) {
632 RejectPromise(promise_id,
633 error,
634 system_code,
635 std::string(error_message, error_message_length));
636 }
637
638 void CdmAdapter::RejectPromise(uint32_t promise_id,
639 cdm::Error error,
640 uint32_t system_code,
641 const std::string& error_message) {
642 PostOnMain(callback_factory_.NewCallback(
643 &CdmAdapter::SendPromiseRejectedInternal,
644 promise_id,
645 SessionError(error, system_code, error_message)));
646 }
647
648 void CdmAdapter::OnSessionMessage(const char* web_session_id,
649 uint32_t web_session_id_length,
650 const char* message,
651 uint32_t message_length,
652 const char* destination_url,
653 uint32_t destination_url_length) {
654 PostOnMain(callback_factory_.NewCallback(
655 &CdmAdapter::SendSessionMessageInternal,
656 std::string(web_session_id, web_session_id_length),
657 std::vector<uint8>(message, message + message_length),
658 std::string(destination_url, destination_url_length)));
659 }
660
661 void CdmAdapter::OnSessionKeysChange(const char* web_session_id,
662 uint32_t web_session_id_length,
663 bool has_new_key) {
664 // TODO(jrummell): Implement this event in subsequent CL
665 // (http://crbug.com/370251).
666 PP_NOTREACHED();
667 }
668
669 void CdmAdapter::OnExpirationChange(const char* web_session_id,
670 uint32_t web_session_id_length,
671 cdm::Time new_expiry_time) {
672 // TODO(jrummell): Implement this event in subsequent CL
673 // (http://crbug.com/370251).
674 PP_NOTREACHED();
675 }
676
677 void CdmAdapter::OnSessionReady(const char* web_session_id,
678 uint32_t web_session_id_length) {
679 PostOnMain(callback_factory_.NewCallback(
680 &CdmAdapter::SendSessionReadyInternal,
681 std::string(web_session_id, web_session_id_length)));
682 }
683
684 void CdmAdapter::OnSessionClosed(const char* web_session_id,
685 uint32_t web_session_id_length) {
686 PostOnMain(callback_factory_.NewCallback(
687 &CdmAdapter::SendSessionClosedInternal,
688 std::string(web_session_id, web_session_id_length)));
689 }
690
691 void CdmAdapter::OnSessionError(const char* web_session_id,
692 uint32_t web_session_id_length,
693 cdm::Error error,
694 uint32_t system_code,
695 const char* error_message,
696 uint32_t error_message_length) {
697 PostOnMain(callback_factory_.NewCallback(
698 &CdmAdapter::SendSessionErrorInternal,
699 std::string(web_session_id, web_session_id_length),
700 SessionError(error,
701 system_code,
702 std::string(error_message, error_message_length))));
703 }
704
705 // cdm::Host_4 methods
ddorwin 2014/05/13 22:44:02 It seems odd to have 4 after 5.
jrummell 2014/05/15 22:38:09 Reordered.
706
532 double CdmAdapter::GetCurrentWallTimeInSeconds() { 707 double CdmAdapter::GetCurrentWallTimeInSeconds() {
533 return pp::Module::Get()->core()->GetTime(); 708 return GetCurrentTime();
534 } 709 }
535 710
536 void CdmAdapter::OnSessionCreated(uint32_t session_id, 711 void CdmAdapter::OnSessionCreated(uint32_t session_id,
537 const char* web_session_id, 712 const char* web_session_id,
538 uint32_t web_session_id_length) { 713 uint32_t web_session_id_length) {
539 PostOnMain(callback_factory_.NewCallback( 714 uint32_t promise_id = cdm_->LookupPromiseId(session_id);
540 &CdmAdapter::SendSessionCreatedInternal, 715 cdm_->AssignWebSessionId(session_id, web_session_id, web_session_id_length);
541 session_id, 716 OnResolveNewSessionPromise(promise_id, web_session_id, web_session_id_length);
542 std::string(web_session_id, web_session_id_length)));
543 } 717 }
544 718
545 void CdmAdapter::OnSessionMessage(uint32_t session_id, 719 void CdmAdapter::OnSessionMessage(uint32_t session_id,
546 const char* message, 720 const char* message,
547 uint32_t message_length, 721 uint32_t message_length,
548 const char* destination_url, 722 const char* destination_url,
549 uint32_t destination_url_length) { 723 uint32_t destination_url_length) {
550 PostOnMain(callback_factory_.NewCallback( 724 std::string web_session_id = cdm_->LookupWebSessionId(session_id);
551 &CdmAdapter::SendSessionMessageInternal, 725 OnSessionMessage(web_session_id.data(),
552 session_id, 726 web_session_id.length(),
553 std::vector<uint8>(message, message + message_length), 727 message,
554 std::string(destination_url, destination_url_length))); 728 message_length,
729 destination_url,
730 destination_url_length);
555 } 731 }
556 732
557 void CdmAdapter::OnSessionReady(uint32_t session_id) { 733 void CdmAdapter::OnSessionReady(uint32_t session_id) {
558 PostOnMain(callback_factory_.NewCallback( 734 uint32_t promise_id = cdm_->LookupPromiseId(session_id);
559 &CdmAdapter::SendSessionReadyInternal, session_id)); 735 if (promise_id) {
736 OnResolvePromise(promise_id);
737 } else {
738 std::string web_session_id = cdm_->LookupWebSessionId(session_id);
739 OnSessionReady(web_session_id.data(), web_session_id.length());
740 }
560 } 741 }
561 742
562 void CdmAdapter::OnSessionClosed(uint32_t session_id) { 743 void CdmAdapter::OnSessionClosed(uint32_t session_id) {
563 PostOnMain(callback_factory_.NewCallback( 744 uint32_t promise_id = cdm_->LookupPromiseId(session_id);
564 &CdmAdapter::SendSessionClosedInternal, session_id)); 745 std::string web_session_id = cdm_->LookupWebSessionId(session_id);
746 cdm_->DropWebSessionId(web_session_id);
747 if (promise_id) {
748 OnResolvePromise(promise_id);
749 } else {
750 OnSessionClosed(web_session_id.data(), web_session_id.length());
751 }
565 } 752 }
566 753
567 void CdmAdapter::OnSessionError(uint32_t session_id, 754 void CdmAdapter::OnSessionError(uint32_t session_id,
568 cdm::MediaKeyError error_code, 755 cdm::MediaKeyError error_code,
569 uint32_t system_code) { 756 uint32_t system_code) {
570 PostOnMain(callback_factory_.NewCallback( 757 uint32_t promise_id = cdm_->LookupPromiseId(session_id);
571 &CdmAdapter::SendSessionErrorInternal, 758
572 session_id, 759 // Existing cdm::MediaKeyError don't map to DOM error names. Convert them
573 error_code, 760 // into non-standard names so that the prefixed API can extract them.
574 system_code)); 761 // TODO(jrummell): Remove this conversion and the inverse when CDM4 is gone.
575 } 762 cdm::Error error;
576 763 switch (error_code) {
577 void CdmAdapter::SendSessionCreatedInternal(int32_t result, 764 case cdm::kPrefixedClientError:
578 uint32_t session_id, 765 error = cdm::kClientError;
579 const std::string& web_session_id) { 766 break;
580 PP_DCHECK(result == PP_OK); 767 case cdm::kPrefixedOutputError:
581 pp::ContentDecryptor_Private::SessionCreated(session_id, web_session_id); 768 error = cdm::kOutputError;
582 } 769 break;
583 770 case cdm::kPrefixedUnknownError:
584 void CdmAdapter::SendSessionMessageInternal(int32_t result, 771 default:
585 uint32_t session_id, 772 error = cdm::kUnknownError;
586 const std::vector<uint8>& message, 773 break;
587 const std::string& default_url) { 774 }
775
776 if (promise_id) {
777 RejectPromise(promise_id, error, system_code, std::string());
778 } else {
779 std::string web_session_id = cdm_->LookupWebSessionId(session_id);
780 OnSessionError(web_session_id.data(),
781 web_session_id.length(),
782 error,
783 system_code,
784 NULL,
785 0);
786 }
787 }
788
789 // Helpers to pass the event to Pepper.
790
791 void CdmAdapter::SendPromiseResolvedInternal(int32_t result,
792 uint32_t promise_id) {
793 PP_DCHECK(result == PP_OK);
794 pp::ContentDecryptor_Private::PromiseResolved(promise_id);
795 }
796
797 void CdmAdapter::SendPromiseResolvedWithSessionInternal(
798 int32_t result,
799 uint32_t promise_id,
800 const std::string& web_session_id) {
801 PP_DCHECK(result == PP_OK);
802 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id,
803 web_session_id);
804 }
805
806 void CdmAdapter::SendPromiseRejectedInternal(int32_t result,
807 uint32_t promise_id,
808 const SessionError& error) {
809 PP_DCHECK(result == PP_OK);
810 pp::ContentDecryptor_Private::PromiseRejected(
811 promise_id,
812 CdmExceptionTypeToPpExceptionType(error.error),
813 error.system_code,
814 error.error_description);
815 }
816
817 void CdmAdapter::SendSessionMessageInternal(
818 int32_t result,
819 const std::string& web_session_id,
820 const std::vector<uint8>& message,
821 const std::string& destination_url) {
588 PP_DCHECK(result == PP_OK); 822 PP_DCHECK(result == PP_OK);
589 823
590 pp::VarArrayBuffer message_array_buffer(message.size()); 824 pp::VarArrayBuffer message_array_buffer(message.size());
591 if (message.size() > 0) { 825 if (message.size() > 0) {
592 memcpy(message_array_buffer.Map(), message.data(), message.size()); 826 memcpy(message_array_buffer.Map(), message.data(), message.size());
593 } 827 }
594 828
595 pp::ContentDecryptor_Private::SessionMessage( 829 pp::ContentDecryptor_Private::SessionMessage(
596 session_id, message_array_buffer, default_url); 830 web_session_id, message_array_buffer, destination_url);
597 } 831 }
598 832
599 void CdmAdapter::SendSessionReadyInternal(int32_t result, uint32_t session_id) { 833 void CdmAdapter::SendSessionReadyInternal(int32_t result,
834 const std::string& web_session_id) {
600 PP_DCHECK(result == PP_OK); 835 PP_DCHECK(result == PP_OK);
601 pp::ContentDecryptor_Private::SessionReady(session_id); 836 pp::ContentDecryptor_Private::SessionReady(web_session_id);
602 } 837 }
603 838
604 void CdmAdapter::SendSessionClosedInternal(int32_t result, 839 void CdmAdapter::SendSessionClosedInternal(int32_t result,
605 uint32_t session_id) { 840 const std::string& web_session_id) {
606 PP_DCHECK(result == PP_OK); 841 PP_DCHECK(result == PP_OK);
607 pp::ContentDecryptor_Private::SessionClosed(session_id); 842 pp::ContentDecryptor_Private::SessionClosed(web_session_id);
608 } 843 }
609 844
610 void CdmAdapter::SendSessionErrorInternal(int32_t result, 845 void CdmAdapter::SendSessionErrorInternal(int32_t result,
611 uint32_t session_id, 846 const std::string& web_session_id,
612 cdm::MediaKeyError error_code, 847 const SessionError& error) {
613 uint32_t system_code) {
614 PP_DCHECK(result == PP_OK); 848 PP_DCHECK(result == PP_OK);
615 pp::ContentDecryptor_Private::SessionError( 849 pp::ContentDecryptor_Private::SessionError(
616 session_id, error_code, system_code); 850 web_session_id,
851 CdmExceptionTypeToPpExceptionType(error.error),
852 error.system_code,
853 error.error_description);
617 } 854 }
618 855
619 void CdmAdapter::DeliverBlock(int32_t result, 856 void CdmAdapter::DeliverBlock(int32_t result,
620 const cdm::Status& status, 857 const cdm::Status& status,
621 const LinkedDecryptedBlock& decrypted_block, 858 const LinkedDecryptedBlock& decrypted_block,
622 const PP_DecryptTrackingInfo& tracking_info) { 859 const PP_DecryptTrackingInfo& tracking_info) {
623 PP_DCHECK(result == PP_OK); 860 PP_DCHECK(result == PP_OK);
624 PP_DecryptedBlockInfo decrypted_block_info; 861 PP_DecryptedBlockInfo decrypted_block_info;
625 decrypted_block_info.tracking_info = tracking_info; 862 decrypted_block_info.tracking_info = tracking_info;
626 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); 863 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp();
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 cdm_->OnPlatformChallengeResponse(response); 1172 cdm_->OnPlatformChallengeResponse(response);
936 return; 1173 return;
937 } 1174 }
938 1175
939 pp::VarArrayBuffer signed_data_var(signed_data_output_); 1176 pp::VarArrayBuffer signed_data_var(signed_data_output_);
940 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_); 1177 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_);
941 std::string platform_key_certificate_string = 1178 std::string platform_key_certificate_string =
942 platform_key_certificate_output_.AsString(); 1179 platform_key_certificate_output_.AsString();
943 1180
944 cdm::PlatformChallengeResponse response = { 1181 cdm::PlatformChallengeResponse response = {
945 static_cast<uint8_t*>(signed_data_var.Map()), 1182 static_cast<uint8_t*>(signed_data_var.Map()),
946 signed_data_var.ByteLength(), 1183 signed_data_var.ByteLength(),
947 1184 static_cast<uint8_t*>(signed_data_signature_var.Map()),
948 static_cast<uint8_t*>(signed_data_signature_var.Map()), 1185 signed_data_signature_var.ByteLength(),
949 signed_data_signature_var.ByteLength(), 1186 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.data()),
950 1187 static_cast<uint32_t>(platform_key_certificate_string.length())};
951 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.c_str()),
952 static_cast<uint32_t>(platform_key_certificate_string.length())
953 };
954 cdm_->OnPlatformChallengeResponse(response); 1188 cdm_->OnPlatformChallengeResponse(response);
955 1189
956 signed_data_var.Unmap(); 1190 signed_data_var.Unmap();
957 signed_data_signature_var.Unmap(); 1191 signed_data_signature_var.Unmap();
958 } 1192 }
959 1193
960 void CdmAdapter::EnableProtectionDone(int32_t result) { 1194 void CdmAdapter::EnableProtectionDone(int32_t result) {
961 // Does nothing since clients must call QueryOutputProtectionStatus() to 1195 // Does nothing since clients must call QueryOutputProtectionStatus() to
962 // inspect the protection status on a regular basis. 1196 // inspect the protection status on a regular basis.
963 CDM_DLOG() << __FUNCTION__ << " : " << result; 1197 CDM_DLOG() << __FUNCTION__ << " : " << result;
964 } 1198 }
965 1199
966 void CdmAdapter::QueryOutputProtectionStatusDone(int32_t result) { 1200 void CdmAdapter::QueryOutputProtectionStatusDone(int32_t result) {
967 PP_DCHECK(query_output_protection_in_progress_); 1201 PP_DCHECK(query_output_protection_in_progress_);
968 query_output_protection_in_progress_ = false; 1202 query_output_protection_in_progress_ = false;
969 1203
970 // Return a protection status of none on error. 1204 // Return a protection status of none on error.
971 if (result != PP_OK) 1205 if (result != PP_OK)
972 output_link_mask_ = output_protection_mask_ = 0; 1206 output_link_mask_ = output_protection_mask_ = 0;
973 else 1207 else
974 ReportOutputProtectionQueryResult(); 1208 ReportOutputProtectionQueryResult();
975 1209
976 cdm_->OnQueryOutputProtectionStatus(output_link_mask_, 1210 cdm_->OnQueryOutputProtectionStatus(output_link_mask_,
977 output_protection_mask_); 1211 output_protection_mask_);
978 } 1212 }
979 #endif 1213 #endif
980 1214
1215 CdmAdapter::SessionError::SessionError(cdm::Error error,
1216 uint32_t system_code,
1217 std::string error_description)
1218 : error(error),
1219 system_code(system_code),
1220 error_description(error_description) {
1221 }
1222
981 void* GetCdmHost(int host_interface_version, void* user_data) { 1223 void* GetCdmHost(int host_interface_version, void* user_data) {
982 if (!host_interface_version || !user_data) 1224 if (!host_interface_version || !user_data)
983 return NULL; 1225 return NULL;
984 1226
985 COMPILE_ASSERT( 1227 COMPILE_ASSERT(
986 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_4::kVersion, 1228 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_5::kVersion,
987 update_code_below); 1229 update_code_below);
988 1230
989 // Ensure IsSupportedCdmHostVersion matches implementation of this function. 1231 // Ensure IsSupportedCdmHostVersion matches implementation of this function.
990 // Always update this DCHECK when updating this function. 1232 // Always update this DCHECK when updating this function.
991 // If this check fails, update this function and DCHECK or update 1233 // If this check fails, update this function and DCHECK or update
992 // IsSupportedCdmHostVersion. 1234 // IsSupportedCdmHostVersion.
993 1235
994 PP_DCHECK( 1236 PP_DCHECK(
995 // Future version is not supported. 1237 // Future version is not supported.
996 !IsSupportedCdmHostVersion(cdm::Host_4::kVersion + 1) && 1238 !IsSupportedCdmHostVersion(cdm::Host_5::kVersion + 1) &&
997 // Current version is supported. 1239 // Current version is supported.
1240 IsSupportedCdmHostVersion(cdm::Host_5::kVersion) &&
1241 // Include all previous supported versions (if any) here.
998 IsSupportedCdmHostVersion(cdm::Host_4::kVersion) && 1242 IsSupportedCdmHostVersion(cdm::Host_4::kVersion) &&
999 // Include all previous supported versions (if any) here.
1000 // No supported previous versions.
1001 // One older than the oldest supported version is not supported. 1243 // One older than the oldest supported version is not supported.
1002 !IsSupportedCdmHostVersion(cdm::Host_4::kVersion - 1)); 1244 !IsSupportedCdmHostVersion(cdm::Host_4::kVersion - 1));
1003 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version)); 1245 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version));
1004 1246
1005 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data); 1247 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data);
1006 CDM_DLOG() << "Create CDM Host with version " << host_interface_version; 1248 CDM_DLOG() << "Create CDM Host with version " << host_interface_version;
1007 switch (host_interface_version) { 1249 switch (host_interface_version) {
1008 case cdm::Host_4::kVersion: 1250 case cdm::Host_4::kVersion:
1009 return static_cast<cdm::Host_4*>(cdm_adapter); 1251 return static_cast<cdm::Host_4*>(cdm_adapter);
1252 case cdm::Host_5::kVersion:
1253 return static_cast<cdm::Host_5*>(cdm_adapter);
1010 default: 1254 default:
1011 PP_NOTREACHED(); 1255 PP_NOTREACHED();
1012 return NULL; 1256 return NULL;
1013 } 1257 }
1014 } 1258 }
1015 1259
1016 // This object is the global object representing this plugin library as long 1260 // This object is the global object representing this plugin library as long
1017 // as it is loaded. 1261 // as it is loaded.
1018 class CdmAdapterModule : public pp::Module { 1262 class CdmAdapterModule : public pp::Module {
1019 public: 1263 public:
(...skipping 17 matching lines...) Expand all
1037 } // namespace media 1281 } // namespace media
1038 1282
1039 namespace pp { 1283 namespace pp {
1040 1284
1041 // Factory function for your specialization of the Module object. 1285 // Factory function for your specialization of the Module object.
1042 Module* CreateModule() { 1286 Module* CreateModule() {
1043 return new media::CdmAdapterModule(); 1287 return new media::CdmAdapterModule();
1044 } 1288 }
1045 1289
1046 } // namespace pp 1290 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698