]> granicus.if.org Git - libvpx/blob - test/vp9_end_to_end_test.cc
Test decode and find mismatch in vp9 svc example encoder.
[libvpx] / test / vp9_end_to_end_test.cc
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 "memory"
12
13 #include "third_party/googletest/src/include/gtest/gtest.h"
14
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"
21
22 namespace {
23
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 },
35 };
36
37 typedef struct {
38   const char *filename;
39   unsigned int input_bit_depth;
40   vpx_img_fmt fmt;
41   vpx_bit_depth_t bit_depth;
42   unsigned int profile;
43 } TestVideoParam;
44
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
60 };
61
62 // Encoding modes tested
63 const libvpx_test::TestMode kEncodingModeVectors[] = {
64   ::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
65   ::libvpx_test::kRealTime
66 };
67
68 // Speed settings tested
69 const int kCpuUsedVectors[] = { 1, 2, 3, 5, 6, 7 };
70
71 int is_extension_y4m(const char *filename) {
72   const char *dot = strrchr(filename, '.');
73   if (!dot || dot == filename) {
74     return 0;
75   } else {
76     return !strcmp(dot, ".y4m");
77   }
78 }
79
80 class EndToEndTestAdaptiveRDThresh
81     : public ::libvpx_test::EncoderTest,
82       public ::libvpx_test::CodecTestWith2Params<int, int> {
83  protected:
84   EndToEndTestAdaptiveRDThresh()
85       : EncoderTest(GET_PARAM(0)), cpu_used_start_(GET_PARAM(1)),
86         cpu_used_end_(GET_PARAM(2)) {}
87
88   virtual ~EndToEndTestAdaptiveRDThresh() {}
89
90   virtual void SetUp() {
91     InitializeConfig();
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;
98     dec_cfg_.threads = 4;
99   }
100
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);
107     }
108     if (video->frame() == 100)
109       encoder->Control(VP8E_SET_CPUUSED, cpu_used_end_);
110   }
111
112  private:
113   int cpu_used_start_;
114   int cpu_used_end_;
115 };
116
117 class EndToEndTestLarge
118     : public ::libvpx_test::EncoderTest,
119       public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode,
120                                                  TestVideoParam, int> {
121  protected:
122   EndToEndTestLarge()
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)) {
126     cyclic_refresh_ = 0;
127     denoiser_on_ = 0;
128   }
129
130   virtual ~EndToEndTestLarge() {}
131
132   virtual void SetUp() {
133     InitializeConfig();
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;
138     } else {
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;
144     }
145     dec_cfg_.threads = 4;
146   }
147
148   virtual void BeginPassHook(unsigned int) {
149     psnr_ = 0.0;
150     nframes_ = 0;
151   }
152
153   virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
154     psnr_ += pkt->data.psnr.psnr[0];
155     nframes_++;
156   }
157
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);
169       } else {
170         encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_);
171         encoder->Control(VP9E_SET_AQ_MODE, cyclic_refresh_);
172       }
173     }
174   }
175
176   double GetAveragePsnr() const {
177     if (nframes_) return psnr_ / nframes_;
178     return 0.0;
179   }
180
181   double GetPsnrThreshold() {
182     return kPsnrThreshold[cpu_used_][encoding_mode_];
183   }
184
185   TestVideoParam test_video_param_;
186   int cpu_used_;
187   int cyclic_refresh_;
188   int denoiser_on_;
189
190  private:
191   double psnr_;
192   unsigned int nframes_;
193   libvpx_test::TestMode encoding_mode_;
194 };
195
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;
204
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,
208                                                 kFrames));
209   } else {
210     video.reset(new libvpx_test::YUVVideoSource(
211         test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
212         kFramerate, 1, 0, kFrames));
213   }
214   ASSERT_TRUE(video.get() != NULL);
215
216   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
217   const double psnr = GetAveragePsnr();
218   EXPECT_GT(psnr, GetPsnrThreshold());
219 }
220
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;
228   cyclic_refresh_ = 3;
229   denoiser_on_ = 1;
230   if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
231
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,
235                                                 kFrames));
236   } else {
237     video.reset(new libvpx_test::YUVVideoSource(
238         test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
239         kFramerate, 1, 0, kFrames));
240   }
241   ASSERT_TRUE(video.get() != NULL);
242
243   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
244   const double psnr = GetAveragePsnr();
245   EXPECT_GT(psnr, GetPsnrThreshold());
246 }
247
248 TEST_P(EndToEndTestAdaptiveRDThresh, EndtoEndAdaptiveRDThreshRowMT) {
249   cfg_.rc_target_bitrate = kBitrate;
250   cfg_.g_error_resilient = 0;
251   cfg_.g_threads = 2;
252   ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
253                                        0, 400);
254
255   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
256 }
257
258 VP9_INSTANTIATE_TEST_CASE(EndToEndTestLarge,
259                           ::testing::ValuesIn(kEncodingModeVectors),
260                           ::testing::ValuesIn(kTestVectors),
261                           ::testing::ValuesIn(kCpuUsedVectors));
262
263 VP9_INSTANTIATE_TEST_CASE(EndToEndTestAdaptiveRDThresh,
264                           ::testing::Values(5, 6, 7), ::testing::Values(8, 9));
265 }  // namespace