session: add support for prevent session timeouts

Add an atomix counter to prevent session timeouts when we are, for example,
streaming over TCP.
This commit is contained in:
Wim Taymans 2010-04-06 17:07:27 +02:00
parent 48a54054e7
commit 4fdd2bf4d1
2 changed files with 23 additions and 0 deletions

View file

@ -421,6 +421,20 @@ gst_rtsp_session_touch (GstRTSPSession * session)
g_get_current_time (&session->last_access); g_get_current_time (&session->last_access);
} }
void
gst_rtsp_session_prevent_expire (GstRTSPSession *session)
{
g_return_if_fail (GST_IS_RTSP_SESSION (session));
g_atomic_int_add (&session->expire_count, 1);
}
void
gst_rtsp_session_allow_expire (GstRTSPSession *session)
{
g_atomic_int_add (&session->expire_count, -1);
}
/** /**
* gst_rtsp_session_next_timeout: * gst_rtsp_session_next_timeout:
* @session: a #GstRTSPSession * @session: a #GstRTSPSession
@ -439,6 +453,11 @@ gst_rtsp_session_next_timeout (GstRTSPSession * session, GTimeVal * now)
g_return_val_if_fail (GST_IS_RTSP_SESSION (session), -1); g_return_val_if_fail (GST_IS_RTSP_SESSION (session), -1);
g_return_val_if_fail (now != NULL, -1); g_return_val_if_fail (now != NULL, -1);
if (g_atomic_int_get (&session->expire_count) != 0) {
/* touch session when the expire count is not 0 */
g_get_current_time (&session->last_access);
}
last_access = GST_TIMEVAL_TO_TIME (session->last_access); last_access = GST_TIMEVAL_TO_TIME (session->last_access);
/* add timeout allow for 5 seconds of extra time */ /* add timeout allow for 5 seconds of extra time */
last_access += session->timeout * GST_SECOND + (5 * GST_SECOND); last_access += session->timeout * GST_SECOND + (5 * GST_SECOND);

View file

@ -88,6 +88,7 @@ struct _GstRTSPSessionMedia
* @timeout: the timeout of the session * @timeout: the timeout of the session
* @create_time: the time when the session was created * @create_time: the time when the session was created
* @last_access: the time the session was last accessed * @last_access: the time the session was last accessed
* @expire_count: the expire prevention counter
* @media: a list of #GstRTSPSessionMedia managed in this session * @media: a list of #GstRTSPSessionMedia managed in this session
* *
* Session information kept by the server for a specific client. * Session information kept by the server for a specific client.
@ -102,6 +103,7 @@ struct _GstRTSPSession {
guint timeout; guint timeout;
GTimeVal create_time; GTimeVal create_time;
GTimeVal last_access; GTimeVal last_access;
gint expire_count;
GList *medias; GList *medias;
}; };
@ -122,6 +124,8 @@ guint gst_rtsp_session_get_timeout (GstRTSPSession *se
/* session timeout stuff */ /* session timeout stuff */
void gst_rtsp_session_touch (GstRTSPSession *session); void gst_rtsp_session_touch (GstRTSPSession *session);
void gst_rtsp_session_prevent_expire (GstRTSPSession *session);
void gst_rtsp_session_allow_expire (GstRTSPSession *session);
gint gst_rtsp_session_next_timeout (GstRTSPSession *session, GTimeVal *now); gint gst_rtsp_session_next_timeout (GstRTSPSession *session, GTimeVal *now);
gboolean gst_rtsp_session_is_expired (GstRTSPSession *session, GTimeVal *now); gboolean gst_rtsp_session_is_expired (GstRTSPSession *session, GTimeVal *now);