Title: [287067] trunk
Revision
287067
Author
you...@apple.com
Date
2021-12-15 01:36:17 -0800 (Wed, 15 Dec 2021)

Log Message

Make sure to start a realtime outgoing source in case it is taken to another sender
https://bugs.webkit.org/show_bug.cgi?id=234296
<rdar://86276497>

Reviewed by Eric Carlson.

Source/WebCore:

We are asynchronously starting libwebrtc sources.
When a sender is created first and is assigned a source later, we take the source and assign it to the sender.
In that case, the source might not be started and we will not send any data.

Test: webrtc/addTransceiver-then-addTrack.html

* Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp:

LayoutTests:

* webrtc/addTransceiver-then-addTrack-expected.txt: Added.
* webrtc/addTransceiver-then-addTrack.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (287066 => 287067)


--- trunk/LayoutTests/ChangeLog	2021-12-15 09:16:02 UTC (rev 287066)
+++ trunk/LayoutTests/ChangeLog	2021-12-15 09:36:17 UTC (rev 287067)
@@ -1,3 +1,14 @@
+2021-12-15  Youenn Fablet  <you...@apple.com>
+
+        Make sure to start a realtime outgoing source in case it is taken to another sender
+        https://bugs.webkit.org/show_bug.cgi?id=234296
+        <rdar://86276497>
+
+        Reviewed by Eric Carlson.
+
+        * webrtc/addTransceiver-then-addTrack-expected.txt: Added.
+        * webrtc/addTransceiver-then-addTrack.html: Added.
+
 2021-12-14  Joonghun Park  <jh718.p...@samsung.com>
 
         Fix that height is calculated incorrectly when using display:table, box-sizing:border-box and padding.

Added: trunk/LayoutTests/webrtc/addTransceiver-then-addTrack-expected.txt (0 => 287067)


--- trunk/LayoutTests/webrtc/addTransceiver-then-addTrack-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webrtc/addTransceiver-then-addTrack-expected.txt	2021-12-15 09:36:17 UTC (rev 287067)
@@ -0,0 +1,4 @@
+
+
+PASS Ensure addTrack reuses transceiver as expected
+

Added: trunk/LayoutTests/webrtc/addTransceiver-then-addTrack.html (0 => 287067)


--- trunk/LayoutTests/webrtc/addTransceiver-then-addTrack.html	                        (rev 0)
+++ trunk/LayoutTests/webrtc/addTransceiver-then-addTrack.html	2021-12-15 09:36:17 UTC (rev 287067)
@@ -0,0 +1,106 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <video id="video" autoplay=""></video>
+        <canvas id="canvas" width="640" height="480"></canvas>
+        <script src =""
+        <script>
+function getStatsType(connection)
+{
+    return connection.getStats().then((report) => {
+        var reportTypes = [];
+        report.forEach((statItem) => {
+            if (reportTypes.indexOf(statItem.type) === -1)
+                reportTypes.push(statItem.type);
+        });
+        return reportTypes.sort();
+    });
+}
+
+function getAudioOutboundRTPStats(connection)
+{
+    return connection.getStats().then((report) => {
+        let stats;
+        report.forEach((statItem) => {
+            if (statItem.type === "outbound-rtp" && !("framesSent" in statItem))
+                stats = statItem;
+        });
+        return stats;
+    });
+}
+
+function getVideoOutboundRTPStats(connection)
+{
+    return connection.getStats().then((report) => {
+        let stats;
+        report.forEach((statItem) => {
+            if (statItem.type === "outbound-rtp" && "framesSent" in statItem)
+                stats = statItem;
+        });
+        return stats;
+    });
+}
+
+async function validateVideoIsEncoded(connection)
+{
+    let counter = 0;
+    for (counter = 0; counter < 50; ++counter) {
+        const stats = await getVideoOutboundRTPStats(connection);
+        if (stats.framesSent)
+           return true;
+        await new Promise(resolve => setTimeout(resolve, 50));
+    }
+    return false;
+}
+
+async function validateAudioIsEncoded(connection)
+{
+    let counter = 0;
+    for (counter = 0; counter < 50; ++counter) {
+        const stats = await getAudioOutboundRTPStats(connection);
+        if (stats.bytesSent)
+           return true;
+        await new Promise(resolve => setTimeout(resolve, 50));
+    }
+    return false;
+}
+
+var pc1, pc2;
+promise_test(async (test) => {
+    if (window.testRunner)
+        testRunner.setUserMediaPermission(true);
+
+    const localStream = await navigator.mediaDevices.getUserMedia({video: true, audio: true });
+    const stream = await new Promise((resolve, reject) => {
+        createConnections((firstConnection) => {
+            pc1 = firstConnection;
+            firstConnection.addTransceiver("audio");
+            const senderAudio = firstConnection.addTrack(localStream.getAudioTracks()[0]);
+            senderAudio.setStreams(localStream);
+            firstConnection.addTransceiver("video");
+            const senderVideo = firstConnection.addTrack(localStream.getVideoTracks()[0]);
+            senderVideo.setStreams(localStream);
+        }, (secondConnection) => {
+            pc2 = secondConnection;
+            secondConnection._ontrack_ = (trackEvent) => {
+                resolve(trackEvent.streams[0]);
+            };
+        });
+        setTimeout(() => reject("Test timed out"), 5000);
+    });
+
+    assert_equals(stream.getTracks().length, 2);
+    video.srcObject = stream;
+    await video.play();
+
+    assert_true(await validateAudioIsEncoded(pc1), "audio encoded");
+    assert_true(await validateVideoIsEncoded(pc1), "video encoded");
+}, "Ensure addTrack reuses transceiver as expected");
+        </script>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (287066 => 287067)


--- trunk/Source/WebCore/ChangeLog	2021-12-15 09:16:02 UTC (rev 287066)
+++ trunk/Source/WebCore/ChangeLog	2021-12-15 09:36:17 UTC (rev 287067)
@@ -1,3 +1,19 @@
+2021-12-15  Youenn Fablet  <you...@apple.com>
+
+        Make sure to start a realtime outgoing source in case it is taken to another sender
+        https://bugs.webkit.org/show_bug.cgi?id=234296
+        <rdar://86276497>
+
+        Reviewed by Eric Carlson.
+
+        We are asynchronously starting libwebrtc sources.
+        When a sender is created first and is assigned a source later, we take the source and assign it to the sender.
+        In that case, the source might not be started and we will not send any data.
+
+        Test: webrtc/addTransceiver-then-addTrack.html
+
+        * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp:
+
 2021-12-15  Antoine Quint  <grao...@webkit.org>
 
         ActiveDOMObject::suspendIfNeeded() should not be called within constructors

Modified: trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp (287066 => 287067)


--- trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp	2021-12-15 09:16:02 UTC (rev 287066)
+++ trunk/Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.cpp	2021-12-15 09:36:17 UTC (rev 287067)
@@ -190,7 +190,7 @@
 void LibWebRTCRtpSenderBackend::setSource(Source&& source)
 {
     stopSource();
-    m_source = WTFMove(source);
+    m_source = std::exchange(source, nullptr);
     startSource();
 }
 
@@ -197,9 +197,7 @@
 void LibWebRTCRtpSenderBackend::takeSource(LibWebRTCRtpSenderBackend& backend)
 {
     ASSERT(backend.hasSource());
-    stopSource();
-    m_source = WTFMove(backend.m_source);
-    backend.m_source = nullptr;
+    setSource(WTFMove(backend.m_source));
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to