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