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/cdm/ppapi/cdm_helpers.h" | 7 #include "media/cdm/ppapi/cdm_helpers.h" |
8 | 8 |
9 #if defined(CHECK_DOCUMENT_URL) | 9 #if defined(CHECK_DOCUMENT_URL) |
10 #include "ppapi/cpp/dev/url_util_dev.h" | 10 #include "ppapi/cpp/dev/url_util_dev.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 void ConfigureInputBuffer( | 39 void ConfigureInputBuffer( |
40 const pp::Buffer_Dev& encrypted_buffer, | 40 const pp::Buffer_Dev& encrypted_buffer, |
41 const PP_EncryptedBlockInfo& encrypted_block_info, | 41 const PP_EncryptedBlockInfo& encrypted_block_info, |
42 std::vector<cdm::SubsampleEntry>* subsamples, | 42 std::vector<cdm::SubsampleEntry>* subsamples, |
43 cdm::InputBuffer* input_buffer) { | 43 cdm::InputBuffer* input_buffer) { |
44 PP_DCHECK(subsamples); | 44 PP_DCHECK(subsamples); |
45 PP_DCHECK(!encrypted_buffer.is_null()); | 45 PP_DCHECK(!encrypted_buffer.is_null()); |
46 | 46 |
47 input_buffer->data = static_cast<uint8_t*>(encrypted_buffer.data()); | 47 input_buffer->data = static_cast<uint8_t*>(encrypted_buffer.data()); |
48 input_buffer->data_size = encrypted_block_info.data_size; | 48 input_buffer->data_size = encrypted_block_info.data_size; |
49 PP_DCHECK(encrypted_buffer.size() >= | 49 PP_DCHECK(encrypted_buffer.size() >= input_buffer->data_size); |
50 static_cast<uint32_t>(input_buffer->data_size)); | |
51 input_buffer->data_offset = encrypted_block_info.data_offset; | 50 input_buffer->data_offset = encrypted_block_info.data_offset; |
52 | 51 |
53 PP_DCHECK(encrypted_block_info.key_id_size <= | 52 PP_DCHECK(encrypted_block_info.key_id_size <= |
54 arraysize(encrypted_block_info.key_id)); | 53 arraysize(encrypted_block_info.key_id)); |
55 input_buffer->key_id_size = encrypted_block_info.key_id_size; | 54 input_buffer->key_id_size = encrypted_block_info.key_id_size; |
56 input_buffer->key_id = input_buffer->key_id_size > 0 ? | 55 input_buffer->key_id = input_buffer->key_id_size > 0 ? |
57 encrypted_block_info.key_id : NULL; | 56 encrypted_block_info.key_id : NULL; |
58 | 57 |
59 PP_DCHECK(encrypted_block_info.iv_size <= arraysize(encrypted_block_info.iv)); | 58 PP_DCHECK(encrypted_block_info.iv_size <= arraysize(encrypted_block_info.iv)); |
60 input_buffer->iv_size = encrypted_block_info.iv_size; | 59 input_buffer->iv_size = encrypted_block_info.iv_size; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 pp::VarArrayBuffer key, | 255 pp::VarArrayBuffer key, |
257 pp::VarArrayBuffer init_data) { | 256 pp::VarArrayBuffer init_data) { |
258 // TODO(jrummell): In EME WD, AddKey() can only be called on valid sessions. | 257 // TODO(jrummell): In EME WD, AddKey() can only be called on valid sessions. |
259 // We should be able to DCHECK(cdm_) when addressing http://crbug.com/249976. | 258 // We should be able to DCHECK(cdm_) when addressing http://crbug.com/249976. |
260 if (!cdm_) { | 259 if (!cdm_) { |
261 SendUnknownKeyError(key_system_, session_id); | 260 SendUnknownKeyError(key_system_, session_id); |
262 return; | 261 return; |
263 } | 262 } |
264 | 263 |
265 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); | 264 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); |
266 int key_size = key.ByteLength(); | 265 const uint32_t key_size = key.ByteLength(); |
267 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); | 266 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); |
268 int init_data_size = init_data.ByteLength(); | 267 const uint32_t init_data_size = init_data.ByteLength(); |
269 PP_DCHECK(!init_data_ptr == !init_data_size); | 268 PP_DCHECK(!init_data_ptr == !init_data_size); |
270 | 269 |
271 if (!key_ptr || key_size <= 0) { | 270 if (!key_ptr || !key_size) { |
272 SendUnknownKeyError(key_system_, session_id); | 271 SendUnknownKeyError(key_system_, session_id); |
273 return; | 272 return; |
274 } | 273 } |
275 | 274 |
276 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), | 275 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), |
277 key_ptr, key_size, | 276 key_ptr, key_size, |
278 init_data_ptr, init_data_size); | 277 init_data_ptr, init_data_size); |
279 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); | 278 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); |
280 if (status != cdm::kSuccess) { | 279 if (status != cdm::kSuccess) { |
281 SendUnknownKeyError(key_system_, session_id); | 280 SendUnknownKeyError(key_system_, session_id); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 cdm::Status status = cdm::kSessionError; | 336 cdm::Status status = cdm::kSessionError; |
338 if (cdm_) { | 337 if (cdm_) { |
339 cdm::AudioDecoderConfig cdm_decoder_config; | 338 cdm::AudioDecoderConfig cdm_decoder_config; |
340 cdm_decoder_config.codec = | 339 cdm_decoder_config.codec = |
341 PpAudioCodecToCdmAudioCodec(decoder_config.codec); | 340 PpAudioCodecToCdmAudioCodec(decoder_config.codec); |
342 cdm_decoder_config.channel_count = decoder_config.channel_count; | 341 cdm_decoder_config.channel_count = decoder_config.channel_count; |
343 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel; | 342 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel; |
344 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second; | 343 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second; |
345 cdm_decoder_config.extra_data = | 344 cdm_decoder_config.extra_data = |
346 static_cast<uint8_t*>(extra_data_buffer.data()); | 345 static_cast<uint8_t*>(extra_data_buffer.data()); |
347 cdm_decoder_config.extra_data_size = | 346 cdm_decoder_config.extra_data_size = extra_data_buffer.size(); |
348 static_cast<int32_t>(extra_data_buffer.size()); | |
349 status = cdm_->InitializeAudioDecoder(cdm_decoder_config); | 347 status = cdm_->InitializeAudioDecoder(cdm_decoder_config); |
350 } | 348 } |
351 | 349 |
352 CallOnMain(callback_factory_.NewCallback( | 350 CallOnMain(callback_factory_.NewCallback( |
353 &CdmAdapter::DecoderInitializeDone, | 351 &CdmAdapter::DecoderInitializeDone, |
354 PP_DECRYPTORSTREAMTYPE_AUDIO, | 352 PP_DECRYPTORSTREAMTYPE_AUDIO, |
355 decoder_config.request_id, | 353 decoder_config.request_id, |
356 status == cdm::kSuccess)); | 354 status == cdm::kSuccess)); |
357 } | 355 } |
358 | 356 |
359 void CdmAdapter::InitializeVideoDecoder( | 357 void CdmAdapter::InitializeVideoDecoder( |
360 const PP_VideoDecoderConfig& decoder_config, | 358 const PP_VideoDecoderConfig& decoder_config, |
361 pp::Buffer_Dev extra_data_buffer) { | 359 pp::Buffer_Dev extra_data_buffer) { |
362 cdm::Status status = cdm::kSessionError; | 360 cdm::Status status = cdm::kSessionError; |
363 if (cdm_) { | 361 if (cdm_) { |
364 cdm::VideoDecoderConfig cdm_decoder_config; | 362 cdm::VideoDecoderConfig cdm_decoder_config; |
365 cdm_decoder_config.codec = | 363 cdm_decoder_config.codec = |
366 PpVideoCodecToCdmVideoCodec(decoder_config.codec); | 364 PpVideoCodecToCdmVideoCodec(decoder_config.codec); |
367 cdm_decoder_config.profile = | 365 cdm_decoder_config.profile = |
368 PpVCProfileToCdmVCProfile(decoder_config.profile); | 366 PpVCProfileToCdmVCProfile(decoder_config.profile); |
369 cdm_decoder_config.format = | 367 cdm_decoder_config.format = |
370 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format); | 368 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format); |
371 cdm_decoder_config.coded_size.width = decoder_config.width; | 369 cdm_decoder_config.coded_size.width = decoder_config.width; |
372 cdm_decoder_config.coded_size.height = decoder_config.height; | 370 cdm_decoder_config.coded_size.height = decoder_config.height; |
373 cdm_decoder_config.extra_data = | 371 cdm_decoder_config.extra_data = |
374 static_cast<uint8_t*>(extra_data_buffer.data()); | 372 static_cast<uint8_t*>(extra_data_buffer.data()); |
375 cdm_decoder_config.extra_data_size = | 373 cdm_decoder_config.extra_data_size = extra_data_buffer.size(); |
376 static_cast<int32_t>(extra_data_buffer.size()); | |
377 status = cdm_->InitializeVideoDecoder(cdm_decoder_config); | 374 status = cdm_->InitializeVideoDecoder(cdm_decoder_config); |
378 } | 375 } |
379 | 376 |
380 CallOnMain(callback_factory_.NewCallback( | 377 CallOnMain(callback_factory_.NewCallback( |
381 &CdmAdapter::DecoderInitializeDone, | 378 &CdmAdapter::DecoderInitializeDone, |
382 PP_DECRYPTORSTREAMTYPE_VIDEO, | 379 PP_DECRYPTORSTREAMTYPE_VIDEO, |
383 decoder_config.request_id, | 380 decoder_config.request_id, |
384 status == cdm::kSuccess)); | 381 status == cdm::kSuccess)); |
385 } | 382 } |
386 | 383 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 encrypted_block_info.tracking_info)); | 451 encrypted_block_info.tracking_info)); |
455 return; | 452 return; |
456 } | 453 } |
457 | 454 |
458 default: | 455 default: |
459 PP_NOTREACHED(); | 456 PP_NOTREACHED(); |
460 return; | 457 return; |
461 } | 458 } |
462 } | 459 } |
463 | 460 |
464 cdm::Buffer* CdmAdapter::Allocate(int32_t capacity) { | 461 cdm::Buffer* CdmAdapter::Allocate(uint32_t capacity) { |
465 return allocator_.Allocate(capacity); | 462 return allocator_.Allocate(capacity); |
466 } | 463 } |
467 | 464 |
468 void CdmAdapter::SetTimer(int64_t delay_ms, void* context) { | 465 void CdmAdapter::SetTimer(int64_t delay_ms, void* context) { |
469 // NOTE: doesn't really need to run on the main thread; could just as well run | 466 // NOTE: doesn't really need to run on the main thread; could just as well run |
470 // on a helper thread if |cdm_| were thread-friendly and care was taken. We | 467 // on a helper thread if |cdm_| were thread-friendly and care was taken. We |
471 // only use CallOnMainThread() here to get delayed-execution behavior. | 468 // only use CallOnMainThread() here to get delayed-execution behavior. |
472 pp::Module::Get()->core()->CallOnMainThread( | 469 pp::Module::Get()->core()->CallOnMainThread( |
473 delay_ms, | 470 delay_ms, |
474 callback_factory_.NewCallback(&CdmAdapter::TimerExpired, context), | 471 callback_factory_.NewCallback(&CdmAdapter::TimerExpired, context), |
475 PP_OK); | 472 PP_OK); |
476 } | 473 } |
477 | 474 |
478 void CdmAdapter::TimerExpired(int32_t result, void* context) { | 475 void CdmAdapter::TimerExpired(int32_t result, void* context) { |
479 PP_DCHECK(result == PP_OK); | 476 PP_DCHECK(result == PP_OK); |
480 cdm_->TimerExpired(context); | 477 cdm_->TimerExpired(context); |
481 } | 478 } |
482 | 479 |
483 double CdmAdapter::GetCurrentWallTimeInSeconds() { | 480 double CdmAdapter::GetCurrentWallTimeInSeconds() { |
484 return pp::Module::Get()->core()->GetTime(); | 481 return pp::Module::Get()->core()->GetTime(); |
485 } | 482 } |
486 | 483 |
487 void CdmAdapter::SendKeyMessage( | 484 void CdmAdapter::SendKeyMessage( |
488 const char* session_id, int32_t session_id_length, | 485 const char* session_id, uint32_t session_id_length, |
489 const char* message, int32_t message_length, | 486 const char* message, uint32_t message_length, |
490 const char* default_url, int32_t default_url_length) { | 487 const char* default_url, uint32_t default_url_length) { |
491 PP_DCHECK(!key_system_.empty()); | 488 PP_DCHECK(!key_system_.empty()); |
492 PostOnMain(callback_factory_.NewCallback( | 489 PostOnMain(callback_factory_.NewCallback( |
493 &CdmAdapter::KeyMessage, | 490 &CdmAdapter::KeyMessage, |
494 SessionInfo(key_system_, | 491 SessionInfo(key_system_, |
495 std::string(session_id, session_id_length)), | 492 std::string(session_id, session_id_length)), |
496 std::vector<uint8>(message, message + message_length), | 493 std::vector<uint8>(message, message + message_length), |
497 std::string(default_url, default_url_length))); | 494 std::string(default_url, default_url_length))); |
498 } | 495 } |
499 | 496 |
500 void CdmAdapter::SendKeyError(const char* session_id, | 497 void CdmAdapter::SendKeyError(const char* session_id, |
501 int32_t session_id_length, | 498 uint32_t session_id_length, |
502 cdm::MediaKeyError error_code, | 499 cdm::MediaKeyError error_code, |
503 uint32_t system_code) { | 500 uint32_t system_code) { |
504 SendKeyErrorInternal(key_system_, | 501 SendKeyErrorInternal(key_system_, |
505 std::string(session_id, session_id_length), | 502 std::string(session_id, session_id_length), |
506 error_code, | 503 error_code, |
507 system_code); | 504 system_code); |
508 } | 505 } |
509 | 506 |
510 void CdmAdapter::GetPrivateData(int32_t* instance, | 507 void CdmAdapter::GetPrivateData(int32_t* instance, |
511 GetPrivateInterface* get_interface) { | 508 GetPrivateInterface* get_interface) { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 bool CdmAdapter::IsValidVideoFrame(const LinkedVideoFrame& video_frame) { | 701 bool CdmAdapter::IsValidVideoFrame(const LinkedVideoFrame& video_frame) { |
705 if (!video_frame.get() || | 702 if (!video_frame.get() || |
706 !video_frame->FrameBuffer() || | 703 !video_frame->FrameBuffer() || |
707 (video_frame->Format() != cdm::kI420 && | 704 (video_frame->Format() != cdm::kI420 && |
708 video_frame->Format() != cdm::kYv12)) { | 705 video_frame->Format() != cdm::kYv12)) { |
709 return false; | 706 return false; |
710 } | 707 } |
711 | 708 |
712 PpbBuffer* ppb_buffer = static_cast<PpbBuffer*>(video_frame->FrameBuffer()); | 709 PpbBuffer* ppb_buffer = static_cast<PpbBuffer*>(video_frame->FrameBuffer()); |
713 | 710 |
714 for (int i = 0; i < cdm::VideoFrame::kMaxPlanes; ++i) { | 711 for (uint32_t i = 0; i < cdm::VideoFrame::kMaxPlanes; ++i) { |
715 int plane_height = (i == cdm::VideoFrame::kYPlane) ? | 712 int plane_height = (i == cdm::VideoFrame::kYPlane) ? |
716 video_frame->Size().height : (video_frame->Size().height + 1) / 2; | 713 video_frame->Size().height : (video_frame->Size().height + 1) / 2; |
717 cdm::VideoFrame::VideoPlane plane = | 714 cdm::VideoFrame::VideoPlane plane = |
718 static_cast<cdm::VideoFrame::VideoPlane>(i); | 715 static_cast<cdm::VideoFrame::VideoPlane>(i); |
719 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + | 716 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + |
720 plane_height * video_frame->Stride(plane)) { | 717 plane_height * video_frame->Stride(plane)) { |
721 return false; | 718 return false; |
722 } | 719 } |
723 } | 720 } |
724 | 721 |
725 return true; | 722 return true; |
726 } | 723 } |
727 | 724 |
| 725 void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type, |
| 726 cdm::Status decoder_status) { |
| 727 PP_NOTREACHED(); |
| 728 } |
| 729 |
728 void CdmAdapter::SendPlatformChallenge( | 730 void CdmAdapter::SendPlatformChallenge( |
729 const char* service_id, int32_t service_id_length, | 731 const char* service_id, uint32_t service_id_length, |
730 const char* challenge, int32_t challenge_length) { | 732 const char* challenge, uint32_t challenge_length) { |
731 #if defined(OS_CHROMEOS) | 733 #if defined(OS_CHROMEOS) |
732 PP_DCHECK(!challenge_in_progress_); | 734 PP_DCHECK(!challenge_in_progress_); |
733 | 735 |
734 // Ensure member variables set by the callback are in a clean state. | 736 // Ensure member variables set by the callback are in a clean state. |
735 signed_data_output_ = pp::Var(); | 737 signed_data_output_ = pp::Var(); |
736 signed_data_signature_output_ = pp::Var(); | 738 signed_data_signature_output_ = pp::Var(); |
737 platform_key_certificate_output_ = pp::Var(); | 739 platform_key_certificate_output_ = pp::Var(); |
738 | 740 |
739 pp::VarArrayBuffer challenge_var(challenge_length); | 741 pp::VarArrayBuffer challenge_var(challenge_length); |
740 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); | 742 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 return; | 805 return; |
804 } | 806 } |
805 | 807 |
806 pp::VarArrayBuffer signed_data_var(signed_data_output_); | 808 pp::VarArrayBuffer signed_data_var(signed_data_output_); |
807 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_); | 809 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_); |
808 std::string platform_key_certificate_string = | 810 std::string platform_key_certificate_string = |
809 platform_key_certificate_output_.AsString(); | 811 platform_key_certificate_output_.AsString(); |
810 | 812 |
811 cdm::PlatformChallengeResponse response = { | 813 cdm::PlatformChallengeResponse response = { |
812 static_cast<uint8_t*>(signed_data_var.Map()), | 814 static_cast<uint8_t*>(signed_data_var.Map()), |
813 static_cast<int32_t>(signed_data_var.ByteLength()), | 815 signed_data_var.ByteLength(), |
814 | 816 |
815 static_cast<uint8_t*>(signed_data_signature_var.Map()), | 817 static_cast<uint8_t*>(signed_data_signature_var.Map()), |
816 static_cast<int32_t>(signed_data_signature_var.ByteLength()), | 818 signed_data_signature_var.ByteLength(), |
817 | 819 |
818 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.c_str()), | 820 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.c_str()), |
819 static_cast<int32_t>(platform_key_certificate_string.length()) | 821 static_cast<uint32_t>(platform_key_certificate_string.length()) |
820 }; | 822 }; |
821 cdm_->OnPlatformChallengeResponse(response); | 823 cdm_->OnPlatformChallengeResponse(response); |
822 | 824 |
823 signed_data_var.Unmap(); | 825 signed_data_var.Unmap(); |
824 signed_data_signature_var.Unmap(); | 826 signed_data_signature_var.Unmap(); |
825 } | 827 } |
826 | 828 |
827 void CdmAdapter::EnableProtectionDone(int32_t result) { | 829 void CdmAdapter::EnableProtectionDone(int32_t result) { |
828 // Does nothing since clients must call QueryOutputProtectionStatus() to | 830 // Does nothing since clients must call QueryOutputProtectionStatus() to |
829 // inspect the protection status on a regular basis. | 831 // inspect the protection status on a regular basis. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 } // namespace media | 882 } // namespace media |
881 | 883 |
882 namespace pp { | 884 namespace pp { |
883 | 885 |
884 // Factory function for your specialization of the Module object. | 886 // Factory function for your specialization of the Module object. |
885 Module* CreateModule() { | 887 Module* CreateModule() { |
886 return new media::CdmAdapterModule(); | 888 return new media::CdmAdapterModule(); |
887 } | 889 } |
888 | 890 |
889 } // namespace pp | 891 } // namespace pp |
OLD | NEW |