diff options
author | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 22:18:44 +0000 |
---|---|---|
committer | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 22:18:44 +0000 |
commit | d21da6c24dc4b9fd7528f20e7ba383ae3303dda6 (patch) | |
tree | 1eb7217126a380193f9357c906141bbeefeb16ce /webkit/media/crypto/ppapi/clear_key_cdm.cc | |
parent | f8e733a266ce4e784f10cdd6ec608dadfadb5ece (diff) | |
download | chromium_src-d21da6c24dc4b9fd7528f20e7ba383ae3303dda6.zip chromium_src-d21da6c24dc4b9fd7528f20e7ba383ae3303dda6.tar.gz chromium_src-d21da6c24dc4b9fd7528f20e7ba383ae3303dda6.tar.bz2 |
Fake video decoder in clearkey CDM.
Add a fake video decoder that outputs colorful frames without really trying to decode the compressed buffers. This is useful for testing purpose.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/11147032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162267 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/media/crypto/ppapi/clear_key_cdm.cc')
-rw-r--r-- | webkit/media/crypto/ppapi/clear_key_cdm.cc | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/webkit/media/crypto/ppapi/clear_key_cdm.cc b/webkit/media/crypto/ppapi/clear_key_cdm.cc index 4f0eaef..1fb0b62 100644 --- a/webkit/media/crypto/ppapi/clear_key_cdm.cc +++ b/webkit/media/crypto/ppapi/clear_key_cdm.cc @@ -235,8 +235,13 @@ cdm::Status ClearKeyCdm::Decrypt( cdm::Status ClearKeyCdm::InitializeVideoDecoder( const cdm::VideoDecoderConfig& video_decoder_config) { +#if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) NOTIMPLEMENTED(); return cdm::kSessionError; +#else + video_size_ = video_decoder_config.coded_size; + return cdm::kSuccess; +#endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER } void ClearKeyCdm::ResetDecoder(cdm::StreamType) { @@ -250,8 +255,75 @@ void ClearKeyCdm::DeinitializeDecoder(cdm::StreamType) { cdm::Status ClearKeyCdm::DecryptAndDecodeFrame( const cdm::InputBuffer& encrypted_buffer, cdm::VideoFrame* video_frame) { + if (!encrypted_buffer.data) { + video_frame->set_format(cdm::kEmptyVideoFrame); + return cdm::kSuccess; + } + + scoped_refptr<media::DecoderBuffer> decoder_buffer = + CopyDecoderBufferFrom(encrypted_buffer); + + // Callback is called synchronously, so we can use variables on the stack. + media::Decryptor::Status status; + scoped_refptr<media::DecoderBuffer> buffer; + decryptor_.Decrypt(decoder_buffer, + base::Bind(&CopyDecryptResults, &status, &buffer)); + + if (status == media::Decryptor::kError) + return cdm::kDecryptError; + + if (status == media::Decryptor::kNoKey) + return cdm::kNoKey; + +#if !defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) NOTIMPLEMENTED(); - return cdm::kDecryptError; + return cdm::kDecodeError; +#else + GenerateFakeVideoFrame(decoder_buffer->GetTimestamp(), video_frame); + return cdm::kSuccess; +#endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER +} + +#if defined(CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER) +void ClearKeyCdm::GenerateFakeVideoFrame(base::TimeDelta timestamp, + cdm::VideoFrame* video_frame) { + // Choose non-zero alignment and padding on purpose for testing. + const int kAlignment = 8; + const int kPadding = 16; + const int kPlanePadding = 128; + + int width = video_size_.width; + int height = video_size_.height; + DCHECK(width % 2 == 0); + DCHECK(height % 2 == 0); + + int y_stride = (width + kAlignment - 1) / kAlignment * kAlignment + kPadding; + int uv_stride = + (width / 2 + kAlignment - 1) / kAlignment * kAlignment + kPadding; + int y_rows = height; + int uv_rows = height / 2; + int y_offset = 0; + int v_offset = y_stride * y_rows + kPlanePadding; + int u_offset = v_offset + uv_stride * uv_rows + kPlanePadding; + int frame_size = u_offset + uv_stride * uv_rows + kPlanePadding; + + video_frame->set_format(cdm::kYv12); + video_frame->set_size(video_size_); + video_frame->set_frame_buffer(allocator_->Allocate(frame_size)); + video_frame->set_plane_offset(cdm::VideoFrame::kYPlane, y_offset); + video_frame->set_plane_offset(cdm::VideoFrame::kVPlane, v_offset); + video_frame->set_plane_offset(cdm::VideoFrame::kUPlane, u_offset); + video_frame->set_stride(cdm::VideoFrame::kYPlane, y_stride); + video_frame->set_stride(cdm::VideoFrame::kVPlane, uv_stride); + video_frame->set_stride(cdm::VideoFrame::kUPlane, uv_stride); + video_frame->set_timestamp(timestamp.InMicroseconds()); + + static unsigned char color = 0; + color += 10; + + memset(reinterpret_cast<void*>(video_frame->frame_buffer()->data()), + color, frame_size); } +#endif // CLEAR_KEY_CDM_USE_FAKE_VIDEO_DECODER } // namespace webkit_media |