Restructure PeerConnection tests not to create PortAllocator directly

Instead rely on PeerConnectionFactory to create it.

Bug: webrtc:42232556
Change-Id: I24c9842ef027604b840188306db3e29756e1925f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/376280
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43849}
This commit is contained in:
Danil Chapovalov 2025-02-04 22:21:23 +01:00 committed by WebRTC LUCI CQ
parent e46d8e4ec4
commit 3164c2a4eb
8 changed files with 127 additions and 307 deletions

View File

@ -2183,7 +2183,7 @@ if (rtc_include_tests && !build_with_chromium) {
":peer_connection", ":peer_connection",
":peerconnection_wrapper", ":peerconnection_wrapper",
"../api:audio_options_api", "../api:audio_options_api",
"../api:create_peerconnection_factory", "../api:enable_media_with_defaults",
"../api:libjingle_peerconnection_api", "../api:libjingle_peerconnection_api",
"../api:make_ref_counted", "../api:make_ref_counted",
"../api:media_stream_interface", "../api:media_stream_interface",
@ -2191,15 +2191,8 @@ if (rtc_include_tests && !build_with_chromium) {
"../api:rtc_error_matchers", "../api:rtc_error_matchers",
"../api:rtc_stats_api", "../api:rtc_stats_api",
"../api:scoped_refptr", "../api:scoped_refptr",
"../api/audio:audio_device",
"../api/audio:audio_mixer_api",
"../api/audio:audio_processing",
"../api/audio_codecs:audio_codecs_api",
"../api/audio_codecs:builtin_audio_decoder_factory",
"../api/audio_codecs:builtin_audio_encoder_factory",
"../api/test/metrics:global_metrics_logger_and_exporter", "../api/test/metrics:global_metrics_logger_and_exporter",
"../api/test/metrics:metric", "../api/test/metrics:metric",
"../api/video_codecs:video_codecs_api",
"../api/video_codecs:video_decoder_factory_template", "../api/video_codecs:video_decoder_factory_template",
"../api/video_codecs:video_decoder_factory_template_dav1d_adapter", "../api/video_codecs:video_decoder_factory_template_dav1d_adapter",
"../api/video_codecs:video_decoder_factory_template_libvpx_vp8_adapter", "../api/video_codecs:video_decoder_factory_template_libvpx_vp8_adapter",
@ -2210,26 +2203,19 @@ if (rtc_include_tests && !build_with_chromium) {
"../api/video_codecs:video_encoder_factory_template_libvpx_vp8_adapter", "../api/video_codecs:video_encoder_factory_template_libvpx_vp8_adapter",
"../api/video_codecs:video_encoder_factory_template_libvpx_vp9_adapter", "../api/video_codecs:video_encoder_factory_template_libvpx_vp9_adapter",
"../api/video_codecs:video_encoder_factory_template_open_h264_adapter", "../api/video_codecs:video_encoder_factory_template_open_h264_adapter",
"../media:rtc_media_tests_utils",
"../p2p:basic_packet_socket_factory", "../p2p:basic_packet_socket_factory",
"../p2p:basic_port_allocator",
"../p2p:connection",
"../p2p:p2p_test_utils", "../p2p:p2p_test_utils",
"../p2p:port_allocator",
"../p2p:port_interface", "../p2p:port_interface",
"../rtc_base:checks", "../rtc_base:checks",
"../rtc_base:crypto_random", "../rtc_base:crypto_random",
"../rtc_base:gunit_helpers",
"../rtc_base:rtc_base_tests_utils", "../rtc_base:rtc_base_tests_utils",
"../rtc_base:socket_address", "../rtc_base:socket_address",
"../rtc_base:socket_factory", "../rtc_base:socket_factory",
"../rtc_base:ssl",
"../rtc_base:task_queue_for_test", "../rtc_base:task_queue_for_test",
"../rtc_base:threading", "../rtc_base:threading",
"../system_wrappers", "../system_wrappers",
"../test:test_support", "../test:test_support",
"../test:wait_until", "../test:wait_until",
"//testing/gmock",
] ]
} }
@ -2490,7 +2476,6 @@ if (rtc_include_tests && !build_with_chromium) {
"../modules/audio_processing:mocks", "../modules/audio_processing:mocks",
"../modules/rtp_rtcp:rtp_rtcp_format", "../modules/rtp_rtcp:rtp_rtcp_format",
"../p2p:basic_packet_socket_factory", "../p2p:basic_packet_socket_factory",
"../p2p:basic_port_allocator",
"../p2p:connection_info", "../p2p:connection_info",
"../p2p:dtls_transport_internal", "../p2p:dtls_transport_internal",
"../p2p:fake_port_allocator", "../p2p:fake_port_allocator",
@ -2609,128 +2594,61 @@ if (rtc_include_tests && !build_with_chromium) {
"test/integration_test_helpers.h", "test/integration_test_helpers.h",
] ]
deps = [ deps = [
":audio_rtp_receiver",
":audio_track",
":dtmf_sender",
":jitter_buffer_delay",
":local_audio_source",
":media_session",
":media_stream",
":pc_test_utils", ":pc_test_utils",
":peer_connection", ":peer_connection",
":peer_connection_factory", ":peer_connection_factory",
":peer_connection_proxy", ":peer_connection_proxy",
":remote_audio_source",
":rtp_media_utils",
":rtp_parameters_conversion",
":rtp_receiver",
":rtp_sender",
":rtp_transceiver",
":session_description", ":session_description",
":usage_pattern",
":video_rtp_receiver",
":video_rtp_track_source",
":video_track",
":video_track_source", ":video_track_source",
"../api:array_view",
"../api:audio_options_api", "../api:audio_options_api",
"../api:candidate", "../api:candidate",
"../api:create_peerconnection_factory",
"../api:enable_media_with_defaults", "../api:enable_media_with_defaults",
"../api:fake_frame_decryptor",
"../api:fake_frame_encryptor",
"../api:field_trials", "../api:field_trials",
"../api:field_trials_view", "../api:field_trials_view",
"../api:function_view",
"../api:ice_transport_interface", "../api:ice_transport_interface",
"../api:libjingle_logging_api", "../api:libjingle_logging_api",
"../api:libjingle_peerconnection_api", "../api:libjingle_peerconnection_api",
"../api:make_ref_counted", "../api:make_ref_counted",
"../api:media_stream_interface", "../api:media_stream_interface",
"../api:mock_async_dns_resolver", "../api:mock_async_dns_resolver",
"../api:mock_rtp",
"../api:packet_socket_factory",
"../api:rtc_error", "../api:rtc_error",
"../api:rtc_error_matchers", "../api:rtc_error_matchers",
"../api:rtc_stats_api", "../api:rtc_stats_api",
"../api:rtp_parameters", "../api:rtp_parameters",
"../api:rtp_sender_interface",
"../api:rtp_transceiver_direction", "../api:rtp_transceiver_direction",
"../api:scoped_refptr", "../api:scoped_refptr",
"../api:sequence_checker", "../api:sequence_checker",
"../api/audio:audio_device",
"../api/audio:audio_mixer_api",
"../api/audio:audio_processing",
"../api/audio:builtin_audio_processing_builder", "../api/audio:builtin_audio_processing_builder",
"../api/crypto:frame_decryptor_interface",
"../api/crypto:frame_encryptor_interface",
"../api/crypto:options", "../api/crypto:options",
"../api/metronome", "../api/metronome",
"../api/rtc_event_log",
"../api/rtc_event_log:rtc_event_log_factory", "../api/rtc_event_log:rtc_event_log_factory",
"../api/task_queue", "../api/task_queue",
"../api/task_queue:default_task_queue_factory", "../api/task_queue:default_task_queue_factory",
"../api/task_queue:pending_task_safety_flag", "../api/task_queue:pending_task_safety_flag",
"../api/transport/rtp:rtp_source",
"../api/units:time_delta", "../api/units:time_delta",
"../api/video:builtin_video_bitrate_allocator_factory",
"../api/video:video_rtp_headers", "../api/video:video_rtp_headers",
"../api/video_codecs:video_codecs_api",
"../call:call_interfaces",
"../call/adaptation:resource_adaptation_test_utilities",
"../logging:fake_rtc_event_log", "../logging:fake_rtc_event_log",
"../media:media_engine",
"../media:rtc_media_config",
"../media:rtc_media_tests_utils",
"../media:stream_params", "../media:stream_params",
"../modules/audio_processing:audioproc_test_utils",
"../modules/rtp_rtcp:rtp_rtcp_format",
"../p2p:basic_packet_socket_factory",
"../p2p:basic_port_allocator",
"../p2p:connection",
"../p2p:fake_ice_transport", "../p2p:fake_ice_transport",
"../p2p:fake_port_allocator",
"../p2p:ice_transport_internal", "../p2p:ice_transport_internal",
"../p2p:p2p_constants",
"../p2p:p2p_server_utils",
"../p2p:p2p_test_utils", "../p2p:p2p_test_utils",
"../p2p:port", "../p2p:port",
"../p2p:port_allocator",
"../p2p:port_interface", "../p2p:port_interface",
"../rtc_base:checks", "../rtc_base:checks",
"../rtc_base:crypto_random", "../rtc_base:crypto_random",
"../rtc_base:gunit_helpers",
"../rtc_base:ip_address", "../rtc_base:ip_address",
"../rtc_base:logging", "../rtc_base:logging",
"../rtc_base:macromagic",
"../rtc_base:mdns_responder_interface",
"../rtc_base:null_socket_server",
"../rtc_base:rtc_base_tests_utils", "../rtc_base:rtc_base_tests_utils",
"../rtc_base:rtc_certificate_generator",
"../rtc_base:rtc_event",
"../rtc_base:rtc_json",
"../rtc_base:safe_conversions",
"../rtc_base:socket_address", "../rtc_base:socket_address",
"../rtc_base:socket_factory", "../rtc_base:socket_factory",
"../rtc_base:socket_server", "../rtc_base:socket_server",
"../rtc_base:ssl",
"../rtc_base:ssl_adapter", "../rtc_base:ssl_adapter",
"../rtc_base:task_queue_for_test", "../rtc_base:task_queue_for_test",
"../rtc_base:threading", "../rtc_base:threading",
"../rtc_base:timeutils", "../rtc_base:timeutils",
"../rtc_base/synchronization:mutex",
"../rtc_base/task_utils:repeating_task",
"../rtc_base/third_party/sigslot",
"../system_wrappers:metrics", "../system_wrappers:metrics",
"../test:explicit_key_value_config",
"../test:fileutils",
"../test:rtp_test_utils",
"../test:scoped_key_value_config",
"../test:test_support", "../test:test_support",
"../test:wait_until", "../test:wait_until",
"../test/pc/sctp:fake_sctp_transport",
"../test/time_controller",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/functional:any_invocable", "//third_party/abseil-cpp/absl/functional:any_invocable",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings:string_view", "//third_party/abseil-cpp/absl/strings:string_view",

View File

@ -17,18 +17,13 @@
#include "api/jsep.h" #include "api/jsep.h"
#include "api/jsep_session_description.h" #include "api/jsep_session_description.h"
#include "api/make_ref_counted.h"
#include "api/peer_connection_interface.h" #include "api/peer_connection_interface.h"
#include "api/rtc_error.h" #include "api/rtc_error.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/test/mock_async_dns_resolver.h" #include "api/test/mock_async_dns_resolver.h"
#include "api/test/rtc_error_matchers.h" #include "api/test/rtc_error_matchers.h"
#include "api/units/time_delta.h" #include "api/units/time_delta.h"
#include "p2p/base/port_allocator.h"
#include "p2p/client/basic_port_allocator.h"
#include "pc/peer_connection.h" #include "pc/peer_connection.h"
#include "pc/peer_connection_factory.h"
#include "pc/peer_connection_wrapper.h" #include "pc/peer_connection_wrapper.h"
#include "pc/sdp_utils.h" #include "pc/sdp_utils.h"
#include "pc/test/enable_fake_media.h" #include "pc/test/enable_fake_media.h"
@ -40,6 +35,7 @@
#include "rtc_base/fake_mdns_responder.h" #include "rtc_base/fake_mdns_responder.h"
#include "rtc_base/fake_network.h" #include "rtc_base/fake_network.h"
#include "rtc_base/gunit.h" #include "rtc_base/gunit.h"
#include "rtc_base/network.h"
#include "rtc_base/socket_address.h" #include "rtc_base/socket_address.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
#include "rtc_base/virtual_socket_server.h" #include "rtc_base/virtual_socket_server.h"
@ -71,21 +67,6 @@ int MakeUsageFingerprint(std::set<UsageEvent> events) {
return signature; return signature;
} }
class PeerConnectionFactoryForUsageHistogramTest
: public PeerConnectionFactory {
public:
PeerConnectionFactoryForUsageHistogramTest()
: PeerConnectionFactory([] {
PeerConnectionFactoryDependencies dependencies;
dependencies.network_thread = rtc::Thread::Current();
dependencies.worker_thread = rtc::Thread::Current();
dependencies.signaling_thread = rtc::Thread::Current();
dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
EnableFakeMedia(dependencies);
return dependencies;
}()) {}
};
class PeerConnectionWrapperForUsageHistogramTest; class PeerConnectionWrapperForUsageHistogramTest;
typedef PeerConnectionWrapperForUsageHistogramTest* RawWrapperPtr; typedef PeerConnectionWrapperForUsageHistogramTest* RawWrapperPtr;
@ -229,109 +210,89 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test {
typedef std::unique_ptr<PeerConnectionWrapperForUsageHistogramTest> typedef std::unique_ptr<PeerConnectionWrapperForUsageHistogramTest>
WrapperPtr; WrapperPtr;
PeerConnectionUsageHistogramTest() PeerConnectionUsageHistogramTest() : main_(&vss_) { metrics::Reset(); }
: vss_(new rtc::VirtualSocketServer()),
socket_factory_(new rtc::BasicPacketSocketFactory(vss_.get())),
main_(vss_.get()) {
metrics::Reset();
}
WrapperPtr CreatePeerConnection() { WrapperPtr CreatePeerConnection() {
RTCConfiguration config; RTCConfiguration config;
config.sdp_semantics = SdpSemantics::kUnifiedPlan; config.sdp_semantics = SdpSemantics::kUnifiedPlan;
return CreatePeerConnection( return CreatePeerConnection(config);
config, PeerConnectionFactoryInterface::Options(), nullptr);
} }
WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { WrapperPtr CreatePeerConnection(const RTCConfiguration& config) {
return CreatePeerConnection( return CreatePeerConnection(config,
config, PeerConnectionFactoryInterface::Options(), nullptr); PeerConnectionFactoryInterface::Options(),
PeerConnectionDependencies(nullptr), nullptr);
} }
WrapperPtr CreatePeerConnectionWithMdns(const RTCConfiguration& config) { WrapperPtr CreatePeerConnectionWithMdns(const RTCConfiguration& config) {
auto resolver_factory = PeerConnectionDependencies deps(nullptr /* observer_in */);
deps.async_dns_resolver_factory =
std::make_unique<NiceMock<MockAsyncDnsResolverFactory>>(); std::make_unique<NiceMock<MockAsyncDnsResolverFactory>>();
PeerConnectionDependencies deps(nullptr /* observer_in */); auto fake_network = std::make_unique<rtc::FakeNetworkManager>();
auto fake_network = NewFakeNetwork();
fake_network->set_mdns_responder( fake_network->set_mdns_responder(
std::make_unique<FakeMdnsResponder>(rtc::Thread::Current())); std::make_unique<FakeMdnsResponder>(rtc::Thread::Current()));
fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(NextLocalAddress());
std::unique_ptr<cricket::BasicPortAllocator> port_allocator( return CreatePeerConnection(config,
new cricket::BasicPortAllocator(fake_network, socket_factory_.get())); PeerConnectionFactoryInterface::Options(),
std::move(deps), std::move(fake_network));
deps.async_dns_resolver_factory = std::move(resolver_factory);
deps.allocator = std::move(port_allocator);
return CreatePeerConnection(
config, PeerConnectionFactoryInterface::Options(), std::move(deps));
} }
WrapperPtr CreatePeerConnectionWithImmediateReport() { WrapperPtr CreatePeerConnectionWithImmediateReport() {
RTCConfiguration configuration; RTCConfiguration configuration;
configuration.sdp_semantics = SdpSemantics::kUnifiedPlan; configuration.sdp_semantics = SdpSemantics::kUnifiedPlan;
configuration.report_usage_pattern_delay_ms = 0; configuration.report_usage_pattern_delay_ms = 0;
return CreatePeerConnection( return CreatePeerConnection(configuration);
configuration, PeerConnectionFactoryInterface::Options(), nullptr);
} }
WrapperPtr CreatePeerConnectionWithPrivateLocalAddresses() { WrapperPtr CreatePeerConnectionWithPrivateLocalAddresses() {
auto* fake_network = NewFakeNetwork(); auto fake_network = std::make_unique<rtc::FakeNetworkManager>();
fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(NextLocalAddress());
fake_network->AddInterface(kPrivateLocalAddress); fake_network->AddInterface(kPrivateLocalAddress);
auto port_allocator = std::make_unique<cricket::BasicPortAllocator>(
fake_network, socket_factory_.get());
RTCConfiguration config; RTCConfiguration config;
config.sdp_semantics = SdpSemantics::kUnifiedPlan; config.sdp_semantics = SdpSemantics::kUnifiedPlan;
return CreatePeerConnection(config, return CreatePeerConnection(
PeerConnectionFactoryInterface::Options(), config, PeerConnectionFactoryInterface::Options(),
std::move(port_allocator)); PeerConnectionDependencies(nullptr), std::move(fake_network));
} }
WrapperPtr CreatePeerConnectionWithPrivateIpv6LocalAddresses() { WrapperPtr CreatePeerConnectionWithPrivateIpv6LocalAddresses() {
auto* fake_network = NewFakeNetwork(); auto fake_network = std::make_unique<rtc::FakeNetworkManager>();
fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(NextLocalAddress());
fake_network->AddInterface(kPrivateIpv6LocalAddress); fake_network->AddInterface(kPrivateIpv6LocalAddress);
auto port_allocator = std::make_unique<cricket::BasicPortAllocator>(
fake_network, socket_factory_.get());
RTCConfiguration config; RTCConfiguration config;
config.sdp_semantics = SdpSemantics::kUnifiedPlan; config.sdp_semantics = SdpSemantics::kUnifiedPlan;
return CreatePeerConnection(config, return CreatePeerConnection(
PeerConnectionFactoryInterface::Options(), config, PeerConnectionFactoryInterface::Options(),
std::move(port_allocator)); PeerConnectionDependencies(nullptr), std::move(fake_network));
} }
WrapperPtr CreatePeerConnection( WrapperPtr CreatePeerConnection(
const RTCConfiguration& config, const RTCConfiguration& config,
const PeerConnectionFactoryInterface::Options factory_options, const PeerConnectionFactoryInterface::Options factory_options,
std::unique_ptr<cricket::PortAllocator> allocator) { PeerConnectionDependencies deps,
PeerConnectionDependencies deps(nullptr); std::unique_ptr<rtc::NetworkManager> network_manager) {
deps.allocator = std::move(allocator); PeerConnectionFactoryDependencies pcf_deps;
pcf_deps.network_thread = rtc::Thread::Current();
return CreatePeerConnection(config, factory_options, std::move(deps)); pcf_deps.worker_thread = rtc::Thread::Current();
} pcf_deps.signaling_thread = rtc::Thread::Current();
pcf_deps.socket_factory = &vss_;
WrapperPtr CreatePeerConnection( if (network_manager != nullptr) {
const RTCConfiguration& config, pcf_deps.network_manager = std::move(network_manager);
const PeerConnectionFactoryInterface::Options factory_options, } else {
PeerConnectionDependencies deps) { // If no network manager is provided, one will be created that uses the
auto pc_factory = // host network. This doesn't work on all trybots.
rtc::make_ref_counted<PeerConnectionFactoryForUsageHistogramTest>(); auto fake_network = std::make_unique<rtc::FakeNetworkManager>();
pc_factory->SetOptions(factory_options);
// If no allocator is provided, one will be created using a network manager
// that uses the host network. This doesn't work on all trybots.
if (!deps.allocator) {
auto fake_network = NewFakeNetwork();
fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(NextLocalAddress());
deps.allocator = std::make_unique<cricket::BasicPortAllocator>( pcf_deps.network_manager = std::move(fake_network);
fake_network, socket_factory_.get());
} }
EnableFakeMedia(pcf_deps);
auto pc_factory = CreateModularPeerConnectionFactory(std::move(pcf_deps));
pc_factory->SetOptions(factory_options);
auto observer = std::make_unique<ObserverForUsageHistogramTest>(); auto observer = std::make_unique<ObserverForUsageHistogramTest>();
deps.observer = observer.get(); deps.observer = observer.get();
@ -355,25 +316,13 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test {
return metrics::MinSample(kUsagePatternMetric); return metrics::MinSample(kUsagePatternMetric);
} }
// The PeerConnection's port allocator is tied to the PeerConnection's
// lifetime and expects the underlying NetworkManager to outlive it. That
// prevents us from having the PeerConnectionWrapper own the fake network.
// Therefore, the test fixture will own all the fake networks even though
// tests should access the fake network through the PeerConnectionWrapper.
rtc::FakeNetworkManager* NewFakeNetwork() {
fake_networks_.emplace_back(std::make_unique<rtc::FakeNetworkManager>());
return fake_networks_.back().get();
}
rtc::SocketAddress NextLocalAddress() { rtc::SocketAddress NextLocalAddress() {
RTC_DCHECK(next_local_address_ < (int)arraysize(kLocalAddrs)); RTC_DCHECK(next_local_address_ < (int)arraysize(kLocalAddrs));
return kLocalAddrs[next_local_address_++]; return kLocalAddrs[next_local_address_++];
} }
std::vector<std::unique_ptr<rtc::FakeNetworkManager>> fake_networks_;
int next_local_address_ = 0; int next_local_address_ = 0;
std::unique_ptr<rtc::VirtualSocketServer> vss_; rtc::VirtualSocketServer vss_;
std::unique_ptr<rtc::BasicPacketSocketFactory> socket_factory_;
rtc::AutoSocketServerThread main_; rtc::AutoSocketServerThread main_;
}; };

View File

@ -18,8 +18,8 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "api/audio/audio_device.h"
#include "api/candidate.h" #include "api/candidate.h"
#include "api/enable_media_with_defaults.h"
#include "api/field_trials.h" #include "api/field_trials.h"
#include "api/ice_transport_interface.h" #include "api/ice_transport_interface.h"
#include "api/jsep.h" #include "api/jsep.h"
@ -38,7 +38,6 @@
#include "p2p/base/port_allocator.h" #include "p2p/base/port_allocator.h"
#include "p2p/base/transport_description.h" #include "p2p/base/transport_description.h"
#include "p2p/base/transport_info.h" #include "p2p/base/transport_info.h"
#include "p2p/client/basic_port_allocator.h"
#include "pc/channel_interface.h" #include "pc/channel_interface.h"
#include "pc/dtls_transport.h" #include "pc/dtls_transport.h"
#include "pc/media_session.h" #include "pc/media_session.h"
@ -145,24 +144,10 @@ class PeerConnectionIceBaseTest : public ::testing::Test {
typedef std::unique_ptr<PeerConnectionWrapperForIceTest> WrapperPtr; typedef std::unique_ptr<PeerConnectionWrapperForIceTest> WrapperPtr;
explicit PeerConnectionIceBaseTest(SdpSemantics sdp_semantics) explicit PeerConnectionIceBaseTest(SdpSemantics sdp_semantics)
: vss_(new rtc::VirtualSocketServer()), : main_(&vss_), sdp_semantics_(sdp_semantics) {
socket_factory_(new rtc::BasicPacketSocketFactory(vss_.get())),
main_(vss_.get()),
sdp_semantics_(sdp_semantics) {
#ifdef WEBRTC_ANDROID #ifdef WEBRTC_ANDROID
InitializeAndroidObjects(); InitializeAndroidObjects();
#endif #endif
pc_factory_ = CreatePeerConnectionFactory(
rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
rtc::scoped_refptr<AudioDeviceModule>(FakeAudioCaptureModule::Create()),
CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(),
std::make_unique<VideoEncoderFactoryTemplate<
LibvpxVp8EncoderTemplateAdapter, LibvpxVp9EncoderTemplateAdapter,
OpenH264EncoderTemplateAdapter, LibaomAv1EncoderTemplateAdapter>>(),
std::make_unique<VideoDecoderFactoryTemplate<
LibvpxVp8DecoderTemplateAdapter, LibvpxVp9DecoderTemplateAdapter,
OpenH264DecoderTemplateAdapter, Dav1dDecoderTemplateAdapter>>(),
nullptr /* audio_mixer */, nullptr /* audio_processing */);
} }
WrapperPtr CreatePeerConnection() { WrapperPtr CreatePeerConnection() {
@ -170,18 +155,35 @@ class PeerConnectionIceBaseTest : public ::testing::Test {
} }
WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { WrapperPtr CreatePeerConnection(const RTCConfiguration& config) {
auto* fake_network = NewFakeNetwork(); PeerConnectionFactoryDependencies pcf_deps;
auto port_allocator = std::make_unique<cricket::BasicPortAllocator>( pcf_deps.network_thread = rtc::Thread::Current();
fake_network, socket_factory_.get()); pcf_deps.worker_thread = rtc::Thread::Current();
port_allocator->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | pcf_deps.signaling_thread = rtc::Thread::Current();
cricket::PORTALLOCATOR_DISABLE_RELAY); pcf_deps.socket_factory = &vss_;
port_allocator->set_step_delay(cricket::kMinimumStepDelay); auto network_manager = std::make_unique<rtc::FakeNetworkManager>();
auto* fake_network = network_manager.get();
pcf_deps.network_manager = std::move(network_manager);
pcf_deps.adm = FakeAudioCaptureModule::Create();
pcf_deps.video_encoder_factory =
std::make_unique<VideoEncoderFactoryTemplate<
LibvpxVp8EncoderTemplateAdapter, LibvpxVp9EncoderTemplateAdapter,
OpenH264EncoderTemplateAdapter, LibaomAv1EncoderTemplateAdapter>>();
pcf_deps.video_decoder_factory =
std::make_unique<VideoDecoderFactoryTemplate<
LibvpxVp8DecoderTemplateAdapter, LibvpxVp9DecoderTemplateAdapter,
OpenH264DecoderTemplateAdapter, Dav1dDecoderTemplateAdapter>>();
EnableMediaWithDefaults(pcf_deps);
scoped_refptr<PeerConnectionFactoryInterface> pc_factory =
CreateModularPeerConnectionFactory(std::move(pcf_deps));
RTCConfiguration modified_config = config; RTCConfiguration modified_config = config;
modified_config.set_port_allocator_flags(
cricket::PORTALLOCATOR_DISABLE_TCP |
cricket::PORTALLOCATOR_DISABLE_RELAY);
modified_config.sdp_semantics = sdp_semantics_; modified_config.sdp_semantics = sdp_semantics_;
auto observer = std::make_unique<MockPeerConnectionObserver>(); auto observer = std::make_unique<MockPeerConnectionObserver>();
PeerConnectionDependencies pc_dependencies(observer.get()); PeerConnectionDependencies pc_dependencies(observer.get());
pc_dependencies.allocator = std::move(port_allocator); auto result = pc_factory->CreatePeerConnectionOrError(
auto result = pc_factory_->CreatePeerConnectionOrError(
modified_config, std::move(pc_dependencies)); modified_config, std::move(pc_dependencies));
if (!result.ok()) { if (!result.ok()) {
return nullptr; return nullptr;
@ -189,7 +191,7 @@ class PeerConnectionIceBaseTest : public ::testing::Test {
observer->SetPeerConnectionInterface(result.value().get()); observer->SetPeerConnectionInterface(result.value().get());
auto wrapper = std::make_unique<PeerConnectionWrapperForIceTest>( auto wrapper = std::make_unique<PeerConnectionWrapperForIceTest>(
pc_factory_, result.MoveValue(), std::move(observer)); std::move(pc_factory), result.MoveValue(), std::move(observer));
wrapper->set_network(fake_network); wrapper->set_network(fake_network);
return wrapper; return wrapper;
} }
@ -313,22 +315,8 @@ class PeerConnectionIceBaseTest : public ::testing::Test {
return sdesc->AddCandidate(jsep_candidate.get()); return sdesc->AddCandidate(jsep_candidate.get());
} }
rtc::FakeNetworkManager* NewFakeNetwork() { rtc::VirtualSocketServer vss_;
// The PeerConnection's port allocator is tied to the PeerConnection's
// lifetime and expects the underlying NetworkManager to outlive it. That
// prevents us from having the PeerConnectionWrapper own the fake network.
// Therefore, the test fixture will own all the fake networks even though
// tests should access the fake network through the PeerConnectionWrapper.
auto* fake_network = new rtc::FakeNetworkManager();
fake_networks_.emplace_back(fake_network);
return fake_network;
}
std::unique_ptr<rtc::VirtualSocketServer> vss_;
std::unique_ptr<rtc::BasicPacketSocketFactory> socket_factory_;
rtc::AutoSocketServerThread main_; rtc::AutoSocketServerThread main_;
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_;
std::vector<std::unique_ptr<rtc::FakeNetworkManager>> fake_networks_;
const SdpSemantics sdp_semantics_; const SdpSemantics sdp_semantics_;
}; };

View File

@ -1910,6 +1910,7 @@ TEST_P(PeerConnectionIntegrationTest,
PeerConnectionInterface::RTCConfiguration config; PeerConnectionInterface::RTCConfiguration config;
config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire;
config.port_allocator_config.flags = kOnlyLocalPorts;
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps(
config, std::move(caller_deps), config, std::move(callee_deps))); config, std::move(caller_deps), config, std::move(callee_deps)));
@ -1927,8 +1928,6 @@ TEST_P(PeerConnectionIntegrationTest,
callee()->SetMdnsResponder( callee()->SetMdnsResponder(
std::make_unique<FakeMdnsResponder>(network_thread())); std::make_unique<FakeMdnsResponder>(network_thread()));
SetPortAllocatorFlags(kOnlyLocalPorts, kOnlyLocalPorts);
ConnectFakeSignaling(); ConnectFakeSignaling();
caller()->AddAudioVideoTracks(); caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks(); callee()->AddAudioVideoTracks();
@ -1976,11 +1975,6 @@ class PeerConnectionIntegrationIceStatesTest
return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6); return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6);
} }
void SetPortAllocatorFlags() {
PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags(
port_allocator_flags_, port_allocator_flags_);
}
std::vector<SocketAddress> CallerAddresses() { std::vector<SocketAddress> CallerAddresses() {
std::vector<SocketAddress> addresses; std::vector<SocketAddress> addresses;
addresses.push_back(SocketAddress("1.1.1.1", 0)); addresses.push_back(SocketAddress("1.1.1.1", 0));
@ -2013,6 +2007,8 @@ class PeerConnectionIntegrationIceStatesTest
} }
} }
uint32_t port_allocator_flags() const { return port_allocator_flags_; }
private: private:
uint32_t port_allocator_flags_; uint32_t port_allocator_flags_;
cricket::TestStunServer::StunServerPtr stun_server_; cricket::TestStunServer::StunServerPtr stun_server_;
@ -2036,9 +2032,10 @@ TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock,
firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address); firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address);
} }
ASSERT_TRUE(CreatePeerConnectionWrappers()); PeerConnectionInterface::RTCConfiguration config;
config.port_allocator_config.flags = port_allocator_flags();
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
ConnectFakeSignaling(); ConnectFakeSignaling();
SetPortAllocatorFlags();
SetUpNetworkInterfaces(); SetUpNetworkInterfaces();
caller()->AddAudioVideoTracks(); caller()->AddAudioVideoTracks();
caller()->CreateAndSetAndSignalOffer(); caller()->CreateAndSetAndSignalOffer();
@ -2066,9 +2063,10 @@ TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock,
#define MAYBE_VerifyBestConnection VerifyBestConnection #define MAYBE_VerifyBestConnection VerifyBestConnection
#endif #endif
TEST_P(PeerConnectionIntegrationIceStatesTest, MAYBE_VerifyBestConnection) { TEST_P(PeerConnectionIntegrationIceStatesTest, MAYBE_VerifyBestConnection) {
ASSERT_TRUE(CreatePeerConnectionWrappers()); PeerConnectionInterface::RTCConfiguration config;
config.port_allocator_config.flags = port_allocator_flags();
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
ConnectFakeSignaling(); ConnectFakeSignaling();
SetPortAllocatorFlags();
SetUpNetworkInterfaces(); SetUpNetworkInterfaces();
caller()->AddAudioVideoTracks(); caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks(); callee()->AddAudioVideoTracks();

View File

@ -14,11 +14,8 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "api/audio/audio_device.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/audio_options.h" #include "api/audio_options.h"
#include "api/create_peerconnection_factory.h" #include "api/enable_media_with_defaults.h"
#include "api/jsep.h" #include "api/jsep.h"
#include "api/make_ref_counted.h" #include "api/make_ref_counted.h"
#include "api/media_stream_interface.h" #include "api/media_stream_interface.h"
@ -42,10 +39,8 @@
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h" #include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h" #include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
#include "p2p/base/basic_packet_socket_factory.h" #include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/port_allocator.h"
#include "p2p/base/port_interface.h" #include "p2p/base/port_interface.h"
#include "p2p/base/test_turn_server.h" #include "p2p/base/test_turn_server.h"
#include "p2p/client/basic_port_allocator.h"
#include "pc/peer_connection.h" #include "pc/peer_connection.h"
#include "pc/peer_connection_wrapper.h" #include "pc/peer_connection_wrapper.h"
#include "pc/test/fake_audio_capture_module.h" #include "pc/test/fake_audio_capture_module.h"
@ -157,30 +152,15 @@ class PeerConnectionRampUpTest : public ::testing::Test {
public: public:
PeerConnectionRampUpTest() PeerConnectionRampUpTest()
: clock_(Clock::GetRealTimeClock()), : clock_(Clock::GetRealTimeClock()),
virtual_socket_server_(new rtc::VirtualSocketServer()), firewall_socket_server_(&virtual_socket_server_),
firewall_socket_server_( network_thread_(&firewall_socket_server_),
new rtc::FirewallSocketServer(virtual_socket_server_.get())),
firewall_socket_factory_(
new rtc::BasicPacketSocketFactory(firewall_socket_server_.get())),
network_thread_(new rtc::Thread(firewall_socket_server_.get())),
worker_thread_(rtc::Thread::Create()) { worker_thread_(rtc::Thread::Create()) {
network_thread_->SetName("PCNetworkThread", this); network_thread_.SetName("PCNetworkThread", this);
worker_thread_->SetName("PCWorkerThread", this); worker_thread_->SetName("PCWorkerThread", this);
RTC_CHECK(network_thread_->Start()); RTC_CHECK(network_thread_.Start());
RTC_CHECK(worker_thread_->Start()); RTC_CHECK(worker_thread_->Start());
virtual_socket_server_->set_bandwidth(kNetworkBandwidth / 8); virtual_socket_server_.set_bandwidth(kNetworkBandwidth / 8);
pc_factory_ = CreatePeerConnectionFactory(
network_thread_.get(), worker_thread_.get(), rtc::Thread::Current(),
rtc::scoped_refptr<AudioDeviceModule>(FakeAudioCaptureModule::Create()),
CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(),
std::make_unique<VideoEncoderFactoryTemplate<
LibvpxVp8EncoderTemplateAdapter, LibvpxVp9EncoderTemplateAdapter,
OpenH264EncoderTemplateAdapter, LibaomAv1EncoderTemplateAdapter>>(),
std::make_unique<VideoDecoderFactoryTemplate<
LibvpxVp8DecoderTemplateAdapter, LibvpxVp9DecoderTemplateAdapter,
OpenH264DecoderTemplateAdapter, Dav1dDecoderTemplateAdapter>>(),
nullptr /* audio_mixer */, nullptr /* audio_processing */);
} }
virtual ~PeerConnectionRampUpTest() { virtual ~PeerConnectionRampUpTest() {
@ -196,30 +176,40 @@ class PeerConnectionRampUpTest : public ::testing::Test {
std::unique_ptr<PeerConnectionWrapperForRampUpTest> std::unique_ptr<PeerConnectionWrapperForRampUpTest>
CreatePeerConnectionWrapper(const RTCConfiguration& config) { CreatePeerConnectionWrapper(const RTCConfiguration& config) {
auto* fake_network_manager = new rtc::FakeNetworkManager(); PeerConnectionFactoryDependencies pcf_deps;
fake_network_manager->AddInterface(kDefaultLocalAddress); pcf_deps.network_thread = network_thread();
fake_network_managers_.emplace_back(fake_network_manager); pcf_deps.worker_thread = worker_thread_.get();
pcf_deps.signaling_thread = rtc::Thread::Current();
pcf_deps.socket_factory = &firewall_socket_server_;
auto network_manager = std::make_unique<rtc::FakeNetworkManager>();
network_manager->AddInterface(kDefaultLocalAddress);
pcf_deps.network_manager = std::move(network_manager);
pcf_deps.adm = FakeAudioCaptureModule::Create();
pcf_deps.video_encoder_factory =
std::make_unique<VideoEncoderFactoryTemplate<
LibvpxVp8EncoderTemplateAdapter, LibvpxVp9EncoderTemplateAdapter,
OpenH264EncoderTemplateAdapter, LibaomAv1EncoderTemplateAdapter>>();
pcf_deps.video_decoder_factory =
std::make_unique<VideoDecoderFactoryTemplate<
LibvpxVp8DecoderTemplateAdapter, LibvpxVp9DecoderTemplateAdapter,
OpenH264DecoderTemplateAdapter, Dav1dDecoderTemplateAdapter>>();
EnableMediaWithDefaults(pcf_deps);
scoped_refptr<PeerConnectionFactoryInterface> pc_factory =
CreateModularPeerConnectionFactory(std::move(pcf_deps));
auto observer = std::make_unique<MockPeerConnectionObserver>(); auto observer = std::make_unique<MockPeerConnectionObserver>();
PeerConnectionDependencies dependencies(observer.get()); PeerConnectionDependencies dependencies(observer.get());
cricket::BasicPortAllocator* port_allocator =
new cricket::BasicPortAllocator(fake_network_manager,
firewall_socket_factory_.get());
port_allocator->set_step_delay(cricket::kDefaultStepDelay);
dependencies.allocator =
std::unique_ptr<cricket::BasicPortAllocator>(port_allocator);
dependencies.tls_cert_verifier = dependencies.tls_cert_verifier =
std::make_unique<rtc::TestCertificateVerifier>(); std::make_unique<rtc::TestCertificateVerifier>();
auto result = pc_factory_->CreatePeerConnectionOrError( auto result = pc_factory->CreatePeerConnectionOrError(
config, std::move(dependencies)); config, std::move(dependencies));
if (!result.ok()) { if (!result.ok()) {
return nullptr; return nullptr;
} }
return std::make_unique<PeerConnectionWrapperForRampUpTest>( return std::make_unique<PeerConnectionWrapperForRampUpTest>(
pc_factory_, result.MoveValue(), std::move(observer)); std::move(pc_factory), result.MoveValue(), std::move(observer));
} }
void SetupOneWayCall() { void SetupOneWayCall() {
@ -261,9 +251,9 @@ class PeerConnectionRampUpTest : public ::testing::Test {
void CreateTurnServer(cricket::ProtocolType type, void CreateTurnServer(cricket::ProtocolType type,
const std::string& common_name = "test turn server") { const std::string& common_name = "test turn server") {
rtc::Thread* thread = network_thread(); rtc::Thread* thread = network_thread();
rtc::SocketFactory* factory = firewall_socket_server_.get(); rtc::SocketFactory* factory = &firewall_socket_server_;
std::unique_ptr<cricket::TestTurnServer> turn_server; std::unique_ptr<cricket::TestTurnServer> turn_server;
SendTask(network_thread_.get(), [&] { SendTask(network_thread(), [&] {
static const rtc::SocketAddress turn_server_internal_address{ static const rtc::SocketAddress turn_server_internal_address{
kTurnInternalAddress, kTurnInternalPort}; kTurnInternalAddress, kTurnInternalPort};
static const rtc::SocketAddress turn_server_external_address{ static const rtc::SocketAddress turn_server_external_address{
@ -299,10 +289,10 @@ class PeerConnectionRampUpTest : public ::testing::Test {
ImprovementDirection::kNeitherIsBetter); ImprovementDirection::kNeitherIsBetter);
} }
rtc::Thread* network_thread() { return network_thread_.get(); } rtc::Thread* network_thread() { return &network_thread_; }
rtc::FirewallSocketServer* firewall_socket_server() { rtc::FirewallSocketServer* firewall_socket_server() {
return firewall_socket_server_.get(); return &firewall_socket_server_;
} }
PeerConnectionWrapperForRampUpTest* caller() { return caller_.get(); } PeerConnectionWrapperForRampUpTest* caller() { return caller_.get(); }
@ -353,16 +343,12 @@ class PeerConnectionRampUpTest : public ::testing::Test {
// the VirtualSocketServer. The first ramp down time is very noisy and the // the VirtualSocketServer. The first ramp down time is very noisy and the
// second ramp up time can take up to 300 seconds, most likely due to a built // second ramp up time can take up to 300 seconds, most likely due to a built
// up queue. // up queue.
std::unique_ptr<rtc::VirtualSocketServer> virtual_socket_server_; rtc::VirtualSocketServer virtual_socket_server_;
std::unique_ptr<rtc::FirewallSocketServer> firewall_socket_server_; rtc::FirewallSocketServer firewall_socket_server_;
std::unique_ptr<rtc::BasicPacketSocketFactory> firewall_socket_factory_;
std::unique_ptr<rtc::Thread> network_thread_; rtc::Thread network_thread_;
std::unique_ptr<rtc::Thread> worker_thread_; std::unique_ptr<rtc::Thread> worker_thread_;
// The `pc_factory` uses `network_thread_` & `worker_thread_`, so it must be
// destroyed first.
std::vector<std::unique_ptr<rtc::FakeNetworkManager>> fake_network_managers_;
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_;
std::unique_ptr<PeerConnectionWrapperForRampUpTest> caller_; std::unique_ptr<PeerConnectionWrapperForRampUpTest> caller_;
std::unique_ptr<PeerConnectionWrapperForRampUpTest> callee_; std::unique_ptr<PeerConnectionWrapperForRampUpTest> callee_;
}; };

View File

@ -289,11 +289,6 @@ class PeerConnectionIntegrationIceStatesTest
return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6); return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6);
} }
void SetPortAllocatorFlags() {
PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags(
port_allocator_flags_, port_allocator_flags_);
}
std::vector<SocketAddress> CallerAddresses() { std::vector<SocketAddress> CallerAddresses() {
std::vector<SocketAddress> addresses; std::vector<SocketAddress> addresses;
addresses.push_back(SocketAddress("1.1.1.1", 0)); addresses.push_back(SocketAddress("1.1.1.1", 0));
@ -326,6 +321,8 @@ class PeerConnectionIntegrationIceStatesTest
} }
} }
uint32_t port_allocator_flags() const { return port_allocator_flags_; }
private: private:
uint32_t port_allocator_flags_; uint32_t port_allocator_flags_;
cricket::TestStunServer::StunServerPtr stun_server_; cricket::TestStunServer::StunServerPtr stun_server_;
@ -354,10 +351,10 @@ TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, VerifyIceStates) {
"stun:" + kStunServerAddress.HostAsURIString() + ":" + "stun:" + kStunServerAddress.HostAsURIString() + ":" +
kStunServerAddress.PortAsString()); kStunServerAddress.PortAsString());
config.servers.push_back(ice_stun_server); config.servers.push_back(ice_stun_server);
config.port_allocator_config.flags = port_allocator_flags();
ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
ConnectFakeSignaling(); ConnectFakeSignaling();
SetPortAllocatorFlags();
SetUpNetworkInterfaces(); SetUpNetworkInterfaces();
caller()->AddAudioVideoTracks(); caller()->AddAudioVideoTracks();
callee()->AddAudioVideoTracks(); callee()->AddAudioVideoTracks();

View File

@ -20,6 +20,7 @@
#include "absl/functional/any_invocable.h" #include "absl/functional/any_invocable.h"
#include "api/audio/builtin_audio_processing_builder.h" #include "api/audio/builtin_audio_processing_builder.h"
#include "api/enable_media_with_defaults.h" #include "api/enable_media_with_defaults.h"
#include "api/field_trials_view.h"
#include "api/jsep.h" #include "api/jsep.h"
#include "api/peer_connection_interface.h" #include "api/peer_connection_interface.h"
#include "api/rtc_event_log/rtc_event_log_factory.h" #include "api/rtc_event_log/rtc_event_log_factory.h"
@ -30,9 +31,6 @@
#include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_base.h"
#include "api/units/time_delta.h" #include "api/units/time_delta.h"
#include "logging/rtc_event_log/fake_rtc_event_log_factory.h" #include "logging/rtc_event_log/fake_rtc_event_log_factory.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/port_allocator.h"
#include "p2p/client/basic_port_allocator.h"
#include "pc/peer_connection_factory.h" #include "pc/peer_connection_factory.h"
#include "pc/test/fake_audio_capture_module.h" #include "pc/test/fake_audio_capture_module.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
@ -231,16 +229,12 @@ bool PeerConnectionIntegrationWrapper::Init(
RTC_DCHECK(!peer_connection_); RTC_DCHECK(!peer_connection_);
RTC_DCHECK(!peer_connection_factory_); RTC_DCHECK(!peer_connection_factory_);
fake_network_manager_.reset(new rtc::FakeNetworkManager()); auto network_manager = std::make_unique<rtc::FakeNetworkManager>();
fake_network_manager_ = network_manager.get();
fake_network_manager_->AddInterface(kDefaultLocalAddress); fake_network_manager_->AddInterface(kDefaultLocalAddress);
socket_factory_.reset(new rtc::BasicPacketSocketFactory(socket_server));
network_thread_ = network_thread; network_thread_ = network_thread;
std::unique_ptr<cricket::PortAllocator> port_allocator(
new cricket::BasicPortAllocator(fake_network_manager_.get(),
socket_factory_.get()));
port_allocator_ = port_allocator.get();
fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
if (!fake_audio_capture_module_) { if (!fake_audio_capture_module_) {
return false; return false;
@ -251,6 +245,8 @@ bool PeerConnectionIntegrationWrapper::Init(
pc_factory_dependencies.network_thread = network_thread; pc_factory_dependencies.network_thread = network_thread;
pc_factory_dependencies.worker_thread = worker_thread; pc_factory_dependencies.worker_thread = worker_thread;
pc_factory_dependencies.signaling_thread = signaling_thread; pc_factory_dependencies.signaling_thread = signaling_thread;
pc_factory_dependencies.socket_factory = socket_server;
pc_factory_dependencies.network_manager = std::move(network_manager);
pc_factory_dependencies.task_queue_factory = CreateDefaultTaskQueueFactory(); pc_factory_dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
pc_factory_dependencies.trials = std::move(field_trials); pc_factory_dependencies.trials = std::move(field_trials);
pc_factory_dependencies.decode_metronome = pc_factory_dependencies.decode_metronome =
@ -284,6 +280,7 @@ bool PeerConnectionIntegrationWrapper::Init(
CreateModularPeerConnectionFactory(std::move(pc_factory_dependencies)); CreateModularPeerConnectionFactory(std::move(pc_factory_dependencies));
if (!peer_connection_factory_) { if (!peer_connection_factory_) {
fake_network_manager_ = nullptr;
return false; return false;
} }
if (options) { if (options) {
@ -293,7 +290,6 @@ bool PeerConnectionIntegrationWrapper::Init(
sdp_semantics_ = config->sdp_semantics; sdp_semantics_ = config->sdp_semantics;
} }
dependencies.allocator = std::move(port_allocator);
peer_connection_ = CreatePeerConnection(config, std::move(dependencies)); peer_connection_ = CreatePeerConnection(config, std::move(dependencies));
return peer_connection_.get() != nullptr; return peer_connection_.get() != nullptr;
} }

View File

@ -63,7 +63,6 @@
#include "p2p/base/fake_ice_transport.h" #include "p2p/base/fake_ice_transport.h"
#include "p2p/base/ice_transport_internal.h" #include "p2p/base/ice_transport_internal.h"
#include "p2p/base/port.h" #include "p2p/base/port.h"
#include "p2p/base/port_allocator.h"
#include "p2p/base/port_interface.h" #include "p2p/base/port_interface.h"
#include "p2p/base/test_turn_customizer.h" #include "p2p/base/test_turn_customizer.h"
#include "p2p/base/test_turn_server.h" #include "p2p/base/test_turn_server.h"
@ -645,9 +644,8 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
} }
rtc::FakeNetworkManager* network_manager() const { rtc::FakeNetworkManager* network_manager() const {
return fake_network_manager_.get(); return fake_network_manager_;
} }
cricket::PortAllocator* port_allocator() const { return port_allocator_; }
FakeRtcEventLogFactory* event_log_factory() const { FakeRtcEventLogFactory* event_log_factory() const {
return event_log_factory_; return event_log_factory_;
@ -1120,8 +1118,8 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
std::string debug_name_; std::string debug_name_;
std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_; // Network manager is owned by the `peer_connection_factory_`.
std::unique_ptr<rtc::BasicPacketSocketFactory> socket_factory_; rtc::FakeNetworkManager* fake_network_manager_ = nullptr;
rtc::Thread* network_thread_; rtc::Thread* network_thread_;
// Reference to the mDNS responder owned by `fake_network_manager_` after set. // Reference to the mDNS responder owned by `fake_network_manager_` after set.
@ -1130,7 +1128,6 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
rtc::scoped_refptr<PeerConnectionInterface> peer_connection_; rtc::scoped_refptr<PeerConnectionInterface> peer_connection_;
rtc::scoped_refptr<PeerConnectionFactoryInterface> peer_connection_factory_; rtc::scoped_refptr<PeerConnectionFactoryInterface> peer_connection_factory_;
cricket::PortAllocator* port_allocator_;
// Needed to keep track of number of frames sent. // Needed to keep track of number of frames sent.
rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
// Needed to keep track of number of frames received. // Needed to keep track of number of frames received.
@ -1709,15 +1706,6 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test {
return old; return old;
} }
void SetPortAllocatorFlags(uint32_t caller_flags, uint32_t callee_flags) {
SendTask(network_thread(), [this, caller_flags] {
caller()->port_allocator()->set_flags(caller_flags);
});
SendTask(network_thread(), [this, callee_flags] {
callee()->port_allocator()->set_flags(callee_flags);
});
}
rtc::FirewallSocketServer* firewall() const { return fss_.get(); } rtc::FirewallSocketServer* firewall() const { return fss_.get(); }
// Expects the provided number of new frames to be received within // Expects the provided number of new frames to be received within