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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 if (format == PP_DECRYPTEDFRAMEFORMAT_YV12) | 119 if (format == PP_DECRYPTEDFRAMEFORMAT_YV12) |
120 return cdm::kYv12; | 120 return cdm::kYv12; |
121 else if (format == PP_DECRYPTEDFRAMEFORMAT_I420) | 121 else if (format == PP_DECRYPTEDFRAMEFORMAT_I420) |
122 return cdm::kI420; | 122 return cdm::kI420; |
123 else if (format == PP_DECRYPTEDFRAMEFORMAT_EMPTY) | 123 else if (format == PP_DECRYPTEDFRAMEFORMAT_EMPTY) |
124 return cdm::kEmptyVideoFrame; | 124 return cdm::kEmptyVideoFrame; |
125 | 125 |
126 return cdm::kUnknownVideoFormat; | 126 return cdm::kUnknownVideoFormat; |
127 } | 127 } |
128 | 128 |
129 cdm::StreamType PpDecryptorStreamTypeToCdmStreamType( | |
130 PP_DecryptorStreamType stream_type) { | |
131 switch (stream_type) { | |
132 case PP_DECRYPTORSTREAMTYPE_AUDIO: | |
133 return cdm::kStreamTypeAudio; | |
134 case PP_DECRYPTORSTREAMTYPE_VIDEO: | |
135 return cdm::kStreamTypeVideo; | |
136 } | |
137 | |
138 PP_NOTREACHED(); | |
139 return cdm::kStreamTypeVideo; | |
140 } | |
141 | |
129 } // namespace | 142 } // namespace |
130 | 143 |
131 namespace webkit_media { | 144 namespace webkit_media { |
132 | 145 |
133 // Provides access to memory owned by a pp::Buffer_Dev created by | 146 // Provides access to memory owned by a pp::Buffer_Dev created by |
134 // PpbBufferAllocator::Allocate(). This class holds a reference to the | 147 // PpbBufferAllocator::Allocate(). This class holds a reference to the |
135 // Buffer_Dev throughout its lifetime. | 148 // Buffer_Dev throughout its lifetime. |
136 class PpbBuffer : public cdm::Buffer { | 149 class PpbBuffer : public cdm::Buffer { |
137 public: | 150 public: |
138 // cdm::Buffer methods. | 151 // cdm::Buffer methods. |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 | 487 |
475 PpbBufferAllocator::PpbBufferAllocator(pp::Instance* instance) | 488 PpbBufferAllocator::PpbBufferAllocator(pp::Instance* instance) |
476 : instance_(instance) { | 489 : instance_(instance) { |
477 } | 490 } |
478 | 491 |
479 PpbBufferAllocator::~PpbBufferAllocator() { | 492 PpbBufferAllocator::~PpbBufferAllocator() { |
480 } | 493 } |
481 | 494 |
482 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t size) { | 495 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t size) { |
483 PP_DCHECK(size > 0); | 496 PP_DCHECK(size > 0); |
497 PP_DCHECK(IsMainThread()); | |
484 | 498 |
485 pp::Buffer_Dev buffer(instance_, size); | 499 pp::Buffer_Dev buffer(instance_, size); |
486 if (buffer.is_null()) | 500 if (buffer.is_null()) |
487 return NULL; | 501 return NULL; |
488 | 502 |
489 return new PpbBuffer(buffer); | 503 return new PpbBuffer(buffer); |
490 } | 504 } |
491 | 505 |
492 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) | 506 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) |
493 : pp::Instance(instance), | 507 : pp::Instance(instance), |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 cdm_decoder_config.extra_data = | 623 cdm_decoder_config.extra_data = |
610 static_cast<uint8_t*>(extra_data_buffer.data()); | 624 static_cast<uint8_t*>(extra_data_buffer.data()); |
611 cdm_decoder_config.extra_data_size = | 625 cdm_decoder_config.extra_data_size = |
612 static_cast<int32_t>(extra_data_buffer.size()); | 626 static_cast<int32_t>(extra_data_buffer.size()); |
613 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config); | 627 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config); |
614 | 628 |
615 CallOnMain(callback_factory_.NewCallback( | 629 CallOnMain(callback_factory_.NewCallback( |
616 &CdmWrapper::DecoderInitialized, | 630 &CdmWrapper::DecoderInitialized, |
617 status == cdm::kSuccess, | 631 status == cdm::kSuccess, |
618 decoder_config.request_id)); | 632 decoder_config.request_id)); |
619 | |
620 } | 633 } |
621 | 634 |
622 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type, | 635 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type, |
623 uint32_t request_id) { | 636 uint32_t request_id) { |
624 // TODO(tomfinegan): Implement DeinitializeDecoder in clear key CDM, and call | 637 cdm_->DeinitializeDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type)); |
625 // it here. | |
626 CallOnMain(callback_factory_.NewCallback( | 638 CallOnMain(callback_factory_.NewCallback( |
627 &CdmWrapper::DecoderDeinitializeDone, | 639 &CdmWrapper::DecoderDeinitializeDone, |
628 decoder_type, | 640 decoder_type, |
629 request_id)); | 641 request_id)); |
630 } | 642 } |
631 | 643 |
632 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type, | 644 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type, |
633 uint32_t request_id) { | 645 uint32_t request_id) { |
634 // TODO(tomfinegan): Implement ResetDecoder in clear key CDM, and call it | 646 cdm_->ResetDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type)); |
635 // here. | |
636 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone, | 647 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone, |
637 decoder_type, | 648 decoder_type, |
638 request_id)); | 649 request_id)); |
639 } | 650 } |
640 | 651 |
641 void CdmWrapper::DecryptAndDecode( | 652 void CdmWrapper::DecryptAndDecode( |
642 PP_DecryptorStreamType decoder_type, | 653 PP_DecryptorStreamType decoder_type, |
643 pp::Buffer_Dev encrypted_buffer, | 654 pp::Buffer_Dev encrypted_buffer, |
644 const PP_EncryptedBlockInfo& encrypted_block_info) { | 655 const PP_EncryptedBlockInfo& encrypted_block_info) { |
645 // TODO(tomfinegan): Remove this check when audio decoding is added. | 656 // TODO(tomfinegan): Remove this check when audio decoding is added. |
646 PP_DCHECK(decoder_type == PP_DECRYPTORSTREAMTYPE_VIDEO); | 657 PP_DCHECK(decoder_type == PP_DECRYPTORSTREAMTYPE_VIDEO); |
647 | 658 |
648 PP_DCHECK(!encrypted_buffer.is_null()); | |
649 PP_DCHECK(cdm_); | 659 PP_DCHECK(cdm_); |
650 | 660 |
651 cdm::InputBuffer input_buffer; | 661 cdm::InputBuffer input_buffer; |
652 std::vector<cdm::SubsampleEntry> subsamples; | 662 std::vector<cdm::SubsampleEntry> subsamples; |
653 ConfigureInputBuffer(encrypted_buffer, | 663 if (!encrypted_buffer.is_null()) { |
654 encrypted_block_info, | 664 ConfigureInputBuffer(encrypted_buffer, |
655 &subsamples, | 665 encrypted_block_info, |
656 &input_buffer); | 666 &subsamples, |
667 &input_buffer); | |
668 } | |
657 | 669 |
658 LinkedVideoFrame video_frame(new VideoFrameImpl()); | 670 LinkedVideoFrame video_frame(new VideoFrameImpl()); |
659 cdm::Status status = cdm_->DecryptAndDecodeFrame(input_buffer, | 671 cdm::Status status = cdm_->DecryptAndDecodeFrame(input_buffer, |
660 video_frame.get()); | 672 video_frame.get()); |
661 CallOnMain(callback_factory_.NewCallback( | 673 CallOnMain(callback_factory_.NewCallback( |
662 &CdmWrapper::DeliverFrame, | 674 &CdmWrapper::DeliverFrame, |
663 status, | 675 status, |
664 video_frame, | 676 video_frame, |
665 encrypted_block_info.tracking_info)); | 677 encrypted_block_info.tracking_info)); |
666 } | 678 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 void CdmWrapper::DeliverFrame( | 788 void CdmWrapper::DeliverFrame( |
777 int32_t result, | 789 int32_t result, |
778 const cdm::Status& status, | 790 const cdm::Status& status, |
779 const LinkedVideoFrame& video_frame, | 791 const LinkedVideoFrame& video_frame, |
780 const PP_DecryptTrackingInfo& tracking_info) { | 792 const PP_DecryptTrackingInfo& tracking_info) { |
781 PP_DCHECK(result == PP_OK); | 793 PP_DCHECK(result == PP_OK); |
782 PP_DecryptedFrameInfo decrypted_frame_info; | 794 PP_DecryptedFrameInfo decrypted_frame_info; |
783 decrypted_frame_info.tracking_info = tracking_info; | 795 decrypted_frame_info.tracking_info = tracking_info; |
784 | 796 |
785 switch (status) { | 797 switch (status) { |
798 // TODO(xhwang): Handle cdm::kNeedMoreData. | |
xhwang
2012/10/17 18:43:00
thanks!
| |
786 case cdm::kSuccess: | 799 case cdm::kSuccess: |
787 PP_DCHECK(video_frame->format() == cdm::kI420 || | 800 PP_DCHECK(video_frame->format() == cdm::kI420 || |
788 video_frame->format() == cdm::kYv12); | 801 video_frame->format() == cdm::kYv12); |
789 PP_DCHECK(video_frame.get() && video_frame->frame_buffer()); | 802 PP_DCHECK(video_frame.get() && video_frame->frame_buffer()); |
790 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS; | 803 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS; |
791 decrypted_frame_info.format = | 804 decrypted_frame_info.format = |
792 CdmVideoFormatToPpDecryptedFrameFormat(video_frame->format()); | 805 CdmVideoFormatToPpDecryptedFrameFormat(video_frame->format()); |
793 decrypted_frame_info.width = video_frame->size().width; | 806 decrypted_frame_info.width = video_frame->size().width; |
794 decrypted_frame_info.height = video_frame->size().height; | 807 decrypted_frame_info.height = video_frame->size().height; |
795 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] = | 808 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] = |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
844 } // namespace webkit_media | 857 } // namespace webkit_media |
845 | 858 |
846 namespace pp { | 859 namespace pp { |
847 | 860 |
848 // Factory function for your specialization of the Module object. | 861 // Factory function for your specialization of the Module object. |
849 Module* CreateModule() { | 862 Module* CreateModule() { |
850 return new webkit_media::CdmWrapperModule(); | 863 return new webkit_media::CdmWrapperModule(); |
851 } | 864 } |
852 | 865 |
853 } // namespace pp | 866 } // namespace pp |
OLD | NEW |