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.
18 #include "third_party/googletest/src/include/gtest/gtest.h"
19 #include "../tools_common.h"
20 #include "./vpx_config.h"
21 #include "test/codec_factory.h"
22 #include "test/decode_test_driver.h"
23 #include "test/ivf_video_source.h"
24 #include "test/md5_helper.h"
25 #include "test/test_vectors.h"
26 #include "test/util.h"
28 #include "test/webm_video_source.h"
30 #include "vpx_mem/vpx_mem.h"
34 const int kThreads = 0;
35 const int kMtMode = 1;
36 const int kFileName = 2;
38 typedef std::tuple<int, int, const char *> DecodeParam;
40 class TestVectorTest : public ::libvpx_test::DecoderTest,
41 public ::libvpx_test::CodecTestWithParam<DecodeParam> {
43 TestVectorTest() : DecoderTest(GET_PARAM(0)), md5_file_(nullptr) {
44 #if CONFIG_VP9_DECODER
45 resize_clips_.insert(::libvpx_test::kVP9TestVectorsResize,
46 ::libvpx_test::kVP9TestVectorsResize +
47 ::libvpx_test::kNumVP9TestVectorsResize);
51 virtual ~TestVectorTest() {
52 if (md5_file_) fclose(md5_file_);
55 void OpenMD5File(const std::string &md5_file_name_) {
56 md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
57 ASSERT_NE(md5_file_, nullptr)
58 << "Md5 file open failed. Filename: " << md5_file_name_;
61 #if CONFIG_VP9_DECODER
62 virtual void PreDecodeFrameHook(
63 const libvpx_test::CompressedVideoSource &video,
64 libvpx_test::Decoder *decoder) {
65 if (video.frame_number() == 0 && mt_mode_ >= 0) {
67 decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 1);
68 decoder->Control(VP9D_SET_ROW_MT, 0);
69 } else if (mt_mode_ == 2) {
70 decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 0);
71 decoder->Control(VP9D_SET_ROW_MT, 1);
73 decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 0);
74 decoder->Control(VP9D_SET_ROW_MT, 0);
80 virtual void DecompressedFrameHook(const vpx_image_t &img,
81 const unsigned int frame_number) {
82 ASSERT_NE(md5_file_, nullptr);
83 char expected_md5[33];
86 // Read correct md5 checksums.
87 const int res = fscanf(md5_file_, "%s %s", expected_md5, junk);
88 ASSERT_NE(res, EOF) << "Read md5 data failed";
89 expected_md5[32] = '\0';
91 ::libvpx_test::MD5 md5_res;
93 const char *actual_md5 = md5_res.Get();
96 ASSERT_STREQ(expected_md5, actual_md5)
97 << "Md5 checksums don't match: frame number = " << frame_number;
100 #if CONFIG_VP9_DECODER
101 std::set<std::string> resize_clips_;
109 // This test runs through the whole set of test vectors, and decodes them.
110 // The md5 checksums are computed for each frame in the video file. If md5
111 // checksums match the correct md5 data, then the test is passed. Otherwise,
113 TEST_P(TestVectorTest, MD5Match) {
114 const DecodeParam input = GET_PARAM(1);
115 const std::string filename = std::get<kFileName>(input);
116 vpx_codec_flags_t flags = 0;
117 vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
120 cfg.threads = std::get<kThreads>(input);
121 mt_mode_ = std::get<kMtMode>(input);
122 snprintf(str, sizeof(str) / sizeof(str[0]) - 1,
123 "file: %s threads: %d MT mode: %d", filename.c_str(), cfg.threads,
127 // Open compressed video file.
128 std::unique_ptr<libvpx_test::CompressedVideoSource> video;
129 if (filename.substr(filename.length() - 3, 3) == "ivf") {
130 video.reset(new libvpx_test::IVFVideoSource(filename));
131 } else if (filename.substr(filename.length() - 4, 4) == "webm") {
133 video.reset(new libvpx_test::WebMVideoSource(filename));
135 fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
140 ASSERT_NE(video.get(), nullptr);
143 // Construct md5 file name.
144 const std::string md5_filename = filename + ".md5";
145 OpenMD5File(md5_filename);
147 // Set decode config and flags.
151 // Decode frame, and check the md5 matching.
152 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get(), cfg));
155 #if CONFIG_VP8_DECODER
156 VP8_INSTANTIATE_TEST_SUITE(
159 ::testing::Values(1), // Single thread.
160 ::testing::Values(-1), // LPF opt and Row MT is not applicable
161 ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
162 libvpx_test::kVP8TestVectors +
163 libvpx_test::kNumVP8TestVectors)));
165 // Test VP8 decode in with different numbers of threads.
166 INSTANTIATE_TEST_SUITE_P(
167 VP8MultiThreaded, TestVectorTest,
170 static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP8)),
172 ::testing::Range(2, 9), // With 2 ~ 8 threads.
173 ::testing::Values(-1), // LPF opt and Row MT is not applicable
174 ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
175 libvpx_test::kVP8TestVectors +
176 libvpx_test::kNumVP8TestVectors))));
178 #endif // CONFIG_VP8_DECODER
180 #if CONFIG_VP9_DECODER
181 VP9_INSTANTIATE_TEST_SUITE(
184 ::testing::Values(1), // Single thread.
185 ::testing::Values(-1), // LPF opt and Row MT is not applicable
186 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
187 libvpx_test::kVP9TestVectors +
188 libvpx_test::kNumVP9TestVectors)));
190 INSTANTIATE_TEST_SUITE_P(
191 VP9MultiThreaded, TestVectorTest,
194 static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)),
196 ::testing::Range(2, 9), // With 2 ~ 8 threads.
197 ::testing::Range(0, 3), // With multi threads modes 0 ~ 2
198 // 0: LPF opt and Row MT disabled
199 // 1: LPF opt enabled
201 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
202 libvpx_test::kVP9TestVectors +
203 libvpx_test::kNumVP9TestVectors))));