cpu_speed_test.cc 4.77 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 10 11
 * 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.
*/

Jim Bankoski's avatar
Jim Bankoski committed
12 13 14 15 16
#include "third_party/googletest/src/include/gtest/gtest.h"
#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
Yaowu Xu's avatar
Yaowu Xu committed
24 25
    : public ::libaom_test::EncoderTest,
      public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> {
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
  virtual ~CpuSpeedTest() {}
Jim Bankoski's avatar
Jim Bankoski committed
31 32 33

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

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

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

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

Yaowu Xu's avatar
Yaowu Xu committed
63
  ::libaom_test::TestMode encoding_mode_;
Jim Bankoski's avatar
Jim Bankoski committed
64
  int set_cpu_used_;
65
  double min_psnr_;
Jim Bankoski's avatar
Jim Bankoski committed
66 67 68 69 70 71 72 73 74 75 76 77 78
};

TEST_P(CpuSpeedTest, TestQ0) {
  // 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;
  cfg_.rc_2pass_vbr_minsection_pct = 2000;
  cfg_.rc_target_bitrate = 400;
  cfg_.rc_max_quantizer = 0;
  cfg_.rc_min_quantizer = 0;

Yaowu Xu's avatar
Yaowu Xu committed
79
  ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
Jim Bankoski's avatar
Jim Bankoski committed
80 81
                                       20);

Adrian Grange's avatar
Adrian Grange committed
82
  init_flags_ = AOM_CODEC_USE_PSNR;
83

Jim Bankoski's avatar
Jim Bankoski committed
84
  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
85
  EXPECT_GE(min_psnr_, kMaxPSNR);
Jim Bankoski's avatar
Jim Bankoski committed
86 87
}

88
TEST_P(CpuSpeedTest, TestScreencastQ0) {
Yaowu Xu's avatar
Yaowu Xu committed
89
  ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 25);
90 91 92 93 94 95 96
  cfg_.g_timebase = video.timebase();
  cfg_.rc_2pass_vbr_minsection_pct = 5;
  cfg_.rc_2pass_vbr_minsection_pct = 2000;
  cfg_.rc_target_bitrate = 400;
  cfg_.rc_max_quantizer = 0;
  cfg_.rc_min_quantizer = 0;

Adrian Grange's avatar
Adrian Grange committed
97
  init_flags_ = AOM_CODEC_USE_PSNR;
98 99 100 101

  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  EXPECT_GE(min_psnr_, kMaxPSNR);
}
Jim Bankoski's avatar
Jim Bankoski committed
102 103 104 105 106 107 108 109 110 111 112 113

TEST_P(CpuSpeedTest, TestEncodeHighBitrate) {
  // 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;
  cfg_.rc_2pass_vbr_minsection_pct = 2000;
  cfg_.rc_target_bitrate = 12000;
  cfg_.rc_max_quantizer = 10;
  cfg_.rc_min_quantizer = 0;

Yaowu Xu's avatar
Yaowu Xu committed
114
  ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
115
                                       20);
Jim Bankoski's avatar
Jim Bankoski committed
116 117 118

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

Jim Bankoski's avatar
Jim Bankoski committed
120 121 122 123 124 125 126 127 128
TEST_P(CpuSpeedTest, TestLowBitrate) {
  // 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;
  cfg_.rc_2pass_vbr_minsection_pct = 2000;
  cfg_.rc_target_bitrate = 200;
  cfg_.rc_min_quantizer = 40;

Yaowu Xu's avatar
Yaowu Xu committed
129
  ::libaom_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
130
                                       20);
Jim Bankoski's avatar
Jim Bankoski committed
131 132 133 134

  ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
}

135
AV1_INSTANTIATE_TEST_CASE(CpuSpeedTest,
Yaowu Xu's avatar
Yaowu Xu committed
136 137
                           ::testing::Values(::libaom_test::kTwoPassGood,
                                             ::libaom_test::kOnePassGood),
clang-format's avatar
clang-format committed
138
                           ::testing::Range(0, 3));
Jim Bankoski's avatar
Jim Bankoski committed
139
}  // namespace