In PCLF remove ability to inject TaskQueueFactory and CallFactory

Instead rely on TaskQueueFactory and Clock provided by the internal TimeController of the PCLF framework.

Bug: webrtc:15574
Change-Id: I473e1f12ead97f866dbd45771ed5a59541c0c47c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/325182
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41026}
diff --git a/api/test/pclf/BUILD.gn b/api/test/pclf/BUILD.gn
index f94150f..372ff51 100644
--- a/api/test/pclf/BUILD.gn
+++ b/api/test/pclf/BUILD.gn
@@ -66,14 +66,12 @@
   deps = [
     ":media_configuration",
     "../..:async_dns_resolver",
-    "../../../api:callfactory_api",
     "../../../api:fec_controller_api",
     "../../../api:field_trials_view",
     "../../../api:libjingle_peerconnection_api",
     "../../../api:packet_socket_factory",
     "../../../api/audio:audio_mixer_api",
     "../../../api/rtc_event_log",
-    "../../../api/task_queue",
     "../../../api/transport:network_control",
     "../../../api/video_codecs:video_codecs_api",
     "../../../modules/audio_processing:api",
@@ -96,7 +94,6 @@
     ":media_configuration",
     ":media_quality_test_params",
     "../..:async_dns_resolver",
-    "../../../api:callfactory_api",
     "../../../api:create_peer_connection_quality_test_frame_generator",
     "../../../api:fec_controller_api",
     "../../../api:field_trials_view",
@@ -109,7 +106,6 @@
     "../../../api/audio_codecs:audio_codecs_api",
     "../../../api/neteq:neteq_api",
     "../../../api/rtc_event_log",
-    "../../../api/task_queue",
     "../../../api/transport:bitrate_settings",
     "../../../api/transport:network_control",
     "../../../api/video_codecs:video_codecs_api",
diff --git a/api/test/pclf/media_quality_test_params.h b/api/test/pclf/media_quality_test_params.h
index a247f34..b2ccdf1 100644
--- a/api/test/pclf/media_quality_test_params.h
+++ b/api/test/pclf/media_quality_test_params.h
@@ -17,11 +17,9 @@
 
 #include "api/async_dns_resolver.h"
 #include "api/audio/audio_mixer.h"
-#include "api/call/call_factory_interface.h"
 #include "api/fec_controller.h"
 #include "api/field_trials_view.h"
 #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
-#include "api/task_queue/task_queue_factory.h"
 #include "api/test/pclf/media_configuration.h"
 #include "api/transport/network_control.h"
 #include "api/video_codecs/video_decoder_factory.h"
@@ -46,8 +44,6 @@
 // can override only some parts of media engine like video encoder/decoder
 // factories.
 struct PeerConnectionFactoryComponents {
-  std::unique_ptr<TaskQueueFactory> task_queue_factory;
-  std::unique_ptr<CallFactoryInterface> call_factory;
   std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory;
   std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory;
   std::unique_ptr<NetworkControllerFactoryInterface> network_controller_factory;
diff --git a/api/test/pclf/peer_configurer.cc b/api/test/pclf/peer_configurer.cc
index 949dbd3..5e38545 100644
--- a/api/test/pclf/peer_configurer.cc
+++ b/api/test/pclf/peer_configurer.cc
@@ -22,7 +22,6 @@
 #include "api/audio/audio_mixer.h"
 #include "api/audio_codecs/audio_decoder_factory.h"
 #include "api/audio_codecs/audio_encoder_factory.h"
-#include "api/call/call_factory_interface.h"
 #include "api/fec_controller.h"
 #include "api/field_trials_view.h"
 #include "api/ice_transport_interface.h"
@@ -30,7 +29,6 @@
 #include "api/peer_connection_interface.h"
 #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
 #include "api/scoped_refptr.h"
-#include "api/task_queue/task_queue_factory.h"
 #include "api/test/create_peer_connection_quality_test_frame_generator.h"
 #include "api/test/frame_generator_interface.h"
 #include "api/test/pclf/media_configuration.h"
@@ -62,17 +60,6 @@
   return this;
 }
 
-PeerConfigurer* PeerConfigurer::SetTaskQueueFactory(
-    std::unique_ptr<TaskQueueFactory> task_queue_factory) {
-  components_->pcf_dependencies->task_queue_factory =
-      std::move(task_queue_factory);
-  return this;
-}
-PeerConfigurer* PeerConfigurer::SetCallFactory(
-    std::unique_ptr<CallFactoryInterface> call_factory) {
-  components_->pcf_dependencies->call_factory = std::move(call_factory);
-  return this;
-}
 PeerConfigurer* PeerConfigurer::SetEventLogFactory(
     std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) {
   components_->pcf_dependencies->event_log_factory =
diff --git a/api/test/pclf/peer_configurer.h b/api/test/pclf/peer_configurer.h
index 2012ebc2..c0faf85 100644
--- a/api/test/pclf/peer_configurer.h
+++ b/api/test/pclf/peer_configurer.h
@@ -21,7 +21,6 @@
 #include "api/audio/audio_mixer.h"
 #include "api/audio_codecs/audio_decoder_factory.h"
 #include "api/audio_codecs/audio_encoder_factory.h"
-#include "api/call/call_factory_interface.h"
 #include "api/fec_controller.h"
 #include "api/field_trials_view.h"
 #include "api/ice_transport_interface.h"
@@ -29,7 +28,6 @@
 #include "api/peer_connection_interface.h"
 #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
 #include "api/scoped_refptr.h"
-#include "api/task_queue/task_queue_factory.h"
 #include "api/test/frame_generator_interface.h"
 #include "api/test/pclf/media_configuration.h"
 #include "api/test/pclf/media_quality_test_params.h"
@@ -59,13 +57,9 @@
   // unique.
   PeerConfigurer* SetName(absl::string_view name);
 
-  // The parameters of the following 9 methods will be passed to the
+  // The parameters of the following 7 methods will be passed to the
   // PeerConnectionFactoryInterface implementation that will be created for
   // this peer.
-  PeerConfigurer* SetTaskQueueFactory(
-      std::unique_ptr<TaskQueueFactory> task_queue_factory);
-  PeerConfigurer* SetCallFactory(
-      std::unique_ptr<CallFactoryInterface> call_factory);
   PeerConfigurer* SetEventLogFactory(
       std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory);
   PeerConfigurer* SetFecControllerFactory(
diff --git a/test/pc/e2e/test_peer_factory.cc b/test/pc/e2e/test_peer_factory.cc
index 9b2f2d6..41f7533 100644
--- a/test/pc/e2e/test_peer_factory.cc
+++ b/test/pc/e2e/test_peer_factory.cc
@@ -50,18 +50,10 @@
   RTC_DCHECK(components->pc_dependencies);
 
   // Setup required peer connection factory dependencies.
-  if (components->pcf_dependencies->task_queue_factory == nullptr) {
-    components->pcf_dependencies->task_queue_factory =
-        time_controller.CreateTaskQueueFactory();
-  }
-  if (components->pcf_dependencies->call_factory == nullptr) {
-    components->pcf_dependencies->call_factory =
-        CreateTimeControllerBasedCallFactory(&time_controller);
-  }
   if (components->pcf_dependencies->event_log_factory == nullptr) {
     components->pcf_dependencies->event_log_factory =
         std::make_unique<RtcEventLogFactory>(
-            components->pcf_dependencies->task_queue_factory.get());
+            time_controller.GetTaskQueueFactory());
   }
   if (!components->pcf_dependencies->trials) {
     components->pcf_dependencies->trials =
@@ -155,10 +147,11 @@
 }
 
 std::unique_ptr<cricket::MediaEngineInterface> CreateMediaEngine(
+    TaskQueueFactory* task_queue_factory,
     PeerConnectionFactoryComponents* pcf_dependencies,
     rtc::scoped_refptr<AudioDeviceModule> audio_device_module) {
   cricket::MediaEngineDependencies media_deps;
-  media_deps.task_queue_factory = pcf_dependencies->task_queue_factory.get();
+  media_deps.task_queue_factory = task_queue_factory;
   media_deps.adm = audio_device_module;
   media_deps.audio_processing = pcf_dependencies->audio_processing;
   media_deps.audio_mixer = pcf_dependencies->audio_mixer;
@@ -212,6 +205,7 @@
 // from InjectableComponents::PeerConnectionFactoryComponents.
 PeerConnectionFactoryDependencies CreatePCFDependencies(
     std::unique_ptr<PeerConnectionFactoryComponents> pcf_dependencies,
+    TimeController& time_controller,
     std::unique_ptr<cricket::MediaEngineInterface> media_engine,
     rtc::Thread* signaling_thread,
     rtc::Thread* worker_thread,
@@ -222,9 +216,10 @@
   pcf_deps.network_thread = network_thread;
   pcf_deps.media_engine = std::move(media_engine);
 
-  pcf_deps.call_factory = std::move(pcf_dependencies->call_factory);
+  pcf_deps.call_factory =
+      CreateTimeControllerBasedCallFactory(&time_controller);
   pcf_deps.event_log_factory = std::move(pcf_dependencies->event_log_factory);
-  pcf_deps.task_queue_factory = std::move(pcf_dependencies->task_queue_factory);
+  pcf_deps.task_queue_factory = time_controller.CreateTaskQueueFactory();
 
   if (pcf_dependencies->fec_controller_factory != nullptr) {
     pcf_deps.fec_controller_factory =
@@ -318,9 +313,9 @@
         *params->aec_dump_path, -1, task_queue_);
   }
   rtc::scoped_refptr<AudioDeviceModule> audio_device_module =
-      CreateAudioDeviceModule(
-          params->audio_config, remote_audio_config, echo_emulation_config,
-          components->pcf_dependencies->task_queue_factory.get());
+      CreateAudioDeviceModule(params->audio_config, remote_audio_config,
+                              echo_emulation_config,
+                              time_controller_.GetTaskQueueFactory());
   WrapVideoEncoderFactory(
       params->name.value(), params->video_encoder_bitrate_multiplier,
       CalculateRequiredSpatialIndexPerStream(
@@ -330,7 +325,8 @@
                           components->pcf_dependencies.get(),
                           video_analyzer_helper_);
   std::unique_ptr<cricket::MediaEngineInterface> media_engine =
-      CreateMediaEngine(components->pcf_dependencies.get(),
+      CreateMediaEngine(time_controller_.GetTaskQueueFactory(),
+                        components->pcf_dependencies.get(),
                         audio_device_module);
 
   std::unique_ptr<rtc::Thread> owned_worker_thread =
@@ -346,8 +342,9 @@
   rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing =
       components->pcf_dependencies->audio_processing;
   PeerConnectionFactoryDependencies pcf_deps = CreatePCFDependencies(
-      std::move(components->pcf_dependencies), std::move(media_engine),
-      signaling_thread_, components->worker_thread, components->network_thread);
+      std::move(components->pcf_dependencies), time_controller_,
+      std::move(media_engine), signaling_thread_, components->worker_thread,
+      components->network_thread);
   rtc::scoped_refptr<PeerConnectionFactoryInterface> peer_connection_factory =
       CreateModularPeerConnectionFactory(std::move(pcf_deps));