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/limits.h" | 7 #include "media/base/limits.h" |
8 #include "media/cdm/ppapi/cdm_file_io_impl.h" | 8 #include "media/cdm/ppapi/cdm_file_io_impl.h" |
9 #include "media/cdm/ppapi/cdm_helpers.h" | 9 #include "media/cdm/ppapi/cdm_helpers.h" |
10 #include "media/cdm/ppapi/cdm_logging.h" | 10 #include "media/cdm/ppapi/cdm_logging.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 215 } |
216 | 216 |
217 PP_NOTREACHED(); | 217 PP_NOTREACHED(); |
218 return cdm::kStreamTypeVideo; | 218 return cdm::kStreamTypeVideo; |
219 } | 219 } |
220 | 220 |
221 cdm::SessionType PpSessionTypeToCdmSessionType(PP_SessionType session_type) { | 221 cdm::SessionType PpSessionTypeToCdmSessionType(PP_SessionType session_type) { |
222 switch (session_type) { | 222 switch (session_type) { |
223 case PP_SESSIONTYPE_TEMPORARY: | 223 case PP_SESSIONTYPE_TEMPORARY: |
224 return cdm::kTemporary; | 224 return cdm::kTemporary; |
225 case PP_SESSIONTYPE_PERSISTENT: | 225 case PP_SESSIONTYPE_PERSISTENT_LICENSE: |
226 return cdm::kPersistent; | 226 return cdm::kPersistentLicense; |
227 default: | 227 case PP_SESSIONTYPE_PERSISTENT_RELEASE: |
228 PP_NOTREACHED(); | 228 return cdm::kPersistentKeyRelease; |
229 return cdm::kTemporary; | |
230 } | 229 } |
| 230 |
| 231 PP_NOTREACHED(); |
| 232 return cdm::kTemporary; |
231 } | 233 } |
232 | 234 |
233 PP_CdmExceptionCode CdmExceptionTypeToPpCdmExceptionType(cdm::Error error) { | 235 PP_CdmExceptionCode CdmExceptionTypeToPpCdmExceptionType(cdm::Error error) { |
234 switch (error) { | 236 switch (error) { |
235 case cdm::kNotSupportedError: | 237 case cdm::kNotSupportedError: |
236 return PP_CDMEXCEPTIONCODE_NOTSUPPORTEDERROR; | 238 return PP_CDMEXCEPTIONCODE_NOTSUPPORTEDERROR; |
237 case cdm::kInvalidStateError: | 239 case cdm::kInvalidStateError: |
238 return PP_CDMEXCEPTIONCODE_INVALIDSTATEERROR; | 240 return PP_CDMEXCEPTIONCODE_INVALIDSTATEERROR; |
239 case cdm::kInvalidAccessError: | 241 case cdm::kInvalidAccessError: |
240 return PP_CDMEXCEPTIONCODE_INVALIDACCESSERROR; | 242 return PP_CDMEXCEPTIONCODE_INVALIDACCESSERROR; |
241 case cdm::kQuotaExceededError: | 243 case cdm::kQuotaExceededError: |
242 return PP_CDMEXCEPTIONCODE_QUOTAEXCEEDEDERROR; | 244 return PP_CDMEXCEPTIONCODE_QUOTAEXCEEDEDERROR; |
243 case cdm::kUnknownError: | 245 case cdm::kUnknownError: |
244 return PP_CDMEXCEPTIONCODE_UNKNOWNERROR; | 246 return PP_CDMEXCEPTIONCODE_UNKNOWNERROR; |
245 case cdm::kClientError: | 247 case cdm::kClientError: |
246 return PP_CDMEXCEPTIONCODE_CLIENTERROR; | 248 return PP_CDMEXCEPTIONCODE_CLIENTERROR; |
247 case cdm::kOutputError: | 249 case cdm::kOutputError: |
248 return PP_CDMEXCEPTIONCODE_OUTPUTERROR; | 250 return PP_CDMEXCEPTIONCODE_OUTPUTERROR; |
249 default: | |
250 PP_NOTREACHED(); | |
251 return PP_CDMEXCEPTIONCODE_UNKNOWNERROR; | |
252 } | 251 } |
| 252 |
| 253 PP_NOTREACHED(); |
| 254 return PP_CDMEXCEPTIONCODE_UNKNOWNERROR; |
| 255 } |
| 256 |
| 257 PP_CdmMessageType CdmMessageTypeToPpMessageType(cdm::MessageType message) { |
| 258 switch (message) { |
| 259 case cdm::kLicenseRequest: |
| 260 return PP_CDMMESSAGETYPE_LICENSE_REQUEST; |
| 261 case cdm::kLicenseRenewal: |
| 262 return PP_CDMMESSAGETYPE_LICENSE_RENEWAL; |
| 263 case cdm::kLicenseRelease: |
| 264 return PP_CDMMESSAGETYPE_LICENSE_RELEASE; |
| 265 } |
| 266 |
| 267 PP_NOTREACHED(); |
| 268 return PP_CDMMESSAGETYPE_LICENSE_REQUEST; |
| 269 } |
| 270 |
| 271 PP_CdmKeyStatus CdmKeyStatusToPpKeyStatus(cdm::KeyStatus status) { |
| 272 switch (status) { |
| 273 case cdm::kUsable: |
| 274 return PP_CDMKEYSTATUS_USABLE; |
| 275 case cdm::kInternalError: |
| 276 return PP_CDMKEYSTATUS_INVALID; |
| 277 case cdm::kExpired: |
| 278 return PP_CDMKEYSTATUS_EXPIRED; |
| 279 case cdm::kOutputNotAllowed: |
| 280 return PP_CDMKEYSTATUS_OUTPUTNOTALLOWED; |
| 281 } |
| 282 |
| 283 PP_NOTREACHED(); |
| 284 return PP_CDMKEYSTATUS_INVALID; |
253 } | 285 } |
254 | 286 |
255 } // namespace | 287 } // namespace |
256 | 288 |
257 namespace media { | 289 namespace media { |
258 | 290 |
259 CdmAdapter::CdmAdapter(PP_Instance instance, pp::Module* module) | 291 CdmAdapter::CdmAdapter(PP_Instance instance, pp::Module* module) |
260 : pp::Instance(instance), | 292 : pp::Instance(instance), |
261 pp::ContentDecryptor_Private(this), | 293 pp::ContentDecryptor_Private(this), |
262 #if defined(OS_CHROMEOS) | 294 #if defined(OS_CHROMEOS) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 cdm::kInvalidStateError, | 386 cdm::kInvalidStateError, |
355 0, | 387 0, |
356 "CDM has not been initialized."); | 388 "CDM has not been initialized."); |
357 return; | 389 return; |
358 } | 390 } |
359 | 391 |
360 cdm_->SetServerCertificate( | 392 cdm_->SetServerCertificate( |
361 promise_id, server_certificate_ptr, server_certificate_size); | 393 promise_id, server_certificate_ptr, server_certificate_size); |
362 } | 394 } |
363 | 395 |
364 void CdmAdapter::CreateSession(uint32_t promise_id, | 396 void CdmAdapter::CreateSessionAndGenerateRequest( |
365 const std::string& init_data_type, | 397 uint32_t promise_id, |
366 pp::VarArrayBuffer init_data, | 398 PP_SessionType session_type, |
367 PP_SessionType session_type) { | 399 const std::string& init_data_type, |
| 400 pp::VarArrayBuffer init_data) { |
368 // Initialize() doesn't report an error, so CreateSession() can be called | 401 // Initialize() doesn't report an error, so CreateSession() can be called |
369 // even if Initialize() failed. | 402 // even if Initialize() failed. |
370 // TODO(jrummell): Remove this code when prefixed EME gets removed. | 403 // TODO(jrummell): Remove this code when prefixed EME gets removed. |
371 // TODO(jrummell): Verify that Initialize() failing does not resolve the | 404 // TODO(jrummell): Verify that Initialize() failing does not resolve the |
372 // MediaKeys.create() promise. | 405 // MediaKeys.create() promise. |
373 if (!cdm_) { | 406 if (!cdm_) { |
374 RejectPromise(promise_id, | 407 RejectPromise(promise_id, |
375 cdm::kInvalidStateError, | 408 cdm::kInvalidStateError, |
376 0, | 409 0, |
377 "CDM has not been initialized."); | 410 "CDM has not been initialized."); |
378 return; | 411 return; |
379 } | 412 } |
380 | 413 |
381 cdm_->CreateSession(promise_id, | 414 cdm_->CreateSessionAndGenerateRequest( |
382 init_data_type.data(), | 415 promise_id, PpSessionTypeToCdmSessionType(session_type), |
383 init_data_type.size(), | 416 init_data_type.data(), init_data_type.size(), |
384 static_cast<const uint8_t*>(init_data.Map()), | 417 static_cast<const uint8_t*>(init_data.Map()), init_data.ByteLength()); |
385 init_data.ByteLength(), | |
386 PpSessionTypeToCdmSessionType(session_type)); | |
387 } | 418 } |
388 | 419 |
389 void CdmAdapter::LoadSession(uint32_t promise_id, | 420 void CdmAdapter::LoadSession(uint32_t promise_id, |
390 const std::string& web_session_id) { | 421 PP_SessionType session_type, |
| 422 const std::string& session_id) { |
391 // Initialize() doesn't report an error, so LoadSession() can be called | 423 // Initialize() doesn't report an error, so LoadSession() can be called |
392 // even if Initialize() failed. | 424 // even if Initialize() failed. |
393 // TODO(jrummell): Remove this code when prefixed EME gets removed. | 425 // TODO(jrummell): Remove this code when prefixed EME gets removed. |
394 // TODO(jrummell): Verify that Initialize() failing does not resolve the | 426 // TODO(jrummell): Verify that Initialize() failing does not resolve the |
395 // MediaKeys.create() promise. | 427 // MediaKeys.create() promise. |
396 if (!cdm_) { | 428 if (!cdm_) { |
397 RejectPromise(promise_id, | 429 RejectPromise(promise_id, |
398 cdm::kInvalidStateError, | 430 cdm::kInvalidStateError, |
399 0, | 431 0, |
400 "CDM has not been initialized."); | 432 "CDM has not been initialized."); |
401 return; | 433 return; |
402 } | 434 } |
403 | 435 |
404 cdm_->LoadSession(promise_id, web_session_id.data(), web_session_id.size()); | 436 cdm_->LoadSession(promise_id, PpSessionTypeToCdmSessionType(session_type), |
| 437 session_id.data(), session_id.size()); |
405 } | 438 } |
406 | 439 |
407 void CdmAdapter::UpdateSession(uint32_t promise_id, | 440 void CdmAdapter::UpdateSession(uint32_t promise_id, |
408 const std::string& web_session_id, | 441 const std::string& session_id, |
409 pp::VarArrayBuffer response) { | 442 pp::VarArrayBuffer response) { |
410 const uint8_t* response_ptr = static_cast<const uint8_t*>(response.Map()); | 443 const uint8_t* response_ptr = static_cast<const uint8_t*>(response.Map()); |
411 const uint32_t response_size = response.ByteLength(); | 444 const uint32_t response_size = response.ByteLength(); |
412 | 445 |
413 PP_DCHECK(!web_session_id.empty()); | 446 PP_DCHECK(!session_id.empty()); |
414 PP_DCHECK(response_ptr); | 447 PP_DCHECK(response_ptr); |
415 PP_DCHECK(response_size > 0); | 448 PP_DCHECK(response_size > 0); |
416 | 449 |
417 cdm_->UpdateSession(promise_id, | 450 cdm_->UpdateSession(promise_id, session_id.data(), session_id.length(), |
418 web_session_id.data(), | 451 response_ptr, response_size); |
419 web_session_id.length(), | |
420 response_ptr, | |
421 response_size); | |
422 } | 452 } |
423 | 453 |
424 void CdmAdapter::CloseSession(uint32_t promise_id, | 454 void CdmAdapter::CloseSession(uint32_t promise_id, |
425 const std::string& web_session_id) { | 455 const std::string& session_id) { |
426 cdm_->CloseSession( | 456 cdm_->CloseSession(promise_id, session_id.data(), session_id.length()); |
427 promise_id, web_session_id.data(), web_session_id.length()); | |
428 } | 457 } |
429 | 458 |
430 void CdmAdapter::RemoveSession(uint32_t promise_id, | 459 void CdmAdapter::RemoveSession(uint32_t promise_id, |
431 const std::string& web_session_id) { | 460 const std::string& session_id) { |
432 cdm_->RemoveSession( | 461 cdm_->RemoveSession(promise_id, session_id.data(), session_id.length()); |
433 promise_id, web_session_id.data(), web_session_id.length()); | |
434 } | |
435 | |
436 void CdmAdapter::GetUsableKeyIds(uint32_t promise_id, | |
437 const std::string& web_session_id) { | |
438 cdm_->GetUsableKeyIds( | |
439 promise_id, web_session_id.data(), web_session_id.length()); | |
440 } | 462 } |
441 | 463 |
442 // Note: In the following decryption/decoding related functions, errors are NOT | 464 // Note: In the following decryption/decoding related functions, errors are NOT |
443 // reported via KeyError, but are reported via corresponding PPB calls. | 465 // reported via KeyError, but are reported via corresponding PPB calls. |
444 | 466 |
445 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer, | 467 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer, |
446 const PP_EncryptedBlockInfo& encrypted_block_info) { | 468 const PP_EncryptedBlockInfo& encrypted_block_info) { |
447 PP_DCHECK(!encrypted_buffer.is_null()); | 469 PP_DCHECK(!encrypted_buffer.is_null()); |
448 | 470 |
449 // Release a buffer that the caller indicated it is finished with. | 471 // Release a buffer that the caller indicated it is finished with. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 void CdmAdapter::TimerExpired(int32_t result, void* context) { | 653 void CdmAdapter::TimerExpired(int32_t result, void* context) { |
632 PP_DCHECK(result == PP_OK); | 654 PP_DCHECK(result == PP_OK); |
633 cdm_->TimerExpired(context); | 655 cdm_->TimerExpired(context); |
634 } | 656 } |
635 | 657 |
636 cdm::Time CdmAdapter::GetCurrentWallTime() { | 658 cdm::Time CdmAdapter::GetCurrentWallTime() { |
637 return pp::Module::Get()->core()->GetTime(); | 659 return pp::Module::Get()->core()->GetTime(); |
638 } | 660 } |
639 | 661 |
640 void CdmAdapter::OnResolveNewSessionPromise(uint32_t promise_id, | 662 void CdmAdapter::OnResolveNewSessionPromise(uint32_t promise_id, |
641 const char* web_session_id, | 663 const char* session_id, |
642 uint32_t web_session_id_length) { | 664 uint32_t session_id_size) { |
643 PostOnMain(callback_factory_.NewCallback( | 665 PostOnMain(callback_factory_.NewCallback( |
644 &CdmAdapter::SendPromiseResolvedWithSessionInternal, | 666 &CdmAdapter::SendPromiseResolvedWithSessionInternal, promise_id, |
645 promise_id, | 667 std::string(session_id, session_id_size))); |
646 std::string(web_session_id, web_session_id_length))); | |
647 } | 668 } |
648 | 669 |
649 void CdmAdapter::OnResolvePromise(uint32_t promise_id) { | 670 void CdmAdapter::OnResolvePromise(uint32_t promise_id) { |
650 PostOnMain(callback_factory_.NewCallback( | 671 PostOnMain(callback_factory_.NewCallback( |
651 &CdmAdapter::SendPromiseResolvedInternal, promise_id)); | 672 &CdmAdapter::SendPromiseResolvedInternal, promise_id)); |
652 } | 673 } |
653 | 674 |
| 675 // cdm::Host_6 only |
654 void CdmAdapter::OnResolveKeyIdsPromise(uint32_t promise_id, | 676 void CdmAdapter::OnResolveKeyIdsPromise(uint32_t promise_id, |
655 const cdm::BinaryData* usable_key_ids, | 677 const cdm::BinaryData* usable_key_ids, |
656 uint32_t usable_key_ids_length) { | 678 uint32_t usable_key_ids_size) { |
657 std::vector<std::vector<uint8> > key_ids; | 679 // This should never be called as GetUsableKeyIds() has been removed. |
658 for (uint32_t i = 0; i < usable_key_ids_length; ++i) { | 680 PP_NOTREACHED(); |
659 key_ids.push_back( | |
660 std::vector<uint8>(usable_key_ids[i].data, | |
661 usable_key_ids[i].data + usable_key_ids[i].length)); | |
662 } | |
663 PostOnMain(callback_factory_.NewCallback( | |
664 &CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal, | |
665 promise_id, | |
666 key_ids)); | |
667 } | 681 } |
668 | 682 |
669 void CdmAdapter::OnRejectPromise(uint32_t promise_id, | 683 void CdmAdapter::OnRejectPromise(uint32_t promise_id, |
670 cdm::Error error, | 684 cdm::Error error, |
671 uint32_t system_code, | 685 uint32_t system_code, |
672 const char* error_message, | 686 const char* error_message, |
673 uint32_t error_message_length) { | 687 uint32_t error_message_size) { |
674 // UMA to investigate http://crbug.com/410630 | 688 // UMA to investigate http://crbug.com/410630 |
675 // TODO(xhwang): Remove after bug is fixed. | 689 // TODO(xhwang): Remove after bug is fixed. |
676 if (system_code == 0x27) { | 690 if (system_code == 0x27) { |
677 pp::UMAPrivate uma_interface(this); | 691 pp::UMAPrivate uma_interface(this); |
678 uma_interface.HistogramCustomCounts("Media.EME.CdmFileIO.FileSizeKBOnError", | 692 uma_interface.HistogramCustomCounts("Media.EME.CdmFileIO.FileSizeKBOnError", |
679 last_read_file_size_kb_, | 693 last_read_file_size_kb_, |
680 kSizeKBMin, | 694 kSizeKBMin, |
681 kSizeKBMax, | 695 kSizeKBMax, |
682 kSizeKBBuckets); | 696 kSizeKBBuckets); |
683 } | 697 } |
684 | 698 |
685 RejectPromise(promise_id, | 699 RejectPromise(promise_id, error, system_code, |
686 error, | 700 std::string(error_message, error_message_size)); |
687 system_code, | |
688 std::string(error_message, error_message_length)); | |
689 } | 701 } |
690 | 702 |
691 void CdmAdapter::RejectPromise(uint32_t promise_id, | 703 void CdmAdapter::RejectPromise(uint32_t promise_id, |
692 cdm::Error error, | 704 cdm::Error error, |
693 uint32_t system_code, | 705 uint32_t system_code, |
694 const std::string& error_message) { | 706 const std::string& error_message) { |
695 PostOnMain(callback_factory_.NewCallback( | 707 PostOnMain(callback_factory_.NewCallback( |
696 &CdmAdapter::SendPromiseRejectedInternal, | 708 &CdmAdapter::SendPromiseRejectedInternal, |
697 promise_id, | 709 promise_id, |
698 SessionError(error, system_code, error_message))); | 710 SessionError(error, system_code, error_message))); |
699 } | 711 } |
700 | 712 |
701 void CdmAdapter::OnSessionMessage(const char* web_session_id, | 713 // cdm::Host_7 only. |
702 uint32_t web_session_id_length, | 714 void CdmAdapter::OnSessionMessage(const char* session_id, |
| 715 uint32_t session_id_size, |
| 716 cdm::MessageType message_type, |
703 const char* message, | 717 const char* message, |
704 uint32_t message_length, | 718 uint32_t message_size) { |
705 const char* destination_url, | |
706 uint32_t destination_url_length) { | |
707 PostOnMain(callback_factory_.NewCallback( | 719 PostOnMain(callback_factory_.NewCallback( |
708 &CdmAdapter::SendSessionMessageInternal, | 720 &CdmAdapter::SendSessionMessageInternal, |
709 std::string(web_session_id, web_session_id_length), | 721 std::string(session_id, session_id_size), message_type, |
710 std::vector<uint8>(message, message + message_length), | 722 std::vector<uint8_t>(message, message + message_size))); |
711 std::string(destination_url, destination_url_length))); | |
712 } | 723 } |
713 | 724 |
714 void CdmAdapter::OnSessionUsableKeysChange(const char* web_session_id, | 725 // cdm::Host_6 only. |
715 uint32_t web_session_id_length, | 726 void CdmAdapter::OnSessionMessage(const char* session_id, |
| 727 uint32_t session_id_size, |
| 728 const char* message, |
| 729 uint32_t message_size, |
| 730 const char* destination_url, |
| 731 uint32_t destination_url_size) { |
| 732 // |destination_url| is no longer passed to EME applications, so it is |
| 733 // dropped. All messages will appear as license renewals if |destination_url| |
| 734 // is provided, license request if not. |
| 735 cdm::MessageType message_type = (destination_url_size > 0) |
| 736 ? cdm::MessageType::kLicenseRenewal |
| 737 : cdm::MessageType::kLicenseRequest; |
| 738 PostOnMain(callback_factory_.NewCallback( |
| 739 &CdmAdapter::SendSessionMessageInternal, |
| 740 std::string(session_id, session_id_size), message_type, |
| 741 std::vector<uint8_t>(message, message + message_size))); |
| 742 } |
| 743 |
| 744 // cdm::Host_7 only. |
| 745 void CdmAdapter::OnSessionKeysChange(const char* session_id, |
| 746 uint32_t session_id_size, |
| 747 bool has_additional_usable_key, |
| 748 const cdm::KeyInformation* keys_info, |
| 749 uint32_t keys_info_count) { |
| 750 std::vector<PP_KeyInformation> key_information; |
| 751 for (uint32_t i = 0; i < keys_info_count; ++i) { |
| 752 const auto& key_info = keys_info[i]; |
| 753 PP_KeyInformation next_key = {}; |
| 754 |
| 755 if (key_info.key_id_size > sizeof(next_key.key_id)) { |
| 756 PP_NOTREACHED(); |
| 757 continue; |
| 758 } |
| 759 |
| 760 // Copy key_id into |next_key|. |
| 761 memcpy(next_key.key_id, key_info.key_id, key_info.key_id_size); |
| 762 |
| 763 // Set remaining fields on |next_key|. |
| 764 next_key.key_id_size = key_info.key_id_size; |
| 765 next_key.key_status = CdmKeyStatusToPpKeyStatus(key_info.status); |
| 766 next_key.system_code = key_info.system_code; |
| 767 key_information.push_back(next_key); |
| 768 } |
| 769 |
| 770 PostOnMain(callback_factory_.NewCallback( |
| 771 &CdmAdapter::SendSessionKeysChangeInternal, |
| 772 std::string(session_id, session_id_size), has_additional_usable_key, |
| 773 key_information)); |
| 774 } |
| 775 |
| 776 // cdm::Host_6 only. |
| 777 void CdmAdapter::OnSessionUsableKeysChange(const char* session_id, |
| 778 uint32_t session_id_size, |
716 bool has_additional_usable_key) { | 779 bool has_additional_usable_key) { |
717 PostOnMain(callback_factory_.NewCallback( | 780 PostOnMain(callback_factory_.NewCallback( |
718 &CdmAdapter::SendSessionUsableKeysChangeInternal, | 781 &CdmAdapter::SendSessionKeysChangeInternal, |
719 std::string(web_session_id, web_session_id_length), | 782 std::string(session_id, session_id_size), has_additional_usable_key, |
720 has_additional_usable_key)); | 783 std::vector<PP_KeyInformation>())); |
721 } | 784 } |
722 | 785 |
723 void CdmAdapter::OnExpirationChange(const char* web_session_id, | 786 void CdmAdapter::OnExpirationChange(const char* session_id, |
724 uint32_t web_session_id_length, | 787 uint32_t session_id_size, |
725 cdm::Time new_expiry_time) { | 788 cdm::Time new_expiry_time) { |
726 PostOnMain(callback_factory_.NewCallback( | 789 PostOnMain(callback_factory_.NewCallback( |
727 &CdmAdapter::SendExpirationChangeInternal, | 790 &CdmAdapter::SendExpirationChangeInternal, |
728 std::string(web_session_id, web_session_id_length), | 791 std::string(session_id, session_id_size), new_expiry_time)); |
729 new_expiry_time)); | |
730 } | 792 } |
731 | 793 |
732 void CdmAdapter::OnSessionClosed(const char* web_session_id, | 794 void CdmAdapter::OnSessionClosed(const char* session_id, |
733 uint32_t web_session_id_length) { | 795 uint32_t session_id_size) { |
734 PostOnMain(callback_factory_.NewCallback( | 796 PostOnMain( |
735 &CdmAdapter::SendSessionClosedInternal, | 797 callback_factory_.NewCallback(&CdmAdapter::SendSessionClosedInternal, |
736 std::string(web_session_id, web_session_id_length))); | 798 std::string(session_id, session_id_size))); |
737 } | 799 } |
738 | 800 |
739 void CdmAdapter::OnSessionError(const char* web_session_id, | 801 // cdm::Host_6 only. |
740 uint32_t web_session_id_length, | 802 void CdmAdapter::OnSessionError(const char* session_id, |
| 803 uint32_t session_id_size, |
741 cdm::Error error, | 804 cdm::Error error, |
742 uint32_t system_code, | 805 uint32_t system_code, |
743 const char* error_message, | 806 const char* error_message, |
744 uint32_t error_message_length) { | 807 uint32_t error_message_size) { |
745 PostOnMain(callback_factory_.NewCallback( | 808 PostOnMain(callback_factory_.NewCallback( |
746 &CdmAdapter::SendSessionErrorInternal, | 809 &CdmAdapter::SendSessionErrorInternal, |
747 std::string(web_session_id, web_session_id_length), | 810 std::string(session_id, session_id_size), |
748 SessionError(error, | 811 SessionError(error, system_code, |
749 system_code, | 812 std::string(error_message, error_message_size)))); |
750 std::string(error_message, error_message_length)))); | |
751 } | 813 } |
752 | 814 |
753 // Helpers to pass the event to Pepper. | 815 // Helpers to pass the event to Pepper. |
754 | 816 |
755 void CdmAdapter::SendPromiseResolvedInternal(int32_t result, | 817 void CdmAdapter::SendPromiseResolvedInternal(int32_t result, |
756 uint32_t promise_id) { | 818 uint32_t promise_id) { |
757 PP_DCHECK(result == PP_OK); | 819 PP_DCHECK(result == PP_OK); |
758 pp::ContentDecryptor_Private::PromiseResolved(promise_id); | 820 pp::ContentDecryptor_Private::PromiseResolved(promise_id); |
759 } | 821 } |
760 | 822 |
761 void CdmAdapter::SendPromiseResolvedWithSessionInternal( | 823 void CdmAdapter::SendPromiseResolvedWithSessionInternal( |
762 int32_t result, | 824 int32_t result, |
763 uint32_t promise_id, | 825 uint32_t promise_id, |
764 const std::string& web_session_id) { | 826 const std::string& session_id) { |
765 PP_DCHECK(result == PP_OK); | 827 PP_DCHECK(result == PP_OK); |
766 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id, | 828 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id, |
767 web_session_id); | 829 session_id); |
768 } | |
769 | |
770 void CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal( | |
771 int32_t result, | |
772 uint32_t promise_id, | |
773 std::vector<std::vector<uint8> > key_ids) { | |
774 PP_DCHECK(result == PP_OK); | |
775 pp::ContentDecryptor_Private::PromiseResolvedWithKeyIds(promise_id, key_ids); | |
776 } | 830 } |
777 | 831 |
778 void CdmAdapter::SendPromiseRejectedInternal(int32_t result, | 832 void CdmAdapter::SendPromiseRejectedInternal(int32_t result, |
779 uint32_t promise_id, | 833 uint32_t promise_id, |
780 const SessionError& error) { | 834 const SessionError& error) { |
781 PP_DCHECK(result == PP_OK); | 835 PP_DCHECK(result == PP_OK); |
782 pp::ContentDecryptor_Private::PromiseRejected( | 836 pp::ContentDecryptor_Private::PromiseRejected( |
783 promise_id, | 837 promise_id, |
784 CdmExceptionTypeToPpCdmExceptionType(error.error), | 838 CdmExceptionTypeToPpCdmExceptionType(error.error), |
785 error.system_code, | 839 error.system_code, |
786 error.error_description); | 840 error.error_description); |
787 } | 841 } |
788 | 842 |
789 void CdmAdapter::SendSessionMessageInternal( | 843 void CdmAdapter::SendSessionMessageInternal( |
790 int32_t result, | 844 int32_t result, |
791 const std::string& web_session_id, | 845 const std::string& session_id, |
792 const std::vector<uint8>& message, | 846 cdm::MessageType message_type, |
793 const std::string& destination_url) { | 847 const std::vector<uint8_t>& message) { |
794 PP_DCHECK(result == PP_OK); | 848 PP_DCHECK(result == PP_OK); |
795 | 849 |
796 pp::VarArrayBuffer message_array_buffer(message.size()); | 850 pp::VarArrayBuffer message_array_buffer(message.size()); |
797 if (message.size() > 0) { | 851 if (message.size() > 0) { |
798 memcpy(message_array_buffer.Map(), message.data(), message.size()); | 852 memcpy(message_array_buffer.Map(), message.data(), message.size()); |
799 } | 853 } |
800 | 854 |
801 pp::ContentDecryptor_Private::SessionMessage( | 855 pp::ContentDecryptor_Private::SessionMessage( |
802 web_session_id, message_array_buffer, destination_url); | 856 session_id, CdmMessageTypeToPpMessageType(message_type), |
803 } | 857 message_array_buffer); |
804 | |
805 void CdmAdapter::SendSessionReadyInternal(int32_t result, | |
806 const std::string& web_session_id) { | |
807 PP_DCHECK(result == PP_OK); | |
808 pp::ContentDecryptor_Private::SessionReady(web_session_id); | |
809 } | 858 } |
810 | 859 |
811 void CdmAdapter::SendSessionClosedInternal(int32_t result, | 860 void CdmAdapter::SendSessionClosedInternal(int32_t result, |
812 const std::string& web_session_id) { | 861 const std::string& session_id) { |
813 PP_DCHECK(result == PP_OK); | 862 PP_DCHECK(result == PP_OK); |
814 pp::ContentDecryptor_Private::SessionClosed(web_session_id); | 863 pp::ContentDecryptor_Private::SessionClosed(session_id); |
815 } | 864 } |
816 | 865 |
817 void CdmAdapter::SendSessionErrorInternal(int32_t result, | 866 void CdmAdapter::SendSessionErrorInternal(int32_t result, |
818 const std::string& web_session_id, | 867 const std::string& session_id, |
819 const SessionError& error) { | 868 const SessionError& error) { |
820 PP_DCHECK(result == PP_OK); | 869 PP_DCHECK(result == PP_OK); |
821 pp::ContentDecryptor_Private::SessionError( | 870 pp::ContentDecryptor_Private::SessionError( |
822 web_session_id, | 871 session_id, CdmExceptionTypeToPpCdmExceptionType(error.error), |
823 CdmExceptionTypeToPpCdmExceptionType(error.error), | 872 error.system_code, error.error_description); |
824 error.system_code, | |
825 error.error_description); | |
826 } | 873 } |
827 | 874 |
828 void CdmAdapter::SendSessionUsableKeysChangeInternal( | 875 void CdmAdapter::SendSessionKeysChangeInternal( |
829 int32_t result, | 876 int32_t result, |
830 const std::string& web_session_id, | 877 const std::string& session_id, |
831 bool has_additional_usable_key) { | 878 bool has_additional_usable_key, |
| 879 const std::vector<PP_KeyInformation>& key_info) { |
832 PP_DCHECK(result == PP_OK); | 880 PP_DCHECK(result == PP_OK); |
833 pp::ContentDecryptor_Private::SessionKeysChange(web_session_id, | 881 pp::ContentDecryptor_Private::SessionKeysChange( |
834 has_additional_usable_key); | 882 session_id, has_additional_usable_key, key_info); |
835 } | 883 } |
836 | 884 |
837 void CdmAdapter::SendExpirationChangeInternal(int32_t result, | 885 void CdmAdapter::SendExpirationChangeInternal(int32_t result, |
838 const std::string& web_session_id, | 886 const std::string& session_id, |
839 cdm::Time new_expiry_time) { | 887 cdm::Time new_expiry_time) { |
840 PP_DCHECK(result == PP_OK); | 888 PP_DCHECK(result == PP_OK); |
841 pp::ContentDecryptor_Private::SessionExpirationChange(web_session_id, | 889 pp::ContentDecryptor_Private::SessionExpirationChange(session_id, |
842 new_expiry_time); | 890 new_expiry_time); |
843 } | 891 } |
844 | 892 |
845 void CdmAdapter::DeliverBlock(int32_t result, | 893 void CdmAdapter::DeliverBlock(int32_t result, |
846 const cdm::Status& status, | 894 const cdm::Status& status, |
847 const LinkedDecryptedBlock& decrypted_block, | 895 const LinkedDecryptedBlock& decrypted_block, |
848 const PP_DecryptTrackingInfo& tracking_info) { | 896 const PP_DecryptTrackingInfo& tracking_info) { |
849 PP_DCHECK(result == PP_OK); | 897 PP_DCHECK(result == PP_OK); |
850 PP_DecryptedBlockInfo decrypted_block_info = {}; | 898 PP_DecryptedBlockInfo decrypted_block_info = {}; |
851 decrypted_block_info.tracking_info = tracking_info; | 899 decrypted_block_info.tracking_info = tracking_info; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 | 1074 |
1027 #if !defined(NDEBUG) | 1075 #if !defined(NDEBUG) |
1028 void CdmAdapter::LogToConsole(const pp::Var& value) { | 1076 void CdmAdapter::LogToConsole(const pp::Var& value) { |
1029 PP_DCHECK(IsMainThread()); | 1077 PP_DCHECK(IsMainThread()); |
1030 const PPB_Console* console = reinterpret_cast<const PPB_Console*>( | 1078 const PPB_Console* console = reinterpret_cast<const PPB_Console*>( |
1031 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); | 1079 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); |
1032 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var()); | 1080 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var()); |
1033 } | 1081 } |
1034 #endif // !defined(NDEBUG) | 1082 #endif // !defined(NDEBUG) |
1035 | 1083 |
1036 void CdmAdapter::SendPlatformChallenge( | 1084 void CdmAdapter::SendPlatformChallenge(const char* service_id, |
1037 const char* service_id, uint32_t service_id_length, | 1085 uint32_t service_id_size, |
1038 const char* challenge, uint32_t challenge_length) { | 1086 const char* challenge, |
| 1087 uint32_t challenge_size) { |
1039 #if defined(OS_CHROMEOS) | 1088 #if defined(OS_CHROMEOS) |
1040 pp::VarArrayBuffer challenge_var(challenge_length); | 1089 pp::VarArrayBuffer challenge_var(challenge_size); |
1041 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); | 1090 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); |
1042 memcpy(var_data, challenge, challenge_length); | 1091 memcpy(var_data, challenge, challenge_size); |
1043 | 1092 |
1044 std::string service_id_str(service_id, service_id_length); | 1093 std::string service_id_str(service_id, service_id_size); |
1045 | 1094 |
1046 linked_ptr<PepperPlatformChallengeResponse> response( | 1095 linked_ptr<PepperPlatformChallengeResponse> response( |
1047 new PepperPlatformChallengeResponse()); | 1096 new PepperPlatformChallengeResponse()); |
1048 | 1097 |
1049 int32_t result = platform_verification_.ChallengePlatform( | 1098 int32_t result = platform_verification_.ChallengePlatform( |
1050 pp::Var(service_id_str), | 1099 pp::Var(service_id_str), |
1051 challenge_var, | 1100 challenge_var, |
1052 &response->signed_data, | 1101 &response->signed_data, |
1053 &response->signed_data_signature, | 1102 &response->signed_data_signature, |
1054 &response->platform_key_certificate, | 1103 &response->platform_key_certificate, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 callback_factory_.NewCallback( | 1140 callback_factory_.NewCallback( |
1092 &CdmAdapter::QueryOutputProtectionStatusDone)); | 1141 &CdmAdapter::QueryOutputProtectionStatusDone)); |
1093 if (result == PP_OK_COMPLETIONPENDING) { | 1142 if (result == PP_OK_COMPLETIONPENDING) { |
1094 query_output_protection_in_progress_ = true; | 1143 query_output_protection_in_progress_ = true; |
1095 ReportOutputProtectionQuery(); | 1144 ReportOutputProtectionQuery(); |
1096 return; | 1145 return; |
1097 } | 1146 } |
1098 | 1147 |
1099 // Fall through on error and issue an empty OnQueryOutputProtectionStatus(). | 1148 // Fall through on error and issue an empty OnQueryOutputProtectionStatus(). |
1100 PP_DCHECK(result != PP_OK); | 1149 PP_DCHECK(result != PP_OK); |
| 1150 CDM_DLOG() << __FUNCTION__ << " failed, result = " << result; |
1101 #endif | 1151 #endif |
1102 | 1152 cdm_->OnQueryOutputProtectionStatus(cdm::kQueryFailed, 0, 0); |
1103 cdm_->OnQueryOutputProtectionStatus(0, 0); | |
1104 } | 1153 } |
1105 | 1154 |
1106 void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type, | 1155 void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type, |
1107 cdm::Status decoder_status) { | 1156 cdm::Status decoder_status) { |
1108 switch (stream_type) { | 1157 switch (stream_type) { |
1109 case cdm::kStreamTypeAudio: | 1158 case cdm::kStreamTypeAudio: |
1110 PP_DCHECK(deferred_initialize_audio_decoder_); | 1159 PP_DCHECK(deferred_initialize_audio_decoder_); |
1111 CallOnMain( | 1160 CallOnMain( |
1112 callback_factory_.NewCallback(&CdmAdapter::DecoderInitializeDone, | 1161 callback_factory_.NewCallback(&CdmAdapter::DecoderInitializeDone, |
1113 PP_DECRYPTORSTREAMTYPE_AUDIO, | 1162 PP_DECRYPTORSTREAMTYPE_AUDIO, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 void CdmAdapter::EnableProtectionDone(int32_t result) { | 1264 void CdmAdapter::EnableProtectionDone(int32_t result) { |
1216 // Does nothing since clients must call QueryOutputProtectionStatus() to | 1265 // Does nothing since clients must call QueryOutputProtectionStatus() to |
1217 // inspect the protection status on a regular basis. | 1266 // inspect the protection status on a regular basis. |
1218 CDM_DLOG() << __FUNCTION__ << " : " << result; | 1267 CDM_DLOG() << __FUNCTION__ << " : " << result; |
1219 } | 1268 } |
1220 | 1269 |
1221 void CdmAdapter::QueryOutputProtectionStatusDone(int32_t result) { | 1270 void CdmAdapter::QueryOutputProtectionStatusDone(int32_t result) { |
1222 PP_DCHECK(query_output_protection_in_progress_); | 1271 PP_DCHECK(query_output_protection_in_progress_); |
1223 query_output_protection_in_progress_ = false; | 1272 query_output_protection_in_progress_ = false; |
1224 | 1273 |
1225 // Return a protection status of none on error. | 1274 // Return a query status of failed on error. |
1226 if (result != PP_OK) | 1275 cdm::QueryResult query_result; |
| 1276 if (result != PP_OK) { |
| 1277 CDM_DLOG() << __FUNCTION__ << " failed, result = " << result; |
1227 output_link_mask_ = output_protection_mask_ = 0; | 1278 output_link_mask_ = output_protection_mask_ = 0; |
1228 else | 1279 query_result = cdm::kQueryFailed; |
| 1280 } else { |
| 1281 query_result = cdm::kQuerySucceeded; |
1229 ReportOutputProtectionQueryResult(); | 1282 ReportOutputProtectionQueryResult(); |
| 1283 } |
1230 | 1284 |
1231 cdm_->OnQueryOutputProtectionStatus(output_link_mask_, | 1285 cdm_->OnQueryOutputProtectionStatus(query_result, output_link_mask_, |
1232 output_protection_mask_); | 1286 output_protection_mask_); |
1233 } | 1287 } |
1234 #endif | 1288 #endif |
1235 | 1289 |
1236 CdmAdapter::SessionError::SessionError(cdm::Error error, | 1290 CdmAdapter::SessionError::SessionError(cdm::Error error, |
1237 uint32_t system_code, | 1291 uint32_t system_code, |
1238 std::string error_description) | 1292 std::string error_description) |
1239 : error(error), | 1293 : error(error), |
1240 system_code(system_code), | 1294 system_code(system_code), |
1241 error_description(error_description) { | 1295 error_description(error_description) { |
1242 } | 1296 } |
1243 | 1297 |
1244 void* GetCdmHost(int host_interface_version, void* user_data) { | 1298 void* GetCdmHost(int host_interface_version, void* user_data) { |
1245 if (!host_interface_version || !user_data) | 1299 if (!host_interface_version || !user_data) |
1246 return NULL; | 1300 return NULL; |
1247 | 1301 |
1248 static_assert( | 1302 static_assert( |
1249 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_6::kVersion, | 1303 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_7::kVersion, |
1250 "update the code below"); | 1304 "update the code below"); |
1251 | 1305 |
1252 // Ensure IsSupportedCdmHostVersion matches implementation of this function. | 1306 // Ensure IsSupportedCdmHostVersion matches implementation of this function. |
1253 // Always update this DCHECK when updating this function. | 1307 // Always update this DCHECK when updating this function. |
1254 // If this check fails, update this function and DCHECK or update | 1308 // If this check fails, update this function and DCHECK or update |
1255 // IsSupportedCdmHostVersion. | 1309 // IsSupportedCdmHostVersion. |
1256 | 1310 |
1257 PP_DCHECK( | 1311 PP_DCHECK( |
1258 // Future version is not supported. | 1312 // Future version is not supported. |
1259 !IsSupportedCdmHostVersion(cdm::Host_6::kVersion + 1) && | 1313 !IsSupportedCdmHostVersion(cdm::Host_7::kVersion + 1) && |
1260 // Current version is supported. | 1314 // Current version is supported. |
| 1315 IsSupportedCdmHostVersion(cdm::Host_7::kVersion) && |
| 1316 // Include all previous supported versions (if any) here. |
1261 IsSupportedCdmHostVersion(cdm::Host_6::kVersion) && | 1317 IsSupportedCdmHostVersion(cdm::Host_6::kVersion) && |
1262 // Include all previous supported versions (if any) here. | |
1263 // One older than the oldest supported version is not supported. | 1318 // One older than the oldest supported version is not supported. |
1264 !IsSupportedCdmHostVersion(cdm::Host_6::kVersion - 1)); | 1319 !IsSupportedCdmHostVersion(cdm::Host_6::kVersion - 1)); |
1265 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version)); | 1320 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version)); |
1266 | 1321 |
1267 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data); | 1322 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data); |
1268 CDM_DLOG() << "Create CDM Host with version " << host_interface_version; | 1323 CDM_DLOG() << "Create CDM Host with version " << host_interface_version; |
1269 switch (host_interface_version) { | 1324 switch (host_interface_version) { |
| 1325 case cdm::Host_7::kVersion: |
| 1326 return static_cast<cdm::Host_7*>(cdm_adapter); |
1270 case cdm::Host_6::kVersion: | 1327 case cdm::Host_6::kVersion: |
1271 return static_cast<cdm::Host_6*>(cdm_adapter); | 1328 return static_cast<cdm::Host_6*>(cdm_adapter); |
1272 default: | 1329 default: |
1273 PP_NOTREACHED(); | 1330 PP_NOTREACHED(); |
1274 return NULL; | 1331 return NULL; |
1275 } | 1332 } |
1276 } | 1333 } |
1277 | 1334 |
1278 // This object is the global object representing this plugin library as long | 1335 // This object is the global object representing this plugin library as long |
1279 // as it is loaded. | 1336 // as it is loaded. |
(...skipping 19 matching lines...) Expand all Loading... |
1299 } // namespace media | 1356 } // namespace media |
1300 | 1357 |
1301 namespace pp { | 1358 namespace pp { |
1302 | 1359 |
1303 // Factory function for your specialization of the Module object. | 1360 // Factory function for your specialization of the Module object. |
1304 Module* CreateModule() { | 1361 Module* CreateModule() { |
1305 return new media::CdmAdapterModule(); | 1362 return new media::CdmAdapterModule(); |
1306 } | 1363 } |
1307 | 1364 |
1308 } // namespace pp | 1365 } // namespace pp |
OLD | NEW |