Add better support for session timeouts
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 13 Feb 2009 18:56:01 +0000 (19:56 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 13 Feb 2009 18:56:01 +0000 (19:56 +0100)
Add a method to request the number of milliseconds when a session will timeout.

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

index d8faa61..a80e280 100644 (file)
@@ -400,30 +400,52 @@ gst_rtsp_session_touch (GstRTSPSession *session)
 }
 
 /**
- * gst_rtsp_session_is_expired:
+ * gst_rtsp_session_next_timeout:
  * @session: a #GstRTSPSession
+ * @now: the current system time
  *
- * Check if @session timeout out. 
+ * Get the amount of milliseconds till the session will expire.
  *
- * Returns: %TRUE if @session timed out
+ * Returns: the amount of milliseconds since the session will time out.
  */
-gboolean
-gst_rtsp_session_is_expired (GstRTSPSession *session)
+gint
+gst_rtsp_session_next_timeout (GstRTSPSession *session, GTimeVal *now)
 {
-  gboolean res;
+  gint res;
   GstClockTime last_access, now_ns;
-  GTimeVal now;
 
-  g_return_val_if_fail (GST_IS_RTSP_SESSION (session), FALSE);
+  g_return_val_if_fail (GST_IS_RTSP_SESSION (session), -1);
+  g_return_val_if_fail (now != NULL, -1);
 
   last_access = GST_TIMEVAL_TO_TIME (session->last_access);
   /* add timeout */
   last_access += session->timeout * GST_SECOND;
 
-  g_get_current_time (&now);
-  now_ns = GST_TIMEVAL_TO_TIME (now);
+  now_ns = GST_TIMEVAL_TO_TIME (*now);
+
+  if (last_access > now_ns) 
+    res =  GST_TIME_AS_MSECONDS (last_access - now_ns);
+  else
+    res =  0;
+
+  return res;
+}
+
+/**
+ * gst_rtsp_session_is_expired:
+ * @session: a #GstRTSPSession
+ * @now: the current system time
+ *
+ * Check if @session timeout out. 
+ *
+ * Returns: %TRUE if @session timed out
+ */
+gboolean
+gst_rtsp_session_is_expired (GstRTSPSession *session, GTimeVal *now)
+{
+  gboolean res;
 
-  res = now_ns > last_access;
+  res = (gst_rtsp_session_next_timeout (session, now) == 0);
 
   return res;
 }
index bcda088..b3797b1 100644 (file)
@@ -119,7 +119,8 @@ guint                  gst_rtsp_session_get_timeout          (GstRTSPSession *se
 
 /* session timeout stuff */
 void                   gst_rtsp_session_touch                (GstRTSPSession *session);
-gboolean               gst_rtsp_session_is_expired           (GstRTSPSession *session);
+gint                   gst_rtsp_session_next_timeout         (GstRTSPSession *session, GTimeVal *now);
+gboolean               gst_rtsp_session_is_expired           (GstRTSPSession *session, GTimeVal *now);
 
 /* handle media in a session */
 GstRTSPSessionMedia *  gst_rtsp_session_manage_media         (GstRTSPSession *sess,