test_vector_test.cc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  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.
  9. */
  10. #include <cstdio>
  11. #include <cstdlib>
  12. #include <memory>
  13. #include <set>
  14. #include <string>
  15. #include <tuple>
  16. #include "third_party/googletest/src/include/gtest/gtest.h"
  17. #include "../tools_common.h"
  18. #include "./vpx_config.h"
  19. #include "test/codec_factory.h"
  20. #include "test/decode_test_driver.h"
  21. #include "test/ivf_video_source.h"
  22. #include "test/md5_helper.h"
  23. #include "test/test_vectors.h"
  24. #include "test/util.h"
  25. #if CONFIG_WEBM_IO
  26. #include "test/webm_video_source.h"
  27. #endif
  28. #include "vpx_mem/vpx_mem.h"
  29. namespace {
  30. const int kThreads = 0;
  31. const int kMtMode = 1;
  32. const int kFileName = 2;
  33. typedef std::tuple<int, int, const char *> DecodeParam;
  34. class TestVectorTest : public ::libvpx_test::DecoderTest,
  35. public ::libvpx_test::CodecTestWithParam<DecodeParam> {
  36. protected:
  37. TestVectorTest() : DecoderTest(GET_PARAM(0)), md5_file_(NULL) {
  38. #if CONFIG_VP9_DECODER
  39. resize_clips_.insert(::libvpx_test::kVP9TestVectorsResize,
  40. ::libvpx_test::kVP9TestVectorsResize +
  41. ::libvpx_test::kNumVP9TestVectorsResize);
  42. #endif
  43. }
  44. virtual ~TestVectorTest() {
  45. if (md5_file_) fclose(md5_file_);
  46. }
  47. void OpenMD5File(const std::string &md5_file_name_) {
  48. md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
  49. ASSERT_TRUE(md5_file_ != NULL)
  50. << "Md5 file open failed. Filename: " << md5_file_name_;
  51. }
  52. #if CONFIG_VP9_DECODER
  53. virtual void PreDecodeFrameHook(
  54. const libvpx_test::CompressedVideoSource &video,
  55. libvpx_test::Decoder *decoder) {
  56. if (video.frame_number() == 0 && mt_mode_ >= 0) {
  57. if (mt_mode_ == 1) {
  58. decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 1);
  59. decoder->Control(VP9D_SET_ROW_MT, 0);
  60. } else if (mt_mode_ == 2) {
  61. decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 0);
  62. decoder->Control(VP9D_SET_ROW_MT, 1);
  63. } else {
  64. decoder->Control(VP9D_SET_LOOP_FILTER_OPT, 0);
  65. decoder->Control(VP9D_SET_ROW_MT, 0);
  66. }
  67. }
  68. }
  69. #endif
  70. virtual void DecompressedFrameHook(const vpx_image_t &img,
  71. const unsigned int frame_number) {
  72. ASSERT_TRUE(md5_file_ != NULL);
  73. char expected_md5[33];
  74. char junk[128];
  75. // Read correct md5 checksums.
  76. const int res = fscanf(md5_file_, "%s %s", expected_md5, junk);
  77. ASSERT_NE(res, EOF) << "Read md5 data failed";
  78. expected_md5[32] = '\0';
  79. ::libvpx_test::MD5 md5_res;
  80. md5_res.Add(&img);
  81. const char *actual_md5 = md5_res.Get();
  82. // Check md5 match.
  83. ASSERT_STREQ(expected_md5, actual_md5)
  84. << "Md5 checksums don't match: frame number = " << frame_number;
  85. }
  86. #if CONFIG_VP9_DECODER
  87. std::set<std::string> resize_clips_;
  88. #endif
  89. int mt_mode_;
  90. private:
  91. FILE *md5_file_;
  92. };
  93. // This test runs through the whole set of test vectors, and decodes them.
  94. // The md5 checksums are computed for each frame in the video file. If md5
  95. // checksums match the correct md5 data, then the test is passed. Otherwise,
  96. // the test failed.
  97. TEST_P(TestVectorTest, MD5Match) {
  98. const DecodeParam input = GET_PARAM(1);
  99. const std::string filename = std::get<kFileName>(input);
  100. vpx_codec_flags_t flags = 0;
  101. vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
  102. char str[256];
  103. cfg.threads = std::get<kThreads>(input);
  104. mt_mode_ = std::get<kMtMode>(input);
  105. snprintf(str, sizeof(str) / sizeof(str[0]) - 1,
  106. "file: %s threads: %d MT mode: %d", filename.c_str(), cfg.threads,
  107. mt_mode_);
  108. SCOPED_TRACE(str);
  109. // Open compressed video file.
  110. std::unique_ptr<libvpx_test::CompressedVideoSource> video;
  111. if (filename.substr(filename.length() - 3, 3) == "ivf") {
  112. video.reset(new libvpx_test::IVFVideoSource(filename));
  113. } else if (filename.substr(filename.length() - 4, 4) == "webm") {
  114. #if CONFIG_WEBM_IO
  115. video.reset(new libvpx_test::WebMVideoSource(filename));
  116. #else
  117. fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
  118. filename.c_str());
  119. return;
  120. #endif
  121. }
  122. ASSERT_TRUE(video.get() != NULL);
  123. video->Init();
  124. // Construct md5 file name.
  125. const std::string md5_filename = filename + ".md5";
  126. OpenMD5File(md5_filename);
  127. // Set decode config and flags.
  128. set_cfg(cfg);
  129. set_flags(flags);
  130. // Decode frame, and check the md5 matching.
  131. ASSERT_NO_FATAL_FAILURE(RunLoop(video.get(), cfg));
  132. }
  133. #if CONFIG_VP8_DECODER
  134. VP8_INSTANTIATE_TEST_CASE(
  135. TestVectorTest,
  136. ::testing::Combine(
  137. ::testing::Values(1), // Single thread.
  138. ::testing::Values(-1), // LPF opt and Row MT is not applicable
  139. ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
  140. libvpx_test::kVP8TestVectors +
  141. libvpx_test::kNumVP8TestVectors)));
  142. // Test VP8 decode in with different numbers of threads.
  143. INSTANTIATE_TEST_CASE_P(
  144. VP8MultiThreaded, TestVectorTest,
  145. ::testing::Combine(
  146. ::testing::Values(
  147. static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP8)),
  148. ::testing::Combine(
  149. ::testing::Range(2, 9), // With 2 ~ 8 threads.
  150. ::testing::Values(-1), // LPF opt and Row MT is not applicable
  151. ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
  152. libvpx_test::kVP8TestVectors +
  153. libvpx_test::kNumVP8TestVectors))));
  154. #endif // CONFIG_VP8_DECODER
  155. #if CONFIG_VP9_DECODER
  156. VP9_INSTANTIATE_TEST_CASE(
  157. TestVectorTest,
  158. ::testing::Combine(
  159. ::testing::Values(1), // Single thread.
  160. ::testing::Values(-1), // LPF opt and Row MT is not applicable
  161. ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
  162. libvpx_test::kVP9TestVectors +
  163. libvpx_test::kNumVP9TestVectors)));
  164. INSTANTIATE_TEST_CASE_P(
  165. VP9MultiThreaded, TestVectorTest,
  166. ::testing::Combine(
  167. ::testing::Values(
  168. static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)),
  169. ::testing::Combine(
  170. ::testing::Range(2, 9), // With 2 ~ 8 threads.
  171. ::testing::Range(0, 3), // With multi threads modes 0 ~ 2
  172. // 0: LPF opt and Row MT disabled
  173. // 1: LPF opt enabled
  174. // 2: Row MT enabled
  175. ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
  176. libvpx_test::kVP9TestVectors +
  177. libvpx_test::kNumVP9TestVectors))));
  178. #endif
  179. } // namespace