typedef struct
{
- GTimeVal now;
+ gint64 now_monotonic_time;
GstRTSPSessionPool *pool;
GList *removed;
} CleanupData;
{
gboolean expired;
- expired = gst_rtsp_session_is_expired (sess, &data->now);
+ expired = gst_rtsp_session_is_expired_usec (sess, data->now_monotonic_time);
+
if (expired) {
GST_DEBUG ("session expired");
data->removed = g_list_prepend (data->removed, g_object_ref (sess));
}
+
return expired;
}
priv = pool->priv;
- g_get_current_time (&data.now);
+ data.now_monotonic_time = g_get_monotonic_time ();
+
data.pool = pool;
data.removed = NULL;
collect_timeout (gchar * sessionid, GstRTSPSession * sess, GstPoolSource * psrc)
{
gint timeout;
- GTimeVal now;
+ gint64 now_monotonic_time;
+
+ now_monotonic_time = g_get_monotonic_time ();
- g_get_current_time (&now);
+ timeout = gst_rtsp_session_next_timeout_usec (sess, now_monotonic_time);
- timeout = gst_rtsp_session_next_timeout (sess, &now);
GST_INFO ("%p: next timeout: %d", sess, timeout);
if (psrc->timeout == -1 || timeout < psrc->timeout)
psrc->timeout = timeout;
guint timeout;
gboolean timeout_always_visible;
- GTimeVal create_time; /* immutable */
GMutex last_access_lock;
- GTimeVal last_access;
+ gint64 last_access_monotonic_time;
+ gint64 last_access_real_time;
gint expire_count;
GList *medias;
g_mutex_init (&priv->lock);
g_mutex_init (&priv->last_access_lock);
priv->timeout = DEFAULT_TIMEOUT;
- g_get_current_time (&priv->create_time);
+
gst_rtsp_session_touch (session);
}
priv = session->priv;
g_mutex_lock (&priv->last_access_lock);
- g_get_current_time (&priv->last_access);
+ priv->last_access_monotonic_time = g_get_monotonic_time ();
+ priv->last_access_real_time = g_get_real_time ();
g_mutex_unlock (&priv->last_access_lock);
}
}
/**
+ * gst_rtsp_session_next_timeout_usec:
+ * @session: a #GstRTSPSession
+ * @now: (transfer none): the current monotonic 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_usec (GstRTSPSession * session, gint64 now)
+{
+ GstRTSPSessionPrivate *priv;
+ gint res;
+ GstClockTime last_access, now_ns;
+
+ g_return_val_if_fail (GST_IS_RTSP_SESSION (session), -1);
+
+ priv = session->priv;
+
+ g_mutex_lock (&priv->last_access_lock);
+ if (g_atomic_int_get (&priv->expire_count) != 0) {
+ /* touch session when the expire count is not 0 */
+ priv->last_access_monotonic_time = g_get_monotonic_time ();
+ priv->last_access_real_time = g_get_real_time ();
+ }
+
+ last_access = GST_USECOND * (priv->last_access_monotonic_time);
+
+ /* add timeout allow for 5 seconds of extra time */
+ last_access += priv->timeout * GST_SECOND + (5 * GST_SECOND);
+ g_mutex_unlock (&priv->last_access_lock);
+
+ now_ns = GST_USECOND * now;
+
+ if (last_access > now_ns) {
+ res = GST_TIME_AS_MSECONDS (last_access - now_ns);
+ } else {
+ res = 0;
+ }
+
+ return res;
+}
+
+/****** Deprecated API *******/
+
+/**
* gst_rtsp_session_next_timeout:
* @session: a #GstRTSPSession
* @now: (transfer none): 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.
+ *
+ * Deprecated: Use gst_rtsp_session_next_timeout_usec() instead.
*/
+#ifndef GST_REMOVE_DEPRECATED
+#ifndef GST_DISABLE_DEPRECATED
gint
gst_rtsp_session_next_timeout (GstRTSPSession * session, GTimeVal * now)
{
g_mutex_lock (&priv->last_access_lock);
if (g_atomic_int_get (&priv->expire_count) != 0) {
/* touch session when the expire count is not 0 */
- g_get_current_time (&priv->last_access);
+ priv->last_access_monotonic_time = g_get_monotonic_time ();
+ priv->last_access_real_time = g_get_real_time ();
}
- last_access = GST_TIMEVAL_TO_TIME (priv->last_access);
+ last_access = GST_USECOND * (priv->last_access_real_time);
+
/* add timeout allow for 5 seconds of extra time */
last_access += priv->timeout * GST_SECOND + (5 * GST_SECOND);
g_mutex_unlock (&priv->last_access_lock);
now_ns = GST_TIMEVAL_TO_TIME (*now);
- if (last_access > now_ns)
+ if (last_access > now_ns) {
res = GST_TIME_AS_MSECONDS (last_access - now_ns);
- else
+ } else {
res = 0;
+ }
return res;
}
+#endif
+#endif
+
+/**
+ * gst_rtsp_session_is_expired_usec:
+ * @session: a #GstRTSPSession
+ * @now: (transfer none): the current monotonic time
+ *
+ * Check if @session timeout out.
+ *
+ * Returns: %TRUE if @session timed out
+ */
+gboolean
+gst_rtsp_session_is_expired_usec (GstRTSPSession * session, gint64 now)
+{
+ gboolean res;
+
+ res = (gst_rtsp_session_next_timeout_usec (session, now) == 0);
+
+ return res;
+}
+
+
+/****** Deprecated API *******/
/**
* gst_rtsp_session_is_expired:
* Check if @session timeout out.
*
* Returns: %TRUE if @session timed out
+ *
+ * Deprecated: Use gst_rtsp_session_is_expired_usec() instead.
*/
+#ifndef GST_REMOVE_DEPRECATED
+#ifndef GST_DISABLE_DEPRECATED
gboolean
gst_rtsp_session_is_expired (GstRTSPSession * session, GTimeVal * now)
{
return res;
}
+#endif
+#endif