Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 1 | /* |
Frank Galligan | 38536f6 | 2013-12-12 08:36:34 -0800 | [diff] [blame] | 2 | * 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 Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <cstdio> |
| 12 | #include <cstdlib> |
jackychen | d464e8a | 2015-10-15 14:02:46 -0700 | [diff] [blame] | 13 | #include <set> |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 14 | #include <string> |
| 15 | #include "third_party/googletest/src/include/gtest/gtest.h" |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 16 | #include "../tools_common.h" |
Vignesh Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 17 | #include "./vpx_config.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 18 | #include "test/codec_factory.h" |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 19 | #include "test/decode_test_driver.h" |
| 20 | #include "test/ivf_video_source.h" |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 21 | #include "test/md5_helper.h" |
Frank Galligan | 52b2d50 | 2013-12-11 09:01:47 -0800 | [diff] [blame] | 22 | #include "test/test_vectors.h" |
| 23 | #include "test/util.h" |
Vignesh Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 24 | #if CONFIG_WEBM_IO |
Frank Galligan | 52b2d50 | 2013-12-11 09:01:47 -0800 | [diff] [blame] | 25 | #include "test/webm_video_source.h" |
Vignesh Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 26 | #endif |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 27 | #include "vpx_mem/vpx_mem.h" |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 28 | |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 29 | namespace { |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 30 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 31 | enum DecodeMode { |
| 32 | kSerialMode, |
Johann | ba13ff8 | 2015-03-25 12:45:27 -0700 | [diff] [blame] | 33 | kFrameParallelMode |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | const int kDecodeMode = 0; |
| 37 | const int kThreads = 1; |
| 38 | const int kFileName = 2; |
| 39 | |
| 40 | typedef std::tr1::tuple<int, int, const char*> DecodeParam; |
| 41 | |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 42 | class TestVectorTest : public ::libvpx_test::DecoderTest, |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 43 | public ::libvpx_test::CodecTestWithParam<DecodeParam> { |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 44 | protected: |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 45 | TestVectorTest() |
| 46 | : DecoderTest(GET_PARAM(0)), |
| 47 | md5_file_(NULL) { |
jackychen | d464e8a | 2015-10-15 14:02:46 -0700 | [diff] [blame] | 48 | #if CONFIG_VP9_DECODER |
| 49 | resize_clips_.insert( |
| 50 | ::libvpx_test::kVP9TestVectorsResize, |
| 51 | ::libvpx_test::kVP9TestVectorsResize + |
| 52 | ::libvpx_test::kNumVP9TestVectorsResize); |
| 53 | #endif |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 54 | } |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 55 | |
| 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 Zern | 77e64d8 | 2013-12-18 17:00:40 -0800 | [diff] [blame] | 63 | ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: " |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 64 | << md5_file_name_; |
| 65 | } |
| 66 | |
| 67 | virtual void DecompressedFrameHook(const vpx_image_t& img, |
| 68 | const unsigned int frame_number) { |
James Zern | 66c7dff | 2013-06-25 17:55:28 -0700 | [diff] [blame] | 69 | ASSERT_TRUE(md5_file_ != NULL); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 70 | 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. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 78 | ::libvpx_test::MD5 md5_res; |
| 79 | md5_res.Add(&img); |
| 80 | const char *actual_md5 = md5_res.Get(); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 81 | |
| 82 | // Check md5 match. |
| 83 | ASSERT_STREQ(expected_md5, actual_md5) |
| 84 | << "Md5 checksums don't match: frame number = " << frame_number; |
| 85 | } |
| 86 | |
jackychen | d464e8a | 2015-10-15 14:02:46 -0700 | [diff] [blame] | 87 | #if CONFIG_VP9_DECODER |
| 88 | std::set<std::string> resize_clips_; |
| 89 | #endif |
| 90 | |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 91 | 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. |
| 99 | TEST_P(TestVectorTest, MD5Match) { |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 100 | 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 Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 104 | libvpx_test::CompressedVideoSource *video = NULL; |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 105 | vpx_codec_flags_t flags = 0; |
James Zern | 153ef3d | 2016-02-11 18:52:45 -0800 | [diff] [blame] | 106 | vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t(); |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 107 | char str[256]; |
| 108 | |
Johann | ba13ff8 | 2015-03-25 12:45:27 -0700 | [diff] [blame] | 109 | if (mode == kFrameParallelMode) { |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 110 | flags |= VPX_CODEC_USE_FRAME_THREADING; |
jackychen | d464e8a | 2015-10-15 14:02:46 -0700 | [diff] [blame] | 111 | #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 |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 119 | } |
| 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 Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 127 | |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 128 | // 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 Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 132 | #if CONFIG_WEBM_IO |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 133 | video = new libvpx_test::WebMVideoSource(filename); |
Vignesh Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 134 | #else |
| 135 | fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n", |
| 136 | filename.c_str()); |
| 137 | return; |
| 138 | #endif |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 139 | } |
| 140 | video->Init(); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 141 | |
| 142 | // Construct md5 file name. |
| 143 | const std::string md5_filename = filename + ".md5"; |
| 144 | OpenMD5File(md5_filename); |
| 145 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 146 | // Set decode config and flags. |
| 147 | set_cfg(cfg); |
| 148 | set_flags(flags); |
| 149 | |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 150 | // Decode frame, and check the md5 matching. |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 151 | ASSERT_NO_FATAL_FAILURE(RunLoop(video, cfg)); |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 152 | delete video; |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 155 | // Test VP8 decode in serial mode with single thread. |
| 156 | // NOTE: VP8 only support serial mode. |
Jingning Han | 463c948 | 2015-08-06 12:02:05 -0700 | [diff] [blame] | 157 | #if CONFIG_VP8_DECODER |
James Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 158 | VP8_INSTANTIATE_TEST_CASE( |
| 159 | TestVectorTest, |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 160 | ::testing::Combine( |
James Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 161 | ::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 Han | 463c948 | 2015-08-06 12:02:05 -0700 | [diff] [blame] | 166 | #endif // CONFIG_VP8_DECODER |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 167 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 168 | // Test VP9 decode in serial mode with single thread. |
Jingning Han | 463c948 | 2015-08-06 12:02:05 -0700 | [diff] [blame] | 169 | #if CONFIG_VP9_DECODER |
James Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 170 | VP9_INSTANTIATE_TEST_CASE( |
| 171 | TestVectorTest, |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 172 | ::testing::Combine( |
James Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 173 | ::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))); |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 178 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 179 | // Test VP9 decode in frame parallel mode with different number of threads. |
| 180 | INSTANTIATE_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 Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 191 | #endif |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 192 | } // namespace |