2008-10-09 12:29:12 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:14:25 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
2009-01-29 12:31:27 +00:00
|
|
|
#include <string.h>
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
#include "rtsp-session.h"
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
2009-02-04 18:52:50 +00:00
|
|
|
#define DEFAULT_TIMEOUT 60
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_SESSIONID,
|
|
|
|
PROP_TIMEOUT,
|
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2011-01-12 17:14:48 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_session_debug);
|
2009-11-21 18:20:23 +00:00
|
|
|
#define GST_CAT_DEFAULT rtsp_session_debug
|
|
|
|
|
2010-03-16 17:34:43 +00:00
|
|
|
static void gst_rtsp_session_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_session_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2008-10-09 12:29:12 +00:00
|
|
|
static void gst_rtsp_session_finalize (GObject * obj);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstRTSPSession, gst_rtsp_session, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_session_class_init (GstRTSPSessionClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2009-02-04 18:52:50 +00:00
|
|
|
gobject_class->get_property = gst_rtsp_session_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_session_set_property;
|
2008-10-09 12:29:12 +00:00
|
|
|
gobject_class->finalize = gst_rtsp_session_finalize;
|
2009-02-04 18:52:50 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SESSIONID,
|
|
|
|
g_param_spec_string ("sessionid", "Sessionid", "the session id",
|
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
2010-03-16 17:34:43 +00:00
|
|
|
G_PARAM_STATIC_STRINGS));
|
2009-02-04 18:52:50 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TIMEOUT,
|
2010-03-16 17:34:43 +00:00
|
|
|
g_param_spec_uint ("timeout", "timeout",
|
|
|
|
"the timeout of the session (0 = never)", 0, G_MAXUINT,
|
|
|
|
DEFAULT_TIMEOUT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-01-12 17:14:48 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_session_debug, "rtspsession", 0,
|
|
|
|
"GstRTSPSession");
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_session_init (GstRTSPSession * session)
|
|
|
|
{
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_init (&session->lock);
|
2009-02-04 18:52:50 +00:00
|
|
|
session->timeout = DEFAULT_TIMEOUT;
|
|
|
|
g_get_current_time (&session->create_time);
|
|
|
|
gst_rtsp_session_touch (session);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_session_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstRTSPSession *session;
|
|
|
|
|
|
|
|
session = GST_RTSP_SESSION (obj);
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("finalize session %p", session);
|
2009-02-04 16:00:42 +00:00
|
|
|
|
2009-01-29 17:55:22 +00:00
|
|
|
/* free all media */
|
2012-10-25 19:29:58 +00:00
|
|
|
g_list_free_full (session->medias, g_object_unref);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-29 17:55:22 +00:00
|
|
|
/* free session id */
|
|
|
|
g_free (session->sessionid);
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_clear (&session->lock);
|
2009-01-29 17:55:22 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtsp_session_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
2009-02-04 18:52:50 +00:00
|
|
|
static void
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2009-02-04 18:52:50 +00:00
|
|
|
{
|
|
|
|
GstRTSPSession *session = GST_RTSP_SESSION (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SESSIONID:
|
|
|
|
g_value_set_string (value, session->sessionid);
|
|
|
|
break;
|
|
|
|
case PROP_TIMEOUT:
|
|
|
|
g_value_set_uint (value, gst_rtsp_session_get_timeout (session));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2009-02-04 18:52:50 +00:00
|
|
|
{
|
|
|
|
GstRTSPSession *session = GST_RTSP_SESSION (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SESSIONID:
|
|
|
|
g_free (session->sessionid);
|
|
|
|
session->sessionid = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_TIMEOUT:
|
|
|
|
gst_rtsp_session_set_timeout (session, g_value_get_uint (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_manage_media:
|
|
|
|
* @sess: a #GstRTSPSession
|
2010-12-11 09:48:25 +00:00
|
|
|
* @uri: the uri for the media
|
2012-10-01 17:46:15 +00:00
|
|
|
* @media: (transfer full): a #GstRTSPMedia
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
2010-12-11 09:48:25 +00:00
|
|
|
* Manage the media object @obj in @sess. @uri will be used to retrieve this
|
2009-02-04 16:00:42 +00:00
|
|
|
* media from the session with gst_rtsp_session_get_media().
|
|
|
|
*
|
|
|
|
* Ownership is taken from @media.
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
2012-10-28 12:48:44 +00:00
|
|
|
* Returns: (transfer none): a new @GstRTSPSessionMedia object.
|
2009-01-29 12:31:27 +00:00
|
|
|
*/
|
|
|
|
GstRTSPSessionMedia *
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_manage_media (GstRTSPSession * sess, const GstRTSPUrl * uri,
|
|
|
|
GstRTSPMedia * media)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPSessionMedia *result;
|
2009-02-03 18:32:38 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (sess), NULL);
|
|
|
|
g_return_val_if_fail (uri != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
2010-03-05 16:51:26 +00:00
|
|
|
g_return_val_if_fail (media->status == GST_RTSP_MEDIA_STATUS_PREPARED, NULL);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
result = gst_rtsp_session_media_new (uri, media);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_lock (&sess->lock);
|
2009-01-29 12:31:27 +00:00
|
|
|
sess->medias = g_list_prepend (sess->medias, result);
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_unlock (&sess->lock);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("manage new media %p in session %p", media, result);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_release_media:
|
|
|
|
* @sess: a #GstRTSPSession
|
2010-12-11 09:48:25 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
2009-02-04 16:00:42 +00:00
|
|
|
*
|
|
|
|
* Release the managed @media in @sess, freeing the memory allocated by it.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if there are more media session left in @sess.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_release_media (GstRTSPSession * sess,
|
|
|
|
GstRTSPSessionMedia * media)
|
2009-02-04 16:00:42 +00:00
|
|
|
{
|
2012-10-25 19:29:58 +00:00
|
|
|
GList *find;
|
2012-11-12 15:42:37 +00:00
|
|
|
gboolean more;
|
2009-02-04 16:00:42 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (sess), FALSE);
|
|
|
|
g_return_val_if_fail (media != NULL, FALSE);
|
|
|
|
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_lock (&sess->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
find = g_list_find (sess->medias, media);
|
2012-11-12 15:42:37 +00:00
|
|
|
if (find)
|
2012-10-25 19:29:58 +00:00
|
|
|
sess->medias = g_list_delete_link (sess->medias, find);
|
2012-11-12 15:42:37 +00:00
|
|
|
more = (sess->medias != NULL);
|
|
|
|
g_mutex_unlock (&sess->lock);
|
|
|
|
|
|
|
|
if (find)
|
|
|
|
g_object_unref (media);
|
|
|
|
|
|
|
|
return more;
|
2009-02-04 16:00:42 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_get_media:
|
|
|
|
* @sess: a #GstRTSPSession
|
2009-01-22 16:58:19 +00:00
|
|
|
* @url: the url for the media
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2009-01-29 12:31:27 +00:00
|
|
|
* Get the session media of the @url.
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2012-10-28 12:48:44 +00:00
|
|
|
* Returns: (transfer none): the configuration for @url in @sess.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
GstRTSPSessionMedia *
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_get_media (GstRTSPSession * sess, const GstRTSPUrl * url)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPSessionMedia *result;
|
|
|
|
GList *walk;
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (sess), NULL);
|
|
|
|
g_return_val_if_fail (url != NULL, NULL);
|
|
|
|
|
2008-10-23 10:14:55 +00:00
|
|
|
result = NULL;
|
|
|
|
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_lock (&sess->lock);
|
2008-10-09 12:29:12 +00:00
|
|
|
for (walk = sess->medias; walk; walk = g_list_next (walk)) {
|
2010-03-16 17:34:43 +00:00
|
|
|
result = (GstRTSPSessionMedia *) walk->data;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
if (g_str_equal (result->url->abspath, url->abspath))
|
2008-10-09 12:29:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
}
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_unlock (&sess->lock);
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_session_new:
|
2012-10-26 10:33:21 +00:00
|
|
|
* @sessionid: a session id
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2012-10-26 10:33:21 +00:00
|
|
|
* Create a new #GstRTSPSession instance with @sessionid.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
GstRTSPSession *
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_new (const gchar * sessionid)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPSession *result;
|
|
|
|
|
2009-02-04 18:52:50 +00:00
|
|
|
g_return_val_if_fail (sessionid != NULL, NULL);
|
|
|
|
|
|
|
|
result = g_object_new (GST_TYPE_RTSP_SESSION, "sessionid", sessionid, NULL);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-02-04 18:52:50 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_get_sessionid:
|
|
|
|
* @session: a #GstRTSPSession
|
|
|
|
*
|
|
|
|
* Get the sessionid of @session.
|
|
|
|
*
|
|
|
|
* Returns: the sessionid of @session. The value remains valid as long as
|
|
|
|
* @session is alive.
|
|
|
|
*/
|
|
|
|
const gchar *
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_get_sessionid (GstRTSPSession * session)
|
2009-02-04 18:52:50 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (session), NULL);
|
|
|
|
|
|
|
|
return session->sessionid;
|
|
|
|
}
|
|
|
|
|
2012-11-12 11:40:34 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_get_header:
|
|
|
|
* @session: a #GstRTSPSession
|
|
|
|
*
|
|
|
|
* Get the string that can be placed in the Session header field.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the Session header of @session. g_free() after usage.
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_session_get_header (GstRTSPSession * session)
|
|
|
|
{
|
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (session), NULL);
|
|
|
|
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_lock (&session->lock);
|
2012-11-12 11:40:34 +00:00
|
|
|
if (session->timeout != 60)
|
|
|
|
result = g_strdup_printf ("%s; timeout=%d", session->sessionid,
|
|
|
|
session->timeout);
|
|
|
|
else
|
|
|
|
result = g_strdup (session->sessionid);
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_unlock (&session->lock);
|
2012-11-12 11:40:34 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-02-04 18:52:50 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_set_timeout:
|
|
|
|
* @session: a #GstRTSPSession
|
|
|
|
* @timeout: the new timeout
|
|
|
|
*
|
|
|
|
* Configure @session for a timeout of @timeout seconds. The session will be
|
|
|
|
* cleaned up when there is no activity for @timeout seconds.
|
|
|
|
*/
|
|
|
|
void
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_set_timeout (GstRTSPSession * session, guint timeout)
|
2009-02-04 18:52:50 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SESSION (session));
|
|
|
|
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_lock (&session->lock);
|
2009-02-04 18:52:50 +00:00
|
|
|
session->timeout = timeout;
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_unlock (&session->lock);
|
2009-02-04 18:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_session_get_timeout:
|
|
|
|
* @session: a #GstRTSPSession
|
|
|
|
*
|
|
|
|
* Get the timeout value of @session.
|
|
|
|
*
|
|
|
|
* Returns: the timeout of @session in seconds.
|
|
|
|
*/
|
|
|
|
guint
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_get_timeout (GstRTSPSession * session)
|
2009-02-04 18:52:50 +00:00
|
|
|
{
|
2012-11-12 15:42:37 +00:00
|
|
|
guint res;
|
|
|
|
|
2009-02-04 18:52:50 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (session), 0);
|
|
|
|
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_lock (&session->lock);
|
|
|
|
res = session->timeout;
|
|
|
|
g_mutex_unlock (&session->lock);
|
|
|
|
|
|
|
|
return res;
|
2009-02-04 18:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_session_touch:
|
|
|
|
* @session: a #GstRTSPSession
|
|
|
|
*
|
|
|
|
* Update the last_access time of the session to the current time.
|
|
|
|
*/
|
|
|
|
void
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_touch (GstRTSPSession * session)
|
2009-02-04 18:52:50 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SESSION (session));
|
|
|
|
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_lock (&session->lock);
|
2009-02-04 18:52:50 +00:00
|
|
|
g_get_current_time (&session->last_access);
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_unlock (&session->lock);
|
2009-02-04 18:52:50 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 10:33:21 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_prevent_expire:
|
|
|
|
* @session: a #GstRTSPSession
|
|
|
|
*
|
|
|
|
* Prevent @session from expiring.
|
|
|
|
*/
|
2010-04-06 15:07:27 +00:00
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_session_prevent_expire (GstRTSPSession * session)
|
2010-04-06 15:07:27 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SESSION (session));
|
|
|
|
|
|
|
|
g_atomic_int_add (&session->expire_count, 1);
|
|
|
|
}
|
|
|
|
|
2012-10-26 10:33:21 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_allow_expire:
|
|
|
|
* @session: a #GstRTSPSession
|
|
|
|
*
|
|
|
|
* Allow @session to expire. This method must be called an equal
|
|
|
|
* amount of time as gst_rtsp_session_prevent_expire().
|
|
|
|
*/
|
2010-04-06 15:07:27 +00:00
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_session_allow_expire (GstRTSPSession * session)
|
2010-04-06 15:07:27 +00:00
|
|
|
{
|
|
|
|
g_atomic_int_add (&session->expire_count, -1);
|
|
|
|
}
|
|
|
|
|
2009-02-04 19:10:39 +00:00
|
|
|
/**
|
2009-02-13 18:56:01 +00:00
|
|
|
* gst_rtsp_session_next_timeout:
|
2009-02-04 19:10:39 +00:00
|
|
|
* @session: a #GstRTSPSession
|
2009-02-13 18:56:01 +00:00
|
|
|
* @now: the current system time
|
2009-02-04 19:10:39 +00:00
|
|
|
*
|
2009-02-13 18:56:01 +00:00
|
|
|
* Get the amount of milliseconds till the session will expire.
|
2009-02-04 19:10:39 +00:00
|
|
|
*
|
2009-02-13 18:56:01 +00:00
|
|
|
* Returns: the amount of milliseconds since the session will time out.
|
2009-02-04 19:10:39 +00:00
|
|
|
*/
|
2009-02-13 18:56:01 +00:00
|
|
|
gint
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_next_timeout (GstRTSPSession * session, GTimeVal * now)
|
2009-02-04 19:10:39 +00:00
|
|
|
{
|
2009-02-13 18:56:01 +00:00
|
|
|
gint res;
|
2009-02-04 19:10:39 +00:00
|
|
|
GstClockTime last_access, now_ns;
|
|
|
|
|
2009-02-13 18:56:01 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (session), -1);
|
|
|
|
g_return_val_if_fail (now != NULL, -1);
|
2009-02-04 19:10:39 +00:00
|
|
|
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_lock (&session->lock);
|
2010-04-06 15:07:27 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-02-04 19:10:39 +00:00
|
|
|
last_access = GST_TIMEVAL_TO_TIME (session->last_access);
|
2009-05-26 15:27:07 +00:00
|
|
|
/* add timeout allow for 5 seconds of extra time */
|
|
|
|
last_access += session->timeout * GST_SECOND + (5 * GST_SECOND);
|
2012-11-12 15:42:37 +00:00
|
|
|
g_mutex_unlock (&session->lock);
|
2009-02-04 19:10:39 +00:00
|
|
|
|
2009-02-13 18:56:01 +00:00
|
|
|
now_ns = GST_TIMEVAL_TO_TIME (*now);
|
|
|
|
|
2010-03-16 17:34:43 +00:00
|
|
|
if (last_access > now_ns)
|
|
|
|
res = GST_TIME_AS_MSECONDS (last_access - now_ns);
|
2009-02-13 18:56:01 +00:00
|
|
|
else
|
2010-03-16 17:34:43 +00:00
|
|
|
res = 0;
|
2009-02-13 18:56:01 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_session_is_expired:
|
|
|
|
* @session: a #GstRTSPSession
|
|
|
|
* @now: the current system time
|
|
|
|
*
|
2010-03-16 17:34:43 +00:00
|
|
|
* Check if @session timeout out.
|
2009-02-13 18:56:01 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if @session timed out
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-16 17:34:43 +00:00
|
|
|
gst_rtsp_session_is_expired (GstRTSPSession * session, GTimeVal * now)
|
2009-02-13 18:56:01 +00:00
|
|
|
{
|
|
|
|
gboolean res;
|
2009-02-04 19:10:39 +00:00
|
|
|
|
2009-02-13 18:56:01 +00:00
|
|
|
res = (gst_rtsp_session_next_timeout (session, now) == 0);
|
2009-02-04 19:10:39 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|