From c4fe52395b21b54fd6ee6b9a5010737404889242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Fri, 5 Oct 2018 12:10:06 -0700 Subject: [PATCH] webrtcbin: start and stop thread when changing state It might be possible that if we set webrtcbin to the NULL state some tasks (idle sources) are still executed and they might even freeze. The freeze is caused because the webrtcbin tasks don't hold a reference to webrtcbin and if it's last unref inside the idle source itself this will not allow the main loop to finish because the main loop is waiting on the idle source to finish. We now start and stop webrtcbin thread when changing states. This will allow the idle sources to finish properly. https://bugzilla.gnome.org/show_bug.cgi?id=797251 --- ext/webrtc/gstwebrtcbin.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index 60614b829c..d7c1d479b2 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -4476,6 +4476,7 @@ gst_webrtc_bin_change_state (GstElement * element, GstStateChange transition) case GST_STATE_CHANGE_NULL_TO_READY:{ if (!_have_nice_elements (webrtc) || !_have_dtls_elements (webrtc)) return GST_STATE_CHANGE_FAILURE; + _start_thread (webrtc); _update_need_negotiation (webrtc); break; } @@ -4501,6 +4502,9 @@ gst_webrtc_bin_change_state (GstElement * element, GstStateChange transition) case GST_STATE_CHANGE_PAUSED_TO_READY: webrtc->priv->running = FALSE; break; + case GST_STATE_CHANGE_READY_TO_NULL: + _stop_thread (webrtc); + break; default: break; } @@ -4663,8 +4667,6 @@ gst_webrtc_bin_dispose (GObject * object) { GstWebRTCBin *webrtc = GST_WEBRTC_BIN (object); - _stop_thread (webrtc); - if (webrtc->priv->ice) gst_object_unref (webrtc->priv->ice); webrtc->priv->ice = NULL; @@ -5110,8 +5112,6 @@ gst_webrtc_bin_init (GstWebRTCBin * webrtc) g_mutex_init (PC_GET_LOCK (webrtc)); g_cond_init (PC_GET_COND (webrtc)); - _start_thread (webrtc); - webrtc->rtpbin = _create_rtpbin (webrtc); gst_bin_add (GST_BIN (webrtc), webrtc->rtpbin);