2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
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.
13 #include "third_party/googletest/src/include/gtest/gtest.h"
15 #include "test/codec_factory.h"
16 #include "test/encode_test_driver.h"
17 #include "test/i420_video_source.h"
18 #include "test/util.h"
19 #include "test/y4m_video_source.h"
20 #include "test/yuv_video_source.h"
24 const unsigned int kWidth = 160;
25 const unsigned int kHeight = 90;
26 const unsigned int kFramerate = 50;
27 const unsigned int kFrames = 20;
28 const int kBitrate = 500;
29 // List of psnr thresholds for speed settings 0-7 and 5 encoding modes
30 const double kPsnrThreshold[][5] = {
31 { 36.0, 37.0, 37.0, 37.0, 37.0 }, { 35.0, 36.0, 36.0, 36.0, 36.0 },
32 { 34.0, 35.0, 35.0, 35.0, 35.0 }, { 33.0, 34.0, 34.0, 34.0, 34.0 },
33 { 32.0, 33.0, 33.0, 33.0, 33.0 }, { 28.0, 32.0, 32.0, 32.0, 32.0 },
34 { 28.4, 31.0, 31.0, 31.0, 31.0 }, { 27.5, 30.0, 30.0, 30.0, 30.0 },
39 unsigned int input_bit_depth;
41 vpx_bit_depth_t bit_depth;
45 const TestVideoParam kTestVectors[] = {
46 { "park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, VPX_BITS_8, 0 },
47 { "park_joy_90p_8_422.y4m", 8, VPX_IMG_FMT_I422, VPX_BITS_8, 1 },
48 { "park_joy_90p_8_444.y4m", 8, VPX_IMG_FMT_I444, VPX_BITS_8, 1 },
49 { "park_joy_90p_8_440.yuv", 8, VPX_IMG_FMT_I440, VPX_BITS_8, 1 },
50 #if CONFIG_VP9_HIGHBITDEPTH
51 { "park_joy_90p_10_420_20f.y4m", 10, VPX_IMG_FMT_I42016, VPX_BITS_10, 2 },
52 { "park_joy_90p_10_422_20f.y4m", 10, VPX_IMG_FMT_I42216, VPX_BITS_10, 3 },
53 { "park_joy_90p_10_444_20f.y4m", 10, VPX_IMG_FMT_I44416, VPX_BITS_10, 3 },
54 { "park_joy_90p_10_440.yuv", 10, VPX_IMG_FMT_I44016, VPX_BITS_10, 3 },
55 { "park_joy_90p_12_420_20f.y4m", 12, VPX_IMG_FMT_I42016, VPX_BITS_12, 2 },
56 { "park_joy_90p_12_422_20f.y4m", 12, VPX_IMG_FMT_I42216, VPX_BITS_12, 3 },
57 { "park_joy_90p_12_444_20f.y4m", 12, VPX_IMG_FMT_I44416, VPX_BITS_12, 3 },
58 { "park_joy_90p_12_440.yuv", 12, VPX_IMG_FMT_I44016, VPX_BITS_12, 3 },
59 #endif // CONFIG_VP9_HIGHBITDEPTH
62 const TestVideoParam kTestVectorsNv12[] = {
63 { "hantro_collage_w352h288_nv12.yuv", 8, VPX_IMG_FMT_NV12, VPX_BITS_8, 0 },
66 // Encoding modes tested
67 const libvpx_test::TestMode kEncodingModeVectors[] = {
68 ::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
69 ::libvpx_test::kRealTime
72 // Speed settings tested
73 const int kCpuUsedVectors[] = { 1, 2, 3, 5, 6, 7 };
75 int is_extension_y4m(const char *filename) {
76 const char *dot = strrchr(filename, '.');
77 if (!dot || dot == filename) {
80 return !strcmp(dot, ".y4m");
84 class EndToEndTestAdaptiveRDThresh
85 : public ::libvpx_test::EncoderTest,
86 public ::libvpx_test::CodecTestWith2Params<int, int> {
88 EndToEndTestAdaptiveRDThresh()
89 : EncoderTest(GET_PARAM(0)), cpu_used_start_(GET_PARAM(1)),
90 cpu_used_end_(GET_PARAM(2)) {}
92 virtual ~EndToEndTestAdaptiveRDThresh() {}
94 virtual void SetUp() {
96 SetMode(::libvpx_test::kRealTime);
97 cfg_.g_lag_in_frames = 0;
98 cfg_.rc_end_usage = VPX_CBR;
99 cfg_.rc_buf_sz = 1000;
100 cfg_.rc_buf_initial_sz = 500;
101 cfg_.rc_buf_optimal_sz = 600;
102 dec_cfg_.threads = 4;
105 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
106 ::libvpx_test::Encoder *encoder) {
107 if (video->frame() == 0) {
108 encoder->Control(VP8E_SET_CPUUSED, cpu_used_start_);
109 encoder->Control(VP9E_SET_ROW_MT, 1);
110 encoder->Control(VP9E_SET_TILE_COLUMNS, 2);
112 if (video->frame() == 100)
113 encoder->Control(VP8E_SET_CPUUSED, cpu_used_end_);
121 class EndToEndTestLarge
122 : public ::libvpx_test::EncoderTest,
123 public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode,
124 TestVideoParam, int> {
127 : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(2)),
128 cpu_used_(GET_PARAM(3)), psnr_(0.0), nframes_(0),
129 encoding_mode_(GET_PARAM(1)) {
134 virtual ~EndToEndTestLarge() {}
136 virtual void SetUp() {
138 SetMode(encoding_mode_);
139 if (encoding_mode_ != ::libvpx_test::kRealTime) {
140 cfg_.g_lag_in_frames = 5;
141 cfg_.rc_end_usage = VPX_VBR;
143 cfg_.g_lag_in_frames = 0;
144 cfg_.rc_end_usage = VPX_CBR;
145 cfg_.rc_buf_sz = 1000;
146 cfg_.rc_buf_initial_sz = 500;
147 cfg_.rc_buf_optimal_sz = 600;
149 dec_cfg_.threads = 4;
152 virtual void BeginPassHook(unsigned int) {
157 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
158 psnr_ += pkt->data.psnr.psnr[0];
162 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
163 ::libvpx_test::Encoder *encoder) {
164 if (video->frame() == 0) {
165 encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
166 encoder->Control(VP9E_SET_TILE_COLUMNS, 4);
167 encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
168 if (encoding_mode_ != ::libvpx_test::kRealTime) {
169 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
170 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
171 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
172 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
174 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_);
175 encoder->Control(VP9E_SET_AQ_MODE, cyclic_refresh_);
180 double GetAveragePsnr() const {
181 if (nframes_) return psnr_ / nframes_;
185 double GetPsnrThreshold() {
186 return kPsnrThreshold[cpu_used_][encoding_mode_];
189 TestVideoParam test_video_param_;
196 unsigned int nframes_;
197 libvpx_test::TestMode encoding_mode_;
200 #if CONFIG_VP9_DECODER
201 // The test parameters control VP9D_SET_LOOP_FILTER_OPT and the number of
203 class EndToEndTestLoopFilterThreading
204 : public ::libvpx_test::EncoderTest,
205 public ::libvpx_test::CodecTestWith2Params<bool, int> {
207 EndToEndTestLoopFilterThreading()
208 : EncoderTest(GET_PARAM(0)), use_loop_filter_opt_(GET_PARAM(1)) {}
210 virtual ~EndToEndTestLoopFilterThreading() {}
212 virtual void SetUp() {
214 SetMode(::libvpx_test::kRealTime);
216 cfg_.g_lag_in_frames = 0;
217 cfg_.rc_target_bitrate = 500;
218 cfg_.rc_end_usage = VPX_CBR;
219 cfg_.kf_min_dist = 1;
220 cfg_.kf_max_dist = 1;
221 dec_cfg_.threads = GET_PARAM(2);
224 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
225 ::libvpx_test::Encoder *encoder) {
226 if (video->frame() == 0) {
227 encoder->Control(VP8E_SET_CPUUSED, 8);
229 encoder->Control(VP9E_SET_TILE_COLUMNS, 4 - video->frame() % 5);
232 virtual void PreDecodeFrameHook(::libvpx_test::VideoSource *video,
233 ::libvpx_test::Decoder *decoder) {
234 if (video->frame() == 0) {
235 decoder->Control(VP9D_SET_LOOP_FILTER_OPT, use_loop_filter_opt_ ? 1 : 0);
240 const bool use_loop_filter_opt_;
242 #endif // CONFIG_VP9_DECODER
244 class EndToEndNV12 : public EndToEndTestLarge {};
246 TEST_P(EndToEndNV12, EndtoEndNV12Test) {
247 cfg_.rc_target_bitrate = kBitrate;
248 cfg_.g_error_resilient = 0;
249 cfg_.g_profile = test_video_param_.profile;
250 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
251 cfg_.g_bit_depth = test_video_param_.bit_depth;
252 init_flags_ = VPX_CODEC_USE_PSNR;
253 if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
255 std::unique_ptr<libvpx_test::VideoSource> video;
257 video.reset(new libvpx_test::YUVVideoSource(test_video_param_.filename,
258 test_video_param_.fmt, 352, 288,
260 ASSERT_NE(video.get(), nullptr);
262 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
265 TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) {
266 cfg_.rc_target_bitrate = kBitrate;
267 cfg_.g_error_resilient = 0;
268 cfg_.g_profile = test_video_param_.profile;
269 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
270 cfg_.g_bit_depth = test_video_param_.bit_depth;
271 init_flags_ = VPX_CODEC_USE_PSNR;
272 if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
274 std::unique_ptr<libvpx_test::VideoSource> video;
275 if (is_extension_y4m(test_video_param_.filename)) {
276 video.reset(new libvpx_test::Y4mVideoSource(test_video_param_.filename, 0,
279 video.reset(new libvpx_test::YUVVideoSource(
280 test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
281 kFramerate, 1, 0, kFrames));
283 ASSERT_NE(video.get(), nullptr);
285 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
286 const double psnr = GetAveragePsnr();
287 EXPECT_GT(psnr, GetPsnrThreshold());
290 TEST_P(EndToEndTestLarge, EndtoEndPSNRDenoiserAQTest) {
291 cfg_.rc_target_bitrate = kBitrate;
292 cfg_.g_error_resilient = 0;
293 cfg_.g_profile = test_video_param_.profile;
294 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
295 cfg_.g_bit_depth = test_video_param_.bit_depth;
296 init_flags_ = VPX_CODEC_USE_PSNR;
299 if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
301 std::unique_ptr<libvpx_test::VideoSource> video;
302 if (is_extension_y4m(test_video_param_.filename)) {
303 video.reset(new libvpx_test::Y4mVideoSource(test_video_param_.filename, 0,
306 video.reset(new libvpx_test::YUVVideoSource(
307 test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
308 kFramerate, 1, 0, kFrames));
310 ASSERT_NE(video.get(), nullptr);
312 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
313 const double psnr = GetAveragePsnr();
314 EXPECT_GT(psnr, GetPsnrThreshold());
317 TEST_P(EndToEndTestAdaptiveRDThresh, EndtoEndAdaptiveRDThreshRowMT) {
318 cfg_.rc_target_bitrate = kBitrate;
319 cfg_.g_error_resilient = 0;
321 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
324 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
327 #if CONFIG_VP9_DECODER
328 TEST_P(EndToEndTestLoopFilterThreading, TileCountChange) {
329 ::libvpx_test::RandomVideoSource video;
330 video.SetSize(4096, 2160);
333 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
335 #endif // CONFIG_VP9_DECODER
337 VP9_INSTANTIATE_TEST_SUITE(EndToEndTestLarge,
338 ::testing::ValuesIn(kEncodingModeVectors),
339 ::testing::ValuesIn(kTestVectors),
340 ::testing::ValuesIn(kCpuUsedVectors));
342 VP9_INSTANTIATE_TEST_SUITE(EndToEndNV12,
343 ::testing::Values(::libvpx_test::kRealTime),
344 ::testing::ValuesIn(kTestVectorsNv12),
345 ::testing::Values(6, 7, 8));
347 VP9_INSTANTIATE_TEST_SUITE(EndToEndTestAdaptiveRDThresh,
348 ::testing::Values(5, 6, 7), ::testing::Values(8, 9));
350 #if CONFIG_VP9_DECODER
351 VP9_INSTANTIATE_TEST_SUITE(EndToEndTestLoopFilterThreading, ::testing::Bool(),
352 ::testing::Range(2, 6));
353 #endif // CONFIG_VP9_DECODER