diff --git a/gst/rtsp-server/rtsp-session.c b/gst/rtsp-server/rtsp-session.c index d8faa61723..a80e28022a 100644 --- a/gst/rtsp-server/rtsp-session.c +++ b/gst/rtsp-server/rtsp-session.c @@ -399,31 +399,53 @@ gst_rtsp_session_touch (GstRTSPSession *session) g_get_current_time (&session->last_access); } +/** + * gst_rtsp_session_next_timeout: + * @session: a #GstRTSPSession + * @now: the current system time + * + * Get the amount of milliseconds till the session will expire. + * + * Returns: the amount of milliseconds since the session will time out. + */ +gint +gst_rtsp_session_next_timeout (GstRTSPSession *session, GTimeVal *now) +{ + gint res; + GstClockTime last_access, now_ns; + + 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; + + 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) +gst_rtsp_session_is_expired (GstRTSPSession *session, GTimeVal *now) { gboolean res; - GstClockTime last_access, now_ns; - GTimeVal now; - g_return_val_if_fail (GST_IS_RTSP_SESSION (session), FALSE); - - 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); - - 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 bcda0887d5..b3797b13ce 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,