Skip to content

Commit 521581d

Browse files
committed
rdar://168225793 https://bugs.webkit.org/show_bug.cgi?id=305564 Reviewed by Eric Carlson. We add RTCConfiguration.targetLatency and compute whether enabling service class accordingly. We remove some no longer needed code. We add an internal API to query whether service class is enabled for a given peer connection and use that in a test to validate that passing the parameter works fine. Covered by added tests. Canonical link: https://commits.webkit.org/306062@main
1 parent ea11204 commit 521581d

22 files changed

+119
-48
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
PASS Valid targetLatency
3+
PASS Invalid targetLatency
4+
PASS Changing targetLatency
5+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
<title>RTCConfiguration targetLatency</title>
4+
<script src='/resources/testharness.js'></script>
5+
<script src='/resources/testharnessreport.js'></script>
6+
<script>
7+
test(() => {
8+
let pc = new RTCPeerConnection({ });
9+
assert_equals(pc.getConfiguration().targetLatency, "lowest");
10+
pc.close();
11+
12+
pc = new RTCPeerConnection({ targetLatency: "lowest" });
13+
assert_equals(pc.getConfiguration().targetLatency, "lowest");
14+
pc.close();
15+
16+
pc = new RTCPeerConnection({ targetLatency: "none" });
17+
assert_equals(pc.getConfiguration().targetLatency, "none");
18+
pc.close();
19+
}, "Valid targetLatency");
20+
21+
test(() => {
22+
assert_throws_js(TypeError, () => new RTCPeerConnection({ targetLatency: "whatever" }));
23+
}, "Invalid targetLatency");
24+
25+
test(() => {
26+
let pc = new RTCPeerConnection({ targetLatency: "lowest" });
27+
pc.setConfiguration({ });
28+
pc.setConfiguration({ targetLatency: "lowest" });
29+
assert_throws_js(TypeError, () => pc.setConfiguration({ targetLatency: "none" }));
30+
pc.close();
31+
32+
pc = new RTCPeerConnection({ targetLatency: "none" });
33+
pc.setConfiguration({ targetLatency: "none" });
34+
assert_throws_js(TypeError, () => pc.setConfiguration({ }));
35+
assert_throws_js(TypeError, () => pc.setConfiguration({ targetLatency: "lowest" }));
36+
pc.close();
37+
}, "Changing targetLatency");
38+
</script>

LayoutTests/platform/glib/TestExpectations

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,8 @@ webkit.org/b/235885 webrtc/remove-track.html [ Crash Failure ]
26892689
# Stopping a transceiver is unsupported in GstWebRTC.
26902690
imported/w3c/web-platform-tests/webrtc/protocol/transceiver-mline-recycling.html [ Failure ]
26912691

2692+
webrtc/RTCConfiguration-targetLatency.html [ Failure ]
2693+
26922694
# Specific to LibWebRTC:
26932695
webkit.org/b/235885 webrtc/disable-encryption.html [ Skip ]
26942696
webkit.org/b/235885 webrtc/libwebrtc/ [ Skip ]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
PASS targetLatency and serviceClass
3+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!doctype html><!-- webkit-test-runner [ WebRTCSocketsServiceClassEnabled=true ] -->
2+
<meta charset=utf-8>
3+
<title>RTCConfiguration targetLatency</title>
4+
<script src='../resources/testharness.js'></script>
5+
<script src='../resources/testharnessreport.js'></script>
6+
<script>
7+
test(() => {
8+
if (!window.internals)
9+
return;
10+
11+
const pc1 = new RTCPeerConnection({ targetLatency: "lowest" });
12+
assert_true(internals.hasPeerConnectionEnabledServiceClass(pc1));
13+
pc1.close();
14+
15+
const pc2 = new RTCPeerConnection({ targetLatency: "none" });
16+
assert_false(internals.hasPeerConnectionEnabledServiceClass(pc2));
17+
pc2.close();
18+
}, "targetLatency and serviceClass");
19+
</script>

Source/WebCore/Modules/mediastream/PeerConnectionBackend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class WeakPtrImplWithEventTargetData;
7373

7474
struct MediaEndpointConfiguration;
7575
struct RTCAnswerOptions;
76+
struct RTCConfiguration;
7677
struct RTCDataChannelInit;
7778
struct RTCOfferOptions;
7879
struct RTCRtpTransceiverInit;
@@ -232,6 +233,8 @@ class PeerConnectionBackend
232233
WEBCORE_EXPORT void ref() const;
233234
WEBCORE_EXPORT void deref() const;
234235

236+
virtual bool shouldEnableServiceClass() const { return true; }
237+
235238
protected:
236239
void doneGatheringCandidates();
237240

Source/WebCore/Modules/mediastream/RTCConfiguration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct RTCConfiguration {
4848
RTCPMuxPolicy rtcpMuxPolicy;
4949
unsigned short iceCandidatePoolSize;
5050
Vector<Ref<RTCCertificate>> certificates;
51+
enum class TargetLatency { Lowest, None };
52+
TargetLatency targetLatency { TargetLatency::Lowest };
5153
};
5254

5355
} // namespace WebCore

Source/WebCore/Modules/mediastream/RTCConfiguration.idl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
"require"
5252
};
5353

54+
[
55+
Conditional=WEB_RTC,
56+
EnabledBySetting=PeerConnectionEnabled
57+
] enum RTCConfigurationTargetLatency {
58+
"lowest",
59+
"none"
60+
};
61+
5462
[
5563
Conditional=WEB_RTC,
5664
EnabledBySetting=PeerConnectionEnabled,
@@ -65,4 +73,5 @@
6573
// FIXME 169662: missing peerIdentity
6674
sequence<RTCCertificate> certificates;
6775
[EnforceRange] octet iceCandidatePoolSize = 0;
76+
RTCConfigurationTargetLatency targetLatency = "lowest";
6877
};

Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,13 @@ ExceptionOr<void> RTCPeerConnection::initializeWithConfiguration(RTCConfiguratio
599599
if (certificates.hasException())
600600
return certificates.releaseException();
601601

602-
lazyInitialize(m_backend, PeerConnectionBackend::create(*this, { servers.releaseReturnValue(), configuration.iceTransportPolicy, configuration.bundlePolicy, configuration.rtcpMuxPolicy, configuration.iceCandidatePoolSize, certificates.releaseReturnValue() }));
602+
lazyInitialize(m_backend, PeerConnectionBackend::create(*this, { servers.releaseReturnValue(), configuration.iceTransportPolicy, configuration.bundlePolicy, configuration.rtcpMuxPolicy, configuration.iceCandidatePoolSize, certificates.releaseReturnValue(), configuration.targetLatency == RTCConfiguration::TargetLatency::Lowest }));
603603

604604
if (!m_backend)
605605
return Exception { ExceptionCode::InvalidAccessError, "Bad Configuration Parameters"_s };
606606

607607
m_configuration = WTF::move(configuration);
608+
608609
return { };
609610
}
610611

@@ -632,6 +633,9 @@ ExceptionOr<void> RTCPeerConnection::setConfiguration(RTCConfiguration&& configu
632633
}
633634
}
634635

636+
if (configuration.targetLatency != m_configuration.targetLatency)
637+
return Exception { ExceptionCode::TypeError, "Configuration targetLatency is immutable"_s };
638+
635639
if (!protectedBackend()->setConfiguration({ servers.releaseReturnValue(), configuration.iceTransportPolicy, configuration.bundlePolicy, configuration.rtcpMuxPolicy, configuration.iceCandidatePoolSize, { } }))
636640
return Exception { ExceptionCode::InvalidAccessError, "Bad Configuration Parameters"_s };
637641

Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ static void prepareConfiguration(webrtc::PeerConnectionInterface::RTCConfigurati
7777
configuration.crypto_options.srtp.enable_gcm_crypto_suites = true;
7878
}
7979

80-
RefPtr<LibWebRTCMediaEndpoint> LibWebRTCMediaEndpoint::create(RTCPeerConnection& peerConnection, LibWebRTCProvider& client, Document& document, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
80+
RefPtr<LibWebRTCMediaEndpoint> LibWebRTCMediaEndpoint::create(RTCPeerConnection& peerConnection, LibWebRTCProvider& client, Document& document, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration, bool shouldEnableServiceClass)
8181
{
8282
prepareConfiguration(configuration);
8383

84-
Ref endpoint = adoptRef(*new LibWebRTCMediaEndpoint(peerConnection, client, document));
84+
Ref endpoint = adoptRef(*new LibWebRTCMediaEndpoint(peerConnection, client, document, shouldEnableServiceClass));
8585
RefPtr backend = toRefPtr(client.createPeerConnection(document.identifier(), endpoint, endpoint->m_rtcSocketFactory.get(), WTF::move(configuration)));
8686
if (!backend)
8787
return { };
@@ -90,23 +90,23 @@ RefPtr<LibWebRTCMediaEndpoint> LibWebRTCMediaEndpoint::create(RTCPeerConnection&
9090
return endpoint;
9191
}
9292

93-
static std::unique_ptr<LibWebRTCProvider::SuspendableSocketFactory> createLibWebRTCMediaEndpointSocketFactory(LibWebRTCProvider& client, Document& document)
93+
static std::unique_ptr<LibWebRTCProvider::SuspendableSocketFactory> createLibWebRTCMediaEndpointSocketFactory(LibWebRTCProvider& client, Document& document, bool shouldEnableServiceClass)
9494
{
9595
RegistrableDomain domain { document.url() };
9696
bool isFirstParty = domain == RegistrableDomain(document.firstPartyForCookies());
97-
auto rtcSocketFactory = client.createSocketFactory(document.userAgent(document.url()), document.identifier(), isFirstParty, WTF::move(domain));
97+
auto rtcSocketFactory = client.createSocketFactory(document.userAgent(document.url()), document.identifier(), isFirstParty, WTF::move(domain), shouldEnableServiceClass);
9898
if (!client.isSupportingMDNS() && rtcSocketFactory)
9999
rtcSocketFactory->disableRelay();
100100
return rtcSocketFactory;
101101
}
102102

103-
LibWebRTCMediaEndpoint::LibWebRTCMediaEndpoint(RTCPeerConnection& peerConnection, LibWebRTCProvider& client, Document& document)
103+
LibWebRTCMediaEndpoint::LibWebRTCMediaEndpoint(RTCPeerConnection& peerConnection, LibWebRTCProvider& client, Document& document, bool shouldEnableServiceClass)
104104
: m_peerConnectionFactory(*client.factory())
105105
, m_createSessionDescriptionObserver(*this)
106106
, m_setLocalSessionDescriptionObserver(*this)
107107
, m_setRemoteSessionDescriptionObserver(*this)
108108
, m_statsLogTimer(*this, &LibWebRTCMediaEndpoint::gatherStatsForLogging)
109-
, m_rtcSocketFactory(createLibWebRTCMediaEndpointSocketFactory(client, document))
109+
, m_rtcSocketFactory(createLibWebRTCMediaEndpointSocketFactory(client, document, shouldEnableServiceClass))
110110
#if !RELEASE_LOG_DISABLED
111111
, m_logger(peerConnection.logger())
112112
, m_logIdentifier(peerConnection.logIdentifier())
@@ -144,26 +144,6 @@ void LibWebRTCMediaEndpoint::restartIce()
144144
m_backend->RestartIce();
145145
}
146146

147-
static std::unique_ptr<LibWebRTCProvider::SuspendableSocketFactory> createLibWebRTCMediaEndpointSocketFactory(LibWebRTCProvider& client, LibWebRTCPeerConnectionBackend& peerConnectionBackend, Document& document)
148-
{
149-
RegistrableDomain domain { document.url() };
150-
bool isFirstParty = domain == RegistrableDomain(document.firstPartyForCookies());
151-
auto rtcSocketFactory = client.createSocketFactory(document.userAgent(document.url()), document.identifier(), isFirstParty, WTF::move(domain));
152-
if (!peerConnectionBackend.shouldFilterICECandidates() && rtcSocketFactory)
153-
rtcSocketFactory->disableRelay();
154-
return rtcSocketFactory;
155-
}
156-
157-
RefPtr<webrtc::PeerConnectionInterface> LibWebRTCMediaEndpoint::createBackend(LibWebRTCProvider& client, webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
158-
{
159-
Ref peerConnectionBackend = *m_peerConnectionBackend;
160-
Ref document = *downcast<Document>(peerConnectionBackend->protectedConnection()->scriptExecutionContext());
161-
if (!m_rtcSocketFactory)
162-
lazyInitialize(m_rtcSocketFactory, createLibWebRTCMediaEndpointSocketFactory(client, peerConnectionBackend, document));
163-
164-
return toRefPtr(client.createPeerConnection(document->identifier(), *this, m_rtcSocketFactory.get(), WTF::move(configuration)));
165-
}
166-
167147
bool LibWebRTCMediaEndpoint::setConfiguration(webrtc::PeerConnectionInterface::RTCConfiguration&& configuration)
168148
{
169149
prepareConfiguration(configuration);

0 commit comments

Comments
 (0)