]> granicus.if.org Git - libvpx/blob - test/cpu_speed_test.cc
Add tests for VP9E_CONTENT_SCREEN.
[libvpx] / test / cpu_speed_test.cc
1 /*
2  *  Copyright (c) 2012 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 "third_party/googletest/src/include/gtest/gtest.h"
11 #include "test/codec_factory.h"
12 #include "test/encode_test_driver.h"
13 #include "test/i420_video_source.h"
14 #include "test/util.h"
15 #include "test/y4m_video_source.h"
16
17 namespace {
18
19 const int kMaxPSNR = 100;
20
21 class CpuSpeedTest
22     : public ::libvpx_test::EncoderTest,
23       public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> {
24  protected:
25   CpuSpeedTest()
26       : EncoderTest(GET_PARAM(0)),
27         encoding_mode_(GET_PARAM(1)),
28         set_cpu_used_(GET_PARAM(2)),
29         min_psnr_(kMaxPSNR),
30         tune_content_(VP9E_CONTENT_DEFAULT) {}
31   virtual ~CpuSpeedTest() {}
32
33   virtual void SetUp() {
34     InitializeConfig();
35     SetMode(encoding_mode_);
36     if (encoding_mode_ != ::libvpx_test::kRealTime) {
37       cfg_.g_lag_in_frames = 25;
38       cfg_.rc_end_usage = VPX_VBR;
39     } else {
40       cfg_.g_lag_in_frames = 0;
41       cfg_.rc_end_usage = VPX_CBR;
42     }
43   }
44
45   virtual void BeginPassHook(unsigned int /*pass*/) {
46     min_psnr_ = kMaxPSNR;
47   }
48
49   virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
50                                   ::libvpx_test::Encoder *encoder) {
51     if (video->frame() == 1) {
52       encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
53       encoder->Control(VP9E_SET_TUNE_CONTENT, VP9E_CONTENT_SCREEN);
54       if (encoding_mode_ != ::libvpx_test::kRealTime) {
55         encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
56         encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
57         encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
58         encoder->Control(VP8E_SET_ARNR_TYPE, 3);
59       }
60     }
61   }
62
63   virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
64     if (pkt->data.psnr.psnr[0] < min_psnr_)
65       min_psnr_ = pkt->data.psnr.psnr[0];
66   }
67
68   ::libvpx_test::TestMode encoding_mode_;
69   int set_cpu_used_;
70   double min_psnr_;
71   int tune_content_;
72 };
73
74 TEST_P(CpuSpeedTest, TestQ0) {
75   // Validate that this non multiple of 64 wide clip encodes and decodes
76   // without a mismatch when passing in a very low max q.  This pushes
77   // the encoder to producing lots of big partitions which will likely
78   // extend into the border and test the border condition.
79   cfg_.rc_2pass_vbr_minsection_pct = 5;
80   cfg_.rc_2pass_vbr_maxsection_pct = 2000;
81   cfg_.rc_target_bitrate = 400;
82   cfg_.rc_max_quantizer = 0;
83   cfg_.rc_min_quantizer = 0;
84
85   ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
86                                        20);
87
88   init_flags_ = VPX_CODEC_USE_PSNR;
89
90   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
91   EXPECT_GE(min_psnr_, kMaxPSNR);
92 }
93
94 TEST_P(CpuSpeedTest, TestScreencastQ0) {
95   ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25);
96   cfg_.g_timebase = video.timebase();
97   cfg_.rc_2pass_vbr_minsection_pct = 5;
98   cfg_.rc_2pass_vbr_maxsection_pct = 2000;
99   cfg_.rc_target_bitrate = 400;
100   cfg_.rc_max_quantizer = 0;
101   cfg_.rc_min_quantizer = 0;
102
103   init_flags_ = VPX_CODEC_USE_PSNR;
104
105   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
106   EXPECT_GE(min_psnr_, kMaxPSNR);
107 }
108
109 TEST_P(CpuSpeedTest, TestTuneScreen) {
110   ::libvpx_test::Y4mVideoSource video("screendata.y4m", 0, 25);
111   cfg_.g_timebase = video.timebase();
112   cfg_.rc_2pass_vbr_minsection_pct = 5;
113   cfg_.rc_2pass_vbr_minsection_pct = 2000;
114   cfg_.rc_target_bitrate = 2000;
115   cfg_.rc_max_quantizer = 63;
116   cfg_.rc_min_quantizer = 0;
117   tune_content_ = VP9E_CONTENT_SCREEN;
118
119   init_flags_ = VPX_CODEC_USE_PSNR;
120
121   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
122 }
123
124 TEST_P(CpuSpeedTest, TestEncodeHighBitrate) {
125   // Validate that this non multiple of 64 wide clip encodes and decodes
126   // without a mismatch when passing in a very low max q.  This pushes
127   // the encoder to producing lots of big partitions which will likely
128   // extend into the border and test the border condition.
129   cfg_.rc_2pass_vbr_minsection_pct = 5;
130   cfg_.rc_2pass_vbr_maxsection_pct = 2000;
131   cfg_.rc_target_bitrate = 12000;
132   cfg_.rc_max_quantizer = 10;
133   cfg_.rc_min_quantizer = 0;
134
135   ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
136                                        20);
137
138   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
139 }
140
141 TEST_P(CpuSpeedTest, TestLowBitrate) {
142   // Validate that this clip encodes and decodes without a mismatch
143   // when passing in a very high min q.  This pushes the encoder to producing
144   // lots of small partitions which might will test the other condition.
145   cfg_.rc_2pass_vbr_minsection_pct = 5;
146   cfg_.rc_2pass_vbr_maxsection_pct = 2000;
147   cfg_.rc_target_bitrate = 200;
148   cfg_.rc_min_quantizer = 40;
149
150   ::libvpx_test::I420VideoSource video("hantro_odd.yuv", 208, 144, 30, 1, 0,
151                                        20);
152
153   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
154 }
155
156 VP9_INSTANTIATE_TEST_CASE(
157     CpuSpeedTest,
158     ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
159                       ::libvpx_test::kRealTime),
160     ::testing::Range(0, 9));
161
162 VP10_INSTANTIATE_TEST_CASE(
163     CpuSpeedTest,
164     ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood),
165     ::testing::Range(0, 3));
166 }  // namespace