Use TimeController instead of FakeClock in fuzzers/RtpReplayer

FakeClock and TimeController provide similar functionality. This a
step converging on using more modern TimeController over FakeClock.

Bug: webrtc:42223992
Change-Id: I1323f7226b8f40fdf08d4a4ca6c02e01787dd6f2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/470500
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Auto-Submit: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#47647}
diff --git a/test/fuzzers/utils/BUILD.gn b/test/fuzzers/utils/BUILD.gn
index dabdab5..07671b0 100644
--- a/test/fuzzers/utils/BUILD.gn
+++ b/test/fuzzers/utils/BUILD.gn
@@ -15,11 +15,17 @@
     "rtp_replayer.h",
   ]
   deps = [
+    "../..:call_config_utils",
+    "../..:create_test_environment",
+    "../..:encoder_settings",
+    "../..:null_transport",
+    "../..:rtp_test_utils",
+    "../..:run_loop",
+    "../..:test_renderer",
     "../../../api:rtp_parameters",
+    "../../../api:time_controller",
     "../../../api:transport_api",
     "../../../api/environment",
-    "../../../api/environment:environment_factory",
-    "../../../api/test/video:function_video_factory",
     "../../../api/units:time_delta",
     "../../../api/units:timestamp",
     "../../../api/video:video_frame",
@@ -27,27 +33,12 @@
     "../../../call",
     "../../../call:call_interfaces",
     "../../../call:video_receive_stream_api",
-    "../../../common_video",
     "../../../media:rtc_internal_video_codecs",
     "../../../modules/rtp_rtcp:rtp_rtcp_format",
-    "../../../rtc_base:checks",
     "../../../rtc_base:logging",
-    "../../../rtc_base:rtc_base_tests_utils",
     "../../../rtc_base:rtc_json",
-    "../../../rtc_base:timeutils",
     "../../../system_wrappers",
-    "../../../test:call_config_utils",
-    "../../../test:encoder_settings",
-    "../../../test:fake_video_codecs",
-    "../../../test:null_transport",
-    "../../../test:rtp_test_utils",
-    "../../../test:run_loop",
-    "../../../test:run_test",
-    "../../../test:run_test_interface",
-    "../../../test:test_renderer",
-    "../../../test:test_support",
-    "../../../test:test_video_capturer",
-    "../../../test:video_test_common",
+    "../../time_controller",
     "//third_party/abseil-cpp/absl/memory",
   ]
 }
diff --git a/test/fuzzers/utils/rtp_replayer.cc b/test/fuzzers/utils/rtp_replayer.cc
index 90ebfb5..9509c7f 100644
--- a/test/fuzzers/utils/rtp_replayer.cc
+++ b/test/fuzzers/utils/rtp_replayer.cc
@@ -21,8 +21,8 @@
 #include "absl/memory/memory.h"
 #include "api/call/transport.h"
 #include "api/environment/environment.h"
-#include "api/environment/environment_factory.h"
 #include "api/media_types.h"
+#include "api/test/time_controller.h"
 #include "api/units/time_delta.h"
 #include "api/units/timestamp.h"
 #include "call/call.h"
@@ -33,14 +33,15 @@
 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
 #include "modules/rtp_rtcp/source/rtp_packet.h"
 #include "modules/rtp_rtcp/source/rtp_packet_received.h"
-#include "rtc_base/fake_clock.h"
 #include "rtc_base/logging.h"
 #include "rtc_base/strings/json.h"
 #include "system_wrappers/include/clock.h"
 #include "test/call_config_utils.h"
+#include "test/create_test_environment.h"
 #include "test/encoder_settings.h"
 #include "test/rtp_file_reader.h"
 #include "test/run_loop.h"
+#include "test/time_controller/simulated_time_controller.h"
 #include "test/video_renderer.h"
 
 namespace webrtc {
@@ -62,12 +63,8 @@
     const uint8_t* rtp_dump_data,
     size_t rtp_dump_size) {
   RunLoop loop;
-  ScopedBaseFakeClock fake_clock;
-
-  // Work around: webrtc calls webrtc::Random(clock.TimeInMicroseconds())
-  // everywhere and Random expects non-zero seed. Let's set the clock non-zero
-  // to make them happy.
-  fake_clock.SetTime(Timestamp::Millis(1));
+  GlobalSimulatedTimeController time_controller(
+      /*start_time=*/Timestamp::Millis(1));
 
   // Attempt to create an RtpReader from the input file.
   auto rtp_reader = CreateRtpReader(rtp_dump_data, rtp_dump_size);
@@ -87,9 +84,9 @@
   }
 
   // Setup the video streams based on the configuration.
-  Environment env = CreateEnvironment();
+  Environment env = CreateTestEnvironment({.time = &time_controller});
   CallConfig call_config(env);
-  std::unique_ptr<Call> call(Call::Create(std::move(call_config)));
+  std::unique_ptr<Call> call = Call::Create(std::move(call_config));
   SetupVideoStreams(&receive_stream_configs, stream_state.get(), call.get());
 
   // Start replaying the provided stream now that it has been configured.
@@ -97,8 +94,7 @@
     receive_stream->Start();
   }
 
-  ReplayPackets(&fake_clock, env.clock(), call.get(), rtp_reader.get(),
-                extensions);
+  ReplayPackets(time_controller, *call, *rtp_reader, extensions);
 
   for (const auto& receive_stream : stream_state->receive_streams) {
     call->DestroyVideoReceiveStream(receive_stream);
@@ -166,11 +162,11 @@
 }
 
 void RtpReplayer::ReplayPackets(
-    FakeClock* fake_clock,
-    Clock& clock,
-    Call* call,
-    test::RtpFileReader* rtp_reader,
+    TimeController& time_controller,
+    Call& call,
+    test::RtpFileReader& rtp_reader,
     const RtpPacketReceived::ExtensionManager& extensions) {
+  Clock& clock = *time_controller.GetClock();
   int64_t replay_start_ms = -1;
 
   while (true) {
@@ -180,7 +176,7 @@
     }
 
     test::RtpPacket packet;
-    if (!rtp_reader->NextPacket(&packet)) {
+    if (!rtp_reader.NextPacket(&packet)) {
       break;
     }
 
@@ -188,7 +184,7 @@
     if (deliver_in_ms > 0) {
       // StatsCounter::ReportMetricToAggregatedCounter is O(elapsed time).
       // Set an upper limit to prevent waste time.
-      fake_clock->AdvanceTime(TimeDelta::Millis(
+      time_controller.AdvanceTime(TimeDelta::Millis(
           std::min(deliver_in_ms, static_cast<int64_t>(100))));
     }
 
@@ -200,7 +196,7 @@
     // Set the clock rate - always 90K for video
     received_packet.set_payload_type_frequency(kVideoPayloadTypeFrequency);
 
-    call->Receiver()->DeliverRtpPacket(
+    call.Receiver()->DeliverRtpPacket(
         MediaType::VIDEO, std::move(received_packet),
         [&](const RtpPacketReceived& parsed_packet) {
           RTC_LOG(LS_ERROR) << "Unknown SSRC: " << parsed_packet.Ssrc();
diff --git a/test/fuzzers/utils/rtp_replayer.h b/test/fuzzers/utils/rtp_replayer.h
index fd9fbc2..e89e003 100644
--- a/test/fuzzers/utils/rtp_replayer.h
+++ b/test/fuzzers/utils/rtp_replayer.h
@@ -18,13 +18,12 @@
 #include <vector>
 
 #include "api/call/transport.h"
+#include "api/test/time_controller.h"
 #include "api/video/video_sink_interface.h"
 #include "api/video_codecs/video_decoder_factory.h"
 #include "call/call.h"
 #include "call/video_receive_stream.h"
 #include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
-#include "rtc_base/fake_clock.h"
-#include "system_wrappers/include/clock.h"
 #include "test/null_transport.h"
 #include "test/rtp_file_reader.h"
 #include "test/video_renderer.h"
@@ -79,10 +78,9 @@
       size_t rtp_dump_size);
 
   // Replays each packet to from the RtpDump.
-  static void ReplayPackets(FakeClock* fake_clock,
-                            Clock& clock,
-                            Call* call,
-                            test::RtpFileReader* rtp_reader,
+  static void ReplayPackets(TimeController& time_controller,
+                            Call& call,
+                            test::RtpFileReader& rtp_reader,
                             const RtpHeaderExtensionMap& extensions);
 };  // class RtpReplayer