Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: webkit/media/crypto/ppapi/cdm_wrapper.cc

Issue 10899021: Add CDM video decoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 if (format == PP_DECRYPTEDFRAMEFORMAT_YV12) 129 if (format == PP_DECRYPTEDFRAMEFORMAT_YV12)
130 return cdm::kYv12; 130 return cdm::kYv12;
131 else if (format == PP_DECRYPTEDFRAMEFORMAT_I420) 131 else if (format == PP_DECRYPTEDFRAMEFORMAT_I420)
132 return cdm::kI420; 132 return cdm::kI420;
133 else if (format == PP_DECRYPTEDFRAMEFORMAT_EMPTY) 133 else if (format == PP_DECRYPTEDFRAMEFORMAT_EMPTY)
134 return cdm::kEmptyVideoFrame; 134 return cdm::kEmptyVideoFrame;
135 135
136 return cdm::kUnknownVideoFormat; 136 return cdm::kUnknownVideoFormat;
137 } 137 }
138 138
139 cdm::StreamType PpDecryptorStreamTypeToCdmStreamType(
140 PP_DecryptorStreamType stream_type) {
141 switch (stream_type) {
142 case PP_DECRYPTORSTREAMTYPE_AUDIO:
143 return cdm::kStreamTypeAudio;
144 case PP_DECRYPTORSTREAMTYPE_VIDEO:
145 return cdm::kStreamTypeVideo;
146 }
147
148 PP_NOTREACHED();
149 return cdm::kStreamTypeVideo;
150 }
151
139 } // namespace 152 } // namespace
140 153
141 namespace webkit_media { 154 namespace webkit_media {
142 155
143 // Provides access to memory owned by a pp::Buffer_Dev created by 156 // Provides access to memory owned by a pp::Buffer_Dev created by
144 // PpbBufferAllocator::Allocate(). This class holds a reference to the 157 // PpbBufferAllocator::Allocate(). This class holds a reference to the
145 // Buffer_Dev throughout its lifetime. 158 // Buffer_Dev throughout its lifetime.
146 class PpbBuffer : public cdm::Buffer { 159 class PpbBuffer : public cdm::Buffer {
147 public: 160 public:
148 // cdm::Buffer methods. 161 // cdm::Buffer methods.
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 501
489 PpbBufferAllocator::PpbBufferAllocator(pp::Instance* instance) 502 PpbBufferAllocator::PpbBufferAllocator(pp::Instance* instance)
490 : instance_(instance) { 503 : instance_(instance) {
491 } 504 }
492 505
493 PpbBufferAllocator::~PpbBufferAllocator() { 506 PpbBufferAllocator::~PpbBufferAllocator() {
494 } 507 }
495 508
496 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t size) { 509 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t size) {
497 PP_DCHECK(size > 0); 510 PP_DCHECK(size > 0);
511 PP_DCHECK(IsMainThread());
498 512
499 pp::Buffer_Dev buffer(instance_, size); 513 pp::Buffer_Dev buffer(instance_, size);
500 if (buffer.is_null()) 514 if (buffer.is_null())
501 return NULL; 515 return NULL;
502 516
503 return new PpbBuffer(buffer); 517 return new PpbBuffer(buffer);
504 } 518 }
505 519
506 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) 520 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module)
507 : pp::Instance(instance), 521 : pp::Instance(instance),
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 664
651 CallOnMain(callback_factory_.NewCallback( 665 CallOnMain(callback_factory_.NewCallback(
652 &CdmWrapper::DecoderInitializeDone, 666 &CdmWrapper::DecoderInitializeDone,
653 PP_DECRYPTORSTREAMTYPE_VIDEO, 667 PP_DECRYPTORSTREAMTYPE_VIDEO,
654 decoder_config.request_id, 668 decoder_config.request_id,
655 status == cdm::kSuccess)); 669 status == cdm::kSuccess));
656 } 670 }
657 671
658 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type, 672 void CdmWrapper::DeinitializeDecoder(PP_DecryptorStreamType decoder_type,
659 uint32_t request_id) { 673 uint32_t request_id) {
660 // TODO(tomfinegan): Implement DeinitializeDecoder in clear key CDM, and call 674 cdm_->DeinitializeDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type));
661 // it here.
662 CallOnMain(callback_factory_.NewCallback( 675 CallOnMain(callback_factory_.NewCallback(
663 &CdmWrapper::DecoderDeinitializeDone, 676 &CdmWrapper::DecoderDeinitializeDone,
664 decoder_type, 677 decoder_type,
665 request_id)); 678 request_id));
666 } 679 }
667 680
668 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type, 681 void CdmWrapper::ResetDecoder(PP_DecryptorStreamType decoder_type,
669 uint32_t request_id) { 682 uint32_t request_id) {
670 // TODO(tomfinegan): Implement ResetDecoder in clear key CDM, and call it 683 cdm_->ResetDecoder(PpDecryptorStreamTypeToCdmStreamType(decoder_type));
671 // here.
672 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone, 684 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::DecoderResetDone,
673 decoder_type, 685 decoder_type,
674 request_id)); 686 request_id));
675 } 687 }
676 688
677 void CdmWrapper::DecryptAndDecode( 689 void CdmWrapper::DecryptAndDecode(
678 PP_DecryptorStreamType decoder_type, 690 PP_DecryptorStreamType decoder_type,
679 pp::Buffer_Dev encrypted_buffer, 691 pp::Buffer_Dev encrypted_buffer,
680 const PP_EncryptedBlockInfo& encrypted_block_info) { 692 const PP_EncryptedBlockInfo& encrypted_block_info) {
681 // TODO(tomfinegan): Remove this check when audio decoding is added. 693 // TODO(tomfinegan): Remove this check when audio decoding is added.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 video_frame->plane_offset(cdm::VideoFrame::kUPlane); 857 video_frame->plane_offset(cdm::VideoFrame::kUPlane);
846 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] = 858 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] =
847 video_frame->plane_offset(cdm::VideoFrame::kVPlane); 859 video_frame->plane_offset(cdm::VideoFrame::kVPlane);
848 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] = 860 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] =
849 video_frame->stride(cdm::VideoFrame::kYPlane); 861 video_frame->stride(cdm::VideoFrame::kYPlane);
850 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] = 862 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] =
851 video_frame->stride(cdm::VideoFrame::kUPlane); 863 video_frame->stride(cdm::VideoFrame::kUPlane);
852 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_V] = 864 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_V] =
853 video_frame->stride(cdm::VideoFrame::kVPlane); 865 video_frame->stride(cdm::VideoFrame::kVPlane);
854 break; 866 break;
867 case cdm::kNeedMoreData:
868 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS;
869 decrypted_frame_info.format = PP_DECRYPTEDFRAMEFORMAT_EMPTY;
870 break;
855 case cdm::kNoKey: 871 case cdm::kNoKey:
856 decrypted_frame_info.result = PP_DECRYPTRESULT_DECRYPT_NOKEY; 872 decrypted_frame_info.result = PP_DECRYPTRESULT_DECRYPT_NOKEY;
857 break; 873 break;
858 case cdm::kDecryptError: 874 case cdm::kDecryptError:
859 decrypted_frame_info.result = PP_DECRYPTRESULT_DECRYPT_ERROR; 875 decrypted_frame_info.result = PP_DECRYPTRESULT_DECRYPT_ERROR;
860 break; 876 break;
861 case cdm::kDecodeError: 877 case cdm::kDecodeError:
862 decrypted_frame_info.result = PP_DECRYPTRESULT_DECODE_ERROR; 878 decrypted_frame_info.result = PP_DECRYPTRESULT_DECODE_ERROR;
863 break; 879 break;
864 case cdm::kSessionError: 880 case cdm::kSessionError:
(...skipping 26 matching lines...) Expand all
891 } // namespace webkit_media 907 } // namespace webkit_media
892 908
893 namespace pp { 909 namespace pp {
894 910
895 // Factory function for your specialization of the Module object. 911 // Factory function for your specialization of the Module object.
896 Module* CreateModule() { 912 Module* CreateModule() {
897 return new webkit_media::CdmWrapperModule(); 913 return new webkit_media::CdmWrapperModule();
898 } 914 }
899 915
900 } // namespace pp 916 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppp_content_decryptor_private_proxy.cc ('k') | webkit/media/crypto/ppapi/clear_key_cdm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698