Add better support for session timeouts

Add a method to request the number of milliseconds when a session will timeout.
This commit is contained in:
Wim Taymans 2009-02-13 19:56:01 +01:00
parent f0c047ef94
commit bc785b0a47
2 changed files with 37 additions and 14 deletions

View file

@ -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;
}

View 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,