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
|
|
|
*/
|
|
|
|
|
2011-01-11 21:41:12 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
#include "rtsp-client.h"
|
2009-01-29 12:31:27 +00:00
|
|
|
#include "rtsp-sdp.h"
|
2009-06-09 22:01:07 +00:00
|
|
|
#include "rtsp-params.h"
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
#define GST_RTSP_CLIENT_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_CLIENT, GstRTSPClientPrivate))
|
|
|
|
|
|
|
|
struct _GstRTSPClientPrivate
|
|
|
|
{
|
|
|
|
GMutex lock;
|
|
|
|
GstRTSPConnection *connection;
|
|
|
|
GstRTSPWatch *watch;
|
|
|
|
guint close_seq;
|
|
|
|
gchar *server_ip;
|
|
|
|
gboolean is_ipv6;
|
|
|
|
gboolean use_client_settings;
|
|
|
|
|
|
|
|
GstRTSPClientSendFunc send_func;
|
|
|
|
gpointer send_data;
|
|
|
|
GDestroyNotify send_notify;
|
|
|
|
|
|
|
|
GstRTSPSessionPool *session_pool;
|
|
|
|
GstRTSPMountPoints *mount_points;
|
|
|
|
GstRTSPAuth *auth;
|
|
|
|
|
|
|
|
GstRTSPUrl *uri;
|
|
|
|
GstRTSPMedia *media;
|
|
|
|
|
|
|
|
GList *transports;
|
|
|
|
GList *sessions;
|
|
|
|
};
|
|
|
|
|
2012-05-11 07:42:47 +00:00
|
|
|
static GMutex tunnels_lock;
|
2009-03-04 11:44:01 +00:00
|
|
|
static GHashTable *tunnels;
|
|
|
|
|
2012-10-10 09:06:02 +00:00
|
|
|
#define DEFAULT_SESSION_POOL NULL
|
2012-11-26 11:34:05 +00:00
|
|
|
#define DEFAULT_MOUNT_POINTS NULL
|
2012-10-10 09:06:02 +00:00
|
|
|
#define DEFAULT_USE_CLIENT_SETTINGS FALSE
|
|
|
|
|
2009-02-10 15:24:13 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_SESSION_POOL,
|
2012-11-26 11:34:05 +00:00
|
|
|
PROP_MOUNT_POINTS,
|
2012-10-10 09:06:02 +00:00
|
|
|
PROP_USE_CLIENT_SETTINGS,
|
2009-02-10 15:24:13 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2011-01-12 14:35:51 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_CLOSED,
|
2012-08-30 19:03:27 +00:00
|
|
|
SIGNAL_NEW_SESSION,
|
2012-09-03 17:48:14 +00:00
|
|
|
SIGNAL_OPTIONS_REQUEST,
|
|
|
|
SIGNAL_DESCRIBE_REQUEST,
|
|
|
|
SIGNAL_SETUP_REQUEST,
|
|
|
|
SIGNAL_PLAY_REQUEST,
|
|
|
|
SIGNAL_PAUSE_REQUEST,
|
|
|
|
SIGNAL_TEARDOWN_REQUEST,
|
|
|
|
SIGNAL_SET_PARAMETER_REQUEST,
|
|
|
|
SIGNAL_GET_PARAMETER_REQUEST,
|
2011-01-12 14:35:51 +00:00
|
|
|
SIGNAL_LAST
|
|
|
|
};
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_client_debug);
|
|
|
|
#define GST_CAT_DEFAULT rtsp_client_debug
|
|
|
|
|
2011-01-12 14:35:51 +00:00
|
|
|
static guint gst_rtsp_client_signals[SIGNAL_LAST] = { 0 };
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
static void gst_rtsp_client_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_client_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2009-01-22 14:33:29 +00:00
|
|
|
static void gst_rtsp_client_finalize (GObject * obj);
|
|
|
|
|
2012-09-07 15:14:30 +00:00
|
|
|
static GstSDPMessage *create_sdp (GstRTSPClient * client, GstRTSPMedia * media);
|
2009-05-26 17:01:10 +00:00
|
|
|
static void client_session_finalized (GstRTSPClient * client,
|
|
|
|
GstRTSPSession * session);
|
2012-10-25 19:29:58 +00:00
|
|
|
static void unlink_session_transports (GstRTSPClient * client,
|
2010-12-11 09:48:42 +00:00
|
|
|
GstRTSPSession * session, GstRTSPSessionMedia * media);
|
2009-03-11 18:38:06 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
G_DEFINE_TYPE (GstRTSPClient, gst_rtsp_client, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_client_class_init (GstRTSPClientClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstRTSPClientPrivate));
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2009-02-10 15:24:13 +00:00
|
|
|
gobject_class->get_property = gst_rtsp_client_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_client_set_property;
|
2009-01-22 14:33:29 +00:00
|
|
|
gobject_class->finalize = gst_rtsp_client_finalize;
|
2009-02-10 15:24:13 +00:00
|
|
|
|
2012-07-18 13:54:49 +00:00
|
|
|
klass->create_sdp = create_sdp;
|
|
|
|
|
2009-02-10 15:24:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
|
|
|
|
g_param_spec_object ("session-pool", "Session Pool",
|
|
|
|
"The session pool to use for client session",
|
2009-05-26 17:01:10 +00:00
|
|
|
GST_TYPE_RTSP_SESSION_POOL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-02-10 15:24:13 +00:00
|
|
|
|
2012-11-26 11:34:05 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MOUNT_POINTS,
|
|
|
|
g_param_spec_object ("mount-points", "Mount Points",
|
|
|
|
"The mount points to use for client session",
|
|
|
|
GST_TYPE_RTSP_MOUNT_POINTS,
|
2009-05-26 17:01:10 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2012-10-10 09:06:02 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_USE_CLIENT_SETTINGS,
|
|
|
|
g_param_spec_boolean ("use-client-settings", "Use Client Settings",
|
|
|
|
"Use client settings for ttl and destination in multicast",
|
|
|
|
DEFAULT_USE_CLIENT_SETTINGS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-01-12 14:35:51 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_CLOSED] =
|
|
|
|
g_signal_new ("closed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstRTSPClientClass, closed), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
|
|
|
|
|
2012-08-30 19:03:27 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_NEW_SESSION] =
|
|
|
|
g_signal_new ("new-session", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstRTSPClientClass, new_session), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_RTSP_SESSION);
|
|
|
|
|
2012-09-03 17:48:14 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST] =
|
|
|
|
g_signal_new ("options-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, options_request),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
|
|
|
gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST] =
|
|
|
|
g_signal_new ("describe-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, describe_request),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
|
|
|
gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST] =
|
|
|
|
g_signal_new ("setup-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, setup_request),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PLAY_REQUEST] =
|
|
|
|
g_signal_new ("play-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, play_request),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PAUSE_REQUEST] =
|
|
|
|
g_signal_new ("pause-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, pause_request),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
|
|
|
gst_rtsp_client_signals[SIGNAL_TEARDOWN_REQUEST] =
|
|
|
|
g_signal_new ("teardown-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, teardown_request),
|
|
|
|
NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
|
|
|
|
|
|
|
gst_rtsp_client_signals[SIGNAL_SET_PARAMETER_REQUEST] =
|
|
|
|
g_signal_new ("set-parameter-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
|
|
|
set_parameter_request), NULL, NULL, g_cclosure_marshal_VOID__POINTER,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_POINTER);
|
|
|
|
|
|
|
|
gst_rtsp_client_signals[SIGNAL_GET_PARAMETER_REQUEST] =
|
|
|
|
g_signal_new ("get-parameter-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
|
|
|
get_parameter_request), NULL, NULL, g_cclosure_marshal_VOID__POINTER,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_POINTER);
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
tunnels =
|
|
|
|
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_init (&tunnels_lock);
|
2009-11-21 18:20:23 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_client_debug, "rtspclient", 0, "GstRTSPClient");
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_client_init (GstRTSPClient * client)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = GST_RTSP_CLIENT_GET_PRIVATE (client);
|
|
|
|
|
|
|
|
client->priv = priv;
|
|
|
|
|
|
|
|
g_mutex_init (&priv->lock);
|
|
|
|
priv->use_client_settings = DEFAULT_USE_CLIENT_SETTINGS;
|
|
|
|
priv->close_seq = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPFilterResult
|
|
|
|
filter_session (GstRTSPSession * sess, GstRTSPSessionMedia * media,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
|
|
|
|
gst_rtsp_session_media_set_state (media, GST_STATE_NULL);
|
|
|
|
unlink_session_transports (client, sess, media);
|
|
|
|
|
|
|
|
/* unmanage the media in the session */
|
|
|
|
return GST_RTSP_FILTER_REMOVE;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
static void
|
2010-12-11 09:48:42 +00:00
|
|
|
client_unlink_session (GstRTSPClient * client, GstRTSPSession * session)
|
2009-01-22 14:33:29 +00:00
|
|
|
{
|
2010-04-06 15:08:40 +00:00
|
|
|
/* unlink all media managed in this session */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_session_filter (session, filter_session, client);
|
2010-04-06 15:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-11 09:48:42 +00:00
|
|
|
client_cleanup_sessions (GstRTSPClient * client)
|
2010-04-06 15:08:40 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-04-06 15:08:40 +00:00
|
|
|
GList *sessions;
|
2009-02-04 16:00:42 +00:00
|
|
|
|
2009-10-11 11:57:54 +00:00
|
|
|
/* remove weak-ref from sessions */
|
2012-11-29 10:11:05 +00:00
|
|
|
for (sessions = priv->sessions; sessions; sessions = g_list_next (sessions)) {
|
2010-04-06 15:08:40 +00:00
|
|
|
GstRTSPSession *session = (GstRTSPSession *) sessions->data;
|
|
|
|
g_object_weak_unref (G_OBJECT (session),
|
2010-03-16 17:33:23 +00:00
|
|
|
(GWeakNotify) client_session_finalized, client);
|
2010-04-06 15:08:40 +00:00
|
|
|
client_unlink_session (client, session);
|
2009-10-11 11:57:54 +00:00
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_list_free (priv->sessions);
|
|
|
|
priv->sessions = NULL;
|
2010-04-06 15:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* A client is finalized when the connection is broken */
|
|
|
|
static void
|
|
|
|
gst_rtsp_client_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (obj);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-04-06 15:08:40 +00:00
|
|
|
|
|
|
|
GST_INFO ("finalize client %p", client);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->watch)
|
|
|
|
g_source_destroy ((GSource *) priv->watch);
|
2012-10-01 14:13:50 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->send_notify)
|
|
|
|
priv->send_notify (priv->send_data);
|
2012-11-26 16:20:39 +00:00
|
|
|
|
2010-04-06 15:08:40 +00:00
|
|
|
client_cleanup_sessions (client);
|
2009-03-11 18:38:06 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->connection)
|
|
|
|
gst_rtsp_connection_free (priv->connection);
|
|
|
|
if (priv->session_pool)
|
|
|
|
g_object_unref (priv->session_pool);
|
|
|
|
if (priv->mount_points)
|
|
|
|
g_object_unref (priv->mount_points);
|
|
|
|
if (priv->auth)
|
|
|
|
g_object_unref (priv->auth);
|
2009-01-29 17:51:02 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->uri)
|
|
|
|
gst_rtsp_url_free (priv->uri);
|
|
|
|
if (priv->media) {
|
|
|
|
gst_rtsp_media_unprepare (priv->media);
|
|
|
|
g_object_unref (priv->media);
|
2012-11-19 14:47:08 +00:00
|
|
|
}
|
2009-01-29 17:51:02 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_free (priv->server_ip);
|
|
|
|
g_mutex_clear (&priv->lock);
|
2010-03-16 17:33:23 +00:00
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtsp_client_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
2009-02-10 15:24:13 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2009-02-10 15:24:13 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SESSION_POOL:
|
|
|
|
g_value_take_object (value, gst_rtsp_client_get_session_pool (client));
|
|
|
|
break;
|
2012-11-26 11:34:05 +00:00
|
|
|
case PROP_MOUNT_POINTS:
|
|
|
|
g_value_take_object (value, gst_rtsp_client_get_mount_points (client));
|
2009-02-10 15:24:13 +00:00
|
|
|
break;
|
2012-10-10 09:06:02 +00:00
|
|
|
case PROP_USE_CLIENT_SETTINGS:
|
|
|
|
g_value_set_boolean (value,
|
|
|
|
gst_rtsp_client_get_use_client_settings (client));
|
|
|
|
break;
|
2009-02-10 15:24:13 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2009-02-10 15:24:13 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SESSION_POOL:
|
|
|
|
gst_rtsp_client_set_session_pool (client, g_value_get_object (value));
|
|
|
|
break;
|
2012-11-26 11:34:05 +00:00
|
|
|
case PROP_MOUNT_POINTS:
|
|
|
|
gst_rtsp_client_set_mount_points (client, g_value_get_object (value));
|
2009-02-10 15:24:13 +00:00
|
|
|
break;
|
2012-10-10 09:06:02 +00:00
|
|
|
case PROP_USE_CLIENT_SETTINGS:
|
|
|
|
gst_rtsp_client_set_use_client_settings (client,
|
|
|
|
g_value_get_boolean (value));
|
|
|
|
break;
|
2009-02-10 15:24:13 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_new:
|
|
|
|
*
|
|
|
|
* Create a new #GstRTSPClient instance.
|
2010-12-30 11:41:31 +00:00
|
|
|
*
|
|
|
|
* Returns: a new #GstRTSPClient
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
GstRTSPClient *
|
|
|
|
gst_rtsp_client_new (void)
|
|
|
|
{
|
|
|
|
GstRTSPClient *result;
|
|
|
|
|
|
|
|
result = g_object_new (GST_TYPE_RTSP_CLIENT, NULL);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
send_response (GstRTSPClient * client, GstRTSPSession * session,
|
2012-11-26 12:16:59 +00:00
|
|
|
GstRTSPMessage * response, gboolean close)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_add_header (response, GST_RTSP_HDR_SERVER,
|
|
|
|
"GStreamer RTSP server");
|
2009-02-04 16:00:42 +00:00
|
|
|
|
2009-03-11 18:38:06 +00:00
|
|
|
/* remove any previous header */
|
|
|
|
gst_rtsp_message_remove_header (response, GST_RTSP_HDR_SESSION, -1);
|
2009-02-10 15:24:13 +00:00
|
|
|
|
2009-02-13 11:57:45 +00:00
|
|
|
/* add the new session header for new session ids */
|
|
|
|
if (session) {
|
2012-11-12 11:40:34 +00:00
|
|
|
gst_rtsp_message_take_header (response, GST_RTSP_HDR_SESSION,
|
|
|
|
gst_rtsp_session_get_header (session));
|
2009-02-13 11:57:45 +00:00
|
|
|
}
|
2009-11-21 00:17:25 +00:00
|
|
|
|
|
|
|
if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
|
|
|
|
gst_rtsp_message_dump (response);
|
|
|
|
}
|
2009-02-13 11:57:45 +00:00
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
if (close)
|
2012-11-26 12:35:48 +00:00
|
|
|
gst_rtsp_message_add_header (response, GST_RTSP_HDR_CONNECTION, "close");
|
2012-11-26 16:20:39 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->send_func)
|
|
|
|
priv->send_func (client, response, close, priv->send_data);
|
2012-11-26 16:20:39 +00:00
|
|
|
|
2009-01-30 16:06:26 +00:00
|
|
|
gst_rtsp_message_unset (response);
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code,
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPClientState * state)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_init_response (state->response, code,
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_status_as_text (code), state->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, NULL, state->response, FALSE);
|
2009-01-29 17:51:02 +00:00
|
|
|
}
|
|
|
|
|
2011-01-11 23:35:28 +00:00
|
|
|
static void
|
2011-01-12 12:57:09 +00:00
|
|
|
handle_unauthorized_request (GstRTSPClient * client, GstRTSPAuth * auth,
|
|
|
|
GstRTSPClientState * state)
|
2011-01-11 23:17:54 +00:00
|
|
|
{
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_init_response (state->response, GST_RTSP_STS_UNAUTHORIZED,
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_status_as_text (GST_RTSP_STS_UNAUTHORIZED), state->request);
|
|
|
|
|
2011-01-12 12:57:09 +00:00
|
|
|
if (auth) {
|
2011-01-11 23:35:28 +00:00
|
|
|
/* and let the authentication manager setup the auth tokens */
|
2011-01-12 12:57:09 +00:00
|
|
|
gst_rtsp_auth_setup_auth (auth, client, 0, state);
|
2011-01-11 23:35:28 +00:00
|
|
|
}
|
2011-01-11 23:17:54 +00:00
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, state->session, state->response, FALSE);
|
2011-01-11 23:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
static gboolean
|
2009-05-26 17:01:10 +00:00
|
|
|
compare_uri (const GstRTSPUrl * uri1, const GstRTSPUrl * uri2)
|
2009-01-29 17:51:02 +00:00
|
|
|
{
|
|
|
|
if (uri1 == NULL || uri2 == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (strcmp (uri1->abspath, uri2->abspath))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
/* this function is called to initially find the media for the DESCRIBE request
|
|
|
|
* but is cached for when the same client (without breaking the connection) is
|
|
|
|
* doing a setup for the exact same url. */
|
2009-01-29 12:31:27 +00:00
|
|
|
static GstRTSPMedia *
|
2011-01-12 12:16:08 +00:00
|
|
|
find_media (GstRTSPClient * client, GstRTSPClientState * state)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-01-29 12:31:27 +00:00
|
|
|
GstRTSPMediaFactory *factory;
|
|
|
|
GstRTSPMedia *media;
|
2011-01-12 12:57:09 +00:00
|
|
|
GstRTSPAuth *auth;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (!compare_uri (priv->uri, state->uri)) {
|
2009-01-29 17:51:02 +00:00
|
|
|
/* remove any previously cached values before we try to construct a new
|
|
|
|
* media for uri */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->uri)
|
|
|
|
gst_rtsp_url_free (priv->uri);
|
|
|
|
priv->uri = NULL;
|
|
|
|
if (priv->media) {
|
|
|
|
gst_rtsp_media_unprepare (priv->media);
|
|
|
|
g_object_unref (priv->media);
|
2012-11-19 14:47:08 +00:00
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->media = NULL;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (!priv->mount_points)
|
2012-11-26 11:34:05 +00:00
|
|
|
goto no_mount_points;
|
2009-01-29 17:51:02 +00:00
|
|
|
|
|
|
|
/* find the factory for the uri first */
|
2009-05-26 17:01:10 +00:00
|
|
|
if (!(factory =
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_mount_points_find_factory (priv->mount_points,
|
2011-01-12 12:16:08 +00:00
|
|
|
state->uri)))
|
2009-01-29 17:51:02 +00:00
|
|
|
goto no_factory;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2011-01-12 12:57:09 +00:00
|
|
|
/* check if we have access to the factory */
|
|
|
|
if ((auth = gst_rtsp_media_factory_get_auth (factory))) {
|
2012-11-28 10:05:08 +00:00
|
|
|
state->factory = factory;
|
|
|
|
|
2011-01-12 12:57:09 +00:00
|
|
|
if (!gst_rtsp_auth_check (auth, client, 0, state))
|
|
|
|
goto not_allowed;
|
|
|
|
|
2012-11-28 10:05:08 +00:00
|
|
|
state->factory = NULL;
|
2011-01-12 12:57:09 +00:00
|
|
|
g_object_unref (auth);
|
|
|
|
}
|
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
/* prepare the media and add it to the pipeline */
|
2011-01-12 12:16:08 +00:00
|
|
|
if (!(media = gst_rtsp_media_factory_construct (factory, state->uri)))
|
2009-01-29 17:51:02 +00:00
|
|
|
goto no_media;
|
|
|
|
|
2011-01-12 12:57:09 +00:00
|
|
|
g_object_unref (factory);
|
2011-06-27 18:26:26 +00:00
|
|
|
factory = NULL;
|
2011-01-12 12:57:09 +00:00
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
/* prepare the media */
|
|
|
|
if (!(gst_rtsp_media_prepare (media)))
|
|
|
|
goto no_prepare;
|
|
|
|
|
|
|
|
/* now keep track of the uri and the media */
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->uri = gst_rtsp_url_copy (state->uri);
|
|
|
|
priv->media = media;
|
2012-11-28 10:05:08 +00:00
|
|
|
state->media = media;
|
2009-05-26 17:01:10 +00:00
|
|
|
} else {
|
2009-01-29 17:51:02 +00:00
|
|
|
/* we have seen this uri before, used cached media */
|
2012-11-29 10:11:05 +00:00
|
|
|
media = priv->media;
|
2011-01-12 12:16:08 +00:00
|
|
|
state->media = media;
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("reusing cached media %p", media);
|
2009-01-29 17:51:02 +00:00
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
if (media)
|
|
|
|
g_object_ref (media);
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
return media;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-11-26 11:34:05 +00:00
|
|
|
no_mount_points:
|
2009-01-29 17:51:02 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no mount points configured", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
|
2009-01-29 17:51:02 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_factory:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no factory for uri", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
|
2009-01-29 12:31:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-12 12:57:09 +00:00
|
|
|
not_allowed:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: unauthorized request", client);
|
2011-01-12 12:57:09 +00:00
|
|
|
handle_unauthorized_request (client, auth, state);
|
|
|
|
g_object_unref (factory);
|
2012-11-28 10:05:08 +00:00
|
|
|
state->factory = NULL;
|
2011-01-12 12:57:09 +00:00
|
|
|
g_object_unref (auth);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_media:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: can't create media", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_unref (factory);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
no_prepare:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: can't prepare media", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_unref (media);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
static gboolean
|
2009-05-26 17:01:10 +00:00
|
|
|
do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-11 15:45:12 +00:00
|
|
|
GstRTSPMessage message = { 0 };
|
2012-02-13 11:06:33 +00:00
|
|
|
GstMapInfo map_info;
|
2009-03-11 15:45:12 +00:00
|
|
|
guint8 *data;
|
2011-04-26 17:22:50 +00:00
|
|
|
guint usize;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
gst_rtsp_message_init_data (&message, channel);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/* FIXME, need some sort of iovec RTSPMessage here */
|
2012-02-13 11:06:33 +00:00
|
|
|
if (!gst_buffer_map (buffer, &map_info, GST_MAP_READ))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gst_rtsp_message_take_body (&message, map_info.data, map_info.size);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->send_func)
|
|
|
|
priv->send_func (client, &message, FALSE, priv->send_data);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2011-04-26 17:22:50 +00:00
|
|
|
gst_rtsp_message_steal_body (&message, &data, &usize);
|
2012-02-13 11:06:33 +00:00
|
|
|
gst_buffer_unmap (buffer, &map_info);
|
2011-04-26 17:22:50 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
gst_rtsp_message_unset (&message);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-25 19:29:58 +00:00
|
|
|
link_transport (GstRTSPClient * client, GstRTSPSession * session,
|
|
|
|
GstRTSPStreamTransport * trans)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_DEBUG ("client %p: linking transport %p", client, trans);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
gst_rtsp_stream_transport_set_callbacks (trans,
|
|
|
|
(GstRTSPSendFunc) do_send_data,
|
2011-12-09 09:53:30 +00:00
|
|
|
(GstRTSPSendFunc) do_send_data, client, NULL);
|
2012-10-27 21:49:24 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->transports = g_list_prepend (priv->transports, trans);
|
2012-10-27 21:49:24 +00:00
|
|
|
|
2010-04-06 15:08:40 +00:00
|
|
|
/* make sure our session can't expire */
|
|
|
|
gst_rtsp_session_prevent_expire (session);
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-25 19:29:58 +00:00
|
|
|
unlink_transport (GstRTSPClient * client, GstRTSPSession * session,
|
|
|
|
GstRTSPStreamTransport * trans)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_DEBUG ("client %p: unlinking transport %p", client, trans);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
gst_rtsp_stream_transport_set_callbacks (trans, NULL, NULL, NULL, NULL);
|
2012-10-27 21:49:24 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->transports = g_list_remove (priv->transports, trans);
|
2012-10-27 21:49:24 +00:00
|
|
|
|
2010-04-06 15:08:40 +00:00
|
|
|
/* our session can now expire */
|
|
|
|
gst_rtsp_session_allow_expire (session);
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-25 19:29:58 +00:00
|
|
|
unlink_session_transports (GstRTSPClient * client, GstRTSPSession * session,
|
2010-12-11 09:48:42 +00:00
|
|
|
GstRTSPSessionMedia * media)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
|
|
|
guint n_streams, i;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
n_streams =
|
|
|
|
gst_rtsp_media_n_streams (gst_rtsp_session_media_get_media (media));
|
2009-03-11 15:45:12 +00:00
|
|
|
for (i = 0; i < n_streams; i++) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStreamTransport *trans;
|
2012-11-29 10:11:05 +00:00
|
|
|
const GstRTSPTransport *tr;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
/* get the transport, if there is no transport configured, skip this stream */
|
2012-10-27 22:23:57 +00:00
|
|
|
trans = gst_rtsp_session_media_get_transport (media, i);
|
|
|
|
if (trans == NULL)
|
2009-03-11 15:45:12 +00:00
|
|
|
continue;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
tr = gst_rtsp_stream_transport_get_transport (trans);
|
2012-10-27 22:23:57 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
|
|
|
|
/* for TCP, unlink the stream from the TCP connection of the client */
|
2012-10-25 19:29:58 +00:00
|
|
|
unlink_transport (client, session, trans);
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 13:45:56 +00:00
|
|
|
static void
|
|
|
|
close_connection (GstRTSPClient * client)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-12-11 09:48:42 +00:00
|
|
|
const gchar *tunnelid;
|
2010-04-06 13:45:56 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("client %p: closing connection", client);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_lock (&tunnels_lock);
|
2010-04-06 13:45:56 +00:00
|
|
|
/* remove from tunnelids */
|
|
|
|
g_hash_table_remove (tunnels, tunnelid);
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2010-04-06 13:45:56 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_connection_close (priv->connection);
|
2010-04-06 13:45:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
static gboolean
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_teardown_request (GstRTSPClient * client, GstRTSPClientState * state)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPSession *session;
|
2009-01-29 12:31:27 +00:00
|
|
|
GstRTSPSessionMedia *media;
|
|
|
|
GstRTSPStatusCode code;
|
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
if (!state->session)
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_session;
|
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
session = state->session;
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* get a handle to the configuration of the media in the session */
|
2011-01-12 12:16:08 +00:00
|
|
|
media = gst_rtsp_session_get_media (session, state->uri);
|
2009-01-08 15:28:24 +00:00
|
|
|
if (!media)
|
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
state->sessmedia = media;
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* unlink the all TCP callbacks */
|
2012-10-25 19:29:58 +00:00
|
|
|
unlink_session_transports (client, session, media);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-03-11 19:03:06 +00:00
|
|
|
/* remove the session from the watched sessions */
|
2009-05-26 17:01:10 +00:00
|
|
|
g_object_weak_unref (G_OBJECT (session),
|
|
|
|
(GWeakNotify) client_session_finalized, client);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->sessions = g_list_remove (priv->sessions, session);
|
2009-03-11 19:03:06 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
gst_rtsp_session_media_set_state (media, GST_STATE_NULL);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
/* unmanage the media in the session, returns false if all media session
|
|
|
|
* are torn down. */
|
|
|
|
if (!gst_rtsp_session_release_media (session, media)) {
|
|
|
|
/* remove the session */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_session_pool_remove (priv->session_pool, session);
|
2009-02-04 16:00:42 +00:00
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
/* construct the response now */
|
|
|
|
code = GST_RTSP_STS_OK;
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_init_response (state->response, code,
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_status_as_text (code), state->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, session, state->response, TRUE);
|
2009-02-13 11:57:45 +00:00
|
|
|
|
2012-09-03 17:48:14 +00:00
|
|
|
/* we emit the signal before closing the connection */
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_TEARDOWN_REQUEST],
|
|
|
|
0, state);
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-29 12:31:27 +00:00
|
|
|
no_session:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no session", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-08 15:28:24 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no media for uri", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
|
2009-01-08 15:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
static gboolean
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_get_param_request (GstRTSPClient * client, GstRTSPClientState * state)
|
2009-06-09 22:01:07 +00:00
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
res = gst_rtsp_message_get_body (state->request, &data, &size);
|
2009-06-09 22:01:07 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
/* no body, keep-alive request */
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_OK, state);
|
2009-06-09 22:01:07 +00:00
|
|
|
} else {
|
|
|
|
/* there is a body, handle the params */
|
2011-01-12 12:16:08 +00:00
|
|
|
res = gst_rtsp_params_get (client, state);
|
2009-06-09 22:01:07 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, state->session, state->response, FALSE);
|
2009-06-09 22:01:07 +00:00
|
|
|
}
|
2012-09-03 17:48:14 +00:00
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_GET_PARAMETER_REQUEST],
|
|
|
|
0, state);
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
bad_request:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: bad request", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
|
2009-06-09 22:01:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_set_param_request (GstRTSPClient * client, GstRTSPClientState * state)
|
2009-06-09 22:01:07 +00:00
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
res = gst_rtsp_message_get_body (state->request, &data, &size);
|
2009-06-09 22:01:07 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
/* no body, keep-alive request */
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_OK, state);
|
2009-06-09 22:01:07 +00:00
|
|
|
} else {
|
|
|
|
/* there is a body, handle the params */
|
2011-01-12 12:16:08 +00:00
|
|
|
res = gst_rtsp_params_set (client, state);
|
2009-06-09 22:01:07 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, state->session, state->response, FALSE);
|
2009-06-09 22:01:07 +00:00
|
|
|
}
|
2012-09-03 17:48:14 +00:00
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SET_PARAMETER_REQUEST],
|
|
|
|
0, state);
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
bad_request:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: bad request", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
|
2009-06-09 22:01:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static gboolean
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_pause_request (GstRTSPClient * client, GstRTSPClientState * state)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPSession *session;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPSessionMedia *media;
|
|
|
|
GstRTSPStatusCode code;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPState rtspstate;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
if (!(session = state->session))
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_session;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* get a handle to the configuration of the media in the session */
|
2011-01-12 12:16:08 +00:00
|
|
|
media = gst_rtsp_session_get_media (session, state->uri);
|
2009-01-08 15:28:24 +00:00
|
|
|
if (!media)
|
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
state->sessmedia = media;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
rtspstate = gst_rtsp_session_media_get_rtsp_state (media);
|
2009-02-03 18:32:38 +00:00
|
|
|
/* the session state must be playing or recording */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (rtspstate != GST_RTSP_STATE_PLAYING &&
|
|
|
|
rtspstate != GST_RTSP_STATE_RECORDING)
|
2009-02-03 18:32:38 +00:00
|
|
|
goto invalid_state;
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* unlink the all TCP callbacks */
|
2012-10-25 19:29:58 +00:00
|
|
|
unlink_session_transports (client, session, media);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
/* then pause sending */
|
|
|
|
gst_rtsp_session_media_set_state (media, GST_STATE_PAUSED);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* construct the response now */
|
|
|
|
code = GST_RTSP_STS_OK;
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_init_response (state->response, code,
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_status_as_text (code), state->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, session, state->response, FALSE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* the state is now READY */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_session_media_set_rtsp_state (media, GST_RTSP_STATE_READY);
|
2009-02-03 18:32:38 +00:00
|
|
|
|
2012-09-03 17:48:14 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PAUSE_REQUEST],
|
|
|
|
0, state);
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-29 12:31:27 +00:00
|
|
|
no_session:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no seesion", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-08 15:28:24 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no media for uri", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
|
2009-01-08 15:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-02-03 18:32:38 +00:00
|
|
|
invalid_state:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: not PLAYING or RECORDING", client);
|
2009-05-26 17:01:10 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
|
2011-01-12 12:16:08 +00:00
|
|
|
state);
|
2009-02-03 18:32:38 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_play_request (GstRTSPClient * client, GstRTSPClientState * state)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPSession *session;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPSessionMedia *media;
|
|
|
|
GstRTSPStatusCode code;
|
|
|
|
GString *rtpinfo;
|
2009-05-23 14:17:02 +00:00
|
|
|
guint n_streams, i, infocount;
|
2009-02-04 16:00:42 +00:00
|
|
|
gchar *str;
|
2009-03-12 19:32:14 +00:00
|
|
|
GstRTSPTimeRange *range;
|
|
|
|
GstRTSPResult res;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPState rtspstate;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
if (!(session = state->session))
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_session;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* get a handle to the configuration of the media in the session */
|
2011-01-12 12:16:08 +00:00
|
|
|
media = gst_rtsp_session_get_media (session, state->uri);
|
2009-01-08 15:28:24 +00:00
|
|
|
if (!media)
|
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
state->sessmedia = media;
|
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* the session state must be playing or ready */
|
2012-11-29 10:11:05 +00:00
|
|
|
rtspstate = gst_rtsp_session_media_get_rtsp_state (media);
|
|
|
|
if (rtspstate != GST_RTSP_STATE_PLAYING && rtspstate != GST_RTSP_STATE_READY)
|
2009-02-03 18:32:38 +00:00
|
|
|
goto invalid_state;
|
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
/* parse the range header if we have one */
|
2011-01-12 12:16:08 +00:00
|
|
|
res =
|
|
|
|
gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_RANGE, &str, 0);
|
2009-03-12 19:32:14 +00:00
|
|
|
if (res == GST_RTSP_OK) {
|
|
|
|
if (gst_rtsp_range_parse (str, &range) == GST_RTSP_OK) {
|
|
|
|
/* we have a range, seek to the position */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_media_seek (gst_rtsp_session_media_get_media (media), range);
|
2009-03-12 19:32:14 +00:00
|
|
|
gst_rtsp_range_free (range);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* grab RTPInfo from the payloaders now */
|
|
|
|
rtpinfo = g_string_new ("");
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
n_streams =
|
|
|
|
gst_rtsp_media_n_streams (gst_rtsp_session_media_get_media (media));
|
2009-05-23 14:17:02 +00:00
|
|
|
for (i = 0, infocount = 0; i < n_streams; i++) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStreamTransport *trans;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStream *stream;
|
|
|
|
const GstRTSPTransport *tr;
|
2009-01-22 16:58:19 +00:00
|
|
|
gchar *uristr;
|
2012-10-25 19:29:58 +00:00
|
|
|
guint rtptime, seq;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* get the transport, if there is no transport configured, skip this stream */
|
2012-10-27 22:23:57 +00:00
|
|
|
trans = gst_rtsp_session_media_get_transport (media, i);
|
|
|
|
if (trans == NULL) {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("stream %d is not configured", i);
|
2009-03-11 15:45:12 +00:00
|
|
|
continue;
|
2009-05-26 17:01:10 +00:00
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
tr = gst_rtsp_stream_transport_get_transport (trans);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
|
|
|
|
/* for TCP, link the stream to the TCP connection of the client */
|
2012-10-25 19:29:58 +00:00
|
|
|
link_transport (client, session, trans);
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
stream = gst_rtsp_stream_transport_get_stream (trans);
|
|
|
|
if (gst_rtsp_stream_get_rtpinfo (stream, &rtptime, &seq)) {
|
2009-05-23 14:17:02 +00:00
|
|
|
if (infocount > 0)
|
|
|
|
g_string_append (rtpinfo, ", ");
|
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
uristr = gst_rtsp_url_get_request_uri (state->uri);
|
2009-05-26 17:01:10 +00:00
|
|
|
g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u",
|
2012-10-25 19:29:58 +00:00
|
|
|
uristr, i, seq, rtptime);
|
2009-05-23 14:17:02 +00:00
|
|
|
g_free (uristr);
|
|
|
|
|
|
|
|
infocount++;
|
2009-05-26 17:01:10 +00:00
|
|
|
} else {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("RTP-Info cannot be determined for stream %d", i);
|
2009-05-23 14:30:55 +00:00
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* construct the response now */
|
|
|
|
code = GST_RTSP_STS_OK;
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_init_response (state->response, code,
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_status_as_text (code), state->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* add the RTP-Info header */
|
2009-05-23 14:30:55 +00:00
|
|
|
if (infocount > 0) {
|
|
|
|
str = g_string_free (rtpinfo, FALSE);
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RTP_INFO, str);
|
2009-05-26 17:01:10 +00:00
|
|
|
} else {
|
2009-05-23 14:30:55 +00:00
|
|
|
g_string_free (rtpinfo, TRUE);
|
|
|
|
}
|
2009-02-04 16:00:42 +00:00
|
|
|
|
|
|
|
/* add the range */
|
2012-11-29 10:11:05 +00:00
|
|
|
str =
|
|
|
|
gst_rtsp_media_get_range_string (gst_rtsp_session_media_get_media (media),
|
|
|
|
TRUE);
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_take_header (state->response, GST_RTSP_HDR_RANGE, str);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, session, state->response, FALSE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* start playing after sending the request */
|
2009-03-11 15:45:12 +00:00
|
|
|
gst_rtsp_session_media_set_state (media, GST_STATE_PLAYING);
|
2009-02-03 18:32:38 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_session_media_set_rtsp_state (media, GST_RTSP_STATE_PLAYING);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-09-03 17:48:14 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PLAY_REQUEST],
|
|
|
|
0, state);
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-29 12:31:27 +00:00
|
|
|
no_session:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no session", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-08 15:28:24 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: media not found", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
|
2009-01-08 15:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-02-03 18:32:38 +00:00
|
|
|
invalid_state:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: not PLAYING or READY", client);
|
2009-05-26 17:01:10 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
|
2011-01-12 12:16:08 +00:00
|
|
|
state);
|
2009-02-03 18:32:38 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
static void
|
|
|
|
do_keepalive (GstRTSPSession * session)
|
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("keep session %p alive", session);
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_session_touch (session);
|
|
|
|
}
|
|
|
|
|
2012-10-27 19:26:55 +00:00
|
|
|
/* parse @transport and return a valid transport in @tr. only transports
|
|
|
|
* from @supported are returned. Returns FALSE if no valid transport
|
|
|
|
* was found. */
|
|
|
|
static gboolean
|
|
|
|
parse_transport (const char *transport, GstRTSPLowerTrans supported,
|
|
|
|
GstRTSPTransport * tr)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gboolean res;
|
|
|
|
gchar **transports;
|
|
|
|
|
|
|
|
res = FALSE;
|
|
|
|
gst_rtsp_transport_init (tr);
|
|
|
|
|
2012-11-15 15:15:20 +00:00
|
|
|
GST_DEBUG ("parsing transports %s", transport);
|
2012-10-27 19:26:55 +00:00
|
|
|
|
|
|
|
transports = g_strsplit (transport, ",", 0);
|
|
|
|
|
|
|
|
/* loop through the transports, try to parse */
|
|
|
|
for (i = 0; transports[i]; i++) {
|
|
|
|
res = gst_rtsp_transport_parse (transports[i], tr);
|
|
|
|
if (res != GST_RTSP_OK) {
|
|
|
|
/* no valid transport, search some more */
|
|
|
|
GST_WARNING ("could not parse transport %s", transports[i]);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have a transport, see if it's RTP/AVP */
|
|
|
|
if (tr->trans != GST_RTSP_TRANS_RTP || tr->profile != GST_RTSP_PROFILE_AVP) {
|
|
|
|
GST_WARNING ("invalid transport %s", transports[i]);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(tr->lower_transport & supported)) {
|
|
|
|
GST_WARNING ("unsupported transport %s", transports[i]);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have a valid transport */
|
|
|
|
GST_INFO ("found valid transport %s", transports[i]);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
next:
|
|
|
|
gst_rtsp_transport_init (tr);
|
|
|
|
}
|
|
|
|
g_strfreev (transports);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:26:30 +00:00
|
|
|
static gboolean
|
2012-11-15 14:29:35 +00:00
|
|
|
handle_blocksize (GstRTSPMedia * media, GstRTSPStream * stream,
|
|
|
|
GstRTSPMessage * request)
|
2012-07-03 11:26:30 +00:00
|
|
|
{
|
|
|
|
gchar *blocksize_str;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_BLOCKSIZE,
|
2012-07-10 09:39:58 +00:00
|
|
|
&blocksize_str, 0) == GST_RTSP_OK) {
|
2012-07-03 11:26:30 +00:00
|
|
|
guint64 blocksize;
|
|
|
|
gchar *end;
|
|
|
|
|
|
|
|
blocksize = g_ascii_strtoull (blocksize_str, &end, 10);
|
|
|
|
if (end == blocksize_str) {
|
|
|
|
GST_ERROR ("failed to parse blocksize");
|
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
2012-10-27 19:05:03 +00:00
|
|
|
/* we don't want to change the mtu when this media
|
|
|
|
* can be shared because it impacts other clients */
|
|
|
|
if (gst_rtsp_media_is_shared (media))
|
|
|
|
return TRUE;
|
|
|
|
|
2012-07-03 11:26:30 +00:00
|
|
|
if (blocksize > G_MAXUINT)
|
|
|
|
blocksize = G_MAXUINT;
|
2012-11-15 14:29:35 +00:00
|
|
|
gst_rtsp_stream_set_mtu (stream, blocksize);
|
2012-07-03 11:26:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
static gboolean
|
|
|
|
configure_client_transport (GstRTSPClient * client, GstRTSPClientState * state,
|
2012-11-15 15:18:29 +00:00
|
|
|
GstRTSPTransport * ct)
|
2012-10-27 21:49:24 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* we have a valid transport now, set the destination of the client. */
|
|
|
|
if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
|
2012-11-29 10:11:05 +00:00
|
|
|
if (ct->destination == NULL || !priv->use_client_settings) {
|
2012-11-15 15:18:29 +00:00
|
|
|
GstRTSPAddress *addr;
|
2012-11-14 16:23:59 +00:00
|
|
|
|
2012-11-15 15:18:29 +00:00
|
|
|
addr = gst_rtsp_stream_get_address (state->stream);
|
|
|
|
if (addr == NULL)
|
2012-11-14 16:23:59 +00:00
|
|
|
goto no_address;
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
g_free (ct->destination);
|
2012-11-15 15:18:29 +00:00
|
|
|
ct->destination = g_strdup (addr->address);
|
|
|
|
ct->port.min = addr->port;
|
|
|
|
ct->port.max = addr->port + addr->n_ports - 1;
|
|
|
|
ct->ttl = addr->ttl;
|
2012-10-27 21:49:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GstRTSPUrl *url;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
url = gst_rtsp_connection_get_url (priv->connection);
|
2012-10-27 21:49:24 +00:00
|
|
|
g_free (ct->destination);
|
|
|
|
ct->destination = g_strdup (url->host);
|
|
|
|
|
|
|
|
if (ct->lower_transport & GST_RTSP_LOWER_TRANS_TCP) {
|
|
|
|
/* check if the client selected channels for TCP */
|
|
|
|
if (ct->interleaved.min == -1 || ct->interleaved.max == -1) {
|
|
|
|
gst_rtsp_session_media_alloc_channels (state->sessmedia,
|
|
|
|
&ct->interleaved);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2012-11-14 16:23:59 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_address:
|
|
|
|
{
|
2012-11-15 15:18:29 +00:00
|
|
|
GST_ERROR_OBJECT (client, "failed to acquire address for stream");
|
2012-11-14 16:23:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-27 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPTransport *
|
|
|
|
make_server_transport (GstRTSPClient * client, GstRTSPClientState * state,
|
|
|
|
GstRTSPTransport * ct)
|
|
|
|
{
|
|
|
|
GstRTSPTransport *st;
|
|
|
|
|
|
|
|
/* prepare the server transport */
|
|
|
|
gst_rtsp_transport_new (&st);
|
|
|
|
|
|
|
|
st->trans = ct->trans;
|
|
|
|
st->profile = ct->profile;
|
|
|
|
st->lower_transport = ct->lower_transport;
|
|
|
|
|
|
|
|
switch (st->lower_transport) {
|
|
|
|
case GST_RTSP_LOWER_TRANS_UDP:
|
|
|
|
st->client_port = ct->client_port;
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_stream_get_server_port (state->stream, &st->server_port);
|
2012-10-27 21:49:24 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_LOWER_TRANS_UDP_MCAST:
|
|
|
|
st->port = ct->port;
|
|
|
|
st->destination = g_strdup (ct->destination);
|
|
|
|
st->ttl = ct->ttl;
|
|
|
|
break;
|
|
|
|
case GST_RTSP_LOWER_TRANS_TCP:
|
|
|
|
st->interleaved = ct->interleaved;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_stream_get_ssrc (state->stream, &st->ssrc);
|
2012-10-27 21:49:24 +00:00
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static gboolean
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_setup_request (GstRTSPClient * client, GstRTSPClientState * state)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPResult res;
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPUrl *uri;
|
2008-10-09 12:29:12 +00:00
|
|
|
gchar *transport;
|
|
|
|
GstRTSPTransport *ct, *st;
|
|
|
|
GstRTSPLowerTrans supported;
|
|
|
|
GstRTSPStatusCode code;
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPSession *session;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStreamTransport *trans;
|
2008-10-09 12:29:12 +00:00
|
|
|
gchar *trans_str, *pos;
|
|
|
|
guint streamid;
|
2012-10-27 21:49:24 +00:00
|
|
|
GstRTSPSessionMedia *sessmedia;
|
|
|
|
GstRTSPMedia *media;
|
|
|
|
GstRTSPStream *stream;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPState rtspstate;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
uri = state->uri;
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
/* the uri contains the stream number we added in the SDP config, which is
|
2012-10-27 19:26:55 +00:00
|
|
|
* always /stream=%d so we need to strip that off
|
2009-01-22 16:58:19 +00:00
|
|
|
* parse the stream we need to configure, look for the stream in the abspath
|
2009-01-22 14:33:29 +00:00
|
|
|
* first and then in the query. */
|
2010-03-09 12:42:50 +00:00
|
|
|
if (uri->abspath == NULL || !(pos = strstr (uri->abspath, "/stream="))) {
|
|
|
|
if (uri->query == NULL || !(pos = strstr (uri->query, "/stream=")))
|
2009-01-22 14:33:29 +00:00
|
|
|
goto bad_request;
|
|
|
|
}
|
|
|
|
|
2012-10-27 19:26:55 +00:00
|
|
|
/* we can mofify the parsed uri in place */
|
2009-01-22 14:33:29 +00:00
|
|
|
*pos = '\0';
|
|
|
|
|
|
|
|
pos += strlen ("/stream=");
|
|
|
|
if (sscanf (pos, "%u", &streamid) != 1)
|
|
|
|
goto bad_request;
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* parse the transport */
|
2009-05-26 17:01:10 +00:00
|
|
|
res =
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_TRANSPORT,
|
|
|
|
&transport, 0);
|
2008-10-09 12:29:12 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_transport;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_transport_new (&ct);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2010-03-05 12:31:37 +00:00
|
|
|
/* our supported transports */
|
|
|
|
supported = GST_RTSP_LOWER_TRANS_UDP |
|
2010-03-16 17:33:23 +00:00
|
|
|
GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP;
|
2010-03-05 12:31:37 +00:00
|
|
|
|
2012-10-27 19:26:55 +00:00
|
|
|
/* parse and find a usable supported transport */
|
|
|
|
if (!parse_transport (transport, supported, ct))
|
2008-10-09 12:29:12 +00:00
|
|
|
goto unsupported_transports;
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* we create the session after parsing stuff so that we don't make
|
|
|
|
* a session for malformed requests */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->session_pool == NULL)
|
2009-01-29 17:51:02 +00:00
|
|
|
goto no_pool;
|
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
session = state->session;
|
|
|
|
|
2009-02-13 18:52:05 +00:00
|
|
|
if (session) {
|
|
|
|
g_object_ref (session);
|
2009-02-04 16:00:42 +00:00
|
|
|
/* get a handle to the configuration of the media in the session, this can
|
|
|
|
* return NULL if this is a new url to manage in this session. */
|
2012-10-27 21:49:24 +00:00
|
|
|
sessmedia = gst_rtsp_session_get_media (session, uri);
|
2009-05-26 17:01:10 +00:00
|
|
|
} else {
|
2008-10-09 12:29:12 +00:00
|
|
|
/* create a session if this fails we probably reached our session limit or
|
|
|
|
* something. */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (!(session = gst_rtsp_session_pool_create (priv->session_pool)))
|
2008-10-09 12:29:12 +00:00
|
|
|
goto service_unavailable;
|
2009-02-04 16:00:42 +00:00
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
state->session = session;
|
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
/* we need a new media configuration in this session */
|
2012-10-27 21:49:24 +00:00
|
|
|
sessmedia = NULL;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
/* we have no media, find one and manage it */
|
2012-10-27 21:49:24 +00:00
|
|
|
if (sessmedia == NULL) {
|
2009-01-29 12:31:27 +00:00
|
|
|
/* get a handle to the configuration of the media in the session */
|
2012-10-27 21:49:24 +00:00
|
|
|
if ((media = find_media (client, state))) {
|
2009-01-30 15:24:10 +00:00
|
|
|
/* manage the media in our session now */
|
2012-10-27 21:49:24 +00:00
|
|
|
sessmedia = gst_rtsp_session_manage_media (session, uri, media);
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-04 16:00:42 +00:00
|
|
|
|
|
|
|
/* if we stil have no media, error */
|
2012-10-27 21:49:24 +00:00
|
|
|
if (sessmedia == NULL)
|
2009-01-08 15:28:24 +00:00
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
state->sessmedia = sessmedia;
|
2012-11-29 10:11:05 +00:00
|
|
|
state->media = media = gst_rtsp_session_media_get_media (sessmedia);
|
2011-01-12 12:16:08 +00:00
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* now get the stream */
|
|
|
|
stream = gst_rtsp_media_get_stream (media, streamid);
|
|
|
|
if (stream == NULL)
|
|
|
|
goto not_found;
|
2012-07-03 11:26:30 +00:00
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
state->stream = stream;
|
2011-08-16 10:51:44 +00:00
|
|
|
|
2012-11-15 14:29:35 +00:00
|
|
|
/* set blocksize on this stream */
|
|
|
|
if (!handle_blocksize (media, stream, state->request))
|
2012-10-27 21:49:24 +00:00
|
|
|
goto invalid_blocksize;
|
2009-07-27 17:42:44 +00:00
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* update the client transport */
|
2012-11-15 15:18:29 +00:00
|
|
|
if (!configure_client_transport (client, state, ct))
|
2012-11-14 16:23:59 +00:00
|
|
|
goto unsupported_client_transport;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* set in the session media transport */
|
2012-11-15 15:18:29 +00:00
|
|
|
trans = gst_rtsp_session_media_set_transport (sessmedia, stream, ct);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
/* configure keepalive for this transport */
|
2012-10-25 19:29:58 +00:00
|
|
|
gst_rtsp_stream_transport_set_keepalive (trans,
|
2010-03-16 17:33:23 +00:00
|
|
|
(GstRTSPKeepAliveFunc) do_keepalive, session, NULL);
|
2009-05-26 17:01:10 +00:00
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* create and serialize the server transport */
|
|
|
|
st = make_server_transport (client, state, ct);
|
2008-10-09 12:29:12 +00:00
|
|
|
trans_str = gst_rtsp_transport_as_text (st);
|
2009-01-30 16:06:26 +00:00
|
|
|
gst_rtsp_transport_free (st);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* construct the response now */
|
|
|
|
code = GST_RTSP_STS_OK;
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_init_response (state->response, code,
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_status_as_text (code), state->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_TRANSPORT,
|
|
|
|
trans_str);
|
2008-10-09 12:29:12 +00:00
|
|
|
g_free (trans_str);
|
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, session, state->response, FALSE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* update the state */
|
2012-11-29 10:11:05 +00:00
|
|
|
rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
|
|
|
|
switch (rtspstate) {
|
2009-02-03 18:32:38 +00:00
|
|
|
case GST_RTSP_STATE_PLAYING:
|
|
|
|
case GST_RTSP_STATE_RECORDING:
|
|
|
|
case GST_RTSP_STATE_READY:
|
|
|
|
/* no state change */
|
|
|
|
break;
|
|
|
|
default:
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_READY);
|
2009-02-03 18:32:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_object_unref (session);
|
|
|
|
|
2012-09-03 17:48:14 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST],
|
|
|
|
0, state);
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
bad_request:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: bad request", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-22 14:33:29 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: media not found", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, state);
|
2009-02-13 18:52:05 +00:00
|
|
|
g_object_unref (session);
|
2012-06-14 07:59:06 +00:00
|
|
|
gst_rtsp_transport_free (ct);
|
2009-01-22 14:33:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-07-03 11:26:30 +00:00
|
|
|
invalid_blocksize:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: invalid blocksize", client);
|
2012-07-03 11:26:30 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, state);
|
|
|
|
g_object_unref (session);
|
|
|
|
gst_rtsp_transport_free (ct);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-11-14 16:23:59 +00:00
|
|
|
unsupported_client_transport:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: unsupported client transport", client);
|
2012-11-14 16:23:59 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
|
|
|
|
g_object_unref (session);
|
|
|
|
gst_rtsp_transport_free (ct);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_transport:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no transport", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
|
2009-01-29 12:31:27 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
unsupported_transports:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: unsupported transports", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, state);
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_transport_free (ct);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 17:51:02 +00:00
|
|
|
no_pool:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no session pool configured", client);
|
2012-11-27 11:11:41 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, state);
|
2012-06-14 07:59:06 +00:00
|
|
|
gst_rtsp_transport_free (ct);
|
2009-01-29 17:51:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
service_unavailable:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: can't create session", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
|
2012-06-14 07:59:06 +00:00
|
|
|
gst_rtsp_transport_free (ct);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-16 17:33:23 +00:00
|
|
|
static GstSDPMessage *
|
|
|
|
create_sdp (GstRTSPClient * client, GstRTSPMedia * media)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-03-16 17:33:23 +00:00
|
|
|
GstSDPMessage *sdp;
|
|
|
|
GstSDPInfo info;
|
|
|
|
const gchar *proto;
|
|
|
|
|
|
|
|
gst_sdp_message_new (&sdp);
|
|
|
|
|
|
|
|
/* some standard things first */
|
|
|
|
gst_sdp_message_set_version (sdp, "0");
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->is_ipv6)
|
2010-03-16 17:33:23 +00:00
|
|
|
proto = "IP6";
|
|
|
|
else
|
|
|
|
proto = "IP4";
|
|
|
|
|
|
|
|
gst_sdp_message_set_origin (sdp, "-", "1188340656180883", "1", "IN", proto,
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->server_ip);
|
2010-03-16 17:33:23 +00:00
|
|
|
|
|
|
|
gst_sdp_message_set_session_name (sdp, "Session streamed with GStreamer");
|
|
|
|
gst_sdp_message_set_information (sdp, "rtsp-server");
|
|
|
|
gst_sdp_message_add_time (sdp, "0", "0", NULL);
|
|
|
|
gst_sdp_message_add_attribute (sdp, "tool", "GStreamer");
|
|
|
|
gst_sdp_message_add_attribute (sdp, "type", "broadcast");
|
|
|
|
gst_sdp_message_add_attribute (sdp, "control", "*");
|
|
|
|
|
|
|
|
info.server_proto = proto;
|
2012-11-29 10:11:05 +00:00
|
|
|
info.server_ip = g_strdup (priv->server_ip);
|
2010-03-16 17:33:23 +00:00
|
|
|
|
|
|
|
/* create an SDP for the media object */
|
|
|
|
if (!gst_rtsp_sdp_from_media (sdp, &info, media))
|
|
|
|
goto no_sdp;
|
|
|
|
|
2011-08-16 11:31:52 +00:00
|
|
|
g_free (info.server_ip);
|
|
|
|
|
2010-03-16 17:33:23 +00:00
|
|
|
return sdp;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_sdp:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: could not create SDP", client);
|
2011-08-16 11:31:52 +00:00
|
|
|
g_free (info.server_ip);
|
2010-03-16 17:33:23 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
/* for the describe we must generate an SDP */
|
2008-10-09 12:29:12 +00:00
|
|
|
static gboolean
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_describe_request (GstRTSPClient * client, GstRTSPClientState * state)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPResult res;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstSDPMessage *sdp;
|
2010-03-09 12:43:29 +00:00
|
|
|
guint i, str_len;
|
|
|
|
gchar *str, *content_base;
|
2009-01-22 16:58:19 +00:00
|
|
|
GstRTSPMedia *media;
|
2012-07-18 13:54:49 +00:00
|
|
|
GstRTSPClientClass *klass;
|
|
|
|
|
|
|
|
klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
/* check what kind of format is accepted, we don't really do anything with it
|
|
|
|
* and always return SDP for now. */
|
2009-05-26 17:01:10 +00:00
|
|
|
for (i = 0; i++;) {
|
2009-01-22 16:58:19 +00:00
|
|
|
gchar *accept;
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
res =
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_message_get_header (state->request, GST_RTSP_HDR_ACCEPT,
|
|
|
|
&accept, i);
|
2009-01-22 16:58:19 +00:00
|
|
|
if (res == GST_RTSP_ENOTIMPL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (g_ascii_strcasecmp (accept, "application/sdp") == 0)
|
|
|
|
break;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* find the media object for the uri */
|
2011-01-12 12:16:08 +00:00
|
|
|
if (!(media = find_media (client, state)))
|
2009-01-22 16:58:19 +00:00
|
|
|
goto no_media;
|
2009-01-22 17:35:17 +00:00
|
|
|
|
2010-03-16 17:33:23 +00:00
|
|
|
/* create an SDP for the media object on this client */
|
2012-07-18 13:54:49 +00:00
|
|
|
if (!(sdp = klass->create_sdp (client, media)))
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_sdp;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
g_object_unref (media);
|
|
|
|
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_TYPE,
|
2009-05-26 17:01:10 +00:00
|
|
|
"application/sdp");
|
2009-01-22 16:58:19 +00:00
|
|
|
|
2009-01-29 16:19:21 +00:00
|
|
|
/* content base for some clients that might screw up creating the setup uri */
|
2011-01-12 12:16:08 +00:00
|
|
|
str = gst_rtsp_url_get_request_uri (state->uri);
|
2010-03-09 12:43:29 +00:00
|
|
|
str_len = strlen (str);
|
|
|
|
|
|
|
|
/* check for trailing '/' and append one */
|
|
|
|
if (str[str_len - 1] != '/') {
|
2010-03-16 17:33:23 +00:00
|
|
|
content_base = g_malloc (str_len + 2);
|
2010-03-09 12:43:29 +00:00
|
|
|
memcpy (content_base, str, str_len);
|
|
|
|
content_base[str_len] = '/';
|
2010-03-16 17:33:23 +00:00
|
|
|
content_base[str_len + 1] = '\0';
|
2010-03-09 12:43:29 +00:00
|
|
|
g_free (str);
|
|
|
|
} else {
|
|
|
|
content_base = str;
|
|
|
|
}
|
2010-03-16 17:33:23 +00:00
|
|
|
|
|
|
|
GST_INFO ("adding content-base: %s", content_base);
|
|
|
|
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_CONTENT_BASE,
|
2010-03-16 17:33:23 +00:00
|
|
|
content_base);
|
2010-03-09 12:43:29 +00:00
|
|
|
g_free (content_base);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* add SDP to the response body */
|
2009-01-29 12:31:27 +00:00
|
|
|
str = gst_sdp_message_as_text (sdp);
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_take_body (state->response, (guint8 *) str, strlen (str));
|
2008-10-09 12:29:12 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, state->session, state->response, FALSE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-09-03 17:48:14 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST],
|
|
|
|
0, state);
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-22 16:58:19 +00:00
|
|
|
no_media:
|
2009-01-22 14:33:29 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no media", client);
|
2009-01-29 12:31:27 +00:00
|
|
|
/* error reply is already sent */
|
2009-01-22 14:33:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_sdp:
|
2009-01-22 15:53:16 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: can't create SDP", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, state);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_unref (media);
|
2009-01-22 15:53:16 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
static gboolean
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_options_request (GstRTSPClient * client, GstRTSPClientState * state)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPMethod options;
|
2009-01-29 12:31:27 +00:00
|
|
|
gchar *str;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
options = GST_RTSP_DESCRIBE |
|
2009-05-26 17:01:10 +00:00
|
|
|
GST_RTSP_OPTIONS |
|
|
|
|
GST_RTSP_PAUSE |
|
|
|
|
GST_RTSP_PLAY |
|
|
|
|
GST_RTSP_SETUP |
|
|
|
|
GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
str = gst_rtsp_options_as_text (options);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_init_response (state->response, GST_RTSP_STS_OK,
|
2011-01-12 12:16:08 +00:00
|
|
|
gst_rtsp_status_as_text (GST_RTSP_STS_OK), state->request);
|
2009-01-22 17:35:17 +00:00
|
|
|
|
2011-01-12 14:37:39 +00:00
|
|
|
gst_rtsp_message_add_header (state->response, GST_RTSP_HDR_PUBLIC, str);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_free (str);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-26 12:16:59 +00:00
|
|
|
send_response (client, state->session, state->response, FALSE);
|
2009-06-09 22:01:07 +00:00
|
|
|
|
2012-09-03 17:48:14 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST],
|
|
|
|
0, state);
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* remove duplicate and trailing '/' */
|
|
|
|
static void
|
2010-12-28 11:18:41 +00:00
|
|
|
sanitize_uri (GstRTSPUrl * uri)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
gint i, len;
|
|
|
|
gchar *s, *d;
|
|
|
|
gboolean have_slash, prev_slash;
|
|
|
|
|
|
|
|
s = d = uri->abspath;
|
|
|
|
len = strlen (uri->abspath);
|
|
|
|
|
|
|
|
prev_slash = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
have_slash = s[i] == '/';
|
|
|
|
*d = s[i];
|
|
|
|
if (!have_slash || !prev_slash)
|
|
|
|
d++;
|
|
|
|
prev_slash = have_slash;
|
|
|
|
}
|
|
|
|
len = d - uri->abspath;
|
|
|
|
/* don't remove the first slash if that's the only thing left */
|
2009-05-26 17:01:10 +00:00
|
|
|
if (len > 1 && *(d - 1) == '/')
|
2009-01-29 12:31:27 +00:00
|
|
|
d--;
|
|
|
|
*d = '\0';
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 18:38:06 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
client_session_finalized (GstRTSPClient * client, GstRTSPSession * session)
|
2009-03-11 18:38:06 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2010-04-06 13:45:56 +00:00
|
|
|
GST_INFO ("client %p: session %p finished", client, session);
|
|
|
|
|
|
|
|
/* unlink all media managed in this session */
|
2010-04-06 15:08:40 +00:00
|
|
|
client_unlink_session (client, session);
|
2010-04-06 13:45:56 +00:00
|
|
|
|
2010-04-06 15:08:40 +00:00
|
|
|
/* remove the session */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (!(priv->sessions = g_list_remove (priv->sessions, session))) {
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_INFO ("client %p: all sessions finalized, close the connection",
|
|
|
|
client);
|
2010-04-06 13:45:56 +00:00
|
|
|
close_connection (client);
|
2009-03-11 18:38:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
client_watch_session (GstRTSPClient * client, GstRTSPSession * session)
|
2009-03-11 18:38:06 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-11 18:38:06 +00:00
|
|
|
GList *walk;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
for (walk = priv->sessions; walk; walk = g_list_next (walk)) {
|
2009-03-11 18:38:06 +00:00
|
|
|
GstRTSPSession *msession = (GstRTSPSession *) walk->data;
|
|
|
|
|
|
|
|
/* we already know about this session */
|
|
|
|
if (msession == session)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("watching session %p", session);
|
2009-03-11 18:38:06 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
g_object_weak_ref (G_OBJECT (session), (GWeakNotify) client_session_finalized,
|
|
|
|
client);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->sessions = g_list_prepend (priv->sessions, session);
|
2012-08-30 19:03:27 +00:00
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_NEW_SESSION], 0,
|
|
|
|
session);
|
2009-03-11 18:38:06 +00:00
|
|
|
}
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_request (GstRTSPClient * client, GstRTSPMessage * request)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPMethod method;
|
2009-01-22 16:58:19 +00:00
|
|
|
const gchar *uristr;
|
2012-11-27 11:24:21 +00:00
|
|
|
GstRTSPUrl *uri = NULL;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPVersion version;
|
2009-02-18 17:57:31 +00:00
|
|
|
GstRTSPResult res;
|
2012-11-27 11:24:21 +00:00
|
|
|
GstRTSPSession *session = NULL;
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPClientState state = { NULL };
|
2011-01-12 14:37:39 +00:00
|
|
|
GstRTSPMessage response = { 0 };
|
2009-02-18 17:57:31 +00:00
|
|
|
gchar *sessid;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
state.request = request;
|
2011-01-12 14:37:39 +00:00
|
|
|
state.response = &response;
|
2011-01-12 12:16:08 +00:00
|
|
|
|
2009-11-21 00:17:25 +00:00
|
|
|
if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
|
|
|
|
gst_rtsp_message_dump (request);
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: received a request", client);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
gst_rtsp_message_parse_request (request, &method, &uristr, &version);
|
2009-01-22 16:58:19 +00:00
|
|
|
|
2012-11-27 11:24:21 +00:00
|
|
|
/* we can only handle 1.0 requests */
|
|
|
|
if (version != GST_RTSP_VERSION_1_0)
|
|
|
|
goto not_supported;
|
|
|
|
|
2011-01-12 12:16:08 +00:00
|
|
|
state.method = method;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* we always try to parse the url first */
|
2012-11-27 11:24:21 +00:00
|
|
|
if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* get the session if there is any */
|
|
|
|
res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
|
|
|
|
if (res == GST_RTSP_OK) {
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->session_pool == NULL)
|
2009-02-18 17:57:31 +00:00
|
|
|
goto no_pool;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* we had a session in the request, find it again */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (!(session = gst_rtsp_session_pool_find (priv->session_pool, sessid)))
|
2009-02-18 17:57:31 +00:00
|
|
|
goto session_not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-03-11 19:03:06 +00:00
|
|
|
/* we add the session to the client list of watched sessions. When a session
|
|
|
|
* disappears because it times out, we will be notified. If all sessions are
|
|
|
|
* gone, we will close the connection */
|
2009-03-11 18:38:06 +00:00
|
|
|
client_watch_session (client, session);
|
2012-11-27 11:24:21 +00:00
|
|
|
}
|
2009-01-20 12:57:47 +00:00
|
|
|
|
2012-11-27 11:24:21 +00:00
|
|
|
/* sanitize the uri */
|
|
|
|
sanitize_uri (uri);
|
|
|
|
state.uri = uri;
|
2011-01-12 12:16:08 +00:00
|
|
|
state.session = session;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->auth) {
|
|
|
|
if (!gst_rtsp_auth_check (priv->auth, client, 0, &state))
|
2011-01-11 23:17:54 +00:00
|
|
|
goto not_authorized;
|
|
|
|
}
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* now see what is asked and dispatch to a dedicated handler */
|
|
|
|
switch (method) {
|
|
|
|
case GST_RTSP_OPTIONS:
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_options_request (client, &state);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_DESCRIBE:
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_describe_request (client, &state);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_SETUP:
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_setup_request (client, &state);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_PLAY:
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_play_request (client, &state);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_PAUSE:
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_pause_request (client, &state);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_TEARDOWN:
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_teardown_request (client, &state);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
2009-05-26 15:25:59 +00:00
|
|
|
case GST_RTSP_SET_PARAMETER:
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_set_param_request (client, &state);
|
2009-06-09 22:01:07 +00:00
|
|
|
break;
|
2009-02-18 17:57:31 +00:00
|
|
|
case GST_RTSP_GET_PARAMETER:
|
2011-01-12 12:16:08 +00:00
|
|
|
handle_get_param_request (client, &state);
|
2009-05-26 15:25:59 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_ANNOUNCE:
|
2009-02-18 17:57:31 +00:00
|
|
|
case GST_RTSP_RECORD:
|
|
|
|
case GST_RTSP_REDIRECT:
|
2012-11-27 11:33:02 +00:00
|
|
|
goto not_implemented;
|
2009-02-18 17:57:31 +00:00
|
|
|
case GST_RTSP_INVALID:
|
|
|
|
default:
|
2012-11-27 11:33:02 +00:00
|
|
|
goto bad_request;
|
2009-02-18 17:57:31 +00:00
|
|
|
}
|
2012-11-27 11:24:21 +00:00
|
|
|
|
|
|
|
done:
|
2009-02-18 17:57:31 +00:00
|
|
|
if (session)
|
|
|
|
g_object_unref (session);
|
2012-11-27 11:24:21 +00:00
|
|
|
if (uri)
|
|
|
|
gst_rtsp_url_free (uri);
|
2009-02-18 17:57:31 +00:00
|
|
|
return;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2012-11-27 11:24:21 +00:00
|
|
|
not_supported:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: version %d not supported", client, version);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
|
|
|
|
&state);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
bad_request:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: bad request", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, &state);
|
|
|
|
goto done;
|
|
|
|
}
|
2009-02-18 17:57:31 +00:00
|
|
|
no_pool:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no pool configured", client);
|
2012-11-27 11:11:41 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, &state);
|
2012-11-27 11:24:21 +00:00
|
|
|
goto done;
|
2009-02-18 17:57:31 +00:00
|
|
|
}
|
|
|
|
session_not_found:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: session not found", client);
|
2011-01-12 12:16:08 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, &state);
|
2012-11-27 11:24:21 +00:00
|
|
|
goto done;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2011-01-11 23:17:54 +00:00
|
|
|
not_authorized:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: not allowed", client);
|
2012-11-29 10:11:05 +00:00
|
|
|
handle_unauthorized_request (client, priv->auth, &state);
|
2012-11-27 11:24:21 +00:00
|
|
|
goto done;
|
2011-01-11 23:17:54 +00:00
|
|
|
}
|
2012-11-27 11:33:02 +00:00
|
|
|
not_implemented:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: method %d not implemented", client, method);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, &state);
|
|
|
|
goto done;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_data (GstRTSPClient * client, GstRTSPMessage * message)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-11 15:45:12 +00:00
|
|
|
GstRTSPResult res;
|
|
|
|
guint8 channel;
|
|
|
|
GList *walk;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
|
|
|
GstBuffer *buffer;
|
2009-04-14 21:38:58 +00:00
|
|
|
gboolean handled;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
/* find the stream for this message */
|
2009-03-11 15:45:12 +00:00
|
|
|
res = gst_rtsp_message_parse_data (message, &channel);
|
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gst_rtsp_message_steal_body (message, &data, &size);
|
|
|
|
|
2012-04-13 13:27:22 +00:00
|
|
|
buffer = gst_buffer_new_wrapped (data, size);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
handled = FALSE;
|
2012-11-29 10:11:05 +00:00
|
|
|
for (walk = priv->transports; walk; walk = g_list_next (walk)) {
|
2012-10-27 21:49:24 +00:00
|
|
|
GstRTSPStreamTransport *trans;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStream *stream;
|
2012-11-29 10:11:05 +00:00
|
|
|
const GstRTSPTransport *tr;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
trans = walk->data;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
tr = gst_rtsp_stream_transport_get_transport (trans);
|
|
|
|
stream = gst_rtsp_stream_transport_get_stream (trans);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
/* check for TCP transport */
|
|
|
|
if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
|
|
|
|
/* dispatch to the stream based on the channel number */
|
|
|
|
if (tr->interleaved.min == channel) {
|
2012-10-25 19:29:58 +00:00
|
|
|
gst_rtsp_stream_recv_rtp (stream, buffer);
|
2009-05-26 17:01:10 +00:00
|
|
|
handled = TRUE;
|
2009-04-14 21:38:58 +00:00
|
|
|
break;
|
2009-03-11 15:45:12 +00:00
|
|
|
} else if (tr->interleaved.max == channel) {
|
2012-10-25 19:29:58 +00:00
|
|
|
gst_rtsp_stream_recv_rtcp (stream, buffer);
|
2009-05-26 17:01:10 +00:00
|
|
|
handled = TRUE;
|
2009-04-14 21:38:58 +00:00
|
|
|
break;
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-14 21:38:58 +00:00
|
|
|
if (!handled)
|
|
|
|
gst_buffer_unref (buffer);
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_session_pool:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @pool: a #GstRTSPSessionPool
|
|
|
|
*
|
|
|
|
* Set @pool as the sessionpool for @client which it will use to find
|
2009-01-22 14:33:29 +00:00
|
|
|
* or allocate sessions. the sessionpool is usually inherited from the server
|
|
|
|
* that created the client but can be overridden later.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
void
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_set_session_pool (GstRTSPClient * client,
|
|
|
|
GstRTSPSessionPool * pool)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPSessionPool *old;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (pool)
|
|
|
|
g_object_ref (pool);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
old = priv->session_pool;
|
|
|
|
priv->session_pool = pool;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-26 15:30:16 +00:00
|
|
|
|
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_get_session_pool:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPSessionPool object that @client uses to manage its sessions.
|
|
|
|
*
|
2012-10-01 17:46:15 +00:00
|
|
|
* Returns: (transfer full): a #GstRTSPSessionPool, unref after usage.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
GstRTSPSessionPool *
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_get_session_pool (GstRTSPClient * client)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPSessionPool *result;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->session_pool))
|
2008-10-09 12:29:12 +00:00
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
return result;
|
2011-01-12 09:42:52 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 18:46:21 +00:00
|
|
|
/**
|
2012-11-26 11:34:05 +00:00
|
|
|
* gst_rtsp_client_set_mount_points:
|
2009-01-20 18:46:21 +00:00
|
|
|
* @client: a #GstRTSPClient
|
2012-11-26 11:34:05 +00:00
|
|
|
* @mounts: a #GstRTSPMountPoints
|
2009-01-20 18:46:21 +00:00
|
|
|
*
|
2012-11-26 11:34:05 +00:00
|
|
|
* Set @mounts as the mount points for @client which it will use to map urls
|
|
|
|
* to media streams. These mount points are usually inherited from the server that
|
2009-01-22 14:33:29 +00:00
|
|
|
* created the client but can be overriden later.
|
2009-01-20 18:46:21 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-11-26 11:34:05 +00:00
|
|
|
gst_rtsp_client_set_mount_points (GstRTSPClient * client,
|
|
|
|
GstRTSPMountPoints * mounts)
|
2009-01-20 18:46:21 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *old;
|
2009-01-20 18:46:21 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (mounts)
|
|
|
|
g_object_ref (mounts);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
old = priv->mount_points;
|
|
|
|
priv->mount_points = mounts;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2009-01-20 18:46:21 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2009-01-20 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-26 11:34:05 +00:00
|
|
|
* gst_rtsp_client_get_mount_points:
|
2009-01-20 18:46:21 +00:00
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
2012-11-26 11:34:05 +00:00
|
|
|
* Get the #GstRTSPMountPoints object that @client uses to manage its sessions.
|
2009-01-20 18:46:21 +00:00
|
|
|
*
|
2012-11-26 11:34:05 +00:00
|
|
|
* Returns: (transfer full): a #GstRTSPMountPoints, unref after usage.
|
2009-01-20 18:46:21 +00:00
|
|
|
*/
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *
|
|
|
|
gst_rtsp_client_get_mount_points (GstRTSPClient * client)
|
2009-01-20 18:46:21 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *result;
|
2009-01-20 18:46:21 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->mount_points))
|
2009-01-20 18:46:21 +00:00
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2009-01-20 18:46:21 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-10-10 09:06:02 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_use_client_settings:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @use_client_settings: whether to use client settings for multicast
|
|
|
|
*
|
|
|
|
* Use client transport settings (destination and ttl) for multicast.
|
|
|
|
* When @use_client_settings is %FALSE, the server settings will be
|
|
|
|
* used.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_client_set_use_client_settings (GstRTSPClient * client,
|
|
|
|
gboolean use_client_settings)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->use_client_settings = use_client_settings;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-10 09:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_get_use_client_settings:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
|
|
|
* Check if client transport settings (destination and ttl) for multicast
|
|
|
|
* will be used.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_client_get_use_client_settings (GstRTSPClient * client)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2012-11-26 15:30:16 +00:00
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->use_client_settings;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-26 15:30:16 +00:00
|
|
|
|
|
|
|
return res;
|
2012-10-10 09:06:02 +00:00
|
|
|
}
|
|
|
|
|
2011-01-11 23:17:54 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_auth:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @auth: a #GstRTSPAuth
|
|
|
|
*
|
|
|
|
* configure @auth to be used as the authentication manager of @client.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_client_set_auth (GstRTSPClient * client, GstRTSPAuth * auth)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2011-01-11 23:17:54 +00:00
|
|
|
GstRTSPAuth *old;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (auth)
|
|
|
|
g_object_ref (auth);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
old = priv->auth;
|
|
|
|
priv->auth = auth;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2011-01-11 23:17:54 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2011-01-11 23:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_get_auth:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPAuth used as the authentication manager of @client.
|
|
|
|
*
|
2012-10-01 17:46:15 +00:00
|
|
|
* Returns: (transfer full): the #GstRTSPAuth of @client. g_object_unref() after
|
2011-01-11 23:17:54 +00:00
|
|
|
* usage.
|
|
|
|
*/
|
|
|
|
GstRTSPAuth *
|
|
|
|
gst_rtsp_client_get_auth (GstRTSPClient * client)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2011-01-11 23:17:54 +00:00
|
|
|
GstRTSPAuth *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->auth))
|
2011-01-11 23:17:54 +00:00
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2011-01-11 23:17:54 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_send_func:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @func: a #GstRTSPClientSendFunc
|
|
|
|
* @user_data: user data passed to @func
|
|
|
|
* @notify: called when @user_data is no longer in use
|
|
|
|
*
|
|
|
|
* Set @func as the callback that will be called when a new message needs to be
|
|
|
|
* sent to the client. @user_data is passed to @func and @notify is called when
|
|
|
|
* @user_data is no longer in use.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_client_set_send_func (GstRTSPClient * client,
|
|
|
|
GstRTSPClientSendFunc func, gpointer user_data, GDestroyNotify notify)
|
2009-02-18 17:57:31 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2012-11-26 16:35:51 +00:00
|
|
|
GDestroyNotify old_notify;
|
2012-11-26 16:28:29 +00:00
|
|
|
gpointer old_data;
|
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->send_func = func;
|
|
|
|
old_notify = priv->send_notify;
|
|
|
|
old_data = priv->send_data;
|
|
|
|
priv->send_notify = notify;
|
|
|
|
priv->send_data = user_data;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-26 16:28:29 +00:00
|
|
|
|
2012-11-26 16:35:51 +00:00
|
|
|
if (old_notify)
|
|
|
|
old_notify (old_data);
|
2012-11-26 16:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_handle_message:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @message: an #GstRTSPMessage
|
|
|
|
*
|
|
|
|
* Let the client handle @message.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPResult.
|
|
|
|
*/
|
|
|
|
GstRTSPResult
|
|
|
|
gst_rtsp_client_handle_message (GstRTSPClient * client,
|
|
|
|
GstRTSPMessage * message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), GST_RTSP_EINVAL);
|
|
|
|
g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2009-03-04 11:44:01 +00:00
|
|
|
switch (message->type) {
|
|
|
|
case GST_RTSP_MESSAGE_REQUEST:
|
|
|
|
handle_request (client, message);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_MESSAGE_RESPONSE:
|
|
|
|
break;
|
|
|
|
case GST_RTSP_MESSAGE_DATA:
|
2009-03-11 15:45:12 +00:00
|
|
|
handle_data (client, message);
|
2009-03-04 11:44:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-02-18 17:57:31 +00:00
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
static GstRTSPResult
|
|
|
|
do_send_message (GstRTSPClient * client, GstRTSPMessage * message,
|
|
|
|
gboolean close, gpointer user_data)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
/* send the response and store the seq number so we can wait until it's
|
|
|
|
* written to the client to close the connection */
|
2012-11-29 10:11:05 +00:00
|
|
|
return gst_rtsp_watch_send_message (priv->watch, message, close ?
|
|
|
|
&priv->close_seq : NULL);
|
2012-11-26 16:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPResult
|
|
|
|
message_received (GstRTSPWatch * watch, GstRTSPMessage * message,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
return gst_rtsp_client_handle_message (GST_RTSP_CLIENT (user_data), message);
|
|
|
|
}
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
static GstRTSPResult
|
2009-05-26 17:01:10 +00:00
|
|
|
message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
|
2009-02-18 17:57:31 +00:00
|
|
|
{
|
2012-11-26 15:45:04 +00:00
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->close_seq && priv->close_seq == cseq) {
|
|
|
|
priv->close_seq = 0;
|
2012-11-17 13:51:52 +00:00
|
|
|
close_connection (client);
|
|
|
|
}
|
2009-02-18 17:57:31 +00:00
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPResult
|
2009-05-26 17:01:10 +00:00
|
|
|
closed (GstRTSPWatch * watch, gpointer user_data)
|
2009-02-18 17:57:31 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-04 11:44:01 +00:00
|
|
|
const gchar *tunnelid;
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: connection closed", client);
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_lock (&tunnels_lock);
|
2010-04-06 09:13:51 +00:00
|
|
|
/* remove from tunnelids */
|
2009-03-04 15:33:21 +00:00
|
|
|
g_hash_table_remove (tunnels, tunnelid);
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2009-03-04 15:33:21 +00:00
|
|
|
}
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPResult
|
2009-05-26 17:01:10 +00:00
|
|
|
error (GstRTSPWatch * watch, GstRTSPResult result, gpointer user_data)
|
2009-02-18 17:57:31 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = gst_rtsp_strresult (result);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: received an error %s", client, str);
|
2009-02-18 17:57:31 +00:00
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-27 17:38:27 +00:00
|
|
|
static GstRTSPResult
|
2010-03-16 17:33:23 +00:00
|
|
|
error_full (GstRTSPWatch * watch, GstRTSPResult result,
|
|
|
|
GstRTSPMessage * message, guint id, gpointer user_data)
|
2010-01-27 17:38:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = gst_rtsp_strresult (result);
|
2010-03-16 17:33:23 +00:00
|
|
|
GST_INFO
|
|
|
|
("client %p: received an error %s when handling message %p with id %d",
|
2010-01-27 17:38:27 +00:00
|
|
|
client, str, message, id);
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
static gboolean
|
|
|
|
remember_tunnel (GstRTSPClient * client)
|
2009-03-04 11:44:01 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-04 11:44:01 +00:00
|
|
|
const gchar *tunnelid;
|
|
|
|
|
|
|
|
/* store client in the pending tunnels */
|
2012-11-29 10:11:05 +00:00
|
|
|
tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
|
2009-07-24 10:49:41 +00:00
|
|
|
if (tunnelid == NULL)
|
|
|
|
goto no_tunnelid;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* we can't have two clients connecting with the same tunnelid */
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_lock (&tunnels_lock);
|
2009-03-04 11:44:01 +00:00
|
|
|
if (g_hash_table_lookup (tunnels, tunnelid))
|
|
|
|
goto tunnel_existed;
|
|
|
|
|
|
|
|
g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
return TRUE;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-07-24 10:49:41 +00:00
|
|
|
no_tunnelid:
|
|
|
|
{
|
2010-04-06 09:13:51 +00:00
|
|
|
GST_ERROR ("client %p: no tunnelid provided", client);
|
|
|
|
return FALSE;
|
2009-07-24 10:49:41 +00:00
|
|
|
}
|
2009-03-04 11:44:01 +00:00
|
|
|
tunnel_existed:
|
|
|
|
{
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_ERROR ("client %p: tunnel session %s already existed", client,
|
|
|
|
tunnelid);
|
2010-04-06 09:13:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPStatusCode
|
|
|
|
tunnel_start (GstRTSPWatch * watch, gpointer user_data)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-04-06 09:13:51 +00:00
|
|
|
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_INFO ("client %p: tunnel start (connection %p)", client,
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->connection);
|
2010-04-06 09:13:51 +00:00
|
|
|
|
|
|
|
if (!remember_tunnel (client))
|
|
|
|
goto tunnel_error;
|
|
|
|
|
|
|
|
return GST_RTSP_STS_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
tunnel_error:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: error starting tunnel", client);
|
2009-03-04 11:44:01 +00:00
|
|
|
return GST_RTSP_STS_SERVICE_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
static GstRTSPResult
|
|
|
|
tunnel_lost (GstRTSPWatch * watch, gpointer user_data)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-04-06 09:13:51 +00:00
|
|
|
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_WARNING ("client %p: tunnel lost (connection %p)", client,
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->connection);
|
2010-04-06 09:13:51 +00:00
|
|
|
|
|
|
|
/* ignore error, it'll only be a problem when the client does a POST again */
|
|
|
|
remember_tunnel (client);
|
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-04 11:44:01 +00:00
|
|
|
static GstRTSPResult
|
2009-05-26 17:01:10 +00:00
|
|
|
tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
|
2009-03-04 11:44:01 +00:00
|
|
|
{
|
|
|
|
const gchar *tunnelid;
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-04 11:44:01 +00:00
|
|
|
GstRTSPClient *oclient;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *opriv;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: tunnel complete", client);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* find previous tunnel */
|
2012-11-29 10:11:05 +00:00
|
|
|
tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
|
2009-07-24 10:49:41 +00:00
|
|
|
if (tunnelid == NULL)
|
|
|
|
goto no_tunnelid;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_lock (&tunnels_lock);
|
2009-03-04 11:44:01 +00:00
|
|
|
if (!(oclient = g_hash_table_lookup (tunnels, tunnelid)))
|
|
|
|
goto no_tunnel;
|
|
|
|
|
|
|
|
/* remove the old client from the table. ref before because removing it will
|
|
|
|
* remove the ref to it. */
|
|
|
|
g_object_ref (oclient);
|
|
|
|
g_hash_table_remove (tunnels, tunnelid);
|
2010-04-06 13:45:56 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
opriv = oclient->priv;
|
|
|
|
|
|
|
|
if (opriv->watch == NULL)
|
2010-04-06 13:45:56 +00:00
|
|
|
goto tunnel_closed;
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
GST_INFO ("client %p: found tunnel %p (old %p, new %p)", client, oclient,
|
2012-11-29 10:11:05 +00:00
|
|
|
opriv->connection, priv->connection);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* merge the tunnels into the first client */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_connection_do_tunnel (opriv->connection, priv->connection);
|
|
|
|
gst_rtsp_watch_reset (opriv->watch);
|
2009-03-04 11:44:01 +00:00
|
|
|
g_object_unref (oclient);
|
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2009-07-24 10:49:41 +00:00
|
|
|
no_tunnelid:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no tunnelid provided", client);
|
2012-04-13 13:27:22 +00:00
|
|
|
return GST_RTSP_ERROR;
|
2009-07-24 10:49:41 +00:00
|
|
|
}
|
2009-03-04 11:44:01 +00:00
|
|
|
no_tunnel:
|
|
|
|
{
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: tunnel session %s not found", client, tunnelid);
|
2012-04-13 13:27:22 +00:00
|
|
|
return GST_RTSP_ERROR;
|
2009-03-04 11:44:01 +00:00
|
|
|
}
|
2010-04-06 13:45:56 +00:00
|
|
|
tunnel_closed:
|
|
|
|
{
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: tunnel session %s was closed", client, tunnelid);
|
2010-04-06 13:45:56 +00:00
|
|
|
g_object_unref (oclient);
|
2012-04-13 13:27:22 +00:00
|
|
|
return GST_RTSP_ERROR;
|
2010-04-06 13:45:56 +00:00
|
|
|
}
|
2009-03-04 11:44:01 +00:00
|
|
|
}
|
|
|
|
|
2009-02-19 14:53:50 +00:00
|
|
|
static GstRTSPWatchFuncs watch_funcs = {
|
2009-02-18 17:57:31 +00:00
|
|
|
message_received,
|
|
|
|
message_sent,
|
|
|
|
closed,
|
2009-03-04 11:44:01 +00:00
|
|
|
error,
|
|
|
|
tunnel_start,
|
2010-01-27 17:38:27 +00:00
|
|
|
tunnel_complete,
|
2010-04-06 09:13:51 +00:00
|
|
|
error_full,
|
|
|
|
tunnel_lost
|
2009-02-18 17:57:31 +00:00
|
|
|
};
|
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
static void
|
|
|
|
client_watch_notify (GstRTSPClient * client)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
GST_INFO ("client %p: watch destroyed", client);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->watch = NULL;
|
2011-01-12 14:35:51 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL);
|
2010-04-06 09:13:51 +00:00
|
|
|
g_object_unref (client);
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:06:00 +00:00
|
|
|
static gboolean
|
2012-11-12 13:09:09 +00:00
|
|
|
setup_client (GstRTSPClient * client, GSocket * socket,
|
2012-07-10 09:39:58 +00:00
|
|
|
GstRTSPConnection * conn, GError ** error)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2012-03-07 14:03:55 +00:00
|
|
|
GSocket *read_socket;
|
2012-10-23 20:11:17 +00:00
|
|
|
GSocketAddress *address;
|
2009-03-04 11:44:01 +00:00
|
|
|
GstRTSPUrl *url;
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
read_socket = gst_rtsp_connection_get_read_socket (conn);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->is_ipv6 = g_socket_get_family (socket) == G_SOCKET_FAMILY_IPV6;
|
2009-01-29 17:51:02 +00:00
|
|
|
|
2012-10-23 20:11:17 +00:00
|
|
|
if (!(address = g_socket_get_remote_address (read_socket, error)))
|
2012-03-07 14:03:55 +00:00
|
|
|
goto no_address;
|
2010-03-16 17:33:23 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_free (priv->server_ip);
|
2012-09-07 15:14:30 +00:00
|
|
|
/* keep the original ip that the client connected to */
|
2012-10-23 20:11:17 +00:00
|
|
|
if (G_IS_INET_SOCKET_ADDRESS (address)) {
|
2012-09-07 15:14:30 +00:00
|
|
|
GInetAddress *iaddr;
|
2010-03-16 17:33:23 +00:00
|
|
|
|
2012-10-23 20:11:17 +00:00
|
|
|
iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (address));
|
2010-03-16 17:33:23 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->server_ip = g_inet_address_to_string (iaddr);
|
2012-10-23 20:11:17 +00:00
|
|
|
g_object_unref (address);
|
2012-09-07 15:14:30 +00:00
|
|
|
} else {
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->server_ip = g_strdup ("unknown");
|
2012-09-07 15:14:30 +00:00
|
|
|
}
|
2010-03-16 17:33:23 +00:00
|
|
|
|
|
|
|
GST_INFO ("client %p connected to server ip %s, ipv6 = %d", client,
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->server_ip, priv->is_ipv6);
|
2010-03-16 17:33:23 +00:00
|
|
|
|
2009-03-04 11:44:01 +00:00
|
|
|
url = gst_rtsp_connection_get_url (conn);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("added new client %p ip %s:%d", client, url->host, url->port);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->connection = conn;
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-03-07 14:03:55 +00:00
|
|
|
no_address:
|
|
|
|
{
|
|
|
|
GST_ERROR ("could not get remote address %s", (*error)->message);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2012-07-03 16:06:00 +00:00
|
|
|
|
|
|
|
/**
|
2012-11-12 13:30:43 +00:00
|
|
|
* gst_rtsp_client_use_socket:
|
2012-07-03 16:06:00 +00:00
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @socket: a #GSocket
|
|
|
|
* @ip: the IP address of the remote client
|
|
|
|
* @port: the port used by the other end
|
2012-11-12 13:09:09 +00:00
|
|
|
* @initial_buffer: any zero terminated initial data that was already read from
|
|
|
|
* the socket
|
2012-07-03 16:06:00 +00:00
|
|
|
* @error: a #GError
|
|
|
|
*
|
|
|
|
* Take an existing network socket and use it for an RTSP connection.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
2012-11-12 13:09:09 +00:00
|
|
|
gst_rtsp_client_use_socket (GstRTSPClient * client, GSocket * socket,
|
2012-07-03 16:06:00 +00:00
|
|
|
const gchar * ip, gint port, const gchar * initial_buffer, GError ** error)
|
|
|
|
{
|
|
|
|
GstRTSPConnection *conn;
|
|
|
|
GstRTSPResult res;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_SOCKET (socket), FALSE);
|
|
|
|
|
2012-07-03 16:06:00 +00:00
|
|
|
GST_RTSP_CHECK (gst_rtsp_connection_create_from_socket (socket, ip, port,
|
2012-07-10 09:39:58 +00:00
|
|
|
initial_buffer, &conn), no_connection);
|
2012-07-03 16:06:00 +00:00
|
|
|
|
2012-11-12 13:09:09 +00:00
|
|
|
return setup_client (client, socket, conn, error);
|
2012-07-03 16:06:00 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_connection:
|
|
|
|
{
|
|
|
|
gchar *str = gst_rtsp_strresult (res);
|
|
|
|
|
|
|
|
GST_ERROR ("could not create connection from socket %p: %s", socket, str);
|
|
|
|
g_free (str);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-10 09:39:58 +00:00
|
|
|
* gst_rtsp_client_accept:
|
2012-07-03 16:06:00 +00:00
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @socket: a #GSocket
|
2012-11-12 13:09:09 +00:00
|
|
|
* @context: the context to run in
|
2012-07-03 16:06:00 +00:00
|
|
|
* @cancellable: a #GCancellable
|
|
|
|
* @error: a #GError
|
|
|
|
*
|
|
|
|
* Accept a new connection for @client on @socket.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the client could be accepted.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_client_accept (GstRTSPClient * client, GSocket * socket,
|
|
|
|
GCancellable * cancellable, GError ** error)
|
|
|
|
{
|
|
|
|
GstRTSPConnection *conn;
|
|
|
|
GstRTSPResult res;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
|
|
|
|
g_return_val_if_fail (G_IS_SOCKET (socket), FALSE);
|
|
|
|
|
2012-07-03 16:06:00 +00:00
|
|
|
/* a new client connected. */
|
|
|
|
GST_RTSP_CHECK (gst_rtsp_connection_accept (socket, &conn, cancellable),
|
|
|
|
accept_failed);
|
|
|
|
|
2012-11-12 13:09:09 +00:00
|
|
|
return setup_client (client, socket, conn, error);
|
2012-07-03 16:06:00 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
accept_failed:
|
|
|
|
{
|
|
|
|
gchar *str = gst_rtsp_strresult (res);
|
|
|
|
|
|
|
|
GST_ERROR ("Could not accept client on server socket %p: %s", socket, str);
|
|
|
|
g_free (str);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2012-11-12 13:09:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_attach:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @context: (allow-none): a #GMainContext
|
|
|
|
*
|
|
|
|
* Attaches @client to @context. When the mainloop for @context is run, the
|
|
|
|
* client will be dispatched. When @context is NULL, the default context will be
|
|
|
|
* used).
|
|
|
|
*
|
|
|
|
* This function should be called when the client properties and urls are fully
|
|
|
|
* configured and the client is ready to start.
|
|
|
|
*
|
|
|
|
* Returns: the ID (greater than 0) for the source within the GMainContext.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2012-11-12 13:09:09 +00:00
|
|
|
guint res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), 0);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
g_return_val_if_fail (priv->watch == NULL, 0);
|
2012-11-12 13:09:09 +00:00
|
|
|
|
|
|
|
/* create watch for the connection and attach */
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->watch = gst_rtsp_watch_new (priv->connection, &watch_funcs,
|
2012-11-12 13:09:09 +00:00
|
|
|
g_object_ref (client), (GDestroyNotify) client_watch_notify);
|
2012-11-26 16:20:39 +00:00
|
|
|
gst_rtsp_client_set_send_func (client, do_send_message, NULL, NULL);
|
2012-11-12 13:09:09 +00:00
|
|
|
|
|
|
|
GST_INFO ("attaching to context %p", context);
|
2012-11-29 10:11:05 +00:00
|
|
|
res = gst_rtsp_watch_attach (priv->watch, context);
|
|
|
|
gst_rtsp_watch_unref (priv->watch);
|
2012-11-12 13:09:09 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|