Set rates for av1 svc tests

Bug: webrtc:11404
Change-Id: I79c4cee99d1bee1cdd3a8e0f901fadc6178a07a6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235602
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Jerome Jiang <jianj@google.com>
Cr-Commit-Position: refs/heads/main@{#35250}
diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder_unittest.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder_unittest.cc
index 96057a0..6e92e50 100644
--- a/modules/video_coding/codecs/av1/libaom_av1_encoder_unittest.cc
+++ b/modules/video_coding/codecs/av1/libaom_av1_encoder_unittest.cc
@@ -86,13 +86,22 @@
 }
 
 TEST(LibaomAv1EncoderTest, SetsEndOfPictureForLastFrameInTemporalUnit) {
+  VideoBitrateAllocation allocation;
+  allocation.SetBitrate(0, 0, 30000);
+  allocation.SetBitrate(1, 0, 40000);
+  allocation.SetBitrate(2, 0, 30000);
+
   std::unique_ptr<VideoEncoder> encoder = CreateLibaomAv1Encoder();
   VideoCodec codec_settings = DefaultCodecSettings();
   // Configure encoder with 3 spatial layers.
   codec_settings.SetScalabilityMode("L3T1");
+  codec_settings.maxBitrate = allocation.get_sum_kbps();
   ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()),
             WEBRTC_VIDEO_CODEC_OK);
 
+  encoder->SetRates(VideoEncoder::RateControlParameters(
+      allocation, codec_settings.maxFramerate));
+
   std::vector<EncodedVideoFrameProducer::EncodedFrame> encoded_frames =
       EncodedVideoFrameProducer(*encoder).SetNumInputFrames(2).Encode();
   ASSERT_THAT(encoded_frames, SizeIs(6));
@@ -105,6 +114,10 @@
 }
 
 TEST(LibaomAv1EncoderTest, CheckOddDimensionsWithSpatialLayers) {
+  VideoBitrateAllocation allocation;
+  allocation.SetBitrate(0, 0, 30000);
+  allocation.SetBitrate(1, 0, 40000);
+  allocation.SetBitrate(2, 0, 30000);
   std::unique_ptr<VideoEncoder> encoder = CreateLibaomAv1Encoder();
   VideoCodec codec_settings = DefaultCodecSettings();
   // Configure encoder with 3 spatial layers.
@@ -112,8 +125,11 @@
   // Odd width and height values should not make encoder crash.
   codec_settings.width = 623;
   codec_settings.height = 405;
+  codec_settings.maxBitrate = allocation.get_sum_kbps();
   ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()),
             WEBRTC_VIDEO_CODEC_OK);
+  encoder->SetRates(VideoEncoder::RateControlParameters(
+      allocation, codec_settings.maxFramerate));
   EncodedVideoFrameProducer evfp(*encoder);
   evfp.SetResolution(RenderResolution{623, 405});
   std::vector<EncodedVideoFrameProducer::EncodedFrame> encoded_frames =
@@ -137,14 +153,20 @@
 }
 
 TEST(LibaomAv1EncoderTest, PopulatesEncodedFrameSize) {
+  VideoBitrateAllocation allocation;
+  allocation.SetBitrate(0, 0, 30000);
+  allocation.SetBitrate(1, 0, 40000);
+  allocation.SetBitrate(2, 0, 30000);
   std::unique_ptr<VideoEncoder> encoder = CreateLibaomAv1Encoder();
   VideoCodec codec_settings = DefaultCodecSettings();
+  codec_settings.maxBitrate = allocation.get_sum_kbps();
   ASSERT_GT(codec_settings.width, 4);
   // Configure encoder with 3 spatial layers.
   codec_settings.SetScalabilityMode("L3T1");
   ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()),
             WEBRTC_VIDEO_CODEC_OK);
-
+  encoder->SetRates(VideoEncoder::RateControlParameters(
+      allocation, codec_settings.maxFramerate));
   using Frame = EncodedVideoFrameProducer::EncodedFrame;
   std::vector<Frame> encoded_frames =
       EncodedVideoFrameProducer(*encoder).SetNumInputFrames(1).Encode();
diff --git a/modules/video_coding/codecs/av1/libaom_av1_unittest.cc b/modules/video_coding/codecs/av1/libaom_av1_unittest.cc
index 5823266..e893bfd 100644
--- a/modules/video_coding/codecs/av1/libaom_av1_unittest.cc
+++ b/modules/video_coding/codecs/av1/libaom_av1_unittest.cc
@@ -178,15 +178,36 @@
 class LibaomAv1SvcTest : public ::testing::TestWithParam<SvcTestParam> {};
 
 TEST_P(LibaomAv1SvcTest, EncodeAndDecodeAllDecodeTargets) {
-  size_t num_decode_targets = CreateScalabilityStructure(GetParam().name)
-                                  ->DependencyStructure()
-                                  .num_decode_targets;
+  const SvcTestParam param = GetParam();
+  std::unique_ptr<ScalableVideoController> svc_controller =
+      CreateScalabilityStructure(param.name);
+  ASSERT_TRUE(svc_controller);
+  VideoBitrateAllocation allocation;
+  if (param.configured_bitrates.empty()) {
+    ScalableVideoController::StreamLayersConfig config =
+        svc_controller->StreamConfig();
+    for (int sid = 0; sid < config.num_spatial_layers; ++sid) {
+      for (int tid = 0; tid < config.num_temporal_layers; ++tid) {
+        allocation.SetBitrate(sid, tid, 100'000);
+      }
+    }
+  } else {
+    for (const auto& kv : param.configured_bitrates) {
+      allocation.SetBitrate(kv.first.spatial_id, kv.first.temporal_id,
+                            kv.second.bps());
+    }
+  }
+
+  size_t num_decode_targets =
+      svc_controller->DependencyStructure().num_decode_targets;
 
   std::unique_ptr<VideoEncoder> encoder = CreateLibaomAv1Encoder();
   VideoCodec codec_settings = DefaultCodecSettings();
   codec_settings.SetScalabilityMode(GetParam().name);
   ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()),
             WEBRTC_VIDEO_CODEC_OK);
+  encoder->SetRates(VideoEncoder::RateControlParameters(
+      allocation, codec_settings.maxFramerate));
   std::vector<EncodedVideoFrameProducer::EncodedFrame> encoded_frames =
       EncodedVideoFrameProducer(*encoder)
           .SetNumInputFrames(GetParam().num_frames_to_generate)