Add PortAllocator configuration to RTCConfiguration

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 <hta@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35476}
This commit is contained in:
Niels Möller 2021-12-02 13:58:01 +01:00 committed by WebRTC LUCI CQ
parent a0353c0630
commit 73d0774b6b
3 changed files with 31 additions and 1 deletions

View File

@ -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<rtc::NetworkMask> vpn_list;
PortAllocatorConfig port_allocator_config;
//
// Don't forget to update operator== if adding something.
//

View File

@ -338,6 +338,7 @@ bool PeerConnectionInterface::RTCConfiguration::operator==(
absl::optional<int> stable_writable_connection_ping_interval_ms;
webrtc::VpnPreference vpn_preference;
std::vector<rtc::NetworkMask> 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!=(

View File

@ -218,6 +218,11 @@ PeerConnectionFactory::CreatePeerConnectionOrError(
dependencies.allocator = std::make_unique<cricket::BasicPortAllocator>(
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) {