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

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

Issue 811923002: Changes to support CDM_7 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pass array Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cdm/ppapi/cdm_adapter.h" 5 #include "media/cdm/ppapi/cdm_adapter.h"
6 6
7 #include "media/base/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
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
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
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>(message, message + message_size)));
dcheng 2015/01/08 19:12:30 uint8_t
jrummell 2015/01/08 20:12:11 Done.
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>(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(int32_t result,
790 int32_t result, 844 const std::string& session_id,
791 const std::string& web_session_id, 845 cdm::MessageType message_type,
792 const std::vector<uint8>& message, 846 const std::vector<uint8>& message) {
dcheng 2015/01/08 19:12:30 uint8_t
jrummell 2015/01/08 20:12:11 Done.
793 const std::string& destination_url) {
794 PP_DCHECK(result == PP_OK); 847 PP_DCHECK(result == PP_OK);
795 848
796 pp::VarArrayBuffer message_array_buffer(message.size()); 849 pp::VarArrayBuffer message_array_buffer(message.size());
797 if (message.size() > 0) { 850 if (message.size() > 0) {
798 memcpy(message_array_buffer.Map(), message.data(), message.size()); 851 memcpy(message_array_buffer.Map(), message.data(), message.size());
799 } 852 }
800 853
801 pp::ContentDecryptor_Private::SessionMessage( 854 pp::ContentDecryptor_Private::SessionMessage(
802 web_session_id, message_array_buffer, destination_url); 855 session_id, CdmMessageTypeToPpMessageType(message_type),
803 } 856 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 } 857 }
810 858
811 void CdmAdapter::SendSessionClosedInternal(int32_t result, 859 void CdmAdapter::SendSessionClosedInternal(int32_t result,
812 const std::string& web_session_id) { 860 const std::string& session_id) {
813 PP_DCHECK(result == PP_OK); 861 PP_DCHECK(result == PP_OK);
814 pp::ContentDecryptor_Private::SessionClosed(web_session_id); 862 pp::ContentDecryptor_Private::SessionClosed(session_id);
815 } 863 }
816 864
817 void CdmAdapter::SendSessionErrorInternal(int32_t result, 865 void CdmAdapter::SendSessionErrorInternal(int32_t result,
818 const std::string& web_session_id, 866 const std::string& session_id,
819 const SessionError& error) { 867 const SessionError& error) {
820 PP_DCHECK(result == PP_OK); 868 PP_DCHECK(result == PP_OK);
821 pp::ContentDecryptor_Private::SessionError( 869 pp::ContentDecryptor_Private::SessionError(
822 web_session_id, 870 session_id, CdmExceptionTypeToPpCdmExceptionType(error.error),
823 CdmExceptionTypeToPpCdmExceptionType(error.error), 871 error.system_code, error.error_description);
824 error.system_code,
825 error.error_description);
826 } 872 }
827 873
828 void CdmAdapter::SendSessionUsableKeysChangeInternal( 874 void CdmAdapter::SendSessionKeysChangeInternal(
829 int32_t result, 875 int32_t result,
830 const std::string& web_session_id, 876 const std::string& session_id,
831 bool has_additional_usable_key) { 877 bool has_additional_usable_key,
878 std::vector<PP_KeyInformation> key_info) {
832 PP_DCHECK(result == PP_OK); 879 PP_DCHECK(result == PP_OK);
833 pp::ContentDecryptor_Private::SessionKeysChange(web_session_id, 880 pp::ContentDecryptor_Private::SessionKeysChange(
834 has_additional_usable_key); 881 session_id, has_additional_usable_key, key_info);
835 } 882 }
836 883
837 void CdmAdapter::SendExpirationChangeInternal(int32_t result, 884 void CdmAdapter::SendExpirationChangeInternal(int32_t result,
838 const std::string& web_session_id, 885 const std::string& session_id,
839 cdm::Time new_expiry_time) { 886 cdm::Time new_expiry_time) {
840 PP_DCHECK(result == PP_OK); 887 PP_DCHECK(result == PP_OK);
841 pp::ContentDecryptor_Private::SessionExpirationChange(web_session_id, 888 pp::ContentDecryptor_Private::SessionExpirationChange(session_id,
842 new_expiry_time); 889 new_expiry_time);
843 } 890 }
844 891
845 void CdmAdapter::DeliverBlock(int32_t result, 892 void CdmAdapter::DeliverBlock(int32_t result,
846 const cdm::Status& status, 893 const cdm::Status& status,
847 const LinkedDecryptedBlock& decrypted_block, 894 const LinkedDecryptedBlock& decrypted_block,
848 const PP_DecryptTrackingInfo& tracking_info) { 895 const PP_DecryptTrackingInfo& tracking_info) {
849 PP_DCHECK(result == PP_OK); 896 PP_DCHECK(result == PP_OK);
850 PP_DecryptedBlockInfo decrypted_block_info = {}; 897 PP_DecryptedBlockInfo decrypted_block_info = {};
851 decrypted_block_info.tracking_info = tracking_info; 898 decrypted_block_info.tracking_info = tracking_info;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 1073
1027 #if !defined(NDEBUG) 1074 #if !defined(NDEBUG)
1028 void CdmAdapter::LogToConsole(const pp::Var& value) { 1075 void CdmAdapter::LogToConsole(const pp::Var& value) {
1029 PP_DCHECK(IsMainThread()); 1076 PP_DCHECK(IsMainThread());
1030 const PPB_Console* console = reinterpret_cast<const PPB_Console*>( 1077 const PPB_Console* console = reinterpret_cast<const PPB_Console*>(
1031 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); 1078 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE));
1032 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var()); 1079 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var());
1033 } 1080 }
1034 #endif // !defined(NDEBUG) 1081 #endif // !defined(NDEBUG)
1035 1082
1036 void CdmAdapter::SendPlatformChallenge( 1083 void CdmAdapter::SendPlatformChallenge(const char* service_id,
1037 const char* service_id, uint32_t service_id_length, 1084 uint32_t service_id_size,
1038 const char* challenge, uint32_t challenge_length) { 1085 const char* challenge,
1086 uint32_t challenge_size) {
1039 #if defined(OS_CHROMEOS) 1087 #if defined(OS_CHROMEOS)
1040 pp::VarArrayBuffer challenge_var(challenge_length); 1088 pp::VarArrayBuffer challenge_var(challenge_size);
1041 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); 1089 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map());
1042 memcpy(var_data, challenge, challenge_length); 1090 memcpy(var_data, challenge, challenge_size);
1043 1091
1044 std::string service_id_str(service_id, service_id_length); 1092 std::string service_id_str(service_id, service_id_size);
1045 1093
1046 linked_ptr<PepperPlatformChallengeResponse> response( 1094 linked_ptr<PepperPlatformChallengeResponse> response(
1047 new PepperPlatformChallengeResponse()); 1095 new PepperPlatformChallengeResponse());
1048 1096
1049 int32_t result = platform_verification_.ChallengePlatform( 1097 int32_t result = platform_verification_.ChallengePlatform(
1050 pp::Var(service_id_str), 1098 pp::Var(service_id_str),
1051 challenge_var, 1099 challenge_var,
1052 &response->signed_data, 1100 &response->signed_data,
1053 &response->signed_data_signature, 1101 &response->signed_data_signature,
1054 &response->platform_key_certificate, 1102 &response->platform_key_certificate,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 callback_factory_.NewCallback( 1139 callback_factory_.NewCallback(
1092 &CdmAdapter::QueryOutputProtectionStatusDone)); 1140 &CdmAdapter::QueryOutputProtectionStatusDone));
1093 if (result == PP_OK_COMPLETIONPENDING) { 1141 if (result == PP_OK_COMPLETIONPENDING) {
1094 query_output_protection_in_progress_ = true; 1142 query_output_protection_in_progress_ = true;
1095 ReportOutputProtectionQuery(); 1143 ReportOutputProtectionQuery();
1096 return; 1144 return;
1097 } 1145 }
1098 1146
1099 // Fall through on error and issue an empty OnQueryOutputProtectionStatus(). 1147 // Fall through on error and issue an empty OnQueryOutputProtectionStatus().
1100 PP_DCHECK(result != PP_OK); 1148 PP_DCHECK(result != PP_OK);
1149 CDM_DLOG() << __FUNCTION__ << " failed, result = " << result;
1101 #endif 1150 #endif
1102 1151 cdm_->OnQueryOutputProtectionStatus(cdm::kQueryFailed, 0, 0);
1103 cdm_->OnQueryOutputProtectionStatus(0, 0);
1104 } 1152 }
1105 1153
1106 void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type, 1154 void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type,
1107 cdm::Status decoder_status) { 1155 cdm::Status decoder_status) {
1108 switch (stream_type) { 1156 switch (stream_type) {
1109 case cdm::kStreamTypeAudio: 1157 case cdm::kStreamTypeAudio:
1110 PP_DCHECK(deferred_initialize_audio_decoder_); 1158 PP_DCHECK(deferred_initialize_audio_decoder_);
1111 CallOnMain( 1159 CallOnMain(
1112 callback_factory_.NewCallback(&CdmAdapter::DecoderInitializeDone, 1160 callback_factory_.NewCallback(&CdmAdapter::DecoderInitializeDone,
1113 PP_DECRYPTORSTREAMTYPE_AUDIO, 1161 PP_DECRYPTORSTREAMTYPE_AUDIO,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 // Does nothing since clients must call QueryOutputProtectionStatus() to 1264 // Does nothing since clients must call QueryOutputProtectionStatus() to
1217 // inspect the protection status on a regular basis. 1265 // inspect the protection status on a regular basis.
1218 CDM_DLOG() << __FUNCTION__ << " : " << result; 1266 CDM_DLOG() << __FUNCTION__ << " : " << result;
1219 } 1267 }
1220 1268
1221 void CdmAdapter::QueryOutputProtectionStatusDone(int32_t result) { 1269 void CdmAdapter::QueryOutputProtectionStatusDone(int32_t result) {
1222 PP_DCHECK(query_output_protection_in_progress_); 1270 PP_DCHECK(query_output_protection_in_progress_);
1223 query_output_protection_in_progress_ = false; 1271 query_output_protection_in_progress_ = false;
1224 1272
1225 // Return a protection status of none on error. 1273 // Return a protection status of none on error.
1226 if (result != PP_OK) 1274 cdm::ProtectionResult protection_result;
1275 if (result != PP_OK) {
1276 CDM_DLOG() << __FUNCTION__ << " failed, result = " << result;
1227 output_link_mask_ = output_protection_mask_ = 0; 1277 output_link_mask_ = output_protection_mask_ = 0;
1228 else 1278 protection_result = cdm::kQueryFailed;
1279 } else {
1280 protection_result = cdm::kQuerySucceeded;
1229 ReportOutputProtectionQueryResult(); 1281 ReportOutputProtectionQueryResult();
1282 }
1230 1283
1231 cdm_->OnQueryOutputProtectionStatus(output_link_mask_, 1284 cdm_->OnQueryOutputProtectionStatus(protection_result, output_link_mask_,
1232 output_protection_mask_); 1285 output_protection_mask_);
1233 } 1286 }
1234 #endif 1287 #endif
1235 1288
1236 CdmAdapter::SessionError::SessionError(cdm::Error error, 1289 CdmAdapter::SessionError::SessionError(cdm::Error error,
1237 uint32_t system_code, 1290 uint32_t system_code,
1238 std::string error_description) 1291 std::string error_description)
1239 : error(error), 1292 : error(error),
1240 system_code(system_code), 1293 system_code(system_code),
1241 error_description(error_description) { 1294 error_description(error_description) {
1242 } 1295 }
1243 1296
1244 void* GetCdmHost(int host_interface_version, void* user_data) { 1297 void* GetCdmHost(int host_interface_version, void* user_data) {
1245 if (!host_interface_version || !user_data) 1298 if (!host_interface_version || !user_data)
1246 return NULL; 1299 return NULL;
1247 1300
1248 static_assert( 1301 static_assert(
1249 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_6::kVersion, 1302 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_7::kVersion,
1250 "update the code below"); 1303 "update the code below");
1251 1304
1252 // Ensure IsSupportedCdmHostVersion matches implementation of this function. 1305 // Ensure IsSupportedCdmHostVersion matches implementation of this function.
1253 // Always update this DCHECK when updating this function. 1306 // Always update this DCHECK when updating this function.
1254 // If this check fails, update this function and DCHECK or update 1307 // If this check fails, update this function and DCHECK or update
1255 // IsSupportedCdmHostVersion. 1308 // IsSupportedCdmHostVersion.
1256 1309
1257 PP_DCHECK( 1310 PP_DCHECK(
1258 // Future version is not supported. 1311 // Future version is not supported.
1259 !IsSupportedCdmHostVersion(cdm::Host_6::kVersion + 1) && 1312 !IsSupportedCdmHostVersion(cdm::Host_7::kVersion + 1) &&
1260 // Current version is supported. 1313 // Current version is supported.
1314 IsSupportedCdmHostVersion(cdm::Host_7::kVersion) &&
1315 // Include all previous supported versions (if any) here.
1261 IsSupportedCdmHostVersion(cdm::Host_6::kVersion) && 1316 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. 1317 // One older than the oldest supported version is not supported.
1264 !IsSupportedCdmHostVersion(cdm::Host_6::kVersion - 1)); 1318 !IsSupportedCdmHostVersion(cdm::Host_6::kVersion - 1));
1265 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version)); 1319 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version));
1266 1320
1267 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data); 1321 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data);
1268 CDM_DLOG() << "Create CDM Host with version " << host_interface_version; 1322 CDM_DLOG() << "Create CDM Host with version " << host_interface_version;
1269 switch (host_interface_version) { 1323 switch (host_interface_version) {
1324 case cdm::Host_7::kVersion:
1325 return static_cast<cdm::Host_7*>(cdm_adapter);
1270 case cdm::Host_6::kVersion: 1326 case cdm::Host_6::kVersion:
1271 return static_cast<cdm::Host_6*>(cdm_adapter); 1327 return static_cast<cdm::Host_6*>(cdm_adapter);
1272 default: 1328 default:
1273 PP_NOTREACHED(); 1329 PP_NOTREACHED();
1274 return NULL; 1330 return NULL;
1275 } 1331 }
1276 } 1332 }
1277 1333
1278 // This object is the global object representing this plugin library as long 1334 // This object is the global object representing this plugin library as long
1279 // as it is loaded. 1335 // as it is loaded.
(...skipping 19 matching lines...) Expand all
1299 } // namespace media 1355 } // namespace media
1300 1356
1301 namespace pp { 1357 namespace pp {
1302 1358
1303 // Factory function for your specialization of the Module object. 1359 // Factory function for your specialization of the Module object.
1304 Module* CreateModule() { 1360 Module* CreateModule() {
1305 return new media::CdmAdapterModule(); 1361 return new media::CdmAdapterModule();
1306 } 1362 }
1307 1363
1308 } // namespace pp 1364 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698