Reland "Move injection of PacketSocketFactory from PC to PCF"
This is a reland of commit 905c3a6c73d293882ef11942066ccda52a9e14d1
Change from previous attempt is between ps#1 and ps#2: Use PeerConnectionFactoryInterface::Options to clear the `network_ignore_mask`.
Original change's description:
> Move injection of PacketSocketFactory from PC to PCF
>
> Injection via PeerConnectionDependecies was broken, in not accepting
> ownership of the injected object.
>
> Bug: webrtc:7447, webrtc:14204
> Change-Id: Ic53f05d51928b006fc1e46d502633d88471eb518
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/266140
> Reviewed-by: Harald Alvestrand <hta@webrtc.org>
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#37270}
Bug: webrtc:7447, webrtc:14204
Change-Id: Ic78ebec2e88a8c44699015c8c7a44e137f44253a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265982
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37290}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 5f6bc49..cd1c104 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -1100,6 +1100,17 @@
]
}
+ rtc_source_set("mock_packet_socket_factory") {
+ visibility = [ "*" ]
+ testonly = true
+ sources = [ "test/mock_packet_socket_factory.h" ]
+
+ deps = [
+ ":packet_socket_factory",
+ "../test:test_support",
+ ]
+ }
+
rtc_source_set("mock_peerconnectioninterface") {
visibility = [ "*" ]
testonly = true
@@ -1322,6 +1333,7 @@
":mock_frame_decryptor",
":mock_frame_encryptor",
":mock_media_stream_interface",
+ ":mock_packet_socket_factory",
":mock_peer_connection_factory_interface",
":mock_peerconnectioninterface",
":mock_rtp",
diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h
index 3e70855..8a6ae96 100644
--- a/api/peer_connection_interface.h
+++ b/api/peer_connection_interface.h
@@ -1379,10 +1379,9 @@
PeerConnectionObserver* observer = nullptr;
// Optional dependencies
// TODO(bugs.webrtc.org/7447): remove port allocator once downstream is
- // updated. For now, you can only set one of allocator and
- // packet_socket_factory, not both.
+ // updated. The recommended way to inject networking components is to pass a
+ // PacketSocketFactory when creating the PeerConnectionFactory.
std::unique_ptr<cricket::PortAllocator> allocator;
- std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory;
// Factory for creating resolvers that look up hostnames in DNS
std::unique_ptr<webrtc::AsyncDnsResolverFactoryInterface>
async_dns_resolver_factory;
@@ -1422,6 +1421,7 @@
rtc::Thread* worker_thread = nullptr;
rtc::Thread* signaling_thread = nullptr;
rtc::SocketFactory* socket_factory = nullptr;
+ std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory;
std::unique_ptr<TaskQueueFactory> task_queue_factory;
std::unique_ptr<cricket::MediaEngineInterface> media_engine;
std::unique_ptr<CallFactoryInterface> call_factory;
diff --git a/api/test/mock_packet_socket_factory.h b/api/test/mock_packet_socket_factory.h
new file mode 100644
index 0000000..7e59556
--- /dev/null
+++ b/api/test/mock_packet_socket_factory.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2022 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_TEST_MOCK_PACKET_SOCKET_FACTORY_H_
+#define API_TEST_MOCK_PACKET_SOCKET_FACTORY_H_
+
+#include <memory>
+#include <string>
+
+#include "api/packet_socket_factory.h"
+#include "test/gmock.h"
+
+namespace rtc {
+class MockPacketSocketFactory : public PacketSocketFactory {
+ public:
+ MOCK_METHOD(AsyncPacketSocket*,
+ CreateUdpSocket,
+ (const SocketAddress&, uint16_t, uint16_t),
+ (override));
+ MOCK_METHOD(AsyncListenSocket*,
+ CreateServerTcpSocket,
+ (const SocketAddress&, uint16_t, uint16_t, int opts),
+ (override));
+ MOCK_METHOD(AsyncPacketSocket*,
+ CreateClientTcpSocket,
+ (const SocketAddress& local_address,
+ const SocketAddress&,
+ const ProxyInfo&,
+ const std::string&,
+ const PacketSocketTcpOptions&),
+ (override));
+ MOCK_METHOD(std::unique_ptr<webrtc::AsyncDnsResolverInterface>,
+ CreateAsyncDnsResolver,
+ (),
+ (override));
+};
+
+static_assert(!std::is_abstract_v<MockPacketSocketFactory>, "");
+
+} // namespace rtc
+
+#endif // API_TEST_MOCK_PACKET_SOCKET_FACTORY_H_