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
This commit is contained in:
Aleix Conchillo Flaqué 2018-10-05 12:10:06 -07:00 committed by Matthew Waters
parent d5da9e080a
commit c4fe52395b

View file

@ -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);