From 094ce2ef8368c54aaad10b3350c69e1ee618f5e9 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Wed, 22 Jan 2020 14:37:52 +0100 Subject: [PATCH] Adds CreateTaskQueueFactory to TimeController Bug: webrtc:11255 Change-Id: I02bdc944c7081590f40a77b315f64c63adbc6ff8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166921 Commit-Queue: Sebastian Jansson Reviewed-by: Artem Titov Cr-Commit-Position: refs/heads/master@{#30349} --- api/test/time_controller.cc | 16 ++++++++++++++++ api/test/time_controller.h | 6 ++++++ test/peer_scenario/peer_scenario_client.cc | 17 +---------------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/api/test/time_controller.cc b/api/test/time_controller.cc index 26fe69cce1..b3b2f463c5 100644 --- a/api/test/time_controller.cc +++ b/api/test/time_controller.cc @@ -10,6 +10,22 @@ #include "api/test/time_controller.h" namespace webrtc { +std::unique_ptr TimeController::CreateTaskQueueFactory() { + class FactoryWrapper final : public TaskQueueFactory { + public: + explicit FactoryWrapper(TaskQueueFactory* inner_factory) + : inner_(inner_factory) {} + std::unique_ptr CreateTaskQueue( + absl::string_view name, + Priority priority) const override { + return inner_->CreateTaskQueue(name, priority); + } + + private: + TaskQueueFactory* const inner_; + }; + return std::make_unique(GetTaskQueueFactory()); +} bool TimeController::Wait(const std::function& done, TimeDelta max_duration) { // Step size is chosen to be short enough to not significantly affect latency diff --git a/api/test/time_controller.h b/api/test/time_controller.h index 6d09481660..aa69c5200c 100644 --- a/api/test/time_controller.h +++ b/api/test/time_controller.h @@ -35,6 +35,12 @@ class TimeController { // The returned factory will created task queues that runs in implementation // defined time domain. virtual TaskQueueFactory* GetTaskQueueFactory() = 0; + // Simple helper to create an owned factory that can be used as a parameter + // for PeerConnectionFactory. Note that this might depend on the underlying + // time controller and therfore must be destroyed before the time controller + // is destroyed. + std::unique_ptr CreateTaskQueueFactory(); + // Creates a process thread. virtual std::unique_ptr CreateProcessThread( const char* thread_name) = 0; diff --git a/test/peer_scenario/peer_scenario_client.cc b/test/peer_scenario/peer_scenario_client.cc index 4614942f78..3485298fd5 100644 --- a/test/peer_scenario/peer_scenario_client.cc +++ b/test/peer_scenario/peer_scenario_client.cc @@ -114,21 +114,6 @@ class LambdaPeerConnectionObserver final : public PeerConnectionObserver { PeerScenarioClient::CallbackHandlers* handlers_; }; -// Used to supply a unique_ptr for an unowned TaskQueueFactory. -class TaskQueueFactoryWrapper final : public TaskQueueFactory { - public: - explicit TaskQueueFactoryWrapper(TaskQueueFactory* inner_factory) - : inner_factory_(inner_factory) {} - std::unique_ptr CreateTaskQueue( - absl::string_view name, - Priority priority) const override { - return inner_factory_->CreateTaskQueue(name, priority); - } - - private: - TaskQueueFactory* const inner_factory_; -}; - class TimeControllerBasedCallFactory : public CallFactoryInterface { public: explicit TimeControllerBasedCallFactory(TimeController* time_controller) @@ -192,7 +177,7 @@ PeerScenarioClient::PeerScenarioClient( pcf_deps.call_factory = std::make_unique(net->time_controller()); pcf_deps.task_queue_factory = - std::make_unique(task_queue_factory_); + net->time_controller()->CreateTaskQueueFactory(); pcf_deps.event_log_factory = std::make_unique(task_queue_factory_);