From 73d0774b6b28ede75188beb7512bc531ff508aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Thu, 2 Dec 2021 13:58:01 +0100 Subject: [PATCH] Add PortAllocator configuration to RTCConfiguration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So applications don't need to create and inject their own instance of BasicPortAllocator, just to change these settings. Bug: webrtc:13145 Change-Id: I08ac8658b4c0ef87019fa579be9195a8a6b50feb Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/239643 Reviewed-by: Harald Alvestrand Reviewed-by: Henrik Boström Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/main@{#35476} --- api/peer_connection_interface.h | 21 +++++++++++++++++++++ pc/peer_connection.cc | 6 +++++- pc/peer_connection_factory.cc | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h index efe84fbe4a..678ece8762 100644 --- a/api/peer_connection_interface.h +++ b/api/peer_connection_interface.h @@ -295,6 +295,13 @@ class RTC_EXPORT PeerConnectionInterface : public rtc::RefCountInterface { enum ContinualGatheringPolicy { GATHER_ONCE, GATHER_CONTINUALLY }; + struct PortAllocatorConfig { + // For min_port and max_port, 0 means not specified. + int min_port = 0; + int max_port = 0; + uint32_t flags = 0; // Same as kDefaultPortAllocatorFlags. + }; + enum class RTCConfigurationType { // A configuration that is safer to use, despite not having the best // performance. Currently this is the default configuration. @@ -372,6 +379,18 @@ class RTC_EXPORT PeerConnectionInterface : public rtc::RefCountInterface { video_rtcp_report_interval_ms; } + // Settings for the port allcoator. Applied only if the port allocator is + // created by PeerConnectionFactory, not if it is injected with + // PeerConnectionDependencies + int min_port() const { return port_allocator_config.min_port; } + void set_min_port(int port) { port_allocator_config.min_port = port; } + int max_port() const { return port_allocator_config.max_port; } + void set_max_port(int port) { port_allocator_config.max_port = port; } + uint32_t port_allocator_flags() { return port_allocator_config.flags; } + void set_port_allocator_flags(uint32_t flags) { + port_allocator_config.flags = flags; + } + static const int kUndefined = -1; // Default maximum number of packets in the audio jitter buffer. static const int kAudioJitterBufferMaxPackets = 200; @@ -670,6 +689,8 @@ class RTC_EXPORT PeerConnectionInterface : public rtc::RefCountInterface { // VPN (in case webrtc fails to auto detect them). std::vector vpn_list; + PortAllocatorConfig port_allocator_config; + // // Don't forget to update operator== if adding something. // diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index cc8dc6dc24..c3cd87ef59 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -338,6 +338,7 @@ bool PeerConnectionInterface::RTCConfiguration::operator==( absl::optional stable_writable_connection_ping_interval_ms; webrtc::VpnPreference vpn_preference; std::vector vpn_list; + PortAllocatorConfig port_allocator_config; }; static_assert(sizeof(stuff_being_tested_for_equality) == sizeof(*this), "Did you add something to RTCConfiguration and forget to " @@ -400,7 +401,10 @@ bool PeerConnectionInterface::RTCConfiguration::operator==( report_usage_pattern_delay_ms == o.report_usage_pattern_delay_ms && stable_writable_connection_ping_interval_ms == o.stable_writable_connection_ping_interval_ms && - vpn_preference == o.vpn_preference && vpn_list == o.vpn_list; + vpn_preference == o.vpn_preference && vpn_list == o.vpn_list && + port_allocator_config.min_port == o.port_allocator_config.min_port && + port_allocator_config.max_port == o.port_allocator_config.max_port && + port_allocator_config.flags == o.port_allocator_config.flags; } bool PeerConnectionInterface::RTCConfiguration::operator!=( diff --git a/pc/peer_connection_factory.cc b/pc/peer_connection_factory.cc index 8a76c92451..3ab969dc32 100644 --- a/pc/peer_connection_factory.cc +++ b/pc/peer_connection_factory.cc @@ -218,6 +218,11 @@ PeerConnectionFactory::CreatePeerConnectionOrError( dependencies.allocator = std::make_unique( context_->default_network_manager(), packet_socket_factory, configuration.turn_customizer); + dependencies.allocator->SetPortRange( + configuration.port_allocator_config.min_port, + configuration.port_allocator_config.max_port); + dependencies.allocator->set_flags( + configuration.port_allocator_config.flags); } if (!dependencies.async_resolver_factory) {