Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (282361 => 282362)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-09-13 21:44:40 UTC (rev 282361)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-09-13 21:53:41 UTC (rev 282362)
@@ -1,3 +1,12 @@
+2021-09-13 Youenn Fablet <[email protected]>
+
+ Fire RTCPeerConnection.signalstatechange as per spec
+ https://bugs.webkit.org/show_bug.cgi?id=230093
+
+ Reviewed by Eric Carlson.
+
+ * web-platform-tests/webrtc/RTCPeerConnection-onsignalingstatechanged.https-expected.txt:
+
2021-09-13 Sihui Liu <[email protected]>
Add stub for File System Access API
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-onsignalingstatechanged.https-expected.txt (282361 => 282362)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-onsignalingstatechanged.https-expected.txt 2021-09-13 21:44:40 UTC (rev 282361)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-onsignalingstatechanged.https-expected.txt 2021-09-13 21:53:41 UTC (rev 282362)
@@ -1,5 +1,5 @@
PASS Negotiation methods fire signalingstatechange events
-FAIL Closing a PeerConnection should not fire signalingstatechange event assert_unreached: Reached unreachable code
+PASS Closing a PeerConnection should not fire signalingstatechange event
PASS signalingstatechange is the first event to fire
Modified: trunk/Source/WebCore/ChangeLog (282361 => 282362)
--- trunk/Source/WebCore/ChangeLog 2021-09-13 21:44:40 UTC (rev 282361)
+++ trunk/Source/WebCore/ChangeLog 2021-09-13 21:53:41 UTC (rev 282362)
@@ -1,3 +1,27 @@
+2021-09-13 Youenn Fablet <[email protected]>
+
+ Fire RTCPeerConnection.signalstatechange as per spec
+ https://bugs.webkit.org/show_bug.cgi?id=230093
+
+ Reviewed by Eric Carlson.
+
+ Instead of using the built-in OnSignalingChange mechanism, we only update when setting descriptions.
+ As per spec, we fire the event before other tracks related events in case of setting remote description.
+ Covered by existing and updated tests.
+
+ * Modules/mediastream/PeerConnectionBackend.cpp:
+ (WebCore::PeerConnectionBackend::setRemoteDescriptionSucceeded):
+ * Modules/mediastream/PeerConnectionBackend.h:
+ * Modules/mediastream/RTCPeerConnection.cpp:
+ (WebCore::RTCPeerConnection::setSignalingState):
+ (WebCore::RTCPeerConnection::updateDescriptions):
+ * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+ (WebCore::LibWebRTCMediaEndpoint::OnSignalingChange):
+ (WebCore::toRTCSignalingState):
+ (WebCore::descriptionsFromPeerConnection):
+ (WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionSucceeded):
+ (WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionSucceeded):
+
2021-09-13 Sihui Liu <[email protected]>
Add stub for File System Access API
Modified: trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp (282361 => 282362)
--- trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp 2021-09-13 21:44:40 UTC (rev 282361)
+++ trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp 2021-09-13 21:53:41 UTC (rev 282362)
@@ -221,27 +221,29 @@
ALWAYS_LOG(LOGIDENTIFIER, "Set remote description succeeded");
ASSERT(m_setDescriptionCallback);
- auto callback = WTFMove(m_setDescriptionCallback);
- auto events = WTFMove(m_pendingTrackEvents);
- for (auto& event : events) {
- auto& track = event.track.get();
-
- m_peerConnection.dispatchEventWhenFeasible(RTCTrackEvent::create(eventNames().trackEvent, Event::CanBubble::No, Event::IsCancelable::No, WTFMove(event.receiver), WTFMove(event.track), WTFMove(event.streams), WTFMove(event.transceiver)));
- ALWAYS_LOG(LOGIDENTIFIER, "Dispatched if feasible track of type ", track.source().type());
-
+ m_peerConnection.doTask([this, callback = WTFMove(m_setDescriptionCallback), descriptionStates = WTFMove(descriptionStates), sctpBackend = WTFMove(sctpBackend), events = WTFMove(m_pendingTrackEvents)]() mutable {
if (m_peerConnection.isClosed())
return;
- // FIXME: As per spec, we should set muted to 'false' when starting to receive the content from network.
- track.source().setMuted(false);
- }
+ if (descriptionStates)
+ m_peerConnection.updateDescriptions(WTFMove(*descriptionStates));
- m_peerConnection.doTask([this, callback = WTFMove(callback), descriptionStates = WTFMove(descriptionStates), sctpBackend = WTFMove(sctpBackend)]() mutable {
+ for (auto& event : events) {
+ auto& track = event.track.get();
+
+ m_peerConnection.dispatchEventWhenFeasible(RTCTrackEvent::create(eventNames().trackEvent, Event::CanBubble::No, Event::IsCancelable::No, WTFMove(event.receiver), WTFMove(event.track), WTFMove(event.streams), WTFMove(event.transceiver)));
+ ALWAYS_LOG(LOGIDENTIFIER, "Dispatched if feasible track of type ", track.source().type());
+
+ if (m_peerConnection.isClosed())
+ return;
+
+ // FIXME: As per spec, we should set muted to 'false' when starting to receive the content from network.
+ track.source().setMuted(false);
+ }
+
if (m_peerConnection.isClosed())
return;
- if (descriptionStates)
- m_peerConnection.updateDescriptions(WTFMove(*descriptionStates));
m_peerConnection.updateTransceiversAfterSuccessfulRemoteDescription();
m_peerConnection.updateSctpBackend(WTFMove(sctpBackend));
callback({ });
@@ -370,6 +372,9 @@
if (descriptions)
m_peerConnection.updateDescriptions(WTFMove(*descriptions));
+ if (m_peerConnection.isClosed())
+ return;
+
UNUSED_PARAM(logSiteIdentifier);
ALWAYS_LOG(logSiteIdentifier, "Gathered ice candidate:", sdp);
m_finishedGatheringCandidates = false;
Modified: trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h (282361 => 282362)
--- trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h 2021-09-13 21:44:40 UTC (rev 282361)
+++ trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h 2021-09-13 21:53:41 UTC (rev 282362)
@@ -123,6 +123,7 @@
virtual void emulatePlatformEvent(const String& action) = 0;
struct DescriptionStates {
+ std::optional<RTCSignalingState> signalingState;
std::optional<RTCSdpType> currentLocalDescriptionSdpType;
String currentLocalDescriptionSdp;
std::optional<RTCSdpType> pendingLocalDescriptionSdpType;
Modified: trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp (282361 => 282362)
--- trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp 2021-09-13 21:44:40 UTC (rev 282361)
+++ trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp 2021-09-13 21:53:41 UTC (rev 282362)
@@ -608,8 +608,12 @@
void RTCPeerConnection::setSignalingState(RTCSignalingState newState)
{
+ if (m_signalingState == newState)
+ return;
+
ALWAYS_LOG(LOGIDENTIFIER, newState);
m_signalingState = newState;
+ dispatchEventWhenFeasible(Event::create(eventNames().signalingstatechangeEvent, Event::CanBubble::No, Event::IsCancelable::No));
}
void RTCPeerConnection::updateIceGatheringState(RTCIceGatheringState newState)
@@ -932,6 +936,9 @@
void RTCPeerConnection::updateDescriptions(PeerConnectionBackend::DescriptionStates&& states)
{
+ if (states.signalingState)
+ setSignalingState(*states.signalingState);
+
updateDescription(m_currentLocalDescription, states.currentLocalDescriptionSdpType, WTFMove(states.currentLocalDescriptionSdp));
updateDescription(m_pendingLocalDescription, states.pendingLocalDescriptionSdpType, WTFMove(states.pendingLocalDescriptionSdp));
updateDescription(m_currentRemoteDescription, states.currentRemoteDescriptionSdpType, WTFMove(states.currentRemoteDescriptionSdp));
Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp (282361 => 282362)
--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp 2021-09-13 21:44:40 UTC (rev 282361)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp 2021-09-13 21:53:41 UTC (rev 282362)
@@ -282,37 +282,10 @@
m_backend->GetStats(rtc::scoped_refptr<webrtc::RtpSenderInterface>(&sender), createStatsCollector(WTFMove(promise)));
}
-static RTCSignalingState signalingState(webrtc::PeerConnectionInterface::SignalingState state)
+void LibWebRTCMediaEndpoint::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState)
{
- switch (state) {
- case webrtc::PeerConnectionInterface::kStable:
- return RTCSignalingState::Stable;
- case webrtc::PeerConnectionInterface::kHaveLocalOffer:
- return RTCSignalingState::HaveLocalOffer;
- case webrtc::PeerConnectionInterface::kHaveLocalPrAnswer:
- return RTCSignalingState::HaveLocalPranswer;
- case webrtc::PeerConnectionInterface::kHaveRemoteOffer:
- return RTCSignalingState::HaveRemoteOffer;
- case webrtc::PeerConnectionInterface::kHaveRemotePrAnswer:
- return RTCSignalingState::HaveRemotePranswer;
- case webrtc::PeerConnectionInterface::kClosed:
- return RTCSignalingState::Stable;
- }
-
- ASSERT_NOT_REACHED();
- return RTCSignalingState::Stable;
}
-void LibWebRTCMediaEndpoint::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState rtcState)
-{
- auto state = signalingState(rtcState);
- callOnMainThread([protectedThis = makeRef(*this), state] {
- if (protectedThis->isStopped())
- return;
- protectedThis->m_peerConnectionBackend.updateSignalingState(state);
- });
-}
-
MediaStream& LibWebRTCMediaEndpoint::mediaStreamFromRTCStream(webrtc::MediaStreamInterface& rtcStream)
{
auto label = fromStdString(rtcStream.id());
@@ -579,8 +552,30 @@
return RTCSdpType::Pranswer;
}
-static std::optional<PeerConnectionBackend::DescriptionStates> descriptionsFromPeerConnection(webrtc::PeerConnectionInterface* connection)
+static RTCSignalingState toRTCSignalingState(webrtc::PeerConnectionInterface::SignalingState state)
{
+ switch (state) {
+ case webrtc::PeerConnectionInterface::kStable:
+ return RTCSignalingState::Stable;
+ case webrtc::PeerConnectionInterface::kHaveLocalOffer:
+ return RTCSignalingState::HaveLocalOffer;
+ case webrtc::PeerConnectionInterface::kHaveLocalPrAnswer:
+ return RTCSignalingState::HaveLocalPranswer;
+ case webrtc::PeerConnectionInterface::kHaveRemoteOffer:
+ return RTCSignalingState::HaveRemoteOffer;
+ case webrtc::PeerConnectionInterface::kHaveRemotePrAnswer:
+ return RTCSignalingState::HaveRemotePranswer;
+ case webrtc::PeerConnectionInterface::kClosed:
+ return RTCSignalingState::Stable;
+ }
+
+ ASSERT_NOT_REACHED();
+ return RTCSignalingState::Stable;
+}
+
+enum class GatherSignalingState { No, Yes };
+static std::optional<PeerConnectionBackend::DescriptionStates> descriptionsFromPeerConnection(webrtc::PeerConnectionInterface* connection, GatherSignalingState gatherSignalingState = GatherSignalingState::No)
+{
if (!connection)
return { };
@@ -603,7 +598,11 @@
description->ToString(&pendingRemoteDescriptionSdp);
}
+ std::optional<RTCSignalingState> signalingState;
+ if (gatherSignalingState == GatherSignalingState::Yes)
+ signalingState = toRTCSignalingState(connection->signaling_state());
return PeerConnectionBackend::DescriptionStates {
+ signalingState,
currentLocalDescriptionSdpType, fromStdString(currentLocalDescriptionSdp),
pendingLocalDescriptionSdpType, fromStdString(pendingLocalDescriptionSdp),
currentRemoteDescriptionSdpType, fromStdString(currentRemoteDescriptionSdp),
@@ -698,7 +697,7 @@
void LibWebRTCMediaEndpoint::setLocalSessionDescriptionSucceeded()
{
- callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get()), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
+ callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get(), GatherSignalingState::Yes), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
if (protectedThis->isStopped())
return;
protectedThis->m_peerConnectionBackend.setLocalDescriptionSucceeded(WTFMove(descriptions), sctpState.createBackend());
@@ -716,7 +715,7 @@
void LibWebRTCMediaEndpoint::setRemoteSessionDescriptionSucceeded()
{
- callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get()), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
+ callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get(), GatherSignalingState::Yes), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
if (protectedThis->isStopped())
return;
protectedThis->m_peerConnectionBackend.setRemoteDescriptionSucceeded(WTFMove(descriptions), sctpState.createBackend());