• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #include <climits>
13 #include <vector>
14 #include "config/aom_config.h"
15 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
16 #include "test/codec_factory.h"
17 #include "test/datarate_test.h"
18 #include "test/encode_test_driver.h"
19 #include "test/i420_video_source.h"
20 #include "test/util.h"
21 #include "test/y4m_video_source.h"
22 #include "aom/aom_codec.h"
23 #include "av1/common/enums.h"
24 #include "av1/encoder/encoder.h"
25 
26 namespace datarate_test {
27 namespace {
28 
29 struct FrameInfo {
FrameInfodatarate_test::__anone4fbc1bb0111::FrameInfo30   FrameInfo(aom_codec_pts_t _pts, unsigned int _w, unsigned int _h)
31       : pts(_pts), w(_w), h(_h) {}
32 
33   aom_codec_pts_t pts;
34   unsigned int w;
35   unsigned int h;
36 };
37 
38 class DatarateTestSVC
39     : public ::libaom_test::CodecTestWith4Params<libaom_test::TestMode, int,
40                                                  unsigned int, int>,
41       public DatarateTest {
42  public:
DatarateTestSVC()43   DatarateTestSVC() : DatarateTest(GET_PARAM(0)) {
44     set_cpu_used_ = GET_PARAM(2);
45     aq_mode_ = GET_PARAM(3);
46   }
47 
48  protected:
SetUp()49   void SetUp() override {
50     InitializeConfig(GET_PARAM(1));
51     ResetModel();
52   }
53 
DecompressedFrameHook(const aom_image_t & img,aom_codec_pts_t pts)54   void DecompressedFrameHook(const aom_image_t &img,
55                              aom_codec_pts_t pts) override {
56     frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h));
57     ++decoded_nframes_;
58   }
59 
60   std::vector<FrameInfo> frame_info_list_;
61 
GetNumSpatialLayers()62   int GetNumSpatialLayers() override { return number_spatial_layers_; }
63 
ResetModel()64   void ResetModel() override {
65     DatarateTest::ResetModel();
66     layer_frame_cnt_ = 0;
67     superframe_cnt_ = 0;
68     number_temporal_layers_ = 1;
69     number_spatial_layers_ = 1;
70     for (int i = 0; i < AOM_MAX_LAYERS; i++) {
71       target_layer_bitrate_[i] = 0;
72       effective_datarate_tl[i] = 0.0;
73     }
74     memset(&layer_id_, 0, sizeof(aom_svc_layer_id_t));
75     memset(&svc_params_, 0, sizeof(aom_svc_params_t));
76     memset(&ref_frame_config_, 0, sizeof(aom_svc_ref_frame_config_t));
77     memset(&ref_frame_comp_pred_, 0, sizeof(aom_svc_ref_frame_comp_pred_t));
78     drop_frames_ = 0;
79     for (int i = 0; i < 1000; i++) drop_frames_list_[i] = 1000;
80     decoded_nframes_ = 0;
81     mismatch_nframes_ = 0;
82     mismatch_psnr_ = 0.0;
83     set_frame_level_er_ = 0;
84     multi_ref_ = 0;
85     use_fixed_mode_svc_ = 0;
86     comp_pred_ = 0;
87     dynamic_enable_disable_mode_ = 0;
88     intra_only_ = 0;
89     frame_to_start_decoding_ = 0;
90     layer_to_decode_ = 0;
91     frame_sync_ = 0;
92     current_video_frame_ = 0;
93     screen_mode_ = 0;
94     rps_mode_ = 0;
95     rps_recovery_frame_ = 0;
96     user_define_frame_qp_ = 0;
97     set_speed_per_layer_ = false;
98     simulcast_mode_ = false;
99   }
100 
PreEncodeFrameHook(::libaom_test::VideoSource * video,::libaom_test::Encoder * encoder)101   void PreEncodeFrameHook(::libaom_test::VideoSource *video,
102                           ::libaom_test::Encoder *encoder) override {
103     int spatial_layer_id = 0;
104     current_video_frame_ = video->frame();
105     // video->frame() is called every superframe, so we should condition
106     // this on layer_frame_cnt_ = 0, so we only do this once on the very
107     // first frame.
108     if (video->frame() == 0 && layer_frame_cnt_ == 0) {
109       initialize_svc(number_temporal_layers_, number_spatial_layers_,
110                      &svc_params_);
111       if (dynamic_enable_disable_mode_ == 1) {
112         svc_params_.layer_target_bitrate[2] = 0;
113         cfg_.rc_target_bitrate -= target_layer_bitrate_[2];
114       }
115       encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_);
116       // TODO(aomedia:3032): Configure KSVC in fixed mode.
117       encoder->Control(AV1E_SET_ENABLE_ORDER_HINT, 0);
118       encoder->Control(AV1E_SET_ENABLE_TPL_MODEL, 0);
119       encoder->Control(AV1E_SET_DELTAQ_MODE, 0);
120       if (cfg_.g_threads > 1) {
121         if (cfg_.g_threads == 4) {
122           encoder->Control(AV1E_SET_TILE_COLUMNS, 2);
123           encoder->Control(AV1E_SET_TILE_ROWS, 2);
124         } else if (cfg_.g_threads == 8) {
125           encoder->Control(AV1E_SET_TILE_COLUMNS, 4);
126           encoder->Control(AV1E_SET_TILE_ROWS, 2);
127         } else {
128           encoder->Control(AV1E_SET_TILE_COLUMNS, cfg_.g_threads >> 1);
129         }
130         encoder->Control(AV1E_SET_ROW_MT, 1);
131       }
132       if (screen_mode_) {
133         encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN);
134       }
135     }
136     if (number_spatial_layers_ == 2) {
137       spatial_layer_id = (layer_frame_cnt_ % 2 == 0) ? 0 : 1;
138     } else if (number_spatial_layers_ == 3) {
139       spatial_layer_id = (layer_frame_cnt_ % 3 == 0)         ? 0
140                          : ((layer_frame_cnt_ - 1) % 3 == 0) ? 1
141                                                              : 2;
142     }
143     // Set the reference/update flags, layer_id, and reference_map
144     // buffer index.
145     frame_flags_ = set_layer_pattern(
146         video->frame(), &layer_id_, &ref_frame_config_, &ref_frame_comp_pred_,
147         spatial_layer_id, multi_ref_, comp_pred_,
148         (video->frame() % cfg_.kf_max_dist) == 0, dynamic_enable_disable_mode_,
149         rps_mode_, rps_recovery_frame_, simulcast_mode_);
150     if (intra_only_ == 1 && frame_sync_ > 0) {
151       // Set an Intra-only frame on SL0 at frame_sync_.
152       // In order to allow decoding to start on SL0 in mid-sequence we need to
153       // set and refresh all the slots used on SL0 stream, which is 0 and 3
154       // for this test pattern. The other slots (1, 2, 4, 5) are used for the
155       // SL > 0 layers and these slotes are not refreshed on frame_sync_, so
156       // temporal prediction for the top layers can continue.
157       if (spatial_layer_id == 0 && video->frame() == frame_sync_) {
158         ref_frame_config_.ref_idx[0] = 0;
159         ref_frame_config_.ref_idx[3] = 3;
160         ref_frame_config_.refresh[0] = 1;
161         ref_frame_config_.refresh[3] = 1;
162         for (int i = 0; i < INTER_REFS_PER_FRAME; i++)
163           ref_frame_config_.reference[i] = 0;
164       }
165     }
166     if (intra_only_ && video->frame() == 50 && spatial_layer_id == 1) {
167       // Force an intra_only frame here, for SL1.
168       for (int i = 0; i < INTER_REFS_PER_FRAME; i++)
169         ref_frame_config_.reference[i] = 0;
170     }
171     encoder->Control(AV1E_SET_SVC_LAYER_ID, &layer_id_);
172     // The SET_SVC_REF_FRAME_CONFIG and AV1E_SET_SVC_REF_FRAME_COMP_PRED api is
173     // for the flexible SVC mode (i.e., use_fixed_mode_svc == 0).
174     if (!use_fixed_mode_svc_) {
175       encoder->Control(AV1E_SET_SVC_REF_FRAME_CONFIG, &ref_frame_config_);
176       encoder->Control(AV1E_SET_SVC_REF_FRAME_COMP_PRED, &ref_frame_comp_pred_);
177     }
178     if (set_speed_per_layer_) {
179       int speed_per_layer = 10;
180       if (layer_id_.spatial_layer_id == 0) {
181         // For for base SL0,TL0: use the speed the test loops over.
182         if (layer_id_.temporal_layer_id == 1) speed_per_layer = 7;
183         if (layer_id_.temporal_layer_id == 2) speed_per_layer = 8;
184       } else if (layer_id_.spatial_layer_id == 1) {
185         if (layer_id_.temporal_layer_id == 0) speed_per_layer = 7;
186         if (layer_id_.temporal_layer_id == 1) speed_per_layer = 8;
187         if (layer_id_.temporal_layer_id == 2) speed_per_layer = 9;
188       } else if (layer_id_.spatial_layer_id == 2) {
189         if (layer_id_.temporal_layer_id == 0) speed_per_layer = 8;
190         if (layer_id_.temporal_layer_id == 1) speed_per_layer = 9;
191         if (layer_id_.temporal_layer_id == 2) speed_per_layer = 10;
192       }
193       encoder->Control(AOME_SET_CPUUSED, speed_per_layer);
194     }
195     if (set_frame_level_er_) {
196       int mode =
197           (layer_id_.spatial_layer_id > 0 || layer_id_.temporal_layer_id > 0);
198       encoder->Control(AV1E_SET_ERROR_RESILIENT_MODE, mode);
199     }
200     if (dynamic_enable_disable_mode_ == 1) {
201       if (layer_frame_cnt_ == 300 && spatial_layer_id == 0) {
202         // Enable: set top spatial layer bitrate back to non-zero.
203         svc_params_.layer_target_bitrate[2] = target_layer_bitrate_[2];
204         cfg_.rc_target_bitrate += target_layer_bitrate_[2];
205         encoder->Config(&cfg_);
206         encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_);
207       }
208     } else if (dynamic_enable_disable_mode_ == 2) {
209       if (layer_frame_cnt_ == 300 && spatial_layer_id == 0) {
210         // Disable top spatial layer mid-stream.
211         svc_params_.layer_target_bitrate[2] = 0;
212         cfg_.rc_target_bitrate -= target_layer_bitrate_[2];
213         encoder->Config(&cfg_);
214         encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_);
215       } else if (layer_frame_cnt_ == 600 && spatial_layer_id == 0) {
216         // Enable top spatial layer mid-stream.
217         svc_params_.layer_target_bitrate[2] = target_layer_bitrate_[2];
218         cfg_.rc_target_bitrate += target_layer_bitrate_[2];
219         encoder->Config(&cfg_);
220         encoder->Control(AV1E_SET_SVC_PARAMS, &svc_params_);
221       }
222     }
223     layer_frame_cnt_++;
224     DatarateTest::PreEncodeFrameHook(video, encoder);
225 
226     if (user_define_frame_qp_) {
227       frame_qp_ = rnd_.PseudoUniform(63);
228       encoder->Control(AV1E_SET_QUANTIZER_ONE_PASS, frame_qp_);
229     }
230   }
231 
PostEncodeFrameHook(::libaom_test::Encoder * encoder)232   void PostEncodeFrameHook(::libaom_test::Encoder *encoder) override {
233     int num_operating_points;
234     encoder->Control(AV1E_GET_NUM_OPERATING_POINTS, &num_operating_points);
235     ASSERT_EQ(num_operating_points,
236               number_temporal_layers_ * number_spatial_layers_);
237 
238     if (user_define_frame_qp_) {
239       if (current_video_frame_ >= static_cast<unsigned int>(total_frame_))
240         return;
241       int qp;
242       encoder->Control(AOME_GET_LAST_QUANTIZER_64, &qp);
243       ASSERT_EQ(qp, frame_qp_);
244     }
245   }
246 
FramePktHook(const aom_codec_cx_pkt_t * pkt)247   void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
248     const size_t frame_size_in_bits = pkt->data.frame.sz * 8;
249     // Update the layer cumulative  bitrate.
250     for (int i = layer_id_.temporal_layer_id; i < number_temporal_layers_;
251          i++) {
252       int layer = layer_id_.spatial_layer_id * number_temporal_layers_ + i;
253       effective_datarate_tl[layer] += 1.0 * frame_size_in_bits;
254     }
255     if (layer_id_.spatial_layer_id == number_spatial_layers_ - 1) {
256       last_pts_ = pkt->data.frame.pts;
257       superframe_cnt_++;
258     }
259     // For simulcast mode: verify that for first frame to start decoding,
260     // for SL > 0, are Intra-only frames (not Key), whereas SL0 is Key.
261     if (simulcast_mode_ && superframe_cnt_ == (int)frame_to_start_decoding_) {
262       if (layer_id_.spatial_layer_id > 0) {
263         EXPECT_NE(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
264       } else if (layer_id_.spatial_layer_id == 0) {
265         EXPECT_EQ(pkt->data.frame.flags & AOM_FRAME_IS_KEY, AOM_FRAME_IS_KEY);
266       }
267     }
268   }
269 
EndPassHook()270   void EndPassHook() override {
271     duration_ = ((last_pts_ + 1) * timebase_);
272     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
273       effective_datarate_tl[i] = (effective_datarate_tl[i] / 1000) / duration_;
274     }
275   }
276 
DoDecode() const277   bool DoDecode() const override {
278     if (drop_frames_ > 0) {
279       for (unsigned int i = 0; i < drop_frames_; ++i) {
280         if (drop_frames_list_[i] == (unsigned int)superframe_cnt_) {
281           std::cout << "             Skipping decoding frame: "
282                     << drop_frames_list_[i] << "\n";
283           return false;
284         }
285       }
286     } else if (intra_only_ == 1) {
287       // Only start decoding at frames_to_start_decoding_.
288       if (current_video_frame_ < frame_to_start_decoding_) return false;
289       // Only decode base layer for 3SL, for layer_to_decode_ = 0.
290       if (layer_to_decode_ == 0 && frame_sync_ > 0 &&
291           (layer_frame_cnt_ - 1) % 3 != 0)
292         return false;
293     } else if (simulcast_mode_) {
294       // Only start decoding at frames_to_start_decoding_ and only
295       // for top spatial layer SL2 (layer_to_decode_).
296       if (current_video_frame_ < frame_to_start_decoding_) return false;
297       if (layer_id_.spatial_layer_id < (int)layer_to_decode_) return false;
298     }
299     return true;
300   }
301 
MismatchHook(const aom_image_t * img1,const aom_image_t * img2)302   void MismatchHook(const aom_image_t *img1, const aom_image_t *img2) override {
303     double mismatch_psnr = compute_psnr(img1, img2);
304     mismatch_psnr_ += mismatch_psnr;
305     ++mismatch_nframes_;
306   }
307 
GetMismatchFrames()308   unsigned int GetMismatchFrames() { return mismatch_nframes_; }
GetDecodedFrames()309   unsigned int GetDecodedFrames() { return decoded_nframes_; }
310 
ref_config_rps(aom_svc_ref_frame_config_t * ref_frame_config,int frame_cnt,int rps_recovery_frame)311   static void ref_config_rps(aom_svc_ref_frame_config_t *ref_frame_config,
312                              int frame_cnt, int rps_recovery_frame) {
313     // Pattern of 3 references with (ALTREF and GOLDEN) trailing
314     // LAST by 4 and 8 frame, with some switching logic to
315     // only predict from longer-term reference.
316     int last_idx = 0;
317     int last_idx_refresh = 0;
318     int gld_idx = 0;
319     int alt_ref_idx = 0;
320     const int lag_alt = 4;
321     const int lag_gld = 8;
322     const int sh = 8;  // slots 0 - 7.
323     // Moving index slot for last: 0 - (sh - 1)
324     if (frame_cnt > 1) last_idx = (frame_cnt - 1) % sh;
325     // Moving index for refresh of last: one ahead for next frame.
326     last_idx_refresh = frame_cnt % sh;
327     // Moving index for gld_ref, lag behind current by lag_gld
328     if (frame_cnt > lag_gld) gld_idx = (frame_cnt - lag_gld) % sh;
329     // Moving index for alt_ref, lag behind LAST by lag_alt frames.
330     if (frame_cnt > lag_alt) alt_ref_idx = (frame_cnt - lag_alt) % sh;
331     // Set the ref_idx.
332     // Default all references (7) to slot for last.
333     // LAST_FRAME (0), LAST2_FRAME(1), LAST3_FRAME(2), GOLDEN_FRAME(3),
334     // BWDREF_FRAME(4), ALTREF2_FRAME(5), ALTREF_FRAME(6).
335     for (int i = 0; i < INTER_REFS_PER_FRAME; i++)
336       ref_frame_config->ref_idx[i] = last_idx;
337     // Set the ref_idx for the relevant references.
338     ref_frame_config->ref_idx[0] = last_idx;
339     ref_frame_config->ref_idx[1] = last_idx_refresh;
340     ref_frame_config->ref_idx[3] = gld_idx;
341     ref_frame_config->ref_idx[6] = alt_ref_idx;
342     // Refresh this slot, which will become LAST on next frame.
343     ref_frame_config->refresh[last_idx_refresh] = 1;
344     // Reference LAST, ALTREF, and GOLDEN
345     ref_frame_config->reference[0] = 1;
346     ref_frame_config->reference[6] = 1;
347     ref_frame_config->reference[3] = 1;
348     if (frame_cnt == rps_recovery_frame) {
349       // Switch to only reference GOLDEN at recovery_frame.
350       ref_frame_config->reference[0] = 0;
351       ref_frame_config->reference[6] = 0;
352       ref_frame_config->reference[3] = 1;
353     } else if (frame_cnt > rps_recovery_frame &&
354                frame_cnt < rps_recovery_frame + 8) {
355       // Go back to predicting from LAST, and after
356       // 8 frames (GOLDEN is 8 frames aways) go back
357       // to predicting off GOLDEN and ALTREF.
358       ref_frame_config->reference[0] = 1;
359       ref_frame_config->reference[6] = 0;
360       ref_frame_config->reference[3] = 0;
361     }
362   }
363 
364   // Simulcast mode for 3 spatial and 3 temporal layers.
365   // No inter-layer predicton, only prediction is temporal and single
366   // reference (LAST).
367   // No overlap in buffer slots between spatial layers. So for example,
368   // SL0 only uses slots 0 and 1.
369   // SL1 only uses slots 2 and 3.
370   // SL2 only uses slots 4 and 5.
371   // All 7 references for each inter-frame must only access buffer slots
372   // for that spatial layer.
373   // On key (super)frames: SL1 and SL2 must have no references set
374   // and must refresh all the slots for that layer only (so 2 and 3
375   // for SL1, 4 and 5 for SL2). The base SL0 will be labelled internally
376   // as a Key frame (refresh all slots). SL1/SL2 will be labelled
377   // internally as Intra-only frames that allow that stream to be decoded.
378   // These conditions will allow for each spatial stream to be
379   // independently decodeable.
ref_config_simulcast3SL3TL(aom_svc_ref_frame_config_t * ref_frame_config,aom_svc_layer_id_t * layer_id,int is_key_frame,int superframe_cnt)380   static void ref_config_simulcast3SL3TL(
381       aom_svc_ref_frame_config_t *ref_frame_config,
382       aom_svc_layer_id_t *layer_id, int is_key_frame, int superframe_cnt) {
383     int i;
384     // Initialize all references to 0 (don't use reference).
385     for (i = 0; i < INTER_REFS_PER_FRAME; i++)
386       ref_frame_config->reference[i] = 0;
387     // Initialize as no refresh/update for all slots.
388     for (i = 0; i < REF_FRAMES; i++) ref_frame_config->refresh[i] = 0;
389     for (i = 0; i < INTER_REFS_PER_FRAME; i++) ref_frame_config->ref_idx[i] = 0;
390 
391     if (is_key_frame) {
392       if (layer_id->spatial_layer_id == 0) {
393         // Assign LAST/GOLDEN to slot 0/1.
394         // Refesh slots 0 and 1 for SL0.
395         // SL0: this will get set to KEY frame internally.
396         ref_frame_config->ref_idx[0] = 0;
397         ref_frame_config->ref_idx[3] = 1;
398         ref_frame_config->refresh[0] = 1;
399         ref_frame_config->refresh[1] = 1;
400       } else if (layer_id->spatial_layer_id == 1) {
401         // Assign LAST/GOLDEN to slot 2/3.
402         // Refesh slots 2 and 3 for SL1.
403         // This will get set to Intra-only frame internally.
404         ref_frame_config->ref_idx[0] = 2;
405         ref_frame_config->ref_idx[3] = 3;
406         ref_frame_config->refresh[2] = 1;
407         ref_frame_config->refresh[3] = 1;
408       } else if (layer_id->spatial_layer_id == 2) {
409         // Assign LAST/GOLDEN to slot 4/5.
410         // Refresh slots 4 and 5 for SL2.
411         // This will get set to Intra-only frame internally.
412         ref_frame_config->ref_idx[0] = 4;
413         ref_frame_config->ref_idx[3] = 5;
414         ref_frame_config->refresh[4] = 1;
415         ref_frame_config->refresh[5] = 1;
416       }
417     } else if (superframe_cnt % 4 == 0) {
418       // Base temporal layer: TL0
419       layer_id->temporal_layer_id = 0;
420       if (layer_id->spatial_layer_id == 0) {  // SL0
421         // Reference LAST. Assign all references to either slot
422         // 0 or 1. Here we assign LAST to slot 0, all others to 1.
423         // Update slot 0 (LAST).
424         ref_frame_config->reference[0] = 1;
425         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
426           ref_frame_config->ref_idx[i] = 1;
427         ref_frame_config->ref_idx[0] = 0;
428         ref_frame_config->refresh[0] = 1;
429       } else if (layer_id->spatial_layer_id == 1) {  // SL1
430         // Reference LAST. Assign all references to either slot
431         // 2 or 3. Here we assign LAST to slot 2, all others to 3.
432         // Update slot 2 (LAST).
433         ref_frame_config->reference[0] = 1;
434         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
435           ref_frame_config->ref_idx[i] = 3;
436         ref_frame_config->ref_idx[0] = 2;
437         ref_frame_config->refresh[2] = 1;
438       } else if (layer_id->spatial_layer_id == 2) {  // SL2
439         // Reference LAST. Assign all references to either slot
440         // 4 or 5. Here we assign LAST to slot 4, all others to 5.
441         // Update slot 4 (LAST).
442         ref_frame_config->reference[0] = 1;
443         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
444           ref_frame_config->ref_idx[i] = 5;
445         ref_frame_config->ref_idx[0] = 4;
446         ref_frame_config->refresh[4] = 1;
447       }
448     } else if ((superframe_cnt - 1) % 4 == 0) {
449       // First top temporal enhancement layer: TL2
450       layer_id->temporal_layer_id = 2;
451       if (layer_id->spatial_layer_id == 0) {  // SL0
452         // Reference LAST (slot 0). Assign other references to slot 1.
453         // No update/refresh on any slots.
454         ref_frame_config->reference[0] = 1;
455         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
456           ref_frame_config->ref_idx[i] = 1;
457         ref_frame_config->ref_idx[0] = 0;
458       } else if (layer_id->spatial_layer_id == 1) {  // SL1
459         // Reference LAST (slot 2). Assign other references to slot 3.
460         // No update/refresh on any slots.
461         ref_frame_config->reference[0] = 1;
462         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
463           ref_frame_config->ref_idx[i] = 3;
464         ref_frame_config->ref_idx[0] = 2;
465       } else if (layer_id->spatial_layer_id == 2) {  // SL2
466         // Reference LAST (slot 4). Assign other references to slot 4.
467         // No update/refresh on any slots.
468         ref_frame_config->reference[0] = 1;
469         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
470           ref_frame_config->ref_idx[i] = 5;
471         ref_frame_config->ref_idx[0] = 4;
472       }
473     } else if ((superframe_cnt - 2) % 4 == 0) {
474       // Middle temporal enhancement layer: TL1
475       layer_id->temporal_layer_id = 1;
476       if (layer_id->spatial_layer_id == 0) {  // SL0
477         // Reference LAST (slot 0).
478         // Set GOLDEN to slot 1 and update slot 1.
479         // This will be used as reference for next TL2.
480         ref_frame_config->reference[0] = 1;
481         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
482           ref_frame_config->ref_idx[i] = 1;
483         ref_frame_config->ref_idx[0] = 0;
484         ref_frame_config->refresh[1] = 1;
485       } else if (layer_id->spatial_layer_id == 1) {  // SL1
486         // Reference LAST (slot 2).
487         // Set GOLDEN to slot 3 and update slot 3.
488         // This will be used as reference for next TL2.
489         ref_frame_config->reference[0] = 1;
490         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
491           ref_frame_config->ref_idx[i] = 3;
492         ref_frame_config->ref_idx[0] = 2;
493         ref_frame_config->refresh[3] = 1;
494       } else if (layer_id->spatial_layer_id == 2) {  // SL2
495         // Reference LAST (slot 4).
496         // Set GOLDEN to slot 5 and update slot 5.
497         // This will be used as reference for next TL2.
498         ref_frame_config->reference[0] = 1;
499         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
500           ref_frame_config->ref_idx[i] = 5;
501         ref_frame_config->ref_idx[0] = 4;
502         ref_frame_config->refresh[5] = 1;
503       }
504     } else if ((superframe_cnt - 3) % 4 == 0) {
505       // Second top temporal enhancement layer: TL2
506       layer_id->temporal_layer_id = 2;
507       if (layer_id->spatial_layer_id == 0) {  // SL0
508         // Reference LAST (slot 1). Assign other references to slot 0.
509         // No update/refresh on any slots.
510         ref_frame_config->reference[0] = 1;
511         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
512           ref_frame_config->ref_idx[i] = 0;
513         ref_frame_config->ref_idx[0] = 1;
514       } else if (layer_id->spatial_layer_id == 1) {  // SL1
515         // Reference LAST (slot 3). Assign other references to slot 2.
516         // No update/refresh on any slots.
517         ref_frame_config->reference[0] = 1;
518         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
519           ref_frame_config->ref_idx[i] = 2;
520         ref_frame_config->ref_idx[0] = 3;
521       } else if (layer_id->spatial_layer_id == 2) {  // SL2
522         // Reference LAST (slot 5). Assign other references to slot 4.
523         // No update/refresh on any slots.
524         ref_frame_config->reference[0] = 1;
525         for (i = 0; i < INTER_REFS_PER_FRAME; i++)
526           ref_frame_config->ref_idx[i] = 4;
527         ref_frame_config->ref_idx[0] = 5;
528       }
529     }
530   }
531 
532   // 3 spatial and 3 temporal layer.
533   // Overlap in the buffer slot updates: the slots 3 and 4 updated by
534   // first TL2 are reused for update in TL1 superframe.
ref_config_3SL3TL(aom_svc_ref_frame_config_t * ref_frame_config,aom_svc_layer_id_t * layer_id,int is_key_frame,int superframe_cnt)535   static void ref_config_3SL3TL(aom_svc_ref_frame_config_t *ref_frame_config,
536                                 aom_svc_layer_id_t *layer_id, int is_key_frame,
537                                 int superframe_cnt) {
538     if (superframe_cnt % 4 == 0) {
539       // Base temporal layer.
540       layer_id->temporal_layer_id = 0;
541       if (layer_id->spatial_layer_id == 0) {
542         // Reference LAST, update LAST.
543         // Set all buffer_idx to 0.
544         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0;
545         ref_frame_config->refresh[0] = 1;
546       } else if (layer_id->spatial_layer_id == 1) {
547         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1,
548         // GOLDEN (and all other refs) to slot 0.
549         // Update slot 1 (LAST).
550         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0;
551         ref_frame_config->ref_idx[0] = 1;
552         ref_frame_config->refresh[1] = 1;
553       } else if (layer_id->spatial_layer_id == 2) {
554         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2,
555         // GOLDEN (and all other refs) to slot 1.
556         // Update slot 2 (LAST).
557         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 1;
558         ref_frame_config->ref_idx[0] = 2;
559         ref_frame_config->refresh[2] = 1;
560       }
561     } else if ((superframe_cnt - 1) % 4 == 0) {
562       // First top temporal enhancement layer.
563       layer_id->temporal_layer_id = 2;
564       if (layer_id->spatial_layer_id == 0) {
565         // Reference LAST (slot 0).
566         // Set GOLDEN to slot 3 and update slot 3.
567         // Set all other buffer_idx to slot 0.
568         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0;
569         ref_frame_config->ref_idx[3] = 3;
570         ref_frame_config->refresh[3] = 1;
571       } else if (layer_id->spatial_layer_id == 1) {
572         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1,
573         // GOLDEN (and all other refs) to slot 3.
574         // Set LAST2 to slot 4 and Update slot 4.
575         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 3;
576         ref_frame_config->ref_idx[0] = 1;
577         ref_frame_config->ref_idx[1] = 4;
578         ref_frame_config->refresh[4] = 1;
579       } else if (layer_id->spatial_layer_id == 2) {
580         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2,
581         // GOLDEN (and all other refs) to slot 4.
582         // No update.
583         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 4;
584         ref_frame_config->ref_idx[0] = 2;
585       }
586     } else if ((superframe_cnt - 2) % 4 == 0) {
587       // Middle temporal enhancement layer.
588       layer_id->temporal_layer_id = 1;
589       if (layer_id->spatial_layer_id == 0) {
590         // Reference LAST.
591         // Set all buffer_idx to 0.
592         // Set GOLDEN to slot 3 and update slot 3.
593         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0;
594         ref_frame_config->ref_idx[3] = 3;
595         ref_frame_config->refresh[3] = 1;
596       } else if (layer_id->spatial_layer_id == 1) {
597         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1,
598         // GOLDEN (and all other refs) to slot 3.
599         // Set LAST2 to slot 4 and update slot 4.
600         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 3;
601         ref_frame_config->ref_idx[0] = 1;
602         ref_frame_config->ref_idx[2] = 4;
603         ref_frame_config->refresh[4] = 1;
604       } else if (layer_id->spatial_layer_id == 2) {
605         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2,
606         // GOLDEN (and all other refs) to slot 4.
607         // Set LAST2 to slot 5 and update slot 5.
608         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 4;
609         ref_frame_config->ref_idx[0] = 2;
610         ref_frame_config->ref_idx[2] = 5;
611         ref_frame_config->refresh[5] = 1;
612       }
613     } else if ((superframe_cnt - 3) % 4 == 0) {
614       // Second top temporal enhancement layer.
615       layer_id->temporal_layer_id = 2;
616       if (layer_id->spatial_layer_id == 0) {
617         // Set LAST to slot 3 and reference LAST.
618         // Set GOLDEN to slot 3 and update slot 3.
619         // Set all other buffer_idx to 0.
620         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0;
621         ref_frame_config->ref_idx[0] = 3;
622         ref_frame_config->ref_idx[3] = 3;
623         ref_frame_config->refresh[3] = 1;
624       } else if (layer_id->spatial_layer_id == 1) {
625         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 4,
626         // GOLDEN to slot 3. Set LAST2 to slot 4 and update slot 4.
627         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0;
628         ref_frame_config->ref_idx[0] = 4;
629         ref_frame_config->ref_idx[3] = 3;
630         ref_frame_config->ref_idx[1] = 4;
631         ref_frame_config->refresh[4] = 1;
632       } else if (layer_id->spatial_layer_id == 2) {
633         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 5,
634         // GOLDEN to slot 4. No update.
635         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0;
636         ref_frame_config->ref_idx[0] = 5;
637         ref_frame_config->ref_idx[3] = 4;
638       }
639     }
640     if (layer_id->spatial_layer_id > 0) {
641       // Always reference GOLDEN (inter-layer prediction).
642       ref_frame_config->reference[3] = 1;
643       if (is_key_frame && layer_id->spatial_layer_id > 0) {
644         // On superframes whose base is key: remove LAST since GOLDEN
645         // is used as reference.
646         ref_frame_config->reference[0] = 0;
647       }
648     }
649   }
650 
651   // Layer pattern configuration.
set_layer_pattern(int frame_cnt,aom_svc_layer_id_t * layer_id,aom_svc_ref_frame_config_t * ref_frame_config,aom_svc_ref_frame_comp_pred_t * ref_frame_comp_pred,int spatial_layer,int multi_ref,int comp_pred,int is_key_frame,int dynamic_enable_disable_mode,int rps_mode,int rps_recovery_frame,int simulcast_mode)652   virtual int set_layer_pattern(
653       int frame_cnt, aom_svc_layer_id_t *layer_id,
654       aom_svc_ref_frame_config_t *ref_frame_config,
655       aom_svc_ref_frame_comp_pred_t *ref_frame_comp_pred, int spatial_layer,
656       int multi_ref, int comp_pred, int is_key_frame,
657       int dynamic_enable_disable_mode, int rps_mode, int rps_recovery_frame,
658       int simulcast_mode) {
659     int lag_index = 0;
660     int base_count = frame_cnt >> 2;
661     layer_id->spatial_layer_id = spatial_layer;
662     // Set the reference map buffer idx for the 7 references:
663     // LAST_FRAME (0), LAST2_FRAME(1), LAST3_FRAME(2), GOLDEN_FRAME(3),
664     // BWDREF_FRAME(4), ALTREF2_FRAME(5), ALTREF_FRAME(6).
665     for (int i = 0; i < INTER_REFS_PER_FRAME; i++) {
666       ref_frame_config->ref_idx[i] = i;
667       ref_frame_config->reference[i] = 0;
668     }
669     for (int i = 0; i < REF_FRAMES; i++) ref_frame_config->refresh[i] = 0;
670     if (comp_pred) {
671       ref_frame_comp_pred->use_comp_pred[0] = 1;  // GOLDEN_LAST
672       ref_frame_comp_pred->use_comp_pred[1] = 1;  // LAST2_LAST
673       ref_frame_comp_pred->use_comp_pred[2] = 1;  // ALTREF_LAST
674     }
675     // Set layer_flags to 0 when using ref_frame_config->reference.
676     int layer_flags = 0;
677     // Always reference LAST.
678     ref_frame_config->reference[0] = 1;
679     if (number_temporal_layers_ == 1 && number_spatial_layers_ == 1) {
680       ref_frame_config->refresh[0] = 1;
681       if (rps_mode)
682         ref_config_rps(ref_frame_config, frame_cnt, rps_recovery_frame);
683     }
684     if (number_temporal_layers_ == 2 && number_spatial_layers_ == 1) {
685       // 2-temporal layer.
686       //    1    3    5
687       //  0    2    4
688       // Keep golden fixed at slot 3.
689       base_count = frame_cnt >> 1;
690       ref_frame_config->ref_idx[3] = 3;
691       // Cyclically refresh slots 5, 6, 7, for lag alt ref.
692       lag_index = 5;
693       if (base_count > 0) {
694         lag_index = 5 + (base_count % 3);
695         if (frame_cnt % 2 != 0) lag_index = 5 + ((base_count + 1) % 3);
696       }
697       // Set the altref slot to lag_index.
698       ref_frame_config->ref_idx[6] = lag_index;
699       if (frame_cnt % 2 == 0) {
700         layer_id->temporal_layer_id = 0;
701         // Update LAST on layer 0, reference LAST.
702         ref_frame_config->refresh[0] = 1;
703         ref_frame_config->reference[0] = 1;
704         // Refresh lag_index slot, needed for lagging golen.
705         ref_frame_config->refresh[lag_index] = 1;
706         // Refresh GOLDEN every x base layer frames.
707         if (base_count % 32 == 0) ref_frame_config->refresh[3] = 1;
708       } else {
709         layer_id->temporal_layer_id = 1;
710         // No updates on layer 1, reference LAST (TL0).
711         ref_frame_config->reference[0] = 1;
712       }
713       // Always reference golden and altref on TL0.
714       if (layer_id->temporal_layer_id == 0) {
715         ref_frame_config->reference[3] = 1;
716         ref_frame_config->reference[6] = 1;
717       }
718     } else if (number_temporal_layers_ == 3 && number_spatial_layers_ == 1) {
719       // 3-layer:
720       //   1    3   5    7
721       //     2        6
722       // 0        4        8
723       if (multi_ref) {
724         // Keep golden fixed at slot 3.
725         ref_frame_config->ref_idx[3] = 3;
726         // Cyclically refresh slots 4, 5, 6, 7, for lag altref.
727         lag_index = 4 + (base_count % 4);
728         // Set the altref slot to lag_index.
729         ref_frame_config->ref_idx[6] = lag_index;
730       }
731       if (frame_cnt % 4 == 0) {
732         // Base layer.
733         layer_id->temporal_layer_id = 0;
734         // Update LAST on layer 0, reference LAST and GF.
735         ref_frame_config->refresh[0] = 1;
736         ref_frame_config->reference[3] = 1;
737         if (multi_ref) {
738           // Refresh GOLDEN every x ~10 base layer frames.
739           if (base_count % 10 == 0) ref_frame_config->refresh[3] = 1;
740           // Refresh lag_index slot, needed for lagging altref.
741           ref_frame_config->refresh[lag_index] = 1;
742         }
743       } else if ((frame_cnt - 1) % 4 == 0) {
744         layer_id->temporal_layer_id = 2;
745         // First top layer: no updates, only reference LAST (TL0).
746       } else if ((frame_cnt - 2) % 4 == 0) {
747         layer_id->temporal_layer_id = 1;
748         // Middle layer (TL1): update LAST2, only reference LAST (TL0).
749         ref_frame_config->refresh[1] = 1;
750       } else if ((frame_cnt - 3) % 4 == 0) {
751         layer_id->temporal_layer_id = 2;
752         // Second top layer: no updates, only reference LAST.
753         // Set buffer idx for LAST to slot 1, since that was the slot
754         // updated in previous frame. So LAST is TL1 frame.
755         ref_frame_config->ref_idx[0] = 1;
756         ref_frame_config->ref_idx[1] = 0;
757       }
758       if (multi_ref) {
759         // Every frame can reference GOLDEN AND ALTREF.
760         ref_frame_config->reference[3] = 1;
761         ref_frame_config->reference[6] = 1;
762       }
763     } else if (number_temporal_layers_ == 1 && number_spatial_layers_ == 2) {
764       layer_id->temporal_layer_id = 0;
765       if (layer_id->spatial_layer_id == 0) {
766         // Reference LAST, update LAST. Keep LAST and GOLDEN in slots 0 and 3.
767         ref_frame_config->ref_idx[0] = 0;
768         ref_frame_config->ref_idx[3] = 3;
769         ref_frame_config->refresh[0] = 1;
770       } else if (layer_id->spatial_layer_id == 1) {
771         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 3
772         // and GOLDEN to slot 0. Update slot 3 (LAST).
773         ref_frame_config->ref_idx[0] = 3;
774         ref_frame_config->ref_idx[3] = 0;
775         ref_frame_config->refresh[3] = 1;
776       }
777       // Reference GOLDEN.
778       if (layer_id->spatial_layer_id > 0) ref_frame_config->reference[3] = 1;
779     } else if (number_temporal_layers_ == 1 && number_spatial_layers_ == 3) {
780       // 3 spatial layers, 1 temporal.
781       // Note for this case , we set the buffer idx for all references to be
782       // either LAST or GOLDEN, which are always valid references, since decoder
783       // will check if any of the 7 references is valid scale in
784       // valid_ref_frame_size().
785       layer_id->temporal_layer_id = 0;
786       if (layer_id->spatial_layer_id == 0) {
787         // Reference LAST, update LAST. Set all other buffer_idx to 0.
788         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0;
789         ref_frame_config->refresh[0] = 1;
790       } else if (layer_id->spatial_layer_id == 1) {
791         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 1
792         // and GOLDEN (and all other refs) to slot 0.
793         // Update slot 1 (LAST).
794         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 0;
795         ref_frame_config->ref_idx[0] = 1;
796         ref_frame_config->refresh[1] = 1;
797       } else if (layer_id->spatial_layer_id == 2) {
798         // Reference LAST and GOLDEN. Set buffer_idx for LAST to slot 2
799         // and GOLDEN (and all other refs) to slot 1.
800         // Update slot 2 (LAST).
801         for (int i = 0; i < 7; i++) ref_frame_config->ref_idx[i] = 1;
802         ref_frame_config->ref_idx[0] = 2;
803         ref_frame_config->refresh[2] = 1;
804         if (multi_ref) {
805           ref_frame_config->ref_idx[6] = 7;
806           ref_frame_config->reference[6] = 1;
807           if (base_count % 10 == 0) ref_frame_config->refresh[7] = 1;
808         }
809       }
810       // Reference GOLDEN.
811       if (layer_id->spatial_layer_id > 0) ref_frame_config->reference[3] = 1;
812     } else if (number_temporal_layers_ == 3 && number_spatial_layers_ == 3) {
813       if (simulcast_mode) {
814         ref_config_simulcast3SL3TL(ref_frame_config, layer_id, is_key_frame,
815                                    superframe_cnt_);
816       } else {
817         ref_config_3SL3TL(ref_frame_config, layer_id, is_key_frame,
818                           superframe_cnt_);
819         // Allow for top spatial layer to use additional temporal reference.
820         // Additional reference is only updated on base temporal layer, every
821         // 10 TL0 frames here.
822         if (multi_ref && layer_id->spatial_layer_id == 2) {
823           ref_frame_config->ref_idx[6] = 7;
824           if (!is_key_frame) ref_frame_config->reference[6] = 1;
825           if (base_count % 10 == 0 && layer_id->temporal_layer_id == 0)
826             ref_frame_config->refresh[7] = 1;
827         }
828       }
829     }
830     // If the top spatial layer is first-time encoded in mid-sequence
831     // (i.e., dynamic_enable_disable_mode = 1), then don't predict from LAST,
832     // since it will have been last updated on first key frame (SL0) and so
833     // be different resolution from SL2.
834     if (dynamic_enable_disable_mode == 1 &&
835         layer_id->spatial_layer_id == number_spatial_layers_ - 1)
836       ref_frame_config->reference[0] = 0;
837     return layer_flags;
838   }
839 
initialize_svc(int number_temporal_layers,int number_spatial_layers,aom_svc_params * svc_params)840   virtual void initialize_svc(int number_temporal_layers,
841                               int number_spatial_layers,
842                               aom_svc_params *svc_params) {
843     svc_params->number_spatial_layers = number_spatial_layers;
844     svc_params->number_temporal_layers = number_temporal_layers;
845     for (int i = 0; i < number_temporal_layers * number_spatial_layers; ++i) {
846       svc_params->max_quantizers[i] = 60;
847       svc_params->min_quantizers[i] = 2;
848       svc_params->layer_target_bitrate[i] = target_layer_bitrate_[i];
849     }
850     // Do at most 3 spatial or temporal layers here.
851     svc_params->framerate_factor[0] = 1;
852     if (number_temporal_layers == 2) {
853       svc_params->framerate_factor[0] = 2;
854       svc_params->framerate_factor[1] = 1;
855     } else if (number_temporal_layers == 3) {
856       svc_params->framerate_factor[0] = 4;
857       svc_params->framerate_factor[1] = 2;
858       svc_params->framerate_factor[2] = 1;
859     }
860     svc_params->scaling_factor_num[0] = 1;
861     svc_params->scaling_factor_den[0] = 1;
862     if (number_spatial_layers == 2) {
863       svc_params->scaling_factor_num[0] = 1;
864       svc_params->scaling_factor_den[0] = 2;
865       svc_params->scaling_factor_num[1] = 1;
866       svc_params->scaling_factor_den[1] = 1;
867     } else if (number_spatial_layers == 3) {
868       svc_params->scaling_factor_num[0] = 1;
869       svc_params->scaling_factor_den[0] = 4;
870       svc_params->scaling_factor_num[1] = 1;
871       svc_params->scaling_factor_den[1] = 2;
872       svc_params->scaling_factor_num[2] = 1;
873       svc_params->scaling_factor_den[2] = 1;
874     }
875   }
876 
BasicRateTargetingSVC3TL1SLTest()877   virtual void BasicRateTargetingSVC3TL1SLTest() {
878     cfg_.rc_buf_initial_sz = 500;
879     cfg_.rc_buf_optimal_sz = 500;
880     cfg_.rc_buf_sz = 1000;
881     cfg_.rc_dropframe_thresh = 0;
882     cfg_.rc_min_quantizer = 0;
883     cfg_.rc_max_quantizer = 63;
884     cfg_.rc_end_usage = AOM_CBR;
885     cfg_.g_lag_in_frames = 0;
886     cfg_.g_error_resilient = 1;
887 
888     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
889                                          288, 30, 1, 0, 300);
890     const int bitrate_array[2] = { 200, 550 };
891     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
892     ResetModel();
893     number_temporal_layers_ = 3;
894     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
895     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
896     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
897     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
898     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
899       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
900           << " The datarate for the file is lower than target by too much!";
901       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
902           << " The datarate for the file is greater than target by too much!";
903     }
904     // Top temporal layers are non_reference, so exlcude them from
905     // mismatch count, since loopfilter/cdef is not applied for these on
906     // encoder side, but is always applied on decoder.
907     // This means 150 = #frames(300) - #TL2_frames(150).
908     EXPECT_EQ((int)GetMismatchFrames(), 150);
909   }
910 
SetFrameQpSVC3TL1SLTest()911   virtual void SetFrameQpSVC3TL1SLTest() {
912     cfg_.rc_buf_initial_sz = 500;
913     cfg_.rc_buf_optimal_sz = 500;
914     cfg_.rc_buf_sz = 1000;
915     cfg_.rc_dropframe_thresh = 0;
916     cfg_.rc_min_quantizer = 0;
917     cfg_.rc_max_quantizer = 63;
918     cfg_.rc_end_usage = AOM_CBR;
919     cfg_.g_lag_in_frames = 0;
920     cfg_.g_error_resilient = 1;
921 
922     user_define_frame_qp_ = 1;
923     total_frame_ = 300;
924 
925     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
926                                          288, 30, 1, 0, 300);
927     const int bitrate_array[2] = { 200, 550 };
928     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
929     ResetModel();
930     number_temporal_layers_ = 3;
931     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
932     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
933     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
934     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
935   }
936 
SetFrameQpSVC3TL3SLTest()937   virtual void SetFrameQpSVC3TL3SLTest() {
938     cfg_.rc_buf_initial_sz = 500;
939     cfg_.rc_buf_optimal_sz = 500;
940     cfg_.rc_buf_sz = 1000;
941     cfg_.rc_dropframe_thresh = 0;
942     cfg_.rc_min_quantizer = 0;
943     cfg_.rc_max_quantizer = 63;
944     cfg_.rc_end_usage = AOM_CBR;
945     cfg_.g_lag_in_frames = 0;
946     cfg_.g_error_resilient = 0;
947 
948     user_define_frame_qp_ = 1;
949     total_frame_ = 300;
950 
951     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
952                                          288, 30, 1, 0, 300);
953     const int bitrate_array[2] = { 600, 1200 };
954     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
955     ResetModel();
956     number_temporal_layers_ = 3;
957     number_spatial_layers_ = 3;
958     // SL0
959     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
960     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
961     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
962     target_layer_bitrate_[2] = bitrate_sl0;
963     // SL1
964     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
965     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
966     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
967     target_layer_bitrate_[5] = bitrate_sl1;
968     // SL2
969     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
970     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
971     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
972     target_layer_bitrate_[8] = bitrate_sl2;
973     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
974   }
975 
BasicRateTargetingSVC3TL1SLScreenTest()976   virtual void BasicRateTargetingSVC3TL1SLScreenTest() {
977     cfg_.rc_buf_initial_sz = 500;
978     cfg_.rc_buf_optimal_sz = 500;
979     cfg_.rc_buf_sz = 1000;
980     cfg_.rc_dropframe_thresh = 0;
981     cfg_.rc_min_quantizer = 0;
982     cfg_.rc_max_quantizer = 63;
983     cfg_.rc_end_usage = AOM_CBR;
984     cfg_.g_lag_in_frames = 0;
985     cfg_.g_error_resilient = 0;
986 
987     ::libaom_test::Y4mVideoSource video("screendata.y4m", 0, 60);
988 
989     const int bitrate_array[2] = { 800, 1200 };
990     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
991     ResetModel();
992     screen_mode_ = 1;
993     number_temporal_layers_ = 3;
994     number_spatial_layers_ = 1;
995     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
996     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
997     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
998     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
999     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1000       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.50)
1001           << " The datarate for the file is lower than target by too much!";
1002       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.7)
1003           << " The datarate for the file is greater than target by too much!";
1004     }
1005     // Top temporal layers are non_reference, so exlcude them from
1006     // mismatch count, since loopfilter/cdef is not applied for these on
1007     // encoder side, but is always applied on decoder.
1008     // This means 30 = #frames(60) - #TL2_frames(30).
1009     // We use LE for screen since loopfilter level can become very small
1010     // or zero and then the frame is not a mismatch.
1011     EXPECT_LE((int)GetMismatchFrames(), 30);
1012   }
1013 
BasicRateTargetingSVC2TL1SLScreenDropFrameTest()1014   virtual void BasicRateTargetingSVC2TL1SLScreenDropFrameTest() {
1015     cfg_.rc_buf_initial_sz = 500;
1016     cfg_.rc_buf_optimal_sz = 500;
1017     cfg_.rc_buf_sz = 1000;
1018     cfg_.rc_dropframe_thresh = 30;
1019     cfg_.rc_min_quantizer = 0;
1020     cfg_.rc_max_quantizer = 52;
1021     cfg_.rc_end_usage = AOM_CBR;
1022     cfg_.g_lag_in_frames = 0;
1023     cfg_.g_error_resilient = 0;
1024 
1025     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1026                                          288, 30, 1, 0, 300);
1027 
1028     const int bitrate_array[2] = { 60, 100 };
1029     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1030     ResetModel();
1031     screen_mode_ = 1;
1032     number_temporal_layers_ = 2;
1033     number_spatial_layers_ = 1;
1034     target_layer_bitrate_[0] = 60 * cfg_.rc_target_bitrate / 100;
1035     target_layer_bitrate_[1] = cfg_.rc_target_bitrate;
1036     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1037     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1038       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.75)
1039           << " The datarate for the file is lower than target by too much!";
1040       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.5)
1041           << " The datarate for the file is greater than target by too much!";
1042     }
1043     // Top temporal layers are non_reference, so exlcude them from
1044     // mismatch count, since loopfilter/cdef is not applied for these on
1045     // encoder side, but is always applied on decoder.
1046     // This means 300 = #frames(300) - #TL2_frames(150).
1047     // We use LE for screen since loopfilter level can become very small
1048     // or zero and then the frame is not a mismatch.
1049     EXPECT_LE((int)GetMismatchFrames(), 150);
1050   }
1051 
BasicRateTargetingSVC1TL3SLScreenTest()1052   virtual void BasicRateTargetingSVC1TL3SLScreenTest() {
1053     cfg_.rc_buf_initial_sz = 500;
1054     cfg_.rc_buf_optimal_sz = 500;
1055     cfg_.rc_buf_sz = 1000;
1056     cfg_.rc_dropframe_thresh = 0;
1057     cfg_.rc_min_quantizer = 0;
1058     cfg_.rc_max_quantizer = 63;
1059     cfg_.rc_end_usage = AOM_CBR;
1060     cfg_.g_lag_in_frames = 0;
1061     cfg_.g_error_resilient = 0;
1062 
1063     ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
1064 
1065     const int bitrate_array[2] = { 800, 1200 };
1066     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1067     ResetModel();
1068     screen_mode_ = 1;
1069     number_temporal_layers_ = 1;
1070     number_spatial_layers_ = 3;
1071     target_layer_bitrate_[0] = 30 * cfg_.rc_target_bitrate / 100;
1072     target_layer_bitrate_[1] = 60 * cfg_.rc_target_bitrate / 100;
1073     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
1074     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1075     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1076       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.50)
1077           << " The datarate for the file is lower than target by too much!";
1078       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.5)
1079           << " The datarate for the file is greater than target by too much!";
1080     }
1081     EXPECT_EQ((int)GetMismatchFrames(), 0);
1082   }
1083 
BasicRateTargetingSVC1TL1SLScreenScCutsMotionTest()1084   virtual void BasicRateTargetingSVC1TL1SLScreenScCutsMotionTest() {
1085     cfg_.rc_buf_initial_sz = 500;
1086     cfg_.rc_buf_optimal_sz = 500;
1087     cfg_.rc_buf_sz = 1000;
1088     cfg_.rc_dropframe_thresh = 0;
1089     cfg_.rc_min_quantizer = 0;
1090     cfg_.rc_max_quantizer = 63;
1091     cfg_.rc_end_usage = AOM_CBR;
1092     cfg_.g_lag_in_frames = 0;
1093     cfg_.g_error_resilient = 0;
1094 
1095     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1096                                          288, 30, 1, 0, 300);
1097 
1098     const int bitrate_array[2] = { 200, 500 };
1099     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1100     ResetModel();
1101     screen_mode_ = 1;
1102     number_temporal_layers_ = 1;
1103     number_spatial_layers_ = 1;
1104     target_layer_bitrate_[0] = cfg_.rc_target_bitrate;
1105     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1106     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1107       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.40)
1108           << " The datarate for the file is lower than target by too much!";
1109       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.7)
1110           << " The datarate for the file is greater than target by too much!";
1111     }
1112     EXPECT_EQ((int)GetMismatchFrames(), 0);
1113   }
1114 
BasicRateTargetingSVC3TL1SLResizeTest()1115   virtual void BasicRateTargetingSVC3TL1SLResizeTest() {
1116     cfg_.rc_buf_initial_sz = 500;
1117     cfg_.rc_buf_optimal_sz = 500;
1118     cfg_.rc_buf_sz = 1000;
1119     cfg_.rc_dropframe_thresh = 0;
1120     cfg_.rc_min_quantizer = 0;
1121     cfg_.rc_max_quantizer = 63;
1122     cfg_.rc_end_usage = AOM_CBR;
1123     cfg_.g_lag_in_frames = 0;
1124     cfg_.g_error_resilient = 0;
1125     cfg_.rc_resize_mode = RESIZE_DYNAMIC;
1126 
1127     ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30,
1128                                          1, 0, 400);
1129     cfg_.g_w = 640;
1130     cfg_.g_h = 480;
1131     const int bitrate_array[2] = { 80, 90 };
1132     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1133     ResetModel();
1134     number_temporal_layers_ = 3;
1135     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
1136     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
1137     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
1138     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1139     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1140       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.80)
1141           << " The datarate for the file is lower than target by too much!";
1142       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
1143           << " The datarate for the file is greater than target by too much!";
1144     }
1145     unsigned int last_w = cfg_.g_w;
1146     unsigned int last_h = cfg_.g_h;
1147     int resize_down_count = 0;
1148     for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
1149          info != frame_info_list_.end(); ++info) {
1150       if (info->w != last_w || info->h != last_h) {
1151         // Verify that resize down occurs.
1152         ASSERT_LT(info->w, last_w);
1153         ASSERT_LT(info->h, last_h);
1154         last_w = info->w;
1155         last_h = info->h;
1156         resize_down_count++;
1157       }
1158     }
1159     // Must be at least one resize down.
1160     ASSERT_GE(resize_down_count, 1);
1161   }
1162 
BasicRateTargetingSVC1TL2SLTest()1163   virtual void BasicRateTargetingSVC1TL2SLTest() {
1164     cfg_.rc_buf_initial_sz = 500;
1165     cfg_.rc_buf_optimal_sz = 500;
1166     cfg_.rc_buf_sz = 1000;
1167     cfg_.rc_dropframe_thresh = 0;
1168     cfg_.rc_min_quantizer = 0;
1169     cfg_.rc_max_quantizer = 63;
1170     cfg_.rc_end_usage = AOM_CBR;
1171     cfg_.g_lag_in_frames = 0;
1172     cfg_.g_error_resilient = 0;
1173 
1174     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1175                                          288, 30, 1, 0, 300);
1176     const int bitrate_array[2] = { 300, 600 };
1177     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1178     ResetModel();
1179     number_temporal_layers_ = 1;
1180     number_spatial_layers_ = 2;
1181     target_layer_bitrate_[0] = 2 * cfg_.rc_target_bitrate / 4;
1182     target_layer_bitrate_[1] = 2 * cfg_.rc_target_bitrate / 4;
1183     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1184     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1185       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.80)
1186           << " The datarate for the file is lower than target by too much!";
1187       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
1188           << " The datarate for the file is greater than target by too much!";
1189     }
1190   }
1191 
BasicRateTargetingSVC3TL3SLIntraStartDecodeBaseMidSeq()1192   virtual void BasicRateTargetingSVC3TL3SLIntraStartDecodeBaseMidSeq() {
1193     cfg_.rc_buf_initial_sz = 500;
1194     cfg_.rc_buf_optimal_sz = 500;
1195     cfg_.rc_buf_sz = 1000;
1196     cfg_.rc_dropframe_thresh = 0;
1197     cfg_.rc_min_quantizer = 0;
1198     cfg_.rc_max_quantizer = 56;
1199     cfg_.rc_end_usage = AOM_CBR;
1200     cfg_.g_lag_in_frames = 0;
1201     cfg_.g_error_resilient = 0;
1202     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1203                                          288, 30, 1, 0, 300);
1204     const int bitrate_array[2] = { 500, 1000 };
1205     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1206     ResetModel();
1207     intra_only_ = 1;
1208     frame_sync_ = 20;
1209     frame_to_start_decoding_ = frame_sync_;
1210     layer_to_decode_ = 0;
1211     number_temporal_layers_ = 3;
1212     number_spatial_layers_ = 3;
1213     // SL0
1214     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1215     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1216     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1217     target_layer_bitrate_[2] = bitrate_sl0;
1218     // SL1
1219     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1220     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1221     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1222     target_layer_bitrate_[5] = bitrate_sl1;
1223     // SL2
1224     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1225     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1226     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1227     target_layer_bitrate_[8] = bitrate_sl2;
1228     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1229     // Only check datarate on SL0 - this is layer that is decoded starting at
1230     // frame_to_start_decoding_.
1231     for (int i = 0; i < number_temporal_layers_; i++) {
1232       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.50)
1233           << " The datarate for the file is lower than target by too much!";
1234       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
1235           << " The datarate for the file is greater than target by too much!";
1236     }
1237     // Only base spatial layer is decoded and there are no non-referenece
1238     // frames on S0, so #mismatch must be 0.
1239     EXPECT_EQ((int)GetMismatchFrames(), 0);
1240   }
1241 
BasicRateTargetingSVC3TL3SLIntraMidSeqDecodeAll()1242   virtual void BasicRateTargetingSVC3TL3SLIntraMidSeqDecodeAll() {
1243     cfg_.rc_buf_initial_sz = 500;
1244     cfg_.rc_buf_optimal_sz = 500;
1245     cfg_.rc_buf_sz = 1000;
1246     cfg_.rc_dropframe_thresh = 0;
1247     cfg_.rc_min_quantizer = 0;
1248     cfg_.rc_max_quantizer = 56;
1249     cfg_.rc_end_usage = AOM_CBR;
1250     cfg_.g_lag_in_frames = 0;
1251     cfg_.g_error_resilient = 0;
1252     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1253                                          288, 30, 1, 0, 300);
1254     const int bitrate_array[2] = { 500, 1000 };
1255     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1256     ResetModel();
1257     intra_only_ = 1;
1258     frame_sync_ = 20;
1259     frame_to_start_decoding_ = 0;
1260     layer_to_decode_ = 3;
1261     number_temporal_layers_ = 3;
1262     number_spatial_layers_ = 3;
1263     // SL0
1264     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1265     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1266     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1267     target_layer_bitrate_[2] = bitrate_sl0;
1268     // SL1
1269     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1270     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1271     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1272     target_layer_bitrate_[5] = bitrate_sl1;
1273     // SL2
1274     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1275     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1276     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1277     target_layer_bitrate_[8] = bitrate_sl2;
1278     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1279     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1280       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.585)
1281           << " The datarate for the file is lower than target by too much!";
1282       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
1283           << " The datarate for the file is greater than target by too much!";
1284     }
1285     // All 3 spatial layers are decoded, starting at frame 0, so there are
1286     // and there 300/2 = 150 non-reference frames, so mismatch is 150.
1287     EXPECT_EQ((int)GetMismatchFrames(), 150);
1288   }
1289 
BasicRateTargetingSVC3TL3SLSimulcast()1290   virtual void BasicRateTargetingSVC3TL3SLSimulcast() {
1291     cfg_.rc_buf_initial_sz = 500;
1292     cfg_.rc_buf_optimal_sz = 500;
1293     cfg_.rc_buf_sz = 1000;
1294     cfg_.rc_dropframe_thresh = 0;
1295     cfg_.rc_min_quantizer = 0;
1296     cfg_.rc_max_quantizer = 56;
1297     cfg_.rc_end_usage = AOM_CBR;
1298     cfg_.g_lag_in_frames = 0;
1299     cfg_.g_error_resilient = 0;
1300     cfg_.kf_max_dist = 150;
1301     cfg_.kf_min_dist = 150;
1302     int num_frames = 300;
1303     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1304                                          288, 30, 1, 0, num_frames);
1305     const int bitrate_array[2] = { 500, 1000 };
1306     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1307     ResetModel();
1308     simulcast_mode_ = 1;
1309     frame_to_start_decoding_ = cfg_.kf_max_dist;
1310     layer_to_decode_ = 2;  // SL2
1311     number_temporal_layers_ = 3;
1312     number_spatial_layers_ = 3;
1313     // SL0
1314     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1315     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1316     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1317     target_layer_bitrate_[2] = bitrate_sl0;
1318     // SL1
1319     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1320     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1321     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1322     target_layer_bitrate_[5] = bitrate_sl1;
1323     // SL2
1324     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1325     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1326     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1327     target_layer_bitrate_[8] = bitrate_sl2;
1328     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1329     // Only SL2 layer is decoded.
1330     for (int tl = 0; tl < number_temporal_layers_; tl++) {
1331       int i = layer_to_decode_ * number_temporal_layers_ + tl;
1332       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.6)
1333           << " The datarate for the file is lower than target by too much!";
1334       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.7)
1335           << " The datarate for the file is greater than target by too much!";
1336     }
1337     // Only top spatial layer (SL2) is decoded, starting at frame 150
1338     // (frame_to_start_decoding_), so there (300 - 150) / 2 = 75
1339     // non-reference frames, so mismatch is 75.
1340     int num_mismatch = (num_frames - frame_to_start_decoding_) / 2;
1341     EXPECT_EQ((int)GetMismatchFrames(), num_mismatch);
1342   }
1343 
BasicRateTargetingSVC1TL2SLIntraOnlyTest()1344   virtual void BasicRateTargetingSVC1TL2SLIntraOnlyTest() {
1345     cfg_.rc_buf_initial_sz = 500;
1346     cfg_.rc_buf_optimal_sz = 500;
1347     cfg_.rc_buf_sz = 1000;
1348     cfg_.rc_dropframe_thresh = 0;
1349     cfg_.rc_min_quantizer = 0;
1350     cfg_.rc_max_quantizer = 63;
1351     cfg_.rc_end_usage = AOM_CBR;
1352     cfg_.g_lag_in_frames = 0;
1353     cfg_.g_error_resilient = 0;
1354 
1355     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1356                                          288, 30, 1, 0, 300);
1357     const int bitrate_array[2] = { 300, 600 };
1358     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1359     ResetModel();
1360     intra_only_ = 1;
1361     number_temporal_layers_ = 1;
1362     number_spatial_layers_ = 2;
1363     target_layer_bitrate_[0] = 2 * cfg_.rc_target_bitrate / 4;
1364     target_layer_bitrate_[1] = 2 * cfg_.rc_target_bitrate / 4;
1365     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1366     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1367       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.80)
1368           << " The datarate for the file is lower than target by too much!";
1369       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
1370           << " The datarate for the file is greater than target by too much!";
1371     }
1372   }
1373 
BasicRateTargetingSVC1TL3SLTest()1374   virtual void BasicRateTargetingSVC1TL3SLTest() {
1375     cfg_.rc_buf_initial_sz = 500;
1376     cfg_.rc_buf_optimal_sz = 500;
1377     cfg_.rc_buf_sz = 1000;
1378     cfg_.rc_dropframe_thresh = 0;
1379     cfg_.rc_min_quantizer = 0;
1380     cfg_.rc_max_quantizer = 63;
1381     cfg_.rc_end_usage = AOM_CBR;
1382     cfg_.g_lag_in_frames = 0;
1383     cfg_.g_error_resilient = 0;
1384 
1385     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1386                                          288, 30, 1, 0, 300);
1387     const int bitrate_array[2] = { 500, 1000 };
1388     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1389     ResetModel();
1390     number_temporal_layers_ = 1;
1391     number_spatial_layers_ = 3;
1392     target_layer_bitrate_[0] = 1 * cfg_.rc_target_bitrate / 8;
1393     target_layer_bitrate_[1] = 3 * cfg_.rc_target_bitrate / 8;
1394     target_layer_bitrate_[2] = 4 * cfg_.rc_target_bitrate / 8;
1395     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1396     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1397       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.80)
1398           << " The datarate for the file is lower than target by too much!";
1399       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.38)
1400           << " The datarate for the file is greater than target by too much!";
1401     }
1402   }
1403 
BasicRateTargetingSVC1TL3SLMultiRefTest()1404   virtual void BasicRateTargetingSVC1TL3SLMultiRefTest() {
1405     cfg_.rc_buf_initial_sz = 500;
1406     cfg_.rc_buf_optimal_sz = 500;
1407     cfg_.rc_buf_sz = 1000;
1408     cfg_.rc_dropframe_thresh = 0;
1409     cfg_.rc_min_quantizer = 0;
1410     cfg_.rc_max_quantizer = 63;
1411     cfg_.rc_end_usage = AOM_CBR;
1412     cfg_.g_lag_in_frames = 0;
1413     cfg_.g_error_resilient = 0;
1414 
1415     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1416                                          288, 30, 1, 0, 300);
1417     const int bitrate_array[2] = { 500, 1000 };
1418     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1419     ResetModel();
1420     multi_ref_ = 1;
1421     number_temporal_layers_ = 1;
1422     number_spatial_layers_ = 3;
1423     target_layer_bitrate_[0] = 1 * cfg_.rc_target_bitrate / 8;
1424     target_layer_bitrate_[1] = 3 * cfg_.rc_target_bitrate / 8;
1425     target_layer_bitrate_[2] = 4 * cfg_.rc_target_bitrate / 8;
1426     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1427     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1428       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.80)
1429           << " The datarate for the file is lower than target by too much!";
1430       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.38)
1431           << " The datarate for the file is greater than target by too much!";
1432     }
1433   }
1434 
BasicRateTargetingSVC3TL3SLTest()1435   virtual void BasicRateTargetingSVC3TL3SLTest() {
1436     cfg_.rc_buf_initial_sz = 500;
1437     cfg_.rc_buf_optimal_sz = 500;
1438     cfg_.rc_buf_sz = 1000;
1439     cfg_.rc_dropframe_thresh = 0;
1440     cfg_.rc_min_quantizer = 0;
1441     cfg_.rc_max_quantizer = 63;
1442     cfg_.rc_end_usage = AOM_CBR;
1443     cfg_.g_lag_in_frames = 0;
1444     cfg_.g_error_resilient = 0;
1445 
1446     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1447                                          288, 30, 1, 0, 300);
1448     const int bitrate_array[2] = { 600, 1200 };
1449     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1450     ResetModel();
1451     number_temporal_layers_ = 3;
1452     number_spatial_layers_ = 3;
1453     // SL0
1454     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1455     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1456     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1457     target_layer_bitrate_[2] = bitrate_sl0;
1458     // SL1
1459     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1460     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1461     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1462     target_layer_bitrate_[5] = bitrate_sl1;
1463     // SL2
1464     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1465     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1466     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1467     target_layer_bitrate_[8] = bitrate_sl2;
1468     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1469     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1470       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.50)
1471           << " The datarate for the file is lower than target by too much!";
1472       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.38)
1473           << " The datarate for the file is greater than target by too much!";
1474     }
1475   }
1476 
BasicRateTargetingSVC3TL3SLHDTest()1477   virtual void BasicRateTargetingSVC3TL3SLHDTest() {
1478     cfg_.rc_buf_initial_sz = 500;
1479     cfg_.rc_buf_optimal_sz = 500;
1480     cfg_.rc_buf_sz = 1000;
1481     cfg_.rc_dropframe_thresh = 0;
1482     cfg_.rc_min_quantizer = 0;
1483     cfg_.rc_max_quantizer = 63;
1484     cfg_.rc_end_usage = AOM_CBR;
1485     cfg_.g_lag_in_frames = 0;
1486     cfg_.g_error_resilient = 0;
1487 
1488     ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
1489     const int bitrate_array[2] = { 600, 1200 };
1490     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1491     ResetModel();
1492     number_temporal_layers_ = 3;
1493     number_spatial_layers_ = 3;
1494     // SL0
1495     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1496     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1497     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1498     target_layer_bitrate_[2] = bitrate_sl0;
1499     // SL1
1500     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1501     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1502     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1503     target_layer_bitrate_[5] = bitrate_sl1;
1504     // SL2
1505     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1506     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1507     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1508     target_layer_bitrate_[8] = bitrate_sl2;
1509     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1510     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1511       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.70)
1512           << " The datarate for the file is lower than target by too much!";
1513       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.45)
1514           << " The datarate for the file is greater than target by too much!";
1515     }
1516   }
1517 
BasicRateTargetingFixedModeSVC3TL3SLHDTest()1518   virtual void BasicRateTargetingFixedModeSVC3TL3SLHDTest() {
1519     cfg_.rc_buf_initial_sz = 500;
1520     cfg_.rc_buf_optimal_sz = 500;
1521     cfg_.rc_buf_sz = 1000;
1522     cfg_.rc_dropframe_thresh = 0;
1523     cfg_.rc_min_quantizer = 0;
1524     cfg_.rc_max_quantizer = 63;
1525     cfg_.rc_end_usage = AOM_CBR;
1526     cfg_.g_lag_in_frames = 0;
1527     cfg_.g_error_resilient = 0;
1528 
1529     ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
1530     const int bitrate_array[2] = { 600, 1200 };
1531     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1532     ResetModel();
1533     number_temporal_layers_ = 3;
1534     number_spatial_layers_ = 3;
1535     use_fixed_mode_svc_ = 1;
1536     // SL0
1537     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1538     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1539     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1540     target_layer_bitrate_[2] = bitrate_sl0;
1541     // SL1
1542     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1543     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1544     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1545     target_layer_bitrate_[5] = bitrate_sl1;
1546     // SL2
1547     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1548     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1549     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1550     target_layer_bitrate_[8] = bitrate_sl2;
1551     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1552     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1553       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.70)
1554           << " The datarate for the file is lower than target by too much!";
1555       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.45)
1556           << " The datarate for the file is greater than target by too much!";
1557     }
1558   }
1559 
BasicRateTargetingSVC3TL3SLMultiThreadSpeedPerLayerTest()1560   virtual void BasicRateTargetingSVC3TL3SLMultiThreadSpeedPerLayerTest() {
1561     cfg_.rc_buf_initial_sz = 500;
1562     cfg_.rc_buf_optimal_sz = 500;
1563     cfg_.rc_buf_sz = 1000;
1564     cfg_.rc_dropframe_thresh = 0;
1565     cfg_.rc_min_quantizer = 0;
1566     cfg_.rc_max_quantizer = 63;
1567     cfg_.rc_end_usage = AOM_CBR;
1568     cfg_.g_lag_in_frames = 0;
1569     cfg_.g_error_resilient = 0;
1570     cfg_.g_threads = 2;
1571     ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30,
1572                                          1, 0, 400);
1573     cfg_.g_w = 640;
1574     cfg_.g_h = 480;
1575     const int bitrate_array[2] = { 600, 1200 };
1576     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1577     ResetModel();
1578     set_speed_per_layer_ = true;
1579     number_temporal_layers_ = 3;
1580     number_spatial_layers_ = 3;
1581     // SL0
1582     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1583     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1584     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1585     target_layer_bitrate_[2] = bitrate_sl0;
1586     // SL1
1587     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1588     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1589     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1590     target_layer_bitrate_[5] = bitrate_sl1;
1591     // SL2
1592     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1593     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1594     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1595     target_layer_bitrate_[8] = bitrate_sl2;
1596     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1597     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1598       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.70)
1599           << " The datarate for the file is lower than target by too much!";
1600       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.45)
1601           << " The datarate for the file is greater than target by too much!";
1602     }
1603   }
1604 
BasicRateTargetingSVC3TL3SLHDMultiThread2Test()1605   virtual void BasicRateTargetingSVC3TL3SLHDMultiThread2Test() {
1606     cfg_.rc_buf_initial_sz = 500;
1607     cfg_.rc_buf_optimal_sz = 500;
1608     cfg_.rc_buf_sz = 1000;
1609     cfg_.rc_dropframe_thresh = 0;
1610     cfg_.rc_min_quantizer = 0;
1611     cfg_.rc_max_quantizer = 63;
1612     cfg_.rc_end_usage = AOM_CBR;
1613     cfg_.g_lag_in_frames = 0;
1614     cfg_.g_error_resilient = 0;
1615     cfg_.g_threads = 2;
1616 
1617     ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
1618     const int bitrate_array[2] = { 600, 1200 };
1619     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1620     ResetModel();
1621     number_temporal_layers_ = 3;
1622     number_spatial_layers_ = 3;
1623     // SL0
1624     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1625     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1626     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1627     target_layer_bitrate_[2] = bitrate_sl0;
1628     // SL1
1629     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1630     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1631     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1632     target_layer_bitrate_[5] = bitrate_sl1;
1633     // SL2
1634     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1635     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1636     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1637     target_layer_bitrate_[8] = bitrate_sl2;
1638     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1639     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1640       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.70)
1641           << " The datarate for the file is lower than target by too much!";
1642       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.45)
1643           << " The datarate for the file is greater than target by too much!";
1644     }
1645   }
1646 
BasicRateTargetingSVC3TL3SLHDMultiThread4Test()1647   virtual void BasicRateTargetingSVC3TL3SLHDMultiThread4Test() {
1648     cfg_.rc_buf_initial_sz = 500;
1649     cfg_.rc_buf_optimal_sz = 500;
1650     cfg_.rc_buf_sz = 1000;
1651     cfg_.rc_dropframe_thresh = 0;
1652     cfg_.rc_min_quantizer = 0;
1653     cfg_.rc_max_quantizer = 63;
1654     cfg_.rc_end_usage = AOM_CBR;
1655     cfg_.g_lag_in_frames = 0;
1656     cfg_.g_error_resilient = 0;
1657     cfg_.g_threads = 4;
1658 
1659     ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
1660     const int bitrate_array[2] = { 600, 1200 };
1661     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1662     ResetModel();
1663     number_temporal_layers_ = 3;
1664     number_spatial_layers_ = 3;
1665     // SL0
1666     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1667     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1668     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1669     target_layer_bitrate_[2] = bitrate_sl0;
1670     // SL1
1671     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1672     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1673     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1674     target_layer_bitrate_[5] = bitrate_sl1;
1675     // SL2
1676     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1677     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1678     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1679     target_layer_bitrate_[8] = bitrate_sl2;
1680     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1681     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1682       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.70)
1683           << " The datarate for the file is lower than target by too much!";
1684       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.45)
1685           << " The datarate for the file is greater than target by too much!";
1686     }
1687   }
1688 
BasicRateTargetingSVC3TL3SLHDMultiRefTest()1689   virtual void BasicRateTargetingSVC3TL3SLHDMultiRefTest() {
1690     cfg_.rc_buf_initial_sz = 500;
1691     cfg_.rc_buf_optimal_sz = 500;
1692     cfg_.rc_buf_sz = 1000;
1693     cfg_.rc_dropframe_thresh = 0;
1694     cfg_.rc_min_quantizer = 0;
1695     cfg_.rc_max_quantizer = 63;
1696     cfg_.rc_end_usage = AOM_CBR;
1697     cfg_.g_lag_in_frames = 0;
1698     cfg_.g_error_resilient = 0;
1699 
1700     ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
1701     const int bitrate_array[2] = { 600, 1200 };
1702     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1703     ResetModel();
1704     multi_ref_ = 1;
1705     number_temporal_layers_ = 3;
1706     number_spatial_layers_ = 3;
1707     // SL0
1708     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1709     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1710     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1711     target_layer_bitrate_[2] = bitrate_sl0;
1712     // SL1
1713     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1714     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1715     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1716     target_layer_bitrate_[5] = bitrate_sl1;
1717     // SL2
1718     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1719     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1720     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1721     target_layer_bitrate_[8] = bitrate_sl2;
1722     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1723     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1724       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.70)
1725           << " The datarate for the file is lower than target by too much!";
1726       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.45)
1727           << " The datarate for the file is greater than target by too much!";
1728     }
1729   }
1730 
BasicRateTargetingSVC3TL3SLKfTest()1731   virtual void BasicRateTargetingSVC3TL3SLKfTest() {
1732     cfg_.rc_buf_initial_sz = 500;
1733     cfg_.rc_buf_optimal_sz = 500;
1734     cfg_.rc_buf_sz = 1000;
1735     cfg_.rc_dropframe_thresh = 0;
1736     cfg_.rc_min_quantizer = 0;
1737     cfg_.rc_max_quantizer = 63;
1738     cfg_.rc_end_usage = AOM_CBR;
1739     cfg_.g_lag_in_frames = 0;
1740     cfg_.g_error_resilient = 0;
1741     cfg_.kf_mode = AOM_KF_AUTO;
1742     cfg_.kf_min_dist = cfg_.kf_max_dist = 100;
1743 
1744     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1745                                          288, 30, 1, 0, 300);
1746     const int bitrate_array[2] = { 600, 1200 };
1747     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1748     ResetModel();
1749     number_temporal_layers_ = 3;
1750     number_spatial_layers_ = 3;
1751     // SL0
1752     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1753     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1754     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1755     target_layer_bitrate_[2] = bitrate_sl0;
1756     // SL1
1757     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1758     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1759     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1760     target_layer_bitrate_[5] = bitrate_sl1;
1761     // SL2
1762     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1763     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1764     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1765     target_layer_bitrate_[8] = bitrate_sl2;
1766     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1767     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1768       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.55)
1769           << " The datarate for the file is lower than target by too much!";
1770       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.4)
1771           << " The datarate for the file is greater than target by too much!";
1772     }
1773   }
1774 
BasicRateTargeting444SVC3TL3SLTest()1775   virtual void BasicRateTargeting444SVC3TL3SLTest() {
1776     cfg_.rc_buf_initial_sz = 500;
1777     cfg_.rc_buf_optimal_sz = 500;
1778     cfg_.rc_buf_sz = 1000;
1779     cfg_.rc_dropframe_thresh = 0;
1780     cfg_.rc_min_quantizer = 0;
1781     cfg_.rc_max_quantizer = 63;
1782     cfg_.rc_end_usage = AOM_CBR;
1783     cfg_.g_lag_in_frames = 0;
1784     cfg_.g_error_resilient = 0;
1785     cfg_.g_profile = 1;
1786 
1787     ::libaom_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 140);
1788 
1789     const int bitrate_array[2] = { 600, 1200 };
1790     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1791     ResetModel();
1792     number_temporal_layers_ = 3;
1793     number_spatial_layers_ = 3;
1794     // SL0
1795     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
1796     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
1797     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
1798     target_layer_bitrate_[2] = bitrate_sl0;
1799     // SL1
1800     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
1801     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
1802     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
1803     target_layer_bitrate_[5] = bitrate_sl1;
1804     // SL2
1805     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
1806     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
1807     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
1808     target_layer_bitrate_[8] = bitrate_sl2;
1809     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1810     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1811       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.70)
1812           << " The datarate for the file is lower than target by too much!";
1813       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.38)
1814           << " The datarate for the file is greater than target by too much!";
1815     }
1816   }
1817 
BasicRateTargetingSVC3TL1SLMultiRefDropAllEnhTest()1818   virtual void BasicRateTargetingSVC3TL1SLMultiRefDropAllEnhTest() {
1819     cfg_.rc_buf_initial_sz = 500;
1820     cfg_.rc_buf_optimal_sz = 500;
1821     cfg_.rc_buf_sz = 1000;
1822     cfg_.rc_dropframe_thresh = 0;
1823     cfg_.rc_min_quantizer = 0;
1824     cfg_.rc_max_quantizer = 63;
1825     cfg_.rc_end_usage = AOM_CBR;
1826     cfg_.g_lag_in_frames = 0;
1827     // error_resilient can set to off/0, since for SVC the context update
1828     // is done per-layer.
1829     cfg_.g_error_resilient = 0;
1830 
1831     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1832                                          288, 30, 1, 0, 300);
1833     const int bitrate_array[2] = { 200, 550 };
1834     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1835     ResetModel();
1836     multi_ref_ = 1;
1837     // Drop TL1 and TL2: #frames(300) - #TL0.
1838     drop_frames_ = 300 - 300 / 4;
1839     int n = 0;
1840     for (int i = 0; i < 300; i++) {
1841       if (i % 4 != 0) {
1842         drop_frames_list_[n] = i;
1843         n++;
1844       }
1845     }
1846     number_temporal_layers_ = 3;
1847     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
1848     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
1849     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
1850     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1851     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1852       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
1853           << " The datarate for the file is lower than target by too much!";
1854       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
1855           << " The datarate for the file is greater than target by too much!";
1856     }
1857     // Test that no mismatches have been found.
1858     std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
1859     std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
1860     EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_);
1861     EXPECT_EQ((int)GetMismatchFrames(), 0);
1862   }
1863 
BasicRateTargetingSVC3TL1SLDropAllEnhTest()1864   virtual void BasicRateTargetingSVC3TL1SLDropAllEnhTest() {
1865     cfg_.rc_buf_initial_sz = 500;
1866     cfg_.rc_buf_optimal_sz = 500;
1867     cfg_.rc_buf_sz = 1000;
1868     cfg_.rc_dropframe_thresh = 0;
1869     cfg_.rc_min_quantizer = 0;
1870     cfg_.rc_max_quantizer = 63;
1871     cfg_.rc_end_usage = AOM_CBR;
1872     cfg_.g_lag_in_frames = 0;
1873     // error_resilient can set to off/0, since for SVC the context update
1874     // is done per-layer.
1875     cfg_.g_error_resilient = 0;
1876 
1877     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1878                                          288, 30, 1, 0, 300);
1879     const int bitrate_array[2] = { 200, 550 };
1880     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1881     ResetModel();
1882     // Drop TL1 and TL2: #frames(300) - #TL0.
1883     drop_frames_ = 300 - 300 / 4;
1884     int n = 0;
1885     for (int i = 0; i < 300; i++) {
1886       if (i % 4 != 0) {
1887         drop_frames_list_[n] = i;
1888         n++;
1889       }
1890     }
1891     number_temporal_layers_ = 3;
1892     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
1893     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
1894     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
1895     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1896     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1897       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
1898           << " The datarate for the file is lower than target by too much!";
1899       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
1900           << " The datarate for the file is greater than target by too much!";
1901     }
1902     // Test that no mismatches have been found.
1903     std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
1904     std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
1905     EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_);
1906     EXPECT_EQ((int)GetMismatchFrames(), 0);
1907   }
1908 
BasicRateTargetingSVC3TL1SLDropTL2EnhTest()1909   virtual void BasicRateTargetingSVC3TL1SLDropTL2EnhTest() {
1910     cfg_.rc_buf_initial_sz = 500;
1911     cfg_.rc_buf_optimal_sz = 500;
1912     cfg_.rc_buf_sz = 1000;
1913     cfg_.rc_dropframe_thresh = 0;
1914     cfg_.rc_min_quantizer = 0;
1915     cfg_.rc_max_quantizer = 63;
1916     cfg_.rc_end_usage = AOM_CBR;
1917     cfg_.g_lag_in_frames = 0;
1918     // error_resilient for sequence can be off/0, since dropped frames (TL2)
1919     // are non-reference frames.
1920     cfg_.g_error_resilient = 0;
1921 
1922     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1923                                          288, 30, 1, 0, 300);
1924     const int bitrate_array[2] = { 200, 550 };
1925     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1926     ResetModel();
1927     // Drop TL2: #frames(300) - (#TL0 + #TL1).
1928     drop_frames_ = 300 - 300 / 2;
1929     int n = 0;
1930     for (int i = 0; i < 300; i++) {
1931       if (i % 2 != 0) {
1932         drop_frames_list_[n] = i;
1933         n++;
1934       }
1935     }
1936     number_temporal_layers_ = 3;
1937     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
1938     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
1939     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
1940     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1941     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1942       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
1943           << " The datarate for the file is lower than target by too much!";
1944       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
1945           << " The datarate for the file is greater than target by too much!";
1946     }
1947     // Test that no mismatches have been found.
1948     std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
1949     std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
1950     EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_);
1951     EXPECT_EQ((int)GetMismatchFrames(), 0);
1952   }
1953 
BasicRateTargetingSVC3TL1SLDropAllEnhFrameERTest()1954   virtual void BasicRateTargetingSVC3TL1SLDropAllEnhFrameERTest() {
1955     cfg_.rc_buf_initial_sz = 500;
1956     cfg_.rc_buf_optimal_sz = 500;
1957     cfg_.rc_buf_sz = 1000;
1958     cfg_.rc_dropframe_thresh = 0;
1959     cfg_.rc_min_quantizer = 0;
1960     cfg_.rc_max_quantizer = 63;
1961     cfg_.rc_end_usage = AOM_CBR;
1962     cfg_.g_lag_in_frames = 0;
1963 
1964     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
1965                                          288, 30, 1, 0, 300);
1966     const int bitrate_array[2] = { 200, 550 };
1967     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
1968     ResetModel();
1969     // Set error_resilience at frame level, with codec control,
1970     // on/1 for enahancement layers and off/0 for base layer frames.
1971     set_frame_level_er_ = 1;
1972 
1973     // Drop TL1 and TL2: #frames(300) - #TL0.
1974     drop_frames_ = 300 - 300 / 4;
1975     int n = 0;
1976     for (int i = 0; i < 300; i++) {
1977       if (i % 4 != 0) {
1978         drop_frames_list_[n] = i;
1979         n++;
1980       }
1981     }
1982     number_temporal_layers_ = 3;
1983     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
1984     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
1985     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
1986     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1987     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
1988       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
1989           << " The datarate for the file is lower than target by too much!";
1990       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
1991           << " The datarate for the file is greater than target by too much!";
1992     }
1993     // Test that no mismatches have been found.
1994     std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
1995     std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
1996     EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_);
1997     EXPECT_EQ((int)GetMismatchFrames(), 0);
1998   }
1999 
BasicRateTargetingSVC3TL1SLDropSetEnhFrameERTest()2000   virtual void BasicRateTargetingSVC3TL1SLDropSetEnhFrameERTest() {
2001     cfg_.rc_buf_initial_sz = 500;
2002     cfg_.rc_buf_optimal_sz = 500;
2003     cfg_.rc_buf_sz = 1000;
2004     cfg_.rc_dropframe_thresh = 0;
2005     cfg_.rc_min_quantizer = 0;
2006     cfg_.rc_max_quantizer = 63;
2007     cfg_.rc_end_usage = AOM_CBR;
2008     cfg_.g_lag_in_frames = 0;
2009 
2010     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
2011                                          288, 30, 1, 0, 300);
2012     const int bitrate_array[2] = { 200, 550 };
2013     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
2014     ResetModel();
2015     // Set error_resilience at frame level, with codec control,
2016     // on/1 for enahancement layers and off/0 for base layer frames.
2017     set_frame_level_er_ = 1;
2018 
2019     // Drop TL1 and TL2: for part of sequence. Start at first TL2 at
2020     // frame 101, and end at second T2 at frame 199. Frame 200 is TL0,
2021     // so we can continue decoding without mismatch (since LAST is the
2022     // only reference and error_resilient = 1 on TL1/TL2 frames).
2023     int n = 0;
2024     int num_nonref = 300 / 2;
2025     for (int i = 101; i < 200; i++) {
2026       if (i % 4 != 0) {
2027         drop_frames_list_[n] = i;
2028         n++;
2029         if (i % 2 != 0) num_nonref -= 1;
2030       }
2031     }
2032     drop_frames_ = n;
2033     number_temporal_layers_ = 3;
2034     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
2035     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
2036     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
2037     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
2038     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
2039       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
2040           << " The datarate for the file is lower than target by too much!";
2041       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
2042           << " The datarate for the file is greater than target by too much!";
2043     }
2044     // Test that no mismatches have been found.
2045     std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
2046     std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
2047     EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_);
2048     EXPECT_EQ((int)GetMismatchFrames(), num_nonref);
2049   }
2050 
BasicRateTargetingSVC2TL1SLDropSetEnhER0Test()2051   virtual void BasicRateTargetingSVC2TL1SLDropSetEnhER0Test() {
2052     cfg_.rc_buf_initial_sz = 500;
2053     cfg_.rc_buf_optimal_sz = 500;
2054     cfg_.rc_buf_sz = 1000;
2055     cfg_.rc_dropframe_thresh = 0;
2056     cfg_.rc_min_quantizer = 0;
2057     cfg_.rc_max_quantizer = 63;
2058     cfg_.rc_end_usage = AOM_CBR;
2059     cfg_.g_lag_in_frames = 0;
2060 
2061     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
2062                                          288, 30, 1, 0, 300);
2063     const int bitrate_array[2] = { 200, 550 };
2064     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
2065     ResetModel();
2066 
2067     // Set error_resilience off.
2068     cfg_.g_error_resilient = 0;
2069 
2070     // Drop TL1: for part of sequence. Start at first TL1 at
2071     // frame 101, and end at frame 199. Frame 200 is TL0,
2072     // so we can continue decoding without mismatch (since LAST is the
2073     // only reference).
2074     int n = 0;
2075     int num_nonref = 300 / 2;
2076     for (int i = 101; i < 200; i++) {
2077       if (i % 2 != 0) {
2078         drop_frames_list_[n] = i;
2079         n++;
2080         if (i % 2 != 0) num_nonref -= 1;
2081       }
2082     }
2083     drop_frames_ = n;
2084     number_temporal_layers_ = 2;
2085     target_layer_bitrate_[0] = 70 * cfg_.rc_target_bitrate / 100;
2086     target_layer_bitrate_[1] = cfg_.rc_target_bitrate;
2087     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
2088     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
2089       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
2090           << " The datarate for the file is lower than target by too much!";
2091       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
2092           << " The datarate for the file is greater than target by too much!";
2093     }
2094     // Test that no mismatches have been found.
2095     std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
2096     std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
2097     EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_);
2098     EXPECT_EQ((int)GetMismatchFrames(), num_nonref);
2099   }
2100 
BasicRateTargetingSVC3TL1SLDropSetEnhER0Test()2101   virtual void BasicRateTargetingSVC3TL1SLDropSetEnhER0Test() {
2102     cfg_.rc_buf_initial_sz = 500;
2103     cfg_.rc_buf_optimal_sz = 500;
2104     cfg_.rc_buf_sz = 1000;
2105     cfg_.rc_dropframe_thresh = 0;
2106     cfg_.rc_min_quantizer = 0;
2107     cfg_.rc_max_quantizer = 63;
2108     cfg_.rc_end_usage = AOM_CBR;
2109     cfg_.g_lag_in_frames = 0;
2110 
2111     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
2112                                          288, 30, 1, 0, 300);
2113     const int bitrate_array[2] = { 200, 550 };
2114     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
2115     ResetModel();
2116 
2117     // Set error_resilience off.
2118     cfg_.g_error_resilient = 0;
2119 
2120     // Drop TL1 and TL2: for part of sequence. Start at first TL2 at
2121     // frame 101, and end at second T2 at frame 199. Frame 200 is TL0,
2122     // so we can continue decoding without mismatch (since LAST is the
2123     // only reference).
2124     int n = 0;
2125     int num_nonref = 300 / 2;
2126     for (int i = 101; i < 200; i++) {
2127       if (i % 4 != 0) {
2128         drop_frames_list_[n] = i;
2129         n++;
2130         if (i % 2 != 0) num_nonref -= 1;
2131       }
2132     }
2133     drop_frames_ = n;
2134     number_temporal_layers_ = 3;
2135     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
2136     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
2137     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
2138     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
2139     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
2140       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
2141           << " The datarate for the file is lower than target by too much!";
2142       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
2143           << " The datarate for the file is greater than target by too much!";
2144     }
2145     // Test that no mismatches have been found.
2146     std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
2147     std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
2148     EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_);
2149     EXPECT_EQ((int)GetMismatchFrames(), num_nonref);
2150   }
2151 
BasicRateTargetingSVC3TL3SLDropSetEnhER0Test()2152   virtual void BasicRateTargetingSVC3TL3SLDropSetEnhER0Test() {
2153     cfg_.rc_buf_initial_sz = 500;
2154     cfg_.rc_buf_optimal_sz = 500;
2155     cfg_.rc_buf_sz = 1000;
2156     cfg_.rc_dropframe_thresh = 0;
2157     cfg_.rc_min_quantizer = 0;
2158     cfg_.rc_max_quantizer = 63;
2159     cfg_.rc_end_usage = AOM_CBR;
2160     cfg_.g_lag_in_frames = 0;
2161     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
2162                                          288, 30, 1, 0, 300);
2163     const int bitrate_array[2] = { 200, 550 };
2164     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
2165     ResetModel();
2166     // Set error_resilience off.
2167     cfg_.g_error_resilient = 0;
2168     // Drop TL1 and TL2: for part of sequence. Start at first TL2 at
2169     // frame 101, and end at second T2 at frame 199. Frame 200 is TL0,
2170     // so we can continue decoding without mismatch (since LAST is the
2171     // only reference).
2172     // Drop here means drop whole superframe.
2173     int n = 0;
2174     int num_nonref = 300 / 2;
2175     for (int i = 101; i < 200; i++) {
2176       if (i % 4 != 0) {
2177         drop_frames_list_[n] = i;
2178         n++;
2179         if (i % 2 != 0) num_nonref -= 1;
2180       }
2181     }
2182     number_temporal_layers_ = 3;
2183     number_spatial_layers_ = 3;
2184     multi_ref_ = 1;
2185     drop_frames_ = n * number_spatial_layers_;
2186     // SL0
2187     const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
2188     target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
2189     target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
2190     target_layer_bitrate_[2] = bitrate_sl0;
2191     // SL1
2192     const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
2193     target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
2194     target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
2195     target_layer_bitrate_[5] = bitrate_sl1;
2196     // SL2
2197     const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
2198     target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
2199     target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
2200     target_layer_bitrate_[8] = bitrate_sl2;
2201     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
2202     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
2203       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
2204           << " The datarate for the file is lower than target by too much!";
2205       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
2206           << " The datarate for the file is greater than target by too much!";
2207     }
2208     // Test that no mismatches have been found.
2209     std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
2210     std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
2211     EXPECT_EQ(300 * number_spatial_layers_ - GetDecodedFrames(), drop_frames_);
2212     EXPECT_EQ((int)GetMismatchFrames(), num_nonref);
2213   }
2214 
BasicRateTargetingSVC3TL1SLMultiRefCompoundTest()2215   virtual void BasicRateTargetingSVC3TL1SLMultiRefCompoundTest() {
2216     cfg_.rc_buf_initial_sz = 500;
2217     cfg_.rc_buf_optimal_sz = 500;
2218     cfg_.rc_buf_sz = 1000;
2219     cfg_.rc_dropframe_thresh = 0;
2220     cfg_.rc_min_quantizer = 0;
2221     cfg_.rc_max_quantizer = 63;
2222     cfg_.rc_end_usage = AOM_CBR;
2223     cfg_.g_lag_in_frames = 0;
2224     cfg_.g_error_resilient = 0;
2225 
2226     ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30,
2227                                          1, 0, 400);
2228     cfg_.g_w = 640;
2229     cfg_.g_h = 480;
2230     const int bitrate_array[2] = { 400, 800 };
2231     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
2232     ResetModel();
2233     multi_ref_ = 1;
2234     comp_pred_ = 1;
2235     number_temporal_layers_ = 3;
2236     number_spatial_layers_ = 1;
2237     target_layer_bitrate_[0] = 50 * cfg_.rc_target_bitrate / 100;
2238     target_layer_bitrate_[1] = 70 * cfg_.rc_target_bitrate / 100;
2239     target_layer_bitrate_[2] = cfg_.rc_target_bitrate;
2240     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
2241     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
2242       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.80)
2243           << " The datarate for the file is lower than target by too much!";
2244       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
2245           << " The datarate for the file is greater than target by too much!";
2246     }
2247   }
2248 
BasicRateTargetingSVC1TL3SLDynEnablTest()2249   virtual void BasicRateTargetingSVC1TL3SLDynEnablTest() {
2250     cfg_.rc_buf_initial_sz = 500;
2251     cfg_.rc_buf_optimal_sz = 500;
2252     cfg_.rc_buf_sz = 1000;
2253     cfg_.rc_dropframe_thresh = 0;
2254     cfg_.rc_min_quantizer = 0;
2255     cfg_.rc_max_quantizer = 63;
2256     cfg_.rc_end_usage = AOM_CBR;
2257     cfg_.g_lag_in_frames = 0;
2258     cfg_.g_error_resilient = 0;
2259 
2260     ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30,
2261                                          1, 0, 400);
2262     const int bitrate_array[2] = { 500, 1000 };
2263     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
2264     ResetModel();
2265     number_temporal_layers_ = 1;
2266     number_spatial_layers_ = 3;
2267     target_layer_bitrate_[0] = 1 * cfg_.rc_target_bitrate / 8;
2268     target_layer_bitrate_[1] = 3 * cfg_.rc_target_bitrate / 8;
2269     target_layer_bitrate_[2] = 4 * cfg_.rc_target_bitrate / 8;
2270     dynamic_enable_disable_mode_ = 1;
2271     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
2272     // No need to check RC on top layer which is disabled part of the time.
2273     for (int i = 0; i < number_spatial_layers_ - 1; i++) {
2274       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.80)
2275           << " The datarate for the file is lower than target by too much!";
2276       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.38)
2277           << " The datarate for the file is greater than target by too much!";
2278     }
2279   }
2280 
BasicRateTargetingSVC1TL3SLDynDisEnablTest()2281   virtual void BasicRateTargetingSVC1TL3SLDynDisEnablTest() {
2282     cfg_.rc_buf_initial_sz = 500;
2283     cfg_.rc_buf_optimal_sz = 500;
2284     cfg_.rc_buf_sz = 1000;
2285     cfg_.rc_dropframe_thresh = 0;
2286     cfg_.rc_min_quantizer = 0;
2287     cfg_.rc_max_quantizer = 63;
2288     cfg_.rc_end_usage = AOM_CBR;
2289     cfg_.g_lag_in_frames = 0;
2290     cfg_.g_error_resilient = 0;
2291 
2292     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
2293                                          288, 30, 1, 0, 300);
2294     const int bitrate_array[2] = { 500, 1000 };
2295     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
2296     ResetModel();
2297     number_temporal_layers_ = 1;
2298     number_spatial_layers_ = 3;
2299     target_layer_bitrate_[0] = 1 * cfg_.rc_target_bitrate / 8;
2300     target_layer_bitrate_[1] = 3 * cfg_.rc_target_bitrate / 8;
2301     target_layer_bitrate_[2] = 4 * cfg_.rc_target_bitrate / 8;
2302     dynamic_enable_disable_mode_ = 2;
2303     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
2304     // No need to check RC on top layer which is disabled part of the time.
2305     for (int i = 0; i < number_spatial_layers_ - 1; i++) {
2306       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.80)
2307           << " The datarate for the file is lower than target by too much!";
2308       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.38)
2309           << " The datarate for the file is greater than target by too much!";
2310     }
2311   }
2312 
BasicRateTargetingRPS1TL1SLDropFramesTest()2313   virtual void BasicRateTargetingRPS1TL1SLDropFramesTest() {
2314     cfg_.rc_buf_initial_sz = 500;
2315     cfg_.rc_buf_optimal_sz = 500;
2316     cfg_.rc_buf_sz = 1000;
2317     cfg_.rc_dropframe_thresh = 0;
2318     cfg_.rc_min_quantizer = 0;
2319     cfg_.rc_max_quantizer = 63;
2320     cfg_.rc_end_usage = AOM_CBR;
2321     cfg_.g_lag_in_frames = 0;
2322 
2323     ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
2324                                          288, 30, 1, 0, 300);
2325     const int bitrate_array[2] = { 100, 300 };
2326     cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
2327     ResetModel();
2328     rps_mode_ = 1;
2329     rps_recovery_frame_ = 100;
2330     cfg_.g_error_resilient = 0;
2331     // Drop x frames before the recovery frames (where the reference
2332     // is switched to an older reference (golden or altref).
2333     // GOLDEN is 8 frames behind (for the rps pattern example) so we can't
2334     // drop more than 8 frames recovery frame, so choose x = 7.
2335     int n = 0;
2336     for (int i = rps_recovery_frame_ - 7; i < rps_recovery_frame_; i++) {
2337       drop_frames_list_[n] = i;
2338       n++;
2339     }
2340     drop_frames_ = n;
2341     number_spatial_layers_ = 1;
2342     number_temporal_layers_ = 1;
2343     target_layer_bitrate_[0] = cfg_.rc_target_bitrate;
2344     ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
2345     for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
2346       ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
2347           << " The datarate for the file is lower than target by too much!";
2348       ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.60)
2349           << " The datarate for the file is greater than target by too much!";
2350     }
2351     // Test that no mismatches have been found.
2352     std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
2353     std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
2354     EXPECT_EQ(300 - GetDecodedFrames(), drop_frames_);
2355     EXPECT_EQ((int)GetMismatchFrames(), 0);
2356   }
2357 
2358   int layer_frame_cnt_;
2359   int superframe_cnt_;
2360   int number_temporal_layers_;
2361   int number_spatial_layers_;
2362   // Allow for up to 3 temporal layers.
2363   int target_layer_bitrate_[AOM_MAX_LAYERS];
2364   aom_svc_params_t svc_params_;
2365   aom_svc_ref_frame_config_t ref_frame_config_;
2366   aom_svc_ref_frame_comp_pred_t ref_frame_comp_pred_;
2367   aom_svc_layer_id_t layer_id_;
2368   double effective_datarate_tl[AOM_MAX_LAYERS];
2369   unsigned int drop_frames_;
2370   unsigned int drop_frames_list_[1000];
2371   unsigned int mismatch_nframes_;
2372   unsigned int decoded_nframes_;
2373   double mismatch_psnr_;
2374   int set_frame_level_er_;
2375   int multi_ref_;
2376   int use_fixed_mode_svc_;
2377   int comp_pred_;
2378   int dynamic_enable_disable_mode_;
2379   int intra_only_;
2380   unsigned int frame_to_start_decoding_;
2381   unsigned int layer_to_decode_;
2382   unsigned int frame_sync_;
2383   unsigned int current_video_frame_;
2384   int screen_mode_;
2385   int rps_mode_;
2386   int rps_recovery_frame_;
2387   int simulcast_mode_;
2388 
2389   int user_define_frame_qp_;
2390   int frame_qp_;
2391   int total_frame_;
2392   bool set_speed_per_layer_;
2393   libaom_test::ACMRandom rnd_;
2394 };
2395 
2396 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL1SL)2397 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SL) {
2398   BasicRateTargetingSVC3TL1SLTest();
2399 }
2400 
TEST_P(DatarateTestSVC,SetFrameQpSVC3TL1SL)2401 TEST_P(DatarateTestSVC, SetFrameQpSVC3TL1SL) { SetFrameQpSVC3TL1SLTest(); }
2402 
TEST_P(DatarateTestSVC,SetFrameQpSVC3TL3SL)2403 TEST_P(DatarateTestSVC, SetFrameQpSVC3TL3SL) { SetFrameQpSVC3TL3SLTest(); }
2404 
2405 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial
2406 // for screen mode.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL1SLScreen)2407 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLScreen) {
2408   BasicRateTargetingSVC3TL1SLScreenTest();
2409 }
2410 
2411 // Check basic rate targeting for CBR, for 2 temporal layers, 1 spatial
2412 // for screen mode, with frame dropper on at low bitrates
TEST_P(DatarateTestSVC,BasicRateTargetingSVC2TL1SLScreenDropFrame)2413 TEST_P(DatarateTestSVC, BasicRateTargetingSVC2TL1SLScreenDropFrame) {
2414   BasicRateTargetingSVC2TL1SLScreenDropFrameTest();
2415 }
2416 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal
2417 // for screen mode.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC1TL3SLScreen)2418 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLScreen) {
2419   BasicRateTargetingSVC1TL3SLScreenTest();
2420 }
2421 
2422 // Check basic rate targeting for CBR, for 1 temporal layer, 1 spatial
2423 // for screen mode, with source with many scene cuts and motion.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC1TL1SLScreenScCutsMotion)2424 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL1SLScreenScCutsMotion) {
2425   BasicRateTargetingSVC1TL1SLScreenScCutsMotionTest();
2426 }
2427 
2428 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial,
2429 // with dynamic resize on. Encode at very low bitrate and check that
2430 // there is at least one resize (down) event.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL1SLResize)2431 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLResize) {
2432   BasicRateTargetingSVC3TL1SLResizeTest();
2433 }
2434 
2435 // Check basic rate targeting for CBR, for 2 spatial layers, 1 temporal.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC1TL2SL)2436 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL2SL) {
2437   BasicRateTargetingSVC1TL2SLTest();
2438 }
2439 
2440 // Check basic rate targeting for CBR, for 3 spatial layers, 3 temporal,
2441 // with Intra-only frame inserted in the stream. Verify that we can start
2442 // decoding the SL0 stream at the intra_only frame in mid-sequence.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SLIntraStartDecodeBaseMidSeq)2443 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLIntraStartDecodeBaseMidSeq) {
2444   BasicRateTargetingSVC3TL3SLIntraStartDecodeBaseMidSeq();
2445 }
2446 
2447 // Check basic rate targeting for CBR, for 3spatial layers, 3 temporal,
2448 // with Intra-only frame inserted in the stream. Verify that we can
2449 // decode all frames and layers with no mismatch.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SLIntraMidSeqDecodeAll)2450 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLIntraMidSeqDecodeAll) {
2451   BasicRateTargetingSVC3TL3SLIntraMidSeqDecodeAll();
2452 }
2453 
2454 // Check simulcast mode for 3 spatial layers, 3 temporal,
2455 // Key frame is inserted on base SLO in mid-stream, and verify that the
2456 // top spatial layer (SL2) case be decoded, starting with an Intra-only frame.
2457 // Verify that we can decode all frames for SL2 with no mismatch.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SLSimulcast)2458 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLSimulcast) {
2459   BasicRateTargetingSVC3TL3SLSimulcast();
2460 }
2461 
2462 // Check basic rate targeting for CBR, for 2 spatial layers, 1 temporal,
2463 // with Intra-only frame inserted in the stream.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC1TL2SLIntraOnly)2464 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL2SLIntraOnly) {
2465   BasicRateTargetingSVC1TL2SLIntraOnlyTest();
2466 }
2467 
2468 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC1TL3SL)2469 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SL) {
2470   BasicRateTargetingSVC1TL3SLTest();
2471 }
2472 
2473 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal,
2474 // with additional temporal reference for top spatial layer.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC1TL3SLMultiRef)2475 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLMultiRef) {
2476   BasicRateTargetingSVC1TL3SLMultiRefTest();
2477 }
2478 
2479 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SL)2480 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SL) {
2481   BasicRateTargetingSVC3TL3SLTest();
2482 }
2483 
2484 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SLHD)2485 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHD) {
2486   BasicRateTargetingSVC3TL3SLHDTest();
2487 }
2488 
2489 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers,
2490 // for fixed mode SVC.
TEST_P(DatarateTestSVC,BasicRateTargetingFixedModeSVC3TL3SLHD)2491 TEST_P(DatarateTestSVC, BasicRateTargetingFixedModeSVC3TL3SLHD) {
2492   BasicRateTargetingFixedModeSVC3TL3SLHDTest();
2493 }
2494 
2495 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers,
2496 // for 2 threads, 2 tile_columns, row-mt enabled, and different speed
2497 // per layer.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SLMultiThreadSpeedPerLayer)2498 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLMultiThreadSpeedPerLayer) {
2499   BasicRateTargetingSVC3TL3SLMultiThreadSpeedPerLayerTest();
2500 }
2501 
2502 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers,
2503 // for 2 threads, 2 tile_columns, row-mt enabled.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SLHDMultiThread2)2504 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHDMultiThread2) {
2505   BasicRateTargetingSVC3TL3SLHDMultiThread2Test();
2506 }
2507 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers,
2508 // for 4 threads, 4 tile_columns, row-mt enabled.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SLHDMultiThread4)2509 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHDMultiThread4) {
2510   BasicRateTargetingSVC3TL3SLHDMultiThread4Test();
2511 }
2512 
2513 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers,
2514 // with additional temporal reference for top spatial layer.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SLHDMultiRef)2515 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLHDMultiRef) {
2516   BasicRateTargetingSVC3TL3SLHDMultiRefTest();
2517 }
2518 
2519 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers,
2520 // for auto key frame mode with short key frame period.
TEST_P(DatarateTestSVC,BasicRateTargetingSVC3TL3SLKf)2521 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLKf) {
2522   BasicRateTargetingSVC3TL3SLKfTest();
2523 }
2524 
2525 // Check basic rate targeting for CBR, for 3 spatial, 3 temporal layers,
2526 // for 4:4:4 input.
2527 #if defined(CONFIG_MAX_DECODE_PROFILE) && CONFIG_MAX_DECODE_PROFILE < 1
TEST_P(DatarateTestSVC,DISABLED_BasicRateTargeting444SVC3TL3SL)2528 TEST_P(DatarateTestSVC, DISABLED_BasicRateTargeting444SVC3TL3SL) {
2529 #else
2530 TEST_P(DatarateTestSVC, BasicRateTargeting444SVC3TL3SL) {
2531 #endif
2532   BasicRateTargeting444SVC3TL3SLTest();
2533 }
2534 
2535 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer,
2536 // with dropping of all enhancement layers (TL 1 and TL2). Check that the base
2537 // layer (TL0) can still be decodeable (with no mismatch) with the
2538 // error_resilient flag set to 0. This test used the pattern with multiple
2539 // references (last, golden, and altref), updated on base layer.
2540 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLMultiRefDropAllEnh) {
2541   BasicRateTargetingSVC3TL1SLMultiRefDropAllEnhTest();
2542 }
2543 
2544 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer,
2545 // with dropping of all enhancement layers (TL 1 and TL2). Check that the base
2546 // layer (TL0) can still be decodeable (with no mismatch) with the
2547 // error_resilient flag set to 0.
2548 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropAllEnh) {
2549   BasicRateTargetingSVC3TL1SLDropAllEnhTest();
2550 }
2551 
2552 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer,
2553 // with dropping of the TL2 enhancement layer, which are non-reference
2554 // (droppble) frames. For the base layer (TL0) and TL1 to still be decodeable
2555 // (with no mismatch), the error_resilient_flag may be off (set to 0),
2556 // since TL2 are non-reference frames.
2557 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropTL2Enh) {
2558   BasicRateTargetingSVC3TL1SLDropTL2EnhTest();
2559 }
2560 
2561 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer,
2562 // with dropping of all enhancement layers (TL 1 and TL2). Test that the
2563 // error_resilient flag can be set at frame level, with on/1 on
2564 // enhancement layers and off/0 on base layer.
2565 // This allows for successful decoding after dropping enhancement layer frames.
2566 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropAllEnhFrameER) {
2567   BasicRateTargetingSVC3TL1SLDropAllEnhFrameERTest();
2568 }
2569 
2570 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer,
2571 // with dropping set of enhancement layers (TL 1 and TL2) in middle of sequence.
2572 // Test that the error_resilient flag can be set at frame level, with on/1 on
2573 // enhancement layers and off/0 on base layer.
2574 // This allows for successful decoding after dropping a set enhancement layer
2575 // frames in the sequence.
2576 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropSetEnhFrameER) {
2577   BasicRateTargetingSVC3TL1SLDropSetEnhFrameERTest();
2578 }
2579 
2580 // Check basic rate targeting for CBR, for 2 temporal layers, 1 spatial layer,
2581 // with dropping set of enhancement layers (TL 1) in middle of sequence.
2582 // Test that the error_resilient flag can be 0/off for all frames.
2583 // This allows for successful decoding after dropping a set enhancement layer
2584 // frames in the sequence.
2585 TEST_P(DatarateTestSVC, BasicRateTargetingSVC2TL1SLDropSetEnhER0) {
2586   BasicRateTargetingSVC2TL1SLDropSetEnhER0Test();
2587 }
2588 
2589 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer,
2590 // with dropping set of enhancement layers (TL 1 and TL2) in middle of sequence.
2591 // Test that the error_resilient flag can be 0/off for all frames.
2592 // This allows for successful decoding after dropping a set enhancement layer
2593 // frames in the sequence.
2594 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLDropSetEnhER0) {
2595   BasicRateTargetingSVC3TL1SLDropSetEnhER0Test();
2596 }
2597 
2598 // Check basic rate targeting for CBR, for 3 temporal layers, 3 spatial layers,
2599 // with dropping set of enhancement layers (superframe TL 1 and TL2) in middle
2600 // of sequence. Test that the error_resilient flag can be 0/off for all frames.
2601 // This allows for successful decoding after dropping a set enhancement layer
2602 // frames in the sequence.
2603 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLDropSetEnhER0) {
2604   BasicRateTargetingSVC3TL3SLDropSetEnhER0Test();
2605 }
2606 
2607 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer,
2608 // with compound prediction on, for pattern with two additional refereces
2609 // (golden and altref), both updated on base TLO frames.
2610 TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL1SLMultiRefCompound) {
2611   BasicRateTargetingSVC3TL1SLMultiRefCompoundTest();
2612 }
2613 
2614 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal,
2615 // with the top spatial layer starting disabled (0 bitrate) and then
2616 // dynamically enabled after x frames with nonzero bitrate.
2617 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLDynEnabl) {
2618   BasicRateTargetingSVC1TL3SLDynEnablTest();
2619 }
2620 
2621 // Check basic rate targeting for CBR, for 3 spatial layers, 1 temporal,
2622 // with the top spatial layer dynamically disabled snd enabled during the
2623 // middle of the sequence.
2624 TEST_P(DatarateTestSVC, BasicRateTargetingSVC1TL3SLDynDisEnabl) {
2625   BasicRateTargetingSVC1TL3SLDynDisEnablTest();
2626 }
2627 
2628 // Check basic rate targeting and encoder/decodermismatch, for RPS
2629 // with 1 layer. A number of consecutive frames are lost midway in
2630 // sequence, and encoder resorts to a longer term reference to recovery
2631 // and continue decoding successfully.
2632 TEST_P(DatarateTestSVC, BasicRateTargetingRPS1TL1SLDropFrames) {
2633   BasicRateTargetingRPS1TL1SLDropFramesTest();
2634 }
2635 
2636 TEST(SvcParams, BitrateOverflow) {
2637   uint8_t buf[6] = { 0 };
2638   aom_image_t img;
2639   aom_codec_ctx_t enc;
2640   aom_codec_enc_cfg_t cfg;
2641 
2642   EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I420, 1, 1, 1, buf));
2643 
2644   aom_codec_iface_t *const iface = aom_codec_av1_cx();
2645   EXPECT_EQ(aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_REALTIME),
2646             AOM_CODEC_OK);
2647   cfg.g_w = 1;
2648   cfg.g_h = 1;
2649   ASSERT_EQ(aom_codec_enc_init(&enc, iface, &cfg, 0), AOM_CODEC_OK);
2650 
2651   aom_svc_params_t svc_params = {};
2652   svc_params.framerate_factor[0] = 1;
2653   svc_params.framerate_factor[1] = 2;
2654   svc_params.number_spatial_layers = 1;
2655   svc_params.number_temporal_layers = 2;
2656   svc_params.layer_target_bitrate[0] = INT_MAX;
2657   svc_params.layer_target_bitrate[1] = INT_MAX;
2658   EXPECT_EQ(aom_codec_control(&enc, AV1E_SET_SVC_PARAMS, &svc_params),
2659             AOM_CODEC_OK);
2660   EXPECT_EQ(
2661       aom_codec_encode(&enc, &img, /*pts=*/0, /*duration=*/1, /*flags=*/0),
2662       AOM_CODEC_OK);
2663   EXPECT_EQ(aom_codec_encode(&enc, /*img=*/nullptr, /*pts=*/0, /*duration=*/0,
2664                              /*flags=*/0),
2665             AOM_CODEC_OK);
2666   EXPECT_EQ(aom_codec_destroy(&enc), AOM_CODEC_OK);
2667 }
2668 
2669 AV1_INSTANTIATE_TEST_SUITE(DatarateTestSVC,
2670                            ::testing::Values(::libaom_test::kRealTime),
2671                            ::testing::Range(7, 12), ::testing::Values(0, 3),
2672                            ::testing::Values(0, 1));
2673 
2674 }  // namespace
2675 }  // namespace datarate_test
2676