vp9[loongarch]: Optimize fdct4x4/8x8_lsx
[platform/upstream/libvpx.git] / 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 }, { 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 },
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 const TestVideoParam kTestVectorsNv12[] = {
63   { "hantro_collage_w352h288_nv12.yuv", 8, VPX_IMG_FMT_NV12, VPX_BITS_8, 0 },
64 };
65
66 // Encoding modes tested
67 const libvpx_test::TestMode kEncodingModeVectors[] = {
68   ::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
69   ::libvpx_test::kRealTime
70 };
71
72 // Speed settings tested
73 const int kCpuUsedVectors[] = { 1, 2, 3, 5, 6, 7 };
74
75 int is_extension_y4m(const char *filename) {
76   const char *dot = strrchr(filename, '.');
77   if (!dot || dot == filename) {
78     return 0;
79   } else {
80     return !strcmp(dot, ".y4m");
81   }
82 }
83
84 class EndToEndTestAdaptiveRDThresh
85     : public ::libvpx_test::EncoderTest,
86       public ::libvpx_test::CodecTestWith2Params<int, int> {
87  protected:
88   EndToEndTestAdaptiveRDThresh()
89       : EncoderTest(GET_PARAM(0)), cpu_used_start_(GET_PARAM(1)),
90         cpu_used_end_(GET_PARAM(2)) {}
91
92   virtual ~EndToEndTestAdaptiveRDThresh() {}
93
94   virtual void SetUp() {
95     InitializeConfig();
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;
103   }
104
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);
111     }
112     if (video->frame() == 100)
113       encoder->Control(VP8E_SET_CPUUSED, cpu_used_end_);
114   }
115
116  private:
117   int cpu_used_start_;
118   int cpu_used_end_;
119 };
120
121 class EndToEndTestLarge
122     : public ::libvpx_test::EncoderTest,
123       public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode,
124                                                  TestVideoParam, int> {
125  protected:
126   EndToEndTestLarge()
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)) {
130     cyclic_refresh_ = 0;
131     denoiser_on_ = 0;
132   }
133
134   virtual ~EndToEndTestLarge() {}
135
136   virtual void SetUp() {
137     InitializeConfig();
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;
142     } else {
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;
148     }
149     dec_cfg_.threads = 4;
150   }
151
152   virtual void BeginPassHook(unsigned int) {
153     psnr_ = 0.0;
154     nframes_ = 0;
155   }
156
157   virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) {
158     psnr_ += pkt->data.psnr.psnr[0];
159     nframes_++;
160   }
161
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);
173       } else {
174         encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_);
175         encoder->Control(VP9E_SET_AQ_MODE, cyclic_refresh_);
176       }
177     }
178   }
179
180   double GetAveragePsnr() const {
181     if (nframes_) return psnr_ / nframes_;
182     return 0.0;
183   }
184
185   double GetPsnrThreshold() {
186     return kPsnrThreshold[cpu_used_][encoding_mode_];
187   }
188
189   TestVideoParam test_video_param_;
190   int cpu_used_;
191   int cyclic_refresh_;
192   int denoiser_on_;
193
194  private:
195   double psnr_;
196   unsigned int nframes_;
197   libvpx_test::TestMode encoding_mode_;
198 };
199
200 #if CONFIG_VP9_DECODER
201 // The test parameters control VP9D_SET_LOOP_FILTER_OPT and the number of
202 // decoder threads.
203 class EndToEndTestLoopFilterThreading
204     : public ::libvpx_test::EncoderTest,
205       public ::libvpx_test::CodecTestWith2Params<bool, int> {
206  protected:
207   EndToEndTestLoopFilterThreading()
208       : EncoderTest(GET_PARAM(0)), use_loop_filter_opt_(GET_PARAM(1)) {}
209
210   virtual ~EndToEndTestLoopFilterThreading() {}
211
212   virtual void SetUp() {
213     InitializeConfig();
214     SetMode(::libvpx_test::kRealTime);
215     cfg_.g_threads = 2;
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);
222   }
223
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);
228     }
229     encoder->Control(VP9E_SET_TILE_COLUMNS, 4 - video->frame() % 5);
230   }
231
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);
236     }
237   }
238
239  private:
240   const bool use_loop_filter_opt_;
241 };
242 #endif  // CONFIG_VP9_DECODER
243
244 class EndToEndNV12 : public EndToEndTestLarge {};
245
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;
254
255   std::unique_ptr<libvpx_test::VideoSource> video;
256
257   video.reset(new libvpx_test::YUVVideoSource(test_video_param_.filename,
258                                               test_video_param_.fmt, 352, 288,
259                                               30, 1, 0, 100));
260   ASSERT_NE(video.get(), nullptr);
261
262   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
263 }
264
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;
273
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,
277                                                 kFrames));
278   } else {
279     video.reset(new libvpx_test::YUVVideoSource(
280         test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
281         kFramerate, 1, 0, kFrames));
282   }
283   ASSERT_NE(video.get(), nullptr);
284
285   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
286   const double psnr = GetAveragePsnr();
287   EXPECT_GT(psnr, GetPsnrThreshold());
288 }
289
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;
297   cyclic_refresh_ = 3;
298   denoiser_on_ = 1;
299   if (cfg_.g_bit_depth > 8) init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
300
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,
304                                                 kFrames));
305   } else {
306     video.reset(new libvpx_test::YUVVideoSource(
307         test_video_param_.filename, test_video_param_.fmt, kWidth, kHeight,
308         kFramerate, 1, 0, kFrames));
309   }
310   ASSERT_NE(video.get(), nullptr);
311
312   ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
313   const double psnr = GetAveragePsnr();
314   EXPECT_GT(psnr, GetPsnrThreshold());
315 }
316
317 TEST_P(EndToEndTestAdaptiveRDThresh, EndtoEndAdaptiveRDThreshRowMT) {
318   cfg_.rc_target_bitrate = kBitrate;
319   cfg_.g_error_resilient = 0;
320   cfg_.g_threads = 2;
321   ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
322                                        0, 400);
323
324   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
325 }
326
327 #if CONFIG_VP9_DECODER
328 TEST_P(EndToEndTestLoopFilterThreading, TileCountChange) {
329   ::libvpx_test::RandomVideoSource video;
330   video.SetSize(4096, 2160);
331   video.set_limit(10);
332
333   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
334 }
335 #endif  // CONFIG_VP9_DECODER
336
337 VP9_INSTANTIATE_TEST_SUITE(EndToEndTestLarge,
338                            ::testing::ValuesIn(kEncodingModeVectors),
339                            ::testing::ValuesIn(kTestVectors),
340                            ::testing::ValuesIn(kCpuUsedVectors));
341
342 VP9_INSTANTIATE_TEST_SUITE(EndToEndNV12,
343                            ::testing::Values(::libvpx_test::kRealTime),
344                            ::testing::ValuesIn(kTestVectorsNv12),
345                            ::testing::Values(6, 7, 8));
346
347 VP9_INSTANTIATE_TEST_SUITE(EndToEndTestAdaptiveRDThresh,
348                            ::testing::Values(5, 6, 7), ::testing::Values(8, 9));
349
350 #if CONFIG_VP9_DECODER
351 VP9_INSTANTIATE_TEST_SUITE(EndToEndTestLoopFilterThreading, ::testing::Bool(),
352                            ::testing::Range(2, 6));
353 #endif  // CONFIG_VP9_DECODER
354 }  // namespace