2008-10-09 12:29:12 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:14:25 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
2013-07-11 14:57:14 +00:00
|
|
|
/**
|
|
|
|
* SECTION:rtsp-server
|
|
|
|
* @short_description: The main server object
|
|
|
|
* @see_also: #GstRTSPClient, #GstRTSPThreadPool
|
|
|
|
*
|
|
|
|
* The server object is the object listening for connections on a port and
|
|
|
|
* creating #GstRTSPClient objects to handle those connections.
|
|
|
|
*
|
|
|
|
* The server will listen on the address set with gst_rtsp_server_set_address()
|
|
|
|
* and the port or service configured with gst_rtsp_server_set_service().
|
|
|
|
* Use gst_rtsp_server_set_backlog() to configure the amount of pending requests
|
|
|
|
* that the server will keep. By default the server listens on the current
|
|
|
|
* network (0.0.0.0) and port 8554.
|
|
|
|
*
|
|
|
|
* The server will require an SSL connection when a TLS certificate has been
|
2013-07-12 10:41:52 +00:00
|
|
|
* set in the auth object with gst_rtsp_auth_set_tls_certificate().
|
2013-07-11 14:57:14 +00:00
|
|
|
*
|
|
|
|
* To start the server, use gst_rtsp_server_attach() to attach it to a
|
|
|
|
* #GMainContext. For more control, gst_rtsp_server_create_source() and
|
|
|
|
* gst_rtsp_server_create_socket() can be used to get a #GSource and #GSocket
|
|
|
|
* respectively.
|
|
|
|
*
|
|
|
|
* gst_rtsp_server_transfer_connection() can be used to transfer an existing
|
|
|
|
* socket to the RTSP server, for example from an HTTP server.
|
|
|
|
*
|
|
|
|
* Once the server socket is attached to a mainloop, it will start accepting
|
|
|
|
* connections. When a new connection is received, a new #GstRTSPClient object
|
|
|
|
* is created to handle the connection. The new client will be configured with
|
|
|
|
* the server #GstRTSPAuth, #GstRTSPMountPoints, #GstRTSPSessionPool and
|
|
|
|
* #GstRTSPThreadPool.
|
|
|
|
*
|
|
|
|
* The server uses the configured #GstRTSPThreadPool object to handle the
|
|
|
|
* remainder of the communication with this client.
|
|
|
|
*
|
|
|
|
* Last reviewed on 2013-07-11 (1.0.0)
|
|
|
|
*/
|
2018-09-24 08:36:21 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-01-11 23:17:54 +00:00
|
|
|
|
2018-11-01 08:18:22 +00:00
|
|
|
#include "rtsp-context.h"
|
|
|
|
#include "rtsp-server-object.h"
|
2008-10-09 12:29:12 +00:00
|
|
|
#include "rtsp-client.h"
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
#define GST_RTSP_SERVER_GET_LOCK(server) (&(GST_RTSP_SERVER_CAST(server)->priv->lock))
|
|
|
|
#define GST_RTSP_SERVER_LOCK(server) (g_mutex_lock(GST_RTSP_SERVER_GET_LOCK(server)))
|
|
|
|
#define GST_RTSP_SERVER_UNLOCK(server) (g_mutex_unlock(GST_RTSP_SERVER_GET_LOCK(server)))
|
|
|
|
|
|
|
|
struct _GstRTSPServerPrivate
|
|
|
|
{
|
2013-02-18 19:59:58 +00:00
|
|
|
GMutex lock; /* protects everything in this struct */
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
/* server information */
|
|
|
|
gchar *address;
|
|
|
|
gchar *service;
|
|
|
|
gint backlog;
|
|
|
|
|
|
|
|
GSocket *socket;
|
|
|
|
|
|
|
|
/* sessions on this server */
|
|
|
|
GstRTSPSessionPool *session_pool;
|
|
|
|
|
|
|
|
/* mount points for this server */
|
|
|
|
GstRTSPMountPoints *mount_points;
|
|
|
|
|
2019-03-27 15:21:03 +00:00
|
|
|
/* request size limit */
|
|
|
|
guint content_length_limit;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/* authentication manager */
|
|
|
|
GstRTSPAuth *auth;
|
|
|
|
|
2013-07-10 14:49:55 +00:00
|
|
|
/* resource manager */
|
|
|
|
GstRTSPThreadPool *thread_pool;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/* the clients that are connected */
|
|
|
|
GList *clients;
|
2014-07-10 09:32:20 +00:00
|
|
|
guint clients_cookie;
|
2012-11-29 10:11:05 +00:00
|
|
|
};
|
|
|
|
|
2010-03-09 12:49:00 +00:00
|
|
|
#define DEFAULT_ADDRESS "0.0.0.0"
|
2012-10-12 04:21:24 +00:00
|
|
|
#define DEFAULT_BOUND_PORT -1
|
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,
|
2012-10-12 04:21:24 +00:00
|
|
|
PROP_BOUND_PORT,
|
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,
|
2012-11-26 11:34:05 +00:00
|
|
|
PROP_MOUNT_POINTS,
|
2019-03-27 15:21:03 +00:00
|
|
|
PROP_CONTENT_LENGTH_LIMIT,
|
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
|
|
|
|
2011-05-03 14:24:28 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_CLIENT_CONNECTED,
|
|
|
|
SIGNAL_LAST
|
|
|
|
};
|
|
|
|
|
2018-06-24 10:44:26 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GstRTSPServer, gst_rtsp_server, G_TYPE_OBJECT);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_server_debug);
|
|
|
|
#define GST_CAT_DEFAULT rtsp_server_debug
|
|
|
|
|
2012-11-12 14:29:39 +00:00
|
|
|
typedef struct _ClientContext ClientContext;
|
|
|
|
|
2011-05-03 14:24:28 +00:00
|
|
|
static guint gst_rtsp_server_signals[SIGNAL_LAST] = { 0 };
|
|
|
|
|
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);
|
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
|
|
|
|
|
|
|
/**
|
2012-10-01 17:46:15 +00:00
|
|
|
* GstRTSPServer::address:
|
2010-03-09 12:49:00 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
/**
|
2012-10-01 17:46:15 +00:00
|
|
|
* GstRTSPServer::service:
|
2010-03-09 12:49:00 +00:00
|
|
|
*
|
|
|
|
* 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));
|
2012-10-12 04:21:24 +00:00
|
|
|
/**
|
2012-10-01 17:46:15 +00:00
|
|
|
* GstRTSPServer::bound-port:
|
2012-10-12 04:21:24 +00:00
|
|
|
*
|
|
|
|
* The actual port the server is listening on. Can be used to retrieve the
|
|
|
|
* port number when the server is started on port 0, which means bind to a
|
|
|
|
* random port. Set to -1 if the server has not been bound yet.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_BOUND_PORT,
|
|
|
|
g_param_spec_int ("bound-port", "Bound port",
|
|
|
|
"The port number the server is listening on",
|
|
|
|
-1, G_MAXUINT16, DEFAULT_BOUND_PORT,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2009-01-19 18:36:23 +00:00
|
|
|
/**
|
2012-10-01 17:46:15 +00:00
|
|
|
* GstRTSPServer::backlog:
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
|
|
|
* 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
|
2013-07-11 14:57:14 +00:00
|
|
|
* request may be ignored so that a later reattempt at connection succeeds.
|
2009-01-19 18:36:23 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
2012-10-01 17:46:15 +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
|
|
|
/**
|
2012-11-26 11:34:05 +00:00
|
|
|
* GstRTSPServer::mount-points:
|
2009-01-20 18:47:07 +00:00
|
|
|
*
|
2012-11-26 11:34:05 +00:00
|
|
|
* The mount points to use for this server. By default the server has no
|
|
|
|
* mount points and thus cannot map urls to media streams.
|
2009-01-20 18:47:07 +00:00
|
|
|
*/
|
2012-11-26 11:34:05 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MOUNT_POINTS,
|
|
|
|
g_param_spec_object ("mount-points", "Mount Points",
|
|
|
|
"The mount points to use for client session",
|
|
|
|
GST_TYPE_RTSP_MOUNT_POINTS,
|
2010-12-11 09:48:42 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-01-20 12:19:36 +00:00
|
|
|
|
2019-03-27 15:21:03 +00:00
|
|
|
/**
|
|
|
|
* RTSPServer::content-length-limit:
|
|
|
|
*
|
|
|
|
* Define an appropriate request size limit and reject requests exceeding the
|
|
|
|
* limit.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_CONTENT_LENGTH_LIMIT,
|
|
|
|
g_param_spec_uint ("content-length-limit", "Limitation of Content-Length",
|
|
|
|
"Limitation of Content-Length",
|
|
|
|
0, G_MAXUINT, G_MAXUINT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-05-03 14:24:28 +00:00
|
|
|
gst_rtsp_server_signals[SIGNAL_CLIENT_CONNECTED] =
|
|
|
|
g_signal_new ("client-connected", G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPServerClass, client_connected),
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_RTSP_CLIENT);
|
2011-05-03 14:24:28 +00:00
|
|
|
|
2011-01-12 09:57:08 +00:00
|
|
|
klass->create_client = default_create_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)
|
|
|
|
{
|
2018-06-24 10:44:26 +00:00
|
|
|
GstRTSPServerPrivate *priv = gst_rtsp_server_get_instance_private (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
server->priv = priv;
|
|
|
|
|
|
|
|
g_mutex_init (&priv->lock);
|
|
|
|
priv->address = g_strdup (DEFAULT_ADDRESS);
|
|
|
|
priv->service = g_strdup (DEFAULT_SERVICE);
|
|
|
|
priv->socket = NULL;
|
|
|
|
priv->backlog = DEFAULT_BACKLOG;
|
|
|
|
priv->session_pool = gst_rtsp_session_pool_new ();
|
|
|
|
priv->mount_points = gst_rtsp_mount_points_new ();
|
2019-03-27 15:21:03 +00:00
|
|
|
priv->content_length_limit = G_MAXUINT;
|
2013-07-10 14:49:55 +00:00
|
|
|
priv->thread_pool = gst_rtsp_thread_pool_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);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv = server->priv;
|
2009-04-18 14:10:59 +00:00
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "finalize server");
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_free (priv->address);
|
|
|
|
g_free (priv->service);
|
2012-11-20 10:24:35 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->socket)
|
|
|
|
g_object_unref (priv->socket);
|
2010-03-09 12:49:00 +00:00
|
|
|
|
2013-07-10 14:49:55 +00:00
|
|
|
if (priv->session_pool)
|
|
|
|
g_object_unref (priv->session_pool);
|
|
|
|
if (priv->mount_points)
|
|
|
|
g_object_unref (priv->mount_points);
|
|
|
|
if (priv->thread_pool)
|
|
|
|
g_object_unref (priv->thread_pool);
|
2011-01-12 11:07:04 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->auth)
|
|
|
|
g_object_unref (priv->auth);
|
2011-01-12 15:38:34 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_clear (&priv->lock);
|
2011-01-12 17:57:41 +00:00
|
|
|
|
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.
|
2014-03-23 20:24:48 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GstRTSPServer
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
|
|
|
|
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
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_free (priv->address);
|
|
|
|
priv->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
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): 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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2011-01-12 17:57:41 +00:00
|
|
|
gchar *result;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2010-03-09 12:49:00 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
result = g_strdup (priv->address);
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
|
|
|
return result;
|
2010-03-09 12:49:00 +00:00
|
|
|
}
|
|
|
|
|
2012-10-26 10:33:21 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_get_bound_port:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
|
|
|
* Get the port number where the server was bound to.
|
|
|
|
*
|
|
|
|
* Returns: the port number
|
|
|
|
*/
|
2012-10-12 04:21:24 +00:00
|
|
|
int
|
|
|
|
gst_rtsp_server_get_bound_port (GstRTSPServer * server)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2012-10-12 04:21:24 +00:00
|
|
|
GSocketAddress *address;
|
|
|
|
int result = -1;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), result);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2012-10-12 04:21:24 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->socket == NULL)
|
2012-10-12 04:21:24 +00:00
|
|
|
goto out;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
address = g_socket_get_local_address (priv->socket, NULL);
|
2012-10-12 04:21:24 +00:00
|
|
|
result = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (address));
|
|
|
|
g_object_unref (address);
|
|
|
|
|
|
|
|
out:
|
|
|
|
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.
|
|
|
|
*
|
2013-07-11 14:57:14 +00:00
|
|
|
* When @service is set to "0", the server will listen on a random free
|
|
|
|
* port. The actual used port can be retrieved with
|
|
|
|
* gst_rtsp_server_get_bound_port().
|
|
|
|
*
|
2010-03-09 12:49:00 +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_service (GstRTSPServer * server, const gchar * service)
|
2010-03-09 12:49:00 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
|
|
|
|
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
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_free (priv->service);
|
|
|
|
priv->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.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the service. use g_free() after usage.
|
2010-03-09 12:49:00 +00:00
|
|
|
*/
|
|
|
|
gchar *
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_server_get_service (GstRTSPServer * server)
|
2010-03-09 12:49:00 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
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);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
result = g_strdup (priv->service);
|
2011-01-12 17:57:41 +00:00
|
|
|
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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
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);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
result = priv->backlog;
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
|
|
|
return result;
|
2009-01-19 18:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_set_session_pool:
|
|
|
|
* @server: a #GstRTSPServer
|
2018-02-09 23:07:25 +00:00
|
|
|
* @pool: (transfer none) (nullable): a #GstRTSPSessionPool
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
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));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
if (pool)
|
|
|
|
g_object_ref (pool);
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
old = priv->session_pool;
|
|
|
|
priv->session_pool = pool;
|
2011-01-12 17:57:41 +00:00
|
|
|
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.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstRTSPSessionPool used for sessions. g_object_unref() after
|
2009-01-19 18:36:23 +00:00
|
|
|
* 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
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2009-01-19 18:36:23 +00:00
|
|
|
GstRTSPSessionPool *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
if ((result = priv->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
|
|
|
/**
|
2012-11-26 11:34:05 +00:00
|
|
|
* gst_rtsp_server_set_mount_points:
|
2009-01-20 18:47:07 +00:00
|
|
|
* @server: a #GstRTSPServer
|
2018-02-09 23:07:25 +00:00
|
|
|
* @mounts: (transfer none) (nullable): a #GstRTSPMountPoints
|
2009-01-20 18:47:07 +00:00
|
|
|
*
|
2012-11-26 11:34:05 +00:00
|
|
|
* configure @mounts to be used as the mount points of @server.
|
2009-01-20 18:47:07 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-11-26 11:34:05 +00:00
|
|
|
gst_rtsp_server_set_mount_points (GstRTSPServer * server,
|
|
|
|
GstRTSPMountPoints * mounts)
|
2009-01-20 18:47:07 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *old;
|
2009-01-20 18:47:07 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2012-11-26 11:34:05 +00:00
|
|
|
if (mounts)
|
|
|
|
g_object_ref (mounts);
|
2011-01-12 17:57:41 +00:00
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
old = priv->mount_points;
|
|
|
|
priv->mount_points = mounts;
|
2011-01-12 17:57:41 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-11-26 11:34:05 +00:00
|
|
|
* gst_rtsp_server_get_mount_points:
|
2009-01-20 18:47:07 +00:00
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
2012-11-26 11:34:05 +00:00
|
|
|
* Get the #GstRTSPMountPoints used as the mount points of @server.
|
2009-01-20 18:47:07 +00:00
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstRTSPMountPoints of @server. g_object_unref() after
|
2009-01-20 18:47:07 +00:00
|
|
|
* usage.
|
|
|
|
*/
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *
|
|
|
|
gst_rtsp_server_get_mount_points (GstRTSPServer * server)
|
2009-01-20 18:47:07 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *result;
|
2009-01-20 18:47:07 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
if ((result = priv->mount_points))
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-27 15:21:03 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_set_content_length_limit
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
* Configure @server to use the specified Content-Length limit.
|
|
|
|
*
|
|
|
|
* Define an appropriate request size limit and reject requests exceeding the
|
|
|
|
* limit.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_server_set_content_length_limit (GstRTSPServer * server, guint limit)
|
|
|
|
{
|
|
|
|
GstRTSPServerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
|
|
|
|
priv = server->priv;
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
|
|
|
priv->content_length_limit = limit;
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_get_content_length_limit:
|
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
|
|
|
* Get the Content-Length limit of @server.
|
|
|
|
*
|
|
|
|
* Returns: the Content-Length limit.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_server_get_content_length_limit (GstRTSPServer * server)
|
|
|
|
{
|
|
|
|
GstRTSPServerPrivate *priv;
|
|
|
|
guint result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), G_MAXUINT);
|
|
|
|
|
|
|
|
priv = server->priv;
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
|
|
|
result = priv->content_length_limit;
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-11 23:17:54 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_set_auth:
|
|
|
|
* @server: a #GstRTSPServer
|
2018-02-09 23:07:25 +00:00
|
|
|
* @auth: (transfer none) (nullable): a #GstRTSPAuth
|
2011-01-11 23:17:54 +00:00
|
|
|
*
|
|
|
|
* configure @auth to be used as the authentication manager of @server.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_server_set_auth (GstRTSPServer * server, GstRTSPAuth * auth)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2011-01-11 23:17:54 +00:00
|
|
|
GstRTSPAuth *old;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
if (auth)
|
|
|
|
g_object_ref (auth);
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
old = priv->auth;
|
|
|
|
priv->auth = auth;
|
2011-01-12 17:57:41 +00:00
|
|
|
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.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstRTSPAuth of @server. g_object_unref() after
|
2011-01-11 23:17:54 +00:00
|
|
|
* usage.
|
|
|
|
*/
|
|
|
|
GstRTSPAuth *
|
|
|
|
gst_rtsp_server_get_auth (GstRTSPServer * server)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2011-01-11 23:17:54 +00:00
|
|
|
GstRTSPAuth *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
if ((result = priv->auth))
|
2011-01-11 23:17:54 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-12 14:53:28 +00:00
|
|
|
/**
|
2013-07-10 14:49:55 +00:00
|
|
|
* gst_rtsp_server_set_thread_pool:
|
2012-11-12 14:53:28 +00:00
|
|
|
* @server: a #GstRTSPServer
|
2018-02-09 23:07:25 +00:00
|
|
|
* @pool: (transfer none) (nullable): a #GstRTSPThreadPool
|
2012-11-12 14:53:28 +00:00
|
|
|
*
|
2013-07-10 14:49:55 +00:00
|
|
|
* configure @pool to be used as the thread pool of @server.
|
2012-11-12 14:53:28 +00:00
|
|
|
*/
|
|
|
|
void
|
2013-07-10 14:49:55 +00:00
|
|
|
gst_rtsp_server_set_thread_pool (GstRTSPServer * server,
|
|
|
|
GstRTSPThreadPool * pool)
|
2012-11-12 14:53:28 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2013-07-10 14:49:55 +00:00
|
|
|
GstRTSPThreadPool *old;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2012-11-12 14:53:28 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_SERVER (server));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2013-07-10 14:49:55 +00:00
|
|
|
if (pool)
|
|
|
|
g_object_ref (pool);
|
|
|
|
|
2012-11-12 14:53:28 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2013-07-10 14:49:55 +00:00
|
|
|
old = priv->thread_pool;
|
|
|
|
priv->thread_pool = pool;
|
2012-11-12 14:53:28 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2013-07-10 14:49:55 +00:00
|
|
|
|
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2012-11-12 14:53:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-10 14:49:55 +00:00
|
|
|
* gst_rtsp_server_get_thread_pool:
|
2012-11-12 14:53:28 +00:00
|
|
|
* @server: a #GstRTSPServer
|
|
|
|
*
|
2013-07-10 14:49:55 +00:00
|
|
|
* Get the #GstRTSPThreadPool used as the thread pool of @server.
|
2012-11-12 14:53:28 +00:00
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstRTSPThreadPool of @server. g_object_unref() after
|
2013-07-10 14:49:55 +00:00
|
|
|
* usage.
|
2012-11-12 14:53:28 +00:00
|
|
|
*/
|
2013-07-10 14:49:55 +00:00
|
|
|
GstRTSPThreadPool *
|
|
|
|
gst_rtsp_server_get_thread_pool (GstRTSPServer * server)
|
2012-11-12 14:53:28 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2013-07-10 14:49:55 +00:00
|
|
|
GstRTSPThreadPool *result;
|
2012-11-12 14:53:28 +00:00
|
|
|
|
2013-07-10 14:49:55 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
2012-11-12 14:53:28 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2012-11-12 14:53:28 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2013-07-10 14:49:55 +00:00
|
|
|
if ((result = priv->thread_pool))
|
|
|
|
g_object_ref (result);
|
2012-11-12 14:53:28 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
2013-07-10 14:49:55 +00:00
|
|
|
return result;
|
2012-11-12 14:53:28 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2012-10-12 04:21:24 +00:00
|
|
|
case PROP_BOUND_PORT:
|
|
|
|
g_value_set_int (value, gst_rtsp_server_get_bound_port (server));
|
|
|
|
break;
|
2009-01-19 18:36:23 +00:00
|
|
|
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;
|
2012-11-26 11:34:05 +00:00
|
|
|
case PROP_MOUNT_POINTS:
|
|
|
|
g_value_take_object (value, gst_rtsp_server_get_mount_points (server));
|
2009-01-20 18:47:07 +00:00
|
|
|
break;
|
2019-03-27 15:21:03 +00:00
|
|
|
case PROP_CONTENT_LENGTH_LIMIT:
|
|
|
|
g_value_set_uint (value,
|
|
|
|
gst_rtsp_server_get_content_length_limit (server));
|
|
|
|
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;
|
2012-11-26 11:34:05 +00:00
|
|
|
case PROP_MOUNT_POINTS:
|
|
|
|
gst_rtsp_server_set_mount_points (server, g_value_get_object (value));
|
2009-01-20 18:47:07 +00:00
|
|
|
break;
|
2019-03-27 15:21:03 +00:00
|
|
|
case PROP_CONTENT_LENGTH_LIMIT:
|
|
|
|
gst_rtsp_server_set_content_length_limit (server,
|
|
|
|
g_value_get_uint (value));
|
|
|
|
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
|
|
|
/**
|
2012-03-07 14:03:55 +00:00
|
|
|
* gst_rtsp_server_create_socket:
|
2011-01-12 17:24:44 +00:00
|
|
|
* @server: a #GstRTSPServer
|
2014-03-23 20:24:48 +00:00
|
|
|
* @cancellable: (allow-none): a #GCancellable
|
|
|
|
* @error: (out): a #GError
|
2011-01-12 17:24:44 +00:00
|
|
|
*
|
2012-03-07 14:03:55 +00:00
|
|
|
* Create a #GSocket for @server. The socket will listen on the
|
2011-01-12 17:24:44 +00:00
|
|
|
* configured service.
|
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): the #GSocket for @server or %NULL when an error
|
|
|
|
* occurred.
|
2011-01-12 17:24:44 +00:00
|
|
|
*/
|
2012-03-07 14:03:55 +00:00
|
|
|
GSocket *
|
|
|
|
gst_rtsp_server_create_socket (GstRTSPServer * server,
|
|
|
|
GCancellable * cancellable, GError ** error)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2012-03-07 14:03:55 +00:00
|
|
|
GSocketConnectable *conn;
|
|
|
|
GSocketAddressEnumerator *enumerator;
|
2012-05-22 13:37:25 +00:00
|
|
|
GSocket *socket = NULL;
|
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
|
2012-03-07 14:03:55 +00:00
|
|
|
GError *sock_error = NULL;
|
|
|
|
GError *bind_error = NULL;
|
|
|
|
guint16 port;
|
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);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "getting address info of %s/%s", priv->address,
|
|
|
|
priv->service);
|
2010-03-09 12:49:00 +00:00
|
|
|
|
|
|
|
/* resolve the server IP address */
|
2012-11-29 10:11:05 +00:00
|
|
|
port = atoi (priv->service);
|
|
|
|
if (port != 0 || !strcmp (priv->service, "0"))
|
|
|
|
conn = g_network_address_new (priv->address, port);
|
2012-03-07 14:03:55 +00:00
|
|
|
else
|
2012-11-29 10:11:05 +00:00
|
|
|
conn = g_network_service_new (priv->service, "tcp", priv->address);
|
2012-03-07 14:03:55 +00:00
|
|
|
|
|
|
|
enumerator = g_socket_connectable_enumerate (conn);
|
|
|
|
g_object_unref (conn);
|
2010-03-09 12:49:00 +00:00
|
|
|
|
|
|
|
/* create server socket, we loop through all the addresses until we manage to
|
|
|
|
* create a socket and bind. */
|
2012-03-07 14:03:55 +00:00
|
|
|
while (TRUE) {
|
|
|
|
GSocketAddress *sockaddr;
|
|
|
|
|
|
|
|
sockaddr =
|
|
|
|
g_socket_address_enumerator_next (enumerator, cancellable, error);
|
|
|
|
if (!sockaddr) {
|
2012-08-15 13:54:32 +00:00
|
|
|
if (!*error)
|
2012-09-07 15:14:10 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "no more addresses %s",
|
|
|
|
*error ? (*error)->message : "");
|
2012-08-15 13:54:32 +00:00
|
|
|
else
|
2012-09-07 15:14:10 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "failed to retrieve next address %s",
|
|
|
|
(*error)->message);
|
2012-03-07 14:03:55 +00:00
|
|
|
break;
|
2010-03-09 12:49:00 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
/* only keep the first error */
|
|
|
|
socket = g_socket_new (g_socket_address_get_family (sockaddr),
|
|
|
|
G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP,
|
|
|
|
sock_error ? NULL : &sock_error);
|
|
|
|
|
|
|
|
if (socket == NULL) {
|
|
|
|
GST_DEBUG_OBJECT (server, "failed to make socket (%s), try next",
|
|
|
|
sock_error->message);
|
2012-11-20 10:24:35 +00:00
|
|
|
g_object_unref (sockaddr);
|
2012-03-07 14:03:55 +00:00
|
|
|
continue;
|
2010-12-18 10:24:48 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
if (g_socket_bind (socket, sockaddr, TRUE, bind_error ? NULL : &bind_error)) {
|
2013-10-14 06:30:33 +00:00
|
|
|
/* ask what port the socket has been bound to */
|
|
|
|
if (port == 0 || !strcmp (priv->service, "0")) {
|
|
|
|
GError *addr_error = NULL;
|
|
|
|
|
|
|
|
g_object_unref (sockaddr);
|
|
|
|
sockaddr = g_socket_get_local_address (socket, &addr_error);
|
|
|
|
|
|
|
|
if (addr_error != NULL) {
|
|
|
|
GST_DEBUG_OBJECT (server,
|
|
|
|
"failed to get the local address of a bound socket %s",
|
|
|
|
addr_error->message);
|
|
|
|
g_clear_error (&addr_error);
|
|
|
|
break;
|
|
|
|
}
|
2013-11-15 15:35:05 +00:00
|
|
|
port =
|
|
|
|
g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (sockaddr));
|
2013-10-14 06:30:33 +00:00
|
|
|
|
|
|
|
if (port != 0) {
|
|
|
|
g_free (priv->service);
|
|
|
|
priv->service = g_strdup_printf ("%d", port);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (server, "failed to get the port of a bound socket");
|
|
|
|
}
|
|
|
|
}
|
2012-03-07 14:03:55 +00:00
|
|
|
g_object_unref (sockaddr);
|
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",
|
2012-03-07 14:03:55 +00:00
|
|
|
bind_error->message);
|
|
|
|
g_object_unref (sockaddr);
|
|
|
|
g_object_unref (socket);
|
|
|
|
socket = NULL;
|
2010-03-09 12:49:00 +00:00
|
|
|
}
|
2012-03-07 14:03:55 +00:00
|
|
|
g_object_unref (enumerator);
|
2010-03-09 12:49:00 +00:00
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
if (socket == NULL)
|
2008-10-09 12:29:12 +00:00
|
|
|
goto no_socket;
|
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
g_clear_error (&sock_error);
|
|
|
|
g_clear_error (&bind_error);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (server, "opened sending server socket");
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* keep connection alive; avoids SIGPIPE during write */
|
2012-03-07 14:03:55 +00:00
|
|
|
g_socket_set_keepalive (socket, TRUE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
#if 0
|
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;
|
2012-03-07 14:03:55 +00:00
|
|
|
#endif
|
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 */
|
2012-03-07 14:03:55 +00:00
|
|
|
g_socket_set_blocking (socket, FALSE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
/* set listen backlog */
|
2012-11-29 10:11:05 +00:00
|
|
|
g_socket_set_listen_backlog (socket, priv->backlog);
|
2012-03-07 14:03:55 +00:00
|
|
|
|
|
|
|
if (!g_socket_listen (socket, error))
|
2008-10-09 12:29:12 +00:00
|
|
|
goto listen_failed;
|
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "listening on server socket %p with queue of %d",
|
2012-11-29 10:11:05 +00:00
|
|
|
socket, priv->backlog);
|
2011-01-12 17:18:13 +00:00
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2009-02-04 08:57:55 +00:00
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
return socket;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_socket:
|
|
|
|
{
|
2012-03-07 14:03:55 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to create socket");
|
2010-08-16 10:32:28 +00:00
|
|
|
goto close_error;
|
|
|
|
}
|
2012-03-07 14:03:55 +00:00
|
|
|
#if 0
|
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
|
2012-03-07 14:03:55 +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",
|
2012-03-07 14:03:55 +00:00
|
|
|
(*error)->message);
|
2010-08-16 10:32:28 +00:00
|
|
|
goto close_error;
|
|
|
|
}
|
|
|
|
close_error:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-03-07 14:03:55 +00:00
|
|
|
if (socket)
|
|
|
|
g_object_unref (socket);
|
|
|
|
|
|
|
|
if (sock_error) {
|
|
|
|
if (error == NULL)
|
|
|
|
g_propagate_error (error, sock_error);
|
|
|
|
else
|
|
|
|
g_error_free (sock_error);
|
|
|
|
}
|
|
|
|
if (bind_error) {
|
2012-08-15 13:54:32 +00:00
|
|
|
if ((error == NULL) || (*error == NULL))
|
2012-03-07 14:03:55 +00:00
|
|
|
g_propagate_error (error, bind_error);
|
|
|
|
else
|
|
|
|
g_error_free (bind_error);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-12 14:29:39 +00:00
|
|
|
struct _ClientContext
|
2012-11-12 13:09:09 +00:00
|
|
|
{
|
|
|
|
GstRTSPServer *server;
|
2013-07-10 14:49:55 +00:00
|
|
|
GstRTSPThread *thread;
|
2012-11-12 13:09:09 +00:00
|
|
|
GstRTSPClient *client;
|
2012-11-12 14:29:39 +00:00
|
|
|
};
|
2012-11-12 13:09:09 +00:00
|
|
|
|
2013-02-19 18:19:41 +00:00
|
|
|
static gboolean
|
2012-11-12 13:09:09 +00:00
|
|
|
free_client_context (ClientContext * ctx)
|
2011-01-12 14:36:22 +00:00
|
|
|
{
|
2013-07-15 12:50:26 +00:00
|
|
|
GST_DEBUG ("free context %p", ctx);
|
|
|
|
|
2013-02-19 18:19:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (ctx->server);
|
2013-07-10 14:49:55 +00:00
|
|
|
if (ctx->thread)
|
|
|
|
gst_rtsp_thread_stop (ctx->thread);
|
2013-02-19 18:19:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (ctx->server);
|
|
|
|
|
2012-11-12 13:09:09 +00:00
|
|
|
g_object_unref (ctx->client);
|
2013-07-11 15:18:58 +00:00
|
|
|
g_object_unref (ctx->server);
|
2012-11-12 13:09:09 +00:00
|
|
|
g_slice_free (ClientContext, ctx);
|
2013-02-19 18:19:41 +00:00
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
2012-11-12 13:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unmanage_client (GstRTSPClient * client, ClientContext * ctx)
|
|
|
|
{
|
|
|
|
GstRTSPServer *server = ctx->server;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv = server->priv;
|
2012-11-12 13:09:09 +00:00
|
|
|
|
2011-01-12 14:36:22 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "unmanage client %p", client);
|
|
|
|
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->clients = g_list_remove (priv->clients, ctx);
|
2014-07-10 09:32:20 +00:00
|
|
|
priv->clients_cookie++;
|
2011-01-12 17:57:41 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
2011-01-12 14:36:22 +00:00
|
|
|
|
2013-07-10 14:49:55 +00:00
|
|
|
if (ctx->thread) {
|
2013-02-19 18:19:41 +00:00
|
|
|
GSource *src;
|
|
|
|
|
|
|
|
src = g_idle_source_new ();
|
|
|
|
g_source_set_callback (src, (GSourceFunc) free_client_context, ctx, NULL);
|
2013-07-10 14:49:55 +00:00
|
|
|
g_source_attach (src, ctx->thread->context);
|
2013-02-19 18:19:41 +00:00
|
|
|
g_source_unref (src);
|
|
|
|
} else {
|
2012-11-12 13:09:09 +00:00
|
|
|
free_client_context (ctx);
|
2013-02-19 18:19:41 +00:00
|
|
|
}
|
2011-01-12 14:36:22 +00:00
|
|
|
}
|
|
|
|
|
2012-11-12 13:09:09 +00:00
|
|
|
/* add the client context to the active list of clients, takes ownership
|
|
|
|
* of client */
|
2011-01-12 09:57:08 +00:00
|
|
|
static void
|
|
|
|
manage_client (GstRTSPServer * server, GstRTSPClient * client)
|
|
|
|
{
|
2013-07-22 12:25:04 +00:00
|
|
|
ClientContext *cctx;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv = server->priv;
|
2013-07-10 14:49:55 +00:00
|
|
|
GMainContext *mainctx = NULL;
|
2013-07-22 12:25:04 +00:00
|
|
|
GstRTSPContext ctx = { NULL };
|
2012-11-12 13:09:09 +00:00
|
|
|
|
2011-01-12 14:36:22 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "manage client %p", client);
|
2011-01-12 09:57:08 +00:00
|
|
|
|
2013-09-23 12:28:04 +00:00
|
|
|
g_signal_emit (server, gst_rtsp_server_signals[SIGNAL_CLIENT_CONNECTED], 0,
|
|
|
|
client);
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
cctx = g_slice_new0 (ClientContext);
|
|
|
|
cctx->server = g_object_ref (server);
|
|
|
|
cctx->client = client;
|
2013-02-19 18:19:41 +00:00
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-12 13:09:09 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx.server = server;
|
|
|
|
ctx.client = client;
|
2013-07-10 14:49:55 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
cctx->thread = gst_rtsp_thread_pool_get_thread (priv->thread_pool,
|
|
|
|
GST_RTSP_THREAD_TYPE_CLIENT, &ctx);
|
|
|
|
if (cctx->thread)
|
|
|
|
mainctx = cctx->thread->context;
|
2013-07-10 14:49:55 +00:00
|
|
|
else {
|
|
|
|
GSource *source;
|
2012-11-12 13:09:09 +00:00
|
|
|
/* find the context to add the watch */
|
|
|
|
if ((source = g_main_current_source ()))
|
2013-02-19 17:31:23 +00:00
|
|
|
mainctx = g_source_get_context (source);
|
2012-11-12 13:09:09 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
g_signal_connect (client, "closed", (GCallback) unmanage_client, cctx);
|
|
|
|
priv->clients = g_list_prepend (priv->clients, cctx);
|
2014-07-10 09:32:20 +00:00
|
|
|
priv->clients_cookie++;
|
2012-11-12 13:09:09 +00:00
|
|
|
|
2013-02-19 18:19:41 +00:00
|
|
|
gst_rtsp_client_attach (client, mainctx);
|
2012-11-12 13:09:09 +00:00
|
|
|
|
2013-02-19 18:19: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;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv = server->priv;
|
2009-01-20 12:19:36 +00:00
|
|
|
|
|
|
|
/* 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);
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_client_set_session_pool (client, priv->session_pool);
|
2012-11-26 11:34:05 +00:00
|
|
|
/* set the mount points that this client should use */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_client_set_mount_points (client, priv->mount_points);
|
2019-03-27 15:21:03 +00:00
|
|
|
/* Set content-length limit */
|
|
|
|
gst_rtsp_client_set_content_length_limit (GST_RTSP_CLIENT (client),
|
|
|
|
priv->content_length_limit);
|
2011-01-11 23:17:54 +00:00
|
|
|
/* set authentication manager */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_client_set_auth (client, priv->auth);
|
2013-07-10 15:07:13 +00:00
|
|
|
/* set threadpool */
|
|
|
|
gst_rtsp_client_set_thread_pool (client, priv->thread_pool);
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:06:00 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_transfer_connection:
|
|
|
|
* @server: a #GstRTSPServer
|
2013-10-14 10:03:07 +00:00
|
|
|
* @socket: (transfer full): a network socket
|
2012-07-03 16:06:00 +00:00
|
|
|
* @ip: the IP address of the remote client
|
|
|
|
* @port: the port used by the other end
|
2018-02-09 23:07:25 +00:00
|
|
|
* @initial_buffer: (nullable): any initial data that was already read from the socket
|
2012-07-03 16:06:00 +00:00
|
|
|
*
|
|
|
|
* Take an existing network socket and use it for an RTSP connection. This
|
|
|
|
* is used when transferring a socket from an HTTP server which should be used
|
|
|
|
* as an RTSP over HTTP tunnel. The @initial_buffer contains any remaining data
|
|
|
|
* that the HTTP server read from the socket while parsing the HTTP header.
|
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: TRUE if all was ok, FALSE if an error occurred.
|
2012-07-03 16:06:00 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_server_transfer_connection (GstRTSPServer * server, GSocket * socket,
|
2012-09-07 15:14:10 +00:00
|
|
|
const gchar * ip, gint port, const gchar * initial_buffer)
|
2012-07-03 16:06:00 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = NULL;
|
|
|
|
GstRTSPServerClass *klass;
|
2013-05-30 05:18:22 +00:00
|
|
|
GstRTSPConnection *conn;
|
|
|
|
GstRTSPResult res;
|
2012-07-03 16:06:00 +00:00
|
|
|
|
|
|
|
klass = GST_RTSP_SERVER_GET_CLASS (server);
|
|
|
|
|
|
|
|
if (klass->create_client)
|
|
|
|
client = klass->create_client (server);
|
|
|
|
if (client == NULL)
|
|
|
|
goto client_failed;
|
|
|
|
|
2013-05-30 05:18:22 +00:00
|
|
|
GST_RTSP_CHECK (gst_rtsp_connection_create_from_socket (socket, ip, port,
|
|
|
|
initial_buffer, &conn), no_connection);
|
2013-10-14 10:03:07 +00:00
|
|
|
g_object_unref (socket);
|
2013-05-30 05:18:22 +00:00
|
|
|
|
|
|
|
/* set connection on the client now */
|
|
|
|
gst_rtsp_client_set_connection (client, conn);
|
2012-07-03 16:06:00 +00:00
|
|
|
|
|
|
|
/* manage the client connection */
|
|
|
|
manage_client (server, client);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
client_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (server, "failed to create a client");
|
2013-10-14 10:03:07 +00:00
|
|
|
g_object_unref (socket);
|
2012-07-03 16:06:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-05-30 05:18:22 +00:00
|
|
|
no_connection:
|
2012-07-03 16:06:00 +00:00
|
|
|
{
|
2013-05-30 05:18:22 +00:00
|
|
|
gchar *str = gst_rtsp_strresult (res);
|
|
|
|
GST_ERROR ("could not create connection from socket %p: %s", socket, str);
|
|
|
|
g_free (str);
|
2013-10-14 10:03:07 +00:00
|
|
|
g_object_unref (socket);
|
2022-08-19 14:16:26 +00:00
|
|
|
g_object_unref (client);
|
2012-07-03 16:06:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_server_io_func:
|
2012-03-07 14:03:55 +00:00
|
|
|
* @socket: a #GSocket
|
2009-01-19 18:36:23 +00:00
|
|
|
* @condition: the condition on @source
|
2014-03-23 20:24:48 +00:00
|
|
|
* @server: (transfer none): a #GstRTSPServer
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
2012-03-07 14:03:55 +00:00
|
|
|
* A default #GSocketSourceFunc that creates a new #GstRTSPClient to accept and handle a
|
|
|
|
* new connection on @socket or @server.
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: TRUE if the source could be connected, FALSE if an error occurred.
|
2009-01-19 18:36:23 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2012-03-07 14:03:55 +00:00
|
|
|
gst_rtsp_server_io_func (GSocket * socket, GIOCondition condition,
|
2010-12-11 09:48:42 +00:00
|
|
|
GstRTSPServer * server)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2013-07-12 10:41:52 +00:00
|
|
|
GstRTSPServerPrivate *priv = server->priv;
|
2009-01-20 12:19:36 +00:00
|
|
|
GstRTSPClient *client = NULL;
|
|
|
|
GstRTSPServerClass *klass;
|
2013-05-31 09:14:17 +00:00
|
|
|
GstRTSPResult res;
|
2013-05-31 09:42:36 +00:00
|
|
|
GstRTSPConnection *conn = NULL;
|
2013-07-22 12:25:04 +00:00
|
|
|
GstRTSPContext ctx = { NULL };
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
if (condition & G_IO_IN) {
|
2013-07-12 10:41:52 +00:00
|
|
|
/* a new client connected. */
|
|
|
|
GST_RTSP_CHECK (gst_rtsp_connection_accept (socket, &conn, NULL),
|
|
|
|
accept_failed);
|
2013-05-31 09:14:17 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx.server = server;
|
|
|
|
ctx.conn = conn;
|
|
|
|
ctx.auth = priv->auth;
|
|
|
|
gst_rtsp_context_push_current (&ctx);
|
2013-07-12 10:41:52 +00:00
|
|
|
|
|
|
|
if (!gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_CONNECT))
|
|
|
|
goto connection_refused;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-12 10:41:52 +00:00
|
|
|
klass = GST_RTSP_SERVER_GET_CLASS (server);
|
2013-05-31 09:14:17 +00:00
|
|
|
/* a new client connected, create a client object to handle the client. */
|
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
|
|
|
|
2013-05-31 09:14:17 +00:00
|
|
|
/* set connection on the client now */
|
|
|
|
gst_rtsp_client_set_connection (client, conn);
|
2011-01-12 09:57:08 +00:00
|
|
|
|
|
|
|
/* 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);
|
2015-11-11 13:58:33 +00:00
|
|
|
goto exit_no_ctx;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2013-07-12 10:41:52 +00:00
|
|
|
exit:
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_context_pop_current (&ctx);
|
2015-11-11 13:58:33 +00:00
|
|
|
exit_no_ctx:
|
2013-07-12 10:41:52 +00:00
|
|
|
|
2013-05-27 10:58:07 +00:00
|
|
|
return G_SOURCE_CONTINUE;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2011-01-12 09:57:08 +00:00
|
|
|
accept_failed:
|
|
|
|
{
|
2013-05-31 09:14:17 +00:00
|
|
|
gchar *str = gst_rtsp_strresult (res);
|
|
|
|
GST_ERROR_OBJECT (server, "Could not accept client on socket %p: %s",
|
|
|
|
socket, str);
|
|
|
|
g_free (str);
|
2015-11-11 13:58:33 +00:00
|
|
|
/* We haven't pushed the context yet, so just return */
|
|
|
|
goto exit_no_ctx;
|
2011-01-12 09:57:08 +00:00
|
|
|
}
|
2013-07-12 10:41:52 +00:00
|
|
|
connection_refused:
|
2013-05-31 09:42:36 +00:00
|
|
|
{
|
2013-07-12 10:41:52 +00:00
|
|
|
GST_ERROR_OBJECT (server, "connection refused");
|
|
|
|
gst_rtsp_connection_free (conn);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
client_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (server, "failed to create a client");
|
2013-05-31 09:42:36 +00:00
|
|
|
gst_rtsp_connection_free (conn);
|
2013-07-12 10:41:52 +00:00
|
|
|
goto exit;
|
2013-05-31 09:42:36 +00:00
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
static void
|
|
|
|
watch_destroyed (GstRTSPServer * server)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv = server->priv;
|
|
|
|
|
2011-01-12 17:18:13 +00:00
|
|
|
GST_DEBUG_OBJECT (server, "source destroyed");
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
g_object_unref (priv->socket);
|
|
|
|
priv->socket = NULL;
|
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
|
|
|
/**
|
2012-03-07 14:03:55 +00:00
|
|
|
* gst_rtsp_server_create_source:
|
2009-01-19 18:36:23 +00:00
|
|
|
* @server: a #GstRTSPServer
|
2014-03-23 20:24:48 +00:00
|
|
|
* @cancellable: (allow-none): a #GCancellable or %NULL.
|
|
|
|
* @error: (out): a #GError
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
|
|
|
* Create a #GSource for @server. The new source will have a default
|
2012-03-07 14:03:55 +00:00
|
|
|
* #GSocketSourceFunc of gst_rtsp_server_io_func().
|
2009-01-19 18:36:23 +00:00
|
|
|
*
|
2013-11-22 01:28:28 +00:00
|
|
|
* @cancellable if not %NULL can be used to cancel the source, which will cause
|
2012-03-07 14:03:55 +00:00
|
|
|
* the source to trigger, reporting the current condition (which is likely 0
|
|
|
|
* unless cancellation happened at the same time as a condition change). You can
|
|
|
|
* check for this in the callback using g_cancellable_is_cancelled().
|
|
|
|
*
|
2015-07-23 18:50:30 +00:00
|
|
|
* This takes a reference on @server until @source is destroyed.
|
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): the #GSource for @server or %NULL when an error
|
|
|
|
* occurred. Free with g_source_unref ()
|
2009-01-19 18:36:23 +00:00
|
|
|
*/
|
|
|
|
GSource *
|
2012-03-07 14:03:55 +00:00
|
|
|
gst_rtsp_server_create_source (GstRTSPServer * server,
|
|
|
|
GCancellable * cancellable, GError ** error)
|
2009-01-19 18:36:23 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPServerPrivate *priv;
|
2012-11-12 15:30:16 +00:00
|
|
|
GSocket *socket, *old;
|
2011-01-12 17:18:13 +00:00
|
|
|
GSource *source;
|
|
|
|
|
2009-01-19 18:36:23 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = server->priv;
|
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
socket = gst_rtsp_server_create_socket (server, NULL, error);
|
|
|
|
if (socket == NULL)
|
|
|
|
goto no_socket;
|
2012-11-12 15:30:16 +00:00
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2012-11-29 10:11:05 +00:00
|
|
|
old = priv->socket;
|
|
|
|
priv->socket = g_object_ref (socket);
|
2012-11-12 15:30:16 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
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 */
|
2012-03-07 14:03:55 +00:00
|
|
|
source = g_socket_create_source (socket, G_IO_IN |
|
|
|
|
G_IO_ERR | G_IO_HUP | G_IO_NVAL, cancellable);
|
|
|
|
g_object_unref (socket);
|
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
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
no_socket:
|
2009-01-19 18:36:23 +00:00
|
|
|
{
|
2012-03-07 14:03:55 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to create socket");
|
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
|
2012-10-01 17:46:15 +00:00
|
|
|
* @context: (allow-none): a #GMainContext
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
|
|
|
* Attaches @server to @context. When the mainloop for @context is run, the
|
2013-11-22 01:28:28 +00:00
|
|
|
* server will be dispatched. When @context is %NULL, the default context will be
|
2011-01-19 14:29:55 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2015-07-23 18:50:30 +00:00
|
|
|
* This takes a reference on @server until the source is destroyed. Note that
|
|
|
|
* if @context is not the default main context as returned by
|
|
|
|
* g_main_context_default() (or %NULL), g_source_remove() cannot be used to
|
|
|
|
* destroy the source. In that case it is recommended to use
|
|
|
|
* gst_rtsp_server_create_source() and attach it to @context manually.
|
|
|
|
*
|
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;
|
2012-03-07 14:03:55 +00:00
|
|
|
GError *error = NULL;
|
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
|
|
|
|
2012-03-07 14:03:55 +00:00
|
|
|
source = gst_rtsp_server_create_source (server, NULL, &error);
|
2009-01-19 18:36:23 +00:00
|
|
|
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
|
|
|
{
|
2012-03-07 14:03:55 +00:00
|
|
|
GST_ERROR_OBJECT (server, "failed to create watch: %s", error->message);
|
|
|
|
g_error_free (error);
|
2008-10-09 12:29:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2013-08-02 15:15:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_server_client_filter:
|
|
|
|
* @server: a #GstRTSPServer
|
2013-11-18 10:47:04 +00:00
|
|
|
* @func: (scope call) (allow-none): a callback
|
2013-08-02 15:15:09 +00:00
|
|
|
* @user_data: user data passed to @func
|
|
|
|
*
|
|
|
|
* Call @func for each client managed by @server. The result value of @func
|
|
|
|
* determines what happens to the client. @func will be called with @server
|
|
|
|
* locked so no further actions on @server can be performed from @func.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REMOVE, the client will be removed from
|
|
|
|
* @server.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_KEEP, the client will remain in @server.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REF, the client will remain in @server but
|
|
|
|
* will also be added with an additional ref to the result #GList of this
|
|
|
|
* function..
|
|
|
|
*
|
2013-11-15 15:35:05 +00:00
|
|
|
* When @func is %NULL, #GST_RTSP_FILTER_REF will be assumed for each client.
|
|
|
|
*
|
2013-08-02 15:15:09 +00:00
|
|
|
* Returns: (element-type GstRTSPClient) (transfer full): a #GList with all
|
|
|
|
* clients for which @func returned #GST_RTSP_FILTER_REF. After usage, each
|
|
|
|
* element in the #GList should be unreffed before the list is freed.
|
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
gst_rtsp_server_client_filter (GstRTSPServer * server,
|
|
|
|
GstRTSPServerClientFilterFunc func, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPServerPrivate *priv;
|
|
|
|
GList *result, *walk, *next;
|
2014-07-10 09:32:20 +00:00
|
|
|
GHashTable *visited;
|
|
|
|
guint cookie;
|
2013-08-02 15:15:09 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SERVER (server), NULL);
|
|
|
|
|
|
|
|
priv = server->priv;
|
|
|
|
|
|
|
|
result = NULL;
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func)
|
|
|
|
visited = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL);
|
2013-08-02 15:15:09 +00:00
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
2014-07-10 09:32:20 +00:00
|
|
|
restart:
|
|
|
|
cookie = priv->clients_cookie;
|
2013-08-02 15:15:09 +00:00
|
|
|
for (walk = priv->clients; walk; walk = next) {
|
2013-08-16 16:42:22 +00:00
|
|
|
ClientContext *cctx = walk->data;
|
2014-07-10 09:32:20 +00:00
|
|
|
GstRTSPClient *client = cctx->client;
|
2013-11-15 15:35:05 +00:00
|
|
|
GstRTSPFilterResult res;
|
2014-07-10 09:32:20 +00:00
|
|
|
gboolean changed;
|
2013-08-02 15:15:09 +00:00
|
|
|
|
|
|
|
next = g_list_next (walk);
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func) {
|
|
|
|
/* only visit each media once */
|
|
|
|
if (g_hash_table_contains (visited, client))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_hash_table_add (visited, g_object_ref (client));
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
|
|
|
res = func (server, client, user_data);
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
|
|
|
} else
|
2013-11-15 15:35:05 +00:00
|
|
|
res = GST_RTSP_FILTER_REF;
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
changed = (cookie != priv->clients_cookie);
|
|
|
|
|
2013-11-15 15:35:05 +00:00
|
|
|
switch (res) {
|
2013-08-02 15:15:09 +00:00
|
|
|
case GST_RTSP_FILTER_REMOVE:
|
2014-07-10 15:10:06 +00:00
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
|
|
|
gst_rtsp_client_close (client);
|
|
|
|
|
|
|
|
GST_RTSP_SERVER_LOCK (server);
|
|
|
|
changed |= (cookie != priv->clients_cookie);
|
2013-08-02 15:15:09 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_REF:
|
2014-07-10 09:32:20 +00:00
|
|
|
result = g_list_prepend (result, g_object_ref (client));
|
2013-08-02 15:15:09 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_KEEP:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-07-10 09:32:20 +00:00
|
|
|
if (changed)
|
|
|
|
goto restart;
|
2013-08-02 15:15:09 +00:00
|
|
|
}
|
|
|
|
GST_RTSP_SERVER_UNLOCK (server);
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func)
|
|
|
|
g_hash_table_unref (visited);
|
|
|
|
|
2013-08-02 15:15:09 +00:00
|
|
|
return result;
|
|
|
|
}
|