onnegotiationneeded should only be called once
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Apr 2017 16:38:58 +0000 (16:38 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Apr 2017 16:38:58 +0000 (16:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170785

Patch by Youenn Fablet <youenn@apple.com> on 2017-04-13
Reviewed by Alex Christensen.

Source/WebCore:

Covered by updated test.

Disabling explicit call to markAsNeedingNegotiation in case libwebrtc is used as libwebrtc is calling it.
Making sure removeTrack gets notified up to libwebrtc.

* Modules/mediastream/PeerConnectionBackend.h:
(WebCore::PeerConnectionBackend::notifyRemovedTrack):
* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::addTrack):
(WebCore::RTCPeerConnection::removeTrack):
(WebCore::RTCPeerConnection::completeAddTransceiver):
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
(WebCore::LibWebRTCMediaEndpoint::removeTrack):
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
(WebCore::LibWebRTCPeerConnectionBackend::notifyRemovedTrack):
* Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:

LayoutTests:

* webrtc/negotiatedneeded-event-addStream.html:

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

LayoutTests/ChangeLog
LayoutTests/webrtc/negotiatedneeded-event-addStream.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/PeerConnectionBackend.h
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp
Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h

index 11a5306..882bd04 100644 (file)
@@ -1,3 +1,12 @@
+2017-04-13  Youenn Fablet  <youenn@apple.com>
+
+        onnegotiationneeded should only be called once
+        https://bugs.webkit.org/show_bug.cgi?id=170785
+
+        Reviewed by Alex Christensen.
+
+        * webrtc/negotiatedneeded-event-addStream.html:
+
 2017-04-13  Dave Hyatt  <hyatt@apple.com>
 
         Rendering flexbox children across columns
index 534f85d..e2badc0 100644 (file)
@@ -19,7 +19,11 @@ promise_test((test) => {
     return navigator.mediaDevices.getUserMedia({ video: true}).then((stream) => {
         return new Promise((resolve, reject) => {
             var pc = new RTCPeerConnection();
-            pc.onnegotiationneeded = () => { resolve(); };
+            var count = 0;
+            pc.onnegotiationneeded = () => {
+                assert_equals(count++, 0, "Should only be called once");
+                setTimeout(resolve, 500);
+            };
             pc.addTrack(stream.getVideoTracks()[0], stream);
         });
     });
index 8a9843c..7b8e358 100644 (file)
@@ -1,3 +1,28 @@
+2017-04-13  Youenn Fablet  <youenn@apple.com>
+
+        onnegotiationneeded should only be called once
+        https://bugs.webkit.org/show_bug.cgi?id=170785
+
+        Reviewed by Alex Christensen.
+
+        Covered by updated test.
+
+        Disabling explicit call to markAsNeedingNegotiation in case libwebrtc is used as libwebrtc is calling it.
+        Making sure removeTrack gets notified up to libwebrtc.
+
+        * Modules/mediastream/PeerConnectionBackend.h:
+        (WebCore::PeerConnectionBackend::notifyRemovedTrack):
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::RTCPeerConnection::addTrack):
+        (WebCore::RTCPeerConnection::removeTrack):
+        (WebCore::RTCPeerConnection::completeAddTransceiver):
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
+        (WebCore::LibWebRTCMediaEndpoint::removeTrack):
+        * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.h:
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.cpp:
+        (WebCore::LibWebRTCPeerConnectionBackend::notifyRemovedTrack):
+        * Modules/mediastream/libwebrtc/LibWebRTCPeerConnectionBackend.h:
+
 2017-04-13  Dave Hyatt  <hyatt@apple.com>
 
         Rendering flexbox children across columns
index fedf113..555bfb8 100644 (file)
@@ -96,6 +96,7 @@ public:
     virtual Ref<RTCRtpReceiver> createReceiver(const String& transceiverMid, const String& trackKind, const String& trackId) = 0;
     virtual void replaceTrack(RTCRtpSender&, Ref<MediaStreamTrack>&&, DOMPromise<void>&&) = 0;
     virtual void notifyAddedTrack(RTCRtpSender&) { }
+    virtual void notifyRemovedTrack(RTCRtpSender&) { }
 
     virtual RTCRtpParameters getParameters(RTCRtpSender&) const { return { }; }
 
index 849b7a2..c7a8d57 100644 (file)
@@ -148,7 +148,9 @@ ExceptionOr<Ref<RTCRtpSender>> RTCPeerConnection::addTrack(Ref<MediaStreamTrack>
         m_transceiverSet->append(WTFMove(transceiver));
     }
 
+#if !USE(LIBWEBRTC)
     m_backend->markAsNeedingNegotiation();
+#endif
 
     m_backend->notifyAddedTrack(*sender);
     return Ref<RTCRtpSender> { *sender };
@@ -171,7 +173,10 @@ ExceptionOr<void> RTCPeerConnection::removeTrack(RTCRtpSender& sender)
 
     sender.stop();
 
+    m_backend->notifyRemovedTrack(sender);
+#if !USE(LIBWEBRTC)
     m_backend->markAsNeedingNegotiation();
+#endif
     return { };
 }
 
@@ -203,8 +208,9 @@ Ref<RTCRtpTransceiver> RTCPeerConnection::completeAddTransceiver(Ref<RTCRtpSende
     transceiver->setDirection(init.direction);
 
     m_transceiverSet->append(transceiver.copyRef());
+#if !USE(LIBWEBRTC)
     m_backend->markAsNeedingNegotiation();
-
+#endif
     return transceiver;
 }
 
index d2fde41..e33504e 100644 (file)
@@ -193,6 +193,14 @@ void LibWebRTCMediaEndpoint::addTrack(RTCRtpSender& sender, MediaStreamTrack& tr
     }
 }
 
+void LibWebRTCMediaEndpoint::removeTrack(RTCRtpSender& sender)
+{
+    auto rtcSender = m_senders.get(&sender);
+    if (!rtcSender)
+        return;
+    m_backend->RemoveTrack(rtcSender.get());
+}
+
 void LibWebRTCMediaEndpoint::doCreateOffer()
 {
     m_isInitiator = true;
index f568efb..71c05c9 100644 (file)
@@ -81,6 +81,7 @@ public:
     RefPtr<RTCSessionDescription> pendingRemoteDescription() const;
 
     void addTrack(RTCRtpSender&, MediaStreamTrack&, const Vector<String>&);
+    void removeTrack(RTCRtpSender&);
     RTCRtpParameters getRTCRtpSenderParameters(RTCRtpSender&);
 
 private:
index b6e8e51..bedf101 100644 (file)
@@ -311,6 +311,11 @@ void LibWebRTCPeerConnectionBackend::notifyAddedTrack(RTCRtpSender& sender)
     m_endpoint->addTrack(sender, *sender.track(), sender.mediaStreamIds());
 }
 
+void LibWebRTCPeerConnectionBackend::notifyRemovedTrack(RTCRtpSender& sender)
+{
+    m_endpoint->removeTrack(sender);
+}
+
 void LibWebRTCPeerConnectionBackend::removeRemoteStream(MediaStream* mediaStream)
 {
     m_remoteStreams.removeFirstMatching([mediaStream](const auto& item) {
index c3bbbb6..92e68a6 100644 (file)
@@ -87,6 +87,7 @@ private:
     void addRemoteStream(Ref<MediaStream>&&);
 
     void notifyAddedTrack(RTCRtpSender&) final;
+    void notifyRemovedTrack(RTCRtpSender&) final;
 
     struct VideoReceiver {
         Ref<RTCRtpReceiver> receiver;