From f28a7b6ef3c032276bac32a704dcba2eae722d70 Mon Sep 17 00:00:00 2001 From: Emil Ljungdahl Date: Mon, 18 Nov 2024 07:54:55 +0100 Subject: [PATCH] webrtcbin: Tear down src and sink bins before removing them from webrtc Part-of: --- .../gst-plugins-bad/ext/webrtc/gstwebrtcbin.c | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c b/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c index 8e3b9a90d7..3454db5ceb 100644 --- a/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c +++ b/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c @@ -2621,6 +2621,12 @@ _on_data_channel_ready_state (WebRTCDataChannel * channel, gboolean found_pending; gboolean found; + /* Change state on bins outside dc_lock to avoid deadlocks */ + gst_element_set_locked_state (channel->src_bin, TRUE); + gst_element_set_state (channel->src_bin, GST_STATE_NULL); + gst_element_set_locked_state (channel->sink_bin, TRUE); + gst_element_set_state (channel->sink_bin, GST_STATE_NULL); + DC_LOCK (webrtc); found_pending = g_ptr_array_remove (webrtc->priv->pending_data_channels, channel); @@ -2630,11 +2636,7 @@ _on_data_channel_ready_state (WebRTCDataChannel * channel, if (found == FALSE) { GST_FIXME_OBJECT (webrtc, "Received close for unknown data channel"); } else { - /* Take an extra ref to src & sink bins so that teardown can be made outside dc_lock */ - gst_object_ref (channel->src_bin); gst_bin_remove (GST_BIN (webrtc), channel->src_bin); - - gst_object_ref (channel->sink_bin); gst_bin_remove (GST_BIN (webrtc), channel->sink_bin); if (found_pending == FALSE) { @@ -2642,17 +2644,6 @@ _on_data_channel_ready_state (WebRTCDataChannel * channel, } } DC_UNLOCK (webrtc); - - if (found == TRUE) { - /* Tear down bins outside dc_lock to avoid deadlocks */ - gst_element_set_locked_state (channel->src_bin, TRUE); - gst_element_set_state (channel->src_bin, GST_STATE_NULL); - gst_object_unref (channel->src_bin); - - gst_element_set_locked_state (channel->sink_bin, TRUE); - gst_element_set_state (channel->sink_bin, GST_STATE_NULL); - gst_object_unref (channel->sink_bin); - } } }