diff --git a/pc/BUILD.gn b/pc/BUILD.gn index c73261c6df..91c36ff9b5 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -2183,7 +2183,7 @@ if (rtc_include_tests && !build_with_chromium) { ":peer_connection", ":peerconnection_wrapper", "../api:audio_options_api", - "../api:create_peerconnection_factory", + "../api:enable_media_with_defaults", "../api:libjingle_peerconnection_api", "../api:make_ref_counted", "../api:media_stream_interface", @@ -2191,15 +2191,8 @@ if (rtc_include_tests && !build_with_chromium) { "../api:rtc_error_matchers", "../api:rtc_stats_api", "../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:metric", - "../api/video_codecs:video_codecs_api", "../api/video_codecs:video_decoder_factory_template", "../api/video_codecs:video_decoder_factory_template_dav1d_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_vp9_adapter", "../api/video_codecs:video_encoder_factory_template_open_h264_adapter", - "../media:rtc_media_tests_utils", "../p2p:basic_packet_socket_factory", - "../p2p:basic_port_allocator", - "../p2p:connection", "../p2p:p2p_test_utils", - "../p2p:port_allocator", "../p2p:port_interface", "../rtc_base:checks", "../rtc_base:crypto_random", - "../rtc_base:gunit_helpers", "../rtc_base:rtc_base_tests_utils", "../rtc_base:socket_address", "../rtc_base:socket_factory", - "../rtc_base:ssl", "../rtc_base:task_queue_for_test", "../rtc_base:threading", "../system_wrappers", "../test:test_support", "../test:wait_until", - "//testing/gmock", ] } @@ -2490,7 +2476,6 @@ if (rtc_include_tests && !build_with_chromium) { "../modules/audio_processing:mocks", "../modules/rtp_rtcp:rtp_rtcp_format", "../p2p:basic_packet_socket_factory", - "../p2p:basic_port_allocator", "../p2p:connection_info", "../p2p:dtls_transport_internal", "../p2p:fake_port_allocator", @@ -2609,128 +2594,61 @@ if (rtc_include_tests && !build_with_chromium) { "test/integration_test_helpers.h", ] deps = [ - ":audio_rtp_receiver", - ":audio_track", - ":dtmf_sender", - ":jitter_buffer_delay", - ":local_audio_source", - ":media_session", - ":media_stream", ":pc_test_utils", ":peer_connection", ":peer_connection_factory", ":peer_connection_proxy", - ":remote_audio_source", - ":rtp_media_utils", - ":rtp_parameters_conversion", - ":rtp_receiver", - ":rtp_sender", - ":rtp_transceiver", ":session_description", - ":usage_pattern", - ":video_rtp_receiver", - ":video_rtp_track_source", - ":video_track", ":video_track_source", - "../api:array_view", "../api:audio_options_api", "../api:candidate", - "../api:create_peerconnection_factory", "../api:enable_media_with_defaults", - "../api:fake_frame_decryptor", - "../api:fake_frame_encryptor", "../api:field_trials", "../api:field_trials_view", - "../api:function_view", "../api:ice_transport_interface", "../api:libjingle_logging_api", "../api:libjingle_peerconnection_api", "../api:make_ref_counted", "../api:media_stream_interface", "../api:mock_async_dns_resolver", - "../api:mock_rtp", - "../api:packet_socket_factory", "../api:rtc_error", "../api:rtc_error_matchers", "../api:rtc_stats_api", "../api:rtp_parameters", - "../api:rtp_sender_interface", "../api:rtp_transceiver_direction", "../api:scoped_refptr", "../api:sequence_checker", - "../api/audio:audio_device", - "../api/audio:audio_mixer_api", - "../api/audio:audio_processing", "../api/audio:builtin_audio_processing_builder", - "../api/crypto:frame_decryptor_interface", - "../api/crypto:frame_encryptor_interface", "../api/crypto:options", "../api/metronome", - "../api/rtc_event_log", "../api/rtc_event_log:rtc_event_log_factory", "../api/task_queue", "../api/task_queue:default_task_queue_factory", "../api/task_queue:pending_task_safety_flag", - "../api/transport/rtp:rtp_source", "../api/units:time_delta", - "../api/video:builtin_video_bitrate_allocator_factory", "../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", - "../media:media_engine", - "../media:rtc_media_config", - "../media:rtc_media_tests_utils", "../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_port_allocator", "../p2p:ice_transport_internal", - "../p2p:p2p_constants", - "../p2p:p2p_server_utils", "../p2p:p2p_test_utils", "../p2p:port", - "../p2p:port_allocator", "../p2p:port_interface", "../rtc_base:checks", "../rtc_base:crypto_random", - "../rtc_base:gunit_helpers", "../rtc_base:ip_address", "../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_certificate_generator", - "../rtc_base:rtc_event", - "../rtc_base:rtc_json", - "../rtc_base:safe_conversions", "../rtc_base:socket_address", "../rtc_base:socket_factory", "../rtc_base:socket_server", - "../rtc_base:ssl", "../rtc_base:ssl_adapter", "../rtc_base:task_queue_for_test", "../rtc_base:threading", "../rtc_base:timeutils", - "../rtc_base/synchronization:mutex", - "../rtc_base/task_utils:repeating_task", - "../rtc_base/third_party/sigslot", "../system_wrappers:metrics", - "../test:explicit_key_value_config", - "../test:fileutils", - "../test:rtp_test_utils", - "../test:scoped_key_value_config", "../test:test_support", "../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/memory", "//third_party/abseil-cpp/absl/strings:string_view", diff --git a/pc/peer_connection_histogram_unittest.cc b/pc/peer_connection_histogram_unittest.cc index a2847dc4e8..5bd301aaaa 100644 --- a/pc/peer_connection_histogram_unittest.cc +++ b/pc/peer_connection_histogram_unittest.cc @@ -17,18 +17,13 @@ #include "api/jsep.h" #include "api/jsep_session_description.h" -#include "api/make_ref_counted.h" #include "api/peer_connection_interface.h" #include "api/rtc_error.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/rtc_error_matchers.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_factory.h" #include "pc/peer_connection_wrapper.h" #include "pc/sdp_utils.h" #include "pc/test/enable_fake_media.h" @@ -40,6 +35,7 @@ #include "rtc_base/fake_mdns_responder.h" #include "rtc_base/fake_network.h" #include "rtc_base/gunit.h" +#include "rtc_base/network.h" #include "rtc_base/socket_address.h" #include "rtc_base/thread.h" #include "rtc_base/virtual_socket_server.h" @@ -71,21 +67,6 @@ int MakeUsageFingerprint(std::set events) { 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; typedef PeerConnectionWrapperForUsageHistogramTest* RawWrapperPtr; @@ -229,109 +210,89 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { typedef std::unique_ptr WrapperPtr; - PeerConnectionUsageHistogramTest() - : vss_(new rtc::VirtualSocketServer()), - socket_factory_(new rtc::BasicPacketSocketFactory(vss_.get())), - main_(vss_.get()) { - metrics::Reset(); - } + PeerConnectionUsageHistogramTest() : main_(&vss_) { metrics::Reset(); } WrapperPtr CreatePeerConnection() { RTCConfiguration config; config.sdp_semantics = SdpSemantics::kUnifiedPlan; - return CreatePeerConnection( - config, PeerConnectionFactoryInterface::Options(), nullptr); + return CreatePeerConnection(config); } WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { - return CreatePeerConnection( - config, PeerConnectionFactoryInterface::Options(), nullptr); + return CreatePeerConnection(config, + PeerConnectionFactoryInterface::Options(), + PeerConnectionDependencies(nullptr), nullptr); } WrapperPtr CreatePeerConnectionWithMdns(const RTCConfiguration& config) { - auto resolver_factory = + PeerConnectionDependencies deps(nullptr /* observer_in */); + deps.async_dns_resolver_factory = std::make_unique>(); - PeerConnectionDependencies deps(nullptr /* observer_in */); - - auto fake_network = NewFakeNetwork(); + auto fake_network = std::make_unique(); fake_network->set_mdns_responder( std::make_unique(rtc::Thread::Current())); fake_network->AddInterface(NextLocalAddress()); - std::unique_ptr port_allocator( - new cricket::BasicPortAllocator(fake_network, socket_factory_.get())); - - deps.async_dns_resolver_factory = std::move(resolver_factory); - deps.allocator = std::move(port_allocator); - - return CreatePeerConnection( - config, PeerConnectionFactoryInterface::Options(), std::move(deps)); + return CreatePeerConnection(config, + PeerConnectionFactoryInterface::Options(), + std::move(deps), std::move(fake_network)); } WrapperPtr CreatePeerConnectionWithImmediateReport() { RTCConfiguration configuration; configuration.sdp_semantics = SdpSemantics::kUnifiedPlan; configuration.report_usage_pattern_delay_ms = 0; - return CreatePeerConnection( - configuration, PeerConnectionFactoryInterface::Options(), nullptr); + return CreatePeerConnection(configuration); } WrapperPtr CreatePeerConnectionWithPrivateLocalAddresses() { - auto* fake_network = NewFakeNetwork(); + auto fake_network = std::make_unique(); fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(kPrivateLocalAddress); - auto port_allocator = std::make_unique( - fake_network, socket_factory_.get()); RTCConfiguration config; config.sdp_semantics = SdpSemantics::kUnifiedPlan; - return CreatePeerConnection(config, - PeerConnectionFactoryInterface::Options(), - std::move(port_allocator)); + return CreatePeerConnection( + config, PeerConnectionFactoryInterface::Options(), + PeerConnectionDependencies(nullptr), std::move(fake_network)); } WrapperPtr CreatePeerConnectionWithPrivateIpv6LocalAddresses() { - auto* fake_network = NewFakeNetwork(); + auto fake_network = std::make_unique(); fake_network->AddInterface(NextLocalAddress()); fake_network->AddInterface(kPrivateIpv6LocalAddress); - auto port_allocator = std::make_unique( - fake_network, socket_factory_.get()); - RTCConfiguration config; config.sdp_semantics = SdpSemantics::kUnifiedPlan; - return CreatePeerConnection(config, - PeerConnectionFactoryInterface::Options(), - std::move(port_allocator)); + return CreatePeerConnection( + config, PeerConnectionFactoryInterface::Options(), + PeerConnectionDependencies(nullptr), std::move(fake_network)); } WrapperPtr CreatePeerConnection( const RTCConfiguration& config, const PeerConnectionFactoryInterface::Options factory_options, - std::unique_ptr allocator) { - PeerConnectionDependencies deps(nullptr); - deps.allocator = std::move(allocator); - - return CreatePeerConnection(config, factory_options, std::move(deps)); - } - - WrapperPtr CreatePeerConnection( - const RTCConfiguration& config, - const PeerConnectionFactoryInterface::Options factory_options, - PeerConnectionDependencies deps) { - auto pc_factory = - rtc::make_ref_counted(); - 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(); + PeerConnectionDependencies deps, + std::unique_ptr network_manager) { + PeerConnectionFactoryDependencies pcf_deps; + pcf_deps.network_thread = rtc::Thread::Current(); + pcf_deps.worker_thread = rtc::Thread::Current(); + pcf_deps.signaling_thread = rtc::Thread::Current(); + pcf_deps.socket_factory = &vss_; + if (network_manager != nullptr) { + pcf_deps.network_manager = std::move(network_manager); + } else { + // If no network manager is provided, one will be created that uses the + // host network. This doesn't work on all trybots. + auto fake_network = std::make_unique(); fake_network->AddInterface(NextLocalAddress()); - deps.allocator = std::make_unique( - fake_network, socket_factory_.get()); + pcf_deps.network_manager = std::move(fake_network); } + EnableFakeMedia(pcf_deps); + + auto pc_factory = CreateModularPeerConnectionFactory(std::move(pcf_deps)); + pc_factory->SetOptions(factory_options); auto observer = std::make_unique(); deps.observer = observer.get(); @@ -355,25 +316,13 @@ class PeerConnectionUsageHistogramTest : public ::testing::Test { 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()); - return fake_networks_.back().get(); - } - rtc::SocketAddress NextLocalAddress() { RTC_DCHECK(next_local_address_ < (int)arraysize(kLocalAddrs)); return kLocalAddrs[next_local_address_++]; } - std::vector> fake_networks_; int next_local_address_ = 0; - std::unique_ptr vss_; - std::unique_ptr socket_factory_; + rtc::VirtualSocketServer vss_; rtc::AutoSocketServerThread main_; }; diff --git a/pc/peer_connection_ice_unittest.cc b/pc/peer_connection_ice_unittest.cc index bb2531dbbf..0453b8abbc 100644 --- a/pc/peer_connection_ice_unittest.cc +++ b/pc/peer_connection_ice_unittest.cc @@ -18,8 +18,8 @@ #include #include -#include "api/audio/audio_device.h" #include "api/candidate.h" +#include "api/enable_media_with_defaults.h" #include "api/field_trials.h" #include "api/ice_transport_interface.h" #include "api/jsep.h" @@ -38,7 +38,6 @@ #include "p2p/base/port_allocator.h" #include "p2p/base/transport_description.h" #include "p2p/base/transport_info.h" -#include "p2p/client/basic_port_allocator.h" #include "pc/channel_interface.h" #include "pc/dtls_transport.h" #include "pc/media_session.h" @@ -145,24 +144,10 @@ class PeerConnectionIceBaseTest : public ::testing::Test { typedef std::unique_ptr WrapperPtr; explicit PeerConnectionIceBaseTest(SdpSemantics sdp_semantics) - : vss_(new rtc::VirtualSocketServer()), - socket_factory_(new rtc::BasicPacketSocketFactory(vss_.get())), - main_(vss_.get()), - sdp_semantics_(sdp_semantics) { + : main_(&vss_), sdp_semantics_(sdp_semantics) { #ifdef WEBRTC_ANDROID InitializeAndroidObjects(); #endif - pc_factory_ = CreatePeerConnectionFactory( - rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), - rtc::scoped_refptr(FakeAudioCaptureModule::Create()), - CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(), - std::make_unique>(), - std::make_unique>(), - nullptr /* audio_mixer */, nullptr /* audio_processing */); } WrapperPtr CreatePeerConnection() { @@ -170,18 +155,35 @@ class PeerConnectionIceBaseTest : public ::testing::Test { } WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { - auto* fake_network = NewFakeNetwork(); - auto port_allocator = std::make_unique( - fake_network, socket_factory_.get()); - port_allocator->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | - cricket::PORTALLOCATOR_DISABLE_RELAY); - port_allocator->set_step_delay(cricket::kMinimumStepDelay); + PeerConnectionFactoryDependencies pcf_deps; + pcf_deps.network_thread = rtc::Thread::Current(); + pcf_deps.worker_thread = rtc::Thread::Current(); + pcf_deps.signaling_thread = rtc::Thread::Current(); + pcf_deps.socket_factory = &vss_; + auto network_manager = std::make_unique(); + 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>(); + pcf_deps.video_decoder_factory = + std::make_unique>(); + EnableMediaWithDefaults(pcf_deps); + scoped_refptr pc_factory = + CreateModularPeerConnectionFactory(std::move(pcf_deps)); + RTCConfiguration modified_config = config; + modified_config.set_port_allocator_flags( + cricket::PORTALLOCATOR_DISABLE_TCP | + cricket::PORTALLOCATOR_DISABLE_RELAY); modified_config.sdp_semantics = sdp_semantics_; auto observer = std::make_unique(); 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)); if (!result.ok()) { return nullptr; @@ -189,7 +191,7 @@ class PeerConnectionIceBaseTest : public ::testing::Test { observer->SetPeerConnectionInterface(result.value().get()); auto wrapper = std::make_unique( - pc_factory_, result.MoveValue(), std::move(observer)); + std::move(pc_factory), result.MoveValue(), std::move(observer)); wrapper->set_network(fake_network); return wrapper; } @@ -313,22 +315,8 @@ class PeerConnectionIceBaseTest : public ::testing::Test { return sdesc->AddCandidate(jsep_candidate.get()); } - rtc::FakeNetworkManager* NewFakeNetwork() { - // 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 vss_; - std::unique_ptr socket_factory_; + rtc::VirtualSocketServer vss_; rtc::AutoSocketServerThread main_; - rtc::scoped_refptr pc_factory_; - std::vector> fake_networks_; const SdpSemantics sdp_semantics_; }; diff --git a/pc/peer_connection_integrationtest.cc b/pc/peer_connection_integrationtest.cc index 7b6517c9e4..20643c2f29 100644 --- a/pc/peer_connection_integrationtest.cc +++ b/pc/peer_connection_integrationtest.cc @@ -1910,6 +1910,7 @@ TEST_P(PeerConnectionIntegrationTest, PeerConnectionInterface::RTCConfiguration config; config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire; + config.port_allocator_config.flags = kOnlyLocalPorts; ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps( config, std::move(caller_deps), config, std::move(callee_deps))); @@ -1927,8 +1928,6 @@ TEST_P(PeerConnectionIntegrationTest, callee()->SetMdnsResponder( std::make_unique(network_thread())); - SetPortAllocatorFlags(kOnlyLocalPorts, kOnlyLocalPorts); - ConnectFakeSignaling(); caller()->AddAudioVideoTracks(); callee()->AddAudioVideoTracks(); @@ -1976,11 +1975,6 @@ class PeerConnectionIntegrationIceStatesTest return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6); } - void SetPortAllocatorFlags() { - PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags( - port_allocator_flags_, port_allocator_flags_); - } - std::vector CallerAddresses() { std::vector addresses; 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: uint32_t port_allocator_flags_; cricket::TestStunServer::StunServerPtr stun_server_; @@ -2036,9 +2032,10 @@ TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, 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(); - SetPortAllocatorFlags(); SetUpNetworkInterfaces(); caller()->AddAudioVideoTracks(); caller()->CreateAndSetAndSignalOffer(); @@ -2066,9 +2063,10 @@ TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, #define MAYBE_VerifyBestConnection VerifyBestConnection #endif 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(); - SetPortAllocatorFlags(); SetUpNetworkInterfaces(); caller()->AddAudioVideoTracks(); callee()->AddAudioVideoTracks(); diff --git a/pc/peer_connection_rampup_tests.cc b/pc/peer_connection_rampup_tests.cc index d6546e6025..7f5a6c2ec4 100644 --- a/pc/peer_connection_rampup_tests.cc +++ b/pc/peer_connection_rampup_tests.cc @@ -14,11 +14,8 @@ #include #include -#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/create_peerconnection_factory.h" +#include "api/enable_media_with_defaults.h" #include "api/jsep.h" #include "api/make_ref_counted.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_open_h264_adapter.h" #include "p2p/base/basic_packet_socket_factory.h" -#include "p2p/base/port_allocator.h" #include "p2p/base/port_interface.h" #include "p2p/base/test_turn_server.h" -#include "p2p/client/basic_port_allocator.h" #include "pc/peer_connection.h" #include "pc/peer_connection_wrapper.h" #include "pc/test/fake_audio_capture_module.h" @@ -157,30 +152,15 @@ class PeerConnectionRampUpTest : public ::testing::Test { public: PeerConnectionRampUpTest() : clock_(Clock::GetRealTimeClock()), - virtual_socket_server_(new rtc::VirtualSocketServer()), - 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())), + firewall_socket_server_(&virtual_socket_server_), + network_thread_(&firewall_socket_server_), worker_thread_(rtc::Thread::Create()) { - network_thread_->SetName("PCNetworkThread", this); + network_thread_.SetName("PCNetworkThread", this); worker_thread_->SetName("PCWorkerThread", this); - RTC_CHECK(network_thread_->Start()); + RTC_CHECK(network_thread_.Start()); RTC_CHECK(worker_thread_->Start()); - virtual_socket_server_->set_bandwidth(kNetworkBandwidth / 8); - pc_factory_ = CreatePeerConnectionFactory( - network_thread_.get(), worker_thread_.get(), rtc::Thread::Current(), - rtc::scoped_refptr(FakeAudioCaptureModule::Create()), - CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(), - std::make_unique>(), - std::make_unique>(), - nullptr /* audio_mixer */, nullptr /* audio_processing */); + virtual_socket_server_.set_bandwidth(kNetworkBandwidth / 8); } virtual ~PeerConnectionRampUpTest() { @@ -196,30 +176,40 @@ class PeerConnectionRampUpTest : public ::testing::Test { std::unique_ptr CreatePeerConnectionWrapper(const RTCConfiguration& config) { - auto* fake_network_manager = new rtc::FakeNetworkManager(); - fake_network_manager->AddInterface(kDefaultLocalAddress); - fake_network_managers_.emplace_back(fake_network_manager); + PeerConnectionFactoryDependencies pcf_deps; + pcf_deps.network_thread = network_thread(); + 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(); + 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>(); + pcf_deps.video_decoder_factory = + std::make_unique>(); + EnableMediaWithDefaults(pcf_deps); + scoped_refptr pc_factory = + CreateModularPeerConnectionFactory(std::move(pcf_deps)); auto observer = std::make_unique(); 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(port_allocator); dependencies.tls_cert_verifier = std::make_unique(); - auto result = pc_factory_->CreatePeerConnectionOrError( + auto result = pc_factory->CreatePeerConnectionOrError( config, std::move(dependencies)); if (!result.ok()) { return nullptr; } return std::make_unique( - pc_factory_, result.MoveValue(), std::move(observer)); + std::move(pc_factory), result.MoveValue(), std::move(observer)); } void SetupOneWayCall() { @@ -261,9 +251,9 @@ class PeerConnectionRampUpTest : public ::testing::Test { void CreateTurnServer(cricket::ProtocolType type, const std::string& common_name = "test turn server") { rtc::Thread* thread = network_thread(); - rtc::SocketFactory* factory = firewall_socket_server_.get(); + rtc::SocketFactory* factory = &firewall_socket_server_; std::unique_ptr turn_server; - SendTask(network_thread_.get(), [&] { + SendTask(network_thread(), [&] { static const rtc::SocketAddress turn_server_internal_address{ kTurnInternalAddress, kTurnInternalPort}; static const rtc::SocketAddress turn_server_external_address{ @@ -299,10 +289,10 @@ class PeerConnectionRampUpTest : public ::testing::Test { ImprovementDirection::kNeitherIsBetter); } - rtc::Thread* network_thread() { return network_thread_.get(); } + rtc::Thread* network_thread() { return &network_thread_; } rtc::FirewallSocketServer* firewall_socket_server() { - return firewall_socket_server_.get(); + return &firewall_socket_server_; } 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 // second ramp up time can take up to 300 seconds, most likely due to a built // up queue. - std::unique_ptr virtual_socket_server_; - std::unique_ptr firewall_socket_server_; - std::unique_ptr firewall_socket_factory_; + rtc::VirtualSocketServer virtual_socket_server_; + rtc::FirewallSocketServer firewall_socket_server_; - std::unique_ptr network_thread_; + rtc::Thread network_thread_; std::unique_ptr worker_thread_; - // The `pc_factory` uses `network_thread_` & `worker_thread_`, so it must be - // destroyed first. - std::vector> fake_network_managers_; - rtc::scoped_refptr pc_factory_; + std::unique_ptr caller_; std::unique_ptr callee_; }; diff --git a/pc/slow_peer_connection_integration_test.cc b/pc/slow_peer_connection_integration_test.cc index 1e010b44d7..2649f847f6 100644 --- a/pc/slow_peer_connection_integration_test.cc +++ b/pc/slow_peer_connection_integration_test.cc @@ -289,11 +289,6 @@ class PeerConnectionIntegrationIceStatesTest return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6); } - void SetPortAllocatorFlags() { - PeerConnectionIntegrationBaseTest::SetPortAllocatorFlags( - port_allocator_flags_, port_allocator_flags_); - } - std::vector CallerAddresses() { std::vector addresses; 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: uint32_t port_allocator_flags_; cricket::TestStunServer::StunServerPtr stun_server_; @@ -354,10 +351,10 @@ TEST_P(PeerConnectionIntegrationIceStatesTestWithFakeClock, VerifyIceStates) { "stun:" + kStunServerAddress.HostAsURIString() + ":" + kStunServerAddress.PortAsString()); config.servers.push_back(ice_stun_server); + config.port_allocator_config.flags = port_allocator_flags(); ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config)); ConnectFakeSignaling(); - SetPortAllocatorFlags(); SetUpNetworkInterfaces(); caller()->AddAudioVideoTracks(); callee()->AddAudioVideoTracks(); diff --git a/pc/test/integration_test_helpers.cc b/pc/test/integration_test_helpers.cc index 39588d2317..6aed9b0de7 100644 --- a/pc/test/integration_test_helpers.cc +++ b/pc/test/integration_test_helpers.cc @@ -20,6 +20,7 @@ #include "absl/functional/any_invocable.h" #include "api/audio/builtin_audio_processing_builder.h" #include "api/enable_media_with_defaults.h" +#include "api/field_trials_view.h" #include "api/jsep.h" #include "api/peer_connection_interface.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/units/time_delta.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/test/fake_audio_capture_module.h" #include "rtc_base/checks.h" @@ -231,16 +229,12 @@ bool PeerConnectionIntegrationWrapper::Init( RTC_DCHECK(!peer_connection_); RTC_DCHECK(!peer_connection_factory_); - fake_network_manager_.reset(new rtc::FakeNetworkManager()); + auto network_manager = std::make_unique(); + fake_network_manager_ = network_manager.get(); fake_network_manager_->AddInterface(kDefaultLocalAddress); - socket_factory_.reset(new rtc::BasicPacketSocketFactory(socket_server)); network_thread_ = network_thread; - std::unique_ptr port_allocator( - new cricket::BasicPortAllocator(fake_network_manager_.get(), - socket_factory_.get())); - port_allocator_ = port_allocator.get(); fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); if (!fake_audio_capture_module_) { return false; @@ -251,6 +245,8 @@ bool PeerConnectionIntegrationWrapper::Init( pc_factory_dependencies.network_thread = network_thread; pc_factory_dependencies.worker_thread = worker_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.trials = std::move(field_trials); pc_factory_dependencies.decode_metronome = @@ -284,6 +280,7 @@ bool PeerConnectionIntegrationWrapper::Init( CreateModularPeerConnectionFactory(std::move(pc_factory_dependencies)); if (!peer_connection_factory_) { + fake_network_manager_ = nullptr; return false; } if (options) { @@ -293,7 +290,6 @@ bool PeerConnectionIntegrationWrapper::Init( sdp_semantics_ = config->sdp_semantics; } - dependencies.allocator = std::move(port_allocator); peer_connection_ = CreatePeerConnection(config, std::move(dependencies)); return peer_connection_.get() != nullptr; } diff --git a/pc/test/integration_test_helpers.h b/pc/test/integration_test_helpers.h index a23da7cfa3..0b7c8b5de0 100644 --- a/pc/test/integration_test_helpers.h +++ b/pc/test/integration_test_helpers.h @@ -63,7 +63,6 @@ #include "p2p/base/fake_ice_transport.h" #include "p2p/base/ice_transport_internal.h" #include "p2p/base/port.h" -#include "p2p/base/port_allocator.h" #include "p2p/base/port_interface.h" #include "p2p/base/test_turn_customizer.h" #include "p2p/base/test_turn_server.h" @@ -645,9 +644,8 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, } 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 { return event_log_factory_; @@ -1120,8 +1118,8 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, std::string debug_name_; - std::unique_ptr fake_network_manager_; - std::unique_ptr socket_factory_; + // Network manager is owned by the `peer_connection_factory_`. + rtc::FakeNetworkManager* fake_network_manager_ = nullptr; rtc::Thread* network_thread_; // Reference to the mDNS responder owned by `fake_network_manager_` after set. @@ -1130,7 +1128,6 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, rtc::scoped_refptr peer_connection_; rtc::scoped_refptr peer_connection_factory_; - cricket::PortAllocator* port_allocator_; // Needed to keep track of number of frames sent. rtc::scoped_refptr fake_audio_capture_module_; // Needed to keep track of number of frames received. @@ -1709,15 +1706,6 @@ class PeerConnectionIntegrationBaseTest : public ::testing::Test { 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(); } // Expects the provided number of new frames to be received within