cpu_speed_test.cc 6.29 KB
Newer Older
Jim Bankoski's avatar
Jim Bankoski committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jim Bankoski's avatar
Jim Bankoski committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Johann's avatar
Johann committed
10
 */
11

12
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Jim Bankoski's avatar
Jim Bankoski committed
13 14 15 16
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/i420_video_source.h"
#include "test/util.h"
17
#include "test/y4m_video_source.h"
Jim Bankoski's avatar
Jim Bankoski committed
18 19 20

namespace {

21 22
const int kMaxPSNR = 100;

James Zern's avatar
James Zern committed
23
class CpuSpeedTest
24 25
    : public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int>,
      public ::libaom_test::EncoderTest {
Jim Bankoski's avatar
Jim Bankoski committed
26
 protected:
27
  CpuSpeedTest()
clang-format's avatar
clang-format committed
28 29
      : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
        set_cpu_used_(GET_PARAM(2)), min_psnr_(kMaxPSNR),
30
        tune_content_(AOM_CONTENT_DEFAULT) {}
31
  virtual ~CpuSpeedTest() {}
Jim Bankoski's avatar
Jim Bankoski committed
32 33 34

  virtual void SetUp() {
    InitializeConfig();
35
    SetMode(encoding_mode_);
36
    if (encoding_mode_ != ::libaom_test::kRealTime) {
37
      cfg_.g_lag_in_frames = 25;
38
      cfg_.rc_end_usage = AOM_VBR;
39 40
    } else {
      cfg_.g_lag_in_frames = 0;
41
      cfg_.rc_end_usage = AOM_CBR;
42
    }
Jim Bankoski's avatar
Jim Bankoski committed
43 44
  }

clang-format's avatar
clang-format committed
45
  virtual void BeginPassHook(unsigned int /*pass*/) { min_psnr_ = kMaxPSNR; }
46

47 48
  virtual void PreEncodeFrameHook(::libaom_test::VideoSource *video,
                                  ::libaom_test::Encoder *encoder) {
Jim Bankoski's avatar
Jim Bankoski committed
49
    if (video->frame() == 1) {
50 51
      encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
      encoder->Control(AV1E_SET_TUNE_CONTENT, tune_content_);
52
      if (encoding_mode_ != ::libaom_test::kRealTime) {
53 54 55
        encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
        encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
        encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
56
      }
Jim Bankoski's avatar
Jim Bankoski committed
57 58 59
    }
  }

60
  virtual void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) {
clang-format's avatar
clang-format committed
61
    if (pkt->data.psnr.psnr[0] < min_psnr_) min_psnr_ = pkt->data.psnr.psnr[0];
62 63
  }

64 65 66 67 68 69
  void TestQ0();
  void TestScreencastQ0();
  void TestTuneScreen();
  void TestEncodeHighBitrate();
  void TestLowBitrate();

70
  ::libaom_test::TestMode encoding_mode_;
Jim Bankoski's avatar
Jim Bankoski committed
71
  int set_cpu_used_;
72
  double min_psnr_;
73
  int tune_content_;
Jim Bankoski's avatar
Jim Bankoski committed
74 75
};

76
void CpuSpeedTest::TestQ0() {
Jim Bankoski's avatar
Jim Bankoski committed
77 78 79 80 81
  // Validate that this non multiple of 64 wide clip encodes and decodes
  // without a mismatch when passing in a very low max q.  This pushes
  // the encoder to producing lots of big partitions which will likely
  // extend into the border and test the border condition.
  cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su's avatar
hui su committed
82
  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Jim Bankoski's avatar
Jim Bankoski committed
83 84 85 86
  cfg_.rc_target_bitrate = 400;
  cfg_.rc_max_quantizer = 0;
  cfg_.rc_min_quantizer = 0;

87
  ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
88
                                       10);
Jim Bankoski's avatar
Jim Bankoski committed
89

90
  init_flags_ = AOM_CODEC_USE_PSNR;
91

Jim Bankoski's avatar
Jim Bankoski committed
92
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
93
  EXPECT_GE(min_psnr_, kMaxPSNR);
Jim Bankoski's avatar
Jim Bankoski committed
94 95
}

96
void CpuSpeedTest::TestScreencastQ0() {
97
  ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
98 99
  cfg_.g_timebase = video.timebase();
  cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su's avatar
hui su committed
100
  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
101 102 103 104
  cfg_.rc_target_bitrate = 400;
  cfg_.rc_max_quantizer = 0;
  cfg_.rc_min_quantizer = 0;

105
  init_flags_ = AOM_CODEC_USE_PSNR;
106 107 108 109

  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  EXPECT_GE(min_psnr_, kMaxPSNR);
}
Jim Bankoski's avatar
Jim Bankoski committed
110

111
void CpuSpeedTest::TestTuneScreen() {
112
  ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 3);
113 114 115 116 117 118
  cfg_.g_timebase = video.timebase();
  cfg_.rc_2pass_vbr_minsection_pct = 5;
  cfg_.rc_2pass_vbr_minsection_pct = 2000;
  cfg_.rc_target_bitrate = 2000;
  cfg_.rc_max_quantizer = 63;
  cfg_.rc_min_quantizer = 0;
119
  tune_content_ = AOM_CONTENT_SCREEN;
120

121
  init_flags_ = AOM_CODEC_USE_PSNR;
122 123 124 125

  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}

126
void CpuSpeedTest::TestEncodeHighBitrate() {
Jim Bankoski's avatar
Jim Bankoski committed
127 128 129 130 131
  // Validate that this non multiple of 64 wide clip encodes and decodes
  // without a mismatch when passing in a very low max q.  This pushes
  // the encoder to producing lots of big partitions which will likely
  // extend into the border and test the border condition.
  cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su's avatar
hui su committed
132
  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Jim Bankoski's avatar
Jim Bankoski committed
133 134 135 136
  cfg_.rc_target_bitrate = 12000;
  cfg_.rc_max_quantizer = 10;
  cfg_.rc_min_quantizer = 0;

137
  ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
138
                                       10);
Jim Bankoski's avatar
Jim Bankoski committed
139 140 141

  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}
James Zern's avatar
James Zern committed
142

143
void CpuSpeedTest::TestLowBitrate() {
Jim Bankoski's avatar
Jim Bankoski committed
144 145 146 147
  // Validate that this clip encodes and decodes without a mismatch
  // when passing in a very high min q.  This pushes the encoder to producing
  // lots of small partitions which might will test the other condition.
  cfg_.rc_2pass_vbr_minsection_pct = 5;
hui su's avatar
hui su committed
148
  cfg_.rc_2pass_vbr_maxsection_pct = 2000;
Jim Bankoski's avatar
Jim Bankoski committed
149 150 151
  cfg_.rc_target_bitrate = 200;
  cfg_.rc_min_quantizer = 40;

152
  ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
153
                                       10);
Jim Bankoski's avatar
Jim Bankoski committed
154 155 156 157

  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}

158 159 160 161 162 163 164 165 166 167 168 169 170 171
TEST_P(CpuSpeedTest, TestQ0) { TestQ0(); }
TEST_P(CpuSpeedTest, TestScreencastQ0) { TestScreencastQ0(); }
TEST_P(CpuSpeedTest, TestTuneScreen) { TestTuneScreen(); }
TEST_P(CpuSpeedTest, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
TEST_P(CpuSpeedTest, TestLowBitrate) { TestLowBitrate(); }

class CpuSpeedTestLarge : public CpuSpeedTest {};

TEST_P(CpuSpeedTestLarge, TestQ0) { TestQ0(); }
TEST_P(CpuSpeedTestLarge, TestScreencastQ0) { TestScreencastQ0(); }
TEST_P(CpuSpeedTestLarge, TestTuneScreen) { TestTuneScreen(); }
TEST_P(CpuSpeedTestLarge, TestEncodeHighBitrate) { TestEncodeHighBitrate(); }
TEST_P(CpuSpeedTestLarge, TestLowBitrate) { TestLowBitrate(); }

172 173 174 175 176 177 178 179
AV1_INSTANTIATE_TEST_CASE(CpuSpeedTest,
                          ::testing::Values(::libaom_test::kTwoPassGood,
                                            ::libaom_test::kOnePassGood),
                          ::testing::Range(1, 3));
AV1_INSTANTIATE_TEST_CASE(CpuSpeedTestLarge,
                          ::testing::Values(::libaom_test::kTwoPassGood,
                                            ::libaom_test::kOnePassGood),
                          ::testing::Range(0, 1));
Jim Bankoski's avatar
Jim Bankoski committed
180
}  // namespace