]> granicus.if.org Git - libvpx/blob - test/svc_end_to_end_test.cc
test/svc_*_test: fix SetConfig() signature
[libvpx] / test / svc_end_to_end_test.cc
1 /*
2  *  Copyright (c) 2018 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 #include "./vpx_config.h"
11 #include "third_party/googletest/src/include/gtest/gtest.h"
12 #include "test/codec_factory.h"
13 #include "test/encode_test_driver.h"
14 #include "test/i420_video_source.h"
15 #include "test/svc_test.h"
16 #include "test/util.h"
17 #include "test/y4m_video_source.h"
18 #include "vpx/vpx_codec.h"
19 #include "vpx_ports/bitops.h"
20
21 namespace {
22
23 // Params: Inter layer prediction modes.
24 class SyncFrameOnePassCbrSvc : public ::svc_test::OnePassCbrSvc,
25                                public ::libvpx_test::CodecTestWithParam<int> {
26  public:
27   SyncFrameOnePassCbrSvc()
28       : OnePassCbrSvc(GET_PARAM(0)), current_video_frame_(0),
29         frame_to_start_decode_(0), frame_to_sync_(0), mismatch_nframes_(0),
30         num_nonref_frames_(0), inter_layer_pred_mode_(GET_PARAM(1)),
31         decode_to_layer_before_sync_(-1), decode_to_layer_after_sync_(-1),
32         denoiser_on_(0), intra_only_test_(false) {
33     SetMode(::libvpx_test::kRealTime);
34     memset(&svc_layer_sync_, 0, sizeof(svc_layer_sync_));
35   }
36
37  protected:
38   virtual ~SyncFrameOnePassCbrSvc() {}
39
40   virtual void SetUp() {
41     InitializeConfig();
42     speed_setting_ = 7;
43   }
44
45   virtual bool DoDecode() const {
46     return current_video_frame_ >= frame_to_start_decode_;
47   }
48
49   virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
50                                   ::libvpx_test::Encoder *encoder) {
51     current_video_frame_ = video->frame();
52     PreEncodeFrameHookSetup(video, encoder);
53     if (video->frame() == 0) {
54       encoder->Control(VP9E_SET_SVC_INTER_LAYER_PRED, inter_layer_pred_mode_);
55       encoder->Control(VP9E_SET_NOISE_SENSITIVITY, denoiser_on_);
56       if (intra_only_test_)
57         // Decoder sets the color_space for Intra-only frames
58         // to BT_601 (see line 1810 in vp9_decodeframe.c).
59         // So set it here in these tess to avoid encoder-decoder
60         // mismatch check on color space setting.
61         encoder->Control(VP9E_SET_COLOR_SPACE, VPX_CS_BT_601);
62     }
63     if (video->frame() == frame_to_sync_) {
64       encoder->Control(VP9E_SET_SVC_SPATIAL_LAYER_SYNC, &svc_layer_sync_);
65     }
66   }
67
68 #if CONFIG_VP9_DECODER
69   virtual void PreDecodeFrameHook(::libvpx_test::VideoSource *video,
70                                   ::libvpx_test::Decoder *decoder) {
71     if (video->frame() < frame_to_sync_) {
72       if (decode_to_layer_before_sync_ >= 0)
73         decoder->Control(VP9_DECODE_SVC_SPATIAL_LAYER,
74                          decode_to_layer_before_sync_);
75     } else {
76       if (decode_to_layer_after_sync_ >= 0)
77         decoder->Control(VP9_DECODE_SVC_SPATIAL_LAYER,
78                          decode_to_layer_after_sync_);
79     }
80   }
81 #endif
82
83   virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
84     // Keep track of number of non-reference frames, needed for mismatch check.
85     // Non-reference frames are top spatial and temporal layer frames,
86     // for TL > 0.
87     if (temporal_layer_id_ == number_temporal_layers_ - 1 &&
88         temporal_layer_id_ > 0 &&
89         pkt->data.frame.spatial_layer_encoded[number_spatial_layers_ - 1] &&
90         current_video_frame_ >= frame_to_sync_)
91       num_nonref_frames_++;
92
93     if (intra_only_test_ && current_video_frame_ == frame_to_sync_) {
94       // Intra-only frame is only generated for spatial layers > 1 and <= 3,
95       // among other conditions (see constraint in set_intra_only_frame(). If
96       // intra-only is no allowed then encoder will insert key frame instead.
97       const bool key_frame =
98           (pkt->data.frame.flags & VPX_FRAME_IS_KEY) ? true : false;
99       if (number_spatial_layers_ == 1 || number_spatial_layers_ > 3)
100         ASSERT_TRUE(key_frame);
101       else
102         ASSERT_FALSE(key_frame);
103     }
104   }
105
106   virtual void MismatchHook(const vpx_image_t * /*img1*/,
107                             const vpx_image_t * /*img2*/) {
108     if (current_video_frame_ >= frame_to_sync_) ++mismatch_nframes_;
109   }
110
111   unsigned int GetMismatchFrames() const { return mismatch_nframes_; }
112
113   unsigned int current_video_frame_;
114   unsigned int frame_to_start_decode_;
115   unsigned int frame_to_sync_;
116   unsigned int mismatch_nframes_;
117   unsigned int num_nonref_frames_;
118   int inter_layer_pred_mode_;
119   int decode_to_layer_before_sync_;
120   int decode_to_layer_after_sync_;
121   int denoiser_on_;
122   bool intra_only_test_;
123   vpx_svc_spatial_layer_sync_t svc_layer_sync_;
124
125  private:
126   virtual void SetConfig(const int num_temporal_layer) {
127     cfg_.rc_buf_initial_sz = 500;
128     cfg_.rc_buf_optimal_sz = 500;
129     cfg_.rc_buf_sz = 1000;
130     cfg_.rc_min_quantizer = 0;
131     cfg_.rc_max_quantizer = 63;
132     cfg_.rc_end_usage = VPX_CBR;
133     cfg_.g_lag_in_frames = 0;
134     cfg_.g_error_resilient = 1;
135     cfg_.g_threads = 1;
136     cfg_.rc_dropframe_thresh = 30;
137     cfg_.kf_max_dist = 9999;
138     if (num_temporal_layer == 3) {
139       cfg_.ts_rate_decimator[0] = 4;
140       cfg_.ts_rate_decimator[1] = 2;
141       cfg_.ts_rate_decimator[2] = 1;
142       cfg_.temporal_layering_mode = 3;
143     } else if (num_temporal_layer == 2) {
144       cfg_.ts_rate_decimator[0] = 2;
145       cfg_.ts_rate_decimator[1] = 1;
146       cfg_.temporal_layering_mode = 2;
147     } else if (num_temporal_layer == 1) {
148       cfg_.ts_rate_decimator[0] = 1;
149       cfg_.temporal_layering_mode = 1;
150     }
151   }
152 };
153
154 // Test for sync layer for 1 pass CBR SVC: 3 spatial layers and
155 // 3 temporal layers. Only start decoding on the sync layer.
156 // Full sync: insert key frame on base layer.
157 TEST_P(SyncFrameOnePassCbrSvc, OnePassCbrSvc3SL3TLFullSync) {
158   SetSvcConfig(3, 3);
159   // Sync is on base layer so the frame to sync and the frame to start decoding
160   // is the same.
161   frame_to_start_decode_ = 20;
162   frame_to_sync_ = 20;
163   decode_to_layer_before_sync_ = -1;
164   decode_to_layer_after_sync_ = 2;
165
166   // Set up svc layer sync structure.
167   svc_layer_sync_.base_layer_intra_only = 0;
168   svc_layer_sync_.spatial_layer_sync[0] = 1;
169
170   ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
171
172   cfg_.rc_target_bitrate = 600;
173   AssignLayerBitrates();
174   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
175 #if CONFIG_VP9_DECODER
176   // The non-reference frames are expected to be mismatched frames as the
177   // encoder will avoid loopfilter on these frames.
178   EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
179 #endif
180 }
181
182 // Test for sync layer for 1 pass CBR SVC: 2 spatial layers and
183 // 3 temporal layers. Decoding QVGA before sync frame and decode up to
184 // VGA on and after sync.
185 TEST_P(SyncFrameOnePassCbrSvc, OnePassCbrSvc2SL3TLSyncToVGA) {
186   SetSvcConfig(2, 3);
187   frame_to_start_decode_ = 0;
188   frame_to_sync_ = 100;
189   decode_to_layer_before_sync_ = 0;
190   decode_to_layer_after_sync_ = 1;
191
192   // Set up svc layer sync structure.
193   svc_layer_sync_.base_layer_intra_only = 0;
194   svc_layer_sync_.spatial_layer_sync[0] = 0;
195   svc_layer_sync_.spatial_layer_sync[1] = 1;
196
197   ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
198                                        0, 400);
199   cfg_.rc_target_bitrate = 400;
200   AssignLayerBitrates();
201   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
202 #if CONFIG_VP9_DECODER
203   // The non-reference frames are expected to be mismatched frames as the
204   // encoder will avoid loopfilter on these frames.
205   EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
206 #endif
207 }
208
209 // Test for sync layer for 1 pass CBR SVC: 3 spatial layers and
210 // 3 temporal layers. Decoding QVGA and VGA before sync frame and decode up to
211 // HD on and after sync.
212 TEST_P(SyncFrameOnePassCbrSvc, OnePassCbrSvc3SL3TLSyncToHD) {
213   SetSvcConfig(3, 3);
214   frame_to_start_decode_ = 0;
215   frame_to_sync_ = 20;
216   decode_to_layer_before_sync_ = 1;
217   decode_to_layer_after_sync_ = 2;
218
219   // Set up svc layer sync structure.
220   svc_layer_sync_.base_layer_intra_only = 0;
221   svc_layer_sync_.spatial_layer_sync[0] = 0;
222   svc_layer_sync_.spatial_layer_sync[1] = 0;
223   svc_layer_sync_.spatial_layer_sync[2] = 1;
224
225   ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
226   cfg_.rc_target_bitrate = 600;
227   AssignLayerBitrates();
228   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
229 #if CONFIG_VP9_DECODER
230   // The non-reference frames are expected to be mismatched frames as the
231   // encoder will avoid loopfilter on these frames.
232   EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
233 #endif
234 }
235
236 // Test for sync layer for 1 pass CBR SVC: 3 spatial layers and
237 // 3 temporal layers. Decoding QVGA before sync frame and decode up to
238 // HD on and after sync.
239 TEST_P(SyncFrameOnePassCbrSvc, OnePassCbrSvc3SL3TLSyncToVGAHD) {
240   SetSvcConfig(3, 3);
241   frame_to_start_decode_ = 0;
242   frame_to_sync_ = 20;
243   decode_to_layer_before_sync_ = 0;
244   decode_to_layer_after_sync_ = 2;
245
246   // Set up svc layer sync structure.
247   svc_layer_sync_.base_layer_intra_only = 0;
248   svc_layer_sync_.spatial_layer_sync[0] = 0;
249   svc_layer_sync_.spatial_layer_sync[1] = 1;
250   svc_layer_sync_.spatial_layer_sync[2] = 1;
251
252   ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
253   cfg_.rc_target_bitrate = 600;
254   AssignLayerBitrates();
255   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
256 #if CONFIG_VP9_DECODER
257   // The non-reference frames are expected to be mismatched frames as the
258   // encoder will avoid loopfilter on these frames.
259   EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
260 #endif
261 }
262
263 #if CONFIG_VP9_TEMPORAL_DENOISING
264 // Test for sync layer for 1 pass CBR SVC: 2 spatial layers and
265 // 3 temporal layers. Decoding QVGA before sync frame and decode up to
266 // VGA on and after sync.
267 TEST_P(SyncFrameOnePassCbrSvc, OnePassCbrSvc2SL3TLSyncFrameVGADenoise) {
268   SetSvcConfig(2, 3);
269   frame_to_start_decode_ = 0;
270   frame_to_sync_ = 100;
271   decode_to_layer_before_sync_ = 0;
272   decode_to_layer_after_sync_ = 1;
273
274   denoiser_on_ = 1;
275   // Set up svc layer sync structure.
276   svc_layer_sync_.base_layer_intra_only = 0;
277   svc_layer_sync_.spatial_layer_sync[0] = 0;
278   svc_layer_sync_.spatial_layer_sync[1] = 1;
279
280   ::libvpx_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
281                                        0, 400);
282   cfg_.rc_target_bitrate = 400;
283   AssignLayerBitrates();
284   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
285 #if CONFIG_VP9_DECODER
286   // The non-reference frames are expected to be mismatched frames as the
287   // encoder will avoid loopfilter on these frames.
288   EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
289 #endif
290 }
291 #endif
292
293 // Start decoding from beginning of sequence, during sequence insert intra-only
294 // on base/qvga layer. Decode all layers.
295 TEST_P(SyncFrameOnePassCbrSvc, OnePassCbrSvc3SL3TLSyncFrameIntraOnlyQVGA) {
296   SetSvcConfig(3, 3);
297   frame_to_start_decode_ = 0;
298   frame_to_sync_ = 20;
299   decode_to_layer_before_sync_ = 2;
300   // The superframe containing intra-only layer will have 4 frames. Thus set the
301   // layer to decode after sync frame to 3.
302   decode_to_layer_after_sync_ = 3;
303   intra_only_test_ = true;
304
305   // Set up svc layer sync structure.
306   svc_layer_sync_.base_layer_intra_only = 1;
307   svc_layer_sync_.spatial_layer_sync[0] = 1;
308   svc_layer_sync_.spatial_layer_sync[1] = 0;
309   svc_layer_sync_.spatial_layer_sync[2] = 0;
310
311   ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
312   cfg_.rc_target_bitrate = 600;
313   AssignLayerBitrates();
314   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
315 #if CONFIG_VP9_DECODER
316   // The non-reference frames are expected to be mismatched frames as the
317   // encoder will avoid loopfilter on these frames.
318   EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
319 #endif
320 }
321
322 // Start decoding from beginning of sequence, during sequence insert intra-only
323 // on base/qvga layer and sync_layer on middle/VGA layer. Decode all layers.
324 TEST_P(SyncFrameOnePassCbrSvc, OnePassCbrSvc3SL3TLSyncFrameIntraOnlyVGA) {
325   SetSvcConfig(3, 3);
326   frame_to_start_decode_ = 0;
327   frame_to_sync_ = 20;
328   decode_to_layer_before_sync_ = 2;
329   // The superframe containing intra-only layer will have 4 frames. Thus set the
330   // layer to decode after sync frame to 3.
331   decode_to_layer_after_sync_ = 3;
332   intra_only_test_ = true;
333
334   // Set up svc layer sync structure.
335   svc_layer_sync_.base_layer_intra_only = 1;
336   svc_layer_sync_.spatial_layer_sync[0] = 1;
337   svc_layer_sync_.spatial_layer_sync[1] = 1;
338   svc_layer_sync_.spatial_layer_sync[2] = 0;
339
340   ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
341   cfg_.rc_target_bitrate = 600;
342   AssignLayerBitrates();
343   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
344 #if CONFIG_VP9_DECODER
345   // The non-reference frames are expected to be mismatched frames as the
346   // encoder will avoid loopfilter on these frames.
347   EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
348 #endif
349 }
350
351 // Start decoding from sync frame, insert intra-only on base/qvga layer. Decode
352 // all layers. For 1 spatial layer, it inserts a key frame.
353 TEST_P(SyncFrameOnePassCbrSvc, OnePassCbrSvc1SL3TLSyncFrameIntraOnlyQVGA) {
354   SetSvcConfig(1, 3);
355   frame_to_start_decode_ = 20;
356   frame_to_sync_ = 20;
357   decode_to_layer_before_sync_ = 0;
358   decode_to_layer_after_sync_ = 0;
359   intra_only_test_ = true;
360
361   // Set up svc layer sync structure.
362   svc_layer_sync_.base_layer_intra_only = 1;
363   svc_layer_sync_.spatial_layer_sync[0] = 1;
364
365   ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
366   cfg_.rc_target_bitrate = 600;
367   AssignLayerBitrates();
368   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
369 #if CONFIG_VP9_DECODER
370   // The non-reference frames are expected to be mismatched frames as the
371   // encoder will avoid loopfilter on these frames.
372   EXPECT_EQ(num_nonref_frames_, GetMismatchFrames());
373 #endif
374 }
375
376 VP9_INSTANTIATE_TEST_CASE(SyncFrameOnePassCbrSvc, ::testing::Range(0, 3));
377
378 }  // namespace