session: add support for prevent session timeouts
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 6 Apr 2010 15:07:27 +0000 (17:07 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 6 Apr 2010 15:07:27 +0000 (17:07 +0200)
Add an atomix counter to prevent session timeouts when we are, for example,
streaming over TCP.

gst/rtsp-server/rtsp-session.c
gst/rtsp-server/rtsp-session.h

index 30e1f1d..7df6c37 100644 (file)
@@ -421,6 +421,20 @@ gst_rtsp_session_touch (GstRTSPSession * session)
   g_get_current_time (&session->last_access);
 }
 
+void
+gst_rtsp_session_prevent_expire (GstRTSPSession *session)
+{
+  g_return_if_fail (GST_IS_RTSP_SESSION (session));
+
+  g_atomic_int_add (&session->expire_count, 1);
+}
+
+void
+gst_rtsp_session_allow_expire (GstRTSPSession *session)
+{
+  g_atomic_int_add (&session->expire_count, -1);
+}
+
 /**
  * gst_rtsp_session_next_timeout:
  * @session: a #GstRTSPSession
@@ -439,6 +453,11 @@ gst_rtsp_session_next_timeout (GstRTSPSession * session, GTimeVal * now)
   g_return_val_if_fail (GST_IS_RTSP_SESSION (session), -1);
   g_return_val_if_fail (now != NULL, -1);
 
+  if (g_atomic_int_get (&session->expire_count) != 0) {
+    /* touch session when the expire count is not 0 */
+    g_get_current_time (&session->last_access);
+  }
+
   last_access = GST_TIMEVAL_TO_TIME (session->last_access);
   /* add timeout allow for 5 seconds of extra time */
   last_access += session->timeout * GST_SECOND + (5 * GST_SECOND);
index 5681667..3eab592 100644 (file)
@@ -88,6 +88,7 @@ struct _GstRTSPSessionMedia
  * @timeout: the timeout of the session
  * @create_time: the time when the session was created
  * @last_access: the time the session was last accessed
+ * @expire_count: the expire prevention counter
  * @media: a list of #GstRTSPSessionMedia managed in this session
  *
  * Session information kept by the server for a specific client.
@@ -102,6 +103,7 @@ struct _GstRTSPSession {
   guint         timeout;
   GTimeVal      create_time;
   GTimeVal      last_access;
+  gint          expire_count;
 
   GList        *medias;
 };
@@ -122,6 +124,8 @@ guint                  gst_rtsp_session_get_timeout          (GstRTSPSession *se
 
 /* session timeout stuff */
 void                   gst_rtsp_session_touch                (GstRTSPSession *session);
+void                   gst_rtsp_session_prevent_expire       (GstRTSPSession *session);
+void                   gst_rtsp_session_allow_expire         (GstRTSPSession *session);
 gint                   gst_rtsp_session_next_timeout         (GstRTSPSession *session, GTimeVal *now);
 gboolean               gst_rtsp_session_is_expired           (GstRTSPSession *session, GTimeVal *now);