rtsp-*: Treat sending packets to clients as keepalive

As long as gst-rtsp-server can successfully send RTP/RTCP data to
clients then the client must be reading. This change makes the server
timeout the connection if the client stops reading.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=736647
This commit is contained in:
Branko Subasic 2014-09-19 18:28:50 +02:00 committed by Sebastian Dröge
parent 733ef1162b
commit 2218510cae
3 changed files with 16 additions and 6 deletions

View file

@ -691,6 +691,7 @@ do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client)
{
GstRTSPClientPrivate *priv = client->priv;
GstRTSPMessage message = { 0 };
GstRTSPResult res = GST_RTSP_OK;
GstMapInfo map_info;
guint8 *data;
guint usize;
@ -705,7 +706,7 @@ do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client)
g_mutex_lock (&priv->send_lock);
if (priv->send_func)
priv->send_func (client, &message, FALSE, priv->send_data);
res = priv->send_func (client, &message, FALSE, priv->send_data);
g_mutex_unlock (&priv->send_lock);
gst_rtsp_message_steal_body (&message, &data, &usize);
@ -713,7 +714,7 @@ do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client)
gst_rtsp_message_unset (&message);
return TRUE;
return res == GST_RTSP_OK;
}
/**

View file

@ -58,6 +58,7 @@ struct _GstRTSPSessionPrivate
guint timeout;
gboolean timeout_always_visible;
GTimeVal create_time; /* immutable */
GMutex last_access_lock;
GTimeVal last_access;
gint expire_count;
@ -132,6 +133,7 @@ gst_rtsp_session_init (GstRTSPSession * session)
GST_INFO ("init session %p", session);
g_mutex_init (&priv->lock);
g_mutex_init (&priv->last_access_lock);
priv->timeout = DEFAULT_TIMEOUT;
g_get_current_time (&priv->create_time);
gst_rtsp_session_touch (session);
@ -153,6 +155,7 @@ gst_rtsp_session_finalize (GObject * obj)
/* free session id */
g_free (priv->sessionid);
g_mutex_clear (&priv->last_access_lock);
g_mutex_clear (&priv->lock);
G_OBJECT_CLASS (gst_rtsp_session_parent_class)->finalize (obj);
@ -555,9 +558,9 @@ gst_rtsp_session_touch (GstRTSPSession * session)
priv = session->priv;
g_mutex_lock (&priv->lock);
g_mutex_lock (&priv->last_access_lock);
g_get_current_time (&priv->last_access);
g_mutex_unlock (&priv->lock);
g_mutex_unlock (&priv->last_access_lock);
}
/**
@ -608,7 +611,7 @@ gst_rtsp_session_next_timeout (GstRTSPSession * session, GTimeVal * now)
priv = session->priv;
g_mutex_lock (&priv->lock);
g_mutex_lock (&priv->last_access_lock);
if (g_atomic_int_get (&priv->expire_count) != 0) {
/* touch session when the expire count is not 0 */
g_get_current_time (&priv->last_access);
@ -617,7 +620,7 @@ gst_rtsp_session_next_timeout (GstRTSPSession * session, GTimeVal * now)
last_access = GST_TIMEVAL_TO_TIME (priv->last_access);
/* add timeout allow for 5 seconds of extra time */
last_access += priv->timeout * GST_SECOND + (5 * GST_SECOND);
g_mutex_unlock (&priv->lock);
g_mutex_unlock (&priv->last_access_lock);
now_ns = GST_TIMEVAL_TO_TIME (*now);

View file

@ -456,6 +456,9 @@ gst_rtsp_stream_transport_send_rtp (GstRTSPStreamTransport * trans,
priv->send_rtp (buffer, priv->transport->interleaved.min,
priv->user_data);
if (res)
gst_rtsp_stream_transport_keep_alive (trans);
return res;
}
@ -482,6 +485,9 @@ gst_rtsp_stream_transport_send_rtcp (GstRTSPStreamTransport * trans,
priv->send_rtcp (buffer, priv->transport->interleaved.max,
priv->user_data);
if (res)
gst_rtsp_stream_transport_keep_alive (trans);
return res;
}