webrtcbin: Clean up bin elements when datachannel is removed
authorEmil Ljungdahl <emillj@axis.com>
Mon, 14 Oct 2024 09:26:20 +0000 (11:26 +0200)
committerBackport Bot <gitlab-backport-bot@gstreamer-foundation.org>
Wed, 30 Oct 2024 13:48:01 +0000 (13:48 +0000)
When a datachannel within a session is removed after proper close,
reference to the error_ignore_bin elements of the datachannel
appsrc/appsink were left in webrtcbin.

This caused the bin-objects to be left and not freed until the whole
webrtc session was terminated. Among other things that includes a thread
from the appsrc.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7791>

subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c

index 21ecd8b58849249b122082643b289acc99d151cc..f170f512bf6756b9a2413df483b3e01876521974 100644 (file)
@@ -2585,8 +2585,18 @@ _on_data_channel_ready_state (WebRTCDataChannel * channel,
 
     if (found == FALSE) {
       GST_FIXME_OBJECT (webrtc, "Received close for unknown data channel");
-    } else if (found_pending == FALSE) {
-      webrtc->priv->data_channels_closed++;
+    } else {
+      gst_element_set_locked_state (channel->src_bin, TRUE);
+      gst_element_set_state (channel->src_bin, GST_STATE_NULL);
+      gst_bin_remove (GST_BIN (webrtc), channel->src_bin);
+
+      gst_element_set_locked_state (channel->sink_bin, TRUE);
+      gst_element_set_state (channel->sink_bin, GST_STATE_NULL);
+      gst_bin_remove (GST_BIN (webrtc), channel->sink_bin);
+
+      if (found_pending == FALSE) {
+        webrtc->priv->data_channels_closed++;
+      }
     }
     DC_UNLOCK (webrtc);
   }