Vp9Test: Always expect StreamLayersConfig to be present.

The scalability mode should now be supported for all test configurations.

Bug: none
Change-Id: I79aeb56b35d62265c94edefdbcb10c6835bc2750
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/280200
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Commit-Queue: Åsa Persson <asapersson@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38482}
diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc
index b34450a..958d04e 100644
--- a/video/video_send_stream_tests.cc
+++ b/video/video_send_stream_tests.cc
@@ -3039,9 +3039,9 @@
     EXPECT_EQ(kVp9PayloadType, rtp_packet.PayloadType());
     rtc::ArrayView<const uint8_t> rtp_payload = rtp_packet.payload();
 
-    bool new_packet = packets_sent_ == 0 ||
+    bool new_packet = !last_packet_sequence_number_.has_value() ||
                       IsNewerSequenceNumber(rtp_packet.SequenceNumber(),
-                                            last_packet_sequence_number_);
+                                            *last_packet_sequence_number_);
     if (!rtp_payload.empty() && new_packet) {
       RTPVideoHeader video_header;
       EXPECT_NE(
@@ -3056,7 +3056,6 @@
       // Verify configuration specific settings.
       InspectHeader(vp9_header);
 
-      ++packets_sent_;
       if (rtp_packet.Marker()) {
         MutexLock lock(&mutex_);
         ++frames_sent_;
@@ -3278,20 +3277,12 @@
               vp9.num_spatial_layers);
     EXPECT_TRUE(vp9.spatial_layer_resolution_present);  // Y:1
 
-    absl::optional<ScalableVideoController::StreamLayersConfig> info;
-    absl::optional<ScalabilityMode> scalability_mode =
-        ScalabilityModeFromString(params_.scalability_mode);
-    if (scalability_mode) {
-      info = ScalabilityStructureConfig(*scalability_mode);
-    }
-    double default_ratio = 1.0;
-    for (int i = static_cast<int>(vp9.num_spatial_layers) - 1; i >= 0; --i) {
-      double ratio = info ? (static_cast<double>(info->scaling_factor_num[i]) /
-                             info->scaling_factor_den[i])
-                          : default_ratio;
+    ScalableVideoController::StreamLayersConfig config = GetScalabilityConfig();
+    for (int i = config.num_spatial_layers - 1; i >= 0; --i) {
+      double ratio = static_cast<double>(config.scaling_factor_num[i]) /
+                     config.scaling_factor_den[i];
       EXPECT_EQ(expected_width_ * ratio, vp9.width[i]);    // WIDTH
       EXPECT_EQ(expected_height_ * ratio, vp9.height[i]);  // HEIGHT
-      default_ratio /= 2.0;
     }
   }
 
@@ -3301,15 +3292,15 @@
         absl::get<RTPVideoHeaderVP9>(video.video_type_header);
 
     const bool new_temporal_unit =
-        packets_sent_ == 0 ||
-        IsNewerTimestamp(rtp_packet.Timestamp(), last_packet_timestamp_);
+        !last_packet_timestamp_.has_value() ||
+        IsNewerTimestamp(rtp_packet.Timestamp(), *last_packet_timestamp_);
     const bool new_frame =
         new_temporal_unit || last_vp9_.spatial_idx != vp9_header.spatial_idx;
 
     EXPECT_EQ(new_frame, video.is_first_packet_in_frame);
     if (!new_temporal_unit) {
       EXPECT_FALSE(last_packet_marker_);
-      EXPECT_EQ(last_packet_timestamp_, rtp_packet.Timestamp());
+      EXPECT_EQ(*last_packet_timestamp_, rtp_packet.Timestamp());
       EXPECT_EQ(last_vp9_.picture_id, vp9_header.picture_id);
       EXPECT_EQ(last_vp9_.tl0_pic_idx, vp9_header.tl0_pic_idx);
       VerifySpatialIdxWithinFrame(vp9_header);
@@ -3328,16 +3319,26 @@
     VerifyTl0Idx(vp9_header);
   }
 
+  ScalableVideoController::StreamLayersConfig GetScalabilityConfig() const {
+    absl::optional<ScalabilityMode> scalability_mode =
+        ScalabilityModeFromString(params_.scalability_mode);
+    EXPECT_TRUE(scalability_mode.has_value());
+    absl::optional<ScalableVideoController::StreamLayersConfig> config =
+        ScalabilityStructureConfig(*scalability_mode);
+    EXPECT_TRUE(config.has_value());
+    EXPECT_EQ(config->num_spatial_layers, params_.num_spatial_layers);
+    return *config;
+  }
+
   test::FunctionVideoEncoderFactory encoder_factory_;
   const Vp9TestParams params_;
   VideoCodecVP9 vp9_settings_;
   webrtc::VideoEncoderConfig encoder_config_;
   bool last_packet_marker_ = false;
-  uint16_t last_packet_sequence_number_ = 0;
-  uint32_t last_packet_timestamp_ = 0;
+  absl::optional<uint16_t> last_packet_sequence_number_;
+  absl::optional<uint32_t> last_packet_timestamp_;
   RTPVideoHeaderVP9 last_vp9_;
   std::map<int, int> last_temporal_idx_by_spatial_idx_;
-  size_t packets_sent_ = 0;
   Mutex mutex_;
   size_t frames_sent_ = 0;
   int expected_width_ = 0;
@@ -3348,8 +3349,8 @@
                 public ::testing::WithParamInterface<ParameterizationType> {
  public:
   Vp9Test()
-      : params_(::testing::get<0>(GetParam())),
-        use_scalability_mode_identifier_(::testing::get<1>(GetParam())) {}
+      : params_(::testing::get<Vp9TestParams>(GetParam())),
+        use_scalability_mode_identifier_(::testing::get<bool>(GetParam())) {}
 
  protected:
   const Vp9TestParams params_;
@@ -3462,17 +3463,12 @@
     }
 
     int GetRequiredDivisibility() const {
-      absl::optional<ScalabilityMode> scalability_mode =
-          ScalabilityModeFromString(params_.scalability_mode);
-      EXPECT_TRUE(scalability_mode);
-      absl::optional<ScalableVideoController::StreamLayersConfig> config =
-          ScalabilityStructureConfig(*scalability_mode);
-      EXPECT_TRUE(config);
-
+      ScalableVideoController::StreamLayersConfig config =
+          GetScalabilityConfig();
       int required_divisibility = 1;
-      for (size_t sl_idx = 0; sl_idx < params_.num_spatial_layers; ++sl_idx) {
+      for (int sl_idx = 0; sl_idx < config.num_spatial_layers; ++sl_idx) {
         required_divisibility = cricket::LeastCommonMultiple(
-            required_divisibility, config->scaling_factor_den[sl_idx]);
+            required_divisibility, config.scaling_factor_den[sl_idx]);
       }
       return required_divisibility;
     }