2 * Copyright (c) 2013 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.
14 #include "third_party/googletest/src/include/gtest/gtest.h"
15 #include "../tools_common.h"
16 #include "./vpx_config.h"
17 #include "test/codec_factory.h"
18 #include "test/decode_test_driver.h"
19 #include "test/ivf_video_source.h"
20 #include "test/md5_helper.h"
21 #include "test/test_vectors.h"
22 #include "test/util.h"
24 #include "test/webm_video_source.h"
26 #include "vpx_mem/vpx_mem.h"
35 const int kDecodeMode = 0;
36 const int kThreads = 1;
37 const int kFileName = 2;
39 typedef std::tr1::tuple<int, int, const char*> DecodeParam;
41 class TestVectorTest : public ::libvpx_test::DecoderTest,
42 public ::libvpx_test::CodecTestWithParam<DecodeParam> {
45 : DecoderTest(GET_PARAM(0)),
49 virtual ~TestVectorTest() {
54 void OpenMD5File(const std::string& md5_file_name_) {
55 md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
56 ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: "
60 virtual void DecompressedFrameHook(const vpx_image_t& img,
61 const unsigned int frame_number) {
62 ASSERT_TRUE(md5_file_ != NULL);
63 char expected_md5[33];
66 // Read correct md5 checksums.
67 const int res = fscanf(md5_file_, "%s %s", expected_md5, junk);
68 ASSERT_NE(res, EOF) << "Read md5 data failed";
69 expected_md5[32] = '\0';
71 ::libvpx_test::MD5 md5_res;
73 const char *actual_md5 = md5_res.Get();
76 ASSERT_STREQ(expected_md5, actual_md5)
77 << "Md5 checksums don't match: frame number = " << frame_number;
84 // This test runs through the whole set of test vectors, and decodes them.
85 // The md5 checksums are computed for each frame in the video file. If md5
86 // checksums match the correct md5 data, then the test is passed. Otherwise,
88 TEST_P(TestVectorTest, MD5Match) {
89 const DecodeParam input = GET_PARAM(1);
90 const std::string filename = std::tr1::get<kFileName>(input);
91 const int threads = std::tr1::get<kThreads>(input);
92 const int mode = std::tr1::get<kDecodeMode>(input);
93 libvpx_test::CompressedVideoSource *video = NULL;
94 vpx_codec_flags_t flags = 0;
95 vpx_codec_dec_cfg_t cfg = {0};
98 if (mode == kFrameParallelMode) {
99 flags |= VPX_CODEC_USE_FRAME_THREADING;
102 cfg.threads = threads;
104 snprintf(str, sizeof(str) / sizeof(str[0]) - 1,
105 "file: %s mode: %s threads: %d",
106 filename.c_str(), mode == 0 ? "Serial" : "Parallel", threads);
109 // Open compressed video file.
110 if (filename.substr(filename.length() - 3, 3) == "ivf") {
111 video = new libvpx_test::IVFVideoSource(filename);
112 } else if (filename.substr(filename.length() - 4, 4) == "webm") {
114 video = new libvpx_test::WebMVideoSource(filename);
116 fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
123 // Construct md5 file name.
124 const std::string md5_filename = filename + ".md5";
125 OpenMD5File(md5_filename);
127 // Set decode config and flags.
131 // Decode frame, and check the md5 matching.
132 ASSERT_NO_FATAL_FAILURE(RunLoop(video, cfg));
136 // Test VP8 decode in serial mode with single thread.
137 // NOTE: VP8 only support serial mode.
138 #if CONFIG_VP8_DECODER
139 VP8_INSTANTIATE_TEST_CASE(
142 ::testing::Values(0), // Serial Mode.
143 ::testing::Values(1), // Single thread.
144 ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
145 libvpx_test::kVP8TestVectors +
146 libvpx_test::kNumVP8TestVectors)));
147 #endif // CONFIG_VP8_DECODER
149 // Test VP9 decode in serial mode with single thread.
150 #if CONFIG_VP9_DECODER
151 VP9_INSTANTIATE_TEST_CASE(
154 ::testing::Values(0), // Serial Mode.
155 ::testing::Values(1), // Single thread.
156 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
157 libvpx_test::kVP9TestVectors +
158 libvpx_test::kNumVP9TestVectors)));
160 // Test VP9 decode in frame parallel mode with different number of threads.
161 INSTANTIATE_TEST_CASE_P(
162 VP9MultiThreadedFrameParallel, TestVectorTest,
165 static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)),
167 ::testing::Values(1), // Frame Parallel mode.
168 ::testing::Range(2, 9), // With 2 ~ 8 threads.
169 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
170 libvpx_test::kVP9TestVectors +
171 libvpx_test::kNumVP9TestVectors))));