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

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: Rebased. 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 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 // PPB_ContentDecryptor_Private interface. 397 // PPB_ContentDecryptor_Private interface.
373 virtual void GenerateKeyRequest(const std::string& key_system, 398 virtual void GenerateKeyRequest(const std::string& key_system,
374 pp::VarArrayBuffer init_data) OVERRIDE; 399 pp::VarArrayBuffer init_data) OVERRIDE;
375 virtual void AddKey(const std::string& session_id, 400 virtual void AddKey(const std::string& session_id,
376 pp::VarArrayBuffer key, 401 pp::VarArrayBuffer key,
377 pp::VarArrayBuffer init_data) OVERRIDE; 402 pp::VarArrayBuffer init_data) OVERRIDE;
378 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; 403 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE;
379 virtual void Decrypt( 404 virtual void Decrypt(
380 pp::Buffer_Dev encrypted_buffer, 405 pp::Buffer_Dev encrypted_buffer,
381 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; 406 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
407 virtual void InitializeVideoDecoder(
408 const PP_VideoDecoderConfig& decoder_config,
409 pp::Buffer_Dev extra_data_buffer) OVERRIDE;
382 virtual void DecryptAndDecodeFrame( 410 virtual void DecryptAndDecodeFrame(
383 pp::Buffer_Dev encrypted_frame, 411 pp::Buffer_Dev encrypted_frame,
384 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) OVERRIDE; 412 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) OVERRIDE;
385 413
386 // CdmHost methods. 414 // CdmHost methods.
387 virtual void SetTimer(int64 delay_ms) OVERRIDE; 415 virtual void SetTimer(int64 delay_ms) OVERRIDE;
388 virtual double GetCurrentWallTimeMs() OVERRIDE; 416 virtual double GetCurrentWallTimeMs() OVERRIDE;
389 417
390 private: 418 private:
391 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; 419 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock;
392 typedef linked_ptr<KeyMessageImpl> LinkedKeyMessage; 420 typedef linked_ptr<KeyMessageImpl> LinkedKeyMessage;
393 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; 421 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame;
394 422
395 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to 423 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to
396 // <code>callback_factory_</code> to ensure that calls into 424 // <code>callback_factory_</code> to ensure that calls into
397 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. 425 // <code>PPP_ContentDecryptor_Private</code> are asynchronous.
398 void KeyAdded(int32_t result, const std::string& session_id); 426 void KeyAdded(int32_t result, const std::string& session_id);
399 void KeyMessage(int32_t result, const LinkedKeyMessage& message); 427 void KeyMessage(int32_t result, const LinkedKeyMessage& message);
400 void KeyError(int32_t result, const std::string& session_id); 428 void KeyError(int32_t result, const std::string& session_id);
401 void DeliverBlock(int32_t result, 429 void DeliverBlock(int32_t result,
402 const cdm::Status& status, 430 const cdm::Status& status,
403 const LinkedDecryptedBlock& decrypted_block, 431 const LinkedDecryptedBlock& decrypted_block,
404 const PP_DecryptTrackingInfo& tracking_info); 432 const PP_DecryptTrackingInfo& tracking_info);
433 void DecoderInitialized(int32_t result,
434 bool success,
435 uint32_t request_id);
405 void DeliverFrame(int32_t result, 436 void DeliverFrame(int32_t result,
406 const cdm::Status& status, 437 const cdm::Status& status,
407 const LinkedVideoFrame& video_frame, 438 const LinkedVideoFrame& video_frame,
408 const PP_DecryptTrackingInfo& tracking_info); 439 const PP_DecryptTrackingInfo& tracking_info);
409 440
410 // Helper for SetTimer(). 441 // Helper for SetTimer().
411 void TimerExpired(int32 result); 442 void TimerExpired(int32 result);
412 443
413 PpbBufferAllocator allocator_; 444 PpbBufferAllocator allocator_;
414 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_; 445 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl()); 562 LinkedDecryptedBlock decrypted_block(new DecryptedBlockImpl());
532 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get()); 563 cdm::Status status = cdm_->Decrypt(input_buffer, decrypted_block.get());
533 564
534 CallOnMain(callback_factory_.NewCallback( 565 CallOnMain(callback_factory_.NewCallback(
535 &CdmWrapper::DeliverBlock, 566 &CdmWrapper::DeliverBlock,
536 status, 567 status,
537 decrypted_block, 568 decrypted_block,
538 encrypted_block_info.tracking_info)); 569 encrypted_block_info.tracking_info));
539 } 570 }
540 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);
578 cdm_decoder_config.profile =
579 PpVCProfileToCdmVCProfile(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
541 void CdmWrapper::DecryptAndDecodeFrame( 597 void CdmWrapper::DecryptAndDecodeFrame(
542 pp::Buffer_Dev encrypted_frame, 598 pp::Buffer_Dev encrypted_frame,
543 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) { 599 const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) {
544 PP_DCHECK(!encrypted_frame.is_null()); 600 PP_DCHECK(!encrypted_frame.is_null());
545 PP_DCHECK(cdm_); 601 PP_DCHECK(cdm_);
546 602
547 cdm::InputBuffer input_buffer; 603 cdm::InputBuffer input_buffer;
548 std::vector<cdm::SubsampleEntry> subsamples; 604 std::vector<cdm::SubsampleEntry> subsamples;
549 ConfigureInputBuffer(encrypted_frame, 605 ConfigureInputBuffer(encrypted_frame,
550 encrypted_video_frame_info.encryption_info, 606 encrypted_video_frame_info.encryption_info,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } 698 }
643 699
644 const pp::Buffer_Dev& buffer = 700 const pp::Buffer_Dev& buffer =
645 decrypted_block.get() && decrypted_block->buffer() ? 701 decrypted_block.get() && decrypted_block->buffer() ?
646 static_cast<PpbBuffer*>(decrypted_block->buffer())->buffer_dev() : 702 static_cast<PpbBuffer*>(decrypted_block->buffer())->buffer_dev() :
647 pp::Buffer_Dev(); 703 pp::Buffer_Dev();
648 704
649 pp::ContentDecryptor_Private::DeliverBlock(buffer, decrypted_block_info); 705 pp::ContentDecryptor_Private::DeliverBlock(buffer, decrypted_block_info);
650 } 706 }
651 707
708 void CdmWrapper::DecoderInitialized(int32_t result,
709 bool success,
710 uint32_t request_id) {
711 pp::ContentDecryptor_Private::DecoderInitialized(success, request_id);
712 }
713
652 void CdmWrapper::DeliverFrame( 714 void CdmWrapper::DeliverFrame(
653 int32_t result, 715 int32_t result,
654 const cdm::Status& status, 716 const cdm::Status& status,
655 const LinkedVideoFrame& video_frame, 717 const LinkedVideoFrame& video_frame,
656 const PP_DecryptTrackingInfo& tracking_info) { 718 const PP_DecryptTrackingInfo& tracking_info) {
657 PP_DCHECK(result == PP_OK); 719 PP_DCHECK(result == PP_OK);
658 PP_DecryptedFrameInfo decrypted_frame_info; 720 PP_DecryptedFrameInfo decrypted_frame_info;
659 decrypted_frame_info.tracking_info = tracking_info; 721 decrypted_frame_info.tracking_info = tracking_info;
660 722
661 switch (status) { 723 switch (status) {
662 case cdm::kSuccess: 724 case cdm::kSuccess:
663 PP_DCHECK(video_frame->format() == cdm::kI420 || 725 PP_DCHECK(video_frame->format() == cdm::kI420 ||
664 video_frame->format() == cdm::kYv12); 726 video_frame->format() == cdm::kYv12);
665 PP_DCHECK(video_frame.get() && video_frame->frame_buffer()); 727 PP_DCHECK(video_frame.get() && video_frame->frame_buffer());
666 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS; 728 decrypted_frame_info.result = PP_DECRYPTRESULT_SUCCESS;
667 decrypted_frame_info.format = 729 decrypted_frame_info.format =
668 VideoFormatToPpDecryptedFrameFormat(video_frame->format()); 730 CdmVideoFormatToPpDecryptedFrameFormat(video_frame->format());
669 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] = 731 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y] =
670 video_frame->plane_offset(cdm::VideoFrame::kYPlane); 732 video_frame->plane_offset(cdm::VideoFrame::kYPlane);
671 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_U] = 733 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_U] =
672 video_frame->plane_offset(cdm::VideoFrame::kUPlane); 734 video_frame->plane_offset(cdm::VideoFrame::kUPlane);
673 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] = 735 decrypted_frame_info.plane_offsets[PP_DECRYPTEDFRAMEPLANES_V] =
674 video_frame->plane_offset(cdm::VideoFrame::kVPlane); 736 video_frame->plane_offset(cdm::VideoFrame::kVPlane);
675 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] = 737 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_Y] =
676 video_frame->stride(cdm::VideoFrame::kYPlane); 738 video_frame->stride(cdm::VideoFrame::kYPlane);
677 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] = 739 decrypted_frame_info.strides[PP_DECRYPTEDFRAMEPLANES_U] =
678 video_frame->stride(cdm::VideoFrame::kUPlane); 740 video_frame->stride(cdm::VideoFrame::kUPlane);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } // namespace webkit_media 780 } // namespace webkit_media
719 781
720 namespace pp { 782 namespace pp {
721 783
722 // Factory function for your specialization of the Module object. 784 // Factory function for your specialization of the Module object.
723 Module* CreateModule() { 785 Module* CreateModule() {
724 return new webkit_media::CdmWrapperModule(); 786 return new webkit_media::CdmWrapperModule();
725 } 787 }
726 788
727 } // namespace pp 789 } // 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