A sender created through addTransceiver and populated using addTrack should have...
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2018 06:22:21 +0000 (06:22 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2018 06:22:21 +0000 (06:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192136

Reviewed by Eric Carlson.

Source/WebCore:

In case libwebrtc backend is already created, we need to make sure to
set the track source to the libwebrtc sender backend that is actually
tied to the sender.

Covered by updated test.

* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::removeTrack):
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::addTrack):
* Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h:

LayoutTests:

* webrtc/video-replace-track-expected.txt:
* webrtc/video-replace-track.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238845 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webrtc/video-replace-track-expected.txt
LayoutTests/webrtc/video-replace-track.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h

index 07a59ba..5967872 100644 (file)
@@ -1,3 +1,13 @@
+2018-12-03  Youenn Fablet  <youenn@apple.com>
+
+        A sender created through addTransceiver and populated using addTrack should have its source set
+        https://bugs.webkit.org/show_bug.cgi?id=192136
+
+        Reviewed by Eric Carlson.
+
+        * webrtc/video-replace-track-expected.txt:
+        * webrtc/video-replace-track.html:
+
 2018-12-03  YUHAN WU  <yuhan_wu@apple.com>
 
         Implement non-timeslice mode encoding for MediaRecorder
index 6758221..3487723 100644 (file)
@@ -2,4 +2,5 @@
 PASS Switching from front to back camera 
 PASS Switching from front to back camera, with lower resolution 
 PASS Switching from front to back camera, with higher resolution 
+PASS Replace a track for a sender created by addTransceiver and used by addTrack 
 
index e52c719..a62aed7 100644 (file)
@@ -181,6 +181,14 @@ promise_test((test) => {
     });
 
 }, "Switching from front to back camera, with higher resolution");
+
+promise_test(async (test) => {
+    const stream = await navigator.mediaDevices.getUserMedia({ video: true });
+    const pc = new RTCPeerConnection();
+    pc.addTransceiver("video", {direction: "sendonly"});
+    const sender = pc.addTrack(stream.getVideoTracks()[0], stream);
+    await sender.replaceTrack(stream.getVideoTracks()[0].clone());
+}, "Replace a track for a sender created by addTransceiver and used by addTrack");
         </script>
     </body>
 </html>
index a0341c5..79648b5 100644 (file)
@@ -1,3 +1,22 @@
+2018-12-03  Youenn Fablet  <youenn@apple.com>
+
+        A sender created through addTransceiver and populated using addTrack should have its source set
+        https://bugs.webkit.org/show_bug.cgi?id=192136
+
+        Reviewed by Eric Carlson.
+
+        In case libwebrtc backend is already created, we need to make sure to
+        set the track source to the libwebrtc sender backend that is actually
+        tied to the sender.
+
+        Covered by updated test.
+
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::LibWebRTCPeerConnectionBackend::removeTrack):
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
+        (WebCore::LibWebRTCPeerConnectionBackend::addTrack):
+        * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h:
+
 2018-12-03  YUHAN WU  <yuhan_wu@apple.com>
 
         Implement non-timeslice mode encoding for MediaRecorder
index 3acb25c..291ca8e 100644 (file)
@@ -255,6 +255,7 @@ void LibWebRTCMediaEndpoint::removeTrack(LibWebRTCRtpSenderBackend& sender)
 {
     ASSERT(m_backend);
     m_backend->RemoveTrack(sender.rtcSender());
+    sender.clearSource();
 }
 
 void LibWebRTCMediaEndpoint::doCreateOffer(const RTCOfferOptions& options)
index 1a93264..0b408d1 100644 (file)
@@ -403,6 +403,7 @@ ExceptionOr<Ref<RTCRtpSender>> LibWebRTCPeerConnectionBackend::addTrack(MediaStr
             return Exception { TypeError, "Unable to add track"_s };
 
         if (auto sender = findExistingSender(m_peerConnection.currentSenders(), *senderBackend)) {
+            backendFromRTPSender(*sender).takeSource(*senderBackend);
             sender->setTrack(makeRef(track));
             sender->setMediaStreamIds(WTFMove(mediaStreamIds));
             return sender.releaseNonNull();
index 8c9ea61..ad568d0 100644 (file)
@@ -87,6 +87,12 @@ public:
         );
     }
 
+    void clearSource()
+    {
+        ASSERT(hasSource());
+        m_source = nullptr;
+    }
+
     void setSource(Source&& source)
     {
         ASSERT(!hasSource());
@@ -94,6 +100,12 @@ public:
         ASSERT(hasSource());
     }
 
+    void takeSource(LibWebRTCRtpSenderBackend& backend)
+    {
+        ASSERT(backend.hasSource());
+        setSource(WTFMove(backend.m_source));
+    }
+
 private:
     void replaceTrack(ScriptExecutionContext&, RTCRtpSender&, RefPtr<MediaStreamTrack>&&, DOMPromiseDeferred<void>&&) final;
     RTCRtpSendParameters getParameters() const final;