test_vector_test.cc 5.6 KB

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