Title: [281981] trunk
Revision
281981
Author
you...@apple.com
Date
2021-09-03 02:40:55 -0700 (Fri, 03 Sep 2021)

Log Message

Migrate to latest libwebrtc AddIceCandidate
https://bugs.webkit.org/show_bug.cgi?id=229700

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

* web-platform-tests/webrtc/RTCPeerConnection-addIceCandidate-expected.txt:
* web-platform-tests/webrtc/RTCPeerConnection-operations.https-expected.txt:
* web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare-linear.https-expected.txt:
* web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare.https-expected.txt:

Source/WebCore:

AddIceCandidate can now take a callback to return a RTCError which provides necessary information to reject the promise as needed.
Update binding code accordingly.
This allows to use a lambda that takes the promise instead of having the promise as a member of PeerConnectionBackend.
Covered by updated and rebased tests.

* Modules/mediastream/PeerConnectionBackend.cpp:
(WebCore::PeerConnectionBackend::addIceCandidate):
(WebCore::PeerConnectionBackend::stop):
(WebCore::PeerConnectionBackend::addIceCandidateSucceeded): Deleted.
(WebCore::PeerConnectionBackend::addIceCandidateFailed): Deleted.
* Modules/mediastream/PeerConnectionBackend.h:
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::LibWebRTCMediaEndpoint::addIceCandidate):
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
(WebCore::LibWebRTCMediaEndpoint::addIceCandidate): Deleted.
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::doSetLocalDescription):
(WebCore::LibWebRTCPeerConnectionBackend::doSetRemoteDescription):
(WebCore::LibWebRTCPeerConnectionBackend::doAddIceCandidate):
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
* testing/MockLibWebRTCPeerConnection.h:

LayoutTests:

* TestExpectations: mark failing test as flaky as an exception sometimes happen.
* fast/mediastream/RTCPeerConnection-addIceCandidate-expected.txt:
* fast/mediastream/RTCPeerConnection-addIceCandidate.html:
Update the test to match implementation, which makes it consistent with other browsers.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (281980 => 281981)


--- trunk/LayoutTests/ChangeLog	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/LayoutTests/ChangeLog	2021-09-03 09:40:55 UTC (rev 281981)
@@ -1,3 +1,15 @@
+2021-09-03  Youenn Fablet  <you...@apple.com>
+
+        Migrate to latest libwebrtc AddIceCandidate
+        https://bugs.webkit.org/show_bug.cgi?id=229700
+
+        Reviewed by Eric Carlson.
+
+        * TestExpectations: mark failing test as flaky as an exception sometimes happen.
+        * fast/mediastream/RTCPeerConnection-addIceCandidate-expected.txt:
+        * fast/mediastream/RTCPeerConnection-addIceCandidate.html:
+        Update the test to match implementation, which makes it consistent with other browsers.
+
 2021-09-03  Said Abou-Hallawa  <s...@apple.com>
 
         Add a layout test to detect memory leaks when drawing images to a detached canvas

Modified: trunk/LayoutTests/TestExpectations (281980 => 281981)


--- trunk/LayoutTests/TestExpectations	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/LayoutTests/TestExpectations	2021-09-03 09:40:55 UTC (rev 281981)
@@ -2185,6 +2185,8 @@
 imported/w3c/web-platform-tests/webrtc/protocol/split.https.html [ Pass Failure ]
 imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-restartIce-onnegotiationneeded.https.html [ Pass Failure ]
 imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-candidate-in-sdp.https.html [ Pass Failure ]
+imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare.https.html [ Pass Failure ]
+imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare-linear.https.html [ Pass Failure ]
 
 # Skip timing out test
 imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-setRemoteDescription-tracks.https.html [ Skip ]

Modified: trunk/LayoutTests/fast/mediastream/RTCPeerConnection-addIceCandidate-expected.txt (281980 => 281981)


--- trunk/LayoutTests/fast/mediastream/RTCPeerConnection-addIceCandidate-expected.txt	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/LayoutTests/fast/mediastream/RTCPeerConnection-addIceCandidate-expected.txt	2021-09-03 09:40:55 UTC (rev 281981)
@@ -13,10 +13,10 @@
 PASS sdpMLineIndex is not badSdpMLineIndex
 PASS sdpMid is not null
 PASS sdpMid is not badSdpMid
-FAIL promise pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: badSdpMid})) fulfilled unexpectedly.
-FAIL promise pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMLineIndex: badSdpMLineIndex})) fulfilled unexpectedly.
+PASS promise pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: badSdpMid})) rejected with OperationError: Error processing ICE candidate
+PASS promise pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMLineIndex: badSdpMLineIndex})) rejected with OperationError: Error processing ICE candidate
 *** A (bad) sdpMid takes precedesce over valid sdpMLineIndex
-FAIL promise pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: badSdpMid, sdpMLineIndex: sdpMLineIndex})) fulfilled unexpectedly.
+PASS promise pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: badSdpMid, sdpMLineIndex: sdpMLineIndex})) rejected with OperationError: Error processing ICE candidate
 *** Test bad candidate content with valid sdpMid
 PASS promise pc.addIceCandidate(new RTCIceCandidate({candidate: 'bad content', sdpMid: sdpMid})) rejected with OperationError: Expect line: candidate:<candidate-str>
 *** Test bad candidate content with valid sdpMLineIndex
@@ -25,13 +25,12 @@
 PASS promise pc.addIceCandidate({candidate: validCandidate}) rejected with TypeError: Candidate must not have both null sdpMid and sdpMLineIndex
 
 *** Test some OK input
-PASS promise pc.addIceCandidate({candidate: validCandidate, sdpMid: sdpMid}) fulfilled with undefined
+PASS promise pc.addIceCandidate({candidate: validCandidate, sdpMid: sdpMid}) rejected with OperationError: Error processing ICE candidate
 PASS promise pc.addIceCandidate({candidate: validCandidate, sdpMLineIndex: sdpMLineIndex}) fulfilled with undefined
 PASS promise pc.addIceCandidate(undefined) fulfilled with undefined
 PASS promise pc.addIceCandidate(null) fulfilled with undefined
 PASS promise pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMLineIndex: sdpMLineIndex})) fulfilled with undefined
-*** A valid sdpMid takes precedesce over a bad sdpMLineIndex
-PASS promise pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: sdpMid, sdpMLineIndex: badSdpMLineIndex})) fulfilled with undefined
+PASS promise pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: sdpMid, sdpMLineIndex: badSdpMLineIndex})) rejected with OperationError: Error processing ICE candidate
 PASS End of test promise chain
 PASS successfullyParsed is true
 

Modified: trunk/LayoutTests/fast/mediastream/RTCPeerConnection-addIceCandidate.html (281980 => 281981)


--- trunk/LayoutTests/fast/mediastream/RTCPeerConnection-addIceCandidate.html	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/LayoutTests/fast/mediastream/RTCPeerConnection-addIceCandidate.html	2021-09-03 09:40:55 UTC (rev 281981)
@@ -81,7 +81,7 @@
             .then(function () {
                 debug("<br>*** Test some OK input");
                 // Testing passing a RTCIceCandidateInit
-                return promiseShouldResolve("pc.addIceCandidate({candidate: validCandidate, sdpMid: sdpMid})");
+                return promiseShouldReject("pc.addIceCandidate({candidate: validCandidate, sdpMid: sdpMid})");
             })
             .then(function () {
                 return promiseShouldResolve("pc.addIceCandidate({candidate: validCandidate, sdpMLineIndex: sdpMLineIndex})");
@@ -97,8 +97,7 @@
                 return promiseShouldResolve("pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMLineIndex: sdpMLineIndex}))");
             })
             .then(function () {
-                debug("*** A valid sdpMid takes precedesce over a bad sdpMLineIndex");
-                return promiseShouldResolve("pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: sdpMid, sdpMLineIndex: badSdpMLineIndex}))");
+                return promiseShouldReject("pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: sdpMid, sdpMLineIndex: badSdpMLineIndex}))");
             })
             .then(function () {
                 testPassed("End of test promise chain");

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (281980 => 281981)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-09-03 09:40:55 UTC (rev 281981)
@@ -1,3 +1,15 @@
+2021-09-03  Youenn Fablet  <you...@apple.com>
+
+        Migrate to latest libwebrtc AddIceCandidate
+        https://bugs.webkit.org/show_bug.cgi?id=229700
+
+        Reviewed by Eric Carlson.
+
+        * web-platform-tests/webrtc/RTCPeerConnection-addIceCandidate-expected.txt:
+        * web-platform-tests/webrtc/RTCPeerConnection-operations.https-expected.txt:
+        * web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare-linear.https-expected.txt:
+        * web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare.https-expected.txt:
+
 2021-09-02  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         The CSS Font Loading API shouldn't be able to delete a CSS-connected font

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-addIceCandidate-expected.txt (281980 => 281981)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-addIceCandidate-expected.txt	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-addIceCandidate-expected.txt	2021-09-03 09:40:55 UTC (rev 281981)
@@ -1,5 +1,5 @@
 
-FAIL Add ICE candidate before setting remote description should reject with InvalidStateError assert_unreached: Should have rejected: undefined Reached unreachable code
+FAIL Add ICE candidate before setting remote description should reject with InvalidStateError promise_rejects_dom: function "function () { throw e }" threw object "OperationError: Error processing ICE candidate" that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
 FAIL addIceCandidate({"candidate":"","sdpMid":null,"sdpMLineIndex":null}) should work, and add a=end-of-candidates to both m-sections assert_true: Expect candidate line to be found between media lines m=audio and m=video expected true got false
 FAIL addIceCandidate(undefined) should work, and add a=end-of-candidates to both m-sections assert_true: Expect candidate line to be found between media lines m=audio and m=video expected true got false
 FAIL addIceCandidate(null) should work, and add a=end-of-candidates to both m-sections assert_true: Expect candidate line to be found between media lines m=audio and m=video expected true got false
@@ -8,23 +8,23 @@
 FAIL addIceCandidate({usernameFragment: usernameFragment1, sdpMid: sdpMid1}) should work, and add a=end-of-candidates to the first m-section assert_true: Expect candidate line to be found between media lines m=audio and m=video expected true got false
 FAIL addIceCandidate({usernameFragment: usernameFragment2, sdpMLineIndex: 1}) should work, and add a=end-of-candidates to the first m-section assert_true: expected true got false
 FAIL addIceCandidate({usernameFragment: "no such ufrag"}) should not work assert_unreached: Should have rejected: undefined Reached unreachable code
-FAIL Add ICE candidate after setting remote description should succeed assert_true: Expect candidate line to be found after media line m=audio expected true got false
+PASS Add ICE candidate after setting remote description should succeed
 PASS Add ICE candidate with RTCIceCandidate should succeed
 PASS Add candidate with only valid sdpMid should succeed
 PASS Add candidate with only valid sdpMid and RTCIceCandidate should succeed
 PASS Add candidate with only valid sdpMLineIndex should succeed
-FAIL addIceCandidate with first sdpMid and sdpMLineIndex add candidate to first media stream assert_true: Expect candidate line to be found between media lines m=audio and m=video expected true got false
-FAIL addIceCandidate with second sdpMid and sdpMLineIndex should add candidate to second media stream assert_true: Expect candidate line to be found after media line m=video expected true got false
-FAIL Add candidate for first media stream with null usernameFragment should add candidate to first media stream assert_true: Expect candidate line to be found between media lines m=audio and m=video expected true got false
-FAIL Adding multiple candidates should add candidates to their corresponding media stream assert_true: Expect candidate line to be found between media lines m=audio and m=video expected true got false
+PASS addIceCandidate with first sdpMid and sdpMLineIndex add candidate to first media stream
+PASS addIceCandidate with second sdpMid and sdpMLineIndex should add candidate to second media stream
+PASS Add candidate for first media stream with null usernameFragment should add candidate to first media stream
+PASS Adding multiple candidates should add candidates to their corresponding media stream
 FAIL Add with empty candidate string (end of candidate) should succeed assert_true: Expect candidate line to be found between media lines m=audio and m=video expected true got false
 PASS Add candidate with both sdpMid and sdpMLineIndex manually set to null should reject with TypeError
 PASS Add candidate with only valid candidate string should reject with TypeError
 PASS Add candidate with invalid candidate string and both sdpMid and sdpMLineIndex null should reject with TypeError
-FAIL Add candidate with invalid sdpMid should reject with OperationError assert_unreached: Should have rejected: undefined Reached unreachable code
-FAIL Add candidate with invalid sdpMLineIndex should reject with OperationError assert_unreached: Should have rejected: undefined Reached unreachable code
+PASS Add candidate with invalid sdpMid should reject with OperationError
+PASS Add candidate with invalid sdpMLineIndex should reject with OperationError
 PASS Invalid sdpMLineIndex should be ignored if valid sdpMid is provided
-FAIL Add candidate for media stream 2 with null usernameFragment should succeed assert_true: Expect candidate line to be found after media line m=video expected true got false
+PASS Add candidate for media stream 2 with null usernameFragment should succeed
 FAIL Add candidate with invalid usernameFragment should reject with OperationError assert_unreached: Should have rejected: undefined Reached unreachable code
 PASS Add candidate with invalid candidate string should reject with OperationError
 FAIL Add candidate with sdpMid belonging to different usernameFragment should reject with OperationError assert_unreached: Should have rejected: undefined Reached unreachable code

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-operations.https-expected.txt (281980 => 281981)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-operations.https-expected.txt	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-operations.https-expected.txt	2021-09-03 09:40:55 UTC (rev 281981)
@@ -25,7 +25,7 @@
 PASS pc.getStats does NOT use the operations chain
 PASS sender.getStats does NOT use the operations chain
 PASS receiver.getStats does NOT use the operations chain
-FAIL addIceCandidate chains onto SRD, fails before assert_equals: expected "InvalidStateError" but got "Error"
+FAIL addIceCandidate chains onto SRD, fails before assert_equals: expected "InvalidStateError" but got "OperationError"
 FAIL Operations queue not vulnerable to recursion by chained negotiationneeded promise_test: Unhandled rejection with value: object "InvalidStateError: Remote description type 0 is incompatible with current signaling state 1"
 FAIL Pack operations queue with implicit offer and answer promise_test: Unhandled rejection with value: object "OperationError: Expect line: v="
 TIMEOUT Negotiate solely by operations queue and signaling state Test timed out

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare-linear.https-expected.txt (281980 => 281981)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare-linear.https-expected.txt	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare-linear.https-expected.txt	2021-09-03 09:40:55 UTC (rev 281981)
@@ -1,4 +1,6 @@
 
-FAIL Perfect negotiation stress glare linear Remote description type 0 is incompatible with current signaling state 1
-FAIL Perfect negotiation stress glare linear with roles reversed assert_unreached: Error in iframe: InvalidStateError: Remote description type 0 is incompatible with current signaling state 1 Reached unreachable code
+Harness Error (FAIL), message = Unhandled rejection: null is not an object (evaluating 'target.postMessage')
 
+FAIL Perfect negotiation stress glare linear Error processing ICE candidate
+FAIL Perfect negotiation stress glare linear with roles reversed assert_unreached: Error in iframe: OperationError: Error processing ICE candidate Reached unreachable code
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare.https-expected.txt (281980 => 281981)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare.https-expected.txt	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare.https-expected.txt	2021-09-03 09:40:55 UTC (rev 281981)
@@ -1,4 +1,4 @@
 
-FAIL Perfect negotiation stress glare Remote description type 0 is incompatible with current signaling state 1
-FAIL Perfect negotiation stress glare with roles reversed assert_unreached: Error in iframe: InvalidStateError: Remote description type 0 is incompatible with current signaling state 1 Reached unreachable code
+FAIL Perfect negotiation stress glare Error processing ICE candidate
+FAIL Perfect negotiation stress glare with roles reversed assert_unreached: Error in iframe: OperationError: Error processing ICE candidate Reached unreachable code
 

Modified: trunk/Source/WebCore/ChangeLog (281980 => 281981)


--- trunk/Source/WebCore/ChangeLog	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/Source/WebCore/ChangeLog	2021-09-03 09:40:55 UTC (rev 281981)
@@ -1,3 +1,32 @@
+2021-09-03  Youenn Fablet  <you...@apple.com>
+
+        Migrate to latest libwebrtc AddIceCandidate
+        https://bugs.webkit.org/show_bug.cgi?id=229700
+
+        Reviewed by Eric Carlson.
+
+        AddIceCandidate can now take a callback to return a RTCError which provides necessary information to reject the promise as needed.
+        Update binding code accordingly.
+        This allows to use a lambda that takes the promise instead of having the promise as a member of PeerConnectionBackend.
+        Covered by updated and rebased tests.
+
+        * Modules/mediastream/PeerConnectionBackend.cpp:
+        (WebCore::PeerConnectionBackend::addIceCandidate):
+        (WebCore::PeerConnectionBackend::stop):
+        (WebCore::PeerConnectionBackend::addIceCandidateSucceeded): Deleted.
+        (WebCore::PeerConnectionBackend::addIceCandidateFailed): Deleted.
+        * Modules/mediastream/PeerConnectionBackend.h:
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::LibWebRTCMediaEndpoint::addIceCandidate):
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
+        (WebCore::LibWebRTCMediaEndpoint::addIceCandidate): Deleted.
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
+        (WebCore::LibWebRTCPeerConnectionBackend::doSetLocalDescription):
+        (WebCore::LibWebRTCPeerConnectionBackend::doSetRemoteDescription):
+        (WebCore::LibWebRTCPeerConnectionBackend::doAddIceCandidate):
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
+        * testing/MockLibWebRTCPeerConnection.h:
+
 2021-09-03  Said Abou-Hallawa  <s...@apple.com>
 
         Add a layout test to detect memory leaks when drawing images to a detached canvas

Modified: trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp (281980 => 281981)


--- trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp	2021-09-03 09:40:55 UTC (rev 281981)
@@ -348,38 +348,15 @@
         return;
     }
 
-    m_addIceCandidatePromise = WTF::makeUnique<DOMPromiseDeferred<void>>(WTFMove(promise));
-    doAddIceCandidate(*iceCandidate);
-}
-
-void PeerConnectionBackend::addIceCandidateSucceeded()
-{
-    ASSERT(isMainThread());
-    ALWAYS_LOG(LOGIDENTIFIER, "Adding ice candidate succeeded");
-
-    ASSERT(m_addIceCandidatePromise);
-    m_peerConnection.doTask([this, promise = WTFMove(m_addIceCandidatePromise)]() mutable {
-        if (m_peerConnection.isClosed())
+    doAddIceCandidate(*iceCandidate, [weakThis = makeWeakPtr(this), promise = WTFMove(promise)](auto&& result) mutable {
+        ASSERT(isMainThread());
+        if (!weakThis)
             return;
-
-        promise->resolve();
+        RELEASE_LOG_ERROR(WebRTC, "Adding ice candidate finished, success=%d", result.hasException());
+        promise.settle(WTFMove(result));
     });
 }
 
-void PeerConnectionBackend::addIceCandidateFailed(Exception&& exception)
-{
-    ASSERT(isMainThread());
-    ALWAYS_LOG(LOGIDENTIFIER, "Adding ice candidate failed:", exception.message());
-
-    ASSERT(m_addIceCandidatePromise);
-    m_peerConnection.doTask([this, promise = WTFMove(m_addIceCandidatePromise), exception = WTFMove(exception)]() mutable {
-        if (m_peerConnection.isClosed())
-            return;
-
-        promise->reject(WTFMove(exception));
-    });
-}
-
 void PeerConnectionBackend::fireICECandidateEvent(RefPtr<RTCIceCandidate>&& candidate, String&& serverURL)
 {
     ASSERT(isMainThread());
@@ -570,7 +547,6 @@
 {
     m_offerAnswerPromise = nullptr;
     m_setDescriptionPromise = nullptr;
-    m_addIceCandidatePromise = nullptr;
 
     m_pendingTrackEvents.clear();
 

Modified: trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h (281980 => 281981)


--- trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.h	2021-09-03 09:40:55 UTC (rev 281981)
@@ -222,7 +222,7 @@
     virtual void doCreateAnswer(RTCAnswerOptions&&) = 0;
     virtual void doSetLocalDescription(const RTCSessionDescription*) = 0;
     virtual void doSetRemoteDescription(const RTCSessionDescription&) = 0;
-    virtual void doAddIceCandidate(RTCIceCandidate&) = 0;
+    virtual void doAddIceCandidate(RTCIceCandidate&, Function<void(ExceptionOr<void>&&)>&&) = 0;
     virtual void endOfIceCandidates(DOMPromiseDeferred<void>&&);
     virtual void doStop() = 0;
 
@@ -234,7 +234,6 @@
 private:
     std::unique_ptr<PeerConnection::SessionDescriptionPromise> m_offerAnswerPromise;
     std::unique_ptr<DOMPromiseDeferred<void>> m_setDescriptionPromise;
-    std::unique_ptr<DOMPromiseDeferred<void>> m_addIceCandidatePromise;
 
     bool m_shouldFilterICECandidates { true };
     struct PendingICECandidate {

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


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp	2021-09-03 09:40:55 UTC (rev 281981)
@@ -619,6 +619,11 @@
     });
 }
 
+void LibWebRTCMediaEndpoint::addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&& candidate, std::function<void(webrtc::RTCError)>&& callback)
+{
+    m_backend->AddIceCandidate(WTFMove(candidate), WTFMove(callback));
+}
+
 void LibWebRTCMediaEndpoint::OnIceCandidate(const webrtc::IceCandidateInterface *rtcCandidate)
 {
     ASSERT(rtcCandidate);

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


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h	2021-09-03 09:40:55 UTC (rev 281981)
@@ -89,7 +89,7 @@
     void getStats(webrtc::RtpReceiverInterface&, Ref<DeferredPromise>&&);
     void getStats(webrtc::RtpSenderInterface&, Ref<DeferredPromise>&&);
     std::unique_ptr<RTCDataChannelHandler> createDataChannel(const String&, const RTCDataChannelInit&);
-    bool addIceCandidate(webrtc::IceCandidateInterface& candidate) { return m_backend->AddIceCandidate(&candidate); }
+    void addIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>&&, std::function<void(webrtc::RTCError)>&&);
 
     void close();
     void stop();

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


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp	2021-09-03 09:40:55 UTC (rev 281981)
@@ -47,6 +47,7 @@
 #include "RealtimeOutgoingAudioSource.h"
 #include "RealtimeOutgoingVideoSource.h"
 #include "Settings.h"
+#include <wtf/SharedTask.h>
 
 namespace WebCore {
 
@@ -235,26 +236,13 @@
 void LibWebRTCPeerConnectionBackend::doSetLocalDescription(const RTCSessionDescription* description)
 {
     m_endpoint->doSetLocalDescription(description);
-    if (!m_isLocalDescriptionSet) {
-        if (m_isRemoteDescriptionSet) {
-            for (auto& candidate : m_pendingCandidates)
-                m_endpoint->addIceCandidate(*candidate);
-            m_pendingCandidates.clear();
-        }
-        m_isLocalDescriptionSet = true;
-    }
+    m_isLocalDescriptionSet = true;
 }
 
 void LibWebRTCPeerConnectionBackend::doSetRemoteDescription(const RTCSessionDescription& description)
 {
     m_endpoint->doSetRemoteDescription(description);
-    if (!m_isRemoteDescriptionSet) {
-        if (m_isLocalDescriptionSet) {
-            for (auto& candidate : m_pendingCandidates)
-                m_endpoint->addIceCandidate(*candidate);
-        }
-        m_isRemoteDescriptionSet = true;
-    }
+    m_isRemoteDescriptionSet = true;
 }
 
 void LibWebRTCPeerConnectionBackend::doCreateOffer(RTCOfferOptions&& options)
@@ -282,7 +270,7 @@
     m_pendingReceivers.clear();
 }
 
-void LibWebRTCPeerConnectionBackend::doAddIceCandidate(RTCIceCandidate& candidate)
+void LibWebRTCPeerConnectionBackend::doAddIceCandidate(RTCIceCandidate& candidate, Function<void(ExceptionOr<void>&&)>&& callback)
 {
     webrtc::SdpParseError error;
     int sdpMLineIndex = candidate.sdpMLineIndex() ? candidate.sdpMLineIndex().value() : 0;
@@ -289,19 +277,19 @@
     std::unique_ptr<webrtc::IceCandidateInterface> rtcCandidate(webrtc::CreateIceCandidate(candidate.sdpMid().utf8().data(), sdpMLineIndex, candidate.candidate().utf8().data(), &error));
 
     if (!rtcCandidate) {
-        addIceCandidateFailed(Exception { OperationError, String::fromUTF8(error.description.data(), error.description.length()) });
+        callback(Exception { OperationError, String::fromUTF8(error.description.data(), error.description.length()) });
         return;
     }
 
-    // libwebrtc does not like that ice candidates are set before the description.
-    if (!m_isLocalDescriptionSet || !m_isRemoteDescriptionSet)
-        m_pendingCandidates.append(WTFMove(rtcCandidate));
-    else if (!m_endpoint->addIceCandidate(*rtcCandidate.get())) {
-        ASSERT_NOT_REACHED();
-        addIceCandidateFailed(Exception { OperationError, "Failed to apply the received candidate"_s });
-        return;
-    }
-    addIceCandidateSucceeded();
+    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({ });
+        });
+    });
 }
 
 Ref<RTCRtpReceiver> LibWebRTCPeerConnectionBackend::createReceiver(std::unique_ptr<LibWebRTCRtpReceiverBackend>&& backend)

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


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h	2021-09-03 09:40:55 UTC (rev 281981)
@@ -62,7 +62,7 @@
     void doCreateAnswer(RTCAnswerOptions&&) final;
     void doSetLocalDescription(const RTCSessionDescription*) final;
     void doSetRemoteDescription(const RTCSessionDescription&) final;
-    void doAddIceCandidate(RTCIceCandidate&) final;
+    void doAddIceCandidate(RTCIceCandidate&, Function<void(ExceptionOr<void>&&)>&&) final;
     void doStop() final;
     std::unique_ptr<RTCDataChannelHandler> createDataChannelHandler(const String&, const RTCDataChannelInit&) final;
     void restartIce() final;

Modified: trunk/Source/WebCore/testing/MockLibWebRTCPeerConnection.h (281980 => 281981)


--- trunk/Source/WebCore/testing/MockLibWebRTCPeerConnection.h	2021-09-03 08:25:03 UTC (rev 281980)
+++ trunk/Source/WebCore/testing/MockLibWebRTCPeerConnection.h	2021-09-03 09:40:55 UTC (rev 281981)
@@ -285,6 +285,7 @@
     const webrtc::SessionDescriptionInterface* local_description() const override { return nullptr; }
     const webrtc::SessionDescriptionInterface* remote_description() const override { return nullptr; }
     bool AddIceCandidate(const webrtc::IceCandidateInterface*) override { return true; }
+    void AddIceCandidate(std::unique_ptr<webrtc::IceCandidateInterface>, std::function<void(webrtc::RTCError)> callback) override { callback({ }); }
     SignalingState signaling_state() override { return kStable; }
     IceConnectionState ice_connection_state() override { return kIceConnectionNew; }
     IceGatheringState ice_gathering_state() override { return kIceGatheringNew; }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to