1 // Copyright 2013 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.
5 #include "media/cdm/ppapi/external_clear_key/fake_cdm_video_decoder.h"
7 #include "base/logging.h"
11 FakeCdmVideoDecoder::FakeCdmVideoDecoder(cdm::Host
* host
)
12 : is_initialized_(false),
16 FakeCdmVideoDecoder::~FakeCdmVideoDecoder() {
20 bool FakeCdmVideoDecoder::Initialize(const cdm::VideoDecoderConfig
& config
) {
21 DVLOG(1) << "Initialize()";
23 video_size_
= config
.coded_size
;
24 is_initialized_
= true;
28 void FakeCdmVideoDecoder::Deinitialize() {
29 DVLOG(1) << "Deinitialize()";
30 is_initialized_
= false;
33 void FakeCdmVideoDecoder::Reset() {
34 DVLOG(1) << "Reset()";
37 // Creates a YV12 video frame.
38 cdm::Status
FakeCdmVideoDecoder::DecodeFrame(const uint8_t* compressed_frame
,
39 int32_t compressed_frame_size
,
41 cdm::VideoFrame
* decoded_frame
) {
42 DVLOG(1) << "DecodeFrame()";
44 // The fake decoder does not buffer any frames internally. So if the input is
45 // empty (EOS), just return kNeedMoreData.
47 return cdm::kNeedMoreData
;
49 // Choose non-zero alignment and padding on purpose for testing.
50 const int kAlignment
= 8;
51 const int kPadding
= 16;
52 const int kPlanePadding
= 128;
54 int width
= video_size_
.width
;
55 int height
= video_size_
.height
;
56 DCHECK_EQ(width
% 2, 0);
57 DCHECK_EQ(height
% 2, 0);
59 int y_stride
= (width
+ kAlignment
- 1) / kAlignment
* kAlignment
+ kPadding
;
61 (width
/ 2 + kAlignment
- 1) / kAlignment
* kAlignment
+ kPadding
;
63 int uv_rows
= height
/ 2;
65 int v_offset
= y_stride
* y_rows
+ kPlanePadding
;
66 int u_offset
= v_offset
+ uv_stride
* uv_rows
+ kPlanePadding
;
67 int frame_size
= u_offset
+ uv_stride
* uv_rows
+ kPlanePadding
;
69 decoded_frame
->SetFrameBuffer(host_
->Allocate(frame_size
));
70 decoded_frame
->FrameBuffer()->SetSize(frame_size
);
72 decoded_frame
->SetFormat(cdm::kYv12
);
73 decoded_frame
->SetSize(video_size_
);
74 decoded_frame
->SetPlaneOffset(cdm::VideoFrame::kYPlane
, y_offset
);
75 decoded_frame
->SetPlaneOffset(cdm::VideoFrame::kVPlane
, v_offset
);
76 decoded_frame
->SetPlaneOffset(cdm::VideoFrame::kUPlane
, u_offset
);
77 decoded_frame
->SetStride(cdm::VideoFrame::kYPlane
, y_stride
);
78 decoded_frame
->SetStride(cdm::VideoFrame::kVPlane
, uv_stride
);
79 decoded_frame
->SetStride(cdm::VideoFrame::kUPlane
, uv_stride
);
80 decoded_frame
->SetTimestamp(timestamp
);
82 static unsigned char color
= 0;
85 memset(reinterpret_cast<void*>(decoded_frame
->FrameBuffer()->Data()),