| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 pp::VarArrayBuffer key, | 275 pp::VarArrayBuffer key, |
| 277 pp::VarArrayBuffer init_data) { | 276 pp::VarArrayBuffer init_data) { |
| 278 // TODO(jrummell): In EME WD, AddKey() can only be called on valid sessions. | 277 // TODO(jrummell): In EME WD, AddKey() can only be called on valid sessions. |
| 279 // We should be able to DCHECK(cdm_) when addressing http://crbug.com/249976. | 278 // We should be able to DCHECK(cdm_) when addressing http://crbug.com/249976. |
| 280 if (!cdm_) { | 279 if (!cdm_) { |
| 281 SendUnknownKeyError(key_system_, session_id); | 280 SendUnknownKeyError(key_system_, session_id); |
| 282 return; | 281 return; |
| 283 } | 282 } |
| 284 | 283 |
| 285 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); | 284 const uint8_t* key_ptr = static_cast<const uint8_t*>(key.Map()); |
| 286 int key_size = key.ByteLength(); | 285 const uint32_t key_size = key.ByteLength(); |
| 287 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); | 286 const uint8_t* init_data_ptr = static_cast<const uint8_t*>(init_data.Map()); |
| 288 int init_data_size = init_data.ByteLength(); | 287 const uint32_t init_data_size = init_data.ByteLength(); |
| 289 PP_DCHECK(!init_data_ptr == !init_data_size); | 288 PP_DCHECK(!init_data_ptr == !init_data_size); |
| 290 | 289 |
| 291 if (!key_ptr || key_size <= 0) { | 290 if (!key_ptr || !key_size) { |
| 292 SendUnknownKeyError(key_system_, session_id); | 291 SendUnknownKeyError(key_system_, session_id); |
| 293 return; | 292 return; |
| 294 } | 293 } |
| 295 | 294 |
| 296 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), | 295 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), |
| 297 key_ptr, key_size, | 296 key_ptr, key_size, |
| 298 init_data_ptr, init_data_size); | 297 init_data_ptr, init_data_size); |
| 299 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); | 298 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); |
| 300 if (status != cdm::kSuccess) { | 299 if (status != cdm::kSuccess) { |
| 301 SendUnknownKeyError(key_system_, session_id); | 300 SendUnknownKeyError(key_system_, session_id); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 cdm::Status status = cdm::kSessionError; | 356 cdm::Status status = cdm::kSessionError; |
| 358 if (cdm_) { | 357 if (cdm_) { |
| 359 cdm::AudioDecoderConfig cdm_decoder_config; | 358 cdm::AudioDecoderConfig cdm_decoder_config; |
| 360 cdm_decoder_config.codec = | 359 cdm_decoder_config.codec = |
| 361 PpAudioCodecToCdmAudioCodec(decoder_config.codec); | 360 PpAudioCodecToCdmAudioCodec(decoder_config.codec); |
| 362 cdm_decoder_config.channel_count = decoder_config.channel_count; | 361 cdm_decoder_config.channel_count = decoder_config.channel_count; |
| 363 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel; | 362 cdm_decoder_config.bits_per_channel = decoder_config.bits_per_channel; |
| 364 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second; | 363 cdm_decoder_config.samples_per_second = decoder_config.samples_per_second; |
| 365 cdm_decoder_config.extra_data = | 364 cdm_decoder_config.extra_data = |
| 366 static_cast<uint8_t*>(extra_data_buffer.data()); | 365 static_cast<uint8_t*>(extra_data_buffer.data()); |
| 367 cdm_decoder_config.extra_data_size = | 366 cdm_decoder_config.extra_data_size = extra_data_buffer.size(); |
| 368 static_cast<int32_t>(extra_data_buffer.size()); | |
| 369 status = cdm_->InitializeAudioDecoder(cdm_decoder_config); | 367 status = cdm_->InitializeAudioDecoder(cdm_decoder_config); |
| 370 } | 368 } |
| 371 | 369 |
| 372 CallOnMain(callback_factory_.NewCallback( | 370 CallOnMain(callback_factory_.NewCallback( |
| 373 &CdmAdapter::DecoderInitializeDone, | 371 &CdmAdapter::DecoderInitializeDone, |
| 374 PP_DECRYPTORSTREAMTYPE_AUDIO, | 372 PP_DECRYPTORSTREAMTYPE_AUDIO, |
| 375 decoder_config.request_id, | 373 decoder_config.request_id, |
| 376 status == cdm::kSuccess)); | 374 status == cdm::kSuccess)); |
| 377 } | 375 } |
| 378 | 376 |
| 379 void CdmAdapter::InitializeVideoDecoder( | 377 void CdmAdapter::InitializeVideoDecoder( |
| 380 const PP_VideoDecoderConfig& decoder_config, | 378 const PP_VideoDecoderConfig& decoder_config, |
| 381 pp::Buffer_Dev extra_data_buffer) { | 379 pp::Buffer_Dev extra_data_buffer) { |
| 382 cdm::Status status = cdm::kSessionError; | 380 cdm::Status status = cdm::kSessionError; |
| 383 if (cdm_) { | 381 if (cdm_) { |
| 384 cdm::VideoDecoderConfig cdm_decoder_config; | 382 cdm::VideoDecoderConfig cdm_decoder_config; |
| 385 cdm_decoder_config.codec = | 383 cdm_decoder_config.codec = |
| 386 PpVideoCodecToCdmVideoCodec(decoder_config.codec); | 384 PpVideoCodecToCdmVideoCodec(decoder_config.codec); |
| 387 cdm_decoder_config.profile = | 385 cdm_decoder_config.profile = |
| 388 PpVCProfileToCdmVCProfile(decoder_config.profile); | 386 PpVCProfileToCdmVCProfile(decoder_config.profile); |
| 389 cdm_decoder_config.format = | 387 cdm_decoder_config.format = |
| 390 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format); | 388 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format); |
| 391 cdm_decoder_config.coded_size.width = decoder_config.width; | 389 cdm_decoder_config.coded_size.width = decoder_config.width; |
| 392 cdm_decoder_config.coded_size.height = decoder_config.height; | 390 cdm_decoder_config.coded_size.height = decoder_config.height; |
| 393 cdm_decoder_config.extra_data = | 391 cdm_decoder_config.extra_data = |
| 394 static_cast<uint8_t*>(extra_data_buffer.data()); | 392 static_cast<uint8_t*>(extra_data_buffer.data()); |
| 395 cdm_decoder_config.extra_data_size = | 393 cdm_decoder_config.extra_data_size = extra_data_buffer.size(); |
| 396 static_cast<int32_t>(extra_data_buffer.size()); | |
| 397 status = cdm_->InitializeVideoDecoder(cdm_decoder_config); | 394 status = cdm_->InitializeVideoDecoder(cdm_decoder_config); |
| 398 } | 395 } |
| 399 | 396 |
| 400 CallOnMain(callback_factory_.NewCallback( | 397 CallOnMain(callback_factory_.NewCallback( |
| 401 &CdmAdapter::DecoderInitializeDone, | 398 &CdmAdapter::DecoderInitializeDone, |
| 402 PP_DECRYPTORSTREAMTYPE_VIDEO, | 399 PP_DECRYPTORSTREAMTYPE_VIDEO, |
| 403 decoder_config.request_id, | 400 decoder_config.request_id, |
| 404 status == cdm::kSuccess)); | 401 status == cdm::kSuccess)); |
| 405 } | 402 } |
| 406 | 403 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 encrypted_block_info.tracking_info)); | 471 encrypted_block_info.tracking_info)); |
| 475 return; | 472 return; |
| 476 } | 473 } |
| 477 | 474 |
| 478 default: | 475 default: |
| 479 PP_NOTREACHED(); | 476 PP_NOTREACHED(); |
| 480 return; | 477 return; |
| 481 } | 478 } |
| 482 } | 479 } |
| 483 | 480 |
| 484 cdm::Buffer* CdmAdapter::Allocate(int32_t capacity) { | 481 cdm::Buffer* CdmAdapter::Allocate(uint32_t capacity) { |
| 485 return allocator_.Allocate(capacity); | 482 return allocator_.Allocate(capacity); |
| 486 } | 483 } |
| 487 | 484 |
| 488 void CdmAdapter::SetTimer(int64_t delay_ms, void* context) { | 485 void CdmAdapter::SetTimer(int64_t delay_ms, void* context) { |
| 489 // NOTE: doesn't really need to run on the main thread; could just as well run | 486 // NOTE: doesn't really need to run on the main thread; could just as well run |
| 490 // on a helper thread if |cdm_| were thread-friendly and care was taken. We | 487 // on a helper thread if |cdm_| were thread-friendly and care was taken. We |
| 491 // only use CallOnMainThread() here to get delayed-execution behavior. | 488 // only use CallOnMainThread() here to get delayed-execution behavior. |
| 492 pp::Module::Get()->core()->CallOnMainThread( | 489 pp::Module::Get()->core()->CallOnMainThread( |
| 493 delay_ms, | 490 delay_ms, |
| 494 callback_factory_.NewCallback(&CdmAdapter::TimerExpired, context), | 491 callback_factory_.NewCallback(&CdmAdapter::TimerExpired, context), |
| 495 PP_OK); | 492 PP_OK); |
| 496 } | 493 } |
| 497 | 494 |
| 498 void CdmAdapter::TimerExpired(int32_t result, void* context) { | 495 void CdmAdapter::TimerExpired(int32_t result, void* context) { |
| 499 PP_DCHECK(result == PP_OK); | 496 PP_DCHECK(result == PP_OK); |
| 500 cdm_->TimerExpired(context); | 497 cdm_->TimerExpired(context); |
| 501 } | 498 } |
| 502 | 499 |
| 503 double CdmAdapter::GetCurrentWallTimeInSeconds() { | 500 double CdmAdapter::GetCurrentWallTimeInSeconds() { |
| 504 return pp::Module::Get()->core()->GetTime(); | 501 return pp::Module::Get()->core()->GetTime(); |
| 505 } | 502 } |
| 506 | 503 |
| 507 void CdmAdapter::SendKeyMessage( | 504 void CdmAdapter::SendKeyMessage( |
| 508 const char* session_id, int32_t session_id_length, | 505 const char* session_id, uint32_t session_id_length, |
| 509 const char* message, int32_t message_length, | 506 const char* message, uint32_t message_length, |
| 510 const char* default_url, int32_t default_url_length) { | 507 const char* default_url, uint32_t default_url_length) { |
| 511 PP_DCHECK(!key_system_.empty()); | 508 PP_DCHECK(!key_system_.empty()); |
| 512 PostOnMain(callback_factory_.NewCallback( | 509 PostOnMain(callback_factory_.NewCallback( |
| 513 &CdmAdapter::KeyMessage, | 510 &CdmAdapter::KeyMessage, |
| 514 SessionInfo(key_system_, | 511 SessionInfo(key_system_, |
| 515 std::string(session_id, session_id_length)), | 512 std::string(session_id, session_id_length)), |
| 516 std::vector<uint8>(message, message + message_length), | 513 std::vector<uint8>(message, message + message_length), |
| 517 std::string(default_url, default_url_length))); | 514 std::string(default_url, default_url_length))); |
| 518 } | 515 } |
| 519 | 516 |
| 520 void CdmAdapter::SendKeyError(const char* session_id, | 517 void CdmAdapter::SendKeyError(const char* session_id, |
| 521 int32_t session_id_length, | 518 uint32_t session_id_length, |
| 522 cdm::MediaKeyError error_code, | 519 cdm::MediaKeyError error_code, |
| 523 uint32_t system_code) { | 520 uint32_t system_code) { |
| 524 SendKeyErrorInternal(key_system_, | 521 SendKeyErrorInternal(key_system_, |
| 525 std::string(session_id, session_id_length), | 522 std::string(session_id, session_id_length), |
| 526 error_code, | 523 error_code, |
| 527 system_code); | 524 system_code); |
| 528 } | 525 } |
| 529 | 526 |
| 530 void CdmAdapter::GetPrivateData(int32_t* instance, | 527 void CdmAdapter::GetPrivateData(int32_t* instance, |
| 531 GetPrivateInterface* get_interface) { | 528 GetPrivateInterface* get_interface) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 bool CdmAdapter::IsValidVideoFrame(const LinkedVideoFrame& video_frame) { | 723 bool CdmAdapter::IsValidVideoFrame(const LinkedVideoFrame& video_frame) { |
| 727 if (!video_frame.get() || | 724 if (!video_frame.get() || |
| 728 !video_frame->FrameBuffer() || | 725 !video_frame->FrameBuffer() || |
| 729 (video_frame->Format() != cdm::kI420 && | 726 (video_frame->Format() != cdm::kI420 && |
| 730 video_frame->Format() != cdm::kYv12)) { | 727 video_frame->Format() != cdm::kYv12)) { |
| 731 return false; | 728 return false; |
| 732 } | 729 } |
| 733 | 730 |
| 734 PpbBuffer* ppb_buffer = static_cast<PpbBuffer*>(video_frame->FrameBuffer()); | 731 PpbBuffer* ppb_buffer = static_cast<PpbBuffer*>(video_frame->FrameBuffer()); |
| 735 | 732 |
| 736 for (int i = 0; i < cdm::VideoFrame::kMaxPlanes; ++i) { | 733 for (uint32_t i = 0; i < cdm::VideoFrame::kMaxPlanes; ++i) { |
| 737 int plane_height = (i == cdm::VideoFrame::kYPlane) ? | 734 int plane_height = (i == cdm::VideoFrame::kYPlane) ? |
| 738 video_frame->Size().height : (video_frame->Size().height + 1) / 2; | 735 video_frame->Size().height : (video_frame->Size().height + 1) / 2; |
| 739 cdm::VideoFrame::VideoPlane plane = | 736 cdm::VideoFrame::VideoPlane plane = |
| 740 static_cast<cdm::VideoFrame::VideoPlane>(i); | 737 static_cast<cdm::VideoFrame::VideoPlane>(i); |
| 741 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + | 738 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + |
| 742 plane_height * video_frame->Stride(plane)) { | 739 plane_height * video_frame->Stride(plane)) { |
| 743 return false; | 740 return false; |
| 744 } | 741 } |
| 745 } | 742 } |
| 746 | 743 |
| 747 return true; | 744 return true; |
| 748 } | 745 } |
| 749 | 746 |
| 747 void CdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type, |
| 748 cdm::Status decoder_status) { |
| 749 PP_NOTREACHED(); |
| 750 } |
| 751 |
| 750 void CdmAdapter::SendPlatformChallenge( | 752 void CdmAdapter::SendPlatformChallenge( |
| 751 const char* service_id, int32_t service_id_length, | 753 const char* service_id, uint32_t service_id_length, |
| 752 const char* challenge, int32_t challenge_length) { | 754 const char* challenge, uint32_t challenge_length) { |
| 753 #if defined(OS_CHROMEOS) | 755 #if defined(OS_CHROMEOS) |
| 754 PP_DCHECK(!challenge_in_progress_); | 756 PP_DCHECK(!challenge_in_progress_); |
| 755 | 757 |
| 756 // Ensure member variables set by the callback are in a clean state. | 758 // Ensure member variables set by the callback are in a clean state. |
| 757 signed_data_output_ = pp::Var(); | 759 signed_data_output_ = pp::Var(); |
| 758 signed_data_signature_output_ = pp::Var(); | 760 signed_data_signature_output_ = pp::Var(); |
| 759 platform_key_certificate_output_ = pp::Var(); | 761 platform_key_certificate_output_ = pp::Var(); |
| 760 | 762 |
| 761 pp::VarArrayBuffer challenge_var(challenge_length); | 763 pp::VarArrayBuffer challenge_var(challenge_length); |
| 762 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); | 764 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 return; | 827 return; |
| 826 } | 828 } |
| 827 | 829 |
| 828 pp::VarArrayBuffer signed_data_var(signed_data_output_); | 830 pp::VarArrayBuffer signed_data_var(signed_data_output_); |
| 829 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_); | 831 pp::VarArrayBuffer signed_data_signature_var(signed_data_signature_output_); |
| 830 std::string platform_key_certificate_string = | 832 std::string platform_key_certificate_string = |
| 831 platform_key_certificate_output_.AsString(); | 833 platform_key_certificate_output_.AsString(); |
| 832 | 834 |
| 833 cdm::PlatformChallengeResponse response = { | 835 cdm::PlatformChallengeResponse response = { |
| 834 static_cast<uint8_t*>(signed_data_var.Map()), | 836 static_cast<uint8_t*>(signed_data_var.Map()), |
| 835 static_cast<int32_t>(signed_data_var.ByteLength()), | 837 signed_data_var.ByteLength(), |
| 836 | 838 |
| 837 static_cast<uint8_t*>(signed_data_signature_var.Map()), | 839 static_cast<uint8_t*>(signed_data_signature_var.Map()), |
| 838 static_cast<int32_t>(signed_data_signature_var.ByteLength()), | 840 signed_data_signature_var.ByteLength(), |
| 839 | 841 |
| 840 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.c_str()), | 842 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.c_str()), |
| 841 static_cast<int32_t>(platform_key_certificate_string.length()) | 843 static_cast<uint32_t>(platform_key_certificate_string.length()) |
| 842 }; | 844 }; |
| 843 cdm_->OnPlatformChallengeResponse(response); | 845 cdm_->OnPlatformChallengeResponse(response); |
| 844 | 846 |
| 845 signed_data_var.Unmap(); | 847 signed_data_var.Unmap(); |
| 846 signed_data_signature_var.Unmap(); | 848 signed_data_signature_var.Unmap(); |
| 847 } | 849 } |
| 848 | 850 |
| 849 void CdmAdapter::EnableProtectionDone(int32_t result) { | 851 void CdmAdapter::EnableProtectionDone(int32_t result) { |
| 850 // Does nothing since clients must call QueryOutputProtectionStatus() to | 852 // Does nothing since clients must call QueryOutputProtectionStatus() to |
| 851 // inspect the protection status on a regular basis. | 853 // inspect the protection status on a regular basis. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 } // namespace media | 904 } // namespace media |
| 903 | 905 |
| 904 namespace pp { | 906 namespace pp { |
| 905 | 907 |
| 906 // Factory function for your specialization of the Module object. | 908 // Factory function for your specialization of the Module object. |
| 907 Module* CreateModule() { | 909 Module* CreateModule() { |
| 908 return new media::CdmAdapterModule(); | 910 return new media::CdmAdapterModule(); |
| 909 } | 911 } |
| 910 | 912 |
| 911 } // namespace pp | 913 } // namespace pp |
| OLD | NEW |