blob: f1aa4d7f79b478add0659d133333b0df40b1eaa8 [file] [log] [blame]
Yunqing Wang15dffcf2012-10-04 12:59:36 -07001/*
Frank Galligan38536f62013-12-12 08:36:34 -08002 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3 *
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.
Yunqing Wang15dffcf2012-10-04 12:59:36 -07009 */
10
11#include <cstdio>
12#include <cstdlib>
jackychend464e8a2015-10-15 14:02:46 -070013#include <set>
Yunqing Wang15dffcf2012-10-04 12:59:36 -070014#include <string>
15#include "third_party/googletest/src/include/gtest/gtest.h"
hkuangbe6aead2015-01-27 12:26:28 -080016#include "../tools_common.h"
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -070017#include "./vpx_config.h"
John Koleszar706cafe2013-01-18 11:51:12 -080018#include "test/codec_factory.h"
Yunqing Wang15dffcf2012-10-04 12:59:36 -070019#include "test/decode_test_driver.h"
20#include "test/ivf_video_source.h"
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080021#include "test/md5_helper.h"
Frank Galligan52b2d502013-12-11 09:01:47 -080022#include "test/test_vectors.h"
23#include "test/util.h"
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -070024#if CONFIG_WEBM_IO
Frank Galligan52b2d502013-12-11 09:01:47 -080025#include "test/webm_video_source.h"
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -070026#endif
Yunqing Wang15dffcf2012-10-04 12:59:36 -070027#include "vpx_mem/vpx_mem.h"
Yunqing Wang15dffcf2012-10-04 12:59:36 -070028
Yunqing Wang15dffcf2012-10-04 12:59:36 -070029namespace {
Yunqing Wang15dffcf2012-10-04 12:59:36 -070030
hkuangbe6aead2015-01-27 12:26:28 -080031enum DecodeMode {
32 kSerialMode,
Johannba13ff82015-03-25 12:45:27 -070033 kFrameParallelMode
hkuangbe6aead2015-01-27 12:26:28 -080034};
35
36const int kDecodeMode = 0;
37const int kThreads = 1;
38const int kFileName = 2;
39
40typedef std::tr1::tuple<int, int, const char*> DecodeParam;
41
John Koleszar706cafe2013-01-18 11:51:12 -080042class TestVectorTest : public ::libvpx_test::DecoderTest,
hkuangbe6aead2015-01-27 12:26:28 -080043 public ::libvpx_test::CodecTestWithParam<DecodeParam> {
Yunqing Wang15dffcf2012-10-04 12:59:36 -070044 protected:
hkuangbe6aead2015-01-27 12:26:28 -080045 TestVectorTest()
46 : DecoderTest(GET_PARAM(0)),
47 md5_file_(NULL) {
jackychend464e8a2015-10-15 14:02:46 -070048#if CONFIG_VP9_DECODER
49 resize_clips_.insert(
50 ::libvpx_test::kVP9TestVectorsResize,
51 ::libvpx_test::kVP9TestVectorsResize +
52 ::libvpx_test::kNumVP9TestVectorsResize);
53#endif
hkuangbe6aead2015-01-27 12:26:28 -080054 }
Yunqing Wang15dffcf2012-10-04 12:59:36 -070055
56 virtual ~TestVectorTest() {
57 if (md5_file_)
58 fclose(md5_file_);
59 }
60
61 void OpenMD5File(const std::string& md5_file_name_) {
62 md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
James Zern77e64d82013-12-18 17:00:40 -080063 ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: "
Yunqing Wang15dffcf2012-10-04 12:59:36 -070064 << md5_file_name_;
65 }
66
67 virtual void DecompressedFrameHook(const vpx_image_t& img,
68 const unsigned int frame_number) {
James Zern66c7dff2013-06-25 17:55:28 -070069 ASSERT_TRUE(md5_file_ != NULL);
Yunqing Wang15dffcf2012-10-04 12:59:36 -070070 char expected_md5[33];
71 char junk[128];
72
73 // Read correct md5 checksums.
74 const int res = fscanf(md5_file_, "%s %s", expected_md5, junk);
75 ASSERT_NE(res, EOF) << "Read md5 data failed";
76 expected_md5[32] = '\0';
77
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080078 ::libvpx_test::MD5 md5_res;
79 md5_res.Add(&img);
80 const char *actual_md5 = md5_res.Get();
Yunqing Wang15dffcf2012-10-04 12:59:36 -070081
82 // Check md5 match.
83 ASSERT_STREQ(expected_md5, actual_md5)
84 << "Md5 checksums don't match: frame number = " << frame_number;
85 }
86
jackychend464e8a2015-10-15 14:02:46 -070087#if CONFIG_VP9_DECODER
88 std::set<std::string> resize_clips_;
89#endif
90
Yunqing Wang15dffcf2012-10-04 12:59:36 -070091 private:
92 FILE *md5_file_;
93};
94
95// This test runs through the whole set of test vectors, and decodes them.
96// The md5 checksums are computed for each frame in the video file. If md5
97// checksums match the correct md5 data, then the test is passed. Otherwise,
98// the test failed.
99TEST_P(TestVectorTest, MD5Match) {
hkuangbe6aead2015-01-27 12:26:28 -0800100 const DecodeParam input = GET_PARAM(1);
101 const std::string filename = std::tr1::get<kFileName>(input);
102 const int threads = std::tr1::get<kThreads>(input);
103 const int mode = std::tr1::get<kDecodeMode>(input);
John Koleszar119c9812013-06-13 12:42:05 -0700104 libvpx_test::CompressedVideoSource *video = NULL;
hkuangbe6aead2015-01-27 12:26:28 -0800105 vpx_codec_flags_t flags = 0;
James Zern153ef3d2016-02-11 18:52:45 -0800106 vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
hkuangbe6aead2015-01-27 12:26:28 -0800107 char str[256];
108
Johannba13ff82015-03-25 12:45:27 -0700109 if (mode == kFrameParallelMode) {
hkuangbe6aead2015-01-27 12:26:28 -0800110 flags |= VPX_CODEC_USE_FRAME_THREADING;
jackychend464e8a2015-10-15 14:02:46 -0700111#if CONFIG_VP9_DECODER
112 // TODO(hkuang): Fix frame parallel decode bug. See issue 1086.
113 if (resize_clips_.find(filename) != resize_clips_.end()) {
114 printf("Skipping the test file: %s, due to frame parallel decode bug.\n",
115 filename.c_str());
116 return;
117 }
118#endif
hkuangbe6aead2015-01-27 12:26:28 -0800119 }
120
121 cfg.threads = threads;
122
123 snprintf(str, sizeof(str) / sizeof(str[0]) - 1,
124 "file: %s mode: %s threads: %d",
125 filename.c_str(), mode == 0 ? "Serial" : "Parallel", threads);
126 SCOPED_TRACE(str);
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700127
John Koleszar119c9812013-06-13 12:42:05 -0700128 // Open compressed video file.
129 if (filename.substr(filename.length() - 3, 3) == "ivf") {
130 video = new libvpx_test::IVFVideoSource(filename);
131 } else if (filename.substr(filename.length() - 4, 4) == "webm") {
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -0700132#if CONFIG_WEBM_IO
John Koleszar119c9812013-06-13 12:42:05 -0700133 video = new libvpx_test::WebMVideoSource(filename);
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -0700134#else
135 fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
136 filename.c_str());
137 return;
138#endif
John Koleszar119c9812013-06-13 12:42:05 -0700139 }
140 video->Init();
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700141
142 // Construct md5 file name.
143 const std::string md5_filename = filename + ".md5";
144 OpenMD5File(md5_filename);
145
hkuangbe6aead2015-01-27 12:26:28 -0800146 // Set decode config and flags.
147 set_cfg(cfg);
148 set_flags(flags);
149
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700150 // Decode frame, and check the md5 matching.
hkuangbe6aead2015-01-27 12:26:28 -0800151 ASSERT_NO_FATAL_FAILURE(RunLoop(video, cfg));
John Koleszar119c9812013-06-13 12:42:05 -0700152 delete video;
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700153}
154
hkuangbe6aead2015-01-27 12:26:28 -0800155// Test VP8 decode in serial mode with single thread.
156// NOTE: VP8 only support serial mode.
Jingning Han463c9482015-08-06 12:02:05 -0700157#if CONFIG_VP8_DECODER
James Zern5b9dacd2015-02-13 18:48:45 -0800158VP8_INSTANTIATE_TEST_CASE(
159 TestVectorTest,
hkuangbe6aead2015-01-27 12:26:28 -0800160 ::testing::Combine(
James Zern5b9dacd2015-02-13 18:48:45 -0800161 ::testing::Values(0), // Serial Mode.
162 ::testing::Values(1), // Single thread.
163 ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
164 libvpx_test::kVP8TestVectors +
165 libvpx_test::kNumVP8TestVectors)));
Jingning Han463c9482015-08-06 12:02:05 -0700166#endif // CONFIG_VP8_DECODER
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700167
hkuangbe6aead2015-01-27 12:26:28 -0800168// Test VP9 decode in serial mode with single thread.
Jingning Han463c9482015-08-06 12:02:05 -0700169#if CONFIG_VP9_DECODER
James Zern5b9dacd2015-02-13 18:48:45 -0800170VP9_INSTANTIATE_TEST_CASE(
171 TestVectorTest,
hkuangbe6aead2015-01-27 12:26:28 -0800172 ::testing::Combine(
James Zern5b9dacd2015-02-13 18:48:45 -0800173 ::testing::Values(0), // Serial Mode.
174 ::testing::Values(1), // Single thread.
175 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
176 libvpx_test::kVP9TestVectors +
177 libvpx_test::kNumVP9TestVectors)));
hkuangbe6aead2015-01-27 12:26:28 -0800178
hkuangbe6aead2015-01-27 12:26:28 -0800179// Test VP9 decode in frame parallel mode with different number of threads.
180INSTANTIATE_TEST_CASE_P(
181 VP9MultiThreadedFrameParallel, TestVectorTest,
182 ::testing::Combine(
183 ::testing::Values(
184 static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)),
185 ::testing::Combine(
186 ::testing::Values(1), // Frame Parallel mode.
187 ::testing::Range(2, 9), // With 2 ~ 8 threads.
188 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
189 libvpx_test::kVP9TestVectors +
190 libvpx_test::kNumVP9TestVectors))));
James Zern5b9dacd2015-02-13 18:48:45 -0800191#endif
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700192} // namespace