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 }, { 31.0, 32.0, 32.0, 32.0, 32.0 },
34 { 30.0, 31.0, 31.0, 31.0, 31.0 }, { 29.0, 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 // Encoding modes tested
63 const libvpx_test::TestMode kEncodingModeVectors[] = {
64 ::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
65 ::libvpx_test::kRealTime
68 // Speed settings tested
69 const int kCpuUsedVectors[] = { 1, 2, 3, 5, 6, 7 };
71 int is_extension_y4m(const char *filename) {
72 const char *dot = strrchr(filename, '.');
73 if (!dot || dot == filename) {
76 return !strcmp(dot, ".y4m");
80 class EndToEndTestAdaptiveRDThresh
81 : public ::libvpx_test::EncoderTest,
82 public ::libvpx_test::CodecTestWith2Params<int, int> {
84 EndToEndTestAdaptiveRDThresh()
85 : EncoderTest(GET_PARAM(0)), cpu_used_start_(GET_PARAM(1)),
86 cpu_used_end_(GET_PARAM(2)) {}
88 virtual ~EndToEndTestAdaptiveRDThresh() {}
90 virtual void SetUp() {
92 SetMode(::libvpx_test::kRealTime);
93 cfg_.g_lag_in_frames = 0;
94 cfg_.rc_end_usage = VPX_CBR;
95 cfg_.rc_buf_sz = 1000;
96 cfg_.rc_buf_initial_sz = 500;
97 cfg_.rc_buf_optimal_sz = 600;
101 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
102 ::libvpx_test::Encoder *encoder) {
103 if (video->frame() == 0) {
104 encoder->Control(VP8E_SET_CPUUSED, cpu_used_start_);
105 encoder->Control(VP9E_SET_ROW_MT, 1);
106 encoder->Control(VP9E_SET_TILE_COLUMNS, 2);
108 if (video->frame() == 100)
109 encoder->Control(VP8E_SET_CPUUSED, cpu_used_end_);
117 class EndToEndTestLarge
118 : public ::libvpx_test::EncoderTest,
119 public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode,
120 TestVideoParam, int> {
123 : EncoderTest(GET_PARAM(0)), test_video_param_(GET_PARAM(2)),
124 cpu_used_(GET_PARAM(3)), psnr_(0.0), nframes_(0),
125 encoding_mode_(GET_PARAM(1)) {
130 virtual ~EndToEndTestLarge() {}
132 virtual void SetUp() {
134 SetMode(encoding_mode_);
135 if (encoding_mode_ != ::libvpx_test::kRealTime) {
136 cfg_.g_lag_in_frames = 5;
137 cfg_.rc_end_usage = VPX_VBR;
139 cfg_.g_lag_in_frames = 0;
140 cfg_.rc_end_usage = VPX_CBR;
141 cfg_.rc_buf_sz = 1000;
142 cfg_.rc_buf_initial_sz = 500;
143 cfg_.rc_buf_optimal_sz = 600;
145 dec_cfg_.threads = 4;
148 virtual void BeginPassHook(unsigned int) {
153 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
154 psnr_ += pkt->data.psnr.psnr[0];
158 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
159 ::libvpx_test::Encoder *encoder) {
160 if (video->frame() == 0) {
161 encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
162 encoder->Control(VP9E_SET_TILE_COLUMNS, 4);
163 encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
164 if (encoding_mode_ != ::libvpx_test::kRealTime) {
165 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
166 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
167 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
168 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
170 encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_);
171 encoder->Control(VP9E_SET_AQ_MODE, cyclic_refresh_);
176 double GetAveragePsnr() const {
177 if (nframes_) return psnr_ / nframes_;
181 double GetPsnrThreshold() {
182 return kPsnrThreshold[cpu_used_][encoding_mode_];
185 TestVideoParam test_video_param_;
192 unsigned int nframes_;
193 libvpx_test::TestMode encoding_mode_;
196 TEST_P(EndToEndTestLarge, EndtoEndPSNRTest) {
197 cfg_.rc_target_bitrate = kBitrate;
198 cfg_.g_error_resilient = 0;
199 cfg_.g_profile = test_video_param_.profile;
200 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
201 cfg_.g_bit_depth = test_video_param_.bit_depth;
202 init_flags_ = VPX_CODEC_USE_PSNR;
203 if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
205 std::unique_ptr<libvpx_test::VideoSource> video;
206 if (is_extension_y4m(test_video_param_.filename)) {
207 video.reset(new libvpx_test::Y4mVideoSource(test_video_param_.filename, 0,
210 video.reset(new libvpx_test::YUVVideoSource(
211 test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
212 kFramerate, 1, 0, kFrames));
214 ASSERT_TRUE(video.get() != NULL);
216 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
217 const double psnr = GetAveragePsnr();
218 EXPECT_GT(psnr, GetPsnrThreshold());
221 TEST_P(EndToEndTestLarge, EndtoEndPSNRDenoiserAQTest) {
222 cfg_.rc_target_bitrate = kBitrate;
223 cfg_.g_error_resilient = 0;
224 cfg_.g_profile = test_video_param_.profile;
225 cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
226 cfg_.g_bit_depth = test_video_param_.bit_depth;
227 init_flags_ = VPX_CODEC_USE_PSNR;
230 if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
232 std::unique_ptr<libvpx_test::VideoSource> video;
233 if (is_extension_y4m(test_video_param_.filename)) {
234 video.reset(new libvpx_test::Y4mVideoSource(test_video_param_.filename, 0,
237 video.reset(new libvpx_test::YUVVideoSource(
238 test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
239 kFramerate, 1, 0, kFrames));
241 ASSERT_TRUE(video.get() != NULL);
243 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
244 const double psnr = GetAveragePsnr();
245 EXPECT_GT(psnr, GetPsnrThreshold());
248 TEST_P(EndToEndTestAdaptiveRDThresh, EndtoEndAdaptiveRDThreshRowMT) {
249 cfg_.rc_target_bitrate = kBitrate;
250 cfg_.g_error_resilient = 0;
252 ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
255 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
258 VP9_INSTANTIATE_TEST_CASE(EndToEndTestLarge,
259 ::testing::ValuesIn(kEncodingModeVectors),
260 ::testing::ValuesIn(kTestVectors),
261 ::testing::ValuesIn(kCpuUsedVectors));
263 VP9_INSTANTIATE_TEST_CASE(EndToEndTestAdaptiveRDThresh,
264 ::testing::Values(5, 6, 7), ::testing::Values(8, 9));