mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-23 15:48:23 +00:00
Add more timeout stuff
Add method to check if a session is expired. Add method to perform cleanup on a session pool.
This commit is contained in:
parent
aedd4652f3
commit
ae9da4c5b0
4 changed files with 62 additions and 1 deletions
|
@ -352,3 +352,31 @@ gst_rtsp_session_pool_remove (GstRTSPSessionPool *pool, GstRTSPSession *sess)
|
|||
return found;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
cleanup_func (gchar *sessionid, GstRTSPSession *sess, GstRTSPSessionPool *pool)
|
||||
{
|
||||
return gst_rtsp_session_is_expired (sess);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_session_pool_cleanup:
|
||||
* @pool: a #GstRTSPSessionPool
|
||||
*
|
||||
* Inspect all the sessions in @pool and remove the sessions that are inactive
|
||||
* for more than their timeout.
|
||||
*
|
||||
* Returns: the amount of sessions that got removed.
|
||||
*/
|
||||
guint
|
||||
gst_rtsp_session_pool_cleanup (GstRTSPSessionPool *pool)
|
||||
{
|
||||
guint result;
|
||||
|
||||
g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), 0);
|
||||
|
||||
g_mutex_lock (pool->lock);
|
||||
result = g_hash_table_foreach_remove (pool->sessions, (GHRFunc) cleanup_func, pool);
|
||||
g_mutex_unlock (pool->lock);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,9 @@ GstRTSPSession * gst_rtsp_session_pool_find (GstRTSPSessionPoo
|
|||
gboolean gst_rtsp_session_pool_remove (GstRTSPSessionPool *pool,
|
||||
GstRTSPSession *sess);
|
||||
|
||||
/* perform session maintenance */
|
||||
guint gst_rtsp_session_pool_cleanup (GstRTSPSessionPool *pool);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_RTSP_SESSION_POOL_H__ */
|
||||
|
|
|
@ -397,6 +397,35 @@ gst_rtsp_session_touch (GstRTSPSession *session)
|
|||
g_get_current_time (&session->last_access);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_session_is_expired:
|
||||
* @session: a #GstRTSPSession
|
||||
*
|
||||
* Check if @session timeout out.
|
||||
*
|
||||
* Returns: %TRUE if @session timed out
|
||||
*/
|
||||
gboolean
|
||||
gst_rtsp_session_is_expired (GstRTSPSession *session)
|
||||
{
|
||||
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;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_session_stream_init_udp:
|
||||
* @stream: a #GstRTSPSessionStream
|
||||
|
|
|
@ -117,8 +117,9 @@ const gchar * gst_rtsp_session_get_sessionid (GstRTSPSession *se
|
|||
void gst_rtsp_session_set_timeout (GstRTSPSession *session, guint timeout);
|
||||
guint gst_rtsp_session_get_timeout (GstRTSPSession *session);
|
||||
|
||||
/* touch the session, update last_access */
|
||||
/* session timeout stuff */
|
||||
void gst_rtsp_session_touch (GstRTSPSession *session);
|
||||
gboolean gst_rtsp_session_is_expired (GstRTSPSession *session);
|
||||
|
||||
/* handle media in a session */
|
||||
GstRTSPSessionMedia * gst_rtsp_session_manage_media (GstRTSPSession *sess,
|
||||
|
|
Loading…
Reference in a new issue