blob: 5847074b9a37edf8f104c5ed943f6b4533796c3e [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>
13#include <string>
14#include "third_party/googletest/src/include/gtest/gtest.h"
hkuangbe6aead2015-01-27 12:26:28 -080015#include "../tools_common.h"
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -070016#include "./vpx_config.h"
John Koleszar706cafe2013-01-18 11:51:12 -080017#include "test/codec_factory.h"
Yunqing Wang15dffcf2012-10-04 12:59:36 -070018#include "test/decode_test_driver.h"
19#include "test/ivf_video_source.h"
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080020#include "test/md5_helper.h"
Frank Galligan52b2d502013-12-11 09:01:47 -080021#include "test/test_vectors.h"
22#include "test/util.h"
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -070023#if CONFIG_WEBM_IO
Frank Galligan52b2d502013-12-11 09:01:47 -080024#include "test/webm_video_source.h"
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -070025#endif
Yunqing Wang15dffcf2012-10-04 12:59:36 -070026#include "vpx_mem/vpx_mem.h"
Yunqing Wang15dffcf2012-10-04 12:59:36 -070027
Yunqing Wang15dffcf2012-10-04 12:59:36 -070028namespace {
Yunqing Wang15dffcf2012-10-04 12:59:36 -070029
hkuangbe6aead2015-01-27 12:26:28 -080030enum DecodeMode {
31 kSerialMode,
Johannba13ff82015-03-25 12:45:27 -070032 kFrameParallelMode
hkuangbe6aead2015-01-27 12:26:28 -080033};
34
35const int kDecodeMode = 0;
36const int kThreads = 1;
37const int kFileName = 2;
38
39typedef std::tr1::tuple<int, int, const char*> DecodeParam;
40
John Koleszar706cafe2013-01-18 11:51:12 -080041class TestVectorTest : public ::libvpx_test::DecoderTest,
hkuangbe6aead2015-01-27 12:26:28 -080042 public ::libvpx_test::CodecTestWithParam<DecodeParam> {
Yunqing Wang15dffcf2012-10-04 12:59:36 -070043 protected:
hkuangbe6aead2015-01-27 12:26:28 -080044 TestVectorTest()
45 : DecoderTest(GET_PARAM(0)),
46 md5_file_(NULL) {
47 }
Yunqing Wang15dffcf2012-10-04 12:59:36 -070048
49 virtual ~TestVectorTest() {
50 if (md5_file_)
51 fclose(md5_file_);
52 }
53
54 void OpenMD5File(const std::string& md5_file_name_) {
55 md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
James Zern77e64d82013-12-18 17:00:40 -080056 ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: "
Yunqing Wang15dffcf2012-10-04 12:59:36 -070057 << md5_file_name_;
58 }
59
60 virtual void DecompressedFrameHook(const vpx_image_t& img,
61 const unsigned int frame_number) {
James Zern66c7dff2013-06-25 17:55:28 -070062 ASSERT_TRUE(md5_file_ != NULL);
Yunqing Wang15dffcf2012-10-04 12:59:36 -070063 char expected_md5[33];
64 char junk[128];
65
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';
70
Ronald S. Bultje1407bdc2013-02-01 09:35:28 -080071 ::libvpx_test::MD5 md5_res;
72 md5_res.Add(&img);
73 const char *actual_md5 = md5_res.Get();
Yunqing Wang15dffcf2012-10-04 12:59:36 -070074
75 // Check md5 match.
76 ASSERT_STREQ(expected_md5, actual_md5)
77 << "Md5 checksums don't match: frame number = " << frame_number;
78 }
79
80 private:
81 FILE *md5_file_;
82};
83
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,
87// the test failed.
88TEST_P(TestVectorTest, MD5Match) {
hkuangbe6aead2015-01-27 12:26:28 -080089 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);
John Koleszar119c9812013-06-13 12:42:05 -070093 libvpx_test::CompressedVideoSource *video = NULL;
hkuangbe6aead2015-01-27 12:26:28 -080094 vpx_codec_flags_t flags = 0;
95 vpx_codec_dec_cfg_t cfg = {0};
96 char str[256];
97
Johannba13ff82015-03-25 12:45:27 -070098 if (mode == kFrameParallelMode) {
hkuangbe6aead2015-01-27 12:26:28 -080099 flags |= VPX_CODEC_USE_FRAME_THREADING;
100 }
101
102 cfg.threads = threads;
103
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);
107 SCOPED_TRACE(str);
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700108
John Koleszar119c9812013-06-13 12:42:05 -0700109 // 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") {
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -0700113#if CONFIG_WEBM_IO
John Koleszar119c9812013-06-13 12:42:05 -0700114 video = new libvpx_test::WebMVideoSource(filename);
Vignesh Venkatasubramanian68ff3682014-04-18 11:24:02 -0700115#else
116 fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
117 filename.c_str());
118 return;
119#endif
John Koleszar119c9812013-06-13 12:42:05 -0700120 }
121 video->Init();
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700122
123 // Construct md5 file name.
124 const std::string md5_filename = filename + ".md5";
125 OpenMD5File(md5_filename);
126
hkuangbe6aead2015-01-27 12:26:28 -0800127 // Set decode config and flags.
128 set_cfg(cfg);
129 set_flags(flags);
130
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700131 // Decode frame, and check the md5 matching.
hkuangbe6aead2015-01-27 12:26:28 -0800132 ASSERT_NO_FATAL_FAILURE(RunLoop(video, cfg));
John Koleszar119c9812013-06-13 12:42:05 -0700133 delete video;
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700134}
135
hkuangbe6aead2015-01-27 12:26:28 -0800136// Test VP8 decode in serial mode with single thread.
137// NOTE: VP8 only support serial mode.
James Zern5b9dacd2015-02-13 18:48:45 -0800138VP8_INSTANTIATE_TEST_CASE(
139 TestVectorTest,
hkuangbe6aead2015-01-27 12:26:28 -0800140 ::testing::Combine(
James Zern5b9dacd2015-02-13 18:48:45 -0800141 ::testing::Values(0), // Serial Mode.
142 ::testing::Values(1), // Single thread.
143 ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
144 libvpx_test::kVP8TestVectors +
145 libvpx_test::kNumVP8TestVectors)));
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700146
hkuangbe6aead2015-01-27 12:26:28 -0800147// Test VP9 decode in serial mode with single thread.
James Zern5b9dacd2015-02-13 18:48:45 -0800148VP9_INSTANTIATE_TEST_CASE(
149 TestVectorTest,
hkuangbe6aead2015-01-27 12:26:28 -0800150 ::testing::Combine(
James Zern5b9dacd2015-02-13 18:48:45 -0800151 ::testing::Values(0), // Serial Mode.
152 ::testing::Values(1), // Single thread.
153 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
154 libvpx_test::kVP9TestVectors +
155 libvpx_test::kNumVP9TestVectors)));
hkuangbe6aead2015-01-27 12:26:28 -0800156
157
James Zern5b9dacd2015-02-13 18:48:45 -0800158#if CONFIG_VP9_DECODER
hkuangbe6aead2015-01-27 12:26:28 -0800159// Test VP9 decode in frame parallel mode with different number of threads.
160INSTANTIATE_TEST_CASE_P(
161 VP9MultiThreadedFrameParallel, TestVectorTest,
162 ::testing::Combine(
163 ::testing::Values(
164 static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)),
165 ::testing::Combine(
166 ::testing::Values(1), // Frame Parallel mode.
167 ::testing::Range(2, 9), // With 2 ~ 8 threads.
168 ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
169 libvpx_test::kVP9TestVectors +
170 libvpx_test::kNumVP9TestVectors))));
James Zern5b9dacd2015-02-13 18:48:45 -0800171#endif
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700172} // namespace