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