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" |
| 11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
| 12 #include "ppapi/c/pp_stdint.h" | 12 #include "ppapi/c/pp_stdint.h" |
| 13 #include "ppapi/c/private/pp_content_decryptor.h" | 13 #include "ppapi/c/private/pp_content_decryptor.h" |
| 14 #include "ppapi/cpp/completion_callback.h" | 14 #include "ppapi/cpp/completion_callback.h" |
| 15 #include "ppapi/cpp/core.h" | 15 #include "ppapi/cpp/core.h" |
| 16 #include "ppapi/cpp/instance.h" | 16 #include "ppapi/cpp/instance.h" |
| 17 #include "ppapi/cpp/logging.h" | 17 #include "ppapi/cpp/logging.h" |
| 18 #include "ppapi/cpp/module.h" | 18 #include "ppapi/cpp/module.h" |
| 19 #include "ppapi/cpp/pass_ref.h" | 19 #include "ppapi/cpp/pass_ref.h" |
| 20 #include "ppapi/cpp/resource.h" | 20 #include "ppapi/cpp/resource.h" |
| 21 #include "ppapi/cpp/var.h" | 21 #include "ppapi/cpp/var.h" |
| 22 #include "ppapi/cpp/var_array_buffer.h" | 22 #include "ppapi/cpp/var_array_buffer.h" |
| 23 #include "ppapi/cpp/dev/buffer_dev.h" | 23 #include "ppapi/cpp/dev/buffer_dev.h" |
| 24 #include "ppapi/cpp/private/content_decryptor_private.h" | 24 #include "ppapi/cpp/private/content_decryptor_private.h" |
| 25 #include "ppapi/utility/completion_callback_factory.h" | 25 #include "ppapi/utility/completion_callback_factory.h" |
| 26 #include "webkit/media/crypto/ppapi/content_decryption_module.h" | |
| 26 #include "webkit/media/crypto/ppapi/linked_ptr.h" | 27 #include "webkit/media/crypto/ppapi/linked_ptr.h" |
| 27 #include "webkit/media/crypto/ppapi/content_decryption_module.h" | |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // This must be consistent with MediaKeyError defined in the spec: | 31 // This must be consistent with MediaKeyError defined in the spec: |
| 32 // http://goo.gl/rbdnR | 32 // http://goo.gl/rbdnR |
| 33 // TODO(xhwang): Add PP_MediaKeyError enum to avoid later static_cast in | 33 // TODO(xhwang): Add PP_MediaKeyError enum to avoid later static_cast in |
| 34 // PluginInstance. | 34 // PluginInstance. |
| 35 enum MediaKeyError { | 35 enum MediaKeyError { |
| 36 kUnknownError = 1, | 36 kUnknownError = 1, |
| 37 kClientError, | 37 kClientError, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 if (format == PP_DECRYPTEDFRAMEFORMAT_YV12) | 121 if (format == PP_DECRYPTEDFRAMEFORMAT_YV12) |
| 122 return cdm::kYv12; | 122 return cdm::kYv12; |
| 123 else if (format == PP_DECRYPTEDFRAMEFORMAT_I420) | 123 else if (format == PP_DECRYPTEDFRAMEFORMAT_I420) |
| 124 return cdm::kI420; | 124 return cdm::kI420; |
| 125 else if (format == PP_DECRYPTEDFRAMEFORMAT_EMPTY) | 125 else if (format == PP_DECRYPTEDFRAMEFORMAT_EMPTY) |
| 126 return cdm::kEmptyVideoFrame; | 126 return cdm::kEmptyVideoFrame; |
| 127 | 127 |
| 128 return cdm::kUnknownVideoFormat; | 128 return cdm::kUnknownVideoFormat; |
| 129 } | 129 } |
| 130 | 130 |
| 131 cdm::StreamType PpDecryptorStreamTypeToCdmStreamType( | |
| 132 PP_DecryptorStreamType stream_type) { | |
| 133 switch (stream_type) { | |
| 134 case PP_DECRYPTORSTREAMTYPE_AUDIO: | |
| 135 return cdm::kStreamTypeAudio; | |
| 136 case PP_DECRYPTORSTREAMTYPE_VIDEO: | |
| 137 return cdm::kStreamTypeVideo; | |
| 138 } | |
| 139 | |
| 140 PP_NOTREACHED(); | |
| 141 return cdm::kStreamTypeVideo; | |
| 142 } | |
| 143 | |
| 131 } // namespace | 144 } // namespace |
| 132 | 145 |
| 133 namespace webkit_media { | 146 namespace webkit_media { |
| 134 | 147 |
| 135 // Provides access to memory owned by a pp::Buffer_Dev created by | 148 // Provides access to memory owned by a pp::Buffer_Dev created by |
| 136 // PpbBufferAllocator::Allocate(). This class holds a reference to the | 149 // PpbBufferAllocator::Allocate(). This class holds a reference to the |
| 137 // Buffer_Dev throughout its lifetime. | 150 // Buffer_Dev throughout its lifetime. |
| 138 class PpbBuffer : public cdm::Buffer { | 151 class PpbBuffer : public cdm::Buffer { |
| 139 public: | 152 public: |
| 140 // cdm::Buffer methods. | 153 // cdm::Buffer methods. |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 | 489 |
| 477 PpbBufferAllocator::PpbBufferAllocator(pp::Instance* instance) | 490 PpbBufferAllocator::PpbBufferAllocator(pp::Instance* instance) |
| 478 : instance_(instance) { | 491 : instance_(instance) { |
| 479 } | 492 } |
| 480 | 493 |
| 481 PpbBufferAllocator::~PpbBufferAllocator() { | 494 PpbBufferAllocator::~PpbBufferAllocator() { |
| 482 } | 495 } |
| 483 | 496 |
| 484 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t size) { | 497 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t size) { |
| 485 PP_DCHECK(size > 0); | 498 PP_DCHECK(size > 0); |
| 499 PP_DCHECK(IsMainThread()); | |
| 486 | 500 |
| 487 pp::Buffer_Dev buffer(instance_, size); | 501 pp::Buffer_Dev buffer(instance_, size); |
| 488 if (buffer.is_null()) | 502 if (buffer.is_null()) |
| 489 return NULL; | 503 return NULL; |
| 490 | 504 |
| 491 return new PpbBuffer(buffer); | 505 return new PpbBuffer(buffer); |
| 492 } | 506 } |
| 493 | 507 |
| 494 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) | 508 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) |
| 495 : pp::Instance(instance), | 509 : pp::Instance(instance), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 cdm_decoder_config.extra_data = | 625 cdm_decoder_config.extra_data = |
| 612 static_cast<uint8_t*>(extra_data_buffer.data()); | 626 static_cast<uint8_t*>(extra_data_buffer.data()); |
| 613 cdm_decoder_config.extra_data_size = | 627 cdm_decoder_config.extra_data_size = |
| 614 static_cast<int32_t>(extra_data_buffer.size()); | 628 static_cast<int32_t>(extra_data_buffer.size()); |
| 615 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config); | 629 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config); |
| 616 | 630 |
| 617 CallOnMain(callback_factory_.NewCallback( | 631 CallOnMain(callback_factory_.NewCallback( |
| 618 &CdmWrapper::DecoderInitialized, | 632 &CdmWrapper::DecoderInitialized, |
| 619 status == cdm::kSuccess, | 633 status == cdm::kSuccess, |
| 620 decoder_config.request_id)); | 634 decoder_config.request_id)); |
| 621 | |
| 622 } | 635 } |
| 623 | 636 |
| 624 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type, | 637 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type, |
| 625 uint32_t request_id) { | 638 uint32_t request_id) { |
| 626 // TODO(tomfinegan): Implement DeinitializeDecoder in clear key CDM, and call | 639 cdm_->DeinitializeDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type)); |
| 627 // it here. | |
| 628 CallOnMain(callback_factory_.NewCallback( | 640 CallOnMain(callback_factory_.NewCallback( |
| 629 &CdmWrapper::DecoderDeinitializeDone, | 641 &CdmWrapper::DecoderDeinitializeDone, |
| 630 decoder_type, | 642 decoder_type, |
| 631 request_id)); | 643 request_id)); |
| 632 } | 644 } |
| 633 | 645 |
| 634 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type, | 646 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type, |
| 635 uint32_t request_id) { | 647 uint32_t request_id) { |
| 636 // TODO(tomfinegan): Implement ResetDecoder in clear key CDM, and call it | 648 cdm_->ResetDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type)); |
| 637 // here. | |
| 638 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone, | 649 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone, |
| 639 decoder_type, | 650 decoder_type, |
| 640 request_id)); | 651 request_id)); |
| 641 } | 652 } |
| 642 | 653 |
| 643 void CdmWrapper::DecryptAndDecode( | 654 void CdmWrapper::DecryptAndDecode( |
| 644 PP_DecryptorStreamType decoder_type, | 655 PP_DecryptorStreamType decoder_type, |
| 645 pp::Buffer_Dev encrypted_buffer, | 656 pp::Buffer_Dev encrypted_buffer, |
| 646 const PP_EncryptedBlockInfo& encrypted_block_info) { | 657 const PP_EncryptedBlockInfo& encrypted_block_info) { |
| 647 // TODO(tomfinegan): Remove this check when audio decoding is added. | 658 // TODO(tomfinegan): Remove this check when audio decoding is added. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 video_frame->plane_offset(cdm::VideoFrame::kUPlane); | 818 video_frame->plane_offset(cdm::VideoFrame::kUPlane); |
| 808 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] = | 819 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] = |
| 809 video_frame->plane_offset(cdm::VideoFrame::kVPlane); | 820 video_frame->plane_offset(cdm::VideoFrame::kVPlane); |
| 810 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] = | 821 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] = |
| 811 video_frame->stride(cdm::VideoFrame::kYPlane); | 822 video_frame->stride(cdm::VideoFrame::kYPlane); |
| 812 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] = | 823 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] = |
| 813 video_frame->stride(cdm::VideoFrame::kUPlane); | 824 video_frame->stride(cdm::VideoFrame::kUPlane); |
| 814 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_V] = | 825 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_V] = |
| 815 video_frame->stride(cdm::VideoFrame::kVPlane); | 826 video_frame->stride(cdm::VideoFrame::kVPlane); |
| 816 break; | 827 break; |
| 828 case cdm::kNeedMoreData: | |
| 829 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS; | |
|
xhwang
2012/10/18 16:30:25
I am surprised to see we don't have NeedMoreData i
Tom Finegan
2012/10/18 19:29:41
sgtm
| |
| 830 decrypted_frame_info.format = PP_DECRYPTEDFRAMEFORMAT_EMPTY; | |
| 831 break; | |
| 817 case cdm::kNoKey: | 832 case cdm::kNoKey: |
| 818 decrypted_frame_info.result = PP_DECRYPTRESULT_DECRYPT_NOKEY; | 833 decrypted_frame_info.result = PP_DECRYPTRESULT_DECRYPT_NOKEY; |
| 819 break; | 834 break; |
| 820 case cdm::kDecryptError: | 835 case cdm::kDecryptError: |
| 821 decrypted_frame_info.result = PP_DECRYPTRESULT_DECRYPT_ERROR; | 836 decrypted_frame_info.result = PP_DECRYPTRESULT_DECRYPT_ERROR; |
| 822 break; | 837 break; |
| 823 case cdm::kDecodeError: | 838 case cdm::kDecodeError: |
| 824 decrypted_frame_info.result = PP_DECRYPTRESULT_DECODE_ERROR; | 839 decrypted_frame_info.result = PP_DECRYPTRESULT_DECODE_ERROR; |
| 825 break; | 840 break; |
| 826 case cdm::kSessionError: | 841 case cdm::kSessionError: |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 853 } // namespace webkit_media | 868 } // namespace webkit_media |
| 854 | 869 |
| 855 namespace pp { | 870 namespace pp { |
| 856 | 871 |
| 857 // Factory function for your specialization of the Module object. | 872 // Factory function for your specialization of the Module object. |
| 858 Module* CreateModule() { | 873 Module* CreateModule() { |
| 859 return new webkit_media::CdmWrapperModule(); | 874 return new webkit_media::CdmWrapperModule(); |
| 860 } | 875 } |
| 861 | 876 |
| 862 } // namespace pp | 877 } // namespace pp |
| OLD | NEW |