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
|
|
|
*/
|
2013-07-11 14:57:14 +00:00
|
|
|
/**
|
|
|
|
* SECTION:rtsp-session
|
|
|
|
* @short_description: An object to manage media
|
|
|
|
* @see_also: #GstRTSPSessionPool, #GstRTSPSessionMedia, #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* The #GstRTSPSession is identified by an id, unique in the
|
|
|
|
* #GstRTSPSessionPool that created the session and manages media and its
|
|
|
|
* configuration.
|
|
|
|
*
|
|
|
|
* A #GstRTSPSession has a timeout that can be retrieved with
|
|
|
|
* gst_rtsp_session_get_timeout(). You can check if the sessions is expired with
|
|
|
|
* gst_rtsp_session_is_expired(). gst_rtsp_session_touch() will reset the
|
|
|
|
* expiration counter of the session.
|
|
|
|
*
|
|
|
|
* When a client configures a media with SETUP, a session will be created to
|
|
|
|
* keep track of the configuration of that media. With
|
|
|
|
* gst_rtsp_session_manage_media(), the media is added to the managed media
|
|
|
|
* in the session. With gst_rtsp_session_release_media() the media can be
|
|
|
|
* released again from the session. Managed media is identified in the sessions
|
|
|
|
* with a url. Use gst_rtsp_session_get_media() to get the media that matches
|
|
|
|
* (part of) the given url.
|
|
|
|
*
|
|
|
|
* The media in a session can be iterated with gst_rtsp_session_filter().
|
|
|
|
*
|
|
|
|
* Last reviewed on 2013-07-11 (1.0.0)
|
|
|
|
*/
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
#include <string.h>
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
#include "rtsp-session.h"
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
#define GST_RTSP_SESSION_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_SESSION, GstRTSPSessionPrivate))
|
|
|
|
|
|
|
|
struct _GstRTSPSessionPrivate
|
|
|
|
{
|
2013-02-18 19:59:58 +00:00
|
|
|
GMutex lock; /* protects everything but sessionid and create_time */
|
2012-11-29 10:11:05 +00:00
|
|
|
gchar *sessionid;
|
|
|
|
|
|
|
|
guint timeout;
|
2013-02-18 19:59:58 +00:00
|
|
|
GTimeVal create_time; /* immutable */
|
2012-11-29 10:11:05 +00:00
|
|
|
GTimeVal last_access;
|
|
|
|
gint expire_count;
|
|
|
|
|
|
|
|
GList *medias;
|
|
|
|
};
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
#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;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstRTSPSessionPrivate));
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
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-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv = GST_RTSP_SESSION_GET_PRIVATE (session);
|
|
|
|
|
|
|
|
session->priv = priv;
|
|
|
|
|
|
|
|
g_mutex_init (&priv->lock);
|
|
|
|
priv->timeout = DEFAULT_TIMEOUT;
|
|
|
|
g_get_current_time (&priv->create_time);
|
2009-02-04 18:52:50 +00:00
|
|
|
gst_rtsp_session_touch (session);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_session_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstRTSPSession *session;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
session = GST_RTSP_SESSION (obj);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = session->priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
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-11-29 10:11:05 +00:00
|
|
|
g_list_free_full (priv->medias, g_object_unref);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-29 17:55:22 +00:00
|
|
|
/* free session id */
|
2012-11-29 10:11:05 +00:00
|
|
|
g_free (priv->sessionid);
|
|
|
|
g_mutex_clear (&priv->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);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv = session->priv;
|
2009-02-04 18:52:50 +00:00
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SESSIONID:
|
2012-11-29 10:11:05 +00:00
|
|
|
g_value_set_string (value, priv->sessionid);
|
2009-02-04 18:52:50 +00:00
|
|
|
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);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv = session->priv;
|
2009-02-04 18:52:50 +00:00
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SESSIONID:
|
2012-11-29 10:11:05 +00:00
|
|
|
g_free (priv->sessionid);
|
|
|
|
priv->sessionid = g_value_dup_string (value);
|
2009-02-04 18:52:50 +00:00
|
|
|
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
|
2013-07-03 10:37:48 +00:00
|
|
|
* @path: the path for the media
|
2012-10-01 17:46:15 +00:00
|
|
|
* @media: (transfer full): a #GstRTSPMedia
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
2013-07-03 10:37:48 +00:00
|
|
|
* Manage the media object @obj in @sess. @path 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 *
|
2013-07-03 10:37:48 +00:00
|
|
|
gst_rtsp_session_manage_media (GstRTSPSession * sess, const gchar * path,
|
2010-03-16 17:34:43 +00:00
|
|
|
GstRTSPMedia * media)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv;
|
2009-01-29 12:31:27 +00:00
|
|
|
GstRTSPSessionMedia *result;
|
2013-11-28 13:10:19 +00:00
|
|
|
GstRTSPMediaStatus status;
|
2009-02-03 18:32:38 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (sess), NULL);
|
2013-07-03 10:37:48 +00:00
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
2009-02-03 18:32:38 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
2013-11-28 13:10:19 +00:00
|
|
|
status = gst_rtsp_media_get_status (media);
|
|
|
|
g_return_val_if_fail (status == GST_RTSP_MEDIA_STATUS_PREPARED || status ==
|
|
|
|
GST_RTSP_MEDIA_STATUS_SUSPENDED, NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
priv = sess->priv;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2013-07-03 10:37:48 +00:00
|
|
|
result = gst_rtsp_session_media_new (path, media);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->medias = g_list_prepend (priv->medias, result);
|
|
|
|
g_mutex_unlock (&priv->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-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv;
|
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-29 10:11:05 +00:00
|
|
|
priv = sess->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
find = g_list_find (priv->medias, media);
|
2012-11-12 15:42:37 +00:00
|
|
|
if (find)
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->medias = g_list_delete_link (priv->medias, find);
|
|
|
|
more = (priv->medias != NULL);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-12 15:42:37 +00:00
|
|
|
|
|
|
|
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
|
2013-07-03 10:37:48 +00:00
|
|
|
* @path: the path for the media
|
2013-10-12 21:56:00 +00:00
|
|
|
* @matched: (out): the amount of matched characters
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2013-07-03 10:37:48 +00:00
|
|
|
* Get the session media for @path. @matched will contain the number of matched
|
|
|
|
* characters of @path.
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2013-07-03 10:37:48 +00:00
|
|
|
* Returns: (transfer none): the configuration for @path in @sess.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
GstRTSPSessionMedia *
|
2013-07-03 10:37:48 +00:00
|
|
|
gst_rtsp_session_get_media (GstRTSPSession * sess, const gchar * path,
|
|
|
|
gint * matched)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPSessionMedia *result;
|
|
|
|
GList *walk;
|
2013-07-03 10:37:48 +00:00
|
|
|
gint best;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (sess), NULL);
|
2013-07-03 10:37:48 +00:00
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = sess->priv;
|
2008-10-23 10:14:55 +00:00
|
|
|
result = NULL;
|
2013-07-03 10:37:48 +00:00
|
|
|
best = 0;
|
2008-10-23 10:14:55 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
for (walk = priv->medias; walk; walk = g_list_next (walk)) {
|
2013-07-03 10:37:48 +00:00
|
|
|
GstRTSPSessionMedia *test;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-03 10:37:48 +00:00
|
|
|
test = (GstRTSPSessionMedia *) walk->data;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-03 10:37:48 +00:00
|
|
|
/* find largest match */
|
|
|
|
if (gst_rtsp_session_media_matches (test, path, matched)) {
|
|
|
|
if (best < *matched) {
|
|
|
|
result = test;
|
|
|
|
best = *matched;
|
|
|
|
}
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2013-07-03 10:37:48 +00:00
|
|
|
*matched = best;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_session_filter:
|
|
|
|
* @sess: a #GstRTSPSession
|
2013-11-18 10:47:04 +00:00
|
|
|
* @func: (scope call) (allow-none): a callback
|
2012-11-29 10:11:05 +00:00
|
|
|
* @user_data: user data passed to @func
|
|
|
|
*
|
|
|
|
* Call @func for each media in @sess. The result value of @func determines
|
|
|
|
* what happens to the media. @func will be called with @sess
|
|
|
|
* locked so no further actions on @sess can be performed from @func.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REMOVE, the media will be removed from
|
|
|
|
* @sess.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_KEEP, the media will remain in @sess.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REF, the media will remain in @sess but
|
|
|
|
* will also be added with an additional ref to the result #GList of this
|
|
|
|
* function..
|
|
|
|
*
|
2013-11-15 15:35:05 +00:00
|
|
|
* When @func is %NULL, #GST_RTSP_FILTER_REF will be assumed for all media.
|
|
|
|
*
|
2012-11-29 10:11:05 +00:00
|
|
|
* Returns: (element-type GstRTSPSessionMedia) (transfer full): a GList with all
|
|
|
|
* media for which @func returned #GST_RTSP_FILTER_REF. After usage, each
|
|
|
|
* element in the #GList should be unreffed before the list is freed.
|
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
gst_rtsp_session_filter (GstRTSPSession * sess,
|
|
|
|
GstRTSPSessionFilterFunc func, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPSessionPrivate *priv;
|
|
|
|
GList *result, *walk, *next;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (sess), NULL);
|
|
|
|
|
|
|
|
priv = sess->priv;
|
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
for (walk = priv->medias; walk; walk = next) {
|
|
|
|
GstRTSPSessionMedia *media = walk->data;
|
2013-11-15 15:35:05 +00:00
|
|
|
GstRTSPFilterResult res;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
next = g_list_next (walk);
|
|
|
|
|
2013-11-15 15:35:05 +00:00
|
|
|
if (func)
|
|
|
|
res = func (sess, media, user_data);
|
|
|
|
else
|
|
|
|
res = GST_RTSP_FILTER_REF;
|
|
|
|
|
|
|
|
switch (res) {
|
2012-11-29 10:11:05 +00:00
|
|
|
case GST_RTSP_FILTER_REMOVE:
|
|
|
|
g_object_unref (media);
|
|
|
|
priv->medias = g_list_delete_link (priv->medias, walk);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_REF:
|
|
|
|
result = g_list_prepend (result, g_object_ref (media));
|
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_KEEP:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-12 15:42:37 +00:00
|
|
|
|
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);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
return session->priv->sessionid;
|
2009-02-04 18:52:50 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv;
|
2012-11-12 11:40:34 +00:00
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION (session), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = session->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (priv->timeout != 60)
|
|
|
|
result = g_strdup_printf ("%s; timeout=%d", priv->sessionid, priv->timeout);
|
2012-11-12 11:40:34 +00:00
|
|
|
else
|
2012-11-29 10:11:05 +00:00
|
|
|
result = g_strdup (priv->sessionid);
|
|
|
|
g_mutex_unlock (&priv->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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv;
|
|
|
|
|
2009-02-04 18:52:50 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_SESSION (session));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = session->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->timeout = timeout;
|
|
|
|
g_mutex_unlock (&priv->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-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv;
|
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-29 10:11:05 +00:00
|
|
|
priv = session->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->timeout;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-12 15:42:37 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv;
|
|
|
|
|
2009-02-04 18:52:50 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_SESSION (session));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = session->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
g_get_current_time (&priv->last_access);
|
|
|
|
g_mutex_unlock (&priv->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));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_atomic_int_add (&session->priv->expire_count, 1);
|
2010-04-06 15:07:27 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
g_atomic_int_add (&session->priv->expire_count, -1);
|
2010-04-06 15:07:27 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionPrivate *priv;
|
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-29 10:11:05 +00:00
|
|
|
priv = session->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (g_atomic_int_get (&priv->expire_count) != 0) {
|
2010-04-06 15:07:27 +00:00
|
|
|
/* touch session when the expire count is not 0 */
|
2012-11-29 10:11:05 +00:00
|
|
|
g_get_current_time (&priv->last_access);
|
2010-04-06 15:07:27 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
last_access = GST_TIMEVAL_TO_TIME (priv->last_access);
|
2009-05-26 15:27:07 +00:00
|
|
|
/* add timeout allow for 5 seconds of extra time */
|
2012-11-29 10:11:05 +00:00
|
|
|
last_access += priv->timeout * GST_SECOND + (5 * GST_SECOND);
|
|
|
|
g_mutex_unlock (&priv->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;
|
|
|
|
}
|