Remove SetInputFrameRateForTesting from VideoStreamInputStateProvider

Removes the test-only input frame rate override from
VideoStreamInputStateProvider and VideoStreamEncoder, and updates tests
to drive input frame rate naturally or via the existing test fake:

- ResourceAdaptationProcessorTest now uses the existing
  FakeVideoStreamInputStateProvider instead of a real
  VideoStreamInputStateProvider with a testing override.
- VideoStreamInputStateProviderTest.ValuesSet feeds frames across a
  1-second simulated clock window.
- VideoStreamEncoderTest adds a FeedFramesAtFps helper that feeds 1
  second of frames at the desired rate through the FrameForwarder so
  VideoStreamInputStateProvider's RateTracker observes the expected FPS.

Bug: webrtc:587243728, webrtc:14246
Change-Id: I527a2088a07901537e635a462e557b9b7b4b2169
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/520500
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Markus Handell <handellm@webrtc.org>
Auto-Submit: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#49465}
diff --git a/call/adaptation/resource_adaptation_processor_unittest.cc b/call/adaptation/resource_adaptation_processor_unittest.cc
index 50bb826..25cee89 100644
--- a/call/adaptation/resource_adaptation_processor_unittest.cc
+++ b/call/adaptation/resource_adaptation_processor_unittest.cc
@@ -22,9 +22,10 @@
 #include "api/video/video_adaptation_counters.h"
 #include "call/adaptation/test/fake_frame_rate_provider.h"
 #include "call/adaptation/test/fake_resource.h"
+#include "call/adaptation/test/fake_video_stream_input_state_provider.h"
 #include "call/adaptation/video_source_restrictions.h"
 #include "call/adaptation/video_stream_adapter.h"
-#include "call/adaptation/video_stream_input_state_provider.h"
+#include "call/adaptation/video_stream_input_state.h"
 #include "rtc_base/event.h"
 #include "rtc_base/task_queue_for_test.h"
 #include "rtc_base/thread_annotations.h"
@@ -97,7 +98,6 @@
  public:
   ResourceAdaptationProcessorTest()
       : encoder_stats_observer_(),
-        input_state_provider_(/*clock=*/nullptr),
         resource_(FakeResource::Create("FakeResource")),
         other_resource_(FakeResource::Create("OtherFakeResource")),
         video_stream_adapter_(
@@ -117,9 +117,11 @@
   }
 
   void SetInputStates(bool has_input, int fps, int frame_size) {
-    input_state_provider_.OnHasInputChanged(has_input);
-    input_state_provider_.SetInputFrameRateForTesting(fps);
-    input_state_provider_.OnFrameSizeObserved(frame_size);
+    VideoStreamInputState input_state;
+    input_state.set_has_input(has_input);
+    input_state.set_frames_per_second(fps);
+    input_state.set_frame_size_pixels(frame_size);
+    input_state_provider_.SetInputState(input_state);
   }
 
   void RestrictSource(VideoSourceRestrictions restrictions) {
@@ -146,7 +148,7 @@
  protected:
   test::RunLoop main_thread_;
   testing::NiceMock<MockVideoStreamEncoderObserver> encoder_stats_observer_;
-  VideoStreamInputStateProvider input_state_provider_;
+  FakeVideoStreamInputStateProvider input_state_provider_;
   scoped_refptr<FakeResource> resource_;
   scoped_refptr<FakeResource> other_resource_;
   std::unique_ptr<VideoStreamAdapter> video_stream_adapter_;
@@ -167,8 +169,10 @@
   video_stream_adapter_->SetDegradationPreference(
       DegradationPreference::MAINTAIN_FRAMERATE);
   // Adaptation does not happen if input is insufficient.
-  // When frame size is missing (OnFrameSizeObserved not called yet).
-  input_state_provider_.OnHasInputChanged(true);
+  // When frame size is missing.
+  VideoStreamInputState input_state;
+  input_state.set_has_input(true);
+  input_state_provider_.SetInputState(input_state);
   resource_->SetUsageState(ResourceUsageState::kOveruse);
   EXPECT_EQ(0u, restrictions_listener_.restrictions_updated_count());
   // When "has input" is missing.
diff --git a/call/adaptation/test/fake_video_stream_input_state_provider.cc b/call/adaptation/test/fake_video_stream_input_state_provider.cc
index 3205c06..8ad009b 100644
--- a/call/adaptation/test/fake_video_stream_input_state_provider.cc
+++ b/call/adaptation/test/fake_video_stream_input_state_provider.cc
@@ -24,6 +24,11 @@
     default;
 
 void FakeVideoStreamInputStateProvider::SetInputState(
+    VideoStreamInputState input_state) {
+  fake_input_state_ = input_state;
+}
+
+void FakeVideoStreamInputStateProvider::SetInputState(
     int input_pixels,
     int input_fps,
     int min_pixels_per_frame,
diff --git a/call/adaptation/test/fake_video_stream_input_state_provider.h b/call/adaptation/test/fake_video_stream_input_state_provider.h
index d0ac9af..52c0d00 100644
--- a/call/adaptation/test/fake_video_stream_input_state_provider.h
+++ b/call/adaptation/test/fake_video_stream_input_state_provider.h
@@ -23,6 +23,7 @@
   FakeVideoStreamInputStateProvider();
   ~FakeVideoStreamInputStateProvider() override;
 
+  void SetInputState(VideoStreamInputState input_state);
   void SetInputState(
       int input_pixels,
       int input_fps,
diff --git a/call/adaptation/video_stream_input_state_provider.cc b/call/adaptation/video_stream_input_state_provider.cc
index 0d3abed..670d935 100644
--- a/call/adaptation/video_stream_input_state_provider.cc
+++ b/call/adaptation/video_stream_input_state_provider.cc
@@ -62,18 +62,10 @@
           : std::nullopt);
 }
 
-void VideoStreamInputStateProvider::SetInputFrameRateForTesting(
-    std::optional<int> fps) {
-  MutexLock lock(&mutex_);
-  input_frame_rate_override_for_testing_ = fps;
-}
-
 VideoStreamInputState VideoStreamInputStateProvider::InputState() {
   MutexLock lock(&mutex_);
   int input_fps = 0;
-  if (input_frame_rate_override_for_testing_.has_value()) {
-    input_fps = *input_frame_rate_override_for_testing_;
-  } else if (clock_ != nullptr) {
+  if (clock_ != nullptr) {
     input_fps = static_cast<int>(
         std::round(input_frame_rate_tracker_.Rate(clock_->CurrentTime())));
   }
diff --git a/call/adaptation/video_stream_input_state_provider.h b/call/adaptation/video_stream_input_state_provider.h
index 6872b53..3cc71a8 100644
--- a/call/adaptation/video_stream_input_state_provider.h
+++ b/call/adaptation/video_stream_input_state_provider.h
@@ -11,8 +11,6 @@
 #ifndef CALL_ADAPTATION_VIDEO_STREAM_INPUT_STATE_PROVIDER_H_
 #define CALL_ADAPTATION_VIDEO_STREAM_INPUT_STATE_PROVIDER_H_
 
-#include <optional>
-
 #include "call/adaptation/encoder_settings.h"
 #include "call/adaptation/video_stream_input_state.h"
 #include "rtc_base/rate_tracker.h"
@@ -32,18 +30,12 @@
   void OnIncomingFrame();
   void OnEncoderSettingsChanged(const EncoderSettings& encoder_settings);
 
-  // Overrides the tracked input frame rate for testing. Pass std::nullopt to
-  // resume using the tracked rate.
-  void SetInputFrameRateForTesting(std::optional<int> fps);
-
   virtual VideoStreamInputState InputState();
 
  private:
   Clock* const clock_;
   Mutex mutex_;
   RateTracker input_frame_rate_tracker_ RTC_GUARDED_BY(mutex_);
-  std::optional<int> input_frame_rate_override_for_testing_
-      RTC_GUARDED_BY(mutex_);
   VideoStreamInputState input_state_ RTC_GUARDED_BY(mutex_);
 };
 
diff --git a/call/adaptation/video_stream_input_state_provider_unittest.cc b/call/adaptation/video_stream_input_state_provider_unittest.cc
index ab4a4db..979cb7d 100644
--- a/call/adaptation/video_stream_input_state_provider_unittest.cc
+++ b/call/adaptation/video_stream_input_state_provider_unittest.cc
@@ -44,7 +44,13 @@
   VideoStreamInputStateProvider input_state_provider(&clock);
   input_state_provider.OnHasInputChanged(true);
   input_state_provider.OnFrameSizeObserved(42);
-  input_state_provider.SetInputFrameRateForTesting(123);
+  const Timestamp start = clock.CurrentTime();
+  for (int i = 0; i < 123; ++i) {
+    clock.AdvanceTime(start + TimeDelta::Millis((i * 1000) / 123) -
+                      clock.CurrentTime());
+    input_state_provider.OnIncomingFrame();
+  }
+  clock.AdvanceTime(start + TimeDelta::Seconds(1) - clock.CurrentTime());
   VideoEncoder::EncoderInfo encoder_info;
   encoder_info.scaling_settings.min_pixels_per_frame = 1337;
   VideoEncoderConfig encoder_config;
diff --git a/video/video_stream_encoder.h b/video/video_stream_encoder.h
index ef521bd..e2a61ba 100644
--- a/video/video_stream_encoder.h
+++ b/video/video_stream_encoder.h
@@ -167,10 +167,6 @@
       scoped_refptr<Resource> reason,
       const VideoSourceRestrictions& unfiltered_restrictions) override;
 
-  void SetInputFrameRateForTesting(std::optional<int> fps) {
-    input_state_provider_.SetInputFrameRateForTesting(fps);
-  }
-
  private:
   class CadenceCallback : public FrameCadenceAdapterInterface::Callback {
    public:
@@ -613,10 +609,6 @@
       scoped_refptr<Resource> reason,
       const VideoSourceRestrictions& unfiltered_restrictions) override;
 
-  void SetInputFrameRateForTesting(std::optional<int> fps) {
-    impl_->SetInputFrameRateForTesting(fps);
-  }
-
  private:
   std::unique_ptr<VideoStreamEncoderImpl> impl_;
 };
diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc
index 0d00f5e..2d8c953 100644
--- a/video/video_stream_encoder_unittest.cc
+++ b/video/video_stream_encoder_unittest.cc
@@ -496,8 +496,6 @@
     time_controller_->AdvanceTime(TimeDelta::Zero());
   }
 
-  using VideoStreamEncoder::SetInputFrameRateForTesting;
-
   // Triggers resource usage measurements on the fake CPU resource.
   void TriggerCpuOveruse() {
     encoder_queue_ptr_->PostTask([this] {
@@ -1071,6 +1069,36 @@
     return ok;
   }
 
+  // Feeds 1 second of frames through `source` at `fps` so
+  // VideoStreamInputStateProvider's 1000ms RateTracker observes `fps`.
+  // Advances `time_controller_` and `timestamp_ms` accordingly.
+  void FeedFramesAtFps(test::FrameForwarder* source,
+                       int width,
+                       int height,
+                       int fps,
+                       int64_t& timestamp_ms) {
+    // Advance past any prior samples in the 1000ms RateTracker window.
+    AdvanceTime(TimeDelta::Millis(1100));
+    timestamp_ms += 1100;
+    const Timestamp start = time_controller_.GetClock()->CurrentTime();
+    const int64_t start_ts = timestamp_ms;
+    for (int i = 0; i < fps; ++i) {
+      int64_t offset_ms = (i * 1000) / fps;
+      TimeDelta delta = start + TimeDelta::Millis(offset_ms) -
+                        time_controller_.GetClock()->CurrentTime();
+      if (delta > TimeDelta::Zero()) {
+        AdvanceTime(delta);
+      }
+      timestamp_ms = start_ts + offset_ms;
+      source->IncomingCapturedFrame(CreateFrame(timestamp_ms, width, height));
+      video_stream_encoder_->WaitUntilTaskQueueIsIdle();
+    }
+    AdvanceTime(start + TimeDelta::Millis(1000) -
+                time_controller_.GetClock()->CurrentTime());
+    timestamp_ms = start_ts + 1000;
+    sink_.ResetEncodedFrameEvent();
+  }
+
   class TestEncoder : public test::FakeEncoder {
    public:
     explicit TestEncoder(const Environment& env) : FakeEncoder(env) {}
@@ -1607,6 +1635,8 @@
       rtp_timestamp_offsets_ = std::move(offsets);
     }
 
+    void ResetEncodedFrameEvent() { encoded_frame_event_.Reset(); }
+
    private:
     std::vector<uint32_t> GetRtpTimestampOffsets() const override {
       MutexLock lock(&mutex_);
@@ -3559,8 +3589,8 @@
   video_encoder_config_.simulcast_layers[0].max_framerate = kFramerateFps;
   ConfigureEncoder(video_encoder_config_.Copy());
 
-  // We rely on the automatic resolution adaptation, but we handle framerate
-  // adaptation manually by mocking the stats proxy.
+  // We rely on automatic resolution adaptation and feed frames at the target
+  // framerate to drive VideoStreamInputStateProvider's input frame rate.
   video_source_.set_adaptation_enabled(true);
 
   // Enable BALANCED preference, no initial limitation.
@@ -3583,12 +3613,7 @@
 
     // Simulate the framerate we've been asked to adapt to.
     const int fps = std::min(kFramerateFps, last_wants.max_framerate_fps);
-    const int frame_interval_ms = kNumMillisecsPerSec / fps;
-    video_stream_encoder_->SetInputFrameRateForTesting(fps);
-
-    video_source_.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight));
-    sink_.WaitForEncodedFrame(t);
-    t += frame_interval_ms;
+    FeedFramesAtFps(&video_source_, kWidth, kHeight, fps, t);
 
     video_stream_encoder_->TriggerCpuOveruse();
     EXPECT_THAT(
@@ -3616,12 +3641,7 @@
 
     // Simulate the framerate we've been asked to adapt to.
     const int fps = std::min(kFramerateFps, last_wants.max_framerate_fps);
-    const int frame_interval_ms = kNumMillisecsPerSec / fps;
-    video_stream_encoder_->SetInputFrameRateForTesting(fps);
-
-    video_source_.IncomingCapturedFrame(CreateFrame(t, kWidth, kHeight));
-    sink_.WaitForEncodedFrame(t);
-    t += frame_interval_ms;
+    FeedFramesAtFps(&video_source_, kWidth, kHeight, fps, t);
 
     video_stream_encoder_->TriggerCpuUnderuse();
     EXPECT_THAT(
@@ -3654,18 +3674,13 @@
 
   int64_t ntp_time = kFrameIntervalMs;
 
-  // Force an input frame rate to be available, or the adaptation call won't
-  // know what framerate to adapt form.
   const int kInputFps = 30;
-  video_stream_encoder_->SetInputFrameRateForTesting(kInputFps);
-
   video_source_.set_adaptation_enabled(true);
   video_stream_encoder_->SetSource(&video_source_,
                                    DegradationPreference::MAINTAIN_RESOLUTION);
   EXPECT_THAT(video_source_.sink_wants(), UnlimitedSinkWants());
-  video_source_.IncomingCapturedFrame(
-      CreateFrame(ntp_time, kFrameWidth, kFrameHeight));
-  sink_.WaitForEncodedFrame(ntp_time);
+  FeedFramesAtFps(&video_source_, kFrameWidth, kFrameHeight, kInputFps,
+                  ntp_time);
   ntp_time += kFrameIntervalMs;
 
   // Trigger CPU overuse.
@@ -3795,10 +3810,11 @@
   // Initially no degradation registered.
   EXPECT_THAT(new_video_source.sink_wants(), UnlimitedSinkWants());
 
-  // Force an input frame rate to be available, or the adaptation call won't
-  // know what framerate to adapt form.
+  // Feed frames so an input frame rate is available for adaptation.
   const int kInputFps = 30;
-  video_stream_encoder_->SetInputFrameRateForTesting(kInputFps);
+  FeedFramesAtFps(&new_video_source, kFrameWidth, kFrameHeight, kInputFps,
+                  frame_timestamp);
+  frame_timestamp += kFrameIntervalMs;
 
   video_stream_encoder_->TriggerCpuOveruse();
   new_video_source.IncomingCapturedFrame(
@@ -4201,7 +4217,7 @@
 
   const int kWidth = 1280;
   const int kHeight = 720;
-  int sequence = 1;
+  int64_t sequence = 1;
 
   // Enable BALANCED preference, no initial limitation.
   test::FrameForwarder source;
@@ -4231,11 +4247,9 @@
   EXPECT_FALSE(stats.cpu_limited_framerate);
   EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
 
-  // Force an input frame rate to be available, or the adaptation call won't
-  // know what framerate to adapt from.
-  video_stream_encoder_->SetInputFrameRateForTesting(30);
+  // Feed frames so an input frame rate is available for adaptation.
+  FeedFramesAtFps(&source, kWidth, kHeight, /*fps=*/30, sequence);
   video_stream_encoder_->TriggerCpuOveruse();
-  video_stream_encoder_->SetInputFrameRateForTesting(std::nullopt);
   source.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight));
   WaitForEncodedFrame(sequence++);
 
@@ -4263,7 +4277,7 @@
 
   const int kWidth = 1280;
   const int kHeight = 720;
-  int sequence = 1;
+  int64_t sequence = 1;
 
   video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight));
   WaitForEncodedFrame(sequence++);
@@ -4306,11 +4320,9 @@
   EXPECT_FALSE(stats.cpu_limited_framerate);
   EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
 
-  // Force an input frame rate to be available, or the adaptation call won't
-  // know what framerate to adapt from.
-  video_stream_encoder_->SetInputFrameRateForTesting(30);
+  // Feed frames so an input frame rate is available for adaptation.
+  FeedFramesAtFps(&new_video_source, kWidth, kHeight, /*fps=*/30, sequence);
   video_stream_encoder_->TriggerCpuOveruse();
-  video_stream_encoder_->SetInputFrameRateForTesting(std::nullopt);
 
   new_video_source.IncomingCapturedFrame(
       CreateFrame(sequence, kWidth, kHeight));
@@ -4336,9 +4348,8 @@
   EXPECT_EQ(2, stats.number_of_cpu_adapt_changes);
 
   // Try to trigger overuse. Should not succeed.
-  video_stream_encoder_->SetInputFrameRateForTesting(30);
+  FeedFramesAtFps(&new_video_source, kWidth, kHeight, /*fps=*/30, sequence);
   video_stream_encoder_->TriggerCpuOveruse();
-  video_stream_encoder_->SetInputFrameRateForTesting(std::nullopt);
 
   stats = stats_proxy_->GetStats();
   EXPECT_FALSE(stats.cpu_limited_resolution);
@@ -4915,17 +4926,18 @@
   video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources(
       kTargetBitrate, kTargetBitrate, 0, 0, 0);
 
-  video_stream_encoder_->SetInputFrameRateForTesting(kInputFps);
-
+  int64_t timestamp_ms = 1;
   // Expect no scaling to begin with (preference: MAINTAIN_FRAMERATE).
-  video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight));
-  sink_.WaitForEncodedFrame(1);
+  video_source_.IncomingCapturedFrame(
+      CreateFrame(timestamp_ms, kWidth, kHeight));
+  sink_.WaitForEncodedFrame(timestamp_ms++);
   EXPECT_THAT(video_source_.sink_wants(), UnlimitedSinkWants());
 
   // Trigger adapt down, expect scaled down resolution.
   video_stream_encoder_->TriggerQualityLow();
-  video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight));
-  sink_.WaitForEncodedFrame(2);
+  video_source_.IncomingCapturedFrame(
+      CreateFrame(timestamp_ms, kWidth, kHeight));
+  sink_.WaitForEncodedFrame(timestamp_ms++);
   EXPECT_THAT(video_source_.sink_wants(),
               FpsUnlimitedResolutionMatches(Lt(kWidth * kHeight)));
 
@@ -4934,15 +4946,15 @@
   video_stream_encoder_->SetSourceAndWaitForRestrictionsUpdated(
       &new_video_source, DegradationPreference::MAINTAIN_RESOLUTION);
   // Give the encoder queue time to process the change in degradation preference
-  // by waiting for an encoded frame.
-  new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight));
-  sink_.WaitForEncodedFrame(3);
+  // and establish an input frame rate.
+  FeedFramesAtFps(&new_video_source, kWidth, kHeight, kInputFps, timestamp_ms);
   EXPECT_THAT(new_video_source.sink_wants(), UnlimitedSinkWants());
 
   // Trigger adapt down, expect reduced framerate.
   video_stream_encoder_->TriggerQualityLow();
-  new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight));
-  sink_.WaitForEncodedFrame(4);
+  new_video_source.IncomingCapturedFrame(
+      CreateFrame(++timestamp_ms, kWidth, kHeight));
+  sink_.WaitForEncodedFrame(timestamp_ms);
   EXPECT_THAT(new_video_source.sink_wants(),
               FpsMatchesResolutionMax(Lt(kInputFps)));
 
@@ -5240,11 +5252,8 @@
       "WebRTC-Video-BalancedDegradationSettings",
       "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1");
 
-  // Force input frame rate.
   const int kInputFps = 24;
-  video_stream_encoder_->SetInputFrameRateForTesting(kInputFps);
-
-  InsertFrameAndWaitForEncoded();
+  FeedFramesAtFps(&source_, kWidth, kHeight, kInputFps, timestamp_ms_);
   EXPECT_THAT(source_.sink_wants(), UnlimitedSinkWants());
 
   // Trigger adapt down, expect scaled down framerate and resolution,
@@ -5261,11 +5270,8 @@
       "WebRTC-Video-BalancedDegradationSettings",
       "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1");
 
-  // Force input frame rate.
   const int kInputFps = 25;
-  video_stream_encoder_->SetInputFrameRateForTesting(kInputFps);
-
-  InsertFrameAndWaitForEncoded();
+  FeedFramesAtFps(&source_, kWidth, kHeight, kInputFps, timestamp_ms_);
   EXPECT_THAT(source_.sink_wants(), UnlimitedSinkWants());
 
   // Trigger adapt down, expect scaled down framerate only (640x360@24fps).
@@ -6456,7 +6462,9 @@
                                    DegradationPreference::MAINTAIN_RESOLUTION);
 
   // Insert a single frame, triggering initial configuration.
-  source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight));
+  int64_t timestamp_ms = 1;
+  source.IncomingCapturedFrame(
+      CreateFrame(timestamp_ms++, kFrameWidth, kFrameHeight));
   video_stream_encoder_->WaitUntilTaskQueueIsIdle();
 
   EXPECT_EQ(
@@ -6478,7 +6486,7 @@
       kFramerate);
 
   // Trigger overuse, max framerate should be reduced.
-  video_stream_encoder_->SetInputFrameRateForTesting(kFramerate);
+  FeedFramesAtFps(&source, kFrameWidth, kFrameHeight, kFramerate, timestamp_ms);
   video_stream_encoder_->TriggerCpuOveruse();
   video_stream_encoder_->WaitUntilTaskQueueIsIdle();
   int adapted_framerate =
@@ -6486,8 +6494,9 @@
   EXPECT_LT(adapted_framerate, kFramerate);
 
   // Trigger underuse, max framerate should go back to codec configured fps.
-  // Set extra low fps, to make sure it's actually reset, not just incremented.
-  video_stream_encoder_->SetInputFrameRateForTesting(adapted_framerate / 2);
+  // Feed extra low fps, to make sure it's actually reset, not just incremented.
+  FeedFramesAtFps(&source, kFrameWidth, kFrameHeight, adapted_framerate / 2,
+                  timestamp_ms);
   video_stream_encoder_->TriggerCpuUnderuse();
   video_stream_encoder_->WaitUntilTaskQueueIsIdle();
   EXPECT_EQ(
@@ -6515,7 +6524,9 @@
   test::FillEncoderConfiguration(kVideoCodecVP8, 1, &video_encoder_config);
   video_encoder_config.simulcast_layers[0].max_framerate = kLowFramerate;
   video_encoder_config.max_bitrate_bps = kTargetBitrate.bps();
-  source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight));
+  int64_t timestamp_ms = 1;
+  source.IncomingCapturedFrame(
+      CreateFrame(timestamp_ms++, kFrameWidth, kFrameHeight));
   video_stream_encoder_->ConfigureEncoder(video_encoder_config.Copy(),
                                           kMaxPayloadLength);
   video_stream_encoder_->WaitUntilTaskQueueIsIdle();
@@ -6525,7 +6536,8 @@
       kLowFramerate);
 
   // Trigger overuse, max framerate should be reduced.
-  video_stream_encoder_->SetInputFrameRateForTesting(kLowFramerate);
+  FeedFramesAtFps(&source, kFrameWidth, kFrameHeight, kLowFramerate,
+                  timestamp_ms);
   video_stream_encoder_->TriggerCpuOveruse();
   video_stream_encoder_->WaitUntilTaskQueueIsIdle();
   int adapted_framerate =
@@ -6535,7 +6547,8 @@
   // Reconfigure the encoder with a new (higher max framerate), max fps should
   // still respect the adaptation.
   video_encoder_config.simulcast_layers[0].max_framerate = kHighFramerate;
-  source.IncomingCapturedFrame(CreateFrame(2, kFrameWidth, kFrameHeight));
+  source.IncomingCapturedFrame(
+      CreateFrame(++timestamp_ms, kFrameWidth, kFrameHeight));
   video_stream_encoder_->ConfigureEncoder(std::move(video_encoder_config),
                                           kMaxPayloadLength);
   video_stream_encoder_->WaitUntilTaskQueueIsIdle();
@@ -6545,7 +6558,8 @@
       adapted_framerate);
 
   // Trigger underuse, max framerate should go back to codec configured fps.
-  video_stream_encoder_->SetInputFrameRateForTesting(adapted_framerate);
+  FeedFramesAtFps(&source, kFrameWidth, kFrameHeight, adapted_framerate,
+                  timestamp_ms);
   video_stream_encoder_->TriggerCpuUnderuse();
   video_stream_encoder_->WaitUntilTaskQueueIsIdle();
   EXPECT_EQ(
@@ -6572,7 +6586,9 @@
   test::FillEncoderConfiguration(kVideoCodecVP8, 1, &video_encoder_config);
   video_encoder_config.simulcast_layers[0].max_framerate = kFramerate;
   video_encoder_config.max_bitrate_bps = kTargetBitrate.bps();
-  source.IncomingCapturedFrame(CreateFrame(1, kFrameWidth, kFrameHeight));
+  int64_t timestamp_ms = 1;
+  source.IncomingCapturedFrame(
+      CreateFrame(timestamp_ms++, kFrameWidth, kFrameHeight));
   video_stream_encoder_->ConfigureEncoder(std::move(video_encoder_config),
                                           kMaxPayloadLength);
   video_stream_encoder_->WaitUntilTaskQueueIsIdle();
@@ -6582,7 +6598,7 @@
       kFramerate);
 
   // Trigger overuse, max framerate should be reduced.
-  video_stream_encoder_->SetInputFrameRateForTesting(kFramerate);
+  FeedFramesAtFps(&source, kFrameWidth, kFrameHeight, kFramerate, timestamp_ms);
   video_stream_encoder_->TriggerCpuOveruse();
   video_stream_encoder_->WaitUntilTaskQueueIsIdle();
   int adapted_framerate =