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