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

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

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cdm_promise template Created 6 years, 7 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/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 13
13 #if defined(CHECK_DOCUMENT_URL) 14 #if defined(CHECK_DOCUMENT_URL)
14 #include "ppapi/cpp/dev/url_util_dev.h" 15 #include "ppapi/cpp/dev/url_util_dev.h"
15 #include "ppapi/cpp/instance_handle.h" 16 #include "ppapi/cpp/instance_handle.h"
16 #endif // defined(CHECK_DOCUMENT_URL) 17 #endif // defined(CHECK_DOCUMENT_URL)
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 case PP_DECRYPTORSTREAMTYPE_AUDIO: 204 case PP_DECRYPTORSTREAMTYPE_AUDIO:
204 return cdm::kStreamTypeAudio; 205 return cdm::kStreamTypeAudio;
205 case PP_DECRYPTORSTREAMTYPE_VIDEO: 206 case PP_DECRYPTORSTREAMTYPE_VIDEO:
206 return cdm::kStreamTypeVideo; 207 return cdm::kStreamTypeVideo;
207 } 208 }
208 209
209 PP_NOTREACHED(); 210 PP_NOTREACHED();
210 return cdm::kStreamTypeVideo; 211 return cdm::kStreamTypeVideo;
211 } 212 }
212 213
214 cdm::SessionType PpSessionTypeToCdmSessionType(PP_SessionType session_type) {
215 switch (session_type) {
216 case PP_SESSIONTYPE_TEMPORARY:
217 return cdm::kTemporary;
218 case PP_SESSIONTYPE_PERSISTENT:
219 return cdm::kPersistent;
220 default:
221 PP_NOTREACHED();
222 return cdm::kTemporary;
223 }
224 }
225
226 PP_ExceptionCodeType CdmExceptionTypeToPpExceptionType(
227 cdm::MediaKeyException exception_code) {
228 switch (exception_code) {
229 case cdm::kIndexSizeError:
230 return PP_EXCEPTIONCODETYPE_INDEXSIZEERROR;
231 case cdm::kHierarchyRequestError:
232 return PP_EXCEPTIONCODETYPE_HIERARCHYREQUESTERROR;
233 case cdm::kWrongDocumentError:
234 return PP_EXCEPTIONCODETYPE_WRONGDOCUMENTERROR;
235 case cdm::kInvalidCharacterError:
236 return PP_EXCEPTIONCODETYPE_INVALIDCHARACTERERROR;
237 case cdm::kNoModificationAllowedError:
238 return PP_EXCEPTIONCODETYPE_NOMODIFICATIONALLOWEDERROR;
239 case cdm::kNotFoundError:
240 return PP_EXCEPTIONCODETYPE_NOTFOUNDERROR;
241 case cdm::kNotSupportedError:
242 return PP_EXCEPTIONCODETYPE_NOTSUPPORTEDERROR;
243 case cdm::kInvalidStateError:
244 return PP_EXCEPTIONCODETYPE_INVALIDSTATEERROR;
245 case cdm::kSyntaxError:
246 return PP_EXCEPTIONCODETYPE_SYNTAXERROR;
247 case cdm::kInvalidModificationError:
248 return PP_EXCEPTIONCODETYPE_INVALIDMODIFICATIONERROR;
249 case cdm::kNamespaceError:
250 return PP_EXCEPTIONCODETYPE_NAMESPACEERROR;
251 case cdm::kInvalidAccessError:
252 return PP_EXCEPTIONCODETYPE_INVALIDACCESSERROR;
253 case cdm::kSecurityError:
254 return PP_EXCEPTIONCODETYPE_SECURITYERROR;
255 case cdm::kNetworkError:
256 return PP_EXCEPTIONCODETYPE_NETWORKERROR;
257 case cdm::kAbortError:
258 return PP_EXCEPTIONCODETYPE_ABORTERROR;
259 case cdm::kUrlMismatchError:
260 return PP_EXCEPTIONCODETYPE_URLMISMATCHERROR;
261 case cdm::kQuotaExceededError:
262 return PP_EXCEPTIONCODETYPE_QUOTAEXCEEDEDERROR;
263 case cdm::kTimeoutError:
264 return PP_EXCEPTIONCODETYPE_TIMEOUTERROR;
265 case cdm::kInvalidNodeTypeError:
266 return PP_EXCEPTIONCODETYPE_INVALIDNODETYPEERROR;
267 case cdm::kDataCloneError:
268 return PP_EXCEPTIONCODETYPE_DATACLONEERROR;
269 case cdm::kEncodingError:
270 return PP_EXCEPTIONCODETYPE_ENCODINGERROR;
271 case cdm::kNotReadableError:
272 return PP_EXCEPTIONCODETYPE_NOTREADABLEERROR;
273 case cdm::kDataError:
274 return PP_EXCEPTIONCODETYPE_DATAERROR;
275 case cdm::kOperationError:
276 return PP_EXCEPTIONCODETYPE_OPERATIONERROR;
277 case cdm::kVersionError:
278 return PP_EXCEPTIONCODETYPE_VERSIONERROR;
279 case cdm::kMediaKeyErrorUnknownError:
280 return PP_EXCEPTIONCODETYPE_UNKNOWNERROR;
281 case cdm::kMediaKeyErrorClientError:
282 return PP_EXCEPTIONCODETYPE_CLIENTERROR;
283 case cdm::kMediaKeyErrorOutputError:
284 return PP_EXCEPTIONCODETYPE_OUTPUTERROR;
285 default:
286 NOTREACHED();
287 return PP_EXCEPTIONCODETYPE_SECURITYERROR;
288 }
289 }
290
291 /*
292 PP_ExceptionCodeType MediaKeysExceptionTypeToPpExceptionType(
jrummell 2014/05/08 23:37:46 Will remove this.
jrummell 2014/05/09 00:55:23 Done.
293 media::MediaKeys::MediaKeysException exception_code) {
294 switch (exception_code) {
295 case media::MediaKeys::MEDIA_KEYS_EXCEPTION_INDEX_SIZE_ERROR:
296 return PP_EXCEPTIONCODETYPE_INDEXSIZEERROR;
297 case media::MediaKeys::MEDIA_KEYS_EXCEPTION_HIERARCHY_REQUEST_ERROR:
298 return PP_EXCEPTIONCODETYPE_HIERARCHYREQUESTERROR;
299 case media::MediaKeys::MEDIA_KEYS_EXCEPTION_WRONG_DOCUMENT_ERROR:
300 return PP_EXCEPTIONCODETYPE_WRONGDOCUMENTERROR;
301 case media::MediaKeys::MEDIA_KEYS_EXCEPTION_INVALID_CHARACTER_ERROR:
302 return PP_EXCEPTIONCODETYPE_INVALIDCHARACTERERROR;
303 case media::MediaKeys::MEDIA_KEYS_EXCEPTION_NO_MODIFICATION_ALLOWED_ERROR:
304 return PP_EXCEPTIONCODETYPE_NOMODIFICATIONALLOWEDERROR;
305 case media::MediaKeys::MEDIA_KEYS_EXCEPTION_NOT_FOUND_ERROR:
306 return PP_EXCEPTIONCODETYPE_NOTFOUNDERROR;
307 case media::MediaKeys::MEDIA_KEYS_EXCEPTION_NOT_SUPPORTED_ERROR:
308 return PP_EXCEPTIONCODETYPE_NOTSUPPORTEDERROR;
309 case media::MediaKeys::kInvalidStateError:
310 return PP_EXCEPTIONCODETYPE_INVALIDSTATEERROR;
311 case media::MediaKeys::kSyntaxError:
312 return PP_EXCEPTIONCODETYPE_SYNTAXERROR;
313 case media::MediaKeys::kInvalidModificationError:
314 return PP_EXCEPTIONCODETYPE_INVALIDMODIFICATIONERROR;
315 case media::MediaKeys::kNamespaceError:
316 return PP_EXCEPTIONCODETYPE_NAMESPACEERROR;
317 case media::MediaKeys::kInvalidAccessError:
318 return PP_EXCEPTIONCODETYPE_INVALIDACCESSERROR;
319 case media::MediaKeys::kSecurityError:
320 return PP_EXCEPTIONCODETYPE_SECURITYERROR;
321 case media::MediaKeys::kNetworkError:
322 return PP_EXCEPTIONCODETYPE_NETWORKERROR;
323 case media::MediaKeys::kAbortError:
324 return PP_EXCEPTIONCODETYPE_ABORTERROR;
325 case media::MediaKeys::kUrlMismatchError:
326 return PP_EXCEPTIONCODETYPE_URLMISMATCHERROR;
327 case media::MediaKeys::kQuotaExceededError:
328 return PP_EXCEPTIONCODETYPE_QUOTAEXCEEDEDERROR;
329 case media::MediaKeys::kTimeoutError:
330 return PP_EXCEPTIONCODETYPE_TIMEOUTERROR;
331 case media::MediaKeys::kInvalidNodeTypeError:
332 return PP_EXCEPTIONCODETYPE_INVALIDNODETYPEERROR;
333 case media::MediaKeys::kDataCloneError:
334 return PP_EXCEPTIONCODETYPE_DATACLONEERROR;
335 case media::MediaKeys::kEncodingError:
336 return PP_EXCEPTIONCODETYPE_ENCODINGERROR;
337 case media::MediaKeys::kNotReadableError:
338 return PP_EXCEPTIONCODETYPE_NOTREADABLEERROR;
339 case media::MediaKeys::kDataError:
340 return PP_EXCEPTIONCODETYPE_DATAERROR;
341 case media::MediaKeys::kOperationError:
342 return PP_EXCEPTIONCODETYPE_OPERATIONERROR;
343 case media::MediaKeys::kVersionError:
344 return PP_EXCEPTIONCODETYPE_VERSIONERROR;
345 case media::MediaKeys::kMediaKeyErrorUnknownError:
346 return PP_EXCEPTIONCODETYPE_UNKNOWNERROR;
347 case media::MediaKeys::kMediaKeyErrorClientError:
348 return PP_EXCEPTIONCODETYPE_CLIENTERROR;
349 case media::MediaKeys::kMediaKeyErrorOutputError:
350 return PP_EXCEPTIONCODETYPE_OUTPUTERROR;
351 default:
352 NOTREACHED();
353 return PP_EXCEPTIONCODETYPE_SECURITYERROR;
354 }
355 }
356 */
213 } // namespace 357 } // namespace
214 358
215 namespace media { 359 namespace media {
216 360
217 CdmAdapter::CdmAdapter(PP_Instance instance, pp::Module* module) 361 CdmAdapter::CdmAdapter(PP_Instance instance, pp::Module* module)
218 : pp::Instance(instance), 362 : pp::Instance(instance),
219 pp::ContentDecryptor_Private(this), 363 pp::ContentDecryptor_Private(this),
220 #if defined(OS_CHROMEOS) 364 #if defined(OS_CHROMEOS)
221 output_protection_(this), 365 output_protection_(this),
222 platform_verification_(this), 366 platform_verification_(this),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 424 }
281 #endif // defined(CHECK_DOCUMENT_URL) 425 #endif // defined(CHECK_DOCUMENT_URL)
282 426
283 if (!cdm_ && !CreateCdmInstance(key_system)) 427 if (!cdm_ && !CreateCdmInstance(key_system))
284 return; 428 return;
285 429
286 PP_DCHECK(cdm_); 430 PP_DCHECK(cdm_);
287 key_system_ = key_system; 431 key_system_ = key_system;
288 } 432 }
289 433
290 void CdmAdapter::CreateSession(uint32_t session_id, 434 void CdmAdapter::CreateSession(uint32_t promise_id,
291 const std::string& content_type, 435 const std::string& init_data_type,
292 pp::VarArrayBuffer init_data) { 436 pp::VarArrayBuffer init_data,
437 PP_SessionType session_type) {
293 // Initialize() doesn't report an error, so CreateSession() can be called 438 // Initialize() doesn't report an error, so CreateSession() can be called
294 // even if Initialize() failed. 439 // even if Initialize() failed.
295 if (!cdm_) { 440 if (!cdm_) {
296 OnSessionError(session_id, cdm::kUnknownError, 0); 441 RejectPromise(promise_id,
442 cdm::kInvalidStateError,
443 0,
444 "CDM has not been initialized.");
297 return; 445 return;
298 } 446 }
299 447
300 cdm_->CreateSession(session_id, 448 cdm_->CreateSession(promise_id,
301 content_type.data(), 449 init_data_type.data(),
302 content_type.size(), 450 init_data_type.size(),
303 static_cast<const uint8_t*>(init_data.Map()), 451 static_cast<const uint8_t*>(init_data.Map()),
304 init_data.ByteLength()); 452 init_data.ByteLength(),
453 PpSessionTypeToCdmSessionType(session_type));
305 } 454 }
306 455
307 void CdmAdapter::LoadSession(uint32_t session_id, 456 void CdmAdapter::LoadSession(uint32_t promise_id,
308 const std::string& web_session_id) { 457 const std::string& web_session_id) {
309 // Initialize() doesn't report an error, so LoadSession() can be called 458 // Initialize() doesn't report an error, so LoadSession() can be called
310 // even if Initialize() failed. 459 // even if Initialize() failed.
311 if (!cdm_) { 460 if (!cdm_) {
312 OnSessionError(session_id, cdm::kUnknownError, 0); 461 RejectPromise(promise_id,
462 cdm::kInvalidStateError,
463 0,
464 "CDM has not been initialized.");
313 return; 465 return;
314 } 466 }
315 467
316 cdm_->LoadSession(session_id, web_session_id.data(), web_session_id.size()); 468 cdm_->LoadSession(promise_id, web_session_id.data(), web_session_id.size());
317 } 469 }
318 470
319 void CdmAdapter::UpdateSession(uint32_t session_id, 471 void CdmAdapter::UpdateSession(uint32_t promise_id,
472 const std::string& web_session_id,
320 pp::VarArrayBuffer response) { 473 pp::VarArrayBuffer response) {
321 const uint8_t* response_ptr = static_cast<const uint8_t*>(response.Map()); 474 const uint8_t* response_ptr = static_cast<const uint8_t*>(response.Map());
322 const uint32_t response_size = response.ByteLength(); 475 const uint32_t response_size = response.ByteLength();
323 476
477 PP_DCHECK(!web_session_id.empty());
478
324 if (!response_ptr || response_size <= 0) { 479 if (!response_ptr || response_size <= 0) {
325 OnSessionError(session_id, cdm::kUnknownError, 0); 480 RejectPromise(promise_id, cdm::kSyntaxError, 0, "response is empty.");
326 return; 481 return;
327 } 482 }
328 cdm_->UpdateSession(session_id, response_ptr, response_size); 483
484 cdm_->UpdateSession(promise_id,
485 web_session_id.data(),
486 web_session_id.length(),
487 response_ptr,
488 response_size);
329 } 489 }
330 490
331 void CdmAdapter::ReleaseSession(uint32_t session_id) { 491 void CdmAdapter::ReleaseSession(uint32_t promise_id,
332 cdm_->ReleaseSession(session_id); 492 const std::string& web_session_id) {
493 cdm_->ReleaseSession(
494 promise_id, web_session_id.data(), web_session_id.length());
333 } 495 }
334 496
335 // Note: In the following decryption/decoding related functions, errors are NOT 497 // Note: In the following decryption/decoding related functions, errors are NOT
336 // reported via KeyError, but are reported via corresponding PPB calls. 498 // reported via KeyError, but are reported via corresponding PPB calls.
337 499
338 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer, 500 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer,
339 const PP_EncryptedBlockInfo& encrypted_block_info) { 501 const PP_EncryptedBlockInfo& encrypted_block_info) {
340 PP_DCHECK(!encrypted_buffer.is_null()); 502 PP_DCHECK(!encrypted_buffer.is_null());
341 503
342 // Release a buffer that the caller indicated it is finished with. 504 // Release a buffer that the caller indicated it is finished with.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 685
524 void CdmAdapter::TimerExpired(int32_t result, void* context) { 686 void CdmAdapter::TimerExpired(int32_t result, void* context) {
525 PP_DCHECK(result == PP_OK); 687 PP_DCHECK(result == PP_OK);
526 cdm_->TimerExpired(context); 688 cdm_->TimerExpired(context);
527 } 689 }
528 690
529 double CdmAdapter::GetCurrentWallTimeInSeconds() { 691 double CdmAdapter::GetCurrentWallTimeInSeconds() {
530 return pp::Module::Get()->core()->GetTime(); 692 return pp::Module::Get()->core()->GetTime();
531 } 693 }
532 694
695 // cdm::Host_5 methods
696
697 void CdmAdapter::OnResolvePromise(uint32_t promise_id) {
698 PostOnMain(callback_factory_.NewCallback(
699 &CdmAdapter::SendPromiseResolvedInternal, promise_id));
700 }
701
702 void CdmAdapter::OnResolveNewSessionPromise(uint32_t promise_id,
703 const char* web_session_id,
704 uint32_t web_session_id_length) {
705 PostOnMain(callback_factory_.NewCallback(
706 &CdmAdapter::SendPromiseResolvedWithSessionInternal,
707 promise_id,
708 std::string(web_session_id, web_session_id_length)));
709 }
710
711 void CdmAdapter::OnRejectPromise(uint32_t promise_id,
712 cdm::MediaKeyException exception_code,
713 uint32_t system_code,
714 const char* error_message,
715 uint32_t error_message_length) {
716 RejectPromise(promise_id,
717 exception_code,
718 system_code,
719 std::string(error_message, error_message_length));
720 }
721
722 void CdmAdapter::RejectPromise(uint32_t promise_id,
723 cdm::MediaKeyException exception_code,
724 uint32_t system_code,
725 const std::string& error_message) {
726 PostOnMain(callback_factory_.NewCallback(
727 &CdmAdapter::SendPromiseRejectedInternal,
728 promise_id,
729 SessionError(exception_code, system_code, error_message)));
730 }
731
732 void CdmAdapter::OnSessionMessage(const char* web_session_id,
733 uint32_t web_session_id_length,
734 const char* message,
735 uint32_t message_length,
736 const char* destination_url,
737 uint32_t destination_url_length) {
738 PostOnMain(callback_factory_.NewCallback(
739 &CdmAdapter::SendSessionMessageInternal,
740 std::string(web_session_id, web_session_id_length),
741 std::vector<uint8>(message, message + message_length),
742 std::string(destination_url, destination_url_length)));
743 }
744
745 void CdmAdapter::OnSessionReady(const char* web_session_id,
746 uint32_t web_session_id_length) {
747 PostOnMain(callback_factory_.NewCallback(
748 &CdmAdapter::SendSessionReadyInternal,
749 std::string(web_session_id, web_session_id_length)));
750 }
751
752 void CdmAdapter::OnSessionClosed(const char* web_session_id,
753 uint32_t web_session_id_length) {
754 PostOnMain(callback_factory_.NewCallback(
755 &CdmAdapter::SendSessionClosedInternal,
756 std::string(web_session_id, web_session_id_length)));
757 }
758
759 void CdmAdapter::OnSessionError(const char* web_session_id,
760 uint32_t web_session_id_length,
761 cdm::MediaKeyException exception_code,
762 uint32_t system_code,
763 const char* error_message,
764 uint32_t error_message_length) {
765 PostOnMain(callback_factory_.NewCallback(
766 &CdmAdapter::SendSessionErrorInternal,
767 std::string(web_session_id, web_session_id_length),
768 SessionError(exception_code,
769 system_code,
770 std::string(error_message, error_message_length))));
771 }
772
773 // cdm::Host_4 methods
774
533 void CdmAdapter::OnSessionCreated(uint32_t session_id, 775 void CdmAdapter::OnSessionCreated(uint32_t session_id,
534 const char* web_session_id, 776 const char* web_session_id,
535 uint32_t web_session_id_length) { 777 uint32_t web_session_id_length) {
536 PostOnMain(callback_factory_.NewCallback( 778 uint32_t promise_id = cdm_->LookupPromiseId(session_id);
537 &CdmAdapter::SendSessionCreatedInternal, 779 cdm_->AssignWebSessionId(session_id, web_session_id, web_session_id_length);
538 session_id, 780 OnResolveNewSessionPromise(promise_id, web_session_id, web_session_id_length);
539 std::string(web_session_id, web_session_id_length)));
540 } 781 }
541 782
542 void CdmAdapter::OnSessionMessage(uint32_t session_id, 783 void CdmAdapter::OnSessionMessage(uint32_t session_id,
543 const char* message, 784 const char* message,
544 uint32_t message_length, 785 uint32_t message_length,
545 const char* destination_url, 786 const char* destination_url,
546 uint32_t destination_url_length) { 787 uint32_t destination_url_length) {
547 PostOnMain(callback_factory_.NewCallback( 788 std::string web_session_id = cdm_->LookupWebSessionId(session_id);
548 &CdmAdapter::SendSessionMessageInternal, 789 OnSessionMessage(web_session_id.data(),
549 session_id, 790 web_session_id.length(),
550 std::vector<uint8>(message, message + message_length), 791 message,
551 std::string(destination_url, destination_url_length))); 792 message_length,
793 destination_url,
794 destination_url_length);
552 } 795 }
553 796
554 void CdmAdapter::OnSessionReady(uint32_t session_id) { 797 void CdmAdapter::OnSessionReady(uint32_t session_id) {
555 PostOnMain(callback_factory_.NewCallback( 798 uint32_t promise_id = cdm_->LookupPromiseId(session_id);
556 &CdmAdapter::SendSessionReadyInternal, session_id)); 799 if (promise_id) {
800 OnResolvePromise(promise_id);
801 } else {
802 std::string web_session_id = cdm_->LookupWebSessionId(session_id);
803 OnSessionReady(web_session_id.data(), web_session_id.length());
804 }
557 } 805 }
558 806
559 void CdmAdapter::OnSessionClosed(uint32_t session_id) { 807 void CdmAdapter::OnSessionClosed(uint32_t session_id) {
560 PostOnMain(callback_factory_.NewCallback( 808 uint32_t promise_id = cdm_->LookupPromiseId(session_id);
561 &CdmAdapter::SendSessionClosedInternal, session_id)); 809 std::string web_session_id = cdm_->LookupWebSessionId(session_id);
810 cdm_->DropWebSessionId(web_session_id);
811 if (promise_id) {
812 OnResolvePromise(promise_id);
813 } else {
814 OnSessionClosed(web_session_id.data(), web_session_id.length());
815 }
562 } 816 }
563 817
564 void CdmAdapter::OnSessionError(uint32_t session_id, 818 void CdmAdapter::OnSessionError(uint32_t session_id,
565 cdm::MediaKeyError error_code, 819 cdm::MediaKeyError error_code,
566 uint32_t system_code) { 820 uint32_t system_code) {
567 PostOnMain(callback_factory_.NewCallback( 821 uint32_t promise_id = cdm_->LookupPromiseId(session_id);
568 &CdmAdapter::SendSessionErrorInternal, 822
569 session_id, 823 // Existing cdm::MediaKeyError don't map to DOM error names. Convert them
570 error_code, 824 // into non-standard names so that the prefixed API can extract them.
571 system_code)); 825 // TODO(jrummell): Remove this conversion and the inverse when CDM4 is gone.
826 cdm::MediaKeyException exception_code;
827 switch (error_code) {
828 case cdm::kClientError:
829 exception_code = cdm::kMediaKeyErrorClientError;
830 break;
831 case cdm::kOutputError:
832 exception_code = cdm::kMediaKeyErrorOutputError;
833 break;
834 case cdm::kUnknownError:
835 default:
836 exception_code = cdm::kMediaKeyErrorUnknownError;
837 break;
838 }
839
840 if (promise_id) {
841 RejectPromise(promise_id, exception_code, system_code, std::string());
842 } else {
843 std::string web_session_id = cdm_->LookupWebSessionId(session_id);
844 OnSessionError(web_session_id.data(),
845 web_session_id.length(),
846 exception_code,
847 system_code,
848 NULL,
849 0);
850 }
572 } 851 }
573 852
574 void CdmAdapter::SendSessionCreatedInternal(int32_t result, 853 // Helpers to pass the event to Pepper.
575 uint32_t session_id, 854
576 const std::string& web_session_id) { 855 void CdmAdapter::SendPromiseResolvedInternal(int32_t result,
856 uint32_t promise_id) {
577 PP_DCHECK(result == PP_OK); 857 PP_DCHECK(result == PP_OK);
578 pp::ContentDecryptor_Private::SessionCreated(session_id, web_session_id); 858 pp::ContentDecryptor_Private::PromiseResolved(promise_id);
579 } 859 }
580 860
581 void CdmAdapter::SendSessionMessageInternal(int32_t result, 861 void CdmAdapter::SendPromiseResolvedWithSessionInternal(
582 uint32_t session_id, 862 int32_t result,
583 const std::vector<uint8>& message, 863 uint32_t promise_id,
584 const std::string& default_url) { 864 const std::string& web_session_id) {
865 PP_DCHECK(result == PP_OK);
866 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id,
867 web_session_id);
868 }
869
870 void CdmAdapter::SendPromiseRejectedInternal(int32_t result,
871 uint32_t promise_id,
872 const SessionError& error) {
873 PP_DCHECK(result == PP_OK);
874 pp::ContentDecryptor_Private::PromiseRejected(
875 promise_id,
876 CdmExceptionTypeToPpExceptionType(error.exception_code),
877 error.system_code,
878 error.error_description);
879 }
880
881 void CdmAdapter::SendSessionMessageInternal(
882 int32_t result,
883 const std::string& web_session_id,
884 const std::vector<uint8>& message,
885 const std::string& destination_url) {
585 PP_DCHECK(result == PP_OK); 886 PP_DCHECK(result == PP_OK);
586 887
587 pp::VarArrayBuffer message_array_buffer(message.size()); 888 pp::VarArrayBuffer message_array_buffer(message.size());
588 if (message.size() > 0) { 889 if (message.size() > 0) {
589 memcpy(message_array_buffer.Map(), message.data(), message.size()); 890 memcpy(message_array_buffer.Map(), message.data(), message.size());
590 } 891 }
591 892
592 pp::ContentDecryptor_Private::SessionMessage( 893 pp::ContentDecryptor_Private::SessionMessage(
593 session_id, message_array_buffer, default_url); 894 web_session_id, message_array_buffer, destination_url);
594 } 895 }
595 896
596 void CdmAdapter::SendSessionReadyInternal(int32_t result, uint32_t session_id) { 897 void CdmAdapter::SendSessionReadyInternal(int32_t result,
898 const std::string& web_session_id) {
597 PP_DCHECK(result == PP_OK); 899 PP_DCHECK(result == PP_OK);
598 pp::ContentDecryptor_Private::SessionReady(session_id); 900 pp::ContentDecryptor_Private::SessionReady(web_session_id);
599 } 901 }
600 902
601 void CdmAdapter::SendSessionClosedInternal(int32_t result, 903 void CdmAdapter::SendSessionClosedInternal(int32_t result,
602 uint32_t session_id) { 904 const std::string& web_session_id) {
603 PP_DCHECK(result == PP_OK); 905 PP_DCHECK(result == PP_OK);
604 pp::ContentDecryptor_Private::SessionClosed(session_id); 906 pp::ContentDecryptor_Private::SessionClosed(web_session_id);
605 } 907 }
606 908
607 void CdmAdapter::SendSessionErrorInternal(int32_t result, 909 void CdmAdapter::SendSessionErrorInternal(int32_t result,
608 uint32_t session_id, 910 const std::string& web_session_id,
609 cdm::MediaKeyError error_code, 911 const SessionError& error) {
610 uint32_t system_code) {
611 PP_DCHECK(result == PP_OK); 912 PP_DCHECK(result == PP_OK);
612 pp::ContentDecryptor_Private::SessionError( 913 pp::ContentDecryptor_Private::SessionError(
613 session_id, error_code, system_code); 914 web_session_id,
915 CdmExceptionTypeToPpExceptionType(error.exception_code),
916 error.system_code,
917 error.error_description);
614 } 918 }
615 919
616 void CdmAdapter::DeliverBlock(int32_t result, 920 void CdmAdapter::DeliverBlock(int32_t result,
617 const cdm::Status& status, 921 const cdm::Status& status,
618 const LinkedDecryptedBlock& decrypted_block, 922 const LinkedDecryptedBlock& decrypted_block,
619 const PP_DecryptTrackingInfo& tracking_info) { 923 const PP_DecryptTrackingInfo& tracking_info) {
620 PP_DCHECK(result == PP_OK); 924 PP_DCHECK(result == PP_OK);
621 PP_DecryptedBlockInfo decrypted_block_info; 925 PP_DecryptedBlockInfo decrypted_block_info;
622 decrypted_block_info.tracking_info = tracking_info; 926 decrypted_block_info.tracking_info = tracking_info;
623 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); 927 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp();
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 cdm_->OnPlatformChallengeResponse(response); 1196 cdm_->OnPlatformChallengeResponse(response);
893 return; 1197 return;
894 } 1198 }
895 1199
896 pp::VarArrayBuffer signed_data_var(signed_data_output_); 1200 pp::VarArrayBuffer signed_data_var(signed_data_output_);
897 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_); 1201 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_);
898 std::string platform_key_certificate_string = 1202 std::string platform_key_certificate_string =
899 platform_key_certificate_output_.AsString(); 1203 platform_key_certificate_output_.AsString();
900 1204
901 cdm::PlatformChallengeResponse response = { 1205 cdm::PlatformChallengeResponse response = {
902 static_cast<uint8_t*>(signed_data_var.Map()), 1206 static_cast<uint8_t*>(signed_data_var.Map()),
903 signed_data_var.ByteLength(), 1207 signed_data_var.ByteLength(),
904 1208 static_cast<uint8_t*>(signed_data_signature_var.Map()),
905 static_cast<uint8_t*>(signed_data_signature_var.Map()), 1209 signed_data_signature_var.ByteLength(),
906 signed_data_signature_var.ByteLength(), 1210 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.data()),
907 1211 static_cast<uint32_t>(platform_key_certificate_string.length())};
908 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.c_str()),
909 static_cast<uint32_t>(platform_key_certificate_string.length())
910 };
911 cdm_->OnPlatformChallengeResponse(response); 1212 cdm_->OnPlatformChallengeResponse(response);
912 1213
913 signed_data_var.Unmap(); 1214 signed_data_var.Unmap();
914 signed_data_signature_var.Unmap(); 1215 signed_data_signature_var.Unmap();
915 } 1216 }
916 1217
917 void CdmAdapter::EnableProtectionDone(int32_t result) { 1218 void CdmAdapter::EnableProtectionDone(int32_t result) {
918 // Does nothing since clients must call QueryOutputProtectionStatus() to 1219 // Does nothing since clients must call QueryOutputProtectionStatus() to
919 // inspect the protection status on a regular basis. 1220 // inspect the protection status on a regular basis.
920 CDM_DLOG() << __FUNCTION__ << " : " << result; 1221 CDM_DLOG() << __FUNCTION__ << " : " << result;
921 } 1222 }
922 1223
923 void CdmAdapter::QueryOutputProtectionStatusDone(int32_t result) { 1224 void CdmAdapter::QueryOutputProtectionStatusDone(int32_t result) {
924 PP_DCHECK(query_output_protection_in_progress_); 1225 PP_DCHECK(query_output_protection_in_progress_);
925 query_output_protection_in_progress_ = false; 1226 query_output_protection_in_progress_ = false;
926 1227
927 // Return a protection status of none on error. 1228 // Return a protection status of none on error.
928 if (result != PP_OK) 1229 if (result != PP_OK)
929 output_link_mask_ = output_protection_mask_ = 0; 1230 output_link_mask_ = output_protection_mask_ = 0;
930 1231
931 cdm_->OnQueryOutputProtectionStatus(output_link_mask_, 1232 cdm_->OnQueryOutputProtectionStatus(output_link_mask_,
932 output_protection_mask_); 1233 output_protection_mask_);
933 } 1234 }
934 #endif 1235 #endif
935 1236
1237 CdmAdapter::SessionError::SessionError(cdm::MediaKeyException exception_code,
1238 uint32_t system_code,
1239 std::string error_description)
1240 : exception_code(exception_code),
1241 system_code(system_code),
1242 error_description(error_description) {
1243 }
1244
936 void* GetCdmHost(int host_interface_version, void* user_data) { 1245 void* GetCdmHost(int host_interface_version, void* user_data) {
937 if (!host_interface_version || !user_data) 1246 if (!host_interface_version || !user_data)
938 return NULL; 1247 return NULL;
939 1248
940 COMPILE_ASSERT( 1249 COMPILE_ASSERT(
941 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_4::kVersion, 1250 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_5::kVersion,
942 update_code_below); 1251 update_code_below);
943 1252
944 // Ensure IsSupportedCdmHostVersion matches implementation of this function. 1253 // Ensure IsSupportedCdmHostVersion matches implementation of this function.
945 // Always update this DCHECK when updating this function. 1254 // Always update this DCHECK when updating this function.
946 // If this check fails, update this function and DCHECK or update 1255 // If this check fails, update this function and DCHECK or update
947 // IsSupportedCdmHostVersion. 1256 // IsSupportedCdmHostVersion.
948 1257
949 PP_DCHECK( 1258 PP_DCHECK(
950 // Future version is not supported. 1259 // Future version is not supported.
951 !IsSupportedCdmHostVersion(cdm::Host_4::kVersion + 1) && 1260 !IsSupportedCdmHostVersion(cdm::Host_5::kVersion + 1) &&
952 // Current version is supported. 1261 // Current version is supported.
1262 IsSupportedCdmHostVersion(cdm::Host_5::kVersion) &&
1263 // Include all previous supported versions (if any) here.
953 IsSupportedCdmHostVersion(cdm::Host_4::kVersion) && 1264 IsSupportedCdmHostVersion(cdm::Host_4::kVersion) &&
954 // Include all previous supported versions (if any) here.
955 // No supported previous versions.
956 // One older than the oldest supported version is not supported. 1265 // One older than the oldest supported version is not supported.
957 !IsSupportedCdmHostVersion(cdm::Host_4::kVersion - 1)); 1266 !IsSupportedCdmHostVersion(cdm::Host_4::kVersion - 1));
958 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version)); 1267 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version));
959 1268
960 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data); 1269 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data);
961 CDM_DLOG() << "Create CDM Host with version " << host_interface_version; 1270 CDM_DLOG() << "Create CDM Host with version " << host_interface_version;
962 switch (host_interface_version) { 1271 switch (host_interface_version) {
963 case cdm::Host_4::kVersion: 1272 case cdm::Host_4::kVersion:
964 return static_cast<cdm::Host_4*>(cdm_adapter); 1273 return static_cast<cdm::Host_4*>(cdm_adapter);
1274 case cdm::Host_5::kVersion:
1275 return static_cast<cdm::Host_5*>(cdm_adapter);
965 default: 1276 default:
966 PP_NOTREACHED(); 1277 PP_NOTREACHED();
967 return NULL; 1278 return NULL;
968 } 1279 }
969 } 1280 }
970 1281
971 // This object is the global object representing this plugin library as long 1282 // This object is the global object representing this plugin library as long
972 // as it is loaded. 1283 // as it is loaded.
973 class CdmAdapterModule : public pp::Module { 1284 class CdmAdapterModule : public pp::Module {
974 public: 1285 public:
(...skipping 17 matching lines...) Expand all
992 } // namespace media 1303 } // namespace media
993 1304
994 namespace pp { 1305 namespace pp {
995 1306
996 // Factory function for your specialization of the Module object. 1307 // Factory function for your specialization of the Module object.
997 Module* CreateModule() { 1308 Module* CreateModule() {
998 return new media::CdmAdapterModule(); 1309 return new media::CdmAdapterModule();
999 } 1310 }
1000 1311
1001 } // namespace pp 1312 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698