Remove use of TimeMillis in EncoderOvershootDetectorTest

The EncoderOvershootDetector already takes the time as input, so no need
to change any injection.

Bug: webrtc:42223992
Change-Id: Ie8a6e1fe5c1816aed35672883a43e4e957a68f58
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/406762
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45471}
diff --git a/video/encoder_overshoot_detector_unittest.cc b/video/encoder_overshoot_detector_unittest.cc
index ab2a4ab..cc45e43 100644
--- a/video/encoder_overshoot_detector_unittest.cc
+++ b/video/encoder_overshoot_detector_unittest.cc
@@ -18,9 +18,9 @@
 #include "api/units/data_size.h"
 #include "api/units/frequency.h"
 #include "api/units/time_delta.h"
+#include "api/units/timestamp.h"
 #include "api/video/video_codec_type.h"
-#include "rtc_base/fake_clock.h"
-#include "rtc_base/time_utils.h"
+#include "system_wrappers/include/clock.h"
 #include "system_wrappers/include/metrics.h"
 #include "test/gtest.h"
 
@@ -60,7 +60,7 @@
   static constexpr int kDefaultBitrateBps = 300000;
   static constexpr double kDefaultFrameRateFps = 15;
   EncoderOvershootDetectorTest()
-      : detector_(kWindowSizeMs,
+      : detector_(kWindowSize.ms(),
                   GetParam().codec_type,
                   GetParam().is_screenshare),
         target_bitrate_(DataRate::BitsPerSec(kDefaultBitrateBps)),
@@ -71,42 +71,42 @@
   void RunConstantUtilizationTest(double actual_utilization_factor,
                                   double expected_utilization_factor,
                                   double allowed_error,
-                                  int64_t test_duration_ms) {
+                                  TimeDelta test_duration) {
     const int frame_size_bytes =
         static_cast<int>(actual_utilization_factor *
                          (target_bitrate_.bps() / target_framerate_fps_) / 8);
     detector_.SetTargetRate(target_bitrate_, target_framerate_fps_,
-                            TimeMillis());
+                            clock_.TimeInMilliseconds());
 
-    if (TimeMillis() == 0) {
+    if (clock_.TimeInMilliseconds() == 0) {
       // Encode a first frame which by definition has no overuse factor.
-      detector_.OnEncodedFrame(frame_size_bytes, TimeMillis());
+      detector_.OnEncodedFrame(frame_size_bytes, clock_.TimeInMilliseconds());
       clock_.AdvanceTime(TimeDelta::Seconds(1) / target_framerate_fps_);
     }
 
-    int64_t runtime_us = 0;
-    while (runtime_us < test_duration_ms * 1000) {
-      detector_.OnEncodedFrame(frame_size_bytes, TimeMillis());
-      runtime_us += kNumMicrosecsPerSec / target_framerate_fps_;
+    TimeDelta runtime = TimeDelta::Zero();
+    while (runtime < test_duration) {
+      detector_.OnEncodedFrame(frame_size_bytes, clock_.TimeInMilliseconds());
+      runtime += TimeDelta::Seconds(1) / target_framerate_fps_;
       clock_.AdvanceTime(TimeDelta::Seconds(1) / target_framerate_fps_);
     }
 
     // At constant utilization, both network and media utilization should be
     // close to expected.
     const std::optional<double> network_utilization_factor =
-        detector_.GetNetworkRateUtilizationFactor(TimeMillis());
+        detector_.GetNetworkRateUtilizationFactor(clock_.TimeInMilliseconds());
     EXPECT_NEAR(network_utilization_factor.value_or(-1),
                 expected_utilization_factor, allowed_error);
 
     const std::optional<double> media_utilization_factor =
-        detector_.GetMediaRateUtilizationFactor(TimeMillis());
+        detector_.GetMediaRateUtilizationFactor(clock_.TimeInMilliseconds());
     EXPECT_NEAR(media_utilization_factor.value_or(-1),
                 expected_utilization_factor, allowed_error);
   }
 
-  static constexpr int64_t kWindowSizeMs = 3000;
+  static constexpr TimeDelta kWindowSize = TimeDelta::Millis(3000);
   EncoderOvershootDetector detector_;
-  ScopedFakeClock clock_;
+  SimulatedClock clock_{Timestamp::Millis(12345)};
   DataRate target_bitrate_;
   double target_framerate_fps_;
 };
@@ -114,63 +114,67 @@
 TEST_P(EncoderOvershootDetectorTest, NoUtilizationIfNoRate) {
   const int frame_size_bytes = 1000;
   const int64_t time_interval_ms = 33;
-  detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, TimeMillis());
+  detector_.SetTargetRate(target_bitrate_, target_framerate_fps_,
+                          clock_.TimeInMilliseconds());
 
   // No data points, can't determine overshoot rate.
   EXPECT_FALSE(
-      detector_.GetNetworkRateUtilizationFactor(TimeMillis()).has_value());
+      detector_.GetNetworkRateUtilizationFactor(clock_.TimeInMilliseconds())
+          .has_value());
 
-  detector_.OnEncodedFrame(frame_size_bytes, TimeMillis());
+  detector_.OnEncodedFrame(frame_size_bytes, clock_.TimeInMilliseconds());
   clock_.AdvanceTime(TimeDelta::Millis(time_interval_ms));
   EXPECT_TRUE(
-      detector_.GetNetworkRateUtilizationFactor(TimeMillis()).has_value());
+      detector_.GetNetworkRateUtilizationFactor(clock_.TimeInMilliseconds())
+          .has_value());
 }
 
 TEST_P(EncoderOvershootDetectorTest, OptimalSize) {
   // Optimally behaved encoder.
   // Allow some error margin due to rounding errors, eg due to frame
   // interval not being an integer.
-  RunConstantUtilizationTest(1.0, 1.0, 0.01, kWindowSizeMs);
+  RunConstantUtilizationTest(1.0, 1.0, 0.01, kWindowSize);
 }
 
 TEST_P(EncoderOvershootDetectorTest, Undershoot) {
   // Undershoot, reported utilization factor should be capped to 1.0 so
   // that we don't incorrectly boost encoder bitrate during movement.
-  RunConstantUtilizationTest(0.5, 1.0, 0.00, kWindowSizeMs);
+  RunConstantUtilizationTest(0.5, 1.0, 0.00, kWindowSize);
 }
 
 TEST_P(EncoderOvershootDetectorTest, Overshoot) {
   // Overshoot by 20%.
   // Allow some error margin due to rounding errors.
-  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs);
+  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize);
 }
 
 TEST_P(EncoderOvershootDetectorTest, ConstantOvershootVaryingRates) {
   // Overshoot by 20%, but vary framerate and bitrate.
   // Allow some error margin due to rounding errors.
-  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs);
+  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize);
   target_framerate_fps_ /= 2;
-  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs / 2);
+  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize / 2);
   target_bitrate_ = DataRate::BitsPerSec(target_bitrate_.bps() / 2);
-  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs / 2);
+  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize / 2);
 }
 
 TEST_P(EncoderOvershootDetectorTest, ConstantRateVaryingOvershoot) {
   // Overshoot by 10%, keep framerate and bitrate constant.
   // Allow some error margin due to rounding errors.
-  RunConstantUtilizationTest(1.1, 1.1, 0.01, kWindowSizeMs);
+  RunConstantUtilizationTest(1.1, 1.1, 0.01, kWindowSize);
   // Change overshoot to 20%, run for half window and expect overshoot
   // to be 15%.
-  RunConstantUtilizationTest(1.2, 1.15, 0.01, kWindowSizeMs / 2);
+  RunConstantUtilizationTest(1.2, 1.15, 0.01, kWindowSize / 2);
   // Keep running at 20% overshoot, after window is full that should now
   // be the reported overshoot.
-  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSizeMs / 2);
+  RunConstantUtilizationTest(1.2, 1.2, 0.01, kWindowSize / 2);
 }
 
 TEST_P(EncoderOvershootDetectorTest, PartialOvershoot) {
   const int ideal_frame_size_bytes =
       (target_bitrate_.bps() / target_framerate_fps_) / 8;
-  detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, TimeMillis());
+  detector_.SetTargetRate(target_bitrate_, target_framerate_fps_,
+                          clock_.TimeInMilliseconds());
 
   // Test scenario with average bitrate matching the target bitrate, but
   // with some utilization factor penalty as the frames can't be paced out
@@ -182,32 +186,34 @@
   //   4) 20% undershoot, no penalty.
   // On average then utilization penalty is thus 5%.
 
-  int64_t runtime_us = 0;
+  TimeDelta runtime = TimeDelta::Zero();
   int i = 0;
-  while (runtime_us < kWindowSizeMs * kNumMicrosecsPerMillisec) {
-    runtime_us += kNumMicrosecsPerSec / target_framerate_fps_;
+  while (runtime < kWindowSize) {
+    runtime += TimeDelta::Seconds(1) / target_framerate_fps_;
     clock_.AdvanceTime(TimeDelta::Seconds(1) / target_framerate_fps_);
     int frame_size_bytes = (i++ % 4 < 2) ? (ideal_frame_size_bytes * 120) / 100
                                          : (ideal_frame_size_bytes * 80) / 100;
-    detector_.OnEncodedFrame(frame_size_bytes, TimeMillis());
+    detector_.OnEncodedFrame(frame_size_bytes, clock_.TimeInMilliseconds());
   }
 
   // Expect 5% overshoot for network rate, see above.
   const std::optional<double> network_utilization_factor =
-      detector_.GetNetworkRateUtilizationFactor(TimeMillis());
+      detector_.GetNetworkRateUtilizationFactor(clock_.TimeInMilliseconds());
   EXPECT_NEAR(network_utilization_factor.value_or(-1), 1.05, 0.01);
 
   // Expect media rate to be on average correct.
   const std::optional<double> media_utilization_factor =
-      detector_.GetMediaRateUtilizationFactor(TimeMillis());
+      detector_.GetMediaRateUtilizationFactor(clock_.TimeInMilliseconds());
   EXPECT_NEAR(media_utilization_factor.value_or(-1), 1.00, 0.01);
 }
 
 TEST_P(EncoderOvershootDetectorTest, RecordsZeroErrorMetricWithNoOvershoot) {
   DataSize ideal_frame_size =
       target_bitrate_ / Frequency::Hertz(target_framerate_fps_);
-  detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, TimeMillis());
-  detector_.OnEncodedFrame(ideal_frame_size.bytes(), TimeMillis());
+  detector_.SetTargetRate(target_bitrate_, target_framerate_fps_,
+                          clock_.TimeInMilliseconds());
+  detector_.OnEncodedFrame(ideal_frame_size.bytes(),
+                           clock_.TimeInMilliseconds());
   detector_.Reset();
 
   const VideoCodecType codec = GetParam().codec_type;
@@ -238,8 +244,10 @@
       target_bitrate_ / Frequency::Hertz(target_framerate_fps_);
   // Use target frame size with 50% overshoot.
   DataSize target_frame_size = ideal_frame_size * 3 / 2;
-  detector_.SetTargetRate(target_bitrate_, target_framerate_fps_, TimeMillis());
-  detector_.OnEncodedFrame(target_frame_size.bytes(), TimeMillis());
+  detector_.SetTargetRate(target_bitrate_, target_framerate_fps_,
+                          clock_.TimeInMilliseconds());
+  detector_.OnEncodedFrame(target_frame_size.bytes(),
+                           clock_.TimeInMilliseconds());
   detector_.Reset();
 
   const VideoCodecType codec = GetParam().codec_type;