Skip to content

Commit f2f919d

Browse files
committed
[GStreamer][WebRTC] Rework UDP port ranges support
https://bugs.webkit.org/show_bug.cgi?id=281569 Reviewed by Xabier Rodriguez-Calvar. This is a follow-up to 285190@main. The WebKit LibWebRTProvider changes in that revision were incorrect, the provider doesn't have access to the core page from its constructor. The correct approach to apply settings to the provider is to use the Page::settingsDidChange() method. Also minPort or maxPort values of 0 are accepted by libwebrtc and mean they are unspecified, so we should allow those values. * Source/WebCore/page/Page.cpp: (WebCore::Page::settingsDidChange): * Source/WebCore/platform/mediastream/WebRTCProvider.cpp: (WebCore::WebRTCProvider::setPortAllocatorRange): * Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp: (webkit_settings_class_init): * Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp: (WebKit::LibWebRTCProvider::LibWebRTCProvider): * Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp: (testWebKitSettings): Canonical link: https://commits.webkit.org/285333@main
1 parent a711abc commit f2f919d

5 files changed

Lines changed: 26 additions & 10 deletions

File tree

Source/WebCore/page/Page.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ void Page::settingsDidChange()
597597
m_webRTCProvider->setH265Support(settings().webRTCH265CodecEnabled());
598598
m_webRTCProvider->setVP9Support(settings().webRTCVP9Profile0CodecEnabled(), settings().webRTCVP9Profile2CodecEnabled());
599599
m_webRTCProvider->setAV1Support(settings().webRTCAV1CodecEnabled());
600+
m_webRTCProvider->setPortAllocatorRange(settings().webRTCUDPPortRange());
600601
#endif
601602
}
602603

Source/WebCore/platform/mediastream/WebRTCProvider.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,38 @@ std::optional<MediaCapabilitiesEncodingInfo> WebRTCProvider::videoEncodingCapabi
310310

311311
void WebRTCProvider::setPortAllocatorRange(StringView range)
312312
{
313+
if (range.isEmpty())
314+
return;
315+
316+
if (range == "0:0"_s)
317+
return;
318+
313319
auto components = range.toStringWithoutCopying().split(':');
314320
if (UNLIKELY(components.size() != 2)) {
315321
WTFLogAlways("Invalid format for UDP port range. Should be \"min-port:max-port\"");
316322
ASSERT_NOT_REACHED();
317323
return;
318324
}
319325

320-
auto minPort = WTF::parseInteger<int>(components[0]).value_or(0);
321-
auto maxPort = WTF::parseInteger<int>(components[1]).value_or(0);
326+
auto minPort = WTF::parseInteger<int>(components[0]);
327+
auto maxPort = WTF::parseInteger<int>(components[1]);
322328
if (!minPort || !maxPort) {
323329
WTFLogAlways("Invalid format for UDP port range. Should be \"min-port:max-port\"");
324330
ASSERT_NOT_REACHED();
325331
return;
326332
}
327333

328-
m_portAllocatorRange = { { minPort, maxPort } };
334+
if (*minPort < 0) {
335+
WTFLogAlways("Invalid value for UDP minimum port value: %d", *minPort);
336+
return;
337+
}
338+
339+
if (*maxPort < 0) {
340+
WTFLogAlways("Invalid value for UDP maximum port value: %d", *maxPort);
341+
return;
342+
}
343+
344+
m_portAllocatorRange = { { *minPort, *maxPort } };
329345
}
330346

331347
std::optional<std::pair<int, int>> WebRTCProvider::portAllocatorRange() const

Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,8 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass)
17951795
* In some constrained environments where a firewall blocks UDP network traffic excepted on a
17961796
* specific port range, this settings can be used to give hints to the WebRTC backend regarding
17971797
* which ports to allocate. The format is min-port:max-port, so for instance 20000:30000. The
1798-
* default value is 0:0 which means the OS will use no hints from the WebRTC backend.
1798+
* default empty string value means the OS will use no hints from the WebRTC backend. Using 0
1799+
* for one of the values is allowed and means the value is unspecified.
17991800
*
18001801
* Since: 2.48
18011802
*/

Source/WebKit/WebProcess/Network/webrtc/LibWebRTCProvider.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ LibWebRTCProvider::LibWebRTCProvider(WebPage& webPage)
7373
#else
7474
m_supportsMDNS = true;
7575
#endif
76-
77-
auto* page = webPage.corePage();
78-
if (!page || !page->settings().webRTCUDPPortRange())
79-
return;
80-
81-
setPortAllocatorRange(page->settings().webRTCUDPPortRange());
8276
}
8377

8478
rtc::scoped_refptr<webrtc::PeerConnectionInterface> LibWebRTCProvider::createPeerConnection(ScriptExecutionContextIdentifier identifier, webrtc::PeerConnectionObserver& observer, rtc::PacketSocketFactory* socketFactory, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)

Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ ALLOW_DEPRECATED_DECLARATIONS_END
387387
g_assert_cmpstr("", ==, webkit_settings_get_webrtc_udp_ports_range(settings));
388388
webkit_settings_set_webrtc_udp_ports_range(settings, "20000:30000");
389389
g_assert_cmpstr("20000:30000", ==, webkit_settings_get_webrtc_udp_ports_range(settings));
390+
webkit_settings_set_webrtc_udp_ports_range(settings, "20000:0");
391+
g_assert_cmpstr("20000:0", ==, webkit_settings_get_webrtc_udp_ports_range(settings));
392+
webkit_settings_set_webrtc_udp_ports_range(settings, "0:20000");
393+
g_assert_cmpstr("0:20000", ==, webkit_settings_get_webrtc_udp_ports_range(settings));
390394
#endif
391395

392396
g_object_unref(G_OBJECT(settings));

0 commit comments

Comments
 (0)