rtc: Add test for error_resilience for (3SL, 3TL)

Add test for svc-rtc for 3 spatial and 3 temporal
layers, where a set of temporal enhancement layers
are dropped mid-sequence, and then decoding is started
again at next (SL0, TL0) frame. Verfy that successful
decoding can be done with error_resilience off/0.

Successful decoding with lost TL2/TL1 frames is possible
due to the nature of the temporal prediction structures
used for svc-rtc (LAST is always temporal refereance and
refers to lower temporal layer), and the setting of the
primary_ref_frame when error_resilience is off:
https://aomedia-review.googlesource.com/c/aom/+/157583

Change-Id: I1b336d989a232bbc601bec663704160ed35ab876
diff --git a/test/svc_datarate_test.cc b/test/svc_datarate_test.cc
index eadb145..e0b3860 100644
--- a/test/svc_datarate_test.cc
+++ b/test/svc_datarate_test.cc
@@ -1485,6 +1485,69 @@
     EXPECT_EQ((int)GetMismatchFrames(), num_nonref);
   }
 
+  virtual void BasicRateTargetingSVC3TL3SLDropSetEnhER0Test() {
+    cfg_.rc_buf_initial_sz = 500;
+    cfg_.rc_buf_optimal_sz = 500;
+    cfg_.rc_buf_sz = 1000;
+    cfg_.rc_dropframe_thresh = 0;
+    cfg_.rc_min_quantizer = 0;
+    cfg_.rc_max_quantizer = 63;
+    cfg_.rc_end_usage = AOM_CBR;
+    cfg_.g_lag_in_frames = 0;
+    ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352,
+                                         288, 30, 1, 0, 300);
+    const int bitrate_array[2] = { 200, 550 };
+    cfg_.rc_target_bitrate = bitrate_array[GET_PARAM(4)];
+    ResetModel();
+    // Set error_resilience off.
+    cfg_.g_error_resilient = 0;
+    // Drop TL1 and TL2: for part of sequence. Start at first TL2 at
+    // frame 101, and end at second T2 at frame 199. Frame 200 is TL0,
+    // so we can continue decoding without mismatch (since LAST is the
+    // only reference and error_resil = 1 on TL1/TL2 frames).
+    // Drop here means drop whole superframe.
+    int n = 0;
+    int num_nonref = 300 / 2;
+    for (int i = 101; i < 200; i++) {
+      if (i % 4 != 0) {
+        drop_frames_list_[n] = i;
+        n++;
+        if (i % 2 != 0) num_nonref -= 1;
+      }
+    }
+    number_temporal_layers_ = 3;
+    number_spatial_layers_ = 3;
+    multi_ref_ = 1;
+    drop_frames_ = n * number_spatial_layers_;
+    // SL0
+    const int bitrate_sl0 = 1 * cfg_.rc_target_bitrate / 8;
+    target_layer_bitrate_[0] = 50 * bitrate_sl0 / 100;
+    target_layer_bitrate_[1] = 70 * bitrate_sl0 / 100;
+    target_layer_bitrate_[2] = bitrate_sl0;
+    // SL1
+    const int bitrate_sl1 = 3 * cfg_.rc_target_bitrate / 8;
+    target_layer_bitrate_[3] = 50 * bitrate_sl1 / 100;
+    target_layer_bitrate_[4] = 70 * bitrate_sl1 / 100;
+    target_layer_bitrate_[5] = bitrate_sl1;
+    // SL2
+    const int bitrate_sl2 = 4 * cfg_.rc_target_bitrate / 8;
+    target_layer_bitrate_[6] = 50 * bitrate_sl2 / 100;
+    target_layer_bitrate_[7] = 70 * bitrate_sl2 / 100;
+    target_layer_bitrate_[8] = bitrate_sl2;
+    ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
+    for (int i = 0; i < number_temporal_layers_ * number_spatial_layers_; i++) {
+      ASSERT_GE(effective_datarate_tl[i], target_layer_bitrate_[i] * 0.60)
+          << " The datarate for the file is lower than target by too much!";
+      ASSERT_LE(effective_datarate_tl[i], target_layer_bitrate_[i] * 1.35)
+          << " The datarate for the file is greater than target by too much!";
+    }
+    // Test that no mismatches have been found.
+    std::cout << "          Decoded frames: " << GetDecodedFrames() << "\n";
+    std::cout << "          Mismatch frames: " << GetMismatchFrames() << "\n";
+    EXPECT_EQ(300 * number_spatial_layers_ - GetDecodedFrames(), drop_frames_);
+    EXPECT_EQ((int)GetMismatchFrames(), num_nonref);
+  }
+
   virtual void BasicRateTargetingSVC3TL1SLMultiRefCompoundTest() {
     cfg_.rc_buf_initial_sz = 500;
     cfg_.rc_buf_optimal_sz = 500;
@@ -1765,6 +1828,15 @@
   BasicRateTargetingSVC3TL1SLDropSetEnhER0Test();
 }
 
+// Check basic rate targeting for CBR, for 3 temporal layers, 3 spatial layers,
+// with dropping set of enhancement layers (superframe TL 1 and TL2) in middle
+// of sequence. Test that the error_resilient flag can be 0/off for all frames.
+// This allows for successful decoding after dropping a set enhancement layer
+// frames in the sequence.
+TEST_P(DatarateTestSVC, BasicRateTargetingSVC3TL3SLDropSetEnhER0) {
+  BasicRateTargetingSVC3TL3SLDropSetEnhER0Test();
+}
+
 // Check basic rate targeting for CBR, for 3 temporal layers, 1 spatial layer,
 // with compound prediction on, for pattern with two additional refereces
 // (golden and altref), both updated on base TLO frames.