Title: [282217] trunk
Revision
282217
Author
[email protected]
Date
2021-09-09 09:08:51 -0700 (Thu, 09 Sep 2021)

Log Message

Update RTCPeerConnection descriptions as per specification
https://bugs.webkit.org/show_bug.cgi?id=229963

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

* web-platform-tests/webrtc/RTCPeerConnection-description-attributes-timing.https-expected.txt:
* web-platform-tests/webrtc/RTCPeerConnection-setLocalDescription-rollback-expected.txt:

Source/WebCore:

A peer connection has two sets of descriptions: main thread descriptions which are exposed to JS and signaling thread descriptions
which are used/modified internally by the backend.
WebRTC spec describes when signaling thread descriptions should be used to set main thread descriptions.
This should be done at the end of setting remote/local descriptions, as well as when adding or surfacing an ICE candidate.
We make sure to grab signaling thread descriptions at those moments, then hop to main thread to set the main thread descriptions.

In case of closed connection, we stop early as we do not need to surface new descriptions (as well as resolve promises/fire events).

Covered by rebased tests.

* Modules/mediastream/PeerConnectionBackend.cpp:
(WebCore::PeerConnectionBackend::setLocalDescriptionSucceeded):
(WebCore::PeerConnectionBackend::setRemoteDescriptionSucceeded):
(WebCore::PeerConnectionBackend::addIceCandidate):
(WebCore::PeerConnectionBackend::newICECandidate):
* Modules/mediastream/PeerConnectionBackend.h:
* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::updateDescription):
(WebCore::RTCPeerConnection::updateDescriptions):
* Modules/mediastream/RTCPeerConnection.h:
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::fromSessionDescriptionType):
(WebCore::descriptionsFromPeerConnection):
(WebCore::LibWebRTCMediaEndpoint::addIceCandidate):
(WebCore::LibWebRTCMediaEndpoint::OnIceCandidate):
(WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionSucceeded):
(WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionSucceeded):
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::doAddIceCandidate):
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:

LayoutTests:

Now that we update descriptions at specific times,
we need to wait a bit to get the description.

* webrtc/datachannel/mdns-ice-candidates.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (282216 => 282217)


--- trunk/LayoutTests/ChangeLog	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/LayoutTests/ChangeLog	2021-09-09 16:08:51 UTC (rev 282217)
@@ -1,3 +1,15 @@
+2021-09-09  Youenn Fablet  <[email protected]>
+
+        Update RTCPeerConnection descriptions as per specification
+        https://bugs.webkit.org/show_bug.cgi?id=229963
+
+        Reviewed by Eric Carlson.
+
+        Now that we update descriptions at specific times,
+        we need to wait a bit to get the description.
+
+        * webrtc/datachannel/mdns-ice-candidates.html:
+
 2021-09-09  Eric Hutchison  <[email protected]>
 
          [iOS14 Sim Release iPhone] fast/sub-pixel/auto-table-layout-should-avoid-text-wrapping.html is a flaky crash.

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (282216 => 282217)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-09 16:08:51 UTC (rev 282217)
@@ -1,3 +1,13 @@
+2021-09-09  Youenn Fablet  <[email protected]>
+
+        Update RTCPeerConnection descriptions as per specification
+        https://bugs.webkit.org/show_bug.cgi?id=229963
+
+        Reviewed by Eric Carlson.
+
+        * web-platform-tests/webrtc/RTCPeerConnection-description-attributes-timing.https-expected.txt:
+        * web-platform-tests/webrtc/RTCPeerConnection-setLocalDescription-rollback-expected.txt:
+
 2021-09-09  Manuel Rego Casasnovas  <[email protected]>
 
         [css-text-decor] Update WPT test suite

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-description-attributes-timing.https-expected.txt (282216 => 282217)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-description-attributes-timing.https-expected.txt	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-description-attributes-timing.https-expected.txt	2021-09-09 16:08:51 UTC (rev 282217)
@@ -1,6 +1,6 @@
 
-FAIL pendingLocalDescription is surfaced at the right time assert_equals: pendingLocalDescription is still null while promise pending expected null but got object "[object RTCSessionDescription]"
-FAIL pendingRemoteDescription is surfaced at the right time assert_equals: pendingRemoteDescription is still null while promise pending expected null but got object "[object RTCSessionDescription]"
-FAIL currentLocalDescription is surfaced at the right time assert_equals: currentLocalDescription is still null while promise pending expected null but got object "[object RTCSessionDescription]"
-FAIL currentRemoteDescription is surfaced at the right time assert_equals: currentRemoteDescription is still null while promise pending expected null but got object "[object RTCSessionDescription]"
+PASS pendingLocalDescription is surfaced at the right time
+PASS pendingRemoteDescription is surfaced at the right time
+PASS currentLocalDescription is surfaced at the right time
+PASS currentRemoteDescription is surfaced at the right time
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-setLocalDescription-rollback-expected.txt (282216 => 282217)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-setLocalDescription-rollback-expected.txt	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-setLocalDescription-rollback-expected.txt	2021-09-09 16:08:51 UTC (rev 282217)
@@ -3,5 +3,5 @@
 PASS setLocalDescription(rollback) from stable state should reject with InvalidStateError
 PASS setLocalDescription(rollback) after setting answer description should reject with InvalidStateError
 PASS setLocalDescription(rollback) should ignore invalid sdp content and succeed
-FAIL setLocalDescription(rollback) should update internal state with a queued tassk, in the right order assert_not_equals: pendingLocalDescription should not be set synchronously after a call to sLD got disallowed value null
+FAIL setLocalDescription(rollback) should update internal state with a queued tassk, in the right order assert_equals: pendingLocalDescription should be updated before the signalingstatechange event expected null but got object "[object RTCSessionDescription]"
 

Modified: trunk/LayoutTests/webrtc/datachannel/mdns-ice-candidates.html (282216 => 282217)


--- trunk/LayoutTests/webrtc/datachannel/mdns-ice-candidates.html	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/LayoutTests/webrtc/datachannel/mdns-ice-candidates.html	2021-09-09 16:08:51 UTC (rev 282217)
@@ -160,11 +160,14 @@
 
     const channel2 = pc.createDataChannel('sendDataChannel2');
     const offer2 = await pc.createOffer();
-    const description = pc.localDescription;
 
     // Make sure we can apply the filtered description.
-    await pc.setLocalDescription(description);
+    await pc.setLocalDescription(pc.localDescription);
 
+    // Reapply description which should have candidates.
+    await pc.setLocalDescription(offer2);
+    const description = pc.localDescription;
+
     const lines = description.sdp.split('\r\n').filter(line => {
         return line.indexOf('a=candidate') === 0;
     });

Modified: trunk/Source/WebCore/ChangeLog (282216 => 282217)


--- trunk/Source/WebCore/ChangeLog	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/Source/WebCore/ChangeLog	2021-09-09 16:08:51 UTC (rev 282217)
@@ -1,3 +1,42 @@
+2021-09-09  Youenn Fablet  <[email protected]>
+
+        Update RTCPeerConnection descriptions as per specification
+        https://bugs.webkit.org/show_bug.cgi?id=229963
+
+        Reviewed by Eric Carlson.
+
+        A peer connection has two sets of descriptions: main thread descriptions which are exposed to JS and signaling thread descriptions
+        which are used/modified internally by the backend.
+        WebRTC spec describes when signaling thread descriptions should be used to set main thread descriptions.
+        This should be done at the end of setting remote/local descriptions, as well as when adding or surfacing an ICE candidate.
+        We make sure to grab signaling thread descriptions at those moments, then hop to main thread to set the main thread descriptions.
+
+        In case of closed connection, we stop early as we do not need to surface new descriptions (as well as resolve promises/fire events).
+
+        Covered by rebased tests.
+
+        * Modules/mediastream/PeerConnectionBackend.cpp:
+        (WebCore::PeerConnectionBackend::setLocalDescriptionSucceeded):
+        (WebCore::PeerConnectionBackend::setRemoteDescriptionSucceeded):
+        (WebCore::PeerConnectionBackend::addIceCandidate):
+        (WebCore::PeerConnectionBackend::newICECandidate):
+        * Modules/mediastream/PeerConnectionBackend.h:
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::updateDescription):
+        (WebCore::RTCPeerConnection::updateDescriptions):
+        * Modules/mediastream/RTCPeerConnection.h:
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::fromSessionDescriptionType):
+        (WebCore::descriptionsFromPeerConnection):
+        (WebCore::LibWebRTCMediaEndpoint::addIceCandidate):
+        (WebCore::LibWebRTCMediaEndpoint::OnIceCandidate):
+        (WebCore::LibWebRTCMediaEndpoint::setLocalSessionDescriptionSucceeded):
+        (WebCore::LibWebRTCMediaEndpoint::setRemoteSessionDescriptionSucceeded):
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
+        (WebCore::LibWebRTCPeerConnectionBackend::doAddIceCandidate):
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
+
 2021-09-09  Antti Koivisto  <[email protected]>
 
         Add cache to InlineContent for O(1) inline box access

Modified: trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp (282216 => 282217)


--- trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp	2021-09-09 16:08:51 UTC (rev 282217)
@@ -175,16 +175,18 @@
     doSetLocalDescription(sessionDescription);
 }
 
-void PeerConnectionBackend::setLocalDescriptionSucceeded(std::unique_ptr<RTCSctpTransportBackend>&& sctpBackend)
+void PeerConnectionBackend::setLocalDescriptionSucceeded(std::optional<DescriptionStates>&& descriptionStates, std::unique_ptr<RTCSctpTransportBackend>&& sctpBackend)
 {
     ASSERT(isMainThread());
     ALWAYS_LOG(LOGIDENTIFIER);
 
     ASSERT(m_setDescriptionPromise);
-    m_peerConnection.doTask([this, promise = WTFMove(m_setDescriptionPromise), sctpBackend = WTFMove(sctpBackend)]() mutable {
+    m_peerConnection.doTask([this, promise = WTFMove(m_setDescriptionPromise), descriptionStates = WTFMove(descriptionStates), sctpBackend = WTFMove(sctpBackend)]() mutable {
         if (m_peerConnection.isClosed())
             return;
 
+        if (descriptionStates)
+            m_peerConnection.updateDescriptions(WTFMove(*descriptionStates));
         m_peerConnection.updateTransceiversAfterSuccessfulLocalDescription();
         m_peerConnection.updateSctpBackend(WTFMove(sctpBackend));
         promise->resolve();
@@ -213,7 +215,7 @@
     doSetRemoteDescription(sessionDescription);
 }
 
-void PeerConnectionBackend::setRemoteDescriptionSucceeded(std::unique_ptr<RTCSctpTransportBackend>&& sctpBackend)
+void PeerConnectionBackend::setRemoteDescriptionSucceeded(std::optional<DescriptionStates>&& descriptionStates, std::unique_ptr<RTCSctpTransportBackend>&& sctpBackend)
 {
     ASSERT(isMainThread());
     ALWAYS_LOG(LOGIDENTIFIER, "Set remote description succeeded");
@@ -234,10 +236,12 @@
         track.source().setMuted(false);
     }
 
-    m_peerConnection.doTask([this, promise = WTFMove(promise), sctpBackend = WTFMove(sctpBackend)]() mutable {
+    m_peerConnection.doTask([this, promise = WTFMove(promise), descriptionStates = WTFMove(descriptionStates), sctpBackend = WTFMove(sctpBackend)]() mutable {
         if (m_peerConnection.isClosed())
             return;
 
+        if (descriptionStates)
+            m_peerConnection.updateDescriptions(WTFMove(*descriptionStates));
         m_peerConnection.updateTransceiversAfterSuccessfulRemoteDescription();
         m_peerConnection.updateSctpBackend(WTFMove(sctpBackend));
         promise->resolve();
@@ -314,8 +318,16 @@
         ASSERT(isMainThread());
         if (!weakThis || weakThis->m_peerConnection.isClosed())
             return;
-        RELEASE_LOG_ERROR(WebRTC, "Adding ice candidate finished, success=%d", result.hasException());
-        promise.settle(WTFMove(result));
+
+        if (result.hasException()) {
+            RELEASE_LOG_ERROR(WebRTC, "Adding ice candidate failed %d", result.exception().code());
+            promise.reject(result.releaseException());
+            return;
+        }
+
+        if (auto descriptions = result.releaseReturnValue())
+            weakThis->m_peerConnection.updateDescriptions(WTFMove(*descriptions));
+        promise.resolve();
     });
 }
 
@@ -349,12 +361,15 @@
 #endif
 }
 
-void PeerConnectionBackend::newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex, String&& serverURL)
+void PeerConnectionBackend::newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex, String&& serverURL, std::optional<DescriptionStates>&& descriptions)
 {
-    m_peerConnection.doTask([logSiteIdentifier = LOGIDENTIFIER, this, sdp = WTFMove(sdp), mid = WTFMove(mid), sdpMLineIndex, serverURL = WTFMove(serverURL)]() mutable {
+    m_peerConnection.doTask([logSiteIdentifier = LOGIDENTIFIER, this, sdp = WTFMove(sdp), mid = WTFMove(mid), sdpMLineIndex, serverURL = WTFMove(serverURL), descriptions = WTFMove(descriptions)]() mutable {
         if (m_peerConnection.isClosed())
             return;
 
+        if (descriptions)
+            m_peerConnection.updateDescriptions(WTFMove(*descriptions));
+
         UNUSED_PARAM(logSiteIdentifier);
         ALWAYS_LOG(logSiteIdentifier, "Gathered ice candidate:", sdp);
         m_finishedGatheringCandidates = false;

Modified: trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h (282216 => 282217)


--- trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h	2021-09-09 16:08:51 UTC (rev 282217)
@@ -104,14 +104,6 @@
 
     virtual void close() = 0;
 
-    virtual RefPtr<RTCSessionDescription> localDescription() const = 0;
-    virtual RefPtr<RTCSessionDescription> currentLocalDescription() const = 0;
-    virtual RefPtr<RTCSessionDescription> pendingLocalDescription() const = 0;
-
-    virtual RefPtr<RTCSessionDescription> remoteDescription() const = 0;
-    virtual RefPtr<RTCSessionDescription> currentRemoteDescription() const = 0;
-    virtual RefPtr<RTCSessionDescription> pendingRemoteDescription() const = 0;
-
     virtual void restartIce() = 0;
     virtual bool setConfiguration(MediaEndpointConfiguration&&) = 0;
 
@@ -130,7 +122,18 @@
 
     virtual void emulatePlatformEvent(const String& action) = 0;
 
-    void newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex, String&& serverURL);
+    struct DescriptionStates {
+        std::optional<RTCSdpType> currentLocalDescriptionSdpType;
+        String currentLocalDescriptionSdp;
+        std::optional<RTCSdpType> pendingLocalDescriptionSdpType;
+        String pendingLocalDescriptionSdp;
+        std::optional<RTCSdpType> currentRemoteDescriptionSdpType;
+        String currentRemoteDescriptionSdp;
+        std::optional<RTCSdpType> pendingRemoteDescriptionSdpType;
+        String pendingRemoteDescriptionSdp;
+    };
+
+    void newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex, String&& serverURL, std::optional<DescriptionStates>&&);
     virtual void disableICECandidateFiltering();
     void enableICECandidateFiltering();
 
@@ -187,6 +190,9 @@
 
     bool shouldFilterICECandidates() const { return m_shouldFilterICECandidates; };
 
+    using AddIceCandidateCallbackFunction = void(ExceptionOr<std::optional<PeerConnectionBackend::DescriptionStates>>&&);
+    using AddIceCandidateCallback = Function<AddIceCandidateCallbackFunction>;
+
 protected:
     void fireICECandidateEvent(RefPtr<RTCIceCandidate>&&, String&& url);
     void doneGatheringCandidates();
@@ -199,15 +205,12 @@
     void createAnswerSucceeded(String&&);
     void createAnswerFailed(Exception&&);
 
-    void setLocalDescriptionSucceeded(std::unique_ptr<RTCSctpTransportBackend>&&);
+    void setLocalDescriptionSucceeded(std::optional<DescriptionStates>&&, std::unique_ptr<RTCSctpTransportBackend>&&);
     void setLocalDescriptionFailed(Exception&&);
 
-    void setRemoteDescriptionSucceeded(std::unique_ptr<RTCSctpTransportBackend>&&);
+    void setRemoteDescriptionSucceeded(std::optional<DescriptionStates>&&, std::unique_ptr<RTCSctpTransportBackend>&&);
     void setRemoteDescriptionFailed(Exception&&);
 
-    void addIceCandidateSucceeded();
-    void addIceCandidateFailed(Exception&&);
-
     void validateSDP(const String&) const;
 
     struct PendingTrackEvent {
@@ -223,7 +226,7 @@
     virtual void doCreateAnswer(RTCAnswerOptions&&) = 0;
     virtual void doSetLocalDescription(const RTCSessionDescription*) = 0;
     virtual void doSetRemoteDescription(const RTCSessionDescription&) = 0;
-    virtual void doAddIceCandidate(RTCIceCandidate&, Function<void(ExceptionOr<void>&&)>&&) = 0;
+    virtual void doAddIceCandidate(RTCIceCandidate&, AddIceCandidateCallback&&) = 0;
     virtual void endOfIceCandidates(DOMPromiseDeferred<void>&&);
     virtual void doStop() = 0;
 

Modified: trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp (282216 => 282217)


--- trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp	2021-09-09 16:08:51 UTC (rev 282217)
@@ -247,21 +247,6 @@
     });
 }
 
-RefPtr<RTCSessionDescription> RTCPeerConnection::localDescription() const
-{
-    return m_backend->localDescription();
-}
-
-RefPtr<RTCSessionDescription> RTCPeerConnection::currentLocalDescription() const
-{
-    return m_backend->currentLocalDescription();
-}
-
-RefPtr<RTCSessionDescription> RTCPeerConnection::pendingLocalDescription() const
-{
-    return m_backend->pendingLocalDescription();
-}
-
 void RTCPeerConnection::setRemoteDescription(Description&& remoteDescription, Ref<DeferredPromise>&& promise)
 {
     RefPtr<RTCSessionDescription> description;
@@ -286,21 +271,6 @@
     });
 }
 
-RefPtr<RTCSessionDescription> RTCPeerConnection::remoteDescription() const
-{
-    return m_backend->remoteDescription();
-}
-
-RefPtr<RTCSessionDescription> RTCPeerConnection::currentRemoteDescription() const
-{
-    return m_backend->currentRemoteDescription();
-}
-
-RefPtr<RTCSessionDescription> RTCPeerConnection::pendingRemoteDescription() const
-{
-    return m_backend->pendingRemoteDescription();
-}
-
 void RTCPeerConnection::addIceCandidate(Candidate&& rtcCandidate, Ref<DeferredPromise>&& promise)
 {
     std::optional<Exception> exception;
@@ -934,6 +904,25 @@
     return m_dtlsTransports[index].copyRef();
 }
 
+static void updateDescription(RefPtr<RTCSessionDescription>& description, std::optional<RTCSdpType> type, String&& sdp)
+{
+    if (description && type && description->sdp() == sdp && description->type() == *type)
+        return;
+    if (!type || sdp.isEmpty()) {
+        description = nullptr;
+        return;
+    }
+    description = RTCSessionDescription::create(*type, WTFMove(sdp));
+}
+
+void RTCPeerConnection::updateDescriptions(PeerConnectionBackend::DescriptionStates&& states)
+{
+    updateDescription(m_currentLocalDescription, states.currentLocalDescriptionSdpType, WTFMove(states.currentLocalDescriptionSdp));
+    updateDescription(m_pendingLocalDescription, states.pendingLocalDescriptionSdpType, WTFMove(states.pendingLocalDescriptionSdp));
+    updateDescription(m_currentRemoteDescription, states.currentRemoteDescriptionSdpType, WTFMove(states.currentRemoteDescriptionSdp));
+    updateDescription(m_pendingRemoteDescription, states.pendingRemoteDescriptionSdpType, WTFMove(states.pendingRemoteDescriptionSdp));
+}
+
 void RTCPeerConnection::updateTransceiverTransports()
 {
     for (auto& transceiver : m_transceiverSet.list()) {

Modified: trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.h (282216 => 282217)


--- trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.h	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.h	2021-09-09 16:08:51 UTC (rev 282217)
@@ -112,14 +112,14 @@
 
     using Description = Variant<RTCSessionDescriptionInit, RefPtr<RTCSessionDescription>>;
     void setLocalDescription(std::optional<Description>&&, Ref<DeferredPromise>&&);
-    RefPtr<RTCSessionDescription> localDescription() const;
-    RefPtr<RTCSessionDescription> currentLocalDescription() const;
-    RefPtr<RTCSessionDescription> pendingLocalDescription() const;
+    RefPtr<RTCSessionDescription> localDescription() const { return m_pendingLocalDescription ? m_pendingLocalDescription.get() : m_currentLocalDescription.get(); }
+    RefPtr<RTCSessionDescription> currentLocalDescription() const { return m_currentLocalDescription.get(); }
+    RefPtr<RTCSessionDescription> pendingLocalDescription() const { return m_pendingLocalDescription.get(); }
 
     void setRemoteDescription(Description&&, Ref<DeferredPromise>&&);
-    RefPtr<RTCSessionDescription> remoteDescription() const;
-    RefPtr<RTCSessionDescription> currentRemoteDescription() const;
-    RefPtr<RTCSessionDescription> pendingRemoteDescription() const;
+    RTCSessionDescription* remoteDescription() const { return m_pendingRemoteDescription ? m_pendingRemoteDescription.get() : m_currentRemoteDescription.get(); }
+    RTCSessionDescription* currentRemoteDescription() const { return m_currentRemoteDescription.get(); }
+    RTCSessionDescription* pendingRemoteDescription() const { return m_pendingRemoteDescription.get(); }
 
     using Candidate = std::optional<Variant<RTCIceCandidateInit, RefPtr<RTCIceCandidate>>>;
     void addIceCandidate(Candidate&&, Ref<DeferredPromise>&&);
@@ -187,6 +187,7 @@
 
     void doTask(Function<void()>&&);
 
+    void updateDescriptions(PeerConnectionBackend::DescriptionStates&&);
     void updateTransceiversAfterSuccessfulLocalDescription();
     void updateTransceiversAfterSuccessfulRemoteDescription();
     void updateSctpBackend(std::unique_ptr<RTCSctpTransportBackend>&&);
@@ -271,6 +272,11 @@
     Vector<Ref<RTCDtlsTransport>> m_dtlsTransports;
     Vector<Ref<RTCIceTransport>> m_iceTransports;
     RefPtr<RTCSctpTransport> m_sctpTransport;
+
+    RefPtr<RTCSessionDescription> m_currentLocalDescription;
+    RefPtr<RTCSessionDescription> m_pendingLocalDescription;
+    RefPtr<RTCSessionDescription> m_currentRemoteDescription;
+    RefPtr<RTCSessionDescription> m_pendingRemoteDescription;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp (282216 => 282217)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp	2021-09-09 16:08:51 UTC (rev 282217)
@@ -60,6 +60,7 @@
 #include <webrtc/pc/peer_connection_factory.h>
 #include <webrtc/system_wrappers/include/field_trial.h>
 #include <wtf/MainThread.h>
+#include <wtf/SharedTask.h>
 
 namespace WebCore {
 
@@ -143,59 +144,6 @@
     return "";
 }
 
-static inline RTCSdpType fromSessionDescriptionType(const webrtc::SessionDescriptionInterface& description)
-{
-    auto type = description.type();
-    if (type == webrtc::SessionDescriptionInterface::kOffer)
-        return RTCSdpType::Offer;
-    if (type == webrtc::SessionDescriptionInterface::kAnswer)
-        return RTCSdpType::Answer;
-    ASSERT(type == webrtc::SessionDescriptionInterface::kPrAnswer);
-    return RTCSdpType::Pranswer;
-}
-
-static inline RefPtr<RTCSessionDescription> fromSessionDescription(const webrtc::SessionDescriptionInterface* description)
-{
-    if (!description)
-        return nullptr;
-
-    std::string sdp;
-    description->ToString(&sdp);
-
-    return RTCSessionDescription::create(fromSessionDescriptionType(*description), fromStdString(sdp));
-}
-
-// FIXME: We might want to create a new object only if the session actually changed for all description getters.
-RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::currentLocalDescription() const
-{
-    return m_backend ? fromSessionDescription(m_backend->current_local_description()) : nullptr;
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::currentRemoteDescription() const
-{
-    return m_backend ? fromSessionDescription(m_backend->current_remote_description()) : nullptr;
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::pendingLocalDescription() const
-{
-    return m_backend ? fromSessionDescription(m_backend->pending_local_description()) : nullptr;
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::pendingRemoteDescription() const
-{
-    return m_backend ? fromSessionDescription(m_backend->pending_remote_description()) : nullptr;
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::localDescription() const
-{
-    return m_backend ? fromSessionDescription(m_backend->local_description()) : nullptr;
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCMediaEndpoint::remoteDescription() const
-{
-    return m_backend ? fromSessionDescription(m_backend->remote_description()) : nullptr;
-}
-
 void LibWebRTCMediaEndpoint::doSetLocalDescription(const RTCSessionDescription* description)
 {
     ASSERT(m_backend);
@@ -620,11 +568,62 @@
     });
 }
 
-void LibWebRTCMediaEndpoint::addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&& candidate, std::function<void(webrtc::RTCError)>&& callback)
+static inline RTCSdpType fromSessionDescriptionType(const webrtc::SessionDescriptionInterface& description)
 {
-    m_backend->AddIceCandidate(WTFMove(candidate), WTFMove(callback));
+    auto type = description.type();
+    if (type == webrtc::SessionDescriptionInterface::kOffer)
+        return RTCSdpType::Offer;
+    if (type == webrtc::SessionDescriptionInterface::kAnswer)
+        return RTCSdpType::Answer;
+    ASSERT(type == webrtc::SessionDescriptionInterface::kPrAnswer);
+    return RTCSdpType::Pranswer;
 }
 
+static std::optional<PeerConnectionBackend::DescriptionStates> descriptionsFromPeerConnection(webrtc::PeerConnectionInterface* connection)
+{
+    if (!connection)
+        return { };
+
+    std::optional<RTCSdpType> currentLocalDescriptionSdpType, pendingLocalDescriptionSdpType, currentRemoteDescriptionSdpType, pendingRemoteDescriptionSdpType;
+    std::string currentLocalDescriptionSdp, pendingLocalDescriptionSdp, currentRemoteDescriptionSdp, pendingRemoteDescriptionSdp;
+    if (auto* description = connection->current_local_description()) {
+        currentLocalDescriptionSdpType = fromSessionDescriptionType(*description);
+        description->ToString(&currentLocalDescriptionSdp);
+    }
+    if (auto* description = connection->pending_local_description()) {
+        pendingLocalDescriptionSdpType = fromSessionDescriptionType(*description);
+        description->ToString(&pendingLocalDescriptionSdp);
+    }
+    if (auto* description = connection->current_remote_description()) {
+        currentRemoteDescriptionSdpType = fromSessionDescriptionType(*description);
+        description->ToString(&currentRemoteDescriptionSdp);
+    }
+    if (auto* description = connection->pending_remote_description()) {
+        pendingRemoteDescriptionSdpType = fromSessionDescriptionType(*description);
+        description->ToString(&pendingRemoteDescriptionSdp);
+    }
+
+    return PeerConnectionBackend::DescriptionStates {
+        currentLocalDescriptionSdpType, fromStdString(currentLocalDescriptionSdp),
+        pendingLocalDescriptionSdpType, fromStdString(pendingLocalDescriptionSdp),
+        currentRemoteDescriptionSdpType, fromStdString(currentRemoteDescriptionSdp),
+        pendingRemoteDescriptionSdpType, fromStdString(pendingRemoteDescriptionSdp)
+    };
+}
+
+void LibWebRTCMediaEndpoint::addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&& candidate, PeerConnectionBackend::AddIceCandidateCallback&& callback)
+{
+    m_backend->AddIceCandidate(WTFMove(candidate), [task = createSharedTask<PeerConnectionBackend::AddIceCandidateCallbackFunction>(WTFMove(callback)), backend = m_backend](auto&& error) mutable {
+        callOnMainThread([task = WTFMove(task), descriptions = descriptionsFromPeerConnection(backend.get()), error = WTFMove(error)]() mutable {
+            if (!error.ok()) {
+                task->run(toException(error));
+                return;
+            }
+            task->run(WTFMove(descriptions));
+        });
+    });
+}
+
 void LibWebRTCMediaEndpoint::OnIceCandidate(const webrtc::IceCandidateInterface *rtcCandidate)
 {
     ASSERT(rtcCandidate);
@@ -634,10 +633,10 @@
 
     auto sdpMLineIndex = safeCast<unsigned short>(rtcCandidate->sdp_mline_index());
 
-    callOnMainThread([protectedThis = makeRef(*this), mid = fromStdString(rtcCandidate->sdp_mid()), sdp = fromStdString(sdp), sdpMLineIndex, url = "" mutable {
+    callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get()), mid = fromStdString(rtcCandidate->sdp_mid()), sdp = fromStdString(sdp), sdpMLineIndex, url = "" mutable {
         if (protectedThis->isStopped())
             return;
-        protectedThis->m_peerConnectionBackend.newICECandidate(WTFMove(sdp), WTFMove(mid), sdpMLineIndex, WTFMove(url));
+        protectedThis->m_peerConnectionBackend.newICECandidate(WTFMove(sdp), WTFMove(mid), sdpMLineIndex, WTFMove(url), WTFMove(descriptions));
     });
 }
 
@@ -699,10 +698,10 @@
 
 void LibWebRTCMediaEndpoint::setLocalSessionDescriptionSucceeded()
 {
-    callOnMainThread([protectedThis = makeRef(*this), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
+    callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get()), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
         if (protectedThis->isStopped())
             return;
-        protectedThis->m_peerConnectionBackend.setLocalDescriptionSucceeded(sctpState.createBackend());
+        protectedThis->m_peerConnectionBackend.setLocalDescriptionSucceeded(WTFMove(descriptions), sctpState.createBackend());
     });
 }
 
@@ -717,10 +716,10 @@
 
 void LibWebRTCMediaEndpoint::setRemoteSessionDescriptionSucceeded()
 {
-    callOnMainThread([protectedThis = makeRef(*this), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
+    callOnMainThread([protectedThis = makeRef(*this), descriptions = descriptionsFromPeerConnection(m_backend.get()), sctpState = SctpTransportState(m_backend->GetSctpTransport())]() mutable {
         if (protectedThis->isStopped())
             return;
-        protectedThis->m_peerConnectionBackend.setRemoteDescriptionSucceeded(sctpState.createBackend());
+        protectedThis->m_peerConnectionBackend.setRemoteDescriptionSucceeded(WTFMove(descriptions), sctpState.createBackend());
     });
 }
 

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h (282216 => 282217)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h	2021-09-09 16:08:51 UTC (rev 282217)
@@ -89,19 +89,12 @@
     void getStats(webrtc::RtpReceiverInterface&, Ref<DeferredPromise>&&);
     void getStats(webrtc::RtpSenderInterface&, Ref<DeferredPromise>&&);
     std::unique_ptr<RTCDataChannelHandler> createDataChannel(const String&, const RTCDataChannelInit&);
-    void addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&&, std::function<void(webrtc::RTCError)>&&);
+    void addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&&, PeerConnectionBackend::AddIceCandidateCallback&&);
 
     void close();
     void stop();
     bool isStopped() const { return !m_backend; }
 
-    RefPtr<RTCSessionDescription> localDescription() const;
-    RefPtr<RTCSessionDescription> remoteDescription() const;
-    RefPtr<RTCSessionDescription> currentLocalDescription() const;
-    RefPtr<RTCSessionDescription> currentRemoteDescription() const;
-    RefPtr<RTCSessionDescription> pendingLocalDescription() const;
-    RefPtr<RTCSessionDescription> pendingRemoteDescription() const;
-
     bool addTrack(LibWebRTCRtpSenderBackend&, MediaStreamTrack&, const Vector<String>&);
     void removeTrack(LibWebRTCRtpSenderBackend&);
 

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp (282216 => 282217)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp	2021-09-09 16:08:51 UTC (rev 282217)
@@ -47,7 +47,6 @@
 #include "RealtimeOutgoingAudioSource.h"
 #include "RealtimeOutgoingVideoSource.h"
 #include "Settings.h"
-#include <wtf/SharedTask.h>
 
 namespace WebCore {
 
@@ -270,7 +269,7 @@
     m_pendingReceivers.clear();
 }
 
-void LibWebRTCPeerConnectionBackend::doAddIceCandidate(RTCIceCandidate& candidate, Function<void(ExceptionOr<void>&&)>&& callback)
+void LibWebRTCPeerConnectionBackend::doAddIceCandidate(RTCIceCandidate& candidate, AddIceCandidateCallback&& callback)
 {
     webrtc::SdpParseError error;
     int sdpMLineIndex = candidate.sdpMLineIndex() ? candidate.sdpMLineIndex().value() : 0;
@@ -281,15 +280,7 @@
         return;
     }
 
-    m_endpoint->addIceCandidate(WTFMove(rtcCandidate), [task = createSharedTask<void(ExceptionOr<void>&&)>(WTFMove(callback))](auto&& error) mutable {
-        callOnMainThread([task = WTFMove(task), error = WTFMove(error)] {
-            if (!error.ok()) {
-                task->run(toException(error));
-                return;
-            }
-            task->run({ });
-        });
-    });
+    m_endpoint->addIceCandidate(WTFMove(rtcCandidate), WTFMove(callback));
 }
 
 Ref<RTCRtpReceiver> LibWebRTCPeerConnectionBackend::createReceiver(std::unique_ptr<LibWebRTCRtpReceiverBackend>&& backend)
@@ -311,45 +302,6 @@
     return m_endpoint->createDataChannel(label, options);
 }
 
-RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::currentLocalDescription() const
-{
-    auto description = m_endpoint->currentLocalDescription();
-    if (description)
-        validateSDP(description->sdp());
-    return description;
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::currentRemoteDescription() const
-{
-    return m_endpoint->currentRemoteDescription();
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::pendingLocalDescription() const
-{
-    auto description = m_endpoint->pendingLocalDescription();
-    if (description)
-        validateSDP(description->sdp());
-    return description;
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::pendingRemoteDescription() const
-{
-    return m_endpoint->pendingRemoteDescription();
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::localDescription() const
-{
-    auto description = m_endpoint->localDescription();
-    if (description)
-        validateSDP(description->sdp());
-    return description;
-}
-
-RefPtr<RTCSessionDescription> LibWebRTCPeerConnectionBackend::remoteDescription() const
-{
-    return m_endpoint->remoteDescription();
-}
-
 static inline RefPtr<RTCRtpSender> findExistingSender(const Vector<RefPtr<RTCRtpTransceiver>>& transceivers, LibWebRTCRtpSenderBackend& senderBackend)
 {
     ASSERT(senderBackend.rtcSender());

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h (282216 => 282217)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h	2021-09-09 15:57:27 UTC (rev 282216)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h	2021-09-09 16:08:51 UTC (rev 282217)
@@ -62,7 +62,7 @@
     void doCreateAnswer(RTCAnswerOptions&&) final;
     void doSetLocalDescription(const RTCSessionDescription*) final;
     void doSetRemoteDescription(const RTCSessionDescription&) final;
-    void doAddIceCandidate(RTCIceCandidate&, Function<void(ExceptionOr<void>&&)>&&) final;
+    void doAddIceCandidate(RTCIceCandidate&, AddIceCandidateCallback&&) final;
     void doStop() final;
     std::unique_ptr<RTCDataChannelHandler> createDataChannelHandler(const String&, const RTCDataChannelInit&) final;
     void restartIce() final;
@@ -71,14 +71,6 @@
     void getStats(RTCRtpSender&, Ref<DeferredPromise>&&) final;
     void getStats(RTCRtpReceiver&, Ref<DeferredPromise>&&) final;
 
-    RefPtr<RTCSessionDescription> localDescription() const final;
-    RefPtr<RTCSessionDescription> currentLocalDescription() const final;
-    RefPtr<RTCSessionDescription> pendingLocalDescription() const final;
-
-    RefPtr<RTCSessionDescription> remoteDescription() const final;
-    RefPtr<RTCSessionDescription> currentRemoteDescription() const final;
-    RefPtr<RTCSessionDescription> pendingRemoteDescription() const final;
-
     std::optional<bool> canTrickleIceCandidates() const final;
 
     void emulatePlatformEvent(const String&) final { }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to