Introduce create_modular_peer_connection_factory build target
The new target contains not just the declaration of the
CreateModularPeerConnectionFactory, but also includes all the right dependencies to have definition of that function.
Thus users of the new build target won't need to guess what extra build targets they need to depend on to be able to link.
Bug: webrtc:42220069
Change-Id: I9707446d5ebf933455db3b51be1a789ba2ec8017
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/399180
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Auto-Submit: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45098}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 2cd7560..2dbc1c1 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -70,6 +70,19 @@
]
}
+rtc_source_set("create_modular_peer_connection_factory") {
+ visibility = [ "*" ]
+ allow_poison = [ "environment_construction" ]
+ sources = [ "create_modular_peer_connection_factory.h" ]
+ deps = [
+ ":libjingle_peerconnection_api",
+ ":scoped_refptr",
+ "../pc:peer_connection_factory",
+ "../rtc_base/system:rtc_export",
+ "../stats:rtc_stats",
+ ]
+}
+
if (!build_with_chromium) {
rtc_library("create_peerconnection_factory") {
visibility = [ "*" ]
@@ -79,14 +92,13 @@
"create_peerconnection_factory.h",
]
deps = [
+ ":create_modular_peer_connection_factory",
":enable_media",
":field_trials_view",
":libjingle_peerconnection_api",
":scoped_refptr",
- "../pc:peer_connection_factory",
"../rtc_base:threading",
"../rtc_base/system:rtc_export",
- "../stats:rtc_stats",
"audio:audio_device",
"audio:audio_mixer_api",
"audio:audio_processing",
@@ -277,6 +289,17 @@
]
}
+# TODO: bugs.webrtc.org/42220069 - Remove when downstream has been updated
+# to depend on `create_modular_peer_connection_factory` instead.
+rtc_source_set("create_modular_peer_connection_factory_internal") {
+ visibility = [ ":libjingle_peerconnection_api" ]
+ sources = [ "create_modular_peer_connection_factory_internal.h" ]
+ deps = [
+ ":scoped_refptr",
+ "../rtc_base/system:rtc_export",
+ ]
+}
+
rtc_library("libjingle_peerconnection_api") {
visibility = [ "*" ]
cflags = []
@@ -317,6 +340,7 @@
":async_dns_resolver",
":audio_options_api",
":candidate",
+ ":create_modular_peer_connection_factory_internal",
":data_channel_event_observer_interface",
":dtls_transport_interface",
":fec_controller_api",
diff --git a/api/create_modular_peer_connection_factory.h b/api/create_modular_peer_connection_factory.h
new file mode 100644
index 0000000..9dcd3cb
--- /dev/null
+++ b/api/create_modular_peer_connection_factory.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2025 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef API_CREATE_MODULAR_PEER_CONNECTION_FACTORY_H_
+#define API_CREATE_MODULAR_PEER_CONNECTION_FACTORY_H_
+
+#include "api/peer_connection_interface.h"
+#include "api/scoped_refptr.h"
+#include "rtc_base/system/rtc_export.h"
+
+namespace webrtc {
+// Creates a new instance of PeerConnectionFactoryInterface with optional
+// dependencies.
+//
+// If an application knows it will only require certain modules, it can reduce
+// webrtc's impact on its binary size by depending only on this target and the
+// modules the application requires, using CreateModularPeerConnectionFactory.
+// For example, if an application only uses WebRTC for audio, it can pass in
+// null pointers for the video-specific interfaces, and omit the corresponding
+// modules from its build.
+RTC_EXPORT scoped_refptr<PeerConnectionFactoryInterface>
+CreateModularPeerConnectionFactory(
+ PeerConnectionFactoryDependencies dependencies);
+
+} // namespace webrtc
+
+#endif // API_CREATE_MODULAR_PEER_CONNECTION_FACTORY_H_
diff --git a/api/create_modular_peer_connection_factory_internal.h b/api/create_modular_peer_connection_factory_internal.h
new file mode 100644
index 0000000..370c148
--- /dev/null
+++ b/api/create_modular_peer_connection_factory_internal.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2025 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+// This temporary header is here to steer users of the
+// CreateModularPeerConnectionFactory to include
+// `create_modular_peer_connection_factory.h` and thus depend on
+// `create_modular_peer_connection_factory` build target. Once users are
+// migrated this file can be deleted.
+
+// IWYU pragma: private, include "api/create_modular_peer_connection_factory.h"
+
+#ifndef API_CREATE_MODULAR_PEER_CONNECTION_FACTORY_INTERNAL_H_
+#define API_CREATE_MODULAR_PEER_CONNECTION_FACTORY_INTERNAL_H_
+
+#include "api/scoped_refptr.h"
+#include "rtc_base/system/rtc_export.h"
+
+namespace webrtc {
+
+// Forward declare to avoid circular dependencies with
+// `api/peer_connection_interface.h`. This file exists to be included from that
+// header, and same time requires classes defined in that header.
+class PeerConnectionFactoryInterface;
+struct PeerConnectionFactoryDependencies;
+
+RTC_EXPORT scoped_refptr<PeerConnectionFactoryInterface>
+CreateModularPeerConnectionFactory(
+ PeerConnectionFactoryDependencies dependencies);
+
+} // namespace webrtc
+
+#endif // API_CREATE_MODULAR_PEER_CONNECTION_FACTORY_INTERNAL_H_
diff --git a/api/create_peerconnection_factory.cc b/api/create_peerconnection_factory.cc
index 12434ee..c64828e 100644
--- a/api/create_peerconnection_factory.cc
+++ b/api/create_peerconnection_factory.cc
@@ -19,6 +19,7 @@
#include "api/audio/builtin_audio_processing_builder.h"
#include "api/audio_codecs/audio_decoder_factory.h"
#include "api/audio_codecs/audio_encoder_factory.h"
+#include "api/create_modular_peer_connection_factory.h"
#include "api/enable_media.h"
#include "api/environment/environment_factory.h"
#include "api/field_trials_view.h"
diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h
index 25ac226..0791e8c 100644
--- a/api/peer_connection_interface.h
+++ b/api/peer_connection_interface.h
@@ -148,6 +148,10 @@
#include "rtc_base/system/rtc_export.h"
#include "rtc_base/thread.h"
+// TODO: bugs.webrtc.org/42220069 - Remove this include when users of this
+// function include "create_modular_peer_connection_factory.h" instead.
+#include "api/create_modular_peer_connection_factory_internal.h" // IWYU pragma: keep
+
namespace webrtc {
// IWYU pragma: begin_keep
// MediaFactory class definition is not part of the api.
@@ -1594,26 +1598,6 @@
~PeerConnectionFactoryInterface() override = default;
};
-// CreateModularPeerConnectionFactory is implemented in the "peerconnection"
-// build target, which doesn't pull in the implementations of every module
-// webrtc may use.
-//
-// If an application knows it will only require certain modules, it can reduce
-// webrtc's impact on its binary size by depending only on the "peerconnection"
-// target and the modules the application requires, using
-// CreateModularPeerConnectionFactory. For example, if an application
-// only uses WebRTC for audio, it can pass in null pointers for the
-// video-specific interfaces, and omit the corresponding modules from its
-// build.
-//
-// If `network_thread` or `worker_thread` are null, the PeerConnectionFactory
-// will create the necessary thread internally. If `signaling_thread` is null,
-// the PeerConnectionFactory will use the thread on which this method is called
-// as the signaling thread, wrapping it in an Thread object if needed.
-RTC_EXPORT scoped_refptr<PeerConnectionFactoryInterface>
-CreateModularPeerConnectionFactory(
- PeerConnectionFactoryDependencies dependencies);
-
// https://w3c.github.io/webrtc-pc/#dom-rtcsignalingstate
inline constexpr absl::string_view PeerConnectionInterface::AsString(
SignalingState state) {
diff --git a/pc/peer_connection_factory.cc b/pc/peer_connection_factory.cc
index 70c563f..39038d5 100644
--- a/pc/peer_connection_factory.cc
+++ b/pc/peer_connection_factory.cc
@@ -86,6 +86,9 @@
} // namespace
+// TODO: bugs.webrtc.org/42220069 - Move this function to
+// 'create_modular_peer_connection_factory' build target when all users of this
+// function would depend on that build target.
scoped_refptr<PeerConnectionFactoryInterface>
CreateModularPeerConnectionFactory(
PeerConnectionFactoryDependencies dependencies) {