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 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 | 473 |
| 461 PpbBufferAllocator::PpbBufferAllocator(pp::Instance* instance) | 474 PpbBufferAllocator::PpbBufferAllocator(pp::Instance* instance) |
| 462 : instance_(instance) { | 475 : instance_(instance) { |
| 463 } | 476 } |
| 464 | 477 |
| 465 PpbBufferAllocator::~PpbBufferAllocator() { | 478 PpbBufferAllocator::~PpbBufferAllocator() { |
| 466 } | 479 } |
| 467 | 480 |
| 468 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t size) { | 481 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t size) { |
| 469 PP_DCHECK(size > 0); | 482 PP_DCHECK(size > 0); |
| 483 PP_DCHECK(IsMainThread()); | |
| 470 | 484 |
| 471 pp::Buffer_Dev buffer(instance_, size); | 485 pp::Buffer_Dev buffer(instance_, size); |
| 472 if (buffer.is_null()) | 486 if (buffer.is_null()) |
| 473 return NULL; | 487 return NULL; |
| 474 | 488 |
| 475 return new PpbBuffer(buffer); | 489 return new PpbBuffer(buffer); |
| 476 } | 490 } |
| 477 | 491 |
| 478 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) | 492 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) |
| 479 : pp::Instance(instance), | 493 : pp::Instance(instance), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 cdm_decoder_config.extra_data = | 609 cdm_decoder_config.extra_data = |
| 596 static_cast<uint8_t*>(extra_data_buffer.data()); | 610 static_cast<uint8_t*>(extra_data_buffer.data()); |
| 597 cdm_decoder_config.extra_data_size = | 611 cdm_decoder_config.extra_data_size = |
| 598 static_cast<int32_t>(extra_data_buffer.size()); | 612 static_cast<int32_t>(extra_data_buffer.size()); |
| 599 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config); | 613 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config); |
| 600 | 614 |
| 601 CallOnMain(callback_factory_.NewCallback( | 615 CallOnMain(callback_factory_.NewCallback( |
| 602 &CdmWrapper::DecoderInitialized, | 616 &CdmWrapper::DecoderInitialized, |
| 603 status == cdm::kSuccess, | 617 status == cdm::kSuccess, |
| 604 decoder_config.request_id)); | 618 decoder_config.request_id)); |
| 605 | |
| 606 } | 619 } |
| 607 | 620 |
| 608 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type, | 621 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type, |
|
xhwang
2012/10/16 21:59:53
s/decoder_type/stream_type ?
Tom Finegan
2012/10/17 02:39:10
I prefer decoder_type here. I think it fits better
xhwang
2012/10/17 18:43:00
SG :)
| |
| 609 uint32_t request_id) { | 622 uint32_t request_id) { |
| 610 // TODO(tomfinegan): Implement DeinitializeDecoder in clear key CDM, and call | 623 cdm_->DeinitializeDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type)); |
| 611 // it here. | |
| 612 CallOnMain(callback_factory_.NewCallback( | 624 CallOnMain(callback_factory_.NewCallback( |
| 613 &CdmWrapper::DecoderDeinitializeDone, | 625 &CdmWrapper::DecoderDeinitializeDone, |
| 614 decoder_type, | 626 decoder_type, |
| 615 request_id)); | 627 request_id)); |
| 616 } | 628 } |
| 617 | 629 |
| 618 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type, | 630 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type, |
| 619 uint32_t request_id) { | 631 uint32_t request_id) { |
| 620 // TODO(tomfinegan): Implement ResetDecoder in clear key CDM, and call it | 632 cdm_->ResetDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type)); |
| 621 // here. | |
| 622 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone, | 633 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone, |
| 623 decoder_type, | 634 decoder_type, |
| 624 request_id)); | 635 request_id)); |
| 625 } | 636 } |
| 626 | 637 |
| 627 void CdmWrapper::DecryptAndDecode( | 638 void CdmWrapper::DecryptAndDecode( |
| 628 PP_DecryptorStreamType decoder_type, | 639 PP_DecryptorStreamType decoder_type, |
| 629 pp::Buffer_Dev encrypted_buffer, | 640 pp::Buffer_Dev encrypted_buffer, |
| 630 const PP_EncryptedBlockInfo& encrypted_block_info) { | 641 const PP_EncryptedBlockInfo& encrypted_block_info) { |
| 631 // TODO(tomfinegan): Remove this check when audio decoding is added. | 642 // TODO(tomfinegan): Remove this check when audio decoding is added. |
| 632 PP_DCHECK(decoder_type == PP_DECRYPTORSTREAMTYPE_VIDEO); | 643 PP_DCHECK(decoder_type == PP_DECRYPTORSTREAMTYPE_VIDEO); |
| 633 | 644 |
| 634 PP_DCHECK(!encrypted_buffer.is_null()); | |
| 635 PP_DCHECK(cdm_); | 645 PP_DCHECK(cdm_); |
| 636 | 646 |
| 637 cdm::InputBuffer input_buffer; | 647 cdm::InputBuffer input_buffer; |
| 638 std::vector<cdm::SubsampleEntry> subsamples; | 648 std::vector<cdm::SubsampleEntry> subsamples; |
| 639 ConfigureInputBuffer(encrypted_buffer, | 649 if (!encrypted_buffer.is_null()) { |
| 640 encrypted_block_info, | 650 ConfigureInputBuffer(encrypted_buffer, |
| 641 &subsamples, | 651 encrypted_block_info, |
| 642 &input_buffer); | 652 &subsamples, |
| 653 &input_buffer); | |
| 654 } | |
| 643 | 655 |
| 644 LinkedVideoFrame video_frame(new VideoFrameImpl()); | 656 LinkedVideoFrame video_frame(new VideoFrameImpl()); |
| 645 cdm::Status status = cdm_->DecryptAndDecodeFrame(input_buffer, | 657 cdm::Status status = cdm_->DecryptAndDecodeFrame(input_buffer, |
| 646 video_frame.get()); | 658 video_frame.get()); |
| 647 CallOnMain(callback_factory_.NewCallback( | 659 CallOnMain(callback_factory_.NewCallback( |
| 648 &CdmWrapper::DeliverFrame, | 660 &CdmWrapper::DeliverFrame, |
| 649 status, | 661 status, |
| 650 video_frame, | 662 video_frame, |
| 651 encrypted_block_info.tracking_info)); | 663 encrypted_block_info.tracking_info)); |
| 652 } | 664 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 828 } // namespace webkit_media | 840 } // namespace webkit_media |
| 829 | 841 |
| 830 namespace pp { | 842 namespace pp { |
| 831 | 843 |
| 832 // Factory function for your specialization of the Module object. | 844 // Factory function for your specialization of the Module object. |
| 833 Module* CreateModule() { | 845 Module* CreateModule() { |
| 834 return new webkit_media::CdmWrapperModule(); | 846 return new webkit_media::CdmWrapperModule(); |
| 835 } | 847 } |
| 836 | 848 |
| 837 } // namespace pp | 849 } // namespace pp |
| OLD | NEW |