}
/**
- * 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;
}
/* 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,