Add an rtc::SocketFactory* member to PeerConnectionFactoryDependencies

Bug: webrtc:13145
Change-Id: I0267013fdda42e09dc23551a73a6151e0fb9b72e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249950
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35909}
This commit is contained in:
Niels Möller
2022-02-04 14:29:50 +01:00
committed by WebRTC LUCI CQ
parent 64253a93dc
commit b02e1acdaa
4 changed files with 49 additions and 24 deletions

View File

@ -49,6 +49,10 @@ rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
dependencies.task_queue_factory.get());
dependencies.trials = std::make_unique<webrtc::FieldTrialBasedConfig>();
if (network_thread) {
// TODO(bugs.webrtc.org/13145): Add an rtc::SocketFactory* argument.
dependencies.socket_factory = network_thread->socketserver();
}
cricket::MediaEngineDependencies media_dependencies;
media_dependencies.task_queue_factory = dependencies.task_queue_factory.get();
media_dependencies.adm = std::move(default_adm);

View File

@ -1421,6 +1421,7 @@ struct RTC_EXPORT PeerConnectionFactoryDependencies final {
rtc::Thread* network_thread = nullptr;
rtc::Thread* worker_thread = nullptr;
rtc::Thread* signaling_thread = nullptr;
rtc::SocketFactory* socket_factory = nullptr;
std::unique_ptr<TaskQueueFactory> task_queue_factory;
std::unique_ptr<cricket::MediaEngineInterface> media_engine;
std::unique_ptr<CallFactoryInterface> call_factory;

View File

@ -17,6 +17,7 @@
#include "api/transport/field_trial_based_config.h"
#include "media/sctp/sctp_transport_factory.h"
#include "rtc_base/helpers.h"
#include "rtc_base/internal/default_socket_server.h"
#include "rtc_base/task_utils/to_queued_task.h"
#include "rtc_base/time_utils.h"
@ -24,19 +25,31 @@ namespace webrtc {
namespace {
rtc::Thread* MaybeStartThread(rtc::Thread* old_thread,
const std::string& thread_name,
bool with_socket_server,
rtc::Thread* MaybeStartNetworkThread(
rtc::Thread* old_thread,
std::unique_ptr<rtc::SocketFactory>& socket_factory_holder,
std::unique_ptr<rtc::Thread>& thread_holder) {
if (old_thread) {
return old_thread;
}
if (with_socket_server) {
thread_holder = rtc::Thread::CreateWithSocketServer();
} else {
thread_holder = rtc::Thread::Create();
std::unique_ptr<rtc::SocketServer> socket_server =
rtc::CreateDefaultSocketServer();
thread_holder = std::make_unique<rtc::Thread>(socket_server.get());
socket_factory_holder = std::move(socket_server);
thread_holder->SetName("pc_network_thread", nullptr);
thread_holder->Start();
return thread_holder.get();
}
thread_holder->SetName(thread_name, nullptr);
rtc::Thread* MaybeStartWorkerThread(
rtc::Thread* old_thread,
std::unique_ptr<rtc::Thread>& thread_holder) {
if (old_thread) {
return old_thread;
}
thread_holder = rtc::Thread::Create();
thread_holder->SetName("pc_worker_thread", nullptr);
thread_holder->Start();
return thread_holder.get();
}
@ -81,13 +94,10 @@ rtc::scoped_refptr<ConnectionContext> ConnectionContext::Create(
ConnectionContext::ConnectionContext(
PeerConnectionFactoryDependencies* dependencies)
: network_thread_(MaybeStartThread(dependencies->network_thread,
"pc_network_thread",
true,
: network_thread_(MaybeStartNetworkThread(dependencies->network_thread,
owned_socket_factory_,
owned_network_thread_)),
worker_thread_(MaybeStartThread(dependencies->worker_thread,
"pc_worker_thread",
false,
worker_thread_(MaybeStartWorkerThread(dependencies->worker_thread,
owned_worker_thread_)),
signaling_thread_(MaybeWrapThread(dependencies->signaling_thread,
wraps_current_thread_)),
@ -117,17 +127,26 @@ ConnectionContext::ConnectionContext(
RTC_DCHECK_RUN_ON(signaling_thread_);
rtc::InitRandom(rtc::Time32());
rtc::SocketFactory* socket_factory = dependencies->socket_factory;
if (socket_factory == nullptr) {
if (owned_socket_factory_) {
socket_factory = owned_socket_factory_.get();
} else {
// TODO(bugs.webrtc.org/13145): This case should be deleted. Either
// require that a PacketSocketFactory and NetworkManager always are
// injected (with no need to construct these default objects), or require
// that if a network_thread is injected, an approprite rtc::SocketServer
// should be injected too.
socket_factory = network_thread()->socketserver();
}
}
// If network_monitor_factory_ is non-null, it will be used to create a
// network monitor while on the network thread.
default_network_manager_ = std::make_unique<rtc::BasicNetworkManager>(
network_monitor_factory_.get(), network_thread()->socketserver());
network_monitor_factory_.get(), socket_factory);
// TODO(bugs.webrtc.org/13145): Either require that a PacketSocketFactory
// always is injected (with no need to construct this default factory), or get
// the appropriate underlying SocketFactory without going through the
// rtc::Thread::socketserver() accessor.
default_socket_factory_ = std::make_unique<rtc::BasicPacketSocketFactory>(
network_thread()->socketserver());
default_socket_factory_ =
std::make_unique<rtc::BasicPacketSocketFactory>(socket_factory);
channel_manager_ = cricket::ChannelManager::Create(
std::move(dependencies->media_engine),

View File

@ -103,6 +103,7 @@ class ConnectionContext final
// Note: Since owned_network_thread_ and owned_worker_thread_ are used
// in the initialization of network_thread_ and worker_thread_, they
// must be declared before them, so that they are initialized first.
std::unique_ptr<rtc::SocketFactory> owned_socket_factory_;
std::unique_ptr<rtc::Thread> owned_network_thread_
RTC_GUARDED_BY(signaling_thread_);
std::unique_ptr<rtc::Thread> owned_worker_thread_