1 /*
2 * Copyright (c) 2014 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
11 #include "third_party/googletest/src/include/gtest/gtest.h"
12
13 #include "test/codec_factory.h"
14 #include "test/encode_test_driver.h"
15 #include "test/util.h"
16 #include "test/y4m_video_source.h"
17 #include "test/yuv_video_source.h"
18
19 namespace {
20
21 const unsigned int kWidth = 160;
22 const unsigned int kHeight = 90;
23 const unsigned int kFramerate = 50;
24 const unsigned int kFrames = 10;
25 const int kBitrate = 500;
26 // List of psnr thresholds for speed settings 0-7 and 5 encoding modes
27 const double kPsnrThreshold[][5] = {
28 { 36.0, 37.0, 37.0, 37.0, 37.0 },
29 { 35.0, 36.0, 36.0, 36.0, 36.0 },
30 { 34.0, 35.0, 35.0, 35.0, 35.0 },
31 { 33.0, 34.0, 34.0, 34.0, 34.0 },
32 { 32.0, 33.0, 33.0, 33.0, 33.0 },
33 { 31.0, 32.0, 32.0, 32.0, 32.0 },
34 { 30.0, 31.0, 31.0, 31.0, 31.0 },
35 { 29.0, 30.0, 30.0, 30.0, 30.0 },
36 };
37
38 typedef struct {
39 const char *filename;
40 unsigned int input_bit_depth;
41 vpx_img_fmt fmt;
42 vpx_bit_depth_t bit_depth;
43 unsigned int profile;
44 } TestVideoParam;
45
46 const TestVideoParam kTestVectors[] = {
47 {"park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, VPX_BITS_8, 0},
48 {"park_joy_90p_8_422.y4m", 8, VPX_IMG_FMT_I422, VPX_BITS_8, 1},
49 {"park_joy_90p_8_444.y4m", 8, VPX_IMG_FMT_I444, VPX_BITS_8, 1},
50 {"park_joy_90p_8_440.yuv", 8, VPX_IMG_FMT_I440, VPX_BITS_8, 1},
51 #if CONFIG_VP9_HIGHBITDEPTH
52 {"park_joy_90p_10_420.y4m", 10, VPX_IMG_FMT_I42016, VPX_BITS_10, 2},
53 {"park_joy_90p_10_422.y4m", 10, VPX_IMG_FMT_I42216, VPX_BITS_10, 3},
54 {"park_joy_90p_10_444.y4m", 10, VPX_IMG_FMT_I44416, VPX_BITS_10, 3},
55 {"park_joy_90p_10_440.yuv", 10, VPX_IMG_FMT_I44016, VPX_BITS_10, 3},
56 {"park_joy_90p_12_420.y4m", 12, VPX_IMG_FMT_I42016, VPX_BITS_12, 2},
57 {"park_joy_90p_12_422.y4m", 12, VPX_IMG_FMT_I42216, VPX_BITS_12, 3},
58 {"park_joy_90p_12_444.y4m", 12, VPX_IMG_FMT_I44416, VPX_BITS_12, 3},
59 {"park_joy_90p_12_440.yuv", 12, VPX_IMG_FMT_I44016, VPX_BITS_12, 3},
60 #endif // CONFIG_VP9_HIGHBITDEPTH
61 };
62
63 // Encoding modes tested
64 const libvpx_test::TestMode kEncodingModeVectors[] = {
65 ::libvpx_test::kTwoPassGood,
66 ::libvpx_test::kOnePassGood,
67 ::libvpx_test::kRealTime,
68 };
69
70 // Speed settings tested
71 const int kCpuUsedVectors[] = {1, 2, 3, 5, 6};
72
is_extension_y4m(const char * filename)73 int is_extension_y4m(const char *filename) {
74 const char *dot = strrchr(filename, '.');
75 if (!dot || dot == filename)
76 return 0;
77 else
78 return !strcmp(dot, ".y4m");
79 }
80
81 class EndToEndTestLarge
82 : public ::libvpx_test::EncoderTest,
83 public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode, \
84 TestVideoParam, int> {
85 protected:
EndToEndTestLarge()86 EndToEndTestLarge()
87 : EncoderTest(GET_PARAM(0)),
88 test_video_param_(GET_PARAM(2)),
89 cpu_used_(GET_PARAM(3)),
90 psnr_(0.0),
91 nframes_(0),
92 encoding_mode_(GET_PARAM(1)) {
93 }
94
~EndToEndTestLarge()95 virtual ~EndToEndTestLarge() {}
96
SetUp()97 virtual void SetUp() {
98 InitializeConfig();
99 SetMode(encoding_mode_);
100 if (encoding_mode_ != ::libvpx_test::kRealTime) {
101 cfg_.g_lag_in_frames = 5;
102 cfg_.rc_end_usage = VPX_VBR;
103 } else {
104 cfg_.g_lag_in_frames = 0;
105 cfg_.rc_end_usage = VPX_CBR;
106 cfg_.rc_buf_sz = 1000;
107 cfg_.rc_buf_initial_sz = 500;
108 cfg_.rc_buf_optimal_sz = 600;
109 }
110 dec_cfg_.threads = 4;
111 }
112
BeginPassHook(unsigned int)113 virtual void BeginPassHook(unsigned int) {
114 psnr_ = 0.0;
115 nframes_ = 0;
116 }
117
PSNRPktHook(const vpx_codec_cx_pkt_t * pkt)118 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
119 psnr_ += pkt->data.psnr.psnr[0];
120 nframes_++;
121 }
122
PreEncodeFrameHook(::libvpx_test::VideoSource * video,::libvpx_test::Encoder * encoder)123 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
124 ::libvpx_test::Encoder *encoder) {
125 if (video->frame() == 1) {
126 encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
127 encoder->Control(VP9E_SET_TILE_COLUMNS, 4);
128 encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
129 if (encoding_mode_ != ::libvpx_test::kRealTime) {
130 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
131 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
132 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
133 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
134 }
135 }
136 }
137
GetAveragePsnr() const138 double GetAveragePsnr() const {
139 if (nframes_)
140 return psnr_ / nframes_;
141 return 0.0;
142 }
143
GetPsnrThreshold()144 double GetPsnrThreshold() {
145 return kPsnrThreshold[cpu_used_][encoding_mode_];
146 }
147
148 TestVideoParam test_video_param_;
149 int cpu_used_;
150
151 private:
152 double psnr_;
153 unsigned int nframes_;
154 libvpx_test::TestMode encoding_mode_;
155 };
156
TEST_P(EndToEndTestLarge,EndtoEndPSNRTest)157 TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) {
158 cfg_.rc_target_bitrate = kBitrate;
159 cfg_.g_error_resilient = 0;
160 cfg_.g_profile = test_video_param_.profile;
161 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
162 cfg_.g_bit_depth = test_video_param_.bit_depth;
163 init_flags_ = VPX_CODEC_USE_PSNR;
164 if (cfg_.g_bit_depth > 8)
165 init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
166
167 libvpx_test::VideoSource *video;
168 if (is_extension_y4m(test_video_param_.filename)) {
169 video = new libvpx_test::Y4mVideoSource(test_video_param_.filename,
170 0, kFrames);
171 } else {
172 video = new libvpx_test::YUVVideoSource(test_video_param_.filename,
173 test_video_param_.fmt,
174 kWidth, kHeight,
175 kFramerate, 1, 0, kFrames);
176 }
177
178 ASSERT_NO_FATAL_FAILURE(RunLoop(video));
179 const double psnr = GetAveragePsnr();
180 EXPECT_GT(psnr, GetPsnrThreshold());
181 delete(video);
182 }
183
184 VP9_INSTANTIATE_TEST_CASE(
185 EndToEndTestLarge,
186 ::testing::ValuesIn(kEncodingModeVectors),
187 ::testing::ValuesIn(kTestVectors),
188 ::testing::ValuesIn(kCpuUsedVectors));
189
190 #if CONFIG_VP9_HIGHBITDEPTH
191 # if CONFIG_VP10_ENCODER
192 // TODO(angiebird): many fail in high bitdepth mode.
193 INSTANTIATE_TEST_CASE_P(
194 DISABLED_VP10, EndToEndTestLarge,
195 ::testing::Combine(
196 ::testing::Values(static_cast<const libvpx_test::CodecFactory *>(
197 &libvpx_test::kVP10)),
198 ::testing::ValuesIn(kEncodingModeVectors),
199 ::testing::ValuesIn(kTestVectors),
200 ::testing::ValuesIn(kCpuUsedVectors)));
201 # endif // CONFIG_VP10_ENCODER
202 #else
203 VP10_INSTANTIATE_TEST_CASE(
204 EndToEndTestLarge,
205 ::testing::ValuesIn(kEncodingModeVectors),
206 ::testing::ValuesIn(kTestVectors),
207 ::testing::ValuesIn(kCpuUsedVectors));
208 #endif // CONFIG_VP9_HIGHBITDEPTH
209 } // namespace
210