test_vector_test.cc 5.96 KB
Newer Older
1
/*
2 3 4 5 6 7 8
 *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
9 10 11 12
 */

#include <cstdio>
#include <cstdlib>
13
#include <set>
14 15
#include <string>
#include "third_party/googletest/src/include/gtest/gtest.h"
16
#include "../tools_common.h"
17
#include "./vpx_config.h"
18
#include "test/codec_factory.h"
19 20
#include "test/decode_test_driver.h"
#include "test/ivf_video_source.h"
21
#include "test/md5_helper.h"
22 23
#include "test/test_vectors.h"
#include "test/util.h"
24
#if CONFIG_WEBM_IO
25
#include "test/webm_video_source.h"
26
#endif
27 28 29 30
#include "vpx_mem/vpx_mem.h"

namespace {

31 32
enum DecodeMode {
  kSerialMode,
Johann's avatar
Johann committed
33
  kFrameParallelMode
34 35 36 37 38 39 40 41
};

const int kDecodeMode = 0;
const int kThreads = 1;
const int kFileName = 2;

typedef std::tr1::tuple<int, int, const char*> DecodeParam;

42
class TestVectorTest : public ::libvpx_test::DecoderTest,
43
    public ::libvpx_test::CodecTestWithParam<DecodeParam> {
44
 protected:
45 46 47
  TestVectorTest()
      : DecoderTest(GET_PARAM(0)),
        md5_file_(NULL) {
48 49 50 51 52 53
#if CONFIG_VP9_DECODER
    resize_clips_.insert(
      ::libvpx_test::kVP9TestVectorsResize,
      ::libvpx_test::kVP9TestVectorsResize +
          ::libvpx_test::kNumVP9TestVectorsResize);
#endif
54
  }
55 56 57 58 59 60 61 62

  virtual ~TestVectorTest() {
    if (md5_file_)
      fclose(md5_file_);
  }

  void OpenMD5File(const std::string& md5_file_name_) {
    md5_file_ = libvpx_test::OpenTestDataFile(md5_file_name_);
63
    ASSERT_TRUE(md5_file_ != NULL) << "Md5 file open failed. Filename: "
64 65 66 67 68
        << md5_file_name_;
  }

  virtual void DecompressedFrameHook(const vpx_image_t& img,
                                     const unsigned int frame_number) {
69
    ASSERT_TRUE(md5_file_ != NULL);
70 71 72 73 74 75 76 77
    char expected_md5[33];
    char junk[128];

    // Read correct md5 checksums.
    const int res = fscanf(md5_file_, "%s  %s", expected_md5, junk);
    ASSERT_NE(res, EOF) << "Read md5 data failed";
    expected_md5[32] = '\0';

78 79 80
    ::libvpx_test::MD5 md5_res;
    md5_res.Add(&img);
    const char *actual_md5 = md5_res.Get();
81 82 83 84 85 86

    // Check md5 match.
    ASSERT_STREQ(expected_md5, actual_md5)
        << "Md5 checksums don't match: frame number = " << frame_number;
  }

87 88 89 90
#if CONFIG_VP9_DECODER
  std::set<std::string> resize_clips_;
#endif

91 92 93 94 95 96 97 98 99
 private:
  FILE *md5_file_;
};

// This test runs through the whole set of test vectors, and decodes them.
// The md5 checksums are computed for each frame in the video file. If md5
// checksums match the correct md5 data, then the test is passed. Otherwise,
// the test failed.
TEST_P(TestVectorTest, MD5Match) {
100 101 102 103
  const DecodeParam input = GET_PARAM(1);
  const std::string filename = std::tr1::get<kFileName>(input);
  const int threads = std::tr1::get<kThreads>(input);
  const int mode = std::tr1::get<kDecodeMode>(input);
104
  libvpx_test::CompressedVideoSource *video = NULL;
105 106 107 108
  vpx_codec_flags_t flags = 0;
  vpx_codec_dec_cfg_t cfg = {0};
  char str[256];

Johann's avatar
Johann committed
109
  if (mode == kFrameParallelMode) {
110
    flags |= VPX_CODEC_USE_FRAME_THREADING;
111 112 113 114 115 116 117 118
#if CONFIG_VP9_DECODER
    // TODO(hkuang): Fix frame parallel decode bug. See issue 1086.
    if (resize_clips_.find(filename) != resize_clips_.end()) {
      printf("Skipping the test file: %s, due to frame parallel decode bug.\n",
             filename.c_str());
      return;
    }
#endif
119 120 121 122 123 124 125 126
  }

  cfg.threads = threads;

  snprintf(str, sizeof(str) / sizeof(str[0]) - 1,
           "file: %s  mode: %s threads: %d",
           filename.c_str(), mode == 0 ? "Serial" : "Parallel", threads);
  SCOPED_TRACE(str);
127

128 129 130 131
  // Open compressed video file.
  if (filename.substr(filename.length() - 3, 3) == "ivf") {
    video = new libvpx_test::IVFVideoSource(filename);
  } else if (filename.substr(filename.length() - 4, 4) == "webm") {
132
#if CONFIG_WEBM_IO
133
    video = new libvpx_test::WebMVideoSource(filename);
134 135 136 137 138
#else
    fprintf(stderr, "WebM IO is disabled, skipping test vector %s\n",
            filename.c_str());
    return;
#endif
139 140
  }
  video->Init();
141 142 143 144 145

  // Construct md5 file name.
  const std::string md5_filename = filename + ".md5";
  OpenMD5File(md5_filename);

146 147 148 149
  // Set decode config and flags.
  set_cfg(cfg);
  set_flags(flags);

150
  // Decode frame, and check the md5 matching.
151
  ASSERT_NO_FATAL_FAILURE(RunLoop(video, cfg));
152
  delete video;
153 154
}

155 156
// Test VP8 decode in serial mode with single thread.
// NOTE: VP8 only support serial mode.
157
#if CONFIG_VP8_DECODER
158 159
VP8_INSTANTIATE_TEST_CASE(
    TestVectorTest,
160
    ::testing::Combine(
161 162 163 164 165
        ::testing::Values(0),  // Serial Mode.
        ::testing::Values(1),  // Single thread.
        ::testing::ValuesIn(libvpx_test::kVP8TestVectors,
                            libvpx_test::kVP8TestVectors +
                                libvpx_test::kNumVP8TestVectors)));
166
#endif  // CONFIG_VP8_DECODER
167 168

// Test VP9 decode in serial mode with single thread.
169
#if CONFIG_VP9_DECODER
170 171
VP9_INSTANTIATE_TEST_CASE(
    TestVectorTest,
172
    ::testing::Combine(
173 174 175 176 177
        ::testing::Values(0),  // Serial Mode.
        ::testing::Values(1),  // Single thread.
        ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
                            libvpx_test::kVP9TestVectors +
                                libvpx_test::kNumVP9TestVectors)));
178 179 180 181 182 183 184 185 186 187 188 189 190

// Test VP9 decode in frame parallel mode with different number of threads.
INSTANTIATE_TEST_CASE_P(
    VP9MultiThreadedFrameParallel, TestVectorTest,
    ::testing::Combine(
        ::testing::Values(
            static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9)),
        ::testing::Combine(
            ::testing::Values(1),        // Frame Parallel mode.
            ::testing::Range(2, 9),      // With 2 ~ 8 threads.
            ::testing::ValuesIn(libvpx_test::kVP9TestVectors,
                                libvpx_test::kVP9TestVectors +
                                    libvpx_test::kNumVP9TestVectors))));
191
#endif
192
}  // namespace