Don't limit simulcast layers number for screenshare based on resolution

Bug: webrtc:10996
Change-Id: I72de00e615822e913e55d7fdd5bb0e736db31c6e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/154523
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29362}
diff --git a/media/engine/simulcast.cc b/media/engine/simulcast.cc
index 656645c..b8e7a6c 100644
--- a/media/engine/simulcast.cc
+++ b/media/engine/simulcast.cc
@@ -233,15 +233,15 @@
     bool temporal_layers_supported) {
   RTC_DCHECK(max_layers > 1 || is_screenshare_with_conference_mode);
 
-  // Some applications rely on the old behavior limiting the simulcast layer
-  // count based on the resolution automatically, which they can get through
-  // the WebRTC-LegacySimulcastLayerLimit field trial until they update.
-  max_layers = LimitSimulcastLayerCount(width, height, max_layers);
-
   if (is_screenshare_with_conference_mode) {
     return GetScreenshareLayers(max_layers, width, height, bitrate_priority,
                                 max_qp, temporal_layers_supported);
   } else {
+    // Some applications rely on the old behavior limiting the simulcast layer
+    // count based on the resolution automatically, which they can get through
+    // the WebRTC-LegacySimulcastLayerLimit field trial until they update.
+    max_layers = LimitSimulcastLayerCount(width, height, max_layers);
+
     return GetNormalSimulcastLayers(max_layers, width, height, bitrate_priority,
                                     max_qp, temporal_layers_supported);
   }
diff --git a/media/engine/simulcast_unittest.cc b/media/engine/simulcast_unittest.cc
index 27b0913..9e17a89 100644
--- a/media/engine/simulcast_unittest.cc
+++ b/media/engine/simulcast_unittest.cc
@@ -153,6 +153,18 @@
   EXPECT_EQ(600u, streams[1].height);
 }
 
+TEST(SimulcastTest, GetConfigWithLowResolutionScreenshare) {
+  test::ScopedFieldTrials field_trials(
+      "WebRTC-LegacySimulcastLayerLimit/Enabled/");
+  const size_t kMaxLayers = 3;
+  std::vector<VideoStream> streams = cricket::GetSimulcastConfig(
+      kMaxLayers, 100, 100, kBitratePriority, kQpMax, kScreenshare);
+
+  // Simulcast streams number is never decreased for screenshare,
+  // even for very low resolution.
+  EXPECT_GT(streams.size(), 1u);
+}
+
 TEST(SimulcastTest, GetConfigWithNotLimitedMaxLayersForResolution) {
   test::ScopedFieldTrials field_trials(
       "WebRTC-LegacySimulcastLayerLimit/Disabled/");