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

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: 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"
(...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 if (format == cdm::kEmptyVideoFrame)
92 case cdm::kEmptyVideoFrame: 92 return PP_DECRYPTEDFRAMEFORMAT_EMPTY;
93 return PP_DECRYPTEDFRAMEFORMAT_EMPTY; 93 else if (format == cdm::kYv12)
94 case cdm::kYv12: 94 return PP_DECRYPTEDFRAMEFORMAT_YV12;
95 return PP_DECRYPTEDFRAMEFORMAT_YV12; 95 else if (format == cdm::kI420)
96 case cdm::kI420: 96 return PP_DECRYPTEDFRAMEFORMAT_I420;
97 return PP_DECRYPTEDFRAMEFORMAT_I420; 97
98 case cdm::kUnknownVideoFormat: 98 return PP_DECRYPTEDFRAMEFORMAT_UNKNOWN;
99 default: 99 }
100 return PP_DECRYPTEDFRAMEFORMAT_UNKNOWN; 100
101 } 101 cdm::VideoDecoderConfig::VideoCodec PpVideoCodecToCdmVideoCodec(
102 PP_VideoCodec codec) {
103 if (codec == PP_VIDEOCODEC_VP8)
104 return cdm::VideoDecoderConfig::kCodecVP8;
105
106 return cdm::VideoDecoderConfig::kUnknownVideoCodec;
107 }
108
109 cdm::VideoDecoderConfig::VideoCodecProfile PpVCProfileToCdmVCProfile(
110 PP_VideoCodecProfile profile) {
111 if (profile == PP_VIDEOCODECPROFILE_VP8_MAIN)
112 return cdm::VideoDecoderConfig::kVp8ProfileMain;
113
114 return cdm::VideoDecoderConfig::kUnknownVideoCodecProfile;
115 }
116
117 cdm::VideoFormat PpDecryptedFrameFormatToCdmVideoFormat(
118 PP_DecryptedFrameFormat format) {
119 if (format == PP_DECRYPTEDFRAMEFORMAT_YV12)
120 return cdm::kYv12;
121 else if (format == PP_DECRYPTEDFRAMEFORMAT_I420)
122 return cdm::kI420;
123 else if (format == PP_DECRYPTEDFRAMEFORMAT_EMPTY)
124 return cdm::kEmptyVideoFrame;
125
126 return cdm::kUnknownVideoFormat;
102 } 127 }
103 128
104 } // namespace 129 } // namespace
105 130
106 namespace webkit_media { 131 namespace webkit_media {
107 132
108 // Provides access to memory owned by a pp::Buffer_Dev created by 133 // Provides access to memory owned by a pp::Buffer_Dev created by
109 // PpbBufferAllocator::Allocate(). This class holds a reference to the 134 // PpbBufferAllocator::Allocate(). This class holds a reference to the
110 // Buffer_Dev throughout its lifetime. 135 // Buffer_Dev throughout its lifetime.
111 class PpbBuffer : public cdm::Buffer { 136 class PpbBuffer : public cdm::Buffer {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // PPB_ContentDecryptor_Private interface. 396 // PPB_ContentDecryptor_Private interface.
372 virtual void GenerateKeyRequest(const std::string& key_system, 397 virtual void GenerateKeyRequest(const std::string& key_system,
373 pp::VarArrayBuffer init_data) OVERRIDE; 398 pp::VarArrayBuffer init_data) OVERRIDE;
374 virtual void AddKey(const std::string& session_id, 399 virtual void AddKey(const std::string& session_id,
375 pp::VarArrayBuffer key, 400 pp::VarArrayBuffer key,
376 pp::VarArrayBuffer init_data) OVERRIDE; 401 pp::VarArrayBuffer init_data) OVERRIDE;
377 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; 402 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE;
378 virtual void Decrypt( 403 virtual void Decrypt(
379 pp::Buffer_Dev encrypted_buffer, 404 pp::Buffer_Dev encrypted_buffer,
380 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; 405 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
406 virtual void InitializeVideoDecoder(
407 const PP_VideoDecoderConfig& decoder_config,
408 pp::Buffer_Dev extra_data_buffer) OVERRIDE;
381 virtual void DecryptAndDecodeFrame( 409 virtual void DecryptAndDecodeFrame(
382 pp::Buffer_Dev encrypted_frame, 410 pp::Buffer_Dev encrypted_frame,
383 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) OVERRIDE; 411 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) OVERRIDE;
384 412
385 private: 413 private:
386 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; 414 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock;
387 typedef linked_ptr<KeyMessageImpl> LinkedKeyMessage; 415 typedef linked_ptr<KeyMessageImpl> LinkedKeyMessage;
388 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; 416 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame;
389 417
390 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to 418 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to
391 // <code>callback_factory_</code> to ensure that calls into 419 // <code>callback_factory_</code> to ensure that calls into
392 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. 420 // <code>PPP_ContentDecryptor_Private</code> are asynchronous.
393 void KeyAdded(int32_t result, const std::string& session_id); 421 void KeyAdded(int32_t result, const std::string& session_id);
394 void KeyMessage(int32_t result, const LinkedKeyMessage& message); 422 void KeyMessage(int32_t result, const LinkedKeyMessage& message);
395 void KeyError(int32_t result, const std::string& session_id); 423 void KeyError(int32_t result, const std::string& session_id);
396 void DeliverBlock(int32_t result, 424 void DeliverBlock(int32_t result,
397 const cdm::Status& status, 425 const cdm::Status& status,
398 const LinkedDecryptedBlock& decrypted_block, 426 const LinkedDecryptedBlock& decrypted_block,
399 const PP_DecryptTrackingInfo& tracking_info); 427 const PP_DecryptTrackingInfo& tracking_info);
428 void DecoderInitialized(int32_t result,
429 bool success,
430 uint32_t request_id);
400 void DeliverFrame(int32_t result, 431 void DeliverFrame(int32_t result,
401 const cdm::Status& status, 432 const cdm::Status& status,
402 const LinkedVideoFrame& video_frame, 433 const LinkedVideoFrame& video_frame,
403 const PP_DecryptTrackingInfo& tracking_info); 434 const PP_DecryptTrackingInfo& tracking_info);
404 435
405 PpbBufferAllocator allocator_; 436 PpbBufferAllocator allocator_;
406 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_; 437 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_;
407 cdm::ContentDecryptionModule* cdm_; 438 cdm::ContentDecryptionModule* cdm_;
408 std::string key_system_; 439 std::string key_system_;
409 }; 440 };
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl()); 554 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl());
524 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get()); 555 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get());
525 556
526 CallOnMain(callback_factory_.NewCallback( 557 CallOnMain(callback_factory_.NewCallback(
527 &CdmWrapper::DeliverBlock, 558 &CdmWrapper::DeliverBlock,
528 status, 559 status,
529 decrypted_block, 560 decrypted_block,
530 encrypted_block_info.tracking_info)); 561 encrypted_block_info.tracking_info));
531 } 562 }
532 563
564 void CdmWrapper::InitializeVideoDecoder(
565 const PP_VideoDecoderConfig& decoder_config,
566 pp::Buffer_Dev extra_data_buffer) {
567 PP_DCHECK(cdm_);
568 cdm::VideoDecoderConfig cdm_decoder_config;
569 cdm_decoder_config.codec = PpVideoCodecToCdmVideoCodec(decoder_config.codec);
570 cdm_decoder_config.profile =
571 PpVCProfileToCdmVCProfile(decoder_config.profile);
572 cdm_decoder_config.format =
573 PpDecryptedFrameFormatToCdmVideoFormat(decoder_config.format);
574 cdm_decoder_config.coded_size.width = decoder_config.width;
575 cdm_decoder_config.coded_size.height = decoder_config.height;
576 cdm_decoder_config.extra_data =
577 static_cast<uint8_t*>(extra_data_buffer.data());
578 cdm_decoder_config.extra_data_size =
579 static_cast<int32_t>(extra_data_buffer.size());
580 cdm::Status status = cdm_->InitializeVideoDecoder(cdm_decoder_config);
581
582 CallOnMain(callback_factory_.NewCallback(
583 &CdmWrapper::DecoderInitialized,
584 status == cdm::kSuccess,
585 decoder_config.request_id));
586
587 }
588
533 void CdmWrapper::DecryptAndDecodeFrame( 589 void CdmWrapper::DecryptAndDecodeFrame(
534 pp::Buffer_Dev encrypted_frame, 590 pp::Buffer_Dev encrypted_frame,
535 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) { 591 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) {
536 PP_DCHECK(!encrypted_frame.is_null()); 592 PP_DCHECK(!encrypted_frame.is_null());
537 PP_DCHECK(cdm_); 593 PP_DCHECK(cdm_);
538 594
539 cdm::InputBuffer input_buffer; 595 cdm::InputBuffer input_buffer;
540 std::vector<cdm::SubsampleEntry> subsamples; 596 std::vector<cdm::SubsampleEntry> subsamples;
541 ConfigureInputBuffer(encrypted_frame, 597 ConfigureInputBuffer(encrypted_frame,
542 encrypted_video_frame_info.encryption_info, 598 encrypted_video_frame_info.encryption_info,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 656 }
601 657
602 const pp::Buffer_Dev& buffer = 658 const pp::Buffer_Dev& buffer =
603 decrypted_block.get() && decrypted_block->buffer() ? 659 decrypted_block.get() && decrypted_block->buffer() ?
604 static_cast<PpbBuffer*>(decrypted_block->buffer())->buffer_dev() : 660 static_cast<PpbBuffer*>(decrypted_block->buffer())->buffer_dev() :
605 pp::Buffer_Dev(); 661 pp::Buffer_Dev();
606 662
607 pp::ContentDecryptor_Private::DeliverBlock(buffer, decrypted_block_info); 663 pp::ContentDecryptor_Private::DeliverBlock(buffer, decrypted_block_info);
608 } 664 }
609 665
666 void CdmWrapper::DecoderInitialized(int32_t result,
667 bool success,
668 uint32_t request_id) {
669 pp::ContentDecryptor_Private::DecoderInitialized(success, request_id);
670 }
671
610 void CdmWrapper::DeliverFrame( 672 void CdmWrapper::DeliverFrame(
611 int32_t result, 673 int32_t result,
612 const cdm::Status& status, 674 const cdm::Status& status,
613 const LinkedVideoFrame& video_frame, 675 const LinkedVideoFrame& video_frame,
614 const PP_DecryptTrackingInfo& tracking_info) { 676 const PP_DecryptTrackingInfo& tracking_info) {
615 PP_DecryptedFrameInfo decrypted_frame_info; 677 PP_DecryptedFrameInfo decrypted_frame_info;
616 decrypted_frame_info.tracking_info = tracking_info; 678 decrypted_frame_info.tracking_info = tracking_info;
617 679
618 switch (status) { 680 switch (status) {
619 case cdm::kSuccess: 681 case cdm::kSuccess:
620 PP_DCHECK(video_frame->format() == cdm::kI420 || 682 PP_DCHECK(video_frame->format() == cdm::kI420 ||
621 video_frame->format() == cdm::kYv12); 683 video_frame->format() == cdm::kYv12);
622 PP_DCHECK(video_frame.get() && video_frame->frame_buffer()); 684 PP_DCHECK(video_frame.get() && video_frame->frame_buffer());
623 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS; 685 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS;
624 decrypted_frame_info.format = 686 decrypted_frame_info.format =
625 VideoFormatToPpDecryptedFrameFormat(video_frame->format()); 687 CdmVideoFormatToPpDecryptedFrameFormat(video_frame->format());
626 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] = 688 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] =
627 video_frame->plane_offset(cdm::VideoFrame::kYPlane); 689 video_frame->plane_offset(cdm::VideoFrame::kYPlane);
628 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_U] = 690 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_U] =
629 video_frame->plane_offset(cdm::VideoFrame::kUPlane); 691 video_frame->plane_offset(cdm::VideoFrame::kUPlane);
630 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] = 692 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] =
631 video_frame->plane_offset(cdm::VideoFrame::kVPlane); 693 video_frame->plane_offset(cdm::VideoFrame::kVPlane);
632 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] = 694 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] =
633 video_frame->stride(cdm::VideoFrame::kYPlane); 695 video_frame->stride(cdm::VideoFrame::kYPlane);
634 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] = 696 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] =
635 video_frame->stride(cdm::VideoFrame::kUPlane); 697 video_frame->stride(cdm::VideoFrame::kUPlane);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } // namespace webkit_media 737 } // namespace webkit_media
676 738
677 namespace pp { 739 namespace pp {
678 740
679 // Factory function for your specialization of the Module object. 741 // Factory function for your specialization of the Module object.
680 Module* CreateModule() { 742 Module* CreateModule() {
681 return new webkit_media::CdmWrapperModule(); 743 return new webkit_media::CdmWrapperModule();
682 } 744 }
683 745
684 } // namespace pp 746 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698