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> |
| 13 | #include <string> |
| 14 | #include "third_party/googletest/src/include/gtest/gtest.h" |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 15 | #include "../tools_common.h" |
Vignesh Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 16 | #include "./vpx_config.h" |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 17 | #include "test/codec_factory.h" |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 18 | #include "test/decode_test_driver.h" |
| 19 | #include "test/ivf_video_source.h" |
Ronald S. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 20 | #include "test/md5_helper.h" |
Frank Galligan | 52b2d50 | 2013-12-11 09:01:47 -0800 | [diff] [blame] | 21 | #include "test/test_vectors.h" |
| 22 | #include "test/util.h" |
Vignesh Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 23 | #if CONFIG_WEBM_IO |
Frank Galligan | 52b2d50 | 2013-12-11 09:01:47 -0800 | [diff] [blame] | 24 | #include "test/webm_video_source.h" |
Vignesh Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 25 | #endif |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 26 | #include "vpx_mem/vpx_mem.h" |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 27 | |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 28 | namespace { |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 29 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 30 | enum DecodeMode { |
| 31 | kSerialMode, |
Johann | ba13ff8 | 2015-03-25 12:45:27 -0700 | [diff] [blame] | 32 | kFrameParallelMode |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | const int kDecodeMode = 0; |
| 36 | const int kThreads = 1; |
| 37 | const int kFileName = 2; |
| 38 | |
| 39 | typedef std::tr1::tuple<int, int, const char*> DecodeParam; |
| 40 | |
John Koleszar | 706cafe | 2013-01-18 11:51:12 -0800 | [diff] [blame] | 41 | class TestVectorTest : public ::libvpx_test::DecoderTest, |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 42 | public ::libvpx_test::CodecTestWithParam<DecodeParam> { |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 43 | protected: |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 44 | TestVectorTest() |
| 45 | : DecoderTest(GET_PARAM(0)), |
| 46 | md5_file_(NULL) { |
| 47 | } |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 48 | |
| 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 Zern | 77e64d8 | 2013-12-18 17:00:40 -0800 | [diff] [blame] | 56 | ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: " |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 57 | << md5_file_name_; |
| 58 | } |
| 59 | |
| 60 | virtual void DecompressedFrameHook(const vpx_image_t& img, |
| 61 | const unsigned int frame_number) { |
James Zern | 66c7dff | 2013-06-25 17:55:28 -0700 | [diff] [blame] | 62 | ASSERT_TRUE(md5_file_ != NULL); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 63 | 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. Bultje | 1407bdc | 2013-02-01 09:35:28 -0800 | [diff] [blame] | 71 | ::libvpx_test::MD5 md5_res; |
| 72 | md5_res.Add(&img); |
| 73 | const char *actual_md5 = md5_res.Get(); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 74 | |
| 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. |
| 88 | TEST_P(TestVectorTest, MD5Match) { |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 89 | 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 Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 93 | libvpx_test::CompressedVideoSource *video = NULL; |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 94 | vpx_codec_flags_t flags = 0; |
| 95 | vpx_codec_dec_cfg_t cfg = {0}; |
| 96 | char str[256]; |
| 97 | |
Johann | ba13ff8 | 2015-03-25 12:45:27 -0700 | [diff] [blame] | 98 | if (mode == kFrameParallelMode) { |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 99 | 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 Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 108 | |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 109 | // 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 Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 113 | #if CONFIG_WEBM_IO |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 114 | video = new libvpx_test::WebMVideoSource(filename); |
Vignesh Venkatasubramanian | 68ff368 | 2014-04-18 11:24:02 -0700 | [diff] [blame] | 115 | #else |
| 116 | fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n", |
| 117 | filename.c_str()); |
| 118 | return; |
| 119 | #endif |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 120 | } |
| 121 | video->Init(); |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 122 | |
| 123 | // Construct md5 file name. |
| 124 | const std::string md5_filename = filename + ".md5"; |
| 125 | OpenMD5File(md5_filename); |
| 126 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 127 | // Set decode config and flags. |
| 128 | set_cfg(cfg); |
| 129 | set_flags(flags); |
| 130 | |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 131 | // Decode frame, and check the md5 matching. |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 132 | ASSERT_NO_FATAL_FAILURE(RunLoop(video, cfg)); |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 133 | delete video; |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 136 | // Test VP8 decode in serial mode with single thread. |
| 137 | // NOTE: VP8 only support serial mode. |
James Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 138 | VP8_INSTANTIATE_TEST_CASE( |
| 139 | TestVectorTest, |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 140 | ::testing::Combine( |
James Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 141 | ::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 Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 146 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 147 | // Test VP9 decode in serial mode with single thread. |
James Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 148 | VP9_INSTANTIATE_TEST_CASE( |
| 149 | TestVectorTest, |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 150 | ::testing::Combine( |
James Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 151 | ::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))); |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 156 | |
| 157 | |
James Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 158 | #if CONFIG_VP9_DECODER |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 159 | // Test VP9 decode in frame parallel mode with different number of threads. |
| 160 | INSTANTIATE_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 Zern | 5b9dacd | 2015-02-13 18:48:45 -0800 | [diff] [blame] | 171 | #endif |
Yunqing Wang | 15dffcf | 2012-10-04 12:59:36 -0700 | [diff] [blame] | 172 | } // namespace |