xref: /aosp_15_r20/external/libvpx/test/error_resilience_test.cc (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
1 /*
2  *  Copyright (c) 2013 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 "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/util.h"
16 #include "vpx_config.h"
17 
18 namespace {
19 
20 const int kMaxErrorFrames = 12;
21 const int kMaxDroppableFrames = 12;
22 
23 class ErrorResilienceTestLarge
24     : public ::libvpx_test::EncoderTest,
25       public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, bool> {
26  protected:
ErrorResilienceTestLarge()27   ErrorResilienceTestLarge()
28       : EncoderTest(GET_PARAM(0)), svc_support_(GET_PARAM(2)), psnr_(0.0),
29         nframes_(0), mismatch_psnr_(0.0), mismatch_nframes_(0),
30         encoding_mode_(GET_PARAM(1)) {
31     Reset();
32   }
33 
34   ~ErrorResilienceTestLarge() override = default;
35 
Reset()36   void Reset() {
37     error_nframes_ = 0;
38     droppable_nframes_ = 0;
39     pattern_switch_ = 0;
40   }
41 
SetUp()42   void SetUp() override {
43     InitializeConfig();
44     SetMode(encoding_mode_);
45   }
46 
BeginPassHook(unsigned int)47   void BeginPassHook(unsigned int /*pass*/) override {
48     psnr_ = 0.0;
49     nframes_ = 0;
50     mismatch_psnr_ = 0.0;
51     mismatch_nframes_ = 0;
52   }
53 
PSNRPktHook(const vpx_codec_cx_pkt_t * pkt)54   void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) override {
55     psnr_ += pkt->data.psnr.psnr[0];
56     nframes_++;
57   }
58 
59   //
60   // Frame flags and layer id for temporal layers.
61   // For two layers, test pattern is:
62   //   1     3
63   // 0    2     .....
64   // LAST is updated on base/layer 0, GOLDEN  updated on layer 1.
65   // Non-zero pattern_switch parameter means pattern will switch to
66   // not using LAST for frame_num >= pattern_switch.
SetFrameFlags(int frame_num,int num_temp_layers,int pattern_switch)67   int SetFrameFlags(int frame_num, int num_temp_layers, int pattern_switch) {
68     int frame_flags = 0;
69     if (num_temp_layers == 2) {
70       if (frame_num % 2 == 0) {
71         if (frame_num < pattern_switch || pattern_switch == 0) {
72           // Layer 0: predict from LAST and ARF, update LAST.
73           frame_flags =
74               VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
75         } else {
76           // Layer 0: predict from GF and ARF, update GF.
77           frame_flags = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_UPD_LAST |
78                         VP8_EFLAG_NO_UPD_ARF;
79         }
80       } else {
81         if (frame_num < pattern_switch || pattern_switch == 0) {
82           // Layer 1: predict from L, GF, and ARF, update GF.
83           frame_flags = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST;
84         } else {
85           // Layer 1: predict from GF and ARF, update GF.
86           frame_flags = VP8_EFLAG_NO_REF_LAST | VP8_EFLAG_NO_UPD_LAST |
87                         VP8_EFLAG_NO_UPD_ARF;
88         }
89       }
90     }
91     return frame_flags;
92   }
93 
PreEncodeFrameHook(libvpx_test::VideoSource * video)94   void PreEncodeFrameHook(libvpx_test::VideoSource *video) override {
95     frame_flags_ &=
96         ~(VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF);
97     // For temporal layer case.
98     if (cfg_.ts_number_layers > 1) {
99       frame_flags_ =
100           SetFrameFlags(video->frame(), cfg_.ts_number_layers, pattern_switch_);
101       for (unsigned int i = 0; i < droppable_nframes_; ++i) {
102         if (droppable_frames_[i] == video->frame()) {
103           std::cout << "Encoding droppable frame: " << droppable_frames_[i]
104                     << "\n";
105         }
106       }
107     } else {
108       if (droppable_nframes_ > 0 &&
109           (cfg_.g_pass == VPX_RC_LAST_PASS || cfg_.g_pass == VPX_RC_ONE_PASS)) {
110         for (unsigned int i = 0; i < droppable_nframes_; ++i) {
111           if (droppable_frames_[i] == video->frame()) {
112             std::cout << "Encoding droppable frame: " << droppable_frames_[i]
113                       << "\n";
114             frame_flags_ |= (VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_UPD_GF |
115                              VP8_EFLAG_NO_UPD_ARF);
116             return;
117           }
118         }
119       }
120     }
121   }
122 
GetAveragePsnr() const123   double GetAveragePsnr() const {
124     if (nframes_) return psnr_ / nframes_;
125     return 0.0;
126   }
127 
GetAverageMismatchPsnr() const128   double GetAverageMismatchPsnr() const {
129     if (mismatch_nframes_) return mismatch_psnr_ / mismatch_nframes_;
130     return 0.0;
131   }
132 
DoDecode() const133   bool DoDecode() const override {
134     if (error_nframes_ > 0 &&
135         (cfg_.g_pass == VPX_RC_LAST_PASS || cfg_.g_pass == VPX_RC_ONE_PASS)) {
136       for (unsigned int i = 0; i < error_nframes_; ++i) {
137         if (error_frames_[i] == nframes_ - 1) {
138           std::cout << "             Skipping decoding frame: "
139                     << error_frames_[i] << "\n";
140           return false;
141         }
142       }
143     }
144     return true;
145   }
146 
MismatchHook(const vpx_image_t * img1,const vpx_image_t * img2)147   void MismatchHook(const vpx_image_t *img1, const vpx_image_t *img2) override {
148     double mismatch_psnr = compute_psnr(img1, img2);
149     mismatch_psnr_ += mismatch_psnr;
150     ++mismatch_nframes_;
151     // std::cout << "Mismatch frame psnr: " << mismatch_psnr << "\n";
152   }
153 
SetErrorFrames(int num,unsigned int * list)154   void SetErrorFrames(int num, unsigned int *list) {
155     if (num > kMaxErrorFrames) {
156       num = kMaxErrorFrames;
157     } else if (num < 0) {
158       num = 0;
159     }
160     error_nframes_ = num;
161     for (unsigned int i = 0; i < error_nframes_; ++i) {
162       error_frames_[i] = list[i];
163     }
164   }
165 
SetDroppableFrames(int num,unsigned int * list)166   void SetDroppableFrames(int num, unsigned int *list) {
167     if (num > kMaxDroppableFrames) {
168       num = kMaxDroppableFrames;
169     } else if (num < 0) {
170       num = 0;
171     }
172     droppable_nframes_ = num;
173     for (unsigned int i = 0; i < droppable_nframes_; ++i) {
174       droppable_frames_[i] = list[i];
175     }
176   }
177 
GetMismatchFrames()178   unsigned int GetMismatchFrames() { return mismatch_nframes_; }
179 
SetPatternSwitch(int frame_switch)180   void SetPatternSwitch(int frame_switch) { pattern_switch_ = frame_switch; }
181 
182   bool svc_support_;
183 
184  private:
185   double psnr_;
186   unsigned int nframes_;
187   unsigned int error_nframes_;
188   unsigned int droppable_nframes_;
189   unsigned int pattern_switch_;
190   double mismatch_psnr_;
191   unsigned int mismatch_nframes_;
192   unsigned int error_frames_[kMaxErrorFrames];
193   unsigned int droppable_frames_[kMaxDroppableFrames];
194   libvpx_test::TestMode encoding_mode_;
195 };
196 
TEST_P(ErrorResilienceTestLarge,OnVersusOff)197 TEST_P(ErrorResilienceTestLarge, OnVersusOff) {
198 #if CONFIG_REALTIME_ONLY
199   GTEST_SKIP()
200       << "Non-zero g_lag_in_frames is unsupported with CONFIG_REALTIME_ONLY";
201 #else
202   const vpx_rational timebase = { 33333333, 1000000000 };
203   cfg_.g_timebase = timebase;
204   cfg_.rc_target_bitrate = 2000;
205   cfg_.g_lag_in_frames = 10;
206 
207   init_flags_ = VPX_CODEC_USE_PSNR;
208 
209   libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
210                                      timebase.den, timebase.num, 0, 30);
211 
212   // Error resilient mode OFF.
213   cfg_.g_error_resilient = 0;
214   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
215   const double psnr_resilience_off = GetAveragePsnr();
216   EXPECT_GT(psnr_resilience_off, 25.0);
217 
218   // Error resilient mode ON.
219   cfg_.g_error_resilient = 1;
220   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
221   const double psnr_resilience_on = GetAveragePsnr();
222   EXPECT_GT(psnr_resilience_on, 25.0);
223 
224   // Test that turning on error resilient mode hurts by 10% at most.
225   if (psnr_resilience_off > 0.0) {
226     const double psnr_ratio = psnr_resilience_on / psnr_resilience_off;
227     EXPECT_GE(psnr_ratio, 0.9);
228     EXPECT_LE(psnr_ratio, 1.1);
229   }
230 #endif  // CONFIG_REALTIME_ONLY
231 }
232 
233 // Check for successful decoding and no encoder/decoder mismatch
234 // if we lose (i.e., drop before decoding) a set of droppable
235 // frames (i.e., frames that don't update any reference buffers).
236 // Check both isolated and consecutive loss.
TEST_P(ErrorResilienceTestLarge,DropFramesWithoutRecovery)237 TEST_P(ErrorResilienceTestLarge, DropFramesWithoutRecovery) {
238   const vpx_rational timebase = { 33333333, 1000000000 };
239   cfg_.g_timebase = timebase;
240   cfg_.rc_target_bitrate = 500;
241   // FIXME(debargha): Fix this to work for any lag.
242   // Currently this test only works for lag = 0
243   cfg_.g_lag_in_frames = 0;
244 
245   init_flags_ = VPX_CODEC_USE_PSNR;
246 
247   libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
248                                      timebase.den, timebase.num, 0, 40);
249 
250   // Error resilient mode ON.
251   cfg_.g_error_resilient = 1;
252   cfg_.kf_mode = VPX_KF_DISABLED;
253 
254   // Set an arbitrary set of error frames same as droppable frames.
255   // In addition to isolated loss/drop, add a long consecutive series
256   // (of size 9) of dropped frames.
257   unsigned int num_droppable_frames = 11;
258   unsigned int droppable_frame_list[] = { 5,  16, 22, 23, 24, 25,
259                                           26, 27, 28, 29, 30 };
260   SetDroppableFrames(num_droppable_frames, droppable_frame_list);
261   SetErrorFrames(num_droppable_frames, droppable_frame_list);
262   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
263   // Test that no mismatches have been found
264   std::cout << "             Mismatch frames: " << GetMismatchFrames() << "\n";
265   EXPECT_EQ(GetMismatchFrames(), (unsigned int)0);
266 
267   // Reset previously set of error/droppable frames.
268   Reset();
269 
270 #if 0
271   // TODO(jkoleszar): This test is disabled for the time being as too
272   // sensitive. It's not clear how to set a reasonable threshold for
273   // this behavior.
274 
275   // Now set an arbitrary set of error frames that are non-droppable
276   unsigned int num_error_frames = 3;
277   unsigned int error_frame_list[] = {3, 10, 20};
278   SetErrorFrames(num_error_frames, error_frame_list);
279   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
280 
281   // Test that dropping an arbitrary set of inter frames does not hurt too much
282   // Note the Average Mismatch PSNR is the average of the PSNR between
283   // decoded frame and encoder's version of the same frame for all frames
284   // with mismatch.
285   const double psnr_resilience_mismatch = GetAverageMismatchPsnr();
286   std::cout << "             Mismatch PSNR: "
287             << psnr_resilience_mismatch << "\n";
288   EXPECT_GT(psnr_resilience_mismatch, 20.0);
289 #endif
290 }
291 
292 // Check for successful decoding and no encoder/decoder mismatch
293 // if we lose (i.e., drop before decoding) the enhancement layer frames for a
294 // two layer temporal pattern. The base layer does not predict from the top
295 // layer, so successful decoding is expected.
296 TEST_P(ErrorResilienceTestLarge, 2LayersDropEnhancement) {
297   // This test doesn't run if SVC is not supported.
298   if (!svc_support_) return;
299 
300   const vpx_rational timebase = { 33333333, 1000000000 };
301   cfg_.g_timebase = timebase;
302   cfg_.rc_target_bitrate = 500;
303   cfg_.g_lag_in_frames = 0;
304 
305   cfg_.rc_end_usage = VPX_CBR;
306   // 2 Temporal layers, no spatial layers, CBR mode.
307   cfg_.ss_number_layers = 1;
308   cfg_.ts_number_layers = 2;
309   cfg_.ts_rate_decimator[0] = 2;
310   cfg_.ts_rate_decimator[1] = 1;
311   cfg_.ts_periodicity = 2;
312   cfg_.ts_target_bitrate[0] = 60 * cfg_.rc_target_bitrate / 100;
313   cfg_.ts_target_bitrate[1] = cfg_.rc_target_bitrate;
314 
315   init_flags_ = VPX_CODEC_USE_PSNR;
316 
317   libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
318                                      timebase.den, timebase.num, 0, 40);
319 
320   // Error resilient mode ON.
321   cfg_.g_error_resilient = 1;
322   cfg_.kf_mode = VPX_KF_DISABLED;
323   SetPatternSwitch(0);
324 
325   // The odd frames are the enhancement layer for 2 layer pattern, so set
326   // those frames as droppable. Drop the last 7 frames.
327   unsigned int num_droppable_frames = 7;
328   unsigned int droppable_frame_list[] = { 27, 29, 31, 33, 35, 37, 39 };
329   SetDroppableFrames(num_droppable_frames, droppable_frame_list);
330   SetErrorFrames(num_droppable_frames, droppable_frame_list);
331   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
332   // Test that no mismatches have been found
333   std::cout << "             Mismatch frames: " << GetMismatchFrames() << "\n";
334   EXPECT_EQ(GetMismatchFrames(), (unsigned int)0);
335 
336   // Reset previously set of error/droppable frames.
337   Reset();
338 }
339 
340 // Check for successful decoding and no encoder/decoder mismatch
341 // for a two layer temporal pattern, where at some point in the
342 // sequence, the LAST ref is not used anymore.
343 TEST_P(ErrorResilienceTestLarge, 2LayersNoRefLast) {
344   // This test doesn't run if SVC is not supported.
345   if (!svc_support_) return;
346 
347   const vpx_rational timebase = { 33333333, 1000000000 };
348   cfg_.g_timebase = timebase;
349   cfg_.rc_target_bitrate = 500;
350   cfg_.g_lag_in_frames = 0;
351 
352   cfg_.rc_end_usage = VPX_CBR;
353   // 2 Temporal layers, no spatial layers, CBR mode.
354   cfg_.ss_number_layers = 1;
355   cfg_.ts_number_layers = 2;
356   cfg_.ts_rate_decimator[0] = 2;
357   cfg_.ts_rate_decimator[1] = 1;
358   cfg_.ts_periodicity = 2;
359   cfg_.ts_target_bitrate[0] = 60 * cfg_.rc_target_bitrate / 100;
360   cfg_.ts_target_bitrate[1] = cfg_.rc_target_bitrate;
361 
362   init_flags_ = VPX_CODEC_USE_PSNR;
363 
364   libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
365                                      timebase.den, timebase.num, 0, 100);
366 
367   // Error resilient mode ON.
368   cfg_.g_error_resilient = 1;
369   cfg_.kf_mode = VPX_KF_DISABLED;
370   SetPatternSwitch(60);
371 
372   ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
373   // Test that no mismatches have been found
374   std::cout << "             Mismatch frames: " << GetMismatchFrames() << "\n";
375   EXPECT_EQ(GetMismatchFrames(), (unsigned int)0);
376 
377   // Reset previously set of error/droppable frames.
378   Reset();
379 }
380 
381 class ErrorResilienceTestLargeCodecControls
382     : public ::libvpx_test::EncoderTest,
383       public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> {
384  protected:
ErrorResilienceTestLargeCodecControls()385   ErrorResilienceTestLargeCodecControls()
386       : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)) {
387     Reset();
388   }
389 
390   ~ErrorResilienceTestLargeCodecControls() override = default;
391 
Reset()392   void Reset() {
393     last_pts_ = 0;
394     tot_frame_number_ = 0;
395     // For testing up to 3 layers.
396     for (int i = 0; i < 3; ++i) {
397       bits_total_[i] = 0;
398     }
399     duration_ = 0.0;
400   }
401 
SetUp()402   void SetUp() override {
403     InitializeConfig();
404     SetMode(encoding_mode_);
405   }
406 
407   //
408   // Frame flags and layer id for temporal layers.
409   //
410 
411   // For two layers, test pattern is:
412   //   1     3
413   // 0    2     .....
414   // For three layers, test pattern is:
415   //   1      3    5      7
416   //      2           6
417   // 0          4            ....
418   // LAST is always update on base/layer 0, GOLDEN is updated on layer 1,
419   // and ALTREF is updated on top layer for 3 layer pattern.
SetFrameFlags(int frame_num,int num_temp_layers)420   int SetFrameFlags(int frame_num, int num_temp_layers) {
421     int frame_flags = 0;
422     if (num_temp_layers == 2) {
423       if (frame_num % 2 == 0) {
424         // Layer 0: predict from L and ARF, update L.
425         frame_flags =
426             VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF;
427       } else {
428         // Layer 1: predict from L, G and ARF, and update G.
429         frame_flags = VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST |
430                       VP8_EFLAG_NO_UPD_ENTROPY;
431       }
432     } else if (num_temp_layers == 3) {
433       if (frame_num % 4 == 0) {
434         // Layer 0: predict from L, update L.
435         frame_flags = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_ARF |
436                       VP8_EFLAG_NO_REF_GF | VP8_EFLAG_NO_REF_ARF;
437       } else if ((frame_num - 2) % 4 == 0) {
438         // Layer 1: predict from L, G,  update G.
439         frame_flags =
440             VP8_EFLAG_NO_UPD_ARF | VP8_EFLAG_NO_UPD_LAST | VP8_EFLAG_NO_REF_ARF;
441       } else if ((frame_num - 1) % 2 == 0) {
442         // Layer 2: predict from L, G, ARF; update ARG.
443         frame_flags = VP8_EFLAG_NO_UPD_GF | VP8_EFLAG_NO_UPD_LAST;
444       }
445     }
446     return frame_flags;
447   }
448 
SetLayerId(int frame_num,int num_temp_layers)449   int SetLayerId(int frame_num, int num_temp_layers) {
450     int layer_id = 0;
451     if (num_temp_layers == 2) {
452       if (frame_num % 2 == 0) {
453         layer_id = 0;
454       } else {
455         layer_id = 1;
456       }
457     } else if (num_temp_layers == 3) {
458       if (frame_num % 4 == 0) {
459         layer_id = 0;
460       } else if ((frame_num - 2) % 4 == 0) {
461         layer_id = 1;
462       } else if ((frame_num - 1) % 2 == 0) {
463         layer_id = 2;
464       }
465     }
466     return layer_id;
467   }
468 
PreEncodeFrameHook(libvpx_test::VideoSource * video,libvpx_test::Encoder * encoder)469   void PreEncodeFrameHook(libvpx_test::VideoSource *video,
470                           libvpx_test::Encoder *encoder) override {
471     if (cfg_.ts_number_layers > 1) {
472       int layer_id = SetLayerId(video->frame(), cfg_.ts_number_layers);
473       int frame_flags = SetFrameFlags(video->frame(), cfg_.ts_number_layers);
474       if (video->frame() > 0) {
475         encoder->Control(VP8E_SET_TEMPORAL_LAYER_ID, layer_id);
476         encoder->Control(VP8E_SET_FRAME_FLAGS, frame_flags);
477       }
478       const vpx_rational_t tb = video->timebase();
479       timebase_ = static_cast<double>(tb.num) / tb.den;
480       duration_ = 0;
481       return;
482     }
483   }
484 
FramePktHook(const vpx_codec_cx_pkt_t * pkt)485   void FramePktHook(const vpx_codec_cx_pkt_t *pkt) override {
486     // Time since last timestamp = duration.
487     vpx_codec_pts_t duration = pkt->data.frame.pts - last_pts_;
488     if (duration > 1) {
489       // Update counter for total number of frames (#frames input to encoder).
490       // Needed for setting the proper layer_id below.
491       tot_frame_number_ += static_cast<int>(duration - 1);
492     }
493     int layer = SetLayerId(tot_frame_number_, cfg_.ts_number_layers);
494     const size_t frame_size_in_bits = pkt->data.frame.sz * 8;
495     // Update the total encoded bits. For temporal layers, update the cumulative
496     // encoded bits per layer.
497     for (int i = layer; i < static_cast<int>(cfg_.ts_number_layers); ++i) {
498       bits_total_[i] += frame_size_in_bits;
499     }
500     // Update the most recent pts.
501     last_pts_ = pkt->data.frame.pts;
502     ++tot_frame_number_;
503   }
504 
EndPassHook()505   void EndPassHook() override {
506     duration_ = (last_pts_ + 1) * timebase_;
507     if (cfg_.ts_number_layers > 1) {
508       for (int layer = 0; layer < static_cast<int>(cfg_.ts_number_layers);
509            ++layer) {
510         if (bits_total_[layer]) {
511           // Effective file datarate:
512           effective_datarate_[layer] =
513               (bits_total_[layer] / 1000.0) / duration_;
514         }
515       }
516     }
517   }
518 
519   double effective_datarate_[3];
520 
521  private:
522   libvpx_test::TestMode encoding_mode_;
523   vpx_codec_pts_t last_pts_;
524   double timebase_;
525   int64_t bits_total_[3];
526   double duration_;
527   int tot_frame_number_;
528 };
529 
530 // Check two codec controls used for:
531 // (1) for setting temporal layer id, and (2) for settings encoder flags.
532 // This test invokes those controls for each frame, and verifies encoder/decoder
533 // mismatch and basic rate control response.
534 // TODO(marpan): Maybe move this test to datarate_test.cc.
TEST_P(ErrorResilienceTestLargeCodecControls,CodecControl3TemporalLayers)535 TEST_P(ErrorResilienceTestLargeCodecControls, CodecControl3TemporalLayers) {
536   cfg_.rc_buf_initial_sz = 500;
537   cfg_.rc_buf_optimal_sz = 500;
538   cfg_.rc_buf_sz = 1000;
539   cfg_.rc_dropframe_thresh = 1;
540   cfg_.rc_min_quantizer = 2;
541   cfg_.rc_max_quantizer = 56;
542   cfg_.rc_end_usage = VPX_CBR;
543   cfg_.rc_dropframe_thresh = 1;
544   cfg_.g_lag_in_frames = 0;
545   cfg_.kf_mode = VPX_KF_DISABLED;
546   cfg_.g_error_resilient = 1;
547 
548   // 3 Temporal layers. Framerate decimation (4, 2, 1).
549   cfg_.ts_number_layers = 3;
550   cfg_.ts_rate_decimator[0] = 4;
551   cfg_.ts_rate_decimator[1] = 2;
552   cfg_.ts_rate_decimator[2] = 1;
553   cfg_.ts_periodicity = 4;
554   cfg_.ts_layer_id[0] = 0;
555   cfg_.ts_layer_id[1] = 2;
556   cfg_.ts_layer_id[2] = 1;
557   cfg_.ts_layer_id[3] = 2;
558 
559   ::libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
560                                        30, 1, 0, 200);
561   for (int i = 200; i <= 800; i += 200) {
562     cfg_.rc_target_bitrate = i;
563     Reset();
564     // 40-20-40 bitrate allocation for 3 temporal layers.
565     cfg_.ts_target_bitrate[0] = 40 * cfg_.rc_target_bitrate / 100;
566     cfg_.ts_target_bitrate[1] = 60 * cfg_.rc_target_bitrate / 100;
567     cfg_.ts_target_bitrate[2] = cfg_.rc_target_bitrate;
568     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
569     for (int j = 0; j < static_cast<int>(cfg_.ts_number_layers); ++j) {
570       ASSERT_GE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 0.75)
571           << " The datarate for the file is lower than target by too much, "
572              "for layer: "
573           << j;
574       ASSERT_LE(effective_datarate_[j], cfg_.ts_target_bitrate[j] * 1.25)
575           << " The datarate for the file is greater than target by too much, "
576              "for layer: "
577           << j;
578     }
579   }
580 }
581 
582 VP8_INSTANTIATE_TEST_SUITE(ErrorResilienceTestLarge, ONE_PASS_TEST_MODES,
583                            ::testing::Values(true));
584 VP8_INSTANTIATE_TEST_SUITE(ErrorResilienceTestLargeCodecControls,
585                            ONE_PASS_TEST_MODES);
586 VP9_INSTANTIATE_TEST_SUITE(ErrorResilienceTestLarge, ONE_PASS_TEST_MODES,
587                            ::testing::Values(true));
588 }  // namespace
589