From f2b82c28a3534eed327b3c0cd8da0d85e15812dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 27 Apr 2020 13:49:55 +0300 Subject: [PATCH] rtsp-client: If the TEARDOWN response can be sent directly, directly close the client Instead of closing it never at all. Previously there was only code that closed the client asynchronously if sending the response happened asynchrously at a later time. Thanks to Christian M for debugging this issue. Fixes https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/issues/102 Part-of: --- gst/rtsp-server/rtsp-client.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gst/rtsp-server/rtsp-client.c b/gst/rtsp-server/rtsp-client.c index 24c2da4943..023269610f 100644 --- a/gst/rtsp-server/rtsp-client.c +++ b/gst/rtsp-server/rtsp-client.c @@ -4784,8 +4784,12 @@ do_send_messages (GstRTSPClient * client, GstRTSPMessage * messages, guint id = 0; GstRTSPResult ret; guint i; + gboolean closed = FALSE; /* send the message */ + if (close) + GST_INFO ("client %p: sending close message", client); + ret = gst_rtsp_watch_send_messages (priv->watch, messages, n_messages, &id); if (ret != GST_RTSP_OK) goto error; @@ -4794,6 +4798,10 @@ do_send_messages (GstRTSPClient * client, GstRTSPMessage * messages, * written to the client to close the connection */ if (close) priv->close_seq = id; + /* if the returned id is 0 then the TEARDOWN was already sent directly and + * we don't have to wait for it asynchronously */ + if (closed && id == 0) + closed = TRUE; for (i = 0; i < n_messages; i++) { if (gst_rtsp_message_get_type (&messages[i]) == GST_RTSP_MESSAGE_DATA) { @@ -4831,6 +4839,13 @@ do_send_messages (GstRTSPClient * client, GstRTSPMessage * messages, } } + if (closed) { + GST_INFO ("client %p: sent close message", client); + g_mutex_unlock (&priv->send_lock); + gst_rtsp_client_close (client); + g_mutex_lock (&priv->send_lock); + } + return ret == GST_RTSP_OK; /* ERRORS */ @@ -4865,7 +4880,7 @@ message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data) } if (priv->close_seq && priv->close_seq == cseq) { - GST_INFO ("client %p: send close message", client); + GST_INFO ("client %p: sent close message", client); close = TRUE; priv->close_seq = 0; }