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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#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
|
|
|
|
2010-03-19 17:03:40 +00:00
|
|
|
/* temporary multicast address until it's configurable somewhere */
|
|
|
|
#define MCAST_ADDRESS "224.2.0.1"
|
|
|
|
|
2009-03-04 11:44:01 +00:00
|
|
|
static GMutex *tunnels_lock;
|
|
|
|
static GHashTable *tunnels;
|
|
|
|
|
2009-02-10 15:24:13 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_SESSION_POOL,
|
|
|
|
PROP_MEDIA_MAPPING,
|
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_client_debug);
|
|
|
|
#define GST_CAT_DEFAULT rtsp_client_debug
|
|
|
|
|
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);
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
static void client_session_finalized (GstRTSPClient * client,
|
|
|
|
GstRTSPSession * session);
|
2009-03-11 18:38:06 +00:00
|
|
|
|
2010-03-05 17:37:17 +00:00
|
|
|
static void unlink_streams (GstRTSPClient * client);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MEDIA_MAPPING,
|
|
|
|
g_param_spec_object ("media-mapping", "Media Mapping",
|
|
|
|
"The media mapping to use for client session",
|
2009-05-26 17:01:10 +00:00
|
|
|
GST_TYPE_RTSP_MEDIA_MAPPING,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-03-04 11:44:01 +00:00
|
|
|
|
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);
|
2009-03-04 11:44:01 +00:00
|
|
|
tunnels_lock = g_mutex_new ();
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
/* A client is finalized when the connection is broken */
|
2009-01-22 14:33:29 +00:00
|
|
|
static void
|
|
|
|
gst_rtsp_client_finalize (GObject * obj)
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (obj);
|
2009-10-11 11:57:54 +00:00
|
|
|
GList *walk;
|
2009-01-29 17:51:02 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("finalize client %p", client);
|
2009-02-04 16:00:42 +00:00
|
|
|
|
2009-10-11 11:57:54 +00:00
|
|
|
/* remove weak-ref from sessions */
|
|
|
|
for (walk = client->sessions; walk; walk = g_list_next (walk)) {
|
|
|
|
GstRTSPSession *msession = (GstRTSPSession *) walk->data;
|
|
|
|
g_object_weak_unref (G_OBJECT (msession),
|
2010-03-16 17:33:23 +00:00
|
|
|
(GWeakNotify) client_session_finalized, client);
|
2009-10-11 11:57:54 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 17:37:17 +00:00
|
|
|
unlink_streams (client);
|
|
|
|
|
2009-03-11 18:38:06 +00:00
|
|
|
g_list_free (client->sessions);
|
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
gst_rtsp_connection_free (client->connection);
|
|
|
|
if (client->session_pool)
|
|
|
|
g_object_unref (client->session_pool);
|
|
|
|
if (client->media_mapping)
|
|
|
|
g_object_unref (client->media_mapping);
|
|
|
|
|
|
|
|
if (client->uri)
|
|
|
|
gst_rtsp_url_free (client->uri);
|
|
|
|
if (client->media)
|
|
|
|
g_object_unref (client->media);
|
|
|
|
|
2010-03-16 17:33:23 +00:00
|
|
|
g_free (client->server_ip);
|
|
|
|
|
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;
|
|
|
|
case PROP_MEDIA_MAPPING:
|
|
|
|
g_value_take_object (value, gst_rtsp_client_get_media_mapping (client));
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
case PROP_MEDIA_MAPPING:
|
|
|
|
gst_rtsp_client_set_media_mapping (client, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
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,
|
|
|
|
GstRTSPMessage * response)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
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) {
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
if (session->timeout != 60)
|
2009-05-26 17:01:10 +00:00
|
|
|
str =
|
|
|
|
g_strdup_printf ("%s; timeout=%d", session->sessionid,
|
|
|
|
session->timeout);
|
2009-02-13 11:57:45 +00:00
|
|
|
else
|
|
|
|
str = g_strdup (session->sessionid);
|
|
|
|
|
|
|
|
gst_rtsp_message_take_header (response, GST_RTSP_HDR_SESSION, str);
|
|
|
|
}
|
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
|
|
|
|
2009-08-24 11:27:00 +00:00
|
|
|
gst_rtsp_watch_send_message (client->watch, response, NULL);
|
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,
|
|
|
|
GstRTSPMessage * request)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPMessage response = { 0 };
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_init_response (&response, code,
|
|
|
|
gst_rtsp_status_as_text (code), request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-13 11:57:45 +00:00
|
|
|
send_response (client, NULL, &response);
|
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 *
|
2009-05-26 17:01:10 +00:00
|
|
|
find_media (GstRTSPClient * client, GstRTSPUrl * uri, GstRTSPMessage * request)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPMediaFactory *factory;
|
|
|
|
GstRTSPMedia *media;
|
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
if (!compare_uri (client->uri, uri)) {
|
|
|
|
/* remove any previously cached values before we try to construct a new
|
|
|
|
* media for uri */
|
|
|
|
if (client->uri)
|
|
|
|
gst_rtsp_url_free (client->uri);
|
|
|
|
client->uri = NULL;
|
|
|
|
if (client->media)
|
|
|
|
g_object_unref (client->media);
|
|
|
|
client->media = NULL;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
if (!client->media_mapping)
|
|
|
|
goto no_mapping;
|
|
|
|
|
|
|
|
/* find the factory for the uri first */
|
2009-05-26 17:01:10 +00:00
|
|
|
if (!(factory =
|
|
|
|
gst_rtsp_media_mapping_find_factory (client->media_mapping, uri)))
|
2009-01-29 17:51:02 +00:00
|
|
|
goto no_factory;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
/* prepare the media and add it to the pipeline */
|
|
|
|
if (!(media = gst_rtsp_media_factory_construct (factory, uri)))
|
|
|
|
goto no_media;
|
|
|
|
|
2010-03-16 17:33:23 +00:00
|
|
|
/* set ipv6 on the media before preparing */
|
|
|
|
media->is_ipv6 = client->is_ipv6;
|
|
|
|
|
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 */
|
|
|
|
client->uri = gst_rtsp_url_copy (uri);
|
2009-02-04 16:00:42 +00:00
|
|
|
client->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 */
|
2009-02-04 16:00:42 +00:00
|
|
|
media = client->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 */
|
2009-01-29 17:51:02 +00:00
|
|
|
no_mapping:
|
|
|
|
{
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_factory:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
|
2009-01-29 12:31:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
no_media:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_unref (factory);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
no_prepare:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_unref (media);
|
|
|
|
g_object_unref (factory);
|
|
|
|
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
|
|
|
{
|
|
|
|
GstRTSPMessage message = { 0 };
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
|
|
|
|
|
|
|
gst_rtsp_message_init_data (&message, channel);
|
|
|
|
|
|
|
|
data = GST_BUFFER_DATA (buffer);
|
|
|
|
size = GST_BUFFER_SIZE (buffer);
|
|
|
|
gst_rtsp_message_take_body (&message, data, size);
|
|
|
|
|
2009-08-24 11:27:00 +00:00
|
|
|
gst_rtsp_watch_send_message (client->watch, &message, NULL);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
gst_rtsp_message_steal_body (&message, &data, &size);
|
|
|
|
gst_rtsp_message_unset (&message);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
link_stream (GstRTSPClient * client, GstRTSPSessionStream * stream)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
|
|
|
gst_rtsp_session_stream_set_callbacks (stream, (GstRTSPSendFunc) do_send_data,
|
2009-05-26 17:01:10 +00:00
|
|
|
(GstRTSPSendFunc) do_send_data, client, NULL);
|
2009-03-11 15:45:12 +00:00
|
|
|
client->streams = g_list_prepend (client->streams, stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
unlink_stream (GstRTSPClient * client, GstRTSPSessionStream * stream)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_session_stream_set_callbacks (stream, NULL, NULL, NULL, NULL);
|
2009-03-11 15:45:12 +00:00
|
|
|
client->streams = g_list_remove (client->streams, stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
unlink_streams (GstRTSPClient * client)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
|
|
|
GList *walk;
|
|
|
|
|
|
|
|
for (walk = client->streams; walk; walk = g_list_next (walk)) {
|
|
|
|
GstRTSPSessionStream *stream = (GstRTSPSessionStream *) walk->data;
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_session_stream_set_callbacks (stream, NULL, NULL, NULL, NULL);
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
g_list_free (client->streams);
|
|
|
|
client->streams = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
unlink_session_streams (GstRTSPClient * client, GstRTSPSessionMedia * media)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
|
|
|
guint n_streams, i;
|
|
|
|
|
|
|
|
n_streams = gst_rtsp_media_n_streams (media->media);
|
|
|
|
for (i = 0; i < n_streams; i++) {
|
|
|
|
GstRTSPSessionStream *sstream;
|
|
|
|
GstRTSPTransport *tr;
|
|
|
|
|
|
|
|
/* get the stream as configured in the session */
|
|
|
|
sstream = gst_rtsp_session_media_get_stream (media, i);
|
|
|
|
/* get the transport, if there is no transport configured, skip this stream */
|
|
|
|
if (!(tr = sstream->trans.transport))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tr->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
|
|
|
|
/* for TCP, unlink the stream from the TCP connection of the client */
|
|
|
|
unlink_stream (client, sstream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
static gboolean
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_teardown_request (GstRTSPClient * client, GstRTSPUrl * uri,
|
|
|
|
GstRTSPSession * session, GstRTSPMessage * request)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPSessionMedia *media;
|
|
|
|
GstRTSPMessage response = { 0 };
|
|
|
|
GstRTSPStatusCode code;
|
|
|
|
|
2009-02-13 18:52:05 +00:00
|
|
|
if (!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 */
|
2009-01-29 12:31:27 +00:00
|
|
|
media = gst_rtsp_session_get_media (session, uri);
|
2009-01-08 15:28:24 +00:00
|
|
|
if (!media)
|
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* unlink the all TCP callbacks */
|
|
|
|
unlink_session_streams (client, media);
|
|
|
|
|
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);
|
2009-03-11 19:03:06 +00:00
|
|
|
client->sessions = g_list_remove (client->sessions, session);
|
|
|
|
|
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 */
|
|
|
|
gst_rtsp_session_pool_remove (client->session_pool, session);
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
/* construct the response now */
|
|
|
|
code = GST_RTSP_STS_OK;
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_init_response (&response, code,
|
|
|
|
gst_rtsp_status_as_text (code), request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-13 11:57:45 +00:00
|
|
|
send_response (client, session, &response);
|
|
|
|
|
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
|
|
|
{
|
2009-02-13 18:52:05 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-08 15:28:24 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
|
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
|
|
|
|
handle_get_param_request (GstRTSPClient * client, GstRTSPUrl * uri,
|
|
|
|
GstRTSPSession * session, GstRTSPMessage * request)
|
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
|
|
|
|
|
|
|
res = gst_rtsp_message_get_body (request, &data, &size);
|
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
/* no body, keep-alive request */
|
|
|
|
send_generic_response (client, GST_RTSP_STS_OK, request);
|
|
|
|
} else {
|
|
|
|
/* there is a body */
|
|
|
|
GstRTSPMessage response = { 0 };
|
|
|
|
|
|
|
|
/* there is a body, handle the params */
|
|
|
|
res = gst_rtsp_params_get (client, uri, session, request, &response);
|
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
|
|
|
send_response (client, session, &response);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
bad_request:
|
|
|
|
{
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
handle_set_param_request (GstRTSPClient * client, GstRTSPUrl * uri,
|
|
|
|
GstRTSPSession * session, GstRTSPMessage * request)
|
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
|
|
|
|
|
|
|
res = gst_rtsp_message_get_body (request, &data, &size);
|
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
/* no body, keep-alive request */
|
|
|
|
send_generic_response (client, GST_RTSP_STS_OK, request);
|
|
|
|
} else {
|
|
|
|
GstRTSPMessage response = { 0 };
|
|
|
|
|
|
|
|
/* there is a body, handle the params */
|
|
|
|
res = gst_rtsp_params_set (client, uri, session, request, &response);
|
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
|
|
|
send_response (client, session, &response);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
bad_request:
|
|
|
|
{
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static gboolean
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_pause_request (GstRTSPClient * client, GstRTSPUrl * uri,
|
|
|
|
GstRTSPSession * session, GstRTSPMessage * request)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPSessionMedia *media;
|
|
|
|
GstRTSPMessage response = { 0 };
|
|
|
|
GstRTSPStatusCode code;
|
|
|
|
|
2009-02-13 18:52:05 +00:00
|
|
|
if (!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 */
|
2009-01-29 12:31:27 +00:00
|
|
|
media = gst_rtsp_session_get_media (session, uri);
|
2009-01-08 15:28:24 +00:00
|
|
|
if (!media)
|
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* the session state must be playing or recording */
|
|
|
|
if (media->state != GST_RTSP_STATE_PLAYING &&
|
|
|
|
media->state != GST_RTSP_STATE_RECORDING)
|
|
|
|
goto invalid_state;
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* unlink the all TCP callbacks */
|
|
|
|
unlink_session_streams (client, media);
|
|
|
|
|
|
|
|
/* 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;
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_init_response (&response, code,
|
|
|
|
gst_rtsp_status_as_text (code), request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-13 11:57:45 +00:00
|
|
|
send_response (client, session, &response);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* the state is now READY */
|
|
|
|
media->state = GST_RTSP_STATE_READY;
|
|
|
|
|
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
|
|
|
{
|
2009-02-13 18:52:05 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-08 15:28:24 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
|
2009-01-08 15:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-02-03 18:32:38 +00:00
|
|
|
invalid_state:
|
|
|
|
{
|
2009-05-26 17:01:10 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
|
|
|
|
request);
|
2009-02-03 18:32:38 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_play_request (GstRTSPClient * client, GstRTSPUrl * uri,
|
|
|
|
GstRTSPSession * session, GstRTSPMessage * request)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPSessionMedia *media;
|
|
|
|
GstRTSPMessage response = { 0 };
|
|
|
|
GstRTSPStatusCode code;
|
|
|
|
GString *rtpinfo;
|
2009-05-23 14:17:02 +00:00
|
|
|
guint n_streams, i, infocount;
|
2008-10-09 12:29:12 +00:00
|
|
|
guint timestamp, seqnum;
|
2009-02-04 16:00:42 +00:00
|
|
|
gchar *str;
|
2009-03-12 19:32:14 +00:00
|
|
|
GstRTSPTimeRange *range;
|
|
|
|
GstRTSPResult res;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-13 18:52:05 +00:00
|
|
|
if (!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 */
|
2009-01-29 12:31:27 +00:00
|
|
|
media = gst_rtsp_session_get_media (session, uri);
|
2009-01-08 15:28:24 +00:00
|
|
|
if (!media)
|
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* the session state must be playing or ready */
|
|
|
|
if (media->state != GST_RTSP_STATE_PLAYING &&
|
|
|
|
media->state != GST_RTSP_STATE_READY)
|
|
|
|
goto invalid_state;
|
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
/* parse the range header if we have one */
|
|
|
|
res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_RANGE, &str, 0);
|
|
|
|
if (res == GST_RTSP_OK) {
|
|
|
|
if (gst_rtsp_range_parse (str, &range) == GST_RTSP_OK) {
|
|
|
|
/* we have a range, seek to the position */
|
|
|
|
gst_rtsp_media_seek (media->media, range);
|
|
|
|
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
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
n_streams = gst_rtsp_media_n_streams (media->media);
|
2009-05-23 14:17:02 +00:00
|
|
|
for (i = 0, infocount = 0; i < n_streams; i++) {
|
2009-03-11 15:45:12 +00:00
|
|
|
GstRTSPSessionStream *sstream;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPMediaStream *stream;
|
2009-03-11 15:45:12 +00:00
|
|
|
GstRTSPTransport *tr;
|
2009-05-23 14:17:02 +00:00
|
|
|
GObjectClass *payobjclass;
|
2009-01-22 16:58:19 +00:00
|
|
|
gchar *uristr;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* get the stream as configured in the session */
|
|
|
|
sstream = gst_rtsp_session_media_get_stream (media, i);
|
|
|
|
/* get the transport, if there is no transport configured, skip this stream */
|
2009-05-26 17:01:10 +00:00
|
|
|
if (!(tr = sstream->trans.transport)) {
|
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
|
|
|
}
|
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 */
|
|
|
|
link_stream (client, sstream);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = sstream->media_stream;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-05-23 14:17:02 +00:00
|
|
|
payobjclass = G_OBJECT_GET_CLASS (stream->payloader);
|
|
|
|
|
|
|
|
if (g_object_class_find_property (payobjclass, "seqnum") &&
|
2009-05-26 17:01:10 +00:00
|
|
|
g_object_class_find_property (payobjclass, "timestamp")) {
|
2009-05-23 14:17:02 +00:00
|
|
|
GObject *payobj;
|
|
|
|
|
|
|
|
payobj = G_OBJECT (stream->payloader);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-05-23 14:17:02 +00:00
|
|
|
/* only add RTP-Info for streams with seqnum and timestamp */
|
|
|
|
g_object_get (payobj, "seqnum", &seqnum, "timestamp", ×tamp, NULL);
|
2009-01-22 16:58:19 +00:00
|
|
|
|
2009-05-23 14:17:02 +00:00
|
|
|
if (infocount > 0)
|
|
|
|
g_string_append (rtpinfo, ", ");
|
|
|
|
|
|
|
|
uristr = gst_rtsp_url_get_request_uri (uri);
|
2009-05-26 17:01:10 +00:00
|
|
|
g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u",
|
|
|
|
uristr, i, seqnum, timestamp);
|
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;
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_init_response (&response, code,
|
|
|
|
gst_rtsp_status_as_text (code), 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);
|
|
|
|
gst_rtsp_message_take_header (&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 */
|
|
|
|
str = gst_rtsp_range_to_string (&media->media->range);
|
|
|
|
gst_rtsp_message_take_header (&response, GST_RTSP_HDR_RANGE, str);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-13 11:57:45 +00:00
|
|
|
send_response (client, session, &response);
|
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
|
|
|
|
|
|
|
media->state = GST_RTSP_STATE_PLAYING;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
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
|
|
|
{
|
2009-02-18 17:57:31 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-08 15:28:24 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
|
2009-01-08 15:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-02-03 18:32:38 +00:00
|
|
|
invalid_state:
|
|
|
|
{
|
2009-05-26 17:01:10 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
|
|
|
|
request);
|
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);
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static gboolean
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_setup_request (GstRTSPClient * client, GstRTSPUrl * uri,
|
|
|
|
GstRTSPSession * session, GstRTSPMessage * request)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
gchar *transport;
|
|
|
|
gchar **transports;
|
|
|
|
gboolean have_transport;
|
|
|
|
GstRTSPTransport *ct, *st;
|
|
|
|
gint i;
|
|
|
|
GstRTSPLowerTrans supported;
|
|
|
|
GstRTSPMessage response = { 0 };
|
|
|
|
GstRTSPStatusCode code;
|
|
|
|
GstRTSPSessionStream *stream;
|
|
|
|
gchar *trans_str, *pos;
|
|
|
|
guint streamid;
|
|
|
|
GstRTSPSessionMedia *media;
|
|
|
|
gboolean need_session;
|
2009-03-04 11:44:01 +00:00
|
|
|
GstRTSPUrl *url;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
/* the uri contains the stream number we added in the SDP config, which is
|
2009-01-22 16:58:19 +00:00
|
|
|
* always /stream=%d so we need to strip that off
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we can mofify the parse uri in place */
|
|
|
|
*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 =
|
|
|
|
gst_rtsp_message_get_header (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
|
|
|
|
|
|
|
transports = g_strsplit (transport, ",", 0);
|
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
|
|
|
/* init transports */
|
2008-10-09 12:29:12 +00:00
|
|
|
have_transport = FALSE;
|
2010-03-05 12:31:37 +00:00
|
|
|
gst_rtsp_transport_init (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
|
|
|
|
|
|
|
/* loop through the transports, try to parse */
|
|
|
|
for (i = 0; transports[i]; i++) {
|
2008-10-09 12:29:12 +00:00
|
|
|
res = gst_rtsp_transport_parse (transports[i], ct);
|
2010-03-05 12:31:37 +00:00
|
|
|
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 */
|
2010-03-16 17:33:23 +00:00
|
|
|
if (ct->trans != GST_RTSP_TRANS_RTP || ct->profile != GST_RTSP_PROFILE_AVP) {
|
2010-03-05 12:31:37 +00:00
|
|
|
GST_WARNING ("invalid transport %s", transports[i]);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ct->lower_transport & supported)) {
|
|
|
|
GST_WARNING ("unsupported transport %s", transports[i]);
|
|
|
|
goto next;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2010-03-05 12:31:37 +00:00
|
|
|
|
|
|
|
/* we have a valid transport */
|
|
|
|
GST_INFO ("found valid transport %s", transports[i]);
|
|
|
|
have_transport = TRUE;
|
|
|
|
break;
|
|
|
|
|
2010-03-16 17:33:23 +00:00
|
|
|
next:
|
2010-03-05 12:31:37 +00:00
|
|
|
gst_rtsp_transport_init (ct);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
g_strfreev (transports);
|
|
|
|
|
|
|
|
/* we have not found anything usable, error out */
|
2009-05-26 17:01:10 +00:00
|
|
|
if (!have_transport)
|
2008-10-09 12:29:12 +00:00
|
|
|
goto unsupported_transports;
|
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
if (client->session_pool == NULL)
|
|
|
|
goto no_pool;
|
|
|
|
|
2009-01-30 15:24:10 +00:00
|
|
|
/* we have a valid transport now, set the destination of the client. */
|
|
|
|
g_free (ct->destination);
|
2010-03-05 12:31:37 +00:00
|
|
|
if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
|
2010-03-19 17:03:40 +00:00
|
|
|
ct->destination = g_strdup (MCAST_ADDRESS);
|
2010-03-05 12:31:37 +00:00
|
|
|
} else {
|
|
|
|
url = gst_rtsp_connection_get_url (client->connection);
|
|
|
|
ct->destination = g_strdup (url->host);
|
|
|
|
}
|
2009-01-30 15:24:10 +00:00
|
|
|
|
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. */
|
|
|
|
media = gst_rtsp_session_get_media (session, uri);
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
need_session = FALSE;
|
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. */
|
2009-01-29 12:31:27 +00:00
|
|
|
if (!(session = gst_rtsp_session_pool_create (client->session_pool)))
|
2008-10-09 12:29:12 +00:00
|
|
|
goto service_unavailable;
|
2009-02-04 16:00:42 +00:00
|
|
|
|
|
|
|
/* we need a new media configuration in this session */
|
|
|
|
media = NULL;
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
need_session = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
/* we have no media, find one and manage it */
|
|
|
|
if (media == NULL) {
|
2009-01-29 12:31:27 +00:00
|
|
|
GstRTSPMedia *m;
|
|
|
|
|
|
|
|
/* get a handle to the configuration of the media in the session */
|
|
|
|
if ((m = find_media (client, uri, request))) {
|
2009-01-30 15:24:10 +00:00
|
|
|
/* manage the media in our session now */
|
2009-01-29 12:31:27 +00:00
|
|
|
media = gst_rtsp_session_manage_media (session, uri, m);
|
|
|
|
}
|
|
|
|
}
|
2009-02-04 16:00:42 +00:00
|
|
|
|
|
|
|
/* if we stil have no media, error */
|
|
|
|
if (media == NULL)
|
2009-01-08 15:28:24 +00:00
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-07-27 17:42:44 +00:00
|
|
|
/* fix the transports */
|
|
|
|
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 (media, &ct->interleaved);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* get a handle to the stream in the media */
|
2009-01-29 12:31:27 +00:00
|
|
|
if (!(stream = gst_rtsp_session_media_get_stream (media, streamid)))
|
|
|
|
goto no_stream;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
st = gst_rtsp_session_stream_set_transport (stream, ct);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
/* configure keepalive for this transport */
|
|
|
|
gst_rtsp_session_stream_set_keepalive (stream,
|
2010-03-16 17:33:23 +00:00
|
|
|
(GstRTSPKeepAliveFunc) do_keepalive, session, NULL);
|
2009-05-26 17:01:10 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* serialize the server transport */
|
|
|
|
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;
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_init_response (&response, code,
|
|
|
|
gst_rtsp_status_as_text (code), request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
gst_rtsp_message_add_header (&response, GST_RTSP_HDR_TRANSPORT, trans_str);
|
|
|
|
g_free (trans_str);
|
|
|
|
|
2009-02-13 11:57:45 +00:00
|
|
|
send_response (client, session, &response);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* update the state */
|
|
|
|
switch (media->state) {
|
|
|
|
case GST_RTSP_STATE_PLAYING:
|
|
|
|
case GST_RTSP_STATE_RECORDING:
|
|
|
|
case GST_RTSP_STATE_READY:
|
|
|
|
/* no state change */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
media->state = GST_RTSP_STATE_READY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_object_unref (session);
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
bad_request:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-22 14:33:29 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
|
2009-02-13 18:52:05 +00:00
|
|
|
g_object_unref (session);
|
2009-01-22 14:33:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_stream:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, request);
|
2009-02-04 16:00:42 +00:00
|
|
|
g_object_unref (media);
|
2009-02-13 18:52:05 +00:00
|
|
|
g_object_unref (session);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_transport:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, request);
|
2009-01-29 12:31:27 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
unsupported_transports:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, request);
|
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:
|
|
|
|
{
|
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
service_unavailable:
|
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
|
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)
|
|
|
|
{
|
|
|
|
GstSDPMessage *sdp;
|
|
|
|
GstSDPInfo info;
|
|
|
|
const gchar *proto;
|
|
|
|
|
|
|
|
gst_sdp_message_new (&sdp);
|
|
|
|
|
|
|
|
/* some standard things first */
|
|
|
|
gst_sdp_message_set_version (sdp, "0");
|
|
|
|
|
|
|
|
if (client->is_ipv6)
|
|
|
|
proto = "IP6";
|
|
|
|
else
|
|
|
|
proto = "IP4";
|
|
|
|
|
|
|
|
gst_sdp_message_set_origin (sdp, "-", "1188340656180883", "1", "IN", proto,
|
|
|
|
client->server_ip);
|
|
|
|
|
|
|
|
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;
|
2010-03-19 17:03:40 +00:00
|
|
|
if (media->protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST)
|
|
|
|
info.server_ip = MCAST_ADDRESS;
|
|
|
|
else
|
|
|
|
info.server_ip = client->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;
|
|
|
|
|
|
|
|
return sdp;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_sdp:
|
|
|
|
{
|
|
|
|
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
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_describe_request (GstRTSPClient * client, GstRTSPUrl * uri,
|
|
|
|
GstRTSPSession * session, GstRTSPMessage * request)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPMessage response = { 0 };
|
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;
|
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 =
|
|
|
|
gst_rtsp_message_get_header (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 */
|
|
|
|
if (!(media = find_media (client, uri, request)))
|
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 */
|
|
|
|
if (!(sdp = 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);
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK,
|
|
|
|
gst_rtsp_status_as_text (GST_RTSP_STS_OK), request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONTENT_TYPE,
|
|
|
|
"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 */
|
2010-03-09 12:43:29 +00:00
|
|
|
str = gst_rtsp_url_get_request_uri (uri);
|
|
|
|
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);
|
|
|
|
|
|
|
|
gst_rtsp_message_add_header (&response, GST_RTSP_HDR_CONTENT_BASE,
|
|
|
|
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);
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_take_body (&response, (guint8 *) str, strlen (str));
|
2008-10-09 12:29:12 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
|
|
|
|
2009-03-11 18:38:06 +00:00
|
|
|
send_response (client, session, &response);
|
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
|
|
|
{
|
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
|
|
|
{
|
2009-01-29 17:51:02 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
|
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
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_options_request (GstRTSPClient * client, GstRTSPUrl * uri,
|
|
|
|
GstRTSPSession * session, GstRTSPMessage * request)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPMessage response = { 0 };
|
|
|
|
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
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK,
|
|
|
|
gst_rtsp_status_as_text (GST_RTSP_STS_OK), request);
|
2009-01-22 17:35:17 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
gst_rtsp_message_add_header (&response, GST_RTSP_HDR_PUBLIC, str);
|
|
|
|
g_free (str);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-03-11 18:38:06 +00:00
|
|
|
send_response (client, session, &response);
|
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
|
2009-05-26 17:01:10 +00:00
|
|
|
santize_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
|
|
|
{
|
2009-03-11 19:03:06 +00:00
|
|
|
if (!(client->sessions = g_list_remove (client->sessions, session))) {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("all sessions finalized, close the connection");
|
2009-05-26 17:01:10 +00:00
|
|
|
g_source_destroy ((GSource *) client->watch);
|
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
|
|
|
{
|
|
|
|
GList *walk;
|
|
|
|
|
|
|
|
for (walk = client->sessions; walk; walk = g_list_next (walk)) {
|
|
|
|
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);
|
2009-03-11 18:38:06 +00:00
|
|
|
client->sessions = g_list_prepend (client->sessions, session);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
GstRTSPMethod method;
|
2009-01-22 16:58:19 +00:00
|
|
|
const gchar *uristr;
|
|
|
|
GstRTSPUrl *uri;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPVersion version;
|
2009-02-18 17:57:31 +00:00
|
|
|
GstRTSPResult res;
|
|
|
|
GstRTSPSession *session;
|
|
|
|
gchar *sessid;
|
2008-10-09 12:29:12 +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
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
if (version != GST_RTSP_VERSION_1_0) {
|
|
|
|
/* we can only handle 1.0 requests */
|
2009-05-26 17:01:10 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
|
|
|
|
request);
|
2009-02-18 17:57:31 +00:00
|
|
|
return;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* we always try to parse the url first */
|
|
|
|
if ((res = gst_rtsp_url_parse (uristr, &uri)) != GST_RTSP_OK) {
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request);
|
|
|
|
return;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* sanitize the uri */
|
|
|
|
santize_uri (uri);
|
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) {
|
|
|
|
if (client->session_pool == NULL)
|
|
|
|
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 */
|
|
|
|
if (!(session = gst_rtsp_session_pool_find (client->session_pool, sessid)))
|
|
|
|
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);
|
2009-05-26 17:01:10 +00:00
|
|
|
} else
|
2009-02-18 17:57:31 +00:00
|
|
|
session = NULL;
|
2009-01-20 12:57:47 +00:00
|
|
|
|
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:
|
|
|
|
handle_options_request (client, uri, session, request);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_DESCRIBE:
|
|
|
|
handle_describe_request (client, uri, session, request);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_SETUP:
|
|
|
|
handle_setup_request (client, uri, session, request);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_PLAY:
|
|
|
|
handle_play_request (client, uri, session, request);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_PAUSE:
|
|
|
|
handle_pause_request (client, uri, session, request);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_TEARDOWN:
|
|
|
|
handle_teardown_request (client, uri, session, request);
|
|
|
|
break;
|
2009-05-26 15:25:59 +00:00
|
|
|
case GST_RTSP_SET_PARAMETER:
|
2009-06-09 22:01:07 +00:00
|
|
|
handle_set_param_request (client, uri, session, request);
|
|
|
|
break;
|
2009-02-18 17:57:31 +00:00
|
|
|
case GST_RTSP_GET_PARAMETER:
|
2009-06-09 22:01:07 +00:00
|
|
|
handle_get_param_request (client, uri, session, request);
|
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:
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, request);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_INVALID:
|
|
|
|
default:
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, request);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (session)
|
|
|
|
g_object_unref (session);
|
2009-01-20 12:57:47 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
gst_rtsp_url_free (uri);
|
|
|
|
return;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-02-18 17:57:31 +00:00
|
|
|
no_pool:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2009-02-18 17:57:31 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, request);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
session_not_found:
|
|
|
|
{
|
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, request);
|
|
|
|
return;
|
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
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_DATA (buffer) = data;
|
|
|
|
GST_BUFFER_MALLOCDATA (buffer) = data;
|
|
|
|
GST_BUFFER_SIZE (buffer) = size;
|
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
handled = FALSE;
|
2009-03-11 15:45:12 +00:00
|
|
|
for (walk = client->streams; walk; walk = g_list_next (walk)) {
|
|
|
|
GstRTSPSessionStream *stream = (GstRTSPSessionStream *) walk->data;
|
|
|
|
GstRTSPMediaStream *mstream;
|
|
|
|
GstRTSPTransport *tr;
|
|
|
|
|
|
|
|
/* get the transport, if there is no transport configured, skip this stream */
|
|
|
|
if (!(tr = stream->trans.transport))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* we also need a media stream */
|
|
|
|
if (!(mstream = stream->media_stream))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* 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) {
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_media_stream_rtp (mstream, buffer);
|
|
|
|
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) {
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_media_stream_rtcp (mstream, buffer);
|
|
|
|
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;
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
old = client->session_pool;
|
2009-01-22 14:33:29 +00:00
|
|
|
if (old != pool) {
|
|
|
|
if (pool)
|
|
|
|
g_object_ref (pool);
|
2009-01-29 12:31:27 +00:00
|
|
|
client->session_pool = pool;
|
2009-01-22 14:33:29 +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.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPSessionPool, unref after usage.
|
|
|
|
*/
|
|
|
|
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
|
|
|
{
|
|
|
|
GstRTSPSessionPool *result;
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
if ((result = client->session_pool))
|
2008-10-09 12:29:12 +00:00
|
|
|
g_object_ref (result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-01-20 18:46:21 +00:00
|
|
|
/**
|
2009-01-22 14:33:29 +00:00
|
|
|
* gst_rtsp_client_set_media_mapping:
|
2009-01-20 18:46:21 +00:00
|
|
|
* @client: a #GstRTSPClient
|
2009-01-22 14:33:29 +00:00
|
|
|
* @mapping: a #GstRTSPMediaMapping
|
2009-01-20 18:46:21 +00:00
|
|
|
*
|
2009-01-22 14:33:29 +00:00
|
|
|
* Set @mapping as the media mapping for @client which it will use to map urls
|
|
|
|
* to media streams. These mapping is usually inherited from the server that
|
|
|
|
* created the client but can be overriden later.
|
2009-01-20 18:46:21 +00:00
|
|
|
*/
|
|
|
|
void
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_set_media_mapping (GstRTSPClient * client,
|
|
|
|
GstRTSPMediaMapping * mapping)
|
2009-01-20 18:46:21 +00:00
|
|
|
{
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPMediaMapping *old;
|
2009-01-20 18:46:21 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
old = client->media_mapping;
|
2009-01-20 18:46:21 +00:00
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
if (old != mapping) {
|
|
|
|
if (mapping)
|
|
|
|
g_object_ref (mapping);
|
2009-01-29 12:31:27 +00:00
|
|
|
client->media_mapping = mapping;
|
2009-01-20 18:46:21 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-22 14:33:29 +00:00
|
|
|
* gst_rtsp_client_get_media_mapping:
|
2009-01-20 18:46:21 +00:00
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
2009-01-22 14:33:29 +00:00
|
|
|
* Get the #GstRTSPMediaMapping object that @client uses to manage its sessions.
|
2009-01-20 18:46:21 +00:00
|
|
|
*
|
2009-01-22 14:33:29 +00:00
|
|
|
* Returns: a #GstRTSPMediaMapping, unref after usage.
|
2009-01-20 18:46:21 +00:00
|
|
|
*/
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPMediaMapping *
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_get_media_mapping (GstRTSPClient * client)
|
2009-01-20 18:46:21 +00:00
|
|
|
{
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPMediaMapping *result;
|
2009-01-20 18:46:21 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
if ((result = client->media_mapping))
|
2009-01-20 18:46:21 +00:00
|
|
|
g_object_ref (result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
static GstRTSPResult
|
2009-05-26 17:01:10 +00:00
|
|
|
message_received (GstRTSPWatch * watch, GstRTSPMessage * message,
|
|
|
|
gpointer user_data)
|
2009-02-18 17:57:31 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2009-07-27 17:42:44 +00:00
|
|
|
GstRTSPClient *client;
|
2010-03-16 17:33:23 +00:00
|
|
|
|
2009-07-27 17:42:44 +00:00
|
|
|
client = GST_RTSP_CLIENT (user_data);
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
/* GST_INFO ("client %p: sent a message with cseq %d", client, cseq); */
|
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);
|
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
|
|
|
|
2009-03-04 15:33:21 +00:00
|
|
|
if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
|
|
|
|
g_mutex_lock (tunnels_lock);
|
|
|
|
g_hash_table_remove (tunnels, tunnelid);
|
|
|
|
g_mutex_unlock (tunnels_lock);
|
|
|
|
}
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* remove all streams that are streaming over this client connection */
|
|
|
|
unlink_streams (client);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-03-04 11:44:01 +00:00
|
|
|
static GstRTSPStatusCode
|
2009-05-26 17:01:10 +00:00
|
|
|
tunnel_start (GstRTSPWatch * watch, gpointer user_data)
|
2009-03-04 11:44:01 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client;
|
|
|
|
const gchar *tunnelid;
|
|
|
|
|
|
|
|
client = GST_RTSP_CLIENT (user_data);
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: tunnel start", client);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* store client in the pending tunnels */
|
|
|
|
tunnelid = gst_rtsp_connection_get_tunnelid (client->connection);
|
2009-07-24 10:49:41 +00:00
|
|
|
if (tunnelid == NULL)
|
|
|
|
goto no_tunnelid;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: inserting %s", client, tunnelid);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* we can't have two clients connecting with the same tunnelid */
|
|
|
|
g_mutex_lock (tunnels_lock);
|
|
|
|
if (g_hash_table_lookup (tunnels, tunnelid))
|
|
|
|
goto tunnel_existed;
|
|
|
|
|
|
|
|
g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
|
|
|
|
g_mutex_unlock (tunnels_lock);
|
|
|
|
|
|
|
|
return GST_RTSP_STS_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2009-07-24 10:49:41 +00:00
|
|
|
no_tunnelid:
|
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: no tunnelid provided", client);
|
2009-07-24 10:49:41 +00:00
|
|
|
return GST_RTSP_STS_SERVICE_UNAVAILABLE;
|
|
|
|
}
|
2009-03-04 11:44:01 +00:00
|
|
|
tunnel_existed:
|
|
|
|
{
|
|
|
|
g_mutex_unlock (tunnels_lock);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: tunnel session %s existed", client, tunnelid);
|
2009-03-04 11:44:01 +00:00
|
|
|
return GST_RTSP_STS_SERVICE_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
GstRTSPClient *oclient;
|
|
|
|
|
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 */
|
|
|
|
tunnelid = gst_rtsp_connection_get_tunnelid (client->connection);
|
2009-07-24 10:49:41 +00:00
|
|
|
if (tunnelid == NULL)
|
|
|
|
goto no_tunnelid;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
g_mutex_lock (tunnels_lock);
|
|
|
|
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);
|
|
|
|
g_mutex_unlock (tunnels_lock);
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: found tunnel %p", client, oclient);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* merge the tunnels into the first client */
|
|
|
|
gst_rtsp_connection_do_tunnel (oclient->connection, client->connection);
|
|
|
|
gst_rtsp_watch_reset (oclient->watch);
|
|
|
|
g_object_unref (oclient);
|
|
|
|
|
|
|
|
/* we don't need this watch anymore */
|
2009-06-11 09:27:47 +00:00
|
|
|
g_source_destroy ((GSource *) client->watch);
|
|
|
|
client->watchid = 0;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2009-07-24 10:49:41 +00:00
|
|
|
no_tunnelid:
|
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: no tunnelid provided", client);
|
2009-07-24 10:49:41 +00:00
|
|
|
return GST_RTSP_STS_SERVICE_UNAVAILABLE;
|
|
|
|
}
|
2009-03-04 11:44:01 +00:00
|
|
|
no_tunnel:
|
|
|
|
{
|
|
|
|
g_mutex_unlock (tunnels_lock);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: tunnel session %s not found", client, tunnelid);
|
2009-07-24 10:49:41 +00:00
|
|
|
return GST_RTSP_STS_SERVICE_UNAVAILABLE;
|
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,
|
|
|
|
error_full
|
2009-02-18 17:57:31 +00:00
|
|
|
};
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_attach:
|
|
|
|
* @client: a #GstRTSPClient
|
2009-01-19 18:34:29 +00:00
|
|
|
* @channel: a #GIOChannel
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2009-12-25 17:24:10 +00:00
|
|
|
* Accept a new connection for @client on the socket in @channel.
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
|
|
|
* This function should be called when the client properties and urls are fully
|
|
|
|
* configured and the client is ready to start.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the client could be accepted.
|
|
|
|
*/
|
|
|
|
gboolean
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_accept (GstRTSPClient * client, GIOChannel * channel)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2010-03-16 17:33:23 +00:00
|
|
|
int sock, fd;
|
2009-02-18 17:57:31 +00:00
|
|
|
GstRTSPConnection *conn;
|
|
|
|
GstRTSPResult res;
|
|
|
|
GSource *source;
|
|
|
|
GMainContext *context;
|
2009-03-04 11:44:01 +00:00
|
|
|
GstRTSPUrl *url;
|
2010-03-16 17:33:23 +00:00
|
|
|
struct sockaddr_storage addr;
|
|
|
|
socklen_t addrlen;
|
|
|
|
gchar ip[INET6_ADDRSTRLEN];
|
2009-02-18 17:57:31 +00:00
|
|
|
|
|
|
|
/* a new client connected. */
|
|
|
|
sock = g_io_channel_unix_get_fd (channel);
|
|
|
|
|
|
|
|
GST_RTSP_CHECK (gst_rtsp_connection_accept (sock, &conn), accept_failed);
|
2009-01-29 17:51:02 +00:00
|
|
|
|
2010-03-16 17:33:23 +00:00
|
|
|
fd = gst_rtsp_connection_get_readfd (conn);
|
|
|
|
|
|
|
|
addrlen = sizeof (addr);
|
|
|
|
if (getsockname (fd, (struct sockaddr *) &addr, &addrlen) < 0)
|
|
|
|
goto getpeername_failed;
|
|
|
|
|
|
|
|
client->is_ipv6 = addr.ss_family == AF_INET6;
|
|
|
|
|
|
|
|
addrlen = sizeof (addr);
|
|
|
|
if (getnameinfo ((struct sockaddr *) &addr, addrlen, ip, sizeof (ip), NULL, 0,
|
|
|
|
NI_NUMERICHOST) != 0)
|
|
|
|
goto getnameinfo_failed;
|
|
|
|
|
|
|
|
/* keep the original ip that the client connected to */
|
|
|
|
g_free (client->server_ip);
|
|
|
|
client->server_ip = g_strndup (ip, sizeof (ip));
|
|
|
|
|
|
|
|
GST_INFO ("client %p connected to server ip %s, ipv6 = %d", client,
|
|
|
|
client->server_ip, client->is_ipv6);
|
|
|
|
|
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
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
client->connection = conn;
|
|
|
|
|
2009-02-19 14:53:50 +00:00
|
|
|
/* create watch for the connection and attach */
|
|
|
|
client->watch = gst_rtsp_watch_new (client->connection, &watch_funcs,
|
2009-05-26 17:01:10 +00:00
|
|
|
g_object_ref (client), g_object_unref);
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2009-02-19 14:53:50 +00:00
|
|
|
/* find the context to add the watch */
|
2009-02-18 17:57:31 +00:00
|
|
|
if ((source = g_main_current_source ()))
|
|
|
|
context = g_source_get_context (source);
|
|
|
|
else
|
|
|
|
context = NULL;
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("attaching to context %p", context);
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2009-03-04 11:44:01 +00:00
|
|
|
client->watchid = gst_rtsp_watch_attach (client->watch, context);
|
2009-02-19 14:53:50 +00:00
|
|
|
gst_rtsp_watch_unref (client->watch);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
accept_failed:
|
|
|
|
{
|
2009-02-18 17:57:31 +00:00
|
|
|
gchar *str = gst_rtsp_strresult (res);
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_ERROR ("Could not accept client on server socket %d: %s", sock, str);
|
2009-02-18 17:57:31 +00:00
|
|
|
g_free (str);
|
2009-01-29 17:51:02 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-03-16 17:33:23 +00:00
|
|
|
getpeername_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("getpeername failed: %s", g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
getnameinfo_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("getnameinfo failed: %s", g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|