webrtcbin: Tear down src and sink bins before removing them from webrtc

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7900>
This commit is contained in:
Emil Ljungdahl 2024-11-18 07:54:55 +01:00
parent df8b8f9692
commit f28a7b6ef3

View file

@ -2621,6 +2621,12 @@ _on_data_channel_ready_state (WebRTCDataChannel * channel,
gboolean found_pending; gboolean found_pending;
gboolean found; 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); DC_LOCK (webrtc);
found_pending = found_pending =
g_ptr_array_remove (webrtc->priv->pending_data_channels, channel); g_ptr_array_remove (webrtc->priv->pending_data_channels, channel);
@ -2630,11 +2636,7 @@ _on_data_channel_ready_state (WebRTCDataChannel * channel,
if (found == FALSE) { if (found == FALSE) {
GST_FIXME_OBJECT (webrtc, "Received close for unknown data channel"); GST_FIXME_OBJECT (webrtc, "Received close for unknown data channel");
} else { } 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_bin_remove (GST_BIN (webrtc), channel->src_bin);
gst_object_ref (channel->sink_bin);
gst_bin_remove (GST_BIN (webrtc), channel->sink_bin); gst_bin_remove (GST_BIN (webrtc), channel->sink_bin);
if (found_pending == FALSE) { if (found_pending == FALSE) {
@ -2642,17 +2644,6 @@ _on_data_channel_ready_state (WebRTCDataChannel * channel,
} }
} }
DC_UNLOCK (webrtc); 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);
}
} }
} }