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.
|
|
|
|
*/
|
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <arpa/inet.h>
|
2011-01-11 23:17:54 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
#include "rtsp-server.h"
|
|
|
|
#include "rtsp-client.h"
|
|
|
|
|
2010-03-09 12:49:00 +00:00
|
|
|
#define DEFAULT_ADDRESS "0.0.0.0"
|
2010-03-10 10:45:30 +00:00
|
|
|
/* #define DEFAULT_ADDRESS "::0" */
|
2010-03-09 12:49:00 +00:00
|
|
|
#define DEFAULT_SERVICE "8554"
|
2009-01-19 18:36:23 +00:00
|
|
|
#define DEFAULT_BACKLOG 5
|
|
|
|
|
2010-08-20 08:18:34 +00:00
|
|
|
/* Define to use the SO_LINGER option so that the server sockets can be resused
|
|
|
|
* sooner. Disabled for now because it is not very well implemented by various
|
|
|
|
* OSes and it causes clients to fail to read the TEARDOWN response. */
|
|
|
|
#undef USE_SOLINGER
|
|
|
|
|
2009-01-08 12:41:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2009-01-19 18:36:23 +00:00
|
|
|
PROP_0,
|
2010-03-09 12:49:00 +00:00
|
|
|
PROP_ADDRESS,
|
|
|
|
PROP_SERVICE,
|
2009-01-19 18:36:23 +00:00
|
|
|
PROP_BACKLOG,
|
2010-03-09 12:49:00 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
PROP_SESSION_POOL,
|
|
|
|
PROP_MEDIA_MAPPING,
|
2009-01-19 18:36:23 +00:00
|
|
|
PROP_LAST
|
2009-01-08 12:41:33 +00:00
|
|
|
};
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstRTSPServer, gst_rtsp_server, G_TYPE_OBJECT);
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_server_debug);
|
|
|
|
#define GST_CAT_DEFAULT rtsp_server_debug
|
|
|
|
|
2010-12-11 09:48:42 +00:00
|
|
|
static void gst_rtsp_server_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_server_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_server_finalize (GObject * object);
|
2009-01-08 12:41:33 +00:00
|
|
|
|
2011-01-12 09:57:08 +00:00
|
|
|
static GstRTSPClient *default_create_client (GstRTSPServer * server);
|
|
|
|
static gboolean default_accept_client (GstRTSPServer * server,
|
|
|
|
GstRTSPClient * client, GIOChannel * channel);
|
2009-01-20 12:19:36 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static void
|
|
|
|
gst_rtsp_server_class_init (GstRTSPServerClass * klass)
|
2010-03-09 12:49:00 +00:00
|
|
|
{
|
2008-10-09 12:29:12 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2010-03-09 12:49:00 +00:00
|
|
|
|
2009-01-08 12:41:33 +00:00
|
|
|
gobject_class->get_property = gst_rtsp_server_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_server_set_property;
|
2009-04-18 14:10:59 +00:00
|
|
|
gobject_class->finalize = gst_rtsp_server_finalize;
|
2010-03-09 12:49:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstRTSPServer::address
|
|
|
|
*
|
|
|
|
* The address of the server. This is the address where the server will
|
|
|
|
* listen on.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_ADDRESS,
|
2010-12-11 09:48:42 +00:00
|
|
|
g_param_spec_string ("address", "Address",
|
|
|
|
"The address the server uses to listen on", DEFAULT_ADDRESS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2010-03-09 12:49:00 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPServer::service
|
|
|
|
*
|
|
|
|
* The service of the server. This is either a string with the service name or
|
|
|
|
* a port number (as a string) the server will listen on.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SERVICE,
|
2010-12-11 09:48:42 +00:00
|
|
|
g_param_spec_string ("service", "Service",
|
|
|
|
"The service or port number the server uses to listen on",
|
2010-03-09 12:49:00 +00:00
|
|
|
DEFAULT_SERVICE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-01-19 18:36:23 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPServer::backlog
|
|
|
|
*
|
|
|
|
* The backlog argument defines the maximum length to which the queue of
|
|
|
|
* pending connections for the server may grow. If a connection request arrives
|
|
|
|
* when the queue is full, the client may receive an error with an indication of
|
|
|
|
* ECONNREFUSED or, if the underlying protocol supports retransmission, the
|
|
|
|
* request may be ignored so that a later reattempt at connection succeeds.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_BACKLOG,
|
2010-12-11 09:48:42 +00:00
|
|
|
g_param_spec_int ("backlog", "Backlog",
|
|
|
|
"The maximum length to which the queue "
|
|
|
|
"of pending connections may grow", 0, G_MAXINT, DEFAULT_BACKLOG,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-01-19 18:36:23 +00:00
|
|
|
/**
|
2009-01-29 12:31:27 +00:00
|
|
|
* GstRTSPServer::session-pool
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
|
|
|
* The session pool of the server. By default each server has a separate
|
|
|
|
* session pool but sessions can be shared between servers by setting the same
|
|
|
|
* session pool on multiple servers.
|
|
|
|
*/
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
|
|
|
|
g_param_spec_object ("session-pool", "Session Pool",
|
2010-03-09 12:49:00 +00:00
|
|
|
"The session pool to use for client session",
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_TYPE_RTSP_SESSION_POOL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-01-20 18:47:07 +00:00
|
|
|
/**
|
2009-01-29 12:31:27 +00:00
|
|
|
* GstRTSPServer::media-mapping
|
2009-01-20 18:47:07 +00:00
|
|
|
*
|
2009-01-22 14:33:29 +00:00
|
|
|
* The media mapping to use for this server. By default the server has no
|
|
|
|
* media mapping and thus cannot map urls to media streams.
|
2009-01-20 18:47:07 +00:00
|
|
|
*/
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MEDIA_MAPPING,
|
|
|
|
g_param_spec_object ("media-mapping", "Media Mapping",
|
2010-03-09 12:49:00 +00:00
|
|
|
"The media mapping to use for client session",
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_TYPE_RTSP_MEDIA_MAPPING,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-01-20 12:19:36 +00:00
|
|
|
|
2011-01-12 09:57:08 +00:00
|
|
|
klass->create_client = default_create_client;
|
2009-01-30 13:53:28 +00:00
|
|
|
klass->accept_client = default_accept_client;
|
2009-11-21 18:20:23 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_server_debug, "rtspserver", 0, "GstRTSPServer");
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_server_init (GstRTSPServer * server)
|
|
|
|
{
|
2011-01-12 09:57:08 +00:00
|
|
|
server->lock = g_mutex_new ();
|
2010-03-09 12:49:00 +00:00
|
|
|
server->address = g_strdup (DEFAULT_ADDRESS);
|
|
|
|
server->service = g_strdup (DEFAULT_SERVICE);
|
2009-01-19 18:36:23 +00:00
|
|
|
server->backlog = DEFAULT_BACKLOG;
|
2009-01-29 12:31:27 +00:00
|
|
|
server->session_pool = gst_rtsp_session_pool_new ();
|
|
|
|
server->media_mapping = gst_rtsp_media_mapping_new ();
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 14:10:59 +00:00
|
|
|
static void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_finalize (GObject * object)
|
2009-04-18 14:10:59 +00:00
|
|
|
{
|
|
|
|
GstRTSPServer *server = GST_RTSP_SERVER (object);
|
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "finalize server");
|
|
|
|
|
2010-03-09 12:49:00 +00:00
|
|
|
g_free (server->address);
|
|
|
|
g_free (server->service);
|
|
|
|
|
2009-04-18 14:10:59 +00:00
|
|
|
g_object_unref (server->session_pool);
|
|
|
|
g_object_unref (server->media_mapping);
|
2011-01-12 11:07:04 +00:00
|
|
|
|
|
|
|
if (server->auth)
|
|
|
|
g_object_unref (server->auth);
|
2011-01-12 15:38:34 +00:00
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
g_mutex_free (server->lock);
|
|
|
|
|
2011-01-12 15:38:34 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtsp_server_parent_class)->finalize (object);
|
2009-04-18 14:10:59 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_new:
|
|
|
|
*
|
|
|
|
* Create a new #GstRTSPServer instance.
|
|
|
|
*/
|
|
|
|
GstRTSPServer *
|
|
|
|
gst_rtsp_server_new (void)
|
|
|
|
{
|
|
|
|
GstRTSPServer *result;
|
|
|
|
|
|
|
|
result = g_object_new (GST_TYPE_RTSP_SERVER, NULL);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
/**
|
2010-03-09 12:49:00 +00:00
|
|
|
* gst_rtsp_server_set_address:
|
2009-01-19 18:36:23 +00:00
|
|
|
* @server: a #GstRTSPServer
|
2010-03-09 12:49:00 +00:00
|
|
|
* @address: the address
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
2010-03-09 12:49:00 +00:00
|
|
|
* Configure @server to accept connections on the given address.
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
|
|
|
* This function must be called before the server is bound.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_set_address (GstRTSPServer * server, const gchar * address)
|
2009-01-19 18:36:23 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
2010-03-09 12:49:00 +00:00
|
|
|
g_return_if_fail (address != NULL);
|
2009-01-19 18:36:23 +00:00
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2010-03-09 12:49:00 +00:00
|
|
|
g_free (server->address);
|
|
|
|
server->address = g_strdup (address);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2009-01-19 18:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-09 12:49:00 +00:00
|
|
|
* gst_rtsp_server_get_address:
|
2009-01-19 18:36:23 +00:00
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
2010-03-09 12:49:00 +00:00
|
|
|
* Get the address on which the server will accept connections.
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
2010-03-09 12:49:00 +00:00
|
|
|
* Returns: the server address. g_free() after usage.
|
2009-01-19 18:36:23 +00:00
|
|
|
*/
|
2010-03-09 12:49:00 +00:00
|
|
|
gchar *
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_get_address (GstRTSPServer * server)
|
2009-01-19 18:36:23 +00:00
|
|
|
{
|
2011-01-12 17:57:41 +00:00
|
|
|
gchar *result;
|
2010-03-09 12:49:00 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
|
|
|
result = g_strdup (server->address);
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
|
|
|
return result;
|
2010-03-09 12:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_set_service:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
* @service: the service
|
|
|
|
*
|
|
|
|
* Configure @server to accept connections on the given service.
|
|
|
|
* @service should be a string containing the service name (see services(5)) or
|
|
|
|
* a string containing a port number between 1 and 65535.
|
|
|
|
*
|
|
|
|
* This function must be called before the server is bound.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_set_service (GstRTSPServer * server, const gchar * service)
|
2010-03-09 12:49:00 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
g_return_if_fail (service != NULL);
|
2009-01-19 18:36:23 +00:00
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2010-03-09 12:49:00 +00:00
|
|
|
g_free (server->service);
|
|
|
|
server->service = g_strdup (service);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2010-03-09 12:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_get_service:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
|
|
|
* Get the service on which the server will accept connections.
|
|
|
|
*
|
|
|
|
* Returns: the service. use g_free() after usage.
|
|
|
|
*/
|
|
|
|
gchar *
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_get_service (GstRTSPServer * server)
|
2010-03-09 12:49:00 +00:00
|
|
|
{
|
2011-01-12 17:57:41 +00:00
|
|
|
gchar *result;
|
|
|
|
|
2010-03-09 12:49:00 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
|
|
|
result = g_strdup (server->service);
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
|
|
|
return result;
|
2009-01-19 18:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_set_backlog:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
* @backlog: the backlog
|
|
|
|
*
|
|
|
|
* configure the maximum amount of requests that may be queued for the
|
|
|
|
* server.
|
|
|
|
*
|
|
|
|
* This function must be called before the server is bound.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_set_backlog (GstRTSPServer * server, gint backlog)
|
2009-01-19 18:36:23 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2009-01-19 18:36:23 +00:00
|
|
|
server->backlog = backlog;
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2009-01-19 18:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_get_backlog:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
|
|
|
* The maximum amount of queued requests for the server.
|
|
|
|
*
|
|
|
|
* Returns: the server backlog.
|
|
|
|
*/
|
|
|
|
gint
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_get_backlog (GstRTSPServer * server)
|
2009-01-19 18:36:23 +00:00
|
|
|
{
|
2011-01-12 17:57:41 +00:00
|
|
|
gint result;
|
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), -1);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
|
|
|
result = server->backlog;
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
|
|
|
return result;
|
2009-01-19 18:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_set_session_pool:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
* @pool: a #GstRTSPSessionPool
|
|
|
|
*
|
|
|
|
* configure @pool to be used as the session pool of @server.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_set_session_pool (GstRTSPServer * server,
|
|
|
|
GstRTSPSessionPool * pool)
|
2009-01-19 18:36:23 +00:00
|
|
|
{
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPSessionPool *old;
|
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
if (pool)
|
|
|
|
g_object_ref (pool);
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2009-01-29 12:31:27 +00:00
|
|
|
old = server->session_pool;
|
2011-01-12 17:57:41 +00:00
|
|
|
server->session_pool = pool;
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2009-01-19 18:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_get_session_pool:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPSessionPool used as the session pool of @server.
|
|
|
|
*
|
|
|
|
* Returns: the #GstRTSPSessionPool used for sessions. g_object_unref() after
|
|
|
|
* usage.
|
|
|
|
*/
|
|
|
|
GstRTSPSessionPool *
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_get_session_pool (GstRTSPServer * server)
|
2009-01-19 18:36:23 +00:00
|
|
|
{
|
|
|
|
GstRTSPSessionPool *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2009-01-29 12:31:27 +00:00
|
|
|
if ((result = server->session_pool))
|
2009-01-19 18:36:23 +00:00
|
|
|
g_object_ref (result);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2009-01-19 18:36:23 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-01-20 18:47:07 +00:00
|
|
|
/**
|
2009-01-22 14:33:29 +00:00
|
|
|
* gst_rtsp_server_set_media_mapping:
|
2009-01-20 18:47:07 +00:00
|
|
|
* @server: a #GstRTSPServer
|
2009-01-22 14:33:29 +00:00
|
|
|
* @mapping: a #GstRTSPMediaMapping
|
2009-01-20 18:47:07 +00:00
|
|
|
*
|
2009-01-22 14:33:29 +00:00
|
|
|
* configure @mapping to be used as the media mapping of @server.
|
2009-01-20 18:47:07 +00:00
|
|
|
*/
|
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_set_media_mapping (GstRTSPServer * server,
|
|
|
|
GstRTSPMediaMapping * mapping)
|
2009-01-20 18:47:07 +00:00
|
|
|
{
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPMediaMapping *old;
|
2009-01-20 18:47:07 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
if (mapping)
|
|
|
|
g_object_ref (mapping);
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2009-01-29 12:31:27 +00:00
|
|
|
old = server->media_mapping;
|
2011-01-12 17:57:41 +00:00
|
|
|
server->media_mapping = mapping;
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2009-01-20 18:47:07 +00:00
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2009-01-20 18:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-22 14:33:29 +00:00
|
|
|
* gst_rtsp_server_get_media_mapping:
|
2009-01-20 18:47:07 +00:00
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
2009-01-22 14:33:29 +00:00
|
|
|
* Get the #GstRTSPMediaMapping used as the media mapping of @server.
|
2009-01-20 18:47:07 +00:00
|
|
|
*
|
2009-01-22 14:33:29 +00:00
|
|
|
* Returns: the #GstRTSPMediaMapping of @server. g_object_unref() after
|
2009-01-20 18:47:07 +00:00
|
|
|
* usage.
|
|
|
|
*/
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPMediaMapping *
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_get_media_mapping (GstRTSPServer * server)
|
2009-01-20 18:47:07 +00:00
|
|
|
{
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPMediaMapping *result;
|
2009-01-20 18:47:07 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2009-01-29 12:31:27 +00:00
|
|
|
if ((result = server->media_mapping))
|
2009-01-20 18:47:07 +00:00
|
|
|
g_object_ref (result);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2009-01-20 18:47:07 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-11 23:17:54 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_set_auth:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
* @auth: a #GstRTSPAuth
|
|
|
|
*
|
|
|
|
* configure @auth to be used as the authentication manager of @server.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_server_set_auth (GstRTSPServer * server, GstRTSPAuth * auth)
|
|
|
|
{
|
|
|
|
GstRTSPAuth *old;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
if (auth)
|
|
|
|
g_object_ref (auth);
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2011-01-11 23:17:54 +00:00
|
|
|
old = server->auth;
|
2011-01-12 17:57:41 +00:00
|
|
|
server->auth = auth;
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2011-01-11 23:17:54 +00:00
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2011-01-11 23:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_get_auth:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPAuth used as the authentication manager of @server.
|
|
|
|
*
|
|
|
|
* Returns: the #GstRTSPAuth of @server. g_object_unref() after
|
|
|
|
* usage.
|
|
|
|
*/
|
|
|
|
GstRTSPAuth *
|
|
|
|
gst_rtsp_server_get_auth (GstRTSPServer * server)
|
|
|
|
{
|
|
|
|
GstRTSPAuth *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2011-01-11 23:17:54 +00:00
|
|
|
if ((result = server->auth))
|
|
|
|
g_object_ref (result);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2011-01-11 23:17:54 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-01-08 12:41:33 +00:00
|
|
|
static void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2009-01-08 12:41:33 +00:00
|
|
|
{
|
|
|
|
GstRTSPServer *server = GST_RTSP_SERVER (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
2010-03-09 12:49:00 +00:00
|
|
|
case PROP_ADDRESS:
|
|
|
|
g_value_take_string (value, gst_rtsp_server_get_address (server));
|
|
|
|
break;
|
|
|
|
case PROP_SERVICE:
|
|
|
|
g_value_take_string (value, gst_rtsp_server_get_service (server));
|
2009-01-19 18:36:23 +00:00
|
|
|
break;
|
|
|
|
case PROP_BACKLOG:
|
|
|
|
g_value_set_int (value, gst_rtsp_server_get_backlog (server));
|
|
|
|
break;
|
2009-01-29 12:31:27 +00:00
|
|
|
case PROP_SESSION_POOL:
|
2009-01-19 18:36:23 +00:00
|
|
|
g_value_take_object (value, gst_rtsp_server_get_session_pool (server));
|
2009-01-08 12:41:33 +00:00
|
|
|
break;
|
2009-01-29 12:31:27 +00:00
|
|
|
case PROP_MEDIA_MAPPING:
|
2009-01-22 14:33:29 +00:00
|
|
|
g_value_take_object (value, gst_rtsp_server_get_media_mapping (server));
|
2009-01-20 18:47:07 +00:00
|
|
|
break;
|
2009-01-08 12:41:33 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2009-01-08 12:41:33 +00:00
|
|
|
{
|
|
|
|
GstRTSPServer *server = GST_RTSP_SERVER (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
2010-03-09 12:49:00 +00:00
|
|
|
case PROP_ADDRESS:
|
|
|
|
gst_rtsp_server_set_address (server, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
case PROP_SERVICE:
|
|
|
|
gst_rtsp_server_set_service (server, g_value_get_string (value));
|
2009-01-19 18:36:23 +00:00
|
|
|
break;
|
|
|
|
case PROP_BACKLOG:
|
|
|
|
gst_rtsp_server_set_backlog (server, g_value_get_int (value));
|
|
|
|
break;
|
2009-01-29 12:31:27 +00:00
|
|
|
case PROP_SESSION_POOL:
|
2009-01-19 18:36:23 +00:00
|
|
|
gst_rtsp_server_set_session_pool (server, g_value_get_object (value));
|
2009-01-08 12:41:33 +00:00
|
|
|
break;
|
2009-01-29 12:31:27 +00:00
|
|
|
case PROP_MEDIA_MAPPING:
|
2009-01-22 14:33:29 +00:00
|
|
|
gst_rtsp_server_set_media_mapping (server, g_value_get_object (value));
|
2009-01-20 18:47:07 +00:00
|
|
|
break;
|
2009-01-08 12:41:33 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-12 17:24:44 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_get_io_channel:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
|
|
|
* Create a #GIOChannel for @server. The io channel will listen on the
|
|
|
|
* configured service.
|
|
|
|
*
|
|
|
|
* Returns: the GIOChannel for @server or NULL when an error occured.
|
|
|
|
*/
|
|
|
|
GIOChannel *
|
|
|
|
gst_rtsp_server_get_io_channel (GstRTSPServer * server)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2011-01-12 17:18:13 +00:00
|
|
|
GIOChannel *channel;
|
2011-01-12 17:57:41 +00:00
|
|
|
int ret, sockfd = -1;
|
2010-03-09 12:49:00 +00:00
|
|
|
struct addrinfo hints;
|
|
|
|
struct addrinfo *result, *rp;
|
2010-08-20 08:18:34 +00:00
|
|
|
#ifdef USE_SOLINGER
|
2010-08-16 10:32:28 +00:00
|
|
|
struct linger linger;
|
2010-08-20 08:18:34 +00:00
|
|
|
#endif
|
2010-03-09 12:49:00 +00:00
|
|
|
|
2011-01-12 17:24:44 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2010-12-11 09:48:42 +00:00
|
|
|
memset (&hints, 0, sizeof (struct addrinfo));
|
|
|
|
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
|
|
|
hints.ai_socktype = SOCK_STREAM; /* stream socket */
|
|
|
|
hints.ai_flags = AI_PASSIVE | AI_CANONNAME; /* For wildcard IP address */
|
|
|
|
hints.ai_protocol = 0; /* Any protocol */
|
2010-03-09 12:49:00 +00:00
|
|
|
hints.ai_canonname = NULL;
|
|
|
|
hints.ai_addr = NULL;
|
|
|
|
hints.ai_next = NULL;
|
|
|
|
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "getting address info of %s/%s", server->address,
|
|
|
|
server->service);
|
2010-03-09 12:49:00 +00:00
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2010-03-09 12:49:00 +00:00
|
|
|
/* resolve the server IP address */
|
2010-12-11 09:48:42 +00:00
|
|
|
if ((ret =
|
|
|
|
getaddrinfo (server->address, server->service, &hints, &result)) != 0)
|
2010-03-09 12:49:00 +00:00
|
|
|
goto no_address;
|
|
|
|
|
|
|
|
/* create server socket, we loop through all the addresses until we manage to
|
|
|
|
* create a socket and bind. */
|
|
|
|
for (rp = result; rp; rp = rp->ai_next) {
|
|
|
|
sockfd = socket (rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
|
|
|
if (sockfd == -1) {
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "failed to make socket (%s), try next",
|
|
|
|
g_strerror (errno));
|
2010-03-09 12:49:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-12-18 10:24:48 +00:00
|
|
|
/* make address reusable */
|
|
|
|
ret = 1;
|
|
|
|
if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR,
|
|
|
|
(void *) &ret, sizeof (ret)) < 0) {
|
|
|
|
/* warn but try to bind anyway */
|
|
|
|
GST_WARNING_OBJECT (server, "failed to reuse socker (%s)",
|
|
|
|
g_strerror (errno));
|
|
|
|
}
|
|
|
|
|
2010-03-16 17:37:18 +00:00
|
|
|
if (bind (sockfd, rp->ai_addr, rp->ai_addrlen) == 0) {
|
|
|
|
GST_DEBUG_OBJECT (server, "bind on %s", rp->ai_canonname);
|
2010-03-09 12:49:00 +00:00
|
|
|
break;
|
2010-03-16 17:37:18 +00:00
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "failed to bind socket (%s), try next",
|
|
|
|
g_strerror (errno));
|
2010-03-09 12:49:00 +00:00
|
|
|
close (sockfd);
|
2011-01-12 17:57:41 +00:00
|
|
|
sockfd = -1;
|
2010-03-09 12:49:00 +00:00
|
|
|
}
|
|
|
|
freeaddrinfo (result);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
if (sockfd == -1)
|
2008-10-09 12:29:12 +00:00
|
|
|
goto no_socket;
|
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "opened sending server socket with fd %d", sockfd);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* keep connection alive; avoids SIGPIPE during write */
|
|
|
|
ret = 1;
|
2011-01-12 17:18:13 +00:00
|
|
|
if (setsockopt (sockfd, SOL_SOCKET, SO_KEEPALIVE,
|
2008-10-09 12:29:12 +00:00
|
|
|
(void *) &ret, sizeof (ret)) < 0)
|
|
|
|
goto keepalive_failed;
|
|
|
|
|
2010-08-20 08:18:34 +00:00
|
|
|
#ifdef USE_SOLINGER
|
|
|
|
/* make sure socket is reset 5 seconds after close. This ensure that we can
|
|
|
|
* reuse the socket quickly while still having a chance to send data to the
|
|
|
|
* client. */
|
2010-08-16 10:32:28 +00:00
|
|
|
linger.l_onoff = 1;
|
2010-08-19 16:52:47 +00:00
|
|
|
linger.l_linger = 5;
|
2011-01-12 17:18:13 +00:00
|
|
|
if (setsockopt (sockfd, SOL_SOCKET, SO_LINGER,
|
2010-08-16 10:32:28 +00:00
|
|
|
(void *) &linger, sizeof (linger)) < 0)
|
|
|
|
goto linger_failed;
|
2010-08-20 08:18:34 +00:00
|
|
|
#endif
|
2010-08-16 10:32:28 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* set the server socket to nonblocking */
|
2011-01-12 17:18:13 +00:00
|
|
|
fcntl (sockfd, F_SETFL, O_NONBLOCK);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (server, "listening on server socket %d with queue of %d",
|
2011-01-12 17:18:13 +00:00
|
|
|
sockfd, server->backlog);
|
|
|
|
if (listen (sockfd, server->backlog) == -1)
|
2008-10-09 12:29:12 +00:00
|
|
|
goto listen_failed;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (server,
|
2011-01-12 17:18:13 +00:00
|
|
|
"listened on server socket %d, returning from connection setup", sockfd);
|
|
|
|
|
|
|
|
/* create IO channel for the socket */
|
|
|
|
channel = g_io_channel_unix_new (sockfd);
|
|
|
|
g_io_channel_set_close_on_unref (channel, TRUE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2010-03-09 12:49:00 +00:00
|
|
|
GST_INFO_OBJECT (server, "listening on service %s", server->service);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2009-02-04 08:57:55 +00:00
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
return channel;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2010-03-09 12:49:00 +00:00
|
|
|
no_address:
|
|
|
|
{
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to resolve address: %s",
|
|
|
|
gai_strerror (ret));
|
2011-01-12 17:57:41 +00:00
|
|
|
goto close_error;
|
2010-03-09 12:49:00 +00:00
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
no_socket:
|
|
|
|
{
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to create socket: %s",
|
|
|
|
g_strerror (errno));
|
2011-01-12 17:57:41 +00:00
|
|
|
goto close_error;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
keepalive_failed:
|
|
|
|
{
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to configure keepalive socket: %s",
|
|
|
|
g_strerror (errno));
|
2010-08-16 10:32:28 +00:00
|
|
|
goto close_error;
|
|
|
|
}
|
2010-08-20 08:18:34 +00:00
|
|
|
#ifdef USE_SOLINGER
|
2010-08-16 10:32:28 +00:00
|
|
|
linger_failed:
|
|
|
|
{
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to no linger socket: %s",
|
|
|
|
g_strerror (errno));
|
2010-08-16 10:32:28 +00:00
|
|
|
goto close_error;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2010-08-20 08:18:34 +00:00
|
|
|
#endif
|
2008-10-09 12:29:12 +00:00
|
|
|
listen_failed:
|
2010-08-16 10:32:28 +00:00
|
|
|
{
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to listen on socket: %s",
|
|
|
|
g_strerror (errno));
|
2010-08-16 10:32:28 +00:00
|
|
|
goto close_error;
|
|
|
|
}
|
|
|
|
close_error:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2011-01-12 17:18:13 +00:00
|
|
|
if (sockfd >= 0) {
|
|
|
|
close (sockfd);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2011-01-12 17:18:13 +00:00
|
|
|
return NULL;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-12 14:36:22 +00:00
|
|
|
static void
|
|
|
|
unmanage_client (GstRTSPClient * client, GstRTSPServer * server)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (server, "unmanage client %p", client);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
gst_rtsp_client_set_server (client, NULL);
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2011-01-12 14:36:22 +00:00
|
|
|
server->clients = g_list_remove (server->clients, client);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2011-01-12 14:36:22 +00:00
|
|
|
|
|
|
|
g_object_unref (client);
|
|
|
|
}
|
|
|
|
|
2011-01-12 09:57:08 +00:00
|
|
|
/* add the client to the active list of clients, takes ownership of
|
|
|
|
* the client */
|
|
|
|
static void
|
|
|
|
manage_client (GstRTSPServer * server, GstRTSPClient * client)
|
|
|
|
{
|
2011-01-12 14:36:22 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "manage client %p", client);
|
2011-01-12 09:57:08 +00:00
|
|
|
gst_rtsp_client_set_server (client, server);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2011-01-12 14:36:22 +00:00
|
|
|
g_signal_connect (client, "closed", (GCallback) unmanage_client, server);
|
|
|
|
server->clients = g_list_prepend (server->clients, client);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2011-01-12 09:57:08 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 12:19:36 +00:00
|
|
|
static GstRTSPClient *
|
2011-01-12 09:57:08 +00:00
|
|
|
default_create_client (GstRTSPServer * server)
|
2009-01-20 12:19:36 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client;
|
|
|
|
|
|
|
|
/* a new client connected, create a session to handle the client. */
|
|
|
|
client = gst_rtsp_client_new ();
|
|
|
|
|
|
|
|
/* set the session pool that this client should use */
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2009-01-29 12:31:27 +00:00
|
|
|
gst_rtsp_client_set_session_pool (client, server->session_pool);
|
2009-12-25 17:24:10 +00:00
|
|
|
/* set the media mapping that this client should use */
|
2009-01-29 12:31:27 +00:00
|
|
|
gst_rtsp_client_set_media_mapping (client, server->media_mapping);
|
2011-01-11 23:17:54 +00:00
|
|
|
/* set authentication manager */
|
|
|
|
gst_rtsp_client_set_auth (client, server->auth);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2009-01-20 18:47:07 +00:00
|
|
|
|
2011-01-12 09:57:08 +00:00
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default method for creating a new client object in the server to accept and
|
|
|
|
* handle a client connection on this server */
|
|
|
|
static gboolean
|
|
|
|
default_accept_client (GstRTSPServer * server, GstRTSPClient * client,
|
|
|
|
GIOChannel * channel)
|
|
|
|
{
|
2009-01-20 12:19:36 +00:00
|
|
|
/* accept connections for that client, this function returns after accepting
|
|
|
|
* the connection and will run the remainder of the communication with the
|
|
|
|
* client asyncronously. */
|
|
|
|
if (!gst_rtsp_client_accept (client, channel))
|
|
|
|
goto accept_failed;
|
|
|
|
|
2011-01-12 09:57:08 +00:00
|
|
|
return TRUE;
|
2009-01-20 12:19:36 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
accept_failed:
|
|
|
|
{
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_ERROR_OBJECT (server,
|
2011-01-12 17:18:13 +00:00
|
|
|
"Could not accept client on server : %s (%d)", g_strerror (errno),
|
|
|
|
errno);
|
2011-01-12 09:57:08 +00:00
|
|
|
return FALSE;
|
2009-01-20 12:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_io_func:
|
|
|
|
* @channel: a #GIOChannel
|
|
|
|
* @condition: the condition on @source
|
|
|
|
*
|
|
|
|
* A default #GIOFunc that creates a new #GstRTSPClient to accept and handle a
|
|
|
|
* new connection on @channel or @server.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the source could be connected, FALSE if an error occured.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_io_func (GIOChannel * channel, GIOCondition condition,
|
|
|
|
GstRTSPServer * server)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2011-01-12 09:57:08 +00:00
|
|
|
gboolean result;
|
2009-01-20 12:19:36 +00:00
|
|
|
GstRTSPClient *client = NULL;
|
|
|
|
GstRTSPServerClass *klass;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
if (condition & G_IO_IN) {
|
2009-01-20 12:19:36 +00:00
|
|
|
klass = GST_RTSP_SERVER_GET_CLASS (server);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 09:57:08 +00:00
|
|
|
if (klass->create_client)
|
|
|
|
client = klass->create_client (server);
|
2009-01-20 12:19:36 +00:00
|
|
|
if (client == NULL)
|
|
|
|
goto client_failed;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-12 09:57:08 +00:00
|
|
|
/* a new client connected, create a client object to handle the client. */
|
|
|
|
if (klass->accept_client)
|
|
|
|
result = klass->accept_client (server, client, channel);
|
|
|
|
if (!result)
|
|
|
|
goto accept_failed;
|
|
|
|
|
|
|
|
/* manage the client connection */
|
|
|
|
manage_client (server, client);
|
2010-12-11 09:48:42 +00:00
|
|
|
} else {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING_OBJECT (server, "received unknown event %08x", condition);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-20 12:19:36 +00:00
|
|
|
client_failed:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2009-01-20 12:19:36 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to create a client");
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-01-12 09:57:08 +00:00
|
|
|
accept_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (server, "failed to accept client");
|
|
|
|
gst_object_unref (client);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
static void
|
|
|
|
watch_destroyed (GstRTSPServer * server)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (server, "source destroyed");
|
2011-01-12 17:26:57 +00:00
|
|
|
g_object_unref (server);
|
2011-01-12 17:18:13 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_create_watch:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
|
|
|
* Create a #GSource for @server. The new source will have a default
|
|
|
|
* #GIOFunc of gst_rtsp_server_io_func().
|
|
|
|
*
|
|
|
|
* Returns: the #GSource for @server or NULL when an error occured.
|
|
|
|
*/
|
|
|
|
GSource *
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_create_watch (GstRTSPServer * server)
|
2009-01-19 18:36:23 +00:00
|
|
|
{
|
2011-01-12 17:18:13 +00:00
|
|
|
GIOChannel *channel;
|
|
|
|
GSource *source;
|
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
channel = gst_rtsp_server_get_io_channel (server);
|
|
|
|
if (channel == NULL)
|
|
|
|
goto no_channel;
|
2009-01-19 18:36:23 +00:00
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
/* create a watch for reads (new connections) and possible errors */
|
|
|
|
source = g_io_create_watch (channel, G_IO_IN |
|
|
|
|
G_IO_ERR | G_IO_HUP | G_IO_NVAL);
|
|
|
|
g_io_channel_unref (channel);
|
2010-03-16 17:37:18 +00:00
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
/* configure the callback */
|
|
|
|
g_source_set_callback (source,
|
2011-01-12 17:26:57 +00:00
|
|
|
(GSourceFunc) gst_rtsp_server_io_func, g_object_ref (server),
|
2011-01-12 17:18:13 +00:00
|
|
|
(GDestroyNotify) watch_destroyed);
|
2009-01-19 18:36:23 +00:00
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
return source;
|
2009-01-19 18:36:23 +00:00
|
|
|
|
|
|
|
no_channel:
|
|
|
|
{
|
2010-03-09 12:49:00 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to create IO channel");
|
2009-01-19 18:36:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_attach:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
* @context: a #GMainContext
|
|
|
|
*
|
|
|
|
* Attaches @server to @context. When the mainloop for @context is run, the
|
2011-01-19 14:29:55 +00:00
|
|
|
* server will be dispatched. When @context is NULL, the default context will be
|
|
|
|
* used).
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
|
|
|
* This function should be called when the server properties and urls are fully
|
|
|
|
* configured and the server is ready to start.
|
|
|
|
*
|
2010-03-16 17:37:18 +00:00
|
|
|
* Returns: the ID (greater than 0) for the source within the GMainContext.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
guint
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_attach (GstRTSPServer * server, GMainContext * context)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
guint res;
|
2009-01-19 18:36:23 +00:00
|
|
|
GSource *source;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), 0);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
source = gst_rtsp_server_create_watch (server);
|
|
|
|
if (source == NULL)
|
|
|
|
goto no_source;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
res = g_source_attach (source, context);
|
2011-01-12 17:18:13 +00:00
|
|
|
g_source_unref (source);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-19 18:36:23 +00:00
|
|
|
no_source:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2010-03-09 12:49:00 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to create watch");
|
2008-10-09 12:29:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|