rtsp-*: Treat sending packets to clients as keepalive
authorBranko Subasic <branko@axis.com>
Fri, 19 Sep 2014 16:28:50 +0000 (18:28 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 24 Sep 2014 07:37:59 +0000 (10:37 +0300)
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

gst/rtsp-server/rtsp-client.c
gst/rtsp-server/rtsp-session.c
gst/rtsp-server/rtsp-stream-transport.c

index 3d4ce91..40295fe 100644 (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;
 }
 
 /**
index 372746a..1f4b650 100644 (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);
 
index cd0a143..c69de26 100644 (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;
 }