Reland "Replace usage of old SetRates/SetRateAllocation methods"

This is a reland of 7ac0d5f348f0b956089c4ed65c46e65bac125508

Original change's description:
> Replace usage of old SetRates/SetRateAllocation methods
>
> This rather large CL replaces all relevant usage of the old
> VideoEncoder::SetRates()/SetRateAllocation() methods in WebRTC.
> API is unchanged to allow downstream projects to update without
> breakage.
>
> Bug: webrtc:10481
> Change-Id: Iab8f292ce6be6c3f5056a239d26361962b14bb38
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131949
> Commit-Queue: Erik Språng <sprang@webrtc.org>
> Reviewed-by: Per Kjellander <perkj@webrtc.org>
> Reviewed-by: Niels Moller <nisse@webrtc.org>
> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
> Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#27554}

TBR=brandtr@webrtc.org,sakal@webrtc.org,perkj@webrtc.org

Bug: webrtc:10481
Change-Id: I2978d5c527a18e885b7845c4e53a2424e8ad5b4b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132551
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27593}
diff --git a/test/configurable_frame_size_encoder.cc b/test/configurable_frame_size_encoder.cc
index a0a42f0..ba529cb 100644
--- a/test/configurable_frame_size_encoder.cc
+++ b/test/configurable_frame_size_encoder.cc
@@ -74,11 +74,8 @@
   return WEBRTC_VIDEO_CODEC_OK;
 }
 
-int32_t ConfigurableFrameSizeEncoder::SetRateAllocation(
-    const VideoBitrateAllocation& allocation,
-    uint32_t framerate) {
-  return WEBRTC_VIDEO_CODEC_OK;
-}
+void ConfigurableFrameSizeEncoder::SetRates(
+    const RateControlParameters& parameters) {}
 
 int32_t ConfigurableFrameSizeEncoder::SetFrameSize(size_t size) {
   RTC_DCHECK_LE(size, max_frame_size_);
diff --git a/test/configurable_frame_size_encoder.h b/test/configurable_frame_size_encoder.h
index 9daf13e..ddf763f 100644
--- a/test/configurable_frame_size_encoder.h
+++ b/test/configurable_frame_size_encoder.h
@@ -44,8 +44,7 @@
 
   int32_t Release() override;
 
-  int32_t SetRateAllocation(const VideoBitrateAllocation& allocation,
-                            uint32_t framerate) override;
+  void SetRates(const RateControlParameters& parameters) override;
 
   int32_t SetFrameSize(size_t size);
 
diff --git a/test/fake_encoder.cc b/test/fake_encoder.cc
index ac59dfd..7c24b84 100644
--- a/test/fake_encoder.cc
+++ b/test/fake_encoder.cc
@@ -51,7 +51,6 @@
 FakeEncoder::FakeEncoder(Clock* clock)
     : clock_(clock),
       callback_(nullptr),
-      configured_input_framerate_(-1),
       max_target_bitrate_kbps_(-1),
       pending_keyframe_(true),
       counter_(0),
@@ -65,7 +64,7 @@
   RTC_DCHECK_GE(max_kbps, -1);  // max_kbps == -1 disables it.
   rtc::CritScope cs(&crit_sect_);
   max_target_bitrate_kbps_ = max_kbps;
-  SetRateAllocation(target_bitrate_, configured_input_framerate_);
+  SetRates(current_rate_settings_);
 }
 
 int32_t FakeEncoder::InitEncode(const VideoCodec* config,
@@ -73,8 +72,8 @@
                                 size_t max_payload_size) {
   rtc::CritScope cs(&crit_sect_);
   config_ = *config;
-  target_bitrate_.SetBitrate(0, 0, config_.startBitrate * 1000);
-  configured_input_framerate_ = config_.maxFramerate;
+  current_rate_settings_.bitrate.SetBitrate(0, 0, config_.startBitrate * 1000);
+  current_rate_settings_.framerate_fps = config_.maxFramerate;
   pending_keyframe_ = true;
   last_frame_info_ = FrameInfo();
   return 0;
@@ -86,8 +85,7 @@
   unsigned char num_simulcast_streams;
   SimulcastStream simulcast_streams[kMaxSimulcastStreams];
   EncodedImageCallback* callback;
-  VideoBitrateAllocation target_bitrate;
-  int framerate;
+  RateControlParameters rates;
   VideoCodecMode mode;
   bool keyframe;
   uint32_t counter;
@@ -99,12 +97,10 @@
       simulcast_streams[i] = config_.simulcastStream[i];
     }
     callback = callback_;
-    target_bitrate = target_bitrate_;
+    rates = current_rate_settings_;
     mode = config_.mode;
-    if (configured_input_framerate_ > 0) {
-      framerate = configured_input_framerate_;
-    } else {
-      framerate = max_framerate;
+    if (rates.framerate_fps <= 0.0) {
+      rates.framerate_fps = max_framerate;
     }
     keyframe = pending_keyframe_;
     pending_keyframe_ = false;
@@ -112,8 +108,8 @@
   }
 
   FrameInfo frame_info =
-      NextFrame(frame_types, keyframe, num_simulcast_streams, target_bitrate,
-                simulcast_streams, framerate);
+      NextFrame(frame_types, keyframe, num_simulcast_streams, rates.bitrate,
+                simulcast_streams, static_cast<int>(rates.framerate_fps + 0.5));
   for (uint8_t i = 0; i < frame_info.layers.size(); ++i) {
     constexpr int kMinPayLoadLength = 14;
     if (frame_info.layers[i].size < kMinPayLoadLength) {
@@ -237,12 +233,10 @@
   return 0;
 }
 
-int32_t FakeEncoder::SetRateAllocation(
-    const VideoBitrateAllocation& rate_allocation,
-    uint32_t framerate) {
+void FakeEncoder::SetRates(const RateControlParameters& parameters) {
   rtc::CritScope cs(&crit_sect_);
-  target_bitrate_ = rate_allocation;
-  int allocated_bitrate_kbps = target_bitrate_.get_sum_kbps();
+  current_rate_settings_ = parameters;
+  int allocated_bitrate_kbps = parameters.bitrate.get_sum_kbps();
 
   // Scale bitrate allocation to not exceed the given max target bitrate.
   if (max_target_bitrate_kbps_ > 0 &&
@@ -251,20 +245,19 @@
          ++spatial_idx) {
       for (uint8_t temporal_idx = 0; temporal_idx < kMaxTemporalStreams;
            ++temporal_idx) {
-        if (target_bitrate_.HasBitrate(spatial_idx, temporal_idx)) {
-          uint32_t bitrate =
-              target_bitrate_.GetBitrate(spatial_idx, temporal_idx);
+        if (current_rate_settings_.bitrate.HasBitrate(spatial_idx,
+                                                      temporal_idx)) {
+          uint32_t bitrate = current_rate_settings_.bitrate.GetBitrate(
+              spatial_idx, temporal_idx);
           bitrate = static_cast<uint32_t>(
               (bitrate * int64_t{max_target_bitrate_kbps_}) /
               allocated_bitrate_kbps);
-          target_bitrate_.SetBitrate(spatial_idx, temporal_idx, bitrate);
+          current_rate_settings_.bitrate.SetBitrate(spatial_idx, temporal_idx,
+                                                    bitrate);
         }
       }
     }
   }
-
-  configured_input_framerate_ = framerate;
-  return 0;
 }
 
 const char* FakeEncoder::kImplementationName = "fake_encoder";
@@ -276,7 +269,7 @@
 
 int FakeEncoder::GetConfiguredInputFramerate() const {
   rtc::CritScope cs(&crit_sect_);
-  return configured_input_framerate_;
+  return static_cast<int>(current_rate_settings_.framerate_fps + 0.5);
 }
 
 FakeH264Encoder::FakeH264Encoder(Clock* clock)
diff --git a/test/fake_encoder.h b/test/fake_encoder.h
index 95b4b20..7e1c1a1 100644
--- a/test/fake_encoder.h
+++ b/test/fake_encoder.h
@@ -48,8 +48,7 @@
   int32_t RegisterEncodeCompleteCallback(
       EncodedImageCallback* callback) override;
   int32_t Release() override;
-  int32_t SetRateAllocation(const VideoBitrateAllocation& rate_allocation,
-                            uint32_t framerate) override;
+  void SetRates(const RateControlParameters& parameters) override;
   int GetConfiguredInputFramerate() const;
   EncoderInfo GetEncoderInfo() const override;
 
@@ -89,8 +88,7 @@
 
   VideoCodec config_ RTC_GUARDED_BY(crit_sect_);
   EncodedImageCallback* callback_ RTC_GUARDED_BY(crit_sect_);
-  VideoBitrateAllocation target_bitrate_ RTC_GUARDED_BY(crit_sect_);
-  int configured_input_framerate_ RTC_GUARDED_BY(crit_sect_);
+  RateControlParameters current_rate_settings_ RTC_GUARDED_BY(crit_sect_);
   int max_target_bitrate_kbps_ RTC_GUARDED_BY(crit_sect_);
   bool pending_keyframe_ RTC_GUARDED_BY(crit_sect_);
   uint32_t counter_ RTC_GUARDED_BY(crit_sect_);
diff --git a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc
index 39d5701..272f80f 100644
--- a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc
+++ b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.cc
@@ -63,7 +63,9 @@
       bitrate_multiplier_(bitrate_multiplier),
       stream_required_spatial_index_(std::move(stream_required_spatial_index)),
       injector_(injector),
-      analyzer_(analyzer) {}
+      analyzer_(analyzer),
+      mode_(SimulcastMode::kNormal),
+      delegate_callback_(nullptr) {}
 QualityAnalyzingVideoEncoder::~QualityAnalyzingVideoEncoder() = default;
 
 int32_t QualityAnalyzingVideoEncoder::InitEncode(
@@ -147,17 +149,11 @@
   return result;
 }
 
-int32_t QualityAnalyzingVideoEncoder::SetRates(uint32_t bitrate,
-                                               uint32_t framerate) {
-  return delegate_->SetRates(bitrate, framerate);
-}
-
-int32_t QualityAnalyzingVideoEncoder::SetRateAllocation(
-    const VideoBitrateAllocation& allocation,
-    uint32_t framerate) {
+void QualityAnalyzingVideoEncoder::SetRates(
+    const VideoEncoder::RateControlParameters& parameters) {
   RTC_DCHECK_GT(bitrate_multiplier_, 0.0);
   if (fabs(bitrate_multiplier_ - kNoMultiplier) < kEps) {
-    return delegate_->SetRateAllocation(allocation, framerate);
+    return delegate_->SetRates(parameters);
   }
 
   // Simulating encoder overshooting target bitrate, by configuring actual
@@ -166,7 +162,7 @@
   VideoBitrateAllocation multiplied_allocation;
   for (size_t si = 0; si < kMaxSpatialLayers; ++si) {
     const uint32_t spatial_layer_bitrate_bps =
-        allocation.GetSpatialLayerSum(si);
+        parameters.bitrate.GetSpatialLayerSum(si);
     if (spatial_layer_bitrate_bps == 0) {
       continue;
     }
@@ -185,16 +181,18 @@
     }
 
     for (size_t ti = 0; ti < kMaxTemporalStreams; ++ti) {
-      if (allocation.HasBitrate(si, ti)) {
+      if (parameters.bitrate.HasBitrate(si, ti)) {
         multiplied_allocation.SetBitrate(
             si, ti,
             rtc::checked_cast<uint32_t>(bitrate_multiplier *
-                                        allocation.GetBitrate(si, ti)));
+                                        parameters.bitrate.GetBitrate(si, ti)));
       }
     }
   }
 
-  return delegate_->SetRateAllocation(multiplied_allocation, framerate);
+  RateControlParameters adjusted_params = parameters;
+  adjusted_params.bitrate = multiplied_allocation;
+  return delegate_->SetRates(adjusted_params);
 }
 
 VideoEncoder::EncoderInfo QualityAnalyzingVideoEncoder::GetEncoderInfo() const {
diff --git a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h
index d7dd5d1..4861d4c 100644
--- a/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h
+++ b/test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h
@@ -70,9 +70,7 @@
   int32_t Release() override;
   int32_t Encode(const VideoFrame& frame,
                  const std::vector<VideoFrameType>* frame_types) override;
-  int32_t SetRates(uint32_t bitrate, uint32_t framerate) override;
-  int32_t SetRateAllocation(const VideoBitrateAllocation& allocation,
-                            uint32_t framerate) override;
+  void SetRates(const VideoEncoder::RateControlParameters& parameters) override;
   EncoderInfo GetEncoderInfo() const override;
 
   // Methods of EncodedImageCallback interface.
diff --git a/test/video_encoder_proxy_factory.h b/test/video_encoder_proxy_factory.h
index 55a01a1..49a4e2d 100644
--- a/test/video_encoder_proxy_factory.h
+++ b/test/video_encoder_proxy_factory.h
@@ -75,9 +75,8 @@
       return encoder_->RegisterEncodeCompleteCallback(callback);
     }
     int32_t Release() override { return encoder_->Release(); }
-    int32_t SetRateAllocation(const VideoBitrateAllocation& rate_allocation,
-                              uint32_t framerate) override {
-      return encoder_->SetRateAllocation(rate_allocation, framerate);
+    void SetRates(const RateControlParameters& parameters) override {
+      encoder_->SetRates(parameters);
     }
     VideoEncoder::EncoderInfo GetEncoderInfo() const override {
       return encoder_->GetEncoderInfo();