OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/media/crypto/ppapi/fake_cdm_video_decoder.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "webkit/media/crypto/ppapi/content_decryption_module.h" |
| 9 |
| 10 namespace webkit_media { |
| 11 |
| 12 FakeCdmVideoDecoder::FakeCdmVideoDecoder(cdm::Allocator* allocator) |
| 13 : is_initialized_(false), |
| 14 allocator_(allocator) { |
| 15 } |
| 16 |
| 17 FakeCdmVideoDecoder::~FakeCdmVideoDecoder() { |
| 18 Deinitialize(); |
| 19 } |
| 20 |
| 21 bool FakeCdmVideoDecoder::Initialize(const cdm::VideoDecoderConfig& config) { |
| 22 DVLOG(1) << "Initialize()"; |
| 23 |
| 24 video_size_ = config.coded_size; |
| 25 is_initialized_ = true; |
| 26 return true; |
| 27 } |
| 28 |
| 29 void FakeCdmVideoDecoder::Deinitialize() { |
| 30 DVLOG(1) << "Deinitialize()"; |
| 31 is_initialized_ = false; |
| 32 } |
| 33 |
| 34 void FakeCdmVideoDecoder::Reset() { |
| 35 DVLOG(1) << "Reset()"; |
| 36 } |
| 37 |
| 38 // Creates a YV12 video frame. |
| 39 cdm::Status FakeCdmVideoDecoder::DecodeFrame(const uint8_t* compressed_frame, |
| 40 int32_t compressed_frame_size, |
| 41 int64_t timestamp, |
| 42 cdm::VideoFrame* decoded_frame) { |
| 43 DVLOG(1) << "DecodeFrame()"; |
| 44 |
| 45 // The fake decoder does not buffer any frames internally. So if the input is |
| 46 // empty (EOS), just return kNeedMoreData. |
| 47 if (!decoded_frame) |
| 48 return cdm::kNeedMoreData; |
| 49 |
| 50 // Choose non-zero alignment and padding on purpose for testing. |
| 51 const int kAlignment = 8; |
| 52 const int kPadding = 16; |
| 53 const int kPlanePadding = 128; |
| 54 |
| 55 int width = video_size_.width; |
| 56 int height = video_size_.height; |
| 57 DCHECK_EQ(width % 2, 0); |
| 58 DCHECK_EQ(height % 2, 0); |
| 59 |
| 60 int y_stride = (width + kAlignment - 1) / kAlignment * kAlignment + kPadding; |
| 61 int uv_stride = |
| 62 (width / 2 + kAlignment - 1) / kAlignment * kAlignment + kPadding; |
| 63 int y_rows = height; |
| 64 int uv_rows = height / 2; |
| 65 int y_offset = 0; |
| 66 int v_offset = y_stride * y_rows + kPlanePadding; |
| 67 int u_offset = v_offset + uv_stride * uv_rows + kPlanePadding; |
| 68 int frame_size = u_offset + uv_stride * uv_rows + kPlanePadding; |
| 69 |
| 70 decoded_frame->set_format(cdm::kYv12); |
| 71 decoded_frame->set_size(video_size_); |
| 72 decoded_frame->set_frame_buffer(allocator_->Allocate(frame_size)); |
| 73 decoded_frame->set_plane_offset(cdm::VideoFrame::kYPlane, y_offset); |
| 74 decoded_frame->set_plane_offset(cdm::VideoFrame::kVPlane, v_offset); |
| 75 decoded_frame->set_plane_offset(cdm::VideoFrame::kUPlane, u_offset); |
| 76 decoded_frame->set_stride(cdm::VideoFrame::kYPlane, y_stride); |
| 77 decoded_frame->set_stride(cdm::VideoFrame::kVPlane, uv_stride); |
| 78 decoded_frame->set_stride(cdm::VideoFrame::kUPlane, uv_stride); |
| 79 decoded_frame->set_timestamp(timestamp); |
| 80 |
| 81 static unsigned char color = 0; |
| 82 color += 10; |
| 83 |
| 84 memset(reinterpret_cast<void*>(decoded_frame->frame_buffer()->data()), |
| 85 color, frame_size); |
| 86 |
| 87 return cdm::kSuccess; |
| 88 } |
| 89 |
| 90 } // namespace webkit_media |
OLD | NEW |