rtsp-client: Don't ever close the client connection directly when a session is torn down

There might be other sessions that are running over the same RTSP
connection and we should not simply close the client directly if one of
them is torn down.

By default the connection will be closed once the client closes it or
the OS does. This behaviour can be adjusted with the
post-session-timeout property, which allows to close it automatically
from the server side after all sessions are gone and the given timeout
is reached.

This reverts the previous commit.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/115>
This commit is contained in:
Sebastian Dröge 2020-04-27 19:47:15 +03:00
parent f2b82c28a3
commit d33057a031

View file

@ -84,7 +84,6 @@ struct _GstRTSPClientPrivate
GstRTSPClientSendMessagesFunc send_messages_func; GstRTSPClientSendMessagesFunc send_messages_func;
gpointer send_messages_data; gpointer send_messages_data;
GDestroyNotify send_messages_notify; GDestroyNotify send_messages_notify;
guint close_seq;
GArray *data_seqs; GArray *data_seqs;
GstRTSPSessionPool *session_pool; GstRTSPSessionPool *session_pool;
@ -608,7 +607,6 @@ gst_rtsp_client_init (GstRTSPClient * client)
g_mutex_init (&priv->lock); g_mutex_init (&priv->lock);
g_mutex_init (&priv->send_lock); g_mutex_init (&priv->send_lock);
g_mutex_init (&priv->watch_lock); g_mutex_init (&priv->watch_lock);
priv->close_seq = 0;
priv->data_seqs = g_array_new (FALSE, FALSE, sizeof (DataSeq)); priv->data_seqs = g_array_new (FALSE, FALSE, sizeof (DataSeq));
priv->drop_backlog = DEFAULT_DROP_BACKLOG; priv->drop_backlog = DEFAULT_DROP_BACKLOG;
priv->post_session_timeout = DEFAULT_POST_SESSION_TIMEOUT; priv->post_session_timeout = DEFAULT_POST_SESSION_TIMEOUT;
@ -4784,7 +4782,6 @@ do_send_messages (GstRTSPClient * client, GstRTSPMessage * messages,
guint id = 0; guint id = 0;
GstRTSPResult ret; GstRTSPResult ret;
guint i; guint i;
gboolean closed = FALSE;
/* send the message */ /* send the message */
if (close) if (close)
@ -4794,15 +4791,6 @@ do_send_messages (GstRTSPClient * client, GstRTSPMessage * messages,
if (ret != GST_RTSP_OK) if (ret != GST_RTSP_OK)
goto error; goto error;
/* if close flag is set, store the seq number so we can wait until it's
* 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++) { for (i = 0; i < n_messages; i++) {
if (gst_rtsp_message_get_type (&messages[i]) == GST_RTSP_MESSAGE_DATA) { if (gst_rtsp_message_get_type (&messages[i]) == GST_RTSP_MESSAGE_DATA) {
guint8 channel = 0; guint8 channel = 0;
@ -4839,13 +4827,6 @@ 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; return ret == GST_RTSP_OK;
/* ERRORS */ /* ERRORS */
@ -4870,7 +4851,6 @@ message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
GstRTSPClientPrivate *priv = client->priv; GstRTSPClientPrivate *priv = client->priv;
GstRTSPStreamTransport *trans = NULL; GstRTSPStreamTransport *trans = NULL;
guint8 channel = 0; guint8 channel = 0;
gboolean close = FALSE;
g_mutex_lock (&priv->send_lock); g_mutex_lock (&priv->send_lock);
@ -4878,13 +4858,6 @@ message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
trans = g_hash_table_lookup (priv->transports, GINT_TO_POINTER (channel)); trans = g_hash_table_lookup (priv->transports, GINT_TO_POINTER (channel));
set_data_seq (client, channel, 0); set_data_seq (client, channel, 0);
} }
if (priv->close_seq && priv->close_seq == cseq) {
GST_INFO ("client %p: sent close message", client);
close = TRUE;
priv->close_seq = 0;
}
g_mutex_unlock (&priv->send_lock); g_mutex_unlock (&priv->send_lock);
if (trans) { if (trans) {
@ -4892,9 +4865,6 @@ message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
gst_rtsp_stream_transport_message_sent (trans); gst_rtsp_stream_transport_message_sent (trans);
} }
if (close)
gst_rtsp_client_close (client);
return GST_RTSP_OK; return GST_RTSP_OK;
} }