Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstring> | 5 #include <cstring> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 encrypted_block_info.subsamples[i].clear_bytes, | 79 encrypted_block_info.subsamples[i].clear_bytes, |
| 80 encrypted_block_info.subsamples[i].cipher_bytes)); | 80 encrypted_block_info.subsamples[i].cipher_bytes)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 input_buffer->subsamples = &(*subsamples)[0]; | 83 input_buffer->subsamples = &(*subsamples)[0]; |
| 84 } | 84 } |
| 85 | 85 |
| 86 input_buffer->timestamp = encrypted_block_info.tracking_info.timestamp; | 86 input_buffer->timestamp = encrypted_block_info.tracking_info.timestamp; |
| 87 } | 87 } |
| 88 | 88 |
| 89 PP_DecryptedFrameFormat VideoFormatToPpDecryptedFrameFormat( | 89 PP_DecryptedFrameFormat CdmVideoFormatToPpDecryptedFrameFormat( |
| 90 cdm::VideoFormat format) { | 90 cdm::VideoFormat format) { |
| 91 switch(format) { | 91 switch(format) { |
| 92 case cdm::kEmptyVideoFrame: | 92 case cdm::kEmptyVideoFrame: |
| 93 return PP_DECRYPTEDFRAMEFORMAT_EMPTY; | 93 return PP_DECRYPTEDFRAMEFORMAT_EMPTY; |
| 94 case cdm::kYv12: | 94 case cdm::kYv12: |
| 95 return PP_DECRYPTEDFRAMEFORMAT_YV12; | 95 return PP_DECRYPTEDFRAMEFORMAT_YV12; |
| 96 case cdm::kI420: | 96 case cdm::kI420: |
| 97 return PP_DECRYPTEDFRAMEFORMAT_I420; | 97 return PP_DECRYPTEDFRAMEFORMAT_I420; |
| 98 case cdm::kUnknownVideoFormat: | 98 case cdm::kUnknownVideoFormat: |
| 99 default: | 99 default: |
| 100 return PP_DECRYPTEDFRAMEFORMAT_UNKNOWN; | 100 return PP_DECRYPTEDFRAMEFORMAT_UNKNOWN; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 cdm::VideoDecoderConfig::VideoCodec PpVideoCodecToCdmVideoCodec( | |
| 105 PP_VideoCodec codec) { | |
| 106 switch (codec) { | |
| 107 case PP_VIDEOCODEC_VP8: | |
| 108 return cdm::VideoDecoderConfig::kCodecVP8; | |
| 109 case PP_VIDEOCODEC_UNKNOWN: | |
| 110 default: | |
|
Ami GONE FROM CHROMIUM
2012/10/09 07:21:12
The need for these default: cases when all enum va
Tom Finegan
2012/10/09 19:49:09
MSVC has the correct type. I don't know why it's r
| |
| 111 return cdm::VideoDecoderConfig::kUnknownVideoCodec; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 cdm::VideoDecoderConfig::VideoCodecProfile | |
| 116 PpVideoCodecProfileToCdmVideoCodecProfile(PP_VideoCodecProfile profile) { | |
| 117 switch (profile) { | |
| 118 case PP_VIDEOCODECPROFILE_VP8_MAIN: | |
| 119 return cdm::VideoDecoderConfig::kVp8ProfileMain; | |
| 120 case PP_VIDEOCODECPROFILE_UNKNOWN: | |
| 121 default: | |
| 122 return cdm::VideoDecoderConfig::kUnknownVideoCodecProfile; | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 cdm::VideoFormat PpDecryptedFrameFormatToCdmVideoFormat( | |
| 127 PP_DecryptedFrameFormat format) { | |
| 128 switch (format) { | |
| 129 case PP_DECRYPTEDFRAMEFORMAT_YV12: | |
| 130 return cdm::kYv12; | |
| 131 case PP_DECRYPTEDFRAMEFORMAT_I420: | |
| 132 return cdm::kI420; | |
| 133 case PP_DECRYPTEDFRAMEFORMAT_UNKNOWN: | |
| 134 return cdm::kUnknownVideoFormat; | |
| 135 case PP_DECRYPTEDFRAMEFORMAT_EMPTY: | |
| 136 default: | |
| 137 return cdm::kEmptyVideoFrame; | |
| 138 } | |
| 139 } | |
| 140 | |
| 104 } // namespace | 141 } // namespace |
| 105 | 142 |
| 106 namespace webkit_media { | 143 namespace webkit_media { |
| 107 | 144 |
| 108 // Provides access to memory owned by a pp::Buffer_Dev created by | 145 // Provides access to memory owned by a pp::Buffer_Dev created by |
| 109 // PpbBufferAllocator::Allocate(). This class holds a reference to the | 146 // PpbBufferAllocator::Allocate(). This class holds a reference to the |
| 110 // Buffer_Dev throughout its lifetime. | 147 // Buffer_Dev throughout its lifetime. |
| 111 class PpbBuffer : public cdm::Buffer { | 148 class PpbBuffer : public cdm::Buffer { |
| 112 public: | 149 public: |
| 113 // cdm::Buffer methods. | 150 // cdm::Buffer methods. |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 // PPB_ContentDecryptor_Private interface. | 408 // PPB_ContentDecryptor_Private interface. |
| 372 virtual void GenerateKeyRequest(const std::string& key_system, | 409 virtual void GenerateKeyRequest(const std::string& key_system, |
| 373 pp::VarArrayBuffer init_data) OVERRIDE; | 410 pp::VarArrayBuffer init_data) OVERRIDE; |
| 374 virtual void AddKey(const std::string& session_id, | 411 virtual void AddKey(const std::string& session_id, |
| 375 pp::VarArrayBuffer key, | 412 pp::VarArrayBuffer key, |
| 376 pp::VarArrayBuffer init_data) OVERRIDE; | 413 pp::VarArrayBuffer init_data) OVERRIDE; |
| 377 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; | 414 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; |
| 378 virtual void Decrypt( | 415 virtual void Decrypt( |
| 379 pp::Buffer_Dev encrypted_buffer, | 416 pp::Buffer_Dev encrypted_buffer, |
| 380 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 417 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
| 418 virtual void InitializeVideoDecoder( | |
| 419 const PP_VideoDecoderConfig& decoder_config, | |
| 420 pp::Buffer_Dev extra_data_buffer) OVERRIDE; | |
| 381 virtual void DecryptAndDecodeFrame( | 421 virtual void DecryptAndDecodeFrame( |
| 382 pp::Buffer_Dev encrypted_frame, | 422 pp::Buffer_Dev encrypted_frame, |
| 383 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) OVERRIDE; | 423 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) OVERRIDE; |
| 384 | 424 |
| 385 private: | 425 private: |
| 386 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; | 426 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; |
| 387 typedef linked_ptr<KeyMessageImpl> LinkedKeyMessage; | 427 typedef linked_ptr<KeyMessageImpl> LinkedKeyMessage; |
| 388 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; | 428 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; |
| 389 | 429 |
| 390 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to | 430 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to |
| 391 // <code>callback_factory_</code> to ensure that calls into | 431 // <code>callback_factory_</code> to ensure that calls into |
| 392 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. | 432 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. |
| 393 void KeyAdded(int32_t result, const std::string& session_id); | 433 void KeyAdded(int32_t result, const std::string& session_id); |
| 394 void KeyMessage(int32_t result, const LinkedKeyMessage& message); | 434 void KeyMessage(int32_t result, const LinkedKeyMessage& message); |
| 395 void KeyError(int32_t result, const std::string& session_id); | 435 void KeyError(int32_t result, const std::string& session_id); |
| 396 void DeliverBlock(int32_t result, | 436 void DeliverBlock(int32_t result, |
| 397 const cdm::Status& status, | 437 const cdm::Status& status, |
| 398 const LinkedDecryptedBlock& decrypted_block, | 438 const LinkedDecryptedBlock& decrypted_block, |
| 399 const PP_DecryptTrackingInfo& tracking_info); | 439 const PP_DecryptTrackingInfo& tracking_info); |
| 440 void DecoderInitialized(int32_t result, | |
| 441 bool success, | |
| 442 uint32_t request_id); | |
| 400 void DeliverFrame(int32_t result, | 443 void DeliverFrame(int32_t result, |
| 401 const cdm::Status& status, | 444 const cdm::Status& status, |
| 402 const LinkedVideoFrame& video_frame, | 445 const LinkedVideoFrame& video_frame, |
| 403 const PP_DecryptTrackingInfo& tracking_info); | 446 const PP_DecryptTrackingInfo& tracking_info); |
| 404 | 447 |
| 405 PpbBufferAllocator allocator_; | 448 PpbBufferAllocator allocator_; |
| 406 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_; | 449 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_; |
| 407 cdm::ContentDecryptionModule* cdm_; | 450 cdm::ContentDecryptionModule* cdm_; |
| 408 std::string key_system_; | 451 std::string key_system_; |
| 409 }; | 452 }; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl()); | 566 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl()); |
| 524 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get()); | 567 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get()); |
| 525 | 568 |
| 526 CallOnMain(callback_factory_.NewCallback( | 569 CallOnMain(callback_factory_.NewCallback( |
| 527 &CdmWrapper::DeliverBlock, | 570 &CdmWrapper::DeliverBlock, |
| 528 status, | 571 status, |
| 529 decrypted_block, | 572 decrypted_block, |
| 530 encrypted_block_info.tracking_info)); | 573 encrypted_block_info.tracking_info)); |
| 531 } | 574 } |
| 532 | 575 |
| 576 void CdmWrapper::InitializeVideoDecoder( | |
| 577 const PP_VideoDecoderConfig& decoder_config, | |
| 578 pp::Buffer_Dev extra_data_buffer) { | |
| 579 PP_DCHECK(cdm_); | |
| 580 cdm::VideoDecoderConfig cdm_decoder_config; | |
| 581 cdm_decoder_config.codec = PpVideoCodecToCdmVideoCodec(decoder_config.codec); | |
| 582 cdm_decoder_config.profile = | |
| 583 PpVideoCodecProfileToCdmVideoCodecProfile(decoder_config.profile); | |
| 584 cdm_decoder_config.format = | |
| 585 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format); | |
| 586 cdm_decoder_config.coded_size.width = decoder_config.width; | |
| 587 cdm_decoder_config.coded_size.height = decoder_config.height; | |
| 588 cdm_decoder_config.extra_data = | |
| 589 static_cast<uint8_t*>(extra_data_buffer.data()); | |
| 590 cdm_decoder_config.extra_data_size = | |
| 591 static_cast<int32_t>(extra_data_buffer.size()); | |
| 592 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config); | |
| 593 | |
| 594 CallOnMain(callback_factory_.NewCallback( | |
| 595 &CdmWrapper::DecoderInitialized, | |
| 596 status == cdm::kSuccess, | |
| 597 decoder_config.request_id)); | |
| 598 | |
| 599 } | |
| 600 | |
| 533 void CdmWrapper::DecryptAndDecodeFrame( | 601 void CdmWrapper::DecryptAndDecodeFrame( |
| 534 pp::Buffer_Dev encrypted_frame, | 602 pp::Buffer_Dev encrypted_frame, |
| 535 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) { | 603 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) { |
| 536 PP_DCHECK(!encrypted_frame.is_null()); | 604 PP_DCHECK(!encrypted_frame.is_null()); |
| 537 PP_DCHECK(cdm_); | 605 PP_DCHECK(cdm_); |
| 538 | 606 |
| 539 cdm::InputBuffer input_buffer; | 607 cdm::InputBuffer input_buffer; |
| 540 std::vector<cdm::SubsampleEntry> subsamples; | 608 std::vector<cdm::SubsampleEntry> subsamples; |
| 541 ConfigureInputBuffer(encrypted_frame, | 609 ConfigureInputBuffer(encrypted_frame, |
| 542 encrypted_video_frame_info.encryption_info, | 610 encrypted_video_frame_info.encryption_info, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 } | 668 } |
| 601 | 669 |
| 602 const pp::Buffer_Dev& buffer = | 670 const pp::Buffer_Dev& buffer = |
| 603 decrypted_block.get() && decrypted_block->buffer() ? | 671 decrypted_block.get() && decrypted_block->buffer() ? |
| 604 static_cast<PpbBuffer*>(decrypted_block->buffer())->buffer_dev() : | 672 static_cast<PpbBuffer*>(decrypted_block->buffer())->buffer_dev() : |
| 605 pp::Buffer_Dev(); | 673 pp::Buffer_Dev(); |
| 606 | 674 |
| 607 pp::ContentDecryptor_Private::DeliverBlock(buffer, decrypted_block_info); | 675 pp::ContentDecryptor_Private::DeliverBlock(buffer, decrypted_block_info); |
| 608 } | 676 } |
| 609 | 677 |
| 678 void CdmWrapper::DecoderInitialized(int32_t result, | |
| 679 bool success, | |
| 680 uint32_t request_id) { | |
| 681 pp::ContentDecryptor_Private::DecoderInitialized(success, request_id); | |
| 682 } | |
| 683 | |
| 610 void CdmWrapper::DeliverFrame( | 684 void CdmWrapper::DeliverFrame( |
| 611 int32_t result, | 685 int32_t result, |
| 612 const cdm::Status& status, | 686 const cdm::Status& status, |
| 613 const LinkedVideoFrame& video_frame, | 687 const LinkedVideoFrame& video_frame, |
| 614 const PP_DecryptTrackingInfo& tracking_info) { | 688 const PP_DecryptTrackingInfo& tracking_info) { |
| 615 PP_DecryptedFrameInfo decrypted_frame_info; | 689 PP_DecryptedFrameInfo decrypted_frame_info; |
| 616 decrypted_frame_info.tracking_info = tracking_info; | 690 decrypted_frame_info.tracking_info = tracking_info; |
| 617 | 691 |
| 618 switch (status) { | 692 switch (status) { |
| 619 case cdm::kSuccess: | 693 case cdm::kSuccess: |
| 620 PP_DCHECK(video_frame->format() == cdm::kI420 || | 694 PP_DCHECK(video_frame->format() == cdm::kI420 || |
| 621 video_frame->format() == cdm::kYv12); | 695 video_frame->format() == cdm::kYv12); |
| 622 PP_DCHECK(video_frame.get() && video_frame->frame_buffer()); | 696 PP_DCHECK(video_frame.get() && video_frame->frame_buffer()); |
| 623 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS; | 697 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS; |
| 624 decrypted_frame_info.format = | 698 decrypted_frame_info.format = |
| 625 VideoFormatToPpDecryptedFrameFormat(video_frame->format()); | 699 CdmVideoFormatToPpDecryptedFrameFormat(video_frame->format()); |
| 626 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] = | 700 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] = |
| 627 video_frame->plane_offset(cdm::VideoFrame::kYPlane); | 701 video_frame->plane_offset(cdm::VideoFrame::kYPlane); |
| 628 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_U] = | 702 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_U] = |
| 629 video_frame->plane_offset(cdm::VideoFrame::kUPlane); | 703 video_frame->plane_offset(cdm::VideoFrame::kUPlane); |
| 630 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] = | 704 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] = |
| 631 video_frame->plane_offset(cdm::VideoFrame::kVPlane); | 705 video_frame->plane_offset(cdm::VideoFrame::kVPlane); |
| 632 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] = | 706 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] = |
| 633 video_frame->stride(cdm::VideoFrame::kYPlane); | 707 video_frame->stride(cdm::VideoFrame::kYPlane); |
| 634 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] = | 708 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] = |
| 635 video_frame->stride(cdm::VideoFrame::kUPlane); | 709 video_frame->stride(cdm::VideoFrame::kUPlane); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 } // namespace webkit_media | 749 } // namespace webkit_media |
| 676 | 750 |
| 677 namespace pp { | 751 namespace pp { |
| 678 | 752 |
| 679 // Factory function for your specialization of the Module object. | 753 // Factory function for your specialization of the Module object. |
| 680 Module* CreateModule() { | 754 Module* CreateModule() { |
| 681 return new webkit_media::CdmWrapperModule(); | 755 return new webkit_media::CdmWrapperModule(); |
| 682 } | 756 } |
| 683 | 757 |
| 684 } // namespace pp | 758 } // namespace pp |
| OLD | NEW |