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

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

Issue 11013052: Add PPAPI CDM video decoder initialization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed with the exceptions being some questions and TODOs. 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
« no previous file with comments | « ppapi/thunk/ppb_instance_api.h ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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:
100 return PP_DECRYPTEDFRAMEFORMAT_UNKNOWN; 99 return PP_DECRYPTEDFRAMEFORMAT_UNKNOWN;
101 } 100 }
102 } 101 }
103 102
103 cdm::VideoDecoderConfig::VideoCodec PpVideoCodecToCdmVideoCodec(
104 PP_VideoCodec codec) {
105 switch (codec) {
106 case PP_VIDEOCODEC_VP8:
107 return cdm::VideoDecoderConfig::kCodecVP8;
108 case PP_VIDEOCODEC_UNKNOWN:
109 return cdm::VideoDecoderConfig::kUnknownVideoCodec;
110 }
111 }
112
113 cdm::VideoDecoderConfig::VideoCodecProfile
114 PpVideoCodecProfileToCdmVideoCodecProfile(PP_VideoCodecProfile profile) {
xhwang 2012/10/09 00:49:08 I am not sure about if this indentation is correct
Tom Finegan 2012/10/09 01:12:42 Yeah, me neither... incredibly long function name.
Ami GONE FROM CHROMIUM 2012/10/09 07:21:12 <MatrixEvade> rename method to PpVCProfileToCdmVCP
Tom Finegan 2012/10/09 19:49:08 Done.
115 switch (profile) {
116 case PP_VIDEOCODECPROFILE_VP8_MAIN:
117 return cdm::VideoDecoderConfig::kVp8ProfileMain;
118 case PP_VIDEOCODECPROFILE_UNKNOWN:
119 return cdm::VideoDecoderConfig::kUnknownVideoCodecProfile;
120 }
121 }
122
123 cdm::VideoFormat PpDecryptedFrameFormatToCdmVideoFormat(
124 PP_DecryptedFrameFormat format) {
125 switch (format) {
126 case PP_DECRYPTEDFRAMEFORMAT_YV12:
127 return cdm::kYv12;
128 case PP_DECRYPTEDFRAMEFORMAT_I420:
129 return cdm::kI420;
130 case PP_DECRYPTEDFRAMEFORMAT_UNKNOWN:
131 return cdm::kUnknownVideoFormat;
132 case PP_DECRYPTEDFRAMEFORMAT_EMPTY:
133 return cdm::kEmptyVideoFrame;
134 }
135 }
136
104 } // namespace 137 } // namespace
105 138
106 namespace webkit_media { 139 namespace webkit_media {
107 140
108 // Provides access to memory owned by a pp::Buffer_Dev created by 141 // Provides access to memory owned by a pp::Buffer_Dev created by
109 // PpbBufferAllocator::Allocate(). This class holds a reference to the 142 // PpbBufferAllocator::Allocate(). This class holds a reference to the
110 // Buffer_Dev throughout its lifetime. 143 // Buffer_Dev throughout its lifetime.
111 class PpbBuffer : public cdm::Buffer { 144 class PpbBuffer : public cdm::Buffer {
112 public: 145 public:
113 // cdm::Buffer methods. 146 // cdm::Buffer methods.
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // PPB_ContentDecryptor_Private interface. 404 // PPB_ContentDecryptor_Private interface.
372 virtual void GenerateKeyRequest(const std::string& key_system, 405 virtual void GenerateKeyRequest(const std::string& key_system,
373 pp::VarArrayBuffer init_data) OVERRIDE; 406 pp::VarArrayBuffer init_data) OVERRIDE;
374 virtual void AddKey(const std::string& session_id, 407 virtual void AddKey(const std::string& session_id,
375 pp::VarArrayBuffer key, 408 pp::VarArrayBuffer key,
376 pp::VarArrayBuffer init_data) OVERRIDE; 409 pp::VarArrayBuffer init_data) OVERRIDE;
377 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; 410 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE;
378 virtual void Decrypt( 411 virtual void Decrypt(
379 pp::Buffer_Dev encrypted_buffer, 412 pp::Buffer_Dev encrypted_buffer,
380 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; 413 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
414 virtual void InitializeVideoDecoder(
415 const PP_VideoDecoderConfig& decoder_config,
416 pp::Buffer_Dev extra_data_buffer) OVERRIDE;
381 virtual void DecryptAndDecodeFrame( 417 virtual void DecryptAndDecodeFrame(
382 pp::Buffer_Dev encrypted_frame, 418 pp::Buffer_Dev encrypted_frame,
383 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) OVERRIDE; 419 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) OVERRIDE;
384 420
385 private: 421 private:
386 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; 422 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock;
387 typedef linked_ptr<KeyMessageImpl> LinkedKeyMessage; 423 typedef linked_ptr<KeyMessageImpl> LinkedKeyMessage;
388 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; 424 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame;
389 425
390 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to 426 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to
391 // <code>callback_factory_</code> to ensure that calls into 427 // <code>callback_factory_</code> to ensure that calls into
392 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. 428 // <code>PPP_ContentDecryptor_Private</code> are asynchronous.
393 void KeyAdded(int32_t result, const std::string& session_id); 429 void KeyAdded(int32_t result, const std::string& session_id);
394 void KeyMessage(int32_t result, const LinkedKeyMessage& message); 430 void KeyMessage(int32_t result, const LinkedKeyMessage& message);
395 void KeyError(int32_t result, const std::string& session_id); 431 void KeyError(int32_t result, const std::string& session_id);
396 void DeliverBlock(int32_t result, 432 void DeliverBlock(int32_t result,
397 const cdm::Status& status, 433 const cdm::Status& status,
398 const LinkedDecryptedBlock& decrypted_block, 434 const LinkedDecryptedBlock& decrypted_block,
399 const PP_DecryptTrackingInfo& tracking_info); 435 const PP_DecryptTrackingInfo& tracking_info);
436 void DecoderInitialized(int32_t result,
437 bool success,
438 uint32_t request_id);
400 void DeliverFrame(int32_t result, 439 void DeliverFrame(int32_t result,
401 const cdm::Status& status, 440 const cdm::Status& status,
402 const LinkedVideoFrame& video_frame, 441 const LinkedVideoFrame& video_frame,
403 const PP_DecryptTrackingInfo& tracking_info); 442 const PP_DecryptTrackingInfo& tracking_info);
404 443
405 PpbBufferAllocator allocator_; 444 PpbBufferAllocator allocator_;
406 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_; 445 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_;
407 cdm::ContentDecryptionModule* cdm_; 446 cdm::ContentDecryptionModule* cdm_;
408 std::string key_system_; 447 std::string key_system_;
409 }; 448 };
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl()); 562 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl());
524 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get()); 563 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get());
525 564
526 CallOnMain(callback_factory_.NewCallback( 565 CallOnMain(callback_factory_.NewCallback(
527 &CdmWrapper::DeliverBlock, 566 &CdmWrapper::DeliverBlock,
528 status, 567 status,
529 decrypted_block, 568 decrypted_block,
530 encrypted_block_info.tracking_info)); 569 encrypted_block_info.tracking_info));
531 } 570 }
532 571
572 void CdmWrapper::InitializeVideoDecoder(
573 const PP_VideoDecoderConfig& decoder_config,
574 pp::Buffer_Dev extra_data_buffer) {
575 PP_DCHECK(cdm_);
576 cdm::VideoDecoderConfig cdm_decoder_config;
577 cdm_decoder_config.codec = PpVideoCodecToCdmVideoCodec(decoder_config.codec);
xhwang 2012/10/09 00:49:08 This is okay. We can also set the status to kError
Tom Finegan 2012/10/09 01:12:42 My thinking was to allow the CDMs to decide which
xhwang 2012/10/09 15:50:49 ok
578 cdm_decoder_config.profile =
579 PpVideoCodecProfileToCdmVideoCodecProfile(decoder_config.profile);
580 cdm_decoder_config.format =
581 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format);
582 cdm_decoder_config.coded_size.width = decoder_config.width;
583 cdm_decoder_config.coded_size.height = decoder_config.height;
584 cdm_decoder_config.extra_data =
585 static_cast<uint8_t*>(extra_data_buffer.data());
586 cdm_decoder_config.extra_data_size =
587 static_cast<int32_t>(extra_data_buffer.size());
588 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config);
589
590 CallOnMain(callback_factory_.NewCallback(
591 &CdmWrapper::DecoderInitialized,
592 status == cdm::kSuccess,
593 decoder_config.request_id));
594
595 }
596
533 void CdmWrapper::DecryptAndDecodeFrame( 597 void CdmWrapper::DecryptAndDecodeFrame(
534 pp::Buffer_Dev encrypted_frame, 598 pp::Buffer_Dev encrypted_frame,
535 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) { 599 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) {
536 PP_DCHECK(!encrypted_frame.is_null()); 600 PP_DCHECK(!encrypted_frame.is_null());
537 PP_DCHECK(cdm_); 601 PP_DCHECK(cdm_);
538 602
539 cdm::InputBuffer input_buffer; 603 cdm::InputBuffer input_buffer;
540 std::vector<cdm::SubsampleEntry> subsamples; 604 std::vector<cdm::SubsampleEntry> subsamples;
541 ConfigureInputBuffer(encrypted_frame, 605 ConfigureInputBuffer(encrypted_frame,
542 encrypted_video_frame_info.encryption_info, 606 encrypted_video_frame_info.encryption_info,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 664 }
601 665
602 const pp::Buffer_Dev& buffer = 666 const pp::Buffer_Dev& buffer =
603 decrypted_block.get() && decrypted_block->buffer() ? 667 decrypted_block.get() && decrypted_block->buffer() ?
604 static_cast<PpbBuffer*>(decrypted_block->buffer())->buffer_dev() : 668 static_cast<PpbBuffer*>(decrypted_block->buffer())->buffer_dev() :
605 pp::Buffer_Dev(); 669 pp::Buffer_Dev();
606 670
607 pp::ContentDecryptor_Private::DeliverBlock(buffer, decrypted_block_info); 671 pp::ContentDecryptor_Private::DeliverBlock(buffer, decrypted_block_info);
608 } 672 }
609 673
674 void CdmWrapper::DecoderInitialized(int32_t result,
675 bool success,
xhwang 2012/10/09 00:49:08 indentation is off
Tom Finegan 2012/10/09 01:12:42 Done.
676 uint32_t request_id) {
677 pp::ContentDecryptor_Private::DecoderInitialized(success, request_id);
678 }
679
610 void CdmWrapper::DeliverFrame( 680 void CdmWrapper::DeliverFrame(
611 int32_t result, 681 int32_t result,
612 const cdm::Status& status, 682 const cdm::Status& status,
613 const LinkedVideoFrame& video_frame, 683 const LinkedVideoFrame& video_frame,
614 const PP_DecryptTrackingInfo& tracking_info) { 684 const PP_DecryptTrackingInfo& tracking_info) {
615 PP_DecryptedFrameInfo decrypted_frame_info; 685 PP_DecryptedFrameInfo decrypted_frame_info;
616 decrypted_frame_info.tracking_info = tracking_info; 686 decrypted_frame_info.tracking_info = tracking_info;
617 687
618 switch (status) { 688 switch (status) {
619 case cdm::kSuccess: 689 case cdm::kSuccess:
620 PP_DCHECK(video_frame->format() == cdm::kI420 || 690 PP_DCHECK(video_frame->format() == cdm::kI420 ||
621 video_frame->format() == cdm::kYv12); 691 video_frame->format() == cdm::kYv12);
622 PP_DCHECK(video_frame.get() && video_frame->frame_buffer()); 692 PP_DCHECK(video_frame.get() && video_frame->frame_buffer());
623 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS; 693 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS;
624 decrypted_frame_info.format = 694 decrypted_frame_info.format =
625 VideoFormatToPpDecryptedFrameFormat(video_frame->format()); 695 CdmVideoFormatToPpDecryptedFrameFormat(video_frame->format());
626 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] = 696 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] =
627 video_frame->plane_offset(cdm::VideoFrame::kYPlane); 697 video_frame->plane_offset(cdm::VideoFrame::kYPlane);
628 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_U] = 698 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_U] =
629 video_frame->plane_offset(cdm::VideoFrame::kUPlane); 699 video_frame->plane_offset(cdm::VideoFrame::kUPlane);
630 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] = 700 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] =
631 video_frame->plane_offset(cdm::VideoFrame::kVPlane); 701 video_frame->plane_offset(cdm::VideoFrame::kVPlane);
632 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] = 702 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] =
633 video_frame->stride(cdm::VideoFrame::kYPlane); 703 video_frame->stride(cdm::VideoFrame::kYPlane);
634 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] = 704 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] =
635 video_frame->stride(cdm::VideoFrame::kUPlane); 705 video_frame->stride(cdm::VideoFrame::kUPlane);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } // namespace webkit_media 745 } // namespace webkit_media
676 746
677 namespace pp { 747 namespace pp {
678 748
679 // Factory function for your specialization of the Module object. 749 // Factory function for your specialization of the Module object.
680 Module* CreateModule() { 750 Module* CreateModule() {
681 return new webkit_media::CdmWrapperModule(); 751 return new webkit_media::CdmWrapperModule();
682 } 752 }
683 753
684 } // namespace pp 754 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/thunk/ppb_instance_api.h ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698