From bc785b0a47a3586bee00df84811b7abd0b9bd201 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 13 Feb 2009 19:56:01 +0100 Subject: [PATCH] Add better support for session timeouts Add a method to request the number of milliseconds when a session will timeout. --- gst/rtsp-server/rtsp-session.c | 44 +++++++++++++++++++++++++++++++----------- gst/rtsp-server/rtsp-session.h | 3 ++- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/gst/rtsp-server/rtsp-session.c b/gst/rtsp-server/rtsp-session.c index d8faa61..a80e280 100644 --- a/gst/rtsp-server/rtsp-session.c +++ b/gst/rtsp-server/rtsp-session.c @@ -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; } diff --git a/gst/rtsp-server/rtsp-session.h b/gst/rtsp-server/rtsp-session.h index bcda088..b3797b1 100644 --- a/gst/rtsp-server/rtsp-session.h +++ b/gst/rtsp-server/rtsp-session.h @@ -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, -- 2.7.4