test_vector_test.cc (5807B)
1 /* 2 * Copyright (c) 2018, Alliance for Open Media. All rights reserved. 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 #include <cstdio> 13 #include <cstdlib> 14 #include <memory> 15 #include <set> 16 #include <string> 17 #include <tuple> 18 #include "common/tools_common.h" 19 #include "config/aom_config.h" 20 #include "gtest/gtest.h" 21 #include "test/codec_factory.h" 22 #include "test/decode_test_driver.h" 23 #include "test/ivf_video_source.h" 24 #include "test/md5_helper.h" 25 #include "test/test_vectors.h" 26 #include "test/util.h" 27 #if CONFIG_WEBM_IO 28 #include "test/webm_video_source.h" 29 #endif 30 31 namespace { 32 33 const int kThreads = 0; 34 const int kFileName = 1; 35 const int kRowMT = 2; 36 37 using DecodeParam = std::tuple<int, const char *, int>; 38 39 class TestVectorTest : public ::libaom_test::DecoderTest, 40 public ::libaom_test::CodecTestWithParam<DecodeParam> { 41 protected: 42 TestVectorTest() : DecoderTest(GET_PARAM(0)), md5_file_(nullptr) {} 43 44 ~TestVectorTest() override { 45 if (md5_file_) fclose(md5_file_); 46 } 47 48 void OpenMD5File(const std::string &md5_file_name_) { 49 md5_file_ = libaom_test::OpenTestDataFile(md5_file_name_); 50 ASSERT_NE(md5_file_, nullptr) 51 << "Md5 file open failed. Filename: " << md5_file_name_; 52 } 53 54 void PreDecodeFrameHook(const libaom_test::CompressedVideoSource &video, 55 libaom_test::Decoder *decoder) override { 56 if (video.frame_number() == 0) decoder->Control(AV1D_SET_ROW_MT, row_mt_); 57 } 58 59 void DecompressedFrameHook(const aom_image_t &img, 60 const unsigned int frame_number) override { 61 ASSERT_NE(md5_file_, nullptr); 62 char expected_md5[33]; 63 char junk[128]; 64 65 // Read correct md5 checksums. 66 const int res = fscanf(md5_file_, "%s %s", expected_md5, junk); 67 ASSERT_NE(res, EOF) << "Read md5 data failed"; 68 expected_md5[32] = '\0'; 69 70 ::libaom_test::MD5 md5_res; 71 #if FORCE_HIGHBITDEPTH_DECODING 72 const aom_img_fmt_t shifted_fmt = 73 (aom_img_fmt)(img.fmt & ~AOM_IMG_FMT_HIGHBITDEPTH); 74 if (img.bit_depth == 8 && shifted_fmt != img.fmt) { 75 aom_image_t *img_shifted = 76 aom_img_alloc(nullptr, shifted_fmt, img.d_w, img.d_h, 16); 77 img_shifted->bit_depth = img.bit_depth; 78 img_shifted->monochrome = img.monochrome; 79 aom_img_downshift(img_shifted, &img, 0); 80 md5_res.Add(img_shifted); 81 aom_img_free(img_shifted); 82 } else { 83 #endif 84 md5_res.Add(&img); 85 #if FORCE_HIGHBITDEPTH_DECODING 86 } 87 #endif 88 89 const char *actual_md5 = md5_res.Get(); 90 // Check md5 match. 91 ASSERT_STREQ(expected_md5, actual_md5) 92 << "Md5 checksums don't match: frame number = " << frame_number; 93 } 94 95 unsigned int row_mt_; 96 97 private: 98 FILE *md5_file_; 99 }; 100 101 // This test runs through the whole set of test vectors, and decodes them. 102 // The md5 checksums are computed for each frame in the video file. If md5 103 // checksums match the correct md5 data, then the test is passed. Otherwise, 104 // the test failed. 105 TEST_P(TestVectorTest, MD5Match) { 106 const DecodeParam input = GET_PARAM(1); 107 const std::string filename = std::get<kFileName>(input); 108 aom_codec_flags_t flags = 0; 109 aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t(); 110 char str[256]; 111 112 cfg.threads = std::get<kThreads>(input); 113 row_mt_ = std::get<kRowMT>(input); 114 115 snprintf(str, sizeof(str) / sizeof(str[0]) - 1, "file: %s threads: %d", 116 filename.c_str(), cfg.threads); 117 SCOPED_TRACE(str); 118 119 // Open compressed video file. 120 std::unique_ptr<libaom_test::CompressedVideoSource> video; 121 if (filename.substr(filename.length() - 3, 3) == "ivf") { 122 video.reset(new libaom_test::IVFVideoSource(filename)); 123 } else if (filename.substr(filename.length() - 4, 4) == "webm" || 124 filename.substr(filename.length() - 3, 3) == "mkv") { 125 #if CONFIG_WEBM_IO 126 video.reset(new libaom_test::WebMVideoSource(filename)); 127 #else 128 fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n", 129 filename.c_str()); 130 return; 131 #endif 132 } 133 ASSERT_NE(video, nullptr); 134 video->Init(); 135 136 // Construct md5 file name. 137 const std::string md5_filename = filename + ".md5"; 138 OpenMD5File(md5_filename); 139 140 // Set decode config and flags. 141 cfg.allow_lowbitdepth = !FORCE_HIGHBITDEPTH_DECODING; 142 set_cfg(cfg); 143 set_flags(flags); 144 145 // Decode frame, and check the md5 matching. 146 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get(), cfg)); 147 } 148 149 #if CONFIG_AV1_DECODER 150 AV1_INSTANTIATE_TEST_SUITE( 151 TestVectorTest, 152 ::testing::Combine(::testing::Values(1), // Single thread. 153 ::testing::ValuesIn(libaom_test::kAV1TestVectors, 154 libaom_test::kAV1TestVectors + 155 libaom_test::kNumAV1TestVectors), 156 ::testing::Values(0))); 157 158 // Test AV1 decode in with different numbers of threads. 159 INSTANTIATE_TEST_SUITE_P( 160 AV1MultiThreaded, TestVectorTest, 161 ::testing::Combine( 162 ::testing::Values( 163 static_cast<const libaom_test::CodecFactory *>(&libaom_test::kAV1)), 164 ::testing::Combine( 165 ::testing::Range(2, 9), // With 2 ~ 8 threads. 166 ::testing::ValuesIn(libaom_test::kAV1TestVectors, 167 libaom_test::kAV1TestVectors + 168 libaom_test::kNumAV1TestVectors), 169 ::testing::Range(0, 2)))); 170 171 #endif // CONFIG_AV1_DECODER 172 173 } // namespace