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.
15 #include "third_party/googletest/src/include/gtest/gtest.h"
16 #include "../tools_common.h"
17 #include "./vpx_config.h"
18 #include "test/codec_factory.h"
19 #include "test/decode_test_driver.h"
20 #include "test/ivf_video_source.h"
21 #include "test/md5_helper.h"
22 #include "test/test_vectors.h"
23 #include "test/util.h"
25 #include "test/webm_video_source.h"
27 #include "vpx_mem/vpx_mem.h"
31 enum DecodeMode { kSerialMode, kFrameParallelMode };
33 const int kDecodeMode = 0;
34 const int kThreads = 1;
35 const int kFileName = 2;
37 typedef std::tr1::tuple<int, int, const char *> DecodeParam;
39 class TestVectorTest : public ::libvpx_test::DecoderTest,
40 public ::libvpx_test::CodecTestWithParam<DecodeParam> {
42 TestVectorTest() : DecoderTest(GET_PARAM(0)), md5_file_(NULL) {
43 #if CONFIG_VP9_DECODER
44 resize_clips_.insert(::libvpx_test::kVP9TestVectorsResize,
45 ::libvpx_test::kVP9TestVectorsResize +
46 ::libvpx_test::kNumVP9TestVectorsResize);
50 virtual ~TestVectorTest() {
51 if (md5_file_) fclose(md5_file_);
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;
80 #if CONFIG_VP9_DECODER
81 std::set<std::string> resize_clips_;
88 // This test runs through the whole set of test vectors, and decodes them.
89 // The md5 checksums are computed for each frame in the video file. If md5
90 // checksums match the correct md5 data, then the test is passed. Otherwise,
92 TEST_P(TestVectorTest, MD5Match) {
93 const DecodeParam input = GET_PARAM(1);
94 const std::string filename = std::tr1::get<kFileName>(input);
95 const int threads = std::tr1::get<kThreads>(input);
96 const int mode = std::tr1::get<kDecodeMode>(input);
97 vpx_codec_flags_t flags = 0;
98 vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
101 if (mode == kFrameParallelMode) {
102 flags |= VPX_CODEC_USE_FRAME_THREADING;
103 #if CONFIG_VP9_DECODER
104 // TODO(hkuang): Fix frame parallel decode bug. See issue 1086.
105 if (resize_clips_.find(filename) != resize_clips_.end()) {
106 printf("Skipping the test file: %s, due to frame parallel decode bug.\n",
113 cfg.threads = threads;
115 snprintf(str, sizeof(str) / sizeof(str[0]) - 1,
116 "file: %s mode: %s threads: %d", filename.c_str(),
117 mode == 0 ? "Serial" : "Parallel", threads);
120 // Open compressed video file.
121 testing::internal::scoped_ptr<libvpx_test::CompressedVideoSource> video;
122 if (filename.substr(filename.length() - 3, 3) == "ivf") {
123 video.reset(new libvpx_test::IVFVideoSource(filename));
124 } else if (filename.substr(filename.length() - 4, 4) == "webm") {
126 video.reset(new libvpx_test::WebMVideoSource(filename));
128 fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
133 ASSERT_TRUE(video.get() != NULL);
136 // Construct md5 file name.
137 const std::string md5_filename = filename + ".md5";
138 OpenMD5File(md5_filename);
140 // Set decode config and flags.
144 // Decode frame, and check the md5 matching.
145 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get(), cfg));
148 // Test VP8 decode in serial mode with single thread.
149 // NOTE: VP8 only support serial mode.
150 #if CONFIG_VP8_DECODER
151 VP8_INSTANTIATE_TEST_CASE(
154 ::testing::Values(0), // Serial Mode.
155 ::testing::Values(1), // Single thread.
156 ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
157 libvpx_test::kVP8TestVectors +
158 libvpx_test::kNumVP8TestVectors)));
160 // Test VP8 decode in with different numbers of threads.
161 INSTANTIATE_TEST_CASE_P(
162 VP8MultiThreaded, TestVectorTest,
165 static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP8)),
167 ::testing::Values(0), // Serial Mode.
168 ::testing::Range(1, 8), // With 1 ~ 8 threads.
169 ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
170 libvpx_test::kVP8TestVectors +
171 libvpx_test::kNumVP8TestVectors))));
173 #endif // CONFIG_VP8_DECODER
175 // Test VP9 decode in serial mode with single thread.
176 #if CONFIG_VP9_DECODER
177 VP9_INSTANTIATE_TEST_CASE(
180 ::testing::Values(0), // Serial Mode.
181 ::testing::Values(1), // Single thread.
182 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
183 libvpx_test::kVP9TestVectors +
184 libvpx_test::kNumVP9TestVectors)));
186 // Test VP9 decode in frame parallel mode with different number of threads.
187 INSTANTIATE_TEST_CASE_P(
188 DISABLED_VP9MultiThreadedFrameParallel, TestVectorTest,
191 static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)),
193 ::testing::Values(1), // Frame Parallel mode.
194 ::testing::Range(2, 9), // With 2 ~ 8 threads.
195 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
196 libvpx_test::kVP9TestVectors +
197 libvpx_test::kNumVP9TestVectors))));