2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
13 #include "./vpx_config.h"
14 #include "test/codec_factory.h"
15 #include "test/decode_test_driver.h"
16 #include "test/md5_helper.h"
17 #include "test/util.h"
19 #include "test/webm_video_source.h"
26 const int kLegacyByteAlignment
= 0;
27 const int kLegacyYPlaneByteAlignment
= 32;
28 const int kNumPlanesToCheck
= 3;
29 const char kVP9TestFile
[] = "vp90-2-02-size-lf-1920x1080.webm";
30 const char kVP9Md5File
[] = "vp90-2-02-size-lf-1920x1080.webm.md5";
32 struct ByteAlignmentTestParam
{
34 vpx_codec_err_t expected_value
;
35 bool decode_remaining
;
38 const ByteAlignmentTestParam kBaTestParams
[] = {
39 {kLegacyByteAlignment
, VPX_CODEC_OK
, true},
40 {32, VPX_CODEC_OK
, true},
41 {64, VPX_CODEC_OK
, true},
42 {128, VPX_CODEC_OK
, true},
43 {256, VPX_CODEC_OK
, true},
44 {512, VPX_CODEC_OK
, true},
45 {1024, VPX_CODEC_OK
, true},
46 {1, VPX_CODEC_INVALID_PARAM
, false},
47 {-2, VPX_CODEC_INVALID_PARAM
, false},
48 {4, VPX_CODEC_INVALID_PARAM
, false},
49 {16, VPX_CODEC_INVALID_PARAM
, false},
50 {255, VPX_CODEC_INVALID_PARAM
, false},
51 {2048, VPX_CODEC_INVALID_PARAM
, false},
54 // Class for testing byte alignment of reference buffers.
55 class ByteAlignmentTest
56 : public ::testing::TestWithParam
<ByteAlignmentTestParam
> {
63 virtual void SetUp() {
64 video_
= new libvpx_test::WebMVideoSource(kVP9TestFile
);
65 ASSERT_TRUE(video_
!= NULL
);
69 const vpx_codec_dec_cfg_t cfg
= vpx_codec_dec_cfg_t();
70 decoder_
= new libvpx_test::VP9Decoder(cfg
, 0);
71 ASSERT_TRUE(decoder_
!= NULL
);
73 OpenMd5File(kVP9Md5File
);
76 virtual void TearDown() {
77 if (md5_file_
!= NULL
)
84 void SetByteAlignment(int byte_alignment
, vpx_codec_err_t expected_value
) {
85 decoder_
->Control(VP9_SET_BYTE_ALIGNMENT
, byte_alignment
, expected_value
);
88 vpx_codec_err_t
DecodeOneFrame(int byte_alignment_to_check
) {
89 const vpx_codec_err_t res
=
90 decoder_
->DecodeFrame(video_
->cxdata(), video_
->frame_size());
91 CheckDecodedFrames(byte_alignment_to_check
);
92 if (res
== VPX_CODEC_OK
)
97 vpx_codec_err_t
DecodeRemainingFrames(int byte_alignment_to_check
) {
98 for (; video_
->cxdata() != NULL
; video_
->Next()) {
99 const vpx_codec_err_t res
=
100 decoder_
->DecodeFrame(video_
->cxdata(), video_
->frame_size());
101 if (res
!= VPX_CODEC_OK
)
103 CheckDecodedFrames(byte_alignment_to_check
);
109 // Check if |data| is aligned to |byte_alignment_to_check|.
110 // |byte_alignment_to_check| must be a power of 2.
111 void CheckByteAlignment(const uint8_t *data
, int byte_alignment_to_check
) {
112 ASSERT_EQ(0u, reinterpret_cast<size_t>(data
) % byte_alignment_to_check
);
115 // Iterate through the planes of the decoded frames and check for
116 // alignment based off |byte_alignment_to_check|.
117 void CheckDecodedFrames(int byte_alignment_to_check
) {
118 libvpx_test::DxDataIterator dec_iter
= decoder_
->GetDxData();
119 const vpx_image_t
*img
;
121 // Get decompressed data
122 while ((img
= dec_iter
.Next()) != NULL
) {
123 if (byte_alignment_to_check
== kLegacyByteAlignment
) {
124 CheckByteAlignment(img
->planes
[0], kLegacyYPlaneByteAlignment
);
126 for (int i
= 0; i
< kNumPlanesToCheck
; ++i
) {
127 CheckByteAlignment(img
->planes
[i
], byte_alignment_to_check
);
134 // TODO(fgalligan): Move the MD5 testing code into another class.
135 void OpenMd5File(const std::string
&md5_file_name_
) {
136 md5_file_
= libvpx_test::OpenTestDataFile(md5_file_name_
);
137 ASSERT_TRUE(md5_file_
!= NULL
) << "MD5 file open failed. Filename: "
141 void CheckMd5(const vpx_image_t
&img
) {
142 ASSERT_TRUE(md5_file_
!= NULL
);
143 char expected_md5
[33];
146 // Read correct md5 checksums.
147 const int res
= fscanf(md5_file_
, "%s %s", expected_md5
, junk
);
148 ASSERT_NE(EOF
, res
) << "Read md5 data failed";
149 expected_md5
[32] = '\0';
151 ::libvpx_test::MD5 md5_res
;
153 const char *const actual_md5
= md5_res
.Get();
156 ASSERT_STREQ(expected_md5
, actual_md5
) << "MD5 checksums don't match";
159 libvpx_test::WebMVideoSource
*video_
;
160 libvpx_test::VP9Decoder
*decoder_
;
164 TEST_F(ByteAlignmentTest
, SwitchByteAlignment
) {
165 const int num_elements
= 14;
166 const int byte_alignments
[] = { 0, 32, 64, 128, 256, 512, 1024,
167 0, 1024, 32, 512, 64, 256, 128 };
169 for (int i
= 0; i
< num_elements
; ++i
) {
170 SetByteAlignment(byte_alignments
[i
], VPX_CODEC_OK
);
171 ASSERT_EQ(VPX_CODEC_OK
, DecodeOneFrame(byte_alignments
[i
]));
173 SetByteAlignment(byte_alignments
[0], VPX_CODEC_OK
);
174 ASSERT_EQ(VPX_CODEC_OK
, DecodeRemainingFrames(byte_alignments
[0]));
177 TEST_P(ByteAlignmentTest
, TestAlignment
) {
178 const ByteAlignmentTestParam t
= GetParam();
179 SetByteAlignment(t
.byte_alignment
, t
.expected_value
);
180 if (t
.decode_remaining
)
181 ASSERT_EQ(VPX_CODEC_OK
, DecodeRemainingFrames(t
.byte_alignment
));
184 INSTANTIATE_TEST_CASE_P(Alignments
, ByteAlignmentTest
,
185 ::testing::ValuesIn(kBaTestParams
));
187 #endif // CONFIG_WEBM_IO