rtsp-client: make closing more thread safe

+ Take the watch lock prior to using priv->watch
+ Flush both the watch and connection before closing / unreffing

gst_rtsp_connection_close() is not threadsafe on its own, this is
a workaround at the client level, where we control both the watch
and the connection
This commit is contained in:
Mathieu Duponchelle 2020-01-15 17:06:41 +01:00 committed by GStreamer Merge Bot
parent b4948f69a0
commit 90f7e851f4

View file

@ -1292,6 +1292,13 @@ gst_rtsp_client_close (GstRTSPClient * client)
GST_DEBUG ("client %p: closing connection", client);
g_mutex_lock (&priv->watch_lock);
/* Work around the lack of thread safety of gst_rtsp_connection_close */
if (priv->watch) {
gst_rtsp_watch_set_flushing (priv->watch, TRUE);
}
if (priv->connection) {
if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
g_mutex_lock (&tunnels_lock);
@ -1299,11 +1306,10 @@ gst_rtsp_client_close (GstRTSPClient * client)
g_hash_table_remove (tunnels, tunnelid);
g_mutex_unlock (&tunnels_lock);
}
gst_rtsp_connection_flush (priv->connection, TRUE);
gst_rtsp_connection_close (priv->connection);
}
/* connection is now closed, destroy the watch which will also cause the
* closed signal to be emitted */
if (priv->watch) {
GST_DEBUG ("client %p: destroying watch", client);
g_source_destroy ((GSource *) priv->watch);
@ -1314,6 +1320,8 @@ gst_rtsp_client_close (GstRTSPClient * client)
g_main_context_unref (priv->watch_context);
priv->watch_context = NULL;
}
g_mutex_unlock (&priv->watch_lock);
}
static gchar *