2008-10-09 12:29:12 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
2015-01-09 11:40:47 +00:00
|
|
|
* Copyright (C) 2015 Centricular Ltd
|
|
|
|
* Author: Sebastian Dröge <sebastian@centricular.com>
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
|
|
|
* 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-client
|
|
|
|
* @short_description: A client connection state
|
|
|
|
* @see_also: #GstRTSPServer, #GstRTSPThreadPool
|
|
|
|
*
|
|
|
|
* The client object handles the connection with a client for as long as a TCP
|
|
|
|
* connection is open.
|
|
|
|
*
|
|
|
|
* A #GstRTSPClient is created by #GstRTSPServer when a new connection is
|
|
|
|
* accepted and it inherits the #GstRTSPMountPoints, #GstRTSPSessionPool,
|
|
|
|
* #GstRTSPAuth and #GstRTSPThreadPool from the server.
|
|
|
|
*
|
|
|
|
* The client connection should be configured with the #GstRTSPConnection using
|
|
|
|
* gst_rtsp_client_set_connection() before it can be attached to a #GMainContext
|
|
|
|
* using gst_rtsp_client_attach(). From then on the client will handle requests
|
|
|
|
* on the connection.
|
|
|
|
*
|
|
|
|
* Use gst_rtsp_client_session_filter() to iterate or modify all the
|
|
|
|
* #GstRTSPSession objects managed by the client object.
|
|
|
|
*
|
|
|
|
* 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
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2011-01-11 21:41:12 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2014-04-03 10:52:51 +00:00
|
|
|
#include <gst/sdp/gstmikey.h>
|
2016-08-24 09:39:13 +00:00
|
|
|
#include <gst/rtsp/gstrtsp-enumtypes.h>
|
2014-04-03 10:52:51 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
#include "rtsp-client.h"
|
2009-01-29 12:31:27 +00:00
|
|
|
#include "rtsp-sdp.h"
|
2009-06-09 22:01:07 +00:00
|
|
|
#include "rtsp-params.h"
|
2019-10-15 17:08:32 +00:00
|
|
|
#include "rtsp-server-internal.h"
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2018-02-15 12:26:16 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TUNNEL_STATE_UNKNOWN,
|
|
|
|
TUNNEL_STATE_GET,
|
|
|
|
TUNNEL_STATE_POST
|
|
|
|
} GstRTSPTunnelState;
|
|
|
|
|
2013-02-18 19:59:58 +00:00
|
|
|
/* locking order:
|
|
|
|
* send_lock, lock, tunnels_lock
|
|
|
|
*/
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
struct _GstRTSPClientPrivate
|
|
|
|
{
|
2013-02-18 19:59:58 +00:00
|
|
|
GMutex lock; /* protects everything else */
|
2013-01-28 09:31:50 +00:00
|
|
|
GMutex send_lock;
|
2014-08-28 11:35:15 +00:00
|
|
|
GMutex watch_lock;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPConnection *connection;
|
|
|
|
GstRTSPWatch *watch;
|
2014-06-12 11:49:17 +00:00
|
|
|
GMainContext *watch_context;
|
2012-11-29 10:11:05 +00:00
|
|
|
gchar *server_ip;
|
|
|
|
gboolean is_ipv6;
|
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
/* protected by send_lock */
|
|
|
|
GstRTSPClientSendFunc send_func;
|
|
|
|
gpointer send_data;
|
|
|
|
GDestroyNotify send_notify;
|
2018-09-17 19:18:46 +00:00
|
|
|
GstRTSPClientSendMessagesFunc send_messages_func;
|
|
|
|
gpointer send_messages_data;
|
|
|
|
GDestroyNotify send_messages_notify;
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
guint close_seq;
|
|
|
|
GArray *data_seqs;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
GstRTSPSessionPool *session_pool;
|
2014-07-01 10:13:47 +00:00
|
|
|
gulong session_removed_id;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMountPoints *mount_points;
|
|
|
|
GstRTSPAuth *auth;
|
2013-07-10 15:06:36 +00:00
|
|
|
GstRTSPThreadPool *thread_pool;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2013-06-26 15:18:33 +00:00
|
|
|
/* used to cache the media in the last requested DESCRIBE so that
|
|
|
|
* we can pick it up in the next SETUP immediately */
|
2013-07-03 13:55:38 +00:00
|
|
|
gchar *path;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPMedia *media;
|
|
|
|
|
2014-09-09 16:11:39 +00:00
|
|
|
GHashTable *transports;
|
2012-11-29 10:11:05 +00:00
|
|
|
GList *sessions;
|
2014-07-10 09:32:20 +00:00
|
|
|
guint sessions_cookie;
|
2014-04-01 11:04:21 +00:00
|
|
|
|
|
|
|
gboolean drop_backlog;
|
2016-11-21 15:02:39 +00:00
|
|
|
|
2019-03-27 15:21:03 +00:00
|
|
|
guint content_length_limit;
|
|
|
|
|
2016-11-21 15:02:39 +00:00
|
|
|
guint rtsp_ctrl_timeout_id;
|
|
|
|
guint rtsp_ctrl_timeout_cnt;
|
2017-04-22 12:26:07 +00:00
|
|
|
|
|
|
|
/* The version currently being used */
|
|
|
|
GstRTSPVersion version;
|
|
|
|
|
|
|
|
GHashTable *pipelined_requests; /* pipelined_request_id -> session_id */
|
2018-02-15 12:26:16 +00:00
|
|
|
GstRTSPTunnelState tstate;
|
2012-11-29 10:11:05 +00:00
|
|
|
};
|
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
guint8 channel;
|
|
|
|
guint seq;
|
|
|
|
} DataSeq;
|
|
|
|
|
2012-05-11 07:42:47 +00:00
|
|
|
static GMutex tunnels_lock;
|
2013-02-18 19:59:58 +00:00
|
|
|
static GHashTable *tunnels; /* protected by tunnels_lock */
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2014-09-16 09:29:38 +00:00
|
|
|
#define WATCH_BACKLOG_SIZE 100
|
|
|
|
|
2012-10-10 09:06:02 +00:00
|
|
|
#define DEFAULT_SESSION_POOL NULL
|
2012-11-26 11:34:05 +00:00
|
|
|
#define DEFAULT_MOUNT_POINTS NULL
|
2014-04-01 11:04:21 +00:00
|
|
|
#define DEFAULT_DROP_BACKLOG TRUE
|
2012-10-10 09:06:02 +00:00
|
|
|
|
2016-11-21 15:02:39 +00:00
|
|
|
#define RTSP_CTRL_CB_INTERVAL 1
|
|
|
|
#define RTSP_CTRL_TIMEOUT_VALUE 60
|
|
|
|
|
2009-02-10 15:24:13 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_SESSION_POOL,
|
2012-11-26 11:34:05 +00:00
|
|
|
PROP_MOUNT_POINTS,
|
2014-04-01 11:04:21 +00:00
|
|
|
PROP_DROP_BACKLOG,
|
2009-02-10 15:24:13 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2011-01-12 14:35:51 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_CLOSED,
|
2012-08-30 19:03:27 +00:00
|
|
|
SIGNAL_NEW_SESSION,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_OPTIONS_REQUEST,
|
2012-09-03 17:48:14 +00:00
|
|
|
SIGNAL_OPTIONS_REQUEST,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_DESCRIBE_REQUEST,
|
2012-09-03 17:48:14 +00:00
|
|
|
SIGNAL_DESCRIBE_REQUEST,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_SETUP_REQUEST,
|
2012-09-03 17:48:14 +00:00
|
|
|
SIGNAL_SETUP_REQUEST,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_PLAY_REQUEST,
|
2012-09-03 17:48:14 +00:00
|
|
|
SIGNAL_PLAY_REQUEST,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_PAUSE_REQUEST,
|
2012-09-03 17:48:14 +00:00
|
|
|
SIGNAL_PAUSE_REQUEST,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_TEARDOWN_REQUEST,
|
2012-09-03 17:48:14 +00:00
|
|
|
SIGNAL_TEARDOWN_REQUEST,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_SET_PARAMETER_REQUEST,
|
2012-09-03 17:48:14 +00:00
|
|
|
SIGNAL_SET_PARAMETER_REQUEST,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_GET_PARAMETER_REQUEST,
|
2012-09-03 17:48:14 +00:00
|
|
|
SIGNAL_GET_PARAMETER_REQUEST,
|
2013-08-08 14:57:42 +00:00
|
|
|
SIGNAL_HANDLE_RESPONSE,
|
2014-05-01 04:17:06 +00:00
|
|
|
SIGNAL_SEND_MESSAGE,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_ANNOUNCE_REQUEST,
|
2015-01-09 11:40:47 +00:00
|
|
|
SIGNAL_ANNOUNCE_REQUEST,
|
2016-08-24 09:39:13 +00:00
|
|
|
SIGNAL_PRE_RECORD_REQUEST,
|
2015-01-09 11:40:47 +00:00
|
|
|
SIGNAL_RECORD_REQUEST,
|
2015-06-18 11:12:04 +00:00
|
|
|
SIGNAL_CHECK_REQUIREMENTS,
|
2011-01-12 14:35:51 +00:00
|
|
|
SIGNAL_LAST
|
|
|
|
};
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_client_debug);
|
|
|
|
#define GST_CAT_DEFAULT rtsp_client_debug
|
|
|
|
|
2011-01-12 14:35:51 +00:00
|
|
|
static guint gst_rtsp_client_signals[SIGNAL_LAST] = { 0 };
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
static void gst_rtsp_client_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_client_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2009-01-22 14:33:29 +00:00
|
|
|
static void gst_rtsp_client_finalize (GObject * obj);
|
|
|
|
|
2018-12-04 13:12:04 +00:00
|
|
|
static void rtsp_ctrl_timeout_remove (GstRTSPClientPrivate * priv);
|
|
|
|
|
2012-09-07 15:14:30 +00:00
|
|
|
static GstSDPMessage *create_sdp (GstRTSPClient * client, GstRTSPMedia * media);
|
2015-01-09 11:40:47 +00:00
|
|
|
static gboolean handle_sdp (GstRTSPClient * client, GstRTSPContext * ctx,
|
|
|
|
GstRTSPMedia * media, GstSDPMessage * sdp);
|
2013-12-18 14:57:03 +00:00
|
|
|
static gboolean default_configure_client_media (GstRTSPClient * client,
|
|
|
|
GstRTSPMedia * media, GstRTSPStream * stream, GstRTSPContext * ctx);
|
2013-06-17 14:18:37 +00:00
|
|
|
static gboolean default_configure_client_transport (GstRTSPClient * client,
|
2013-07-22 12:25:04 +00:00
|
|
|
GstRTSPContext * ctx, GstRTSPTransport * ct);
|
2013-06-12 10:23:56 +00:00
|
|
|
static GstRTSPResult default_params_set (GstRTSPClient * client,
|
2013-07-22 12:25:04 +00:00
|
|
|
GstRTSPContext * ctx);
|
2013-06-12 10:23:56 +00:00
|
|
|
static GstRTSPResult default_params_get (GstRTSPClient * client,
|
2013-07-22 12:25:04 +00:00
|
|
|
GstRTSPContext * ctx);
|
2013-11-15 15:35:05 +00:00
|
|
|
static gchar *default_make_path_from_uri (GstRTSPClient * client,
|
|
|
|
const GstRTSPUrl * uri);
|
2014-07-09 13:01:31 +00:00
|
|
|
static void client_session_removed (GstRTSPSessionPool * pool,
|
|
|
|
GstRTSPSession * session, GstRTSPClient * client);
|
2016-08-24 09:39:13 +00:00
|
|
|
static GstRTSPStatusCode default_pre_signal_handler (GstRTSPClient * client,
|
|
|
|
GstRTSPContext * ctx);
|
|
|
|
static gboolean pre_signal_accumulator (GSignalInvocationHint * ihint,
|
|
|
|
GValue * return_accu, const GValue * handler_return, gpointer data);
|
2009-03-11 18:38:06 +00:00
|
|
|
|
2018-06-24 10:44:26 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GstRTSPClient, gst_rtsp_client, G_TYPE_OBJECT);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_client_class_init (GstRTSPClientClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2009-02-10 15:24:13 +00:00
|
|
|
gobject_class->get_property = gst_rtsp_client_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_client_set_property;
|
2009-01-22 14:33:29 +00:00
|
|
|
gobject_class->finalize = gst_rtsp_client_finalize;
|
2009-02-10 15:24:13 +00:00
|
|
|
|
2012-07-18 13:54:49 +00:00
|
|
|
klass->create_sdp = create_sdp;
|
2015-01-09 11:40:47 +00:00
|
|
|
klass->handle_sdp = handle_sdp;
|
2013-12-18 14:57:03 +00:00
|
|
|
klass->configure_client_media = default_configure_client_media;
|
2013-06-17 14:18:37 +00:00
|
|
|
klass->configure_client_transport = default_configure_client_transport;
|
2013-06-12 10:23:56 +00:00
|
|
|
klass->params_set = default_params_set;
|
|
|
|
klass->params_get = default_params_get;
|
2013-11-07 12:22:09 +00:00
|
|
|
klass->make_path_from_uri = default_make_path_from_uri;
|
2012-07-18 13:54:49 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
klass->pre_options_request = default_pre_signal_handler;
|
|
|
|
klass->pre_describe_request = default_pre_signal_handler;
|
|
|
|
klass->pre_setup_request = default_pre_signal_handler;
|
|
|
|
klass->pre_play_request = default_pre_signal_handler;
|
|
|
|
klass->pre_pause_request = default_pre_signal_handler;
|
|
|
|
klass->pre_teardown_request = default_pre_signal_handler;
|
|
|
|
klass->pre_set_parameter_request = default_pre_signal_handler;
|
|
|
|
klass->pre_get_parameter_request = default_pre_signal_handler;
|
|
|
|
klass->pre_announce_request = default_pre_signal_handler;
|
|
|
|
klass->pre_record_request = default_pre_signal_handler;
|
|
|
|
|
2009-02-10 15:24:13 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
|
|
|
|
g_param_spec_object ("session-pool", "Session Pool",
|
|
|
|
"The session pool to use for client session",
|
2009-05-26 17:01:10 +00:00
|
|
|
GST_TYPE_RTSP_SESSION_POOL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-02-10 15:24:13 +00:00
|
|
|
|
2012-11-26 11:34:05 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MOUNT_POINTS,
|
|
|
|
g_param_spec_object ("mount-points", "Mount Points",
|
|
|
|
"The mount points to use for client session",
|
|
|
|
GST_TYPE_RTSP_MOUNT_POINTS,
|
2009-05-26 17:01:10 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2014-04-01 11:04:21 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DROP_BACKLOG,
|
|
|
|
g_param_spec_boolean ("drop-backlog", "Drop Backlog",
|
|
|
|
"Drop data when the backlog queue is full",
|
|
|
|
DEFAULT_DROP_BACKLOG, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-01-12 14:35:51 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_CLOSED] =
|
|
|
|
g_signal_new ("closed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
2019-08-29 05:34:26 +00:00
|
|
|
G_STRUCT_OFFSET (GstRTSPClientClass, closed), NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0, G_TYPE_NONE);
|
2011-01-12 14:35:51 +00:00
|
|
|
|
2012-08-30 19:03:27 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_NEW_SESSION] =
|
|
|
|
g_signal_new ("new-session", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
2019-08-29 05:34:26 +00:00
|
|
|
G_STRUCT_OFFSET (GstRTSPClientClass, new_session), NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 1, GST_TYPE_RTSP_SESSION);
|
2012-08-30 19:03:27 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-options-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_OPTIONS_REQUEST] =
|
|
|
|
g_signal_new ("pre-options-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
pre_options_request), pre_signal_accumulator, NULL, NULL,
|
|
|
|
GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::options-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2012-09-03 17:48:14 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST] =
|
|
|
|
g_signal_new ("options-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, options_request),
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-describe-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_DESCRIBE_REQUEST] =
|
|
|
|
g_signal_new ("pre-describe-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
pre_describe_request), pre_signal_accumulator, NULL, NULL,
|
|
|
|
GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::describe-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2012-09-03 17:48:14 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST] =
|
|
|
|
g_signal_new ("describe-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, describe_request),
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-setup-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_SETUP_REQUEST] =
|
|
|
|
g_signal_new ("pre-setup-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
pre_setup_request), pre_signal_accumulator, NULL, NULL,
|
|
|
|
GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::setup-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2012-09-03 17:48:14 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST] =
|
|
|
|
g_signal_new ("setup-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, setup_request),
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-play-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_PLAY_REQUEST] =
|
|
|
|
g_signal_new ("pre-play-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
|
|
|
pre_play_request), pre_signal_accumulator, NULL,
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::play-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2012-09-03 17:48:14 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_PLAY_REQUEST] =
|
|
|
|
g_signal_new ("play-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, play_request),
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-pause-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_PAUSE_REQUEST] =
|
|
|
|
g_signal_new ("pre-pause-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
pre_pause_request), pre_signal_accumulator, NULL, NULL,
|
|
|
|
GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pause-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2012-09-03 17:48:14 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_PAUSE_REQUEST] =
|
|
|
|
g_signal_new ("pause-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, pause_request),
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-teardown-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_TEARDOWN_REQUEST] =
|
|
|
|
g_signal_new ("pre-teardown-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
pre_teardown_request), pre_signal_accumulator, NULL, NULL,
|
|
|
|
GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::teardown-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2012-09-03 17:48:14 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_TEARDOWN_REQUEST] =
|
|
|
|
g_signal_new ("teardown-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, teardown_request),
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-set-parameter-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_SET_PARAMETER_REQUEST] =
|
|
|
|
g_signal_new ("pre-set-parameter-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
pre_set_parameter_request), pre_signal_accumulator, NULL, NULL,
|
2016-08-24 09:39:13 +00:00
|
|
|
GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::set-parameter-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2012-09-03 17:48:14 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_SET_PARAMETER_REQUEST] =
|
|
|
|
g_signal_new ("set-parameter-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
set_parameter_request), NULL, NULL, NULL,
|
2014-06-24 07:43:44 +00:00
|
|
|
G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-get-parameter-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_GET_PARAMETER_REQUEST] =
|
|
|
|
g_signal_new ("pre-get-parameter-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
pre_get_parameter_request), pre_signal_accumulator, NULL, NULL,
|
|
|
|
GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::get-parameter-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2012-09-03 17:48:14 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_GET_PARAMETER_REQUEST] =
|
|
|
|
g_signal_new ("get-parameter-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
get_parameter_request), NULL, NULL, NULL,
|
2014-06-24 07:43:44 +00:00
|
|
|
G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::handle-response:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2013-08-08 14:57:42 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_HANDLE_RESPONSE] =
|
|
|
|
g_signal_new ("handle-response", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
handle_response), NULL, NULL, NULL,
|
2014-06-24 07:43:44 +00:00
|
|
|
G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2013-08-08 14:57:42 +00:00
|
|
|
|
2014-06-24 07:48:45 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::send-message:
|
|
|
|
* @client: The RTSP client
|
|
|
|
* @session: (type GstRtspServer.RTSPSession): The session
|
|
|
|
* @message: (type GstRtsp.RTSPMessage): The message
|
|
|
|
*/
|
2014-05-01 04:17:06 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_SEND_MESSAGE] =
|
|
|
|
g_signal_new ("send-message", G_TYPE_FROM_CLASS (klass),
|
2014-12-29 11:06:50 +00:00
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
send_message), NULL, NULL, NULL,
|
2014-06-24 07:43:44 +00:00
|
|
|
G_TYPE_NONE, 2, GST_TYPE_RTSP_CONTEXT, G_TYPE_POINTER);
|
2014-05-01 04:17:06 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-announce-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_ANNOUNCE_REQUEST] =
|
|
|
|
g_signal_new ("pre-announce-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
pre_announce_request), pre_signal_accumulator, NULL, NULL,
|
|
|
|
GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::announce-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2015-01-09 11:40:47 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_ANNOUNCE_REQUEST] =
|
|
|
|
g_signal_new ("announce-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, announce_request),
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2015-01-09 11:40:47 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::pre-record-request:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2016-08-24 09:39:13 +00:00
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPStatusCode, GST_RTSP_STS_OK in case of success,
|
|
|
|
* otherwise an appropriate return code
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_RECORD_REQUEST] =
|
|
|
|
g_signal_new ("pre-record-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
pre_record_request), pre_signal_accumulator, NULL, NULL,
|
|
|
|
GST_TYPE_RTSP_STATUS_CODE, 1, GST_TYPE_RTSP_CONTEXT);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
2018-02-06 16:58:49 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::record-request:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
|
|
|
*/
|
2015-01-09 11:40:47 +00:00
|
|
|
gst_rtsp_client_signals[SIGNAL_RECORD_REQUEST] =
|
|
|
|
g_signal_new ("record-request", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass, record_request),
|
2019-08-29 05:34:26 +00:00
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_RTSP_CONTEXT);
|
2015-01-09 11:40:47 +00:00
|
|
|
|
2015-06-18 11:12:04 +00:00
|
|
|
/**
|
|
|
|
* GstRTSPClient::check-requirements:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-06 16:58:49 +00:00
|
|
|
* @ctx: (type GstRtspServer.RTSPContext): a #GstRTSPContext
|
2015-06-18 11:12:04 +00:00
|
|
|
* @arr: a NULL-terminated array of strings
|
|
|
|
*
|
|
|
|
* Returns: a newly allocated string with comma-separated list of
|
|
|
|
* unsupported options. An empty string must be returned if
|
|
|
|
* all options are supported.
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
gst_rtsp_client_signals[SIGNAL_CHECK_REQUIREMENTS] =
|
|
|
|
g_signal_new ("check-requirements", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTSPClientClass,
|
2019-08-29 05:34:26 +00:00
|
|
|
check_requirements), NULL, NULL, NULL,
|
2015-06-18 11:12:04 +00:00
|
|
|
G_TYPE_STRING, 2, GST_TYPE_RTSP_CONTEXT, G_TYPE_STRV);
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
tunnels =
|
|
|
|
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_init (&tunnels_lock);
|
2009-11-21 18:20:23 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_client_debug, "rtspclient", 0, "GstRTSPClient");
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_client_init (GstRTSPClient * client)
|
|
|
|
{
|
2018-06-24 10:44:26 +00:00
|
|
|
GstRTSPClientPrivate *priv = gst_rtsp_client_get_instance_private (client);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
client->priv = priv;
|
|
|
|
|
|
|
|
g_mutex_init (&priv->lock);
|
2013-01-28 09:31:50 +00:00
|
|
|
g_mutex_init (&priv->send_lock);
|
2014-08-28 11:35:15 +00:00
|
|
|
g_mutex_init (&priv->watch_lock);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->close_seq = 0;
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
priv->data_seqs = g_array_new (FALSE, FALSE, sizeof (DataSeq));
|
2014-04-01 11:04:21 +00:00
|
|
|
priv->drop_backlog = DEFAULT_DROP_BACKLOG;
|
2014-11-28 11:45:14 +00:00
|
|
|
priv->transports =
|
|
|
|
g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
|
|
|
|
g_object_unref);
|
2017-04-22 12:26:07 +00:00
|
|
|
priv->pipelined_requests = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal, g_free, g_free);
|
2018-02-15 12:26:16 +00:00
|
|
|
priv->tstate = TUNNEL_STATE_UNKNOWN;
|
2019-03-27 15:21:03 +00:00
|
|
|
priv->content_length_limit = G_MAXUINT;
|
2012-11-29 10:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPFilterResult
|
2014-07-01 10:13:47 +00:00
|
|
|
filter_session_media (GstRTSPSession * sess, GstRTSPSessionMedia * sessmedia,
|
2012-11-29 10:11:05 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
2015-12-09 16:24:24 +00:00
|
|
|
gboolean *closed = user_data;
|
|
|
|
GstRTSPMedia *media;
|
|
|
|
guint i, n_streams;
|
|
|
|
gboolean is_all_udp = TRUE;
|
|
|
|
|
|
|
|
media = gst_rtsp_session_media_get_media (sessmedia);
|
|
|
|
n_streams = gst_rtsp_media_n_streams (media);
|
|
|
|
|
|
|
|
for (i = 0; i < n_streams; i++) {
|
|
|
|
GstRTSPStreamTransport *transport =
|
|
|
|
gst_rtsp_session_media_get_transport (sessmedia, i);
|
|
|
|
const GstRTSPTransport *rtsp_transport;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2015-12-09 16:24:24 +00:00
|
|
|
if (!transport)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rtsp_transport = gst_rtsp_stream_transport_get_transport (transport);
|
|
|
|
if (rtsp_transport
|
|
|
|
&& rtsp_transport->lower_transport != GST_RTSP_LOWER_TRANS_UDP
|
|
|
|
&& rtsp_transport->lower_transport != GST_RTSP_LOWER_TRANS_UDP_MCAST) {
|
|
|
|
is_all_udp = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_all_udp || gst_rtsp_media_is_stop_on_disconnect (media)) {
|
|
|
|
gst_rtsp_session_media_set_state (sessmedia, GST_STATE_NULL);
|
|
|
|
return GST_RTSP_FILTER_REMOVE;
|
|
|
|
} else {
|
|
|
|
*closed = FALSE;
|
|
|
|
return GST_RTSP_FILTER_KEEP;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 10:20:21 +00:00
|
|
|
static void
|
|
|
|
client_watch_session (GstRTSPClient * client, GstRTSPSession * session)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2014-07-01 12:41:14 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
/* check if we already know about this session */
|
2014-07-01 13:02:15 +00:00
|
|
|
if (g_list_find (priv->sessions, session) == NULL) {
|
2014-07-01 12:41:14 +00:00
|
|
|
GST_INFO ("watching session %p", session);
|
2014-07-09 13:01:31 +00:00
|
|
|
|
2014-07-01 12:41:14 +00:00
|
|
|
priv->sessions = g_list_prepend (priv->sessions, g_object_ref (session));
|
2014-07-10 09:32:20 +00:00
|
|
|
priv->sessions_cookie++;
|
2014-07-09 13:01:31 +00:00
|
|
|
|
|
|
|
/* connect removed session handler, it will be disconnected when the last
|
|
|
|
* session gets removed */
|
|
|
|
if (priv->session_removed_id == 0)
|
|
|
|
priv->session_removed_id = g_signal_connect_data (priv->session_pool,
|
|
|
|
"session-removed", G_CALLBACK (client_session_removed),
|
|
|
|
g_object_ref (client), (GClosureNotify) g_object_unref, 0);
|
2014-07-01 12:41:14 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2013-06-20 10:20:21 +00:00
|
|
|
|
2014-07-01 12:41:14 +00:00
|
|
|
return;
|
2013-06-20 10:20:21 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 12:41:14 +00:00
|
|
|
/* should be called with lock */
|
2013-06-26 15:18:33 +00:00
|
|
|
static void
|
2014-07-01 10:13:47 +00:00
|
|
|
client_unwatch_session (GstRTSPClient * client, GstRTSPSession * session,
|
|
|
|
GList * link)
|
2013-06-26 15:18:33 +00:00
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2014-07-01 10:13:47 +00:00
|
|
|
GST_INFO ("client %p: unwatch session %p", client, session);
|
2013-06-26 15:18:33 +00:00
|
|
|
|
2014-07-01 10:13:47 +00:00
|
|
|
if (link == NULL) {
|
|
|
|
link = g_list_find (priv->sessions, session);
|
|
|
|
if (link == NULL)
|
|
|
|
return;
|
|
|
|
}
|
2014-07-09 13:01:31 +00:00
|
|
|
|
2014-07-01 12:41:14 +00:00
|
|
|
priv->sessions = g_list_delete_link (priv->sessions, link);
|
2014-07-10 09:32:20 +00:00
|
|
|
priv->sessions_cookie++;
|
2013-06-26 15:18:33 +00:00
|
|
|
|
2014-07-09 13:01:31 +00:00
|
|
|
/* if this was the last session, disconnect the handler.
|
|
|
|
* This will also drop the extra client ref */
|
|
|
|
if (!priv->sessions) {
|
2014-07-10 09:32:20 +00:00
|
|
|
g_signal_handler_disconnect (priv->session_pool, priv->session_removed_id);
|
2014-07-09 13:01:31 +00:00
|
|
|
priv->session_removed_id = 0;
|
|
|
|
}
|
|
|
|
|
2016-09-26 09:16:04 +00:00
|
|
|
if (!priv->drop_backlog) {
|
|
|
|
/* unlink all media managed in this session */
|
|
|
|
gst_rtsp_session_filter (session, filter_session_media, client);
|
|
|
|
}
|
|
|
|
|
2014-07-01 10:13:47 +00:00
|
|
|
/* remove the session */
|
|
|
|
g_object_unref (session);
|
2013-06-26 15:18:33 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 10:13:47 +00:00
|
|
|
static GstRTSPFilterResult
|
|
|
|
cleanup_session (GstRTSPClient * client, GstRTSPSession * sess,
|
|
|
|
gpointer user_data)
|
2010-04-06 15:08:40 +00:00
|
|
|
{
|
2015-12-09 16:24:24 +00:00
|
|
|
gboolean *closed = user_data;
|
2016-09-26 09:16:04 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2015-12-09 16:24:24 +00:00
|
|
|
|
2016-09-26 09:16:04 +00:00
|
|
|
if (priv->drop_backlog) {
|
|
|
|
/* unlink all media managed in this session. This needs to happen
|
|
|
|
* without the client lock, so we really want to do it here. */
|
|
|
|
gst_rtsp_session_filter (sess, filter_session_media, user_data);
|
|
|
|
}
|
2014-09-30 23:36:51 +00:00
|
|
|
|
2015-12-09 16:24:24 +00:00
|
|
|
if (*closed)
|
|
|
|
return GST_RTSP_FILTER_REMOVE;
|
|
|
|
else
|
|
|
|
return GST_RTSP_FILTER_KEEP;
|
2010-04-06 15:08:40 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 11:48:53 +00:00
|
|
|
static void
|
|
|
|
clean_cached_media (GstRTSPClient * client, gboolean unprepare)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
|
|
|
if (priv->path) {
|
|
|
|
g_free (priv->path);
|
|
|
|
priv->path = NULL;
|
|
|
|
}
|
|
|
|
if (priv->media) {
|
|
|
|
if (unprepare)
|
|
|
|
gst_rtsp_media_unprepare (priv->media);
|
|
|
|
g_object_unref (priv->media);
|
|
|
|
priv->media = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 15:08:40 +00:00
|
|
|
/* A client is finalized when the connection is broken */
|
|
|
|
static void
|
|
|
|
gst_rtsp_client_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (obj);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-04-06 15:08:40 +00:00
|
|
|
|
|
|
|
GST_INFO ("finalize client %p", client);
|
|
|
|
|
2014-04-01 11:04:21 +00:00
|
|
|
if (priv->watch)
|
|
|
|
gst_rtsp_watch_set_flushing (priv->watch, TRUE);
|
2013-01-28 09:31:50 +00:00
|
|
|
gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
|
2018-09-17 19:18:46 +00:00
|
|
|
gst_rtsp_client_set_send_messages_func (client, NULL, NULL, NULL);
|
2013-01-28 09:31:50 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->watch)
|
|
|
|
g_source_destroy ((GSource *) priv->watch);
|
2012-10-01 14:13:50 +00:00
|
|
|
|
2014-06-12 11:49:17 +00:00
|
|
|
if (priv->watch_context)
|
|
|
|
g_main_context_unref (priv->watch_context);
|
|
|
|
|
2014-07-09 13:01:31 +00:00
|
|
|
/* all sessions should have been removed by now. We keep a ref to
|
|
|
|
* the client object for the session removed handler. The ref is
|
|
|
|
* dropped when the last session is removed from the list. */
|
|
|
|
g_assert (priv->sessions == NULL);
|
|
|
|
g_assert (priv->session_removed_id == 0);
|
2009-03-11 18:38:06 +00:00
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
g_array_unref (priv->data_seqs);
|
2014-09-09 16:11:39 +00:00
|
|
|
g_hash_table_unref (priv->transports);
|
2017-10-09 10:43:01 +00:00
|
|
|
g_hash_table_unref (priv->pipelined_requests);
|
2014-09-09 16:11:39 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->connection)
|
|
|
|
gst_rtsp_connection_free (priv->connection);
|
2014-07-01 10:13:47 +00:00
|
|
|
if (priv->session_pool) {
|
2012-11-29 10:11:05 +00:00
|
|
|
g_object_unref (priv->session_pool);
|
2014-07-01 10:13:47 +00:00
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->mount_points)
|
|
|
|
g_object_unref (priv->mount_points);
|
|
|
|
if (priv->auth)
|
|
|
|
g_object_unref (priv->auth);
|
2013-09-05 06:56:02 +00:00
|
|
|
if (priv->thread_pool)
|
|
|
|
g_object_unref (priv->thread_pool);
|
2009-01-29 17:51:02 +00:00
|
|
|
|
2014-11-07 11:48:53 +00:00
|
|
|
clean_cached_media (client, TRUE);
|
2009-01-29 17:51:02 +00:00
|
|
|
|
2018-10-20 14:14:53 +00:00
|
|
|
if (priv->rtsp_ctrl_timeout_id != 0) {
|
|
|
|
GST_DEBUG ("Killing leftover timeout GSource for client %p", client);
|
|
|
|
g_source_destroy (g_main_context_find_source_by_id (priv->watch_context,
|
|
|
|
priv->rtsp_ctrl_timeout_id));
|
|
|
|
priv->rtsp_ctrl_timeout_id = 0;
|
|
|
|
priv->rtsp_ctrl_timeout_cnt = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_free (priv->server_ip);
|
|
|
|
g_mutex_clear (&priv->lock);
|
2013-01-28 09:31:50 +00:00
|
|
|
g_mutex_clear (&priv->send_lock);
|
2014-08-28 11:35:15 +00:00
|
|
|
g_mutex_clear (&priv->watch_lock);
|
2010-03-16 17:33:23 +00:00
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtsp_client_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
2009-02-10 15:24:13 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2009-02-10 15:24:13 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (object);
|
2014-04-01 11:04:21 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-02-10 15:24:13 +00:00
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SESSION_POOL:
|
|
|
|
g_value_take_object (value, gst_rtsp_client_get_session_pool (client));
|
|
|
|
break;
|
2012-11-26 11:34:05 +00:00
|
|
|
case PROP_MOUNT_POINTS:
|
|
|
|
g_value_take_object (value, gst_rtsp_client_get_mount_points (client));
|
2009-02-10 15:24:13 +00:00
|
|
|
break;
|
2014-04-01 11:04:21 +00:00
|
|
|
case PROP_DROP_BACKLOG:
|
|
|
|
g_value_set_boolean (value, priv->drop_backlog);
|
|
|
|
break;
|
2009-02-10 15:24:13 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2009-02-10 15:24:13 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (object);
|
2014-04-01 11:04:21 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-02-10 15:24:13 +00:00
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SESSION_POOL:
|
|
|
|
gst_rtsp_client_set_session_pool (client, g_value_get_object (value));
|
|
|
|
break;
|
2012-11-26 11:34:05 +00:00
|
|
|
case PROP_MOUNT_POINTS:
|
|
|
|
gst_rtsp_client_set_mount_points (client, g_value_get_object (value));
|
2009-02-10 15:24:13 +00:00
|
|
|
break;
|
2014-04-01 11:04:21 +00:00
|
|
|
case PROP_DROP_BACKLOG:
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->drop_backlog = g_value_get_boolean (value);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
break;
|
2009-02-10 15:24:13 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_new:
|
|
|
|
*
|
|
|
|
* Create a new #GstRTSPClient instance.
|
2010-12-30 11:41:31 +00:00
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): a new #GstRTSPClient
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
GstRTSPClient *
|
|
|
|
gst_rtsp_client_new (void)
|
|
|
|
{
|
|
|
|
GstRTSPClient *result;
|
|
|
|
|
|
|
|
result = g_object_new (GST_TYPE_RTSP_CLIENT, NULL);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
static void
|
2014-05-01 04:07:08 +00:00
|
|
|
send_message (GstRTSPClient * client, GstRTSPContext * ctx,
|
2013-06-25 13:09:13 +00:00
|
|
|
GstRTSPMessage * message, gboolean close)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2013-06-25 13:09:13 +00:00
|
|
|
gst_rtsp_message_add_header (message, GST_RTSP_HDR_SERVER,
|
2009-05-26 17:01:10 +00:00
|
|
|
"GStreamer RTSP server");
|
2009-02-04 16:00:42 +00:00
|
|
|
|
2009-03-11 18:38:06 +00:00
|
|
|
/* remove any previous header */
|
2013-06-25 13:09:13 +00:00
|
|
|
gst_rtsp_message_remove_header (message, GST_RTSP_HDR_SESSION, -1);
|
2009-02-10 15:24:13 +00:00
|
|
|
|
2009-02-13 11:57:45 +00:00
|
|
|
/* add the new session header for new session ids */
|
2014-05-01 04:07:08 +00:00
|
|
|
if (ctx->session) {
|
2013-06-25 13:09:13 +00:00
|
|
|
gst_rtsp_message_take_header (message, GST_RTSP_HDR_SESSION,
|
2014-05-01 04:07:08 +00:00
|
|
|
gst_rtsp_session_get_header (ctx->session));
|
2009-02-13 11:57:45 +00:00
|
|
|
}
|
2009-11-21 00:17:25 +00:00
|
|
|
|
|
|
|
if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
|
2013-06-25 13:09:13 +00:00
|
|
|
gst_rtsp_message_dump (message);
|
2009-11-21 00:17:25 +00:00
|
|
|
}
|
2009-02-13 11:57:45 +00:00
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
if (close)
|
2013-06-25 13:09:13 +00:00
|
|
|
gst_rtsp_message_add_header (message, GST_RTSP_HDR_CONNECTION, "close");
|
2012-11-26 16:20:39 +00:00
|
|
|
|
2017-04-22 12:26:07 +00:00
|
|
|
if (ctx->request)
|
|
|
|
message->type_data.response.version =
|
|
|
|
ctx->request->type_data.request.version;
|
|
|
|
|
2014-05-01 04:17:06 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SEND_MESSAGE],
|
|
|
|
0, ctx, message);
|
|
|
|
|
2013-01-28 09:31:50 +00:00
|
|
|
g_mutex_lock (&priv->send_lock);
|
2019-01-25 12:22:42 +00:00
|
|
|
if (priv->send_messages_func) {
|
|
|
|
priv->send_messages_func (client, message, 1, close, priv->send_data);
|
|
|
|
} else if (priv->send_func) {
|
2013-06-25 13:09:13 +00:00
|
|
|
priv->send_func (client, message, close, priv->send_data);
|
2019-01-25 12:22:42 +00:00
|
|
|
}
|
2013-01-28 09:31:50 +00:00
|
|
|
g_mutex_unlock (&priv->send_lock);
|
2012-11-26 16:20:39 +00:00
|
|
|
|
2013-06-25 13:09:13 +00:00
|
|
|
gst_rtsp_message_unset (message);
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
send_generic_response (GstRTSPClient * client, GstRTSPStatusCode code,
|
2013-07-22 12:25:04 +00:00
|
|
|
GstRTSPContext * ctx)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_init_response (ctx->response, code,
|
|
|
|
gst_rtsp_status_as_text (code), ctx->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
ctx->session = NULL;
|
|
|
|
|
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
2009-01-29 17:51:02 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 18:59:23 +00:00
|
|
|
static void
|
|
|
|
send_option_not_supported_response (GstRTSPClient * client,
|
|
|
|
GstRTSPContext * ctx, const gchar * unsupported_options)
|
|
|
|
{
|
|
|
|
GstRTSPStatusCode code = GST_RTSP_STS_OPTION_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
gst_rtsp_message_init_response (ctx->response, code,
|
|
|
|
gst_rtsp_status_as_text (code), ctx->request);
|
|
|
|
|
|
|
|
if (unsupported_options != NULL) {
|
|
|
|
gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_UNSUPPORTED,
|
|
|
|
unsupported_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->session = NULL;
|
|
|
|
|
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
|
|
|
}
|
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
static gboolean
|
2013-07-03 13:55:38 +00:00
|
|
|
paths_are_equal (const gchar * path1, const gchar * path2, gint len2)
|
2009-01-29 17:51:02 +00:00
|
|
|
{
|
2013-07-03 13:55:38 +00:00
|
|
|
if (path1 == NULL || path2 == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (strlen (path1) != len2)
|
2009-01-29 17:51:02 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2013-07-03 13:55:38 +00:00
|
|
|
if (strncmp (path1, path2, len2))
|
2009-01-29 17:51:02 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
/* this function is called to initially find the media for the DESCRIBE request
|
|
|
|
* but is cached for when the same client (without breaking the connection) is
|
|
|
|
* doing a setup for the exact same url. */
|
2009-01-29 12:31:27 +00:00
|
|
|
static GstRTSPMedia *
|
2013-09-17 10:21:02 +00:00
|
|
|
find_media (GstRTSPClient * client, GstRTSPContext * ctx, gchar * path,
|
|
|
|
gint * matched)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-01-29 12:31:27 +00:00
|
|
|
GstRTSPMediaFactory *factory;
|
|
|
|
GstRTSPMedia *media;
|
2013-07-03 13:55:38 +00:00
|
|
|
gint path_len;
|
|
|
|
|
|
|
|
/* find the longest matching factory for the uri first */
|
|
|
|
if (!(factory = gst_rtsp_mount_points_match (priv->mount_points,
|
|
|
|
path, matched)))
|
|
|
|
goto no_factory;
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->factory = factory;
|
2013-07-08 14:29:01 +00:00
|
|
|
|
2013-07-09 14:04:35 +00:00
|
|
|
if (!gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_ACCESS))
|
|
|
|
goto no_factory_access;
|
|
|
|
|
|
|
|
if (!gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_CONSTRUCT))
|
2013-07-08 14:29:01 +00:00
|
|
|
goto not_authorized;
|
|
|
|
|
2013-07-03 13:55:38 +00:00
|
|
|
if (matched)
|
|
|
|
path_len = *matched;
|
|
|
|
else
|
|
|
|
path_len = strlen (path);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2013-07-03 13:55:38 +00:00
|
|
|
if (!paths_are_equal (priv->path, path, path_len)) {
|
2009-01-29 17:51:02 +00:00
|
|
|
/* remove any previously cached values before we try to construct a new
|
|
|
|
* media for uri */
|
2014-11-07 11:48:53 +00:00
|
|
|
clean_cached_media (client, TRUE);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-01-29 17:51:02 +00:00
|
|
|
/* prepare the media and add it to the pipeline */
|
2013-07-22 12:25:04 +00:00
|
|
|
if (!(media = gst_rtsp_media_factory_construct (factory, ctx->uri)))
|
2009-01-29 17:51:02 +00:00
|
|
|
goto no_media;
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->media = media;
|
2013-07-10 15:09:27 +00:00
|
|
|
|
2015-01-28 17:54:01 +00:00
|
|
|
if (!(gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_RECORD)) {
|
2015-01-09 11:40:47 +00:00
|
|
|
GstRTSPThread *thread;
|
|
|
|
|
|
|
|
thread = gst_rtsp_thread_pool_get_thread (priv->thread_pool,
|
|
|
|
GST_RTSP_THREAD_TYPE_MEDIA, ctx);
|
|
|
|
if (thread == NULL)
|
|
|
|
goto no_thread;
|
2013-07-10 15:09:27 +00:00
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
/* prepare the media */
|
|
|
|
if (!gst_rtsp_media_prepare (media, thread))
|
|
|
|
goto no_prepare;
|
|
|
|
}
|
2009-01-29 17:51:02 +00:00
|
|
|
|
|
|
|
/* now keep track of the uri and the media */
|
2013-07-03 13:55:38 +00:00
|
|
|
priv->path = g_strndup (path, path_len);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->media = media;
|
2009-05-26 17:01:10 +00:00
|
|
|
} else {
|
2013-07-03 13:55:38 +00:00
|
|
|
/* we have seen this path before, used cached media */
|
2012-11-29 10:11:05 +00:00
|
|
|
media = priv->media;
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->media = media;
|
2013-07-03 13:55:38 +00:00
|
|
|
GST_INFO ("reusing cached media %p for path %s", media, priv->path);
|
2009-01-29 17:51:02 +00:00
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2013-07-03 13:55:38 +00:00
|
|
|
g_object_unref (factory);
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->factory = NULL;
|
2013-07-03 13:55:38 +00:00
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
if (media)
|
|
|
|
g_object_ref (media);
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
return media;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_factory:
|
|
|
|
{
|
2013-09-17 10:21:02 +00:00
|
|
|
GST_ERROR ("client %p: no factory for path %s", client, path);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
2009-01-29 12:31:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-09 14:04:35 +00:00
|
|
|
no_factory_access:
|
|
|
|
{
|
2016-09-14 14:48:39 +00:00
|
|
|
g_object_unref (factory);
|
|
|
|
ctx->factory = NULL;
|
2013-09-17 10:21:02 +00:00
|
|
|
GST_ERROR ("client %p: not authorized to see factory path %s", client,
|
|
|
|
path);
|
2013-09-26 07:41:10 +00:00
|
|
|
/* error reply is already sent */
|
2013-07-09 14:04:35 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-08 14:29:01 +00:00
|
|
|
not_authorized:
|
|
|
|
{
|
2016-09-14 14:48:39 +00:00
|
|
|
g_object_unref (factory);
|
|
|
|
ctx->factory = NULL;
|
2013-09-17 10:21:02 +00:00
|
|
|
GST_ERROR ("client %p: not authorized for factory path %s", client, path);
|
2013-09-26 07:41:10 +00:00
|
|
|
/* error reply is already sent */
|
2013-07-08 14:29:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_media:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: can't create media", client);
|
2013-09-26 09:20:05 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_unref (factory);
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->factory = NULL;
|
2009-01-29 12:31:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-10 15:09:27 +00:00
|
|
|
no_thread:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: can't create thread", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
|
2013-07-10 15:09:27 +00:00
|
|
|
g_object_unref (media);
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->media = NULL;
|
2013-07-10 15:09:27 +00:00
|
|
|
g_object_unref (factory);
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->factory = NULL;
|
2013-07-10 15:09:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_prepare:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: can't prepare media", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_unref (media);
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->media = NULL;
|
2013-07-03 13:55:38 +00:00
|
|
|
g_object_unref (factory);
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->factory = NULL;
|
2009-01-29 12:31:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
static inline DataSeq *
|
|
|
|
get_data_seq_element (GstRTSPClient * client, guint8 channel)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
GArray *data_seqs = priv->data_seqs;
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
while (i < data_seqs->len) {
|
|
|
|
DataSeq *data_seq = &g_array_index (data_seqs, DataSeq, i);
|
|
|
|
if (data_seq->channel == channel)
|
|
|
|
return data_seq;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_data_seq (GstRTSPClient * client, guint8 channel)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
DataSeq data_seq = {.channel = channel,.seq = 0 };
|
|
|
|
|
|
|
|
if (get_data_seq_element (client, channel) == NULL)
|
|
|
|
g_array_append_val (priv->data_seqs, data_seq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_data_seq (GstRTSPClient * client, guint8 channel, guint seq)
|
|
|
|
{
|
|
|
|
DataSeq *data_seq;
|
|
|
|
|
|
|
|
data_seq = get_data_seq_element (client, channel);
|
|
|
|
g_assert_nonnull (data_seq);
|
|
|
|
data_seq->seq = seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
get_data_seq (GstRTSPClient * client, guint8 channel)
|
|
|
|
{
|
|
|
|
DataSeq *data_seq;
|
|
|
|
|
|
|
|
data_seq = get_data_seq_element (client, channel);
|
|
|
|
g_assert_nonnull (data_seq);
|
|
|
|
return data_seq->seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
get_data_channel (GstRTSPClient * client, guint seq, guint8 * channel)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
GArray *data_seqs = priv->data_seqs;
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
while (i < data_seqs->len) {
|
|
|
|
DataSeq *data_seq = &g_array_index (data_seqs, DataSeq, i);
|
|
|
|
if (data_seq->seq == seq) {
|
|
|
|
*channel = data_seq->channel;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
do_close (gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPClient *client = user_data;
|
|
|
|
|
|
|
|
gst_rtsp_client_close (client);
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
static gboolean
|
2009-05-26 17:01:10 +00:00
|
|
|
do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-11 15:45:12 +00:00
|
|
|
GstRTSPMessage message = { 0 };
|
2018-04-17 09:03:11 +00:00
|
|
|
gboolean ret = TRUE;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
gst_rtsp_message_init_data (&message, channel);
|
|
|
|
|
2018-09-17 19:18:46 +00:00
|
|
|
gst_rtsp_message_set_body_buffer (&message, buffer);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2013-01-28 09:31:50 +00:00
|
|
|
g_mutex_lock (&priv->send_lock);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
if (get_data_seq (client, channel) != 0) {
|
|
|
|
GST_WARNING ("already a queued data message for channel %d", channel);
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-01-25 12:22:42 +00:00
|
|
|
if (priv->send_messages_func) {
|
|
|
|
ret =
|
|
|
|
priv->send_messages_func (client, &message, 1, FALSE, priv->send_data);
|
|
|
|
} else if (priv->send_func) {
|
2018-04-17 09:03:11 +00:00
|
|
|
ret = priv->send_func (client, &message, FALSE, priv->send_data);
|
2019-01-25 12:22:42 +00:00
|
|
|
}
|
2013-01-28 09:31:50 +00:00
|
|
|
g_mutex_unlock (&priv->send_lock);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
gst_rtsp_message_unset (&message);
|
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
if (!ret) {
|
|
|
|
GSource *idle_src;
|
|
|
|
|
|
|
|
/* close in watch context */
|
|
|
|
idle_src = g_idle_source_new ();
|
|
|
|
g_source_set_callback (idle_src, do_close, client, NULL);
|
|
|
|
g_source_attach (idle_src, priv->watch_context);
|
|
|
|
g_source_unref (idle_src);
|
|
|
|
}
|
|
|
|
|
2018-04-17 09:03:11 +00:00
|
|
|
return ret;
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 17:08:32 +00:00
|
|
|
static gboolean
|
|
|
|
do_check_back_pressure (guint8 channel, GstRTSPClient * client)
|
|
|
|
{
|
|
|
|
return get_data_seq (client, channel) != 0;
|
|
|
|
}
|
|
|
|
|
2018-06-27 10:17:07 +00:00
|
|
|
static gboolean
|
|
|
|
do_send_data_list (GstBufferList * buffer_list, guint8 channel,
|
|
|
|
GstRTSPClient * client)
|
|
|
|
{
|
2018-09-17 19:18:46 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2018-06-27 10:17:07 +00:00
|
|
|
gboolean ret = TRUE;
|
|
|
|
guint i, n = gst_buffer_list_length (buffer_list);
|
2018-09-17 19:18:46 +00:00
|
|
|
GstRTSPMessage *messages;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->send_lock);
|
|
|
|
if (get_data_seq (client, channel) != 0) {
|
|
|
|
GST_WARNING ("already a queued data message for channel %d", channel);
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-06-27 10:17:07 +00:00
|
|
|
|
2018-09-17 19:18:46 +00:00
|
|
|
messages = g_newa (GstRTSPMessage, n);
|
|
|
|
memset (messages, 0, sizeof (GstRTSPMessage) * n);
|
2018-06-27 10:17:07 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstBuffer *buffer = gst_buffer_list_get (buffer_list, i);
|
2018-09-17 19:18:46 +00:00
|
|
|
gst_rtsp_message_init_data (&messages[i], channel);
|
|
|
|
gst_rtsp_message_set_body_buffer (&messages[i], buffer);
|
|
|
|
}
|
2018-06-27 10:17:07 +00:00
|
|
|
|
2018-09-17 19:18:46 +00:00
|
|
|
if (priv->send_messages_func) {
|
|
|
|
ret =
|
|
|
|
priv->send_messages_func (client, messages, n, FALSE, priv->send_data);
|
|
|
|
} else if (priv->send_func) {
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
ret = priv->send_func (client, &messages[i], FALSE, priv->send_data);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
gst_rtsp_message_unset (&messages[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
GSource *idle_src;
|
|
|
|
|
|
|
|
/* close in watch context */
|
|
|
|
idle_src = g_idle_source_new ();
|
|
|
|
g_source_set_callback (idle_src, do_close, client, NULL);
|
|
|
|
g_source_attach (idle_src, priv->watch_context);
|
|
|
|
g_source_unref (idle_src);
|
2018-06-27 10:17:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-07-10 15:05:13 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_close:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
|
|
|
* Close the connection of @client and remove all media it was managing.
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_client_close (GstRTSPClient * client)
|
2010-04-06 13:45:56 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-12-11 09:48:42 +00:00
|
|
|
const gchar *tunnelid;
|
2010-04-06 13:45:56 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("client %p: closing connection", client);
|
|
|
|
|
2014-07-01 10:13:47 +00:00
|
|
|
if (priv->connection) {
|
|
|
|
if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
|
|
|
|
g_mutex_lock (&tunnels_lock);
|
|
|
|
/* remove from tunnelids */
|
|
|
|
g_hash_table_remove (tunnels, tunnelid);
|
|
|
|
g_mutex_unlock (&tunnels_lock);
|
|
|
|
}
|
|
|
|
gst_rtsp_connection_close (priv->connection);
|
2010-04-06 13:45:56 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 11:48:44 +00:00
|
|
|
/* connection is now closed, destroy the watch which will also cause the
|
|
|
|
* closed signal to be emitted */
|
|
|
|
if (priv->watch) {
|
|
|
|
GST_DEBUG ("client %p: destroying watch", client);
|
|
|
|
g_source_destroy ((GSource *) priv->watch);
|
|
|
|
priv->watch = NULL;
|
|
|
|
gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
|
2018-09-17 19:18:46 +00:00
|
|
|
gst_rtsp_client_set_send_messages_func (client, NULL, NULL, NULL);
|
2018-12-04 13:12:04 +00:00
|
|
|
rtsp_ctrl_timeout_remove (priv);
|
2014-09-22 11:32:06 +00:00
|
|
|
g_main_context_unref (priv->watch_context);
|
|
|
|
priv->watch_context = NULL;
|
2014-06-12 11:48:44 +00:00
|
|
|
}
|
2010-04-06 13:45:56 +00:00
|
|
|
}
|
|
|
|
|
2013-10-04 04:29:30 +00:00
|
|
|
static gchar *
|
2013-11-07 12:22:09 +00:00
|
|
|
default_make_path_from_uri (GstRTSPClient * client, const GstRTSPUrl * uri)
|
2013-10-04 04:29:30 +00:00
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
if (uri->query)
|
|
|
|
path = g_strconcat (uri->abspath, "?", uri->query, NULL);
|
|
|
|
else
|
|
|
|
path = g_strdup (uri->abspath);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
/* Default signal handler function for all "pre-command" signals, like
|
|
|
|
* pre-options-request. It just returns the RTSP return code 200.
|
|
|
|
* Subclasses can override this to get another default behaviour.
|
|
|
|
*/
|
|
|
|
static GstRTSPStatusCode
|
|
|
|
default_pre_signal_handler (GstRTSPClient * client, GstRTSPContext * ctx)
|
|
|
|
{
|
|
|
|
GST_LOG_OBJECT (client, "returning GST_RTSP_STS_OK");
|
|
|
|
return GST_RTSP_STS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The pre-signal accumulator function checks the return value of the signal
|
|
|
|
* handlers. If any of them returns an RTSP status code that does not start
|
|
|
|
* with 2 it will return FALSE, no more signal handlers will be called, and
|
|
|
|
* this last RTSP status code will be the result of the signal emission.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
pre_signal_accumulator (GSignalInvocationHint * ihint, GValue * return_accu,
|
|
|
|
const GValue * handler_return, gpointer data)
|
|
|
|
{
|
|
|
|
GstRTSPStatusCode handler_value = g_value_get_enum (handler_return);
|
|
|
|
GstRTSPStatusCode accumulated_value = g_value_get_enum (return_accu);
|
|
|
|
|
|
|
|
if (handler_value < 200 || handler_value > 299) {
|
|
|
|
GST_DEBUG ("handler_value : %d, returning FALSE", handler_value);
|
|
|
|
g_value_set_enum (return_accu, handler_value);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the accumulated value is initiated to 0 by GLib. if current handler value is
|
|
|
|
* bigger then use that instead
|
|
|
|
*
|
|
|
|
* FIXME: Should we prioritize the 2xx codes in a smarter way?
|
|
|
|
* Like, "201 Created" > "250 Low On Storage Space" > "200 OK"?
|
|
|
|
*/
|
|
|
|
if (handler_value > accumulated_value)
|
|
|
|
g_value_set_enum (return_accu, handler_value);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
static gboolean
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_teardown_request (GstRTSPClient * client, GstRTSPContext * ctx)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2013-11-07 12:22:09 +00:00
|
|
|
GstRTSPClientClass *klass;
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPSession *session;
|
2013-07-02 09:58:02 +00:00
|
|
|
GstRTSPSessionMedia *sessmedia;
|
2019-10-16 13:20:54 +00:00
|
|
|
GstRTSPMedia *media;
|
2009-01-29 12:31:27 +00:00
|
|
|
GstRTSPStatusCode code;
|
2013-10-04 04:29:30 +00:00
|
|
|
gchar *path;
|
2013-07-03 10:37:48 +00:00
|
|
|
gint matched;
|
2014-07-01 10:13:47 +00:00
|
|
|
gboolean keep_session;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2013-09-17 09:41:57 +00:00
|
|
|
if (!ctx->session)
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_session;
|
|
|
|
|
2013-09-17 09:41:57 +00:00
|
|
|
session = ctx->session;
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
if (!ctx->uri)
|
2013-06-20 09:17:29 +00:00
|
|
|
goto no_uri;
|
|
|
|
|
2013-11-07 12:22:09 +00:00
|
|
|
klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
|
|
|
path = klass->make_path_from_uri (client, ctx->uri);
|
2013-07-03 10:37:48 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* get a handle to the configuration of the media in the session */
|
2013-07-03 10:37:48 +00:00
|
|
|
sessmedia = gst_rtsp_session_get_media (session, path, &matched);
|
2013-07-02 09:58:02 +00:00
|
|
|
if (!sessmedia)
|
2009-01-08 15:28:24 +00:00
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-03 14:15:04 +00:00
|
|
|
/* only aggregate control for now.. */
|
|
|
|
if (path[matched] != '\0')
|
|
|
|
goto no_aggregate;
|
|
|
|
|
2013-10-04 04:29:30 +00:00
|
|
|
g_free (path);
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->sessmedia = sessmedia;
|
2011-01-12 12:16:08 +00:00
|
|
|
|
2019-10-16 13:20:54 +00:00
|
|
|
media = gst_rtsp_session_media_get_media (sessmedia);
|
|
|
|
g_object_ref (media);
|
|
|
|
gst_rtsp_media_lock (media);
|
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_TEARDOWN_REQUEST],
|
|
|
|
0, ctx, &sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
|
|
|
|
2013-04-15 10:21:54 +00:00
|
|
|
/* we emit the signal before closing the connection */
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_TEARDOWN_REQUEST],
|
2013-07-22 12:25:04 +00:00
|
|
|
0, ctx);
|
2013-04-15 10:21:54 +00:00
|
|
|
|
2013-07-02 09:58:02 +00:00
|
|
|
gst_rtsp_session_media_set_state (sessmedia, GST_STATE_NULL);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-04 16:00:42 +00:00
|
|
|
/* unmanage the media in the session, returns false if all media session
|
|
|
|
* are torn down. */
|
2014-07-01 10:13:47 +00:00
|
|
|
keep_session = gst_rtsp_session_release_media (session, sessmedia);
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* construct the response now */
|
|
|
|
code = GST_RTSP_STS_OK;
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_init_response (ctx->response, code,
|
|
|
|
gst_rtsp_status_as_text (code), ctx->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
send_message (client, ctx, ctx->response, TRUE);
|
2009-02-13 11:57:45 +00:00
|
|
|
|
2014-07-01 10:13:47 +00:00
|
|
|
if (!keep_session) {
|
|
|
|
/* remove the session */
|
|
|
|
gst_rtsp_session_pool_remove (priv->session_pool, session);
|
|
|
|
}
|
|
|
|
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-29 12:31:27 +00:00
|
|
|
no_session:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no session", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-06-20 09:17:29 +00:00
|
|
|
no_uri:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no uri supplied", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2013-06-20 09:17:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-08 15:28:24 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no media for uri", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
2013-10-04 04:29:30 +00:00
|
|
|
g_free (path);
|
2009-01-08 15:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-07-03 14:15:04 +00:00
|
|
|
no_aggregate:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no aggregate path %s", client, path);
|
|
|
|
send_generic_response (client,
|
2013-07-22 12:25:04 +00:00
|
|
|
GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
|
2013-10-04 04:29:30 +00:00
|
|
|
g_free (path);
|
2013-07-03 14:15:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-08-24 09:39:13 +00:00
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2016-08-24 09:39:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2013-06-12 10:23:56 +00:00
|
|
|
static GstRTSPResult
|
2013-07-22 12:25:04 +00:00
|
|
|
default_params_set (GstRTSPClient * client, GstRTSPContext * ctx)
|
2013-06-12 10:23:56 +00:00
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
res = gst_rtsp_params_set (client, ctx);
|
2013-06-12 10:23:56 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPResult
|
2013-07-22 12:25:04 +00:00
|
|
|
default_params_get (GstRTSPClient * client, GstRTSPContext * ctx)
|
2013-06-12 10:23:56 +00:00
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
res = gst_rtsp_params_get (client, ctx);
|
2013-06-12 10:23:56 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
static gboolean
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_get_param_request (GstRTSPClient * client, GstRTSPContext * ctx)
|
2009-06-09 22:01:07 +00:00
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
|
|
|
|
|
|
|
g_signal_emit (client,
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_GET_PARAMETER_REQUEST], 0, ctx,
|
|
|
|
&sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
2009-06-09 22:01:07 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
res = gst_rtsp_message_get_body (ctx->request, &data, &size);
|
2009-06-09 22:01:07 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
2017-01-19 12:57:19 +00:00
|
|
|
if (size == 0 || !data || strlen ((char *) data) == 0) {
|
2017-04-22 12:26:07 +00:00
|
|
|
if (ctx->request->type_data.request.version >= GST_RTSP_VERSION_2_0) {
|
|
|
|
GST_ERROR_OBJECT (client, "Using PLAY request for keep-alive is forbidden"
|
|
|
|
" in RTSP 2.0");
|
|
|
|
goto bad_request;
|
|
|
|
}
|
|
|
|
|
2017-01-19 12:57:19 +00:00
|
|
|
/* no body (or only '\0'), keep-alive request */
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_OK, ctx);
|
2009-06-09 22:01:07 +00:00
|
|
|
} else {
|
|
|
|
/* there is a body, handle the params */
|
2013-07-22 12:25:04 +00:00
|
|
|
res = GST_RTSP_CLIENT_GET_CLASS (client)->params_get (client, ctx);
|
2009-06-09 22:01:07 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
2009-06-09 22:01:07 +00:00
|
|
|
}
|
2012-09-03 17:48:14 +00:00
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_GET_PARAMETER_REQUEST],
|
2013-07-22 12:25:04 +00:00
|
|
|
0, ctx);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2016-08-24 09:39:13 +00:00
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-06-09 22:01:07 +00:00
|
|
|
bad_request:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: bad request", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2009-06-09 22:01:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_set_param_request (GstRTSPClient * client, GstRTSPContext * ctx)
|
2009-06-09 22:01:07 +00:00
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
|
|
|
|
|
|
|
g_signal_emit (client,
|
|
|
|
gst_rtsp_client_signals[SIGNAL_PRE_SET_PARAMETER_REQUEST], 0, ctx,
|
|
|
|
&sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
2009-06-09 22:01:07 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
res = gst_rtsp_message_get_body (ctx->request, &data, &size);
|
2009-06-09 22:01:07 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
2017-01-19 12:57:19 +00:00
|
|
|
if (size == 0 || !data || strlen ((char *) data) == 0) {
|
|
|
|
/* no body (or only '\0'), keep-alive request */
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_OK, ctx);
|
2009-06-09 22:01:07 +00:00
|
|
|
} else {
|
|
|
|
/* there is a body, handle the params */
|
2013-07-22 12:25:04 +00:00
|
|
|
res = GST_RTSP_CLIENT_GET_CLASS (client)->params_set (client, ctx);
|
2009-06-09 22:01:07 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto bad_request;
|
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
2009-06-09 22:01:07 +00:00
|
|
|
}
|
2012-09-03 17:48:14 +00:00
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SET_PARAMETER_REQUEST],
|
2013-07-22 12:25:04 +00:00
|
|
|
0, ctx);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2016-08-24 09:39:13 +00:00
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-06-09 22:01:07 +00:00
|
|
|
bad_request:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: bad request", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2009-06-09 22:01:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static gboolean
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_pause_request (GstRTSPClient * client, GstRTSPContext * ctx)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPSession *session;
|
2013-11-07 12:22:09 +00:00
|
|
|
GstRTSPClientClass *klass;
|
2013-07-02 09:58:02 +00:00
|
|
|
GstRTSPSessionMedia *sessmedia;
|
2015-12-30 16:39:05 +00:00
|
|
|
GstRTSPMedia *media;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPStatusCode code;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPState rtspstate;
|
2013-10-04 04:29:30 +00:00
|
|
|
gchar *path;
|
2013-07-03 10:37:48 +00:00
|
|
|
gint matched;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
2015-12-30 16:39:05 +00:00
|
|
|
guint i, n;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
if (!(session = ctx->session))
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_session;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
if (!ctx->uri)
|
2013-06-20 09:17:29 +00:00
|
|
|
goto no_uri;
|
|
|
|
|
2013-11-07 12:22:09 +00:00
|
|
|
klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
|
|
|
path = klass->make_path_from_uri (client, ctx->uri);
|
2013-07-03 10:37:48 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* get a handle to the configuration of the media in the session */
|
2013-07-03 10:37:48 +00:00
|
|
|
sessmedia = gst_rtsp_session_get_media (session, path, &matched);
|
2013-07-02 09:58:02 +00:00
|
|
|
if (!sessmedia)
|
2009-01-08 15:28:24 +00:00
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-03 14:15:04 +00:00
|
|
|
if (path[matched] != '\0')
|
|
|
|
goto no_aggregate;
|
|
|
|
|
2013-10-04 04:29:30 +00:00
|
|
|
g_free (path);
|
|
|
|
|
2015-12-30 16:39:05 +00:00
|
|
|
media = gst_rtsp_session_media_get_media (sessmedia);
|
2019-10-16 13:20:54 +00:00
|
|
|
g_object_ref (media);
|
|
|
|
gst_rtsp_media_lock (media);
|
2015-12-30 16:39:05 +00:00
|
|
|
n = gst_rtsp_media_n_streams (media);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
GstRTSPStream *stream = gst_rtsp_media_get_stream (media, i);
|
|
|
|
|
|
|
|
if (gst_rtsp_stream_get_publish_clock_mode (stream) ==
|
|
|
|
GST_RTSP_PUBLISH_CLOCK_MODE_CLOCK_AND_OFFSET)
|
|
|
|
goto not_supported;
|
|
|
|
}
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->sessmedia = sessmedia;
|
2011-01-12 12:16:08 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_PAUSE_REQUEST], 0,
|
|
|
|
ctx, &sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
|
|
|
|
2013-07-02 09:58:02 +00:00
|
|
|
rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
|
2009-02-03 18:32:38 +00:00
|
|
|
/* the session state must be playing or recording */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (rtspstate != GST_RTSP_STATE_PLAYING &&
|
|
|
|
rtspstate != GST_RTSP_STATE_RECORDING)
|
2009-02-03 18:32:38 +00:00
|
|
|
goto invalid_state;
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* then pause sending */
|
2013-07-02 09:58:02 +00:00
|
|
|
gst_rtsp_session_media_set_state (sessmedia, GST_STATE_PAUSED);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* construct the response now */
|
|
|
|
code = GST_RTSP_STS_OK;
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_init_response (ctx->response, code,
|
|
|
|
gst_rtsp_status_as_text (code), ctx->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* the state is now READY */
|
2013-07-02 09:58:02 +00:00
|
|
|
gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_READY);
|
2009-02-03 18:32:38 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PAUSE_REQUEST], 0, ctx);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-29 12:31:27 +00:00
|
|
|
no_session:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2017-08-14 18:04:23 +00:00
|
|
|
GST_ERROR ("client %p: no session", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-06-20 09:17:29 +00:00
|
|
|
no_uri:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no uri supplied", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2013-06-20 09:17:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-08 15:28:24 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no media for uri", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
2013-10-04 04:29:30 +00:00
|
|
|
g_free (path);
|
2009-01-08 15:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-07-03 14:15:04 +00:00
|
|
|
no_aggregate:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no aggregate path %s", client, path);
|
|
|
|
send_generic_response (client,
|
2013-07-22 12:25:04 +00:00
|
|
|
GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
|
2013-10-04 04:29:30 +00:00
|
|
|
g_free (path);
|
2013-07-03 14:15:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-08-24 09:39:13 +00:00
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2016-08-24 09:39:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-02-03 18:32:38 +00:00
|
|
|
invalid_state:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: not PLAYING or RECORDING", client);
|
2009-05-26 17:01:10 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2009-02-03 18:32:38 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-12-30 16:39:05 +00:00
|
|
|
not_supported:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pausing not supported", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2015-12-30 16:39:05 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 12:39:44 +00:00
|
|
|
/* convert @url and @path to a URL used as a content base for the factory
|
|
|
|
* located at @path */
|
|
|
|
static gchar *
|
2014-02-09 09:45:28 +00:00
|
|
|
make_base_url (GstRTSPClient * client, GstRTSPUrl * url, const gchar * path)
|
2013-09-17 12:39:44 +00:00
|
|
|
{
|
|
|
|
GstRTSPUrl tmp;
|
2014-02-09 09:45:28 +00:00
|
|
|
gchar *result;
|
|
|
|
const gchar *trail;
|
2013-09-17 12:39:44 +00:00
|
|
|
|
|
|
|
/* check for trailing '/' and append one */
|
|
|
|
trail = (path[strlen (path) - 1] != '/' ? "/" : "");
|
|
|
|
|
|
|
|
tmp = *url;
|
|
|
|
tmp.user = NULL;
|
|
|
|
tmp.passwd = NULL;
|
|
|
|
tmp.abspath = g_strdup_printf ("%s%s", path, trail);
|
|
|
|
tmp.query = NULL;
|
|
|
|
result = gst_rtsp_url_get_request_uri (&tmp);
|
|
|
|
g_free (tmp.abspath);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-10-12 06:53:04 +00:00
|
|
|
/* Check if the given header of type double is present and, if so,
|
|
|
|
* put it's value in the supplied variable.
|
|
|
|
*/
|
|
|
|
static GstRTSPStatusCode
|
|
|
|
parse_header_value_double (GstRTSPClient * client, GstRTSPContext * ctx,
|
|
|
|
GstRTSPHeaderField header, gboolean * present, gdouble * value)
|
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
gchar *str;
|
|
|
|
gchar *end;
|
|
|
|
|
|
|
|
res = gst_rtsp_message_get_header (ctx->request, header, &str, 0);
|
|
|
|
if (res == GST_RTSP_OK) {
|
|
|
|
*value = g_ascii_strtod (str, &end);
|
|
|
|
if (end == str)
|
|
|
|
goto parse_header_failed;
|
|
|
|
|
|
|
|
GST_DEBUG ("client %p: got '%s', value %f", client,
|
|
|
|
gst_rtsp_header_as_text (header), *value);
|
|
|
|
*present = TRUE;
|
|
|
|
} else {
|
|
|
|
*present = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_RTSP_STS_OK;
|
|
|
|
|
|
|
|
parse_header_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: failed parsing '%s' header", client,
|
|
|
|
gst_rtsp_header_as_text (header));
|
|
|
|
return GST_RTSP_STS_BAD_REQUEST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse scale and speed headers, if present, and set the rate to
|
|
|
|
* (rate * scale * speed) */
|
|
|
|
static GstRTSPStatusCode
|
|
|
|
parse_scale_and_speed (GstRTSPClient * client, GstRTSPContext * ctx,
|
2018-11-06 23:33:01 +00:00
|
|
|
gboolean * scale_present, gboolean * speed_present, gdouble * rate,
|
|
|
|
GstSeekFlags * flags)
|
2018-10-12 06:53:04 +00:00
|
|
|
{
|
|
|
|
gdouble scale = 1.0;
|
|
|
|
gdouble speed = 1.0;
|
|
|
|
GstRTSPStatusCode status;
|
|
|
|
|
|
|
|
GST_DEBUG ("got rate %f", *rate);
|
|
|
|
|
|
|
|
status = parse_header_value_double (client, ctx, GST_RTSP_HDR_SCALE,
|
|
|
|
scale_present, &scale);
|
|
|
|
if (status != GST_RTSP_STS_OK)
|
|
|
|
return status;
|
|
|
|
|
2018-11-06 23:32:29 +00:00
|
|
|
if (*scale_present) {
|
2018-10-12 06:53:04 +00:00
|
|
|
GST_DEBUG ("got Scale %f", scale);
|
|
|
|
if (scale == 0)
|
|
|
|
goto bad_scale_value;
|
|
|
|
*rate *= scale;
|
2018-11-06 23:33:01 +00:00
|
|
|
|
|
|
|
if (ABS (scale) != 1.0)
|
|
|
|
*flags |= GST_SEEK_FLAG_TRICKMODE;
|
2018-10-12 06:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("rate after parsing Scale %f", *rate);
|
|
|
|
|
|
|
|
status = parse_header_value_double (client, ctx, GST_RTSP_HDR_SPEED,
|
|
|
|
speed_present, &speed);
|
|
|
|
if (status != GST_RTSP_STS_OK)
|
|
|
|
return status;
|
|
|
|
|
2018-11-06 23:32:29 +00:00
|
|
|
if (*speed_present) {
|
2018-10-12 06:53:04 +00:00
|
|
|
GST_DEBUG ("got Speed %f", speed);
|
|
|
|
if (speed <= 0)
|
|
|
|
goto bad_speed_value;
|
|
|
|
*rate *= speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("rate after parsing Speed %f", *rate);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
bad_scale_value:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: bad 'Scale' header value (%f)", client, scale);
|
|
|
|
return GST_RTSP_STS_BAD_REQUEST;
|
|
|
|
}
|
|
|
|
bad_speed_value:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: bad 'Speed' header value (%f)", client, speed);
|
|
|
|
return GST_RTSP_STS_BAD_REQUEST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-01 16:51:49 +00:00
|
|
|
static GstRTSPStatusCode
|
|
|
|
setup_play_mode (GstRTSPClient * client, GstRTSPContext * ctx,
|
2018-10-12 06:53:04 +00:00
|
|
|
GstRTSPRangeUnit * unit, gboolean * scale_present, gboolean * speed_present)
|
2018-10-01 16:51:49 +00:00
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
GstRTSPResult res;
|
|
|
|
GstRTSPTimeRange *range = NULL;
|
|
|
|
gdouble rate = 1.0;
|
|
|
|
GstSeekFlags flags = GST_SEEK_FLAG_NONE;
|
|
|
|
GstRTSPClientClass *klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
2018-10-12 06:53:04 +00:00
|
|
|
GstRTSPStatusCode rtsp_status_code;
|
2019-04-04 22:48:07 +00:00
|
|
|
GstClockTime trickmode_interval = 0;
|
|
|
|
gboolean enable_rate_control = TRUE;
|
2018-10-01 16:51:49 +00:00
|
|
|
|
|
|
|
/* parse the range header if we have one */
|
|
|
|
res = gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_RANGE, &str, 0);
|
|
|
|
if (res == GST_RTSP_OK) {
|
|
|
|
gchar *seek_style = NULL;
|
|
|
|
|
|
|
|
res = gst_rtsp_range_parse (str, &range);
|
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
goto parse_range_failed;
|
|
|
|
|
|
|
|
*unit = range->unit;
|
|
|
|
|
|
|
|
/* parse seek style header, if present */
|
|
|
|
res = gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_SEEK_STYLE,
|
|
|
|
&seek_style, 0);
|
|
|
|
|
|
|
|
if (res == GST_RTSP_OK) {
|
|
|
|
if (g_strcmp0 (seek_style, "RAP") == 0)
|
|
|
|
flags = GST_SEEK_FLAG_ACCURATE;
|
|
|
|
else if (g_strcmp0 (seek_style, "CoRAP") == 0)
|
|
|
|
flags = GST_SEEK_FLAG_KEY_UNIT;
|
|
|
|
else if (g_strcmp0 (seek_style, "First-Prior") == 0)
|
|
|
|
flags = GST_SEEK_FLAG_KEY_UNIT & GST_SEEK_FLAG_SNAP_BEFORE;
|
|
|
|
else if (g_strcmp0 (seek_style, "Next") == 0)
|
|
|
|
flags = GST_SEEK_FLAG_KEY_UNIT & GST_SEEK_FLAG_SNAP_AFTER;
|
|
|
|
else
|
|
|
|
GST_FIXME_OBJECT (client, "Add support for seek style %s", seek_style);
|
2019-07-27 03:14:28 +00:00
|
|
|
} else if (range->min.type == GST_RTSP_TIME_END) {
|
|
|
|
flags = GST_SEEK_FLAG_ACCURATE;
|
|
|
|
} else {
|
|
|
|
flags = GST_SEEK_FLAG_KEY_UNIT;
|
2018-10-01 16:51:49 +00:00
|
|
|
}
|
2019-07-27 03:14:28 +00:00
|
|
|
} else {
|
|
|
|
flags = GST_SEEK_FLAG_ACCURATE;
|
2018-10-01 16:51:49 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 06:53:04 +00:00
|
|
|
/* check for scale and/or speed headers
|
|
|
|
* we will set the seek rate to (speed * scale) and let the media decide
|
|
|
|
* the resulting scale and speed. in the response we will use rate and applied
|
|
|
|
* rate from the resulting segment as values for the speed and scale headers
|
|
|
|
* respectively */
|
|
|
|
rtsp_status_code = parse_scale_and_speed (client, ctx, scale_present,
|
2018-11-06 23:33:01 +00:00
|
|
|
speed_present, &rate, &flags);
|
2018-10-12 06:53:04 +00:00
|
|
|
if (rtsp_status_code != GST_RTSP_STS_OK)
|
|
|
|
goto scale_speed_failed;
|
|
|
|
|
2018-10-01 16:51:49 +00:00
|
|
|
/* give the application a chance to tweak range, flags, or rate */
|
|
|
|
if (klass->adjust_play_mode != NULL) {
|
2018-10-12 06:53:04 +00:00
|
|
|
rtsp_status_code =
|
2019-04-04 22:48:07 +00:00
|
|
|
klass->adjust_play_mode (client, ctx, &range, &flags, &rate,
|
|
|
|
&trickmode_interval, &enable_rate_control);
|
2018-10-12 06:53:04 +00:00
|
|
|
if (rtsp_status_code != GST_RTSP_STS_OK)
|
2018-10-01 16:51:49 +00:00
|
|
|
goto adjust_play_mode_failed;
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:48:07 +00:00
|
|
|
gst_rtsp_media_set_rate_control (ctx->media, enable_rate_control);
|
|
|
|
|
2018-10-01 16:51:49 +00:00
|
|
|
/* now do the seek with the seek options */
|
2019-04-04 22:48:07 +00:00
|
|
|
gst_rtsp_media_seek_trickmode (ctx->media, range, flags, rate,
|
|
|
|
trickmode_interval);
|
2018-10-01 16:51:49 +00:00
|
|
|
if (range != NULL)
|
|
|
|
gst_rtsp_range_free (range);
|
|
|
|
|
|
|
|
if (gst_rtsp_media_get_status (ctx->media) == GST_RTSP_MEDIA_STATUS_ERROR)
|
|
|
|
goto seek_failed;
|
|
|
|
|
|
|
|
return GST_RTSP_STS_OK;
|
|
|
|
|
|
|
|
parse_range_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: failed parsing range header", client);
|
|
|
|
return GST_RTSP_STS_BAD_REQUEST;
|
|
|
|
}
|
2018-10-12 06:53:04 +00:00
|
|
|
scale_speed_failed:
|
|
|
|
{
|
|
|
|
if (range != NULL)
|
|
|
|
gst_rtsp_range_free (range);
|
|
|
|
GST_ERROR ("client %p: failed parsing Scale or Speed headers", client);
|
|
|
|
return rtsp_status_code;
|
|
|
|
}
|
2018-10-01 16:51:49 +00:00
|
|
|
adjust_play_mode_failed:
|
|
|
|
{
|
2018-10-12 06:53:04 +00:00
|
|
|
GST_ERROR ("client %p: sub class returned bad code (%d)", client,
|
|
|
|
rtsp_status_code);
|
2018-10-01 16:51:49 +00:00
|
|
|
if (range != NULL)
|
|
|
|
gst_rtsp_range_free (range);
|
2018-10-12 06:53:04 +00:00
|
|
|
return rtsp_status_code;
|
2018-10-01 16:51:49 +00:00
|
|
|
}
|
|
|
|
seek_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: seek failed", client);
|
|
|
|
return GST_RTSP_STS_SERVICE_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static gboolean
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPSession *session;
|
2013-11-07 12:22:09 +00:00
|
|
|
GstRTSPClientClass *klass;
|
2013-07-02 09:58:02 +00:00
|
|
|
GstRTSPSessionMedia *sessmedia;
|
|
|
|
GstRTSPMedia *media;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPStatusCode code;
|
2013-09-17 12:39:44 +00:00
|
|
|
GstRTSPUrl *uri;
|
2013-11-28 16:47:18 +00:00
|
|
|
gchar *str;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPState rtspstate;
|
2013-02-22 19:17:29 +00:00
|
|
|
GstRTSPRangeUnit unit = GST_RTSP_RANGE_NPT;
|
2019-09-25 09:14:08 +00:00
|
|
|
gchar *path, *rtpinfo = NULL;
|
2013-07-03 10:37:48 +00:00
|
|
|
gint matched;
|
2017-04-22 12:26:07 +00:00
|
|
|
gchar *seek_style = NULL;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
2017-10-17 08:44:33 +00:00
|
|
|
GPtrArray *transports;
|
2018-10-12 06:53:04 +00:00
|
|
|
gboolean scale_present;
|
|
|
|
gboolean speed_present;
|
|
|
|
gdouble rate;
|
|
|
|
gdouble applied_rate;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
if (!(session = ctx->session))
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_session;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-09-17 12:39:44 +00:00
|
|
|
if (!(uri = ctx->uri))
|
2013-06-20 09:17:29 +00:00
|
|
|
goto no_uri;
|
|
|
|
|
2013-11-07 12:22:09 +00:00
|
|
|
klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
|
|
|
path = klass->make_path_from_uri (client, uri);
|
2013-07-03 10:37:48 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* get a handle to the configuration of the media in the session */
|
2013-07-03 10:37:48 +00:00
|
|
|
sessmedia = gst_rtsp_session_get_media (session, path, &matched);
|
2013-07-02 09:58:02 +00:00
|
|
|
if (!sessmedia)
|
2009-01-08 15:28:24 +00:00
|
|
|
goto not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-03 14:15:04 +00:00
|
|
|
if (path[matched] != '\0')
|
|
|
|
goto no_aggregate;
|
|
|
|
|
2013-12-26 14:41:14 +00:00
|
|
|
g_free (path);
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->sessmedia = sessmedia;
|
|
|
|
ctx->media = media = gst_rtsp_session_media_get_media (sessmedia);
|
2011-01-12 12:16:08 +00:00
|
|
|
|
2019-10-16 13:20:54 +00:00
|
|
|
g_object_ref (media);
|
|
|
|
gst_rtsp_media_lock (media);
|
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_PLAY_REQUEST], 0,
|
|
|
|
ctx, &sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
|
|
|
|
2015-01-28 17:54:01 +00:00
|
|
|
if (!(gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_PLAY))
|
|
|
|
goto unsupported_mode;
|
2015-01-09 11:40:47 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* the session state must be playing or ready */
|
2013-07-02 09:58:02 +00:00
|
|
|
rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
|
2012-11-29 10:11:05 +00:00
|
|
|
if (rtspstate != GST_RTSP_STATE_PLAYING && rtspstate != GST_RTSP_STATE_READY)
|
2009-02-03 18:32:38 +00:00
|
|
|
goto invalid_state;
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
/* update the pipeline */
|
|
|
|
transports = gst_rtsp_session_media_get_transports (sessmedia);
|
|
|
|
if (!gst_rtsp_media_complete_pipeline (media, transports)) {
|
|
|
|
g_ptr_array_unref (transports);
|
|
|
|
goto pipeline_error;
|
|
|
|
}
|
|
|
|
g_ptr_array_unref (transports);
|
|
|
|
|
2013-11-28 13:14:35 +00:00
|
|
|
/* in play we first unsuspend, media could be suspended from SDP or PAUSED */
|
|
|
|
if (!gst_rtsp_media_unsuspend (media))
|
|
|
|
goto unsuspend_failed;
|
|
|
|
|
2018-10-12 06:53:04 +00:00
|
|
|
code = setup_play_mode (client, ctx, &unit, &scale_present, &speed_present);
|
2018-10-01 16:51:49 +00:00
|
|
|
if (code != GST_RTSP_STS_OK)
|
|
|
|
goto invalid_mode;
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2013-12-26 14:41:14 +00:00
|
|
|
/* grab RTPInfo from the media now */
|
2019-09-30 13:13:15 +00:00
|
|
|
if (gst_rtsp_media_has_completed_sender (media) &&
|
2019-09-25 09:14:08 +00:00
|
|
|
!(rtpinfo = gst_rtsp_session_media_get_rtpinfo (sessmedia)))
|
2019-08-30 12:00:52 +00:00
|
|
|
goto rtp_info_error;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* construct the response now */
|
|
|
|
code = GST_RTSP_STS_OK;
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_init_response (ctx->response, code,
|
|
|
|
gst_rtsp_status_as_text (code), ctx->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* add the RTP-Info header */
|
2019-09-25 09:14:08 +00:00
|
|
|
if (rtpinfo)
|
|
|
|
gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_RTP_INFO,
|
|
|
|
rtpinfo);
|
2017-04-22 12:26:07 +00:00
|
|
|
if (seek_style)
|
|
|
|
gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_SEEK_STYLE,
|
|
|
|
seek_style);
|
2009-02-04 16:00:42 +00:00
|
|
|
|
|
|
|
/* add the range */
|
2013-07-02 09:58:02 +00:00
|
|
|
str = gst_rtsp_media_get_range_string (media, TRUE, unit);
|
2013-07-11 20:11:55 +00:00
|
|
|
if (str)
|
|
|
|
gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_RANGE, str);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2019-08-21 12:57:25 +00:00
|
|
|
if (gst_rtsp_media_has_completed_sender (media)) {
|
2018-10-12 06:53:04 +00:00
|
|
|
/* the scale and speed headers must always be added if they were present in
|
|
|
|
* the request. however, even if they were not, we still add them if
|
|
|
|
* applied_rate or rate deviate from the "normal", i.e. 1.0 */
|
|
|
|
if (!gst_rtsp_media_get_rates (media, &rate, &applied_rate))
|
|
|
|
goto get_rates_error;
|
|
|
|
g_assert (rate != 0 && applied_rate != 0);
|
|
|
|
|
|
|
|
if (scale_present || applied_rate != 1.0)
|
|
|
|
gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_SCALE,
|
|
|
|
g_strdup_printf ("%1.3f", applied_rate));
|
|
|
|
|
|
|
|
if (speed_present || rate != 1.0)
|
|
|
|
gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_SPEED,
|
|
|
|
g_strdup_printf ("%1.3f", rate));
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:48:07 +00:00
|
|
|
if (klass->adjust_play_response) {
|
|
|
|
code = klass->adjust_play_response (client, ctx);
|
|
|
|
if (code != GST_RTSP_STS_OK)
|
|
|
|
goto adjust_play_response_failed;
|
|
|
|
}
|
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2014-05-01 03:29:54 +00:00
|
|
|
/* start playing after sending the response */
|
2013-07-02 09:58:02 +00:00
|
|
|
gst_rtsp_session_media_set_state (sessmedia, GST_STATE_PLAYING);
|
2009-02-03 18:32:38 +00:00
|
|
|
|
2013-07-02 09:58:02 +00:00
|
|
|
gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_PLAYING);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PLAY_REQUEST], 0, ctx);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-01-29 12:31:27 +00:00
|
|
|
no_session:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no session", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-06-20 09:17:29 +00:00
|
|
|
no_uri:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no uri supplied", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2013-06-20 09:17:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-08 15:28:24 +00:00
|
|
|
not_found:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: media not found", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
2009-01-08 15:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-07-03 14:15:04 +00:00
|
|
|
no_aggregate:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no aggregate path %s", client, path);
|
|
|
|
send_generic_response (client,
|
2013-07-22 12:25:04 +00:00
|
|
|
GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
|
2013-10-04 04:29:30 +00:00
|
|
|
g_free (path);
|
2013-07-03 14:15:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-08-24 09:39:13 +00:00
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2016-08-24 09:39:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-02-03 18:32:38 +00:00
|
|
|
invalid_state:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: not PLAYING or READY", client);
|
2009-05-26 17:01:10 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2009-02-03 18:32:38 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
pipeline_error:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: failed to configure the pipeline", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
|
|
|
|
ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2017-10-17 08:44:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-11-28 13:14:35 +00:00
|
|
|
unsuspend_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: unsuspend failed", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2013-11-28 13:14:35 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-10-01 16:51:49 +00:00
|
|
|
invalid_mode:
|
2015-02-12 14:48:46 +00:00
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: seek failed", client);
|
2018-10-01 16:51:49 +00:00
|
|
|
send_generic_response (client, code, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2015-02-12 14:48:46 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-01-28 17:54:01 +00:00
|
|
|
unsupported_mode:
|
2015-01-09 11:40:47 +00:00
|
|
|
{
|
2015-01-28 17:54:01 +00:00
|
|
|
GST_ERROR ("client %p: media does not support PLAY", client);
|
2015-01-09 11:40:47 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_ALLOWED, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2015-01-09 11:40:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-10-12 06:53:04 +00:00
|
|
|
get_rates_error:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: failed obtaining rate and applied_rate", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_INTERNAL_SERVER_ERROR, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2018-10-12 06:53:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2019-04-04 22:48:07 +00:00
|
|
|
adjust_play_response_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: failed to adjust play response", client);
|
|
|
|
send_generic_response (client, code, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2019-04-04 22:48:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2019-08-30 12:00:52 +00:00
|
|
|
rtp_info_error:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: failed to add RTP-Info", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_INTERNAL_SERVER_ERROR, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2019-08-30 12:00:52 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
static void
|
|
|
|
do_keepalive (GstRTSPSession * session)
|
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("keep session %p alive", session);
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_session_touch (session);
|
|
|
|
}
|
|
|
|
|
2012-10-27 19:26:55 +00:00
|
|
|
/* parse @transport and return a valid transport in @tr. only transports
|
2014-01-07 11:28:47 +00:00
|
|
|
* supported by @stream are returned. Returns FALSE if no valid transport
|
2012-10-27 19:26:55 +00:00
|
|
|
* was found. */
|
|
|
|
static gboolean
|
2014-01-07 11:28:47 +00:00
|
|
|
parse_transport (const char *transport, GstRTSPStream * stream,
|
2012-10-27 19:26:55 +00:00
|
|
|
GstRTSPTransport * tr)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gboolean res;
|
|
|
|
gchar **transports;
|
|
|
|
|
|
|
|
res = FALSE;
|
|
|
|
gst_rtsp_transport_init (tr);
|
|
|
|
|
2012-11-15 15:15:20 +00:00
|
|
|
GST_DEBUG ("parsing transports %s", transport);
|
2012-10-27 19:26:55 +00:00
|
|
|
|
|
|
|
transports = g_strsplit (transport, ",", 0);
|
|
|
|
|
|
|
|
/* loop through the transports, try to parse */
|
|
|
|
for (i = 0; transports[i]; i++) {
|
2016-01-08 23:12:14 +00:00
|
|
|
g_strstrip (transports[i]);
|
2012-10-27 19:26:55 +00:00
|
|
|
res = gst_rtsp_transport_parse (transports[i], tr);
|
|
|
|
if (res != GST_RTSP_OK) {
|
|
|
|
/* no valid transport, search some more */
|
|
|
|
GST_WARNING ("could not parse transport %s", transports[i]);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2014-01-07 11:28:47 +00:00
|
|
|
/* we have a transport, see if it's supported */
|
|
|
|
if (!gst_rtsp_stream_is_transport_supported (stream, tr)) {
|
2012-10-27 19:26:55 +00:00
|
|
|
GST_WARNING ("unsupported transport %s", transports[i]);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have a valid transport */
|
|
|
|
GST_INFO ("found valid transport %s", transports[i]);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
next:
|
|
|
|
gst_rtsp_transport_init (tr);
|
|
|
|
}
|
|
|
|
g_strfreev (transports);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:26:30 +00:00
|
|
|
static gboolean
|
2013-12-18 14:57:03 +00:00
|
|
|
default_configure_client_media (GstRTSPClient * client, GstRTSPMedia * media,
|
|
|
|
GstRTSPStream * stream, GstRTSPContext * ctx)
|
2012-07-03 11:26:30 +00:00
|
|
|
{
|
2013-12-18 14:57:03 +00:00
|
|
|
GstRTSPMessage *request = ctx->request;
|
2012-07-03 11:26:30 +00:00
|
|
|
gchar *blocksize_str;
|
|
|
|
|
2018-06-05 06:44:44 +00:00
|
|
|
if (!gst_rtsp_stream_is_sender (stream))
|
|
|
|
return TRUE;
|
|
|
|
|
2012-07-03 11:26:30 +00:00
|
|
|
if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_BLOCKSIZE,
|
2012-07-10 09:39:58 +00:00
|
|
|
&blocksize_str, 0) == GST_RTSP_OK) {
|
2012-07-03 11:26:30 +00:00
|
|
|
guint64 blocksize;
|
|
|
|
gchar *end;
|
|
|
|
|
|
|
|
blocksize = g_ascii_strtoull (blocksize_str, &end, 10);
|
2013-12-18 14:57:03 +00:00
|
|
|
if (end == blocksize_str)
|
|
|
|
goto parse_failed;
|
|
|
|
|
|
|
|
/* we don't want to change the mtu when this media
|
|
|
|
* can be shared because it impacts other clients */
|
|
|
|
if (gst_rtsp_media_is_shared (media))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (blocksize > G_MAXUINT)
|
|
|
|
blocksize = G_MAXUINT;
|
|
|
|
|
|
|
|
gst_rtsp_stream_set_mtu (stream, blocksize);
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
parse_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (client, "failed to parse blocksize");
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
|
|
|
return FALSE;
|
2012-07-03 11:26:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
static gboolean
|
2013-06-17 14:18:37 +00:00
|
|
|
default_configure_client_transport (GstRTSPClient * client,
|
2013-07-22 12:25:04 +00:00
|
|
|
GstRTSPContext * ctx, GstRTSPTransport * ct)
|
2012-10-27 21:49:24 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* we have a valid transport now, set the destination of the client. */
|
2017-10-17 08:44:33 +00:00
|
|
|
if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST ||
|
|
|
|
ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
|
|
|
|
/* allocate UDP ports */
|
|
|
|
GSocketFamily family;
|
|
|
|
gboolean use_client_settings = FALSE;
|
|
|
|
|
|
|
|
family = priv->is_ipv6 ? G_SOCKET_FAMILY_IPV6 : G_SOCKET_FAMILY_IPV4;
|
rtsp-client: always allocate both IPV4 and IPV6 sockets
multiudpsink does not support setting the socket* properties
after it has started, which meant that rtsp-server could no
longer serve on both IPV4 and IPV6 sockets since the patches
from https://bugzilla.gnome.org/show_bug.cgi?id=757488 were
merged.
When first connecting an IPV6 client then an IPV4 client,
multiudpsink fell back to using the IPV6 socket.
When first connecting an IPV4 client, then an IPV6 client,
multiudpsink errored out, released the IPV4 socket, then
crashed when trying to send a message on NULL nevertheless,
that is however a separate issue.
This could probably be fixed by handling the setting of
sockets in multiudpsink after it has started, that will
however be a much more significant effort.
For now, this commit simply partially reverts the behaviour
of rtsp-stream: it will continue to only create the udpsinks
when needed, as was the case since the patches were merged,
it will however when creating them, always allocate both
sockets and set them on the sink before it starts, as was
the case prior to the patches.
Transport configuration will only error out if the allocation
of UDP sockets fails for the actual client's family, this
also downgrades the GST_ERRORs in alloc_ports_one_family
to GST_WARNINGs, as failing to allocate is no longer
necessarily fatal.
https://bugzilla.gnome.org/show_bug.cgi?id=796875
2018-07-25 17:54:55 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if ((ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) &&
|
|
|
|
gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_TRANSPORT_CLIENT_SETTINGS) &&
|
2018-07-25 13:33:18 +00:00
|
|
|
(ct->destination != NULL)) {
|
|
|
|
|
|
|
|
if (!gst_rtsp_stream_verify_mcast_ttl (ctx->stream, ct->ttl))
|
|
|
|
goto error_ttl;
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
use_client_settings = TRUE;
|
2018-07-25 13:33:18 +00:00
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
|
rtsp-client: always allocate both IPV4 and IPV6 sockets
multiudpsink does not support setting the socket* properties
after it has started, which meant that rtsp-server could no
longer serve on both IPV4 and IPV6 sockets since the patches
from https://bugzilla.gnome.org/show_bug.cgi?id=757488 were
merged.
When first connecting an IPV6 client then an IPV4 client,
multiudpsink fell back to using the IPV6 socket.
When first connecting an IPV4 client, then an IPV6 client,
multiudpsink errored out, released the IPV4 socket, then
crashed when trying to send a message on NULL nevertheless,
that is however a separate issue.
This could probably be fixed by handling the setting of
sockets in multiudpsink after it has started, that will
however be a much more significant effort.
For now, this commit simply partially reverts the behaviour
of rtsp-stream: it will continue to only create the udpsinks
when needed, as was the case since the patches were merged,
it will however when creating them, always allocate both
sockets and set them on the sink before it starts, as was
the case prior to the patches.
Transport configuration will only error out if the allocation
of UDP sockets fails for the actual client's family, this
also downgrades the GST_ERRORs in alloc_ports_one_family
to GST_WARNINGs, as failing to allocate is no longer
necessarily fatal.
https://bugzilla.gnome.org/show_bug.cgi?id=796875
2018-07-25 17:54:55 +00:00
|
|
|
/* We need to allocate the sockets for both families before starting
|
|
|
|
* multiudpsink, otherwise multiudpsink won't accept new clients with
|
|
|
|
* a different family.
|
|
|
|
*/
|
|
|
|
/* FIXME: could be more adequately solved by making it possible
|
|
|
|
* to set a socket on multiudpsink after it has already been started */
|
2018-08-14 11:31:55 +00:00
|
|
|
if (!gst_rtsp_stream_allocate_udp_sockets (ctx->stream,
|
|
|
|
G_SOCKET_FAMILY_IPV4, ct, use_client_settings)
|
|
|
|
&& family == G_SOCKET_FAMILY_IPV4)
|
rtsp-client: always allocate both IPV4 and IPV6 sockets
multiudpsink does not support setting the socket* properties
after it has started, which meant that rtsp-server could no
longer serve on both IPV4 and IPV6 sockets since the patches
from https://bugzilla.gnome.org/show_bug.cgi?id=757488 were
merged.
When first connecting an IPV6 client then an IPV4 client,
multiudpsink fell back to using the IPV6 socket.
When first connecting an IPV4 client, then an IPV6 client,
multiudpsink errored out, released the IPV4 socket, then
crashed when trying to send a message on NULL nevertheless,
that is however a separate issue.
This could probably be fixed by handling the setting of
sockets in multiudpsink after it has started, that will
however be a much more significant effort.
For now, this commit simply partially reverts the behaviour
of rtsp-stream: it will continue to only create the udpsinks
when needed, as was the case since the patches were merged,
it will however when creating them, always allocate both
sockets and set them on the sink before it starts, as was
the case prior to the patches.
Transport configuration will only error out if the allocation
of UDP sockets fails for the actual client's family, this
also downgrades the GST_ERRORs in alloc_ports_one_family
to GST_WARNINGs, as failing to allocate is no longer
necessarily fatal.
https://bugzilla.gnome.org/show_bug.cgi?id=796875
2018-07-25 17:54:55 +00:00
|
|
|
goto error_allocating_ports;
|
|
|
|
|
2018-08-14 11:31:55 +00:00
|
|
|
if (!gst_rtsp_stream_allocate_udp_sockets (ctx->stream,
|
|
|
|
G_SOCKET_FAMILY_IPV6, ct, use_client_settings)
|
|
|
|
&& family == G_SOCKET_FAMILY_IPV6)
|
2017-10-17 08:44:33 +00:00
|
|
|
goto error_allocating_ports;
|
|
|
|
|
|
|
|
if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
|
2018-07-25 13:33:18 +00:00
|
|
|
if (use_client_settings) {
|
|
|
|
/* FIXME: the address has been successfully allocated, however, in
|
|
|
|
* the use_client_settings case we need to verify that the allocated
|
|
|
|
* address is the one requested by the client and if this address is
|
|
|
|
* an allowed destination. Verifying this via the address pool in not
|
|
|
|
* the proper way as the address pool should only be used for choosing
|
|
|
|
* the server-selected address/port pairs. */
|
|
|
|
GSocket *rtp_socket;
|
|
|
|
guint ttl;
|
|
|
|
|
|
|
|
rtp_socket =
|
|
|
|
gst_rtsp_stream_get_rtp_multicast_socket (ctx->stream, family);
|
|
|
|
if (rtp_socket == NULL)
|
|
|
|
goto no_socket;
|
|
|
|
ttl = g_socket_get_multicast_ttl (rtp_socket);
|
|
|
|
g_object_unref (rtp_socket);
|
|
|
|
if (ct->ttl < ttl) {
|
|
|
|
/* use the maximum ttl that is requested by multicast clients */
|
|
|
|
GST_DEBUG ("requested ttl %u, but keeping ttl %u", ct->ttl, ttl);
|
|
|
|
ct->ttl = ttl;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2018-07-24 12:02:40 +00:00
|
|
|
GstRTSPAddress *addr = NULL;
|
2017-10-17 08:44:33 +00:00
|
|
|
|
|
|
|
g_free (ct->destination);
|
|
|
|
addr = gst_rtsp_stream_get_multicast_address (ctx->stream, family);
|
|
|
|
if (addr == NULL)
|
|
|
|
goto no_address;
|
|
|
|
ct->destination = g_strdup (addr->address);
|
|
|
|
ct->port.min = addr->port;
|
|
|
|
ct->port.max = addr->port + addr->n_ports - 1;
|
|
|
|
ct->ttl = addr->ttl;
|
2018-07-24 12:02:40 +00:00
|
|
|
gst_rtsp_address_free (addr);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
2018-07-26 10:01:16 +00:00
|
|
|
|
|
|
|
if (!gst_rtsp_stream_add_multicast_client_address (ctx->stream,
|
|
|
|
ct->destination, ct->port.min, ct->port.max, family))
|
|
|
|
goto error_mcast_transport;
|
|
|
|
|
2013-02-13 23:32:20 +00:00
|
|
|
} else {
|
2017-10-17 08:44:33 +00:00
|
|
|
GstRTSPUrl *url;
|
2012-11-14 16:23:59 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
url = gst_rtsp_connection_get_url (priv->connection);
|
2012-10-27 21:49:24 +00:00
|
|
|
g_free (ct->destination);
|
2017-10-17 08:44:33 +00:00
|
|
|
ct->destination = g_strdup (url->host);
|
2012-10-27 21:49:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GstRTSPUrl *url;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
url = gst_rtsp_connection_get_url (priv->connection);
|
2012-10-27 21:49:24 +00:00
|
|
|
g_free (ct->destination);
|
|
|
|
ct->destination = g_strdup (url->host);
|
|
|
|
|
|
|
|
if (ct->lower_transport & GST_RTSP_LOWER_TRANS_TCP) {
|
2014-05-20 13:57:30 +00:00
|
|
|
GSocket *sock;
|
|
|
|
GSocketAddress *addr;
|
|
|
|
|
|
|
|
sock = gst_rtsp_connection_get_read_socket (priv->connection);
|
|
|
|
if ((addr = g_socket_get_remote_address (sock, NULL))) {
|
|
|
|
/* our read port is the sender port of client */
|
|
|
|
ct->client_port.min =
|
|
|
|
g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr));
|
|
|
|
g_object_unref (addr);
|
|
|
|
}
|
|
|
|
if ((addr = g_socket_get_local_address (sock, NULL))) {
|
|
|
|
ct->server_port.max =
|
|
|
|
g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr));
|
|
|
|
g_object_unref (addr);
|
|
|
|
}
|
|
|
|
sock = gst_rtsp_connection_get_write_socket (priv->connection);
|
|
|
|
if ((addr = g_socket_get_remote_address (sock, NULL))) {
|
|
|
|
/* our write port is the receiver port of client */
|
|
|
|
ct->client_port.max =
|
|
|
|
g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr));
|
|
|
|
g_object_unref (addr);
|
|
|
|
}
|
|
|
|
if ((addr = g_socket_get_local_address (sock, NULL))) {
|
|
|
|
ct->server_port.min =
|
|
|
|
g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr));
|
|
|
|
g_object_unref (addr);
|
|
|
|
}
|
2012-10-27 21:49:24 +00:00
|
|
|
/* check if the client selected channels for TCP */
|
|
|
|
if (ct->interleaved.min == -1 || ct->interleaved.max == -1) {
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_session_media_alloc_channels (ctx->sessmedia,
|
2012-10-27 21:49:24 +00:00
|
|
|
&ct->interleaved);
|
|
|
|
}
|
2018-08-17 07:54:27 +00:00
|
|
|
/* alloc new channels if they are already taken */
|
|
|
|
while (g_hash_table_contains (priv->transports,
|
|
|
|
GINT_TO_POINTER (ct->interleaved.min))
|
|
|
|
|| g_hash_table_contains (priv->transports,
|
|
|
|
GINT_TO_POINTER (ct->interleaved.max))) {
|
|
|
|
gst_rtsp_session_media_alloc_channels (ctx->sessmedia,
|
|
|
|
&ct->interleaved);
|
|
|
|
if (ct->interleaved.max > 255)
|
|
|
|
goto error_allocating_channels;
|
|
|
|
}
|
2012-10-27 21:49:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2012-11-14 16:23:59 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2018-07-25 13:33:18 +00:00
|
|
|
error_ttl:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (client,
|
|
|
|
"Failed to allocate UDP ports: invalid ttl value");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
error_allocating_ports:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (client, "Failed to allocate UDP ports");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-11-14 16:23:59 +00:00
|
|
|
no_address:
|
|
|
|
{
|
2017-10-17 08:44:33 +00:00
|
|
|
GST_ERROR_OBJECT (client, "Failed to acquire address for stream");
|
2012-11-14 16:23:59 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-07-25 13:33:18 +00:00
|
|
|
no_socket:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (client, "Failed to get UDP socket");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-07-26 10:01:16 +00:00
|
|
|
error_mcast_transport:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (client, "Failed to add multicast client transport");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-08-17 07:54:27 +00:00
|
|
|
error_allocating_channels:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (client, "Failed to allocate interleaved channels");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-27 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPTransport *
|
2015-01-09 11:40:47 +00:00
|
|
|
make_server_transport (GstRTSPClient * client, GstRTSPMedia * media,
|
|
|
|
GstRTSPContext * ctx, GstRTSPTransport * ct)
|
2012-10-27 21:49:24 +00:00
|
|
|
{
|
|
|
|
GstRTSPTransport *st;
|
2013-05-30 06:07:48 +00:00
|
|
|
GInetAddress *addr;
|
|
|
|
GSocketFamily family;
|
2012-10-27 21:49:24 +00:00
|
|
|
|
|
|
|
/* prepare the server transport */
|
|
|
|
gst_rtsp_transport_new (&st);
|
|
|
|
|
|
|
|
st->trans = ct->trans;
|
|
|
|
st->profile = ct->profile;
|
|
|
|
st->lower_transport = ct->lower_transport;
|
2015-01-09 11:40:47 +00:00
|
|
|
st->mode_play = ct->mode_play;
|
|
|
|
st->mode_record = ct->mode_record;
|
2012-10-27 21:49:24 +00:00
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
addr = g_inet_address_new_from_string (ct->destination);
|
|
|
|
|
|
|
|
if (!addr) {
|
|
|
|
GST_ERROR ("failed to get inet addr from client destination");
|
|
|
|
family = G_SOCKET_FAMILY_IPV4;
|
|
|
|
} else {
|
|
|
|
family = g_inet_address_get_family (addr);
|
|
|
|
g_object_unref (addr);
|
|
|
|
addr = NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
switch (st->lower_transport) {
|
|
|
|
case GST_RTSP_LOWER_TRANS_UDP:
|
|
|
|
st->client_port = ct->client_port;
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_stream_get_server_port (ctx->stream, &st->server_port, family);
|
2012-10-27 21:49:24 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_LOWER_TRANS_UDP_MCAST:
|
|
|
|
st->port = ct->port;
|
|
|
|
st->destination = g_strdup (ct->destination);
|
|
|
|
st->ttl = ct->ttl;
|
|
|
|
break;
|
|
|
|
case GST_RTSP_LOWER_TRANS_TCP:
|
|
|
|
st->interleaved = ct->interleaved;
|
2014-05-20 13:57:30 +00:00
|
|
|
st->client_port = ct->client_port;
|
|
|
|
st->server_port = ct->server_port;
|
2012-10-27 21:49:24 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-28 17:54:01 +00:00
|
|
|
if ((gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_PLAY))
|
2015-01-09 11:40:47 +00:00
|
|
|
gst_rtsp_stream_get_ssrc (ctx->stream, &st->ssrc);
|
2012-10-27 21:49:24 +00:00
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2016-11-21 15:02:39 +00:00
|
|
|
static gboolean
|
|
|
|
rtsp_ctrl_timeout_cb (gpointer user_data)
|
|
|
|
{
|
|
|
|
gboolean res = G_SOURCE_CONTINUE;
|
|
|
|
GstRTSPClient *client = (GstRTSPClient *) user_data;
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
|
|
|
priv->rtsp_ctrl_timeout_cnt += RTSP_CTRL_CB_INTERVAL;
|
|
|
|
|
|
|
|
if (priv->rtsp_ctrl_timeout_cnt > RTSP_CTRL_TIMEOUT_VALUE) {
|
|
|
|
GST_DEBUG ("rtsp control session timeout id=%u expired, closing client.",
|
|
|
|
priv->rtsp_ctrl_timeout_id);
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->rtsp_ctrl_timeout_id = 0;
|
|
|
|
priv->rtsp_ctrl_timeout_cnt = 0;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
gst_rtsp_client_close (client);
|
|
|
|
|
|
|
|
res = G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rtsp_ctrl_timeout_remove (GstRTSPClientPrivate * priv)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
|
|
|
if (priv->rtsp_ctrl_timeout_id != 0) {
|
|
|
|
g_source_destroy (g_main_context_find_source_by_id (priv->watch_context,
|
|
|
|
priv->rtsp_ctrl_timeout_id));
|
|
|
|
GST_DEBUG ("rtsp control session removed timeout id=%u.",
|
|
|
|
priv->rtsp_ctrl_timeout_id);
|
|
|
|
priv->rtsp_ctrl_timeout_id = 0;
|
|
|
|
priv->rtsp_ctrl_timeout_cnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
2018-03-29 14:12:26 +00:00
|
|
|
static gchar *
|
2018-04-04 07:06:06 +00:00
|
|
|
stream_make_keymgmt (GstRTSPClient * client, const gchar * location,
|
|
|
|
GstRTSPStream * stream)
|
2018-03-29 14:12:26 +00:00
|
|
|
{
|
|
|
|
gchar *base64, *result = NULL;
|
|
|
|
GstMIKEYMessage *mikey_msg;
|
|
|
|
GstCaps *srtcpparams;
|
|
|
|
GstElement *rtcp_encoder;
|
|
|
|
gint srtcp_cipher, srtp_cipher;
|
|
|
|
gint srtcp_auth, srtp_auth;
|
|
|
|
GstBuffer *key;
|
|
|
|
GType ciphertype, authtype;
|
|
|
|
GEnumClass *cipher_enum, *auth_enum;
|
2018-04-04 07:06:06 +00:00
|
|
|
GEnumValue *srtcp_cipher_value, *srtp_cipher_value, *srtcp_auth_value,
|
|
|
|
*srtp_auth_value;
|
2018-03-29 14:12:26 +00:00
|
|
|
|
|
|
|
rtcp_encoder = gst_rtsp_stream_get_srtp_encoder (stream);
|
|
|
|
|
|
|
|
if (!rtcp_encoder)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
ciphertype = g_type_from_name ("GstSrtpCipherType");
|
|
|
|
authtype = g_type_from_name ("GstSrtpAuthType");
|
|
|
|
|
|
|
|
cipher_enum = g_type_class_ref (ciphertype);
|
|
|
|
auth_enum = g_type_class_ref (authtype);
|
|
|
|
|
|
|
|
/* We need to bring the encoder to READY so that it generates its key */
|
|
|
|
gst_element_set_state (rtcp_encoder, GST_STATE_READY);
|
|
|
|
|
2018-04-04 07:06:06 +00:00
|
|
|
g_object_get (rtcp_encoder, "rtcp-cipher", &srtcp_cipher, "rtcp-auth",
|
|
|
|
&srtcp_auth, "rtp-cipher", &srtp_cipher, "rtp-auth", &srtp_auth, "key",
|
|
|
|
&key, NULL);
|
2018-03-29 14:12:26 +00:00
|
|
|
g_object_unref (rtcp_encoder);
|
|
|
|
|
|
|
|
srtcp_cipher_value = g_enum_get_value (cipher_enum, srtcp_cipher);
|
|
|
|
srtp_cipher_value = g_enum_get_value (cipher_enum, srtp_cipher);
|
|
|
|
srtcp_auth_value = g_enum_get_value (auth_enum, srtcp_auth);
|
|
|
|
srtp_auth_value = g_enum_get_value (auth_enum, srtp_auth);
|
|
|
|
|
|
|
|
g_type_class_unref (cipher_enum);
|
|
|
|
g_type_class_unref (auth_enum);
|
|
|
|
|
|
|
|
srtcpparams = gst_caps_new_simple ("application/x-srtcp",
|
|
|
|
"srtcp-cipher", G_TYPE_STRING, srtcp_cipher_value->value_nick,
|
|
|
|
"srtcp-auth", G_TYPE_STRING, srtcp_auth_value->value_nick,
|
|
|
|
"srtp-cipher", G_TYPE_STRING, srtp_cipher_value->value_nick,
|
|
|
|
"srtp-auth", G_TYPE_STRING, srtp_auth_value->value_nick,
|
|
|
|
"srtp-key", GST_TYPE_BUFFER, key, NULL);
|
|
|
|
|
|
|
|
mikey_msg = gst_mikey_message_new_from_caps (srtcpparams);
|
|
|
|
if (mikey_msg) {
|
|
|
|
guint send_ssrc;
|
|
|
|
|
|
|
|
gst_rtsp_stream_get_ssrc (stream, &send_ssrc);
|
|
|
|
gst_mikey_message_add_cs_srtp (mikey_msg, 0, send_ssrc, 0);
|
|
|
|
|
|
|
|
base64 = gst_mikey_message_base64_encode (mikey_msg);
|
|
|
|
gst_mikey_message_unref (mikey_msg);
|
|
|
|
|
|
|
|
if (base64) {
|
|
|
|
result = gst_sdp_make_keymgmt (location, base64);
|
|
|
|
g_free (base64);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static gboolean
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPResult res;
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPUrl *uri;
|
2014-04-03 10:52:51 +00:00
|
|
|
gchar *transport, *keymgmt;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPTransport *ct, *st;
|
|
|
|
GstRTSPStatusCode code;
|
2011-01-12 12:16:08 +00:00
|
|
|
GstRTSPSession *session;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStreamTransport *trans;
|
2013-07-03 13:55:38 +00:00
|
|
|
gchar *trans_str;
|
2012-10-27 21:49:24 +00:00
|
|
|
GstRTSPSessionMedia *sessmedia;
|
|
|
|
GstRTSPMedia *media;
|
|
|
|
GstRTSPStream *stream;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPState rtspstate;
|
2013-06-17 14:18:37 +00:00
|
|
|
GstRTSPClientClass *klass;
|
2015-01-19 12:09:20 +00:00
|
|
|
gchar *path, *control = NULL;
|
2013-07-03 10:37:48 +00:00
|
|
|
gint matched;
|
2014-07-08 10:36:12 +00:00
|
|
|
gboolean new_session = FALSE;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
2017-04-22 12:26:07 +00:00
|
|
|
gchar *pipelined_request_id = NULL, *accept_range = NULL;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-09-17 09:41:57 +00:00
|
|
|
if (!ctx->uri)
|
2013-06-20 09:17:29 +00:00
|
|
|
goto no_uri;
|
|
|
|
|
2013-09-17 09:41:57 +00:00
|
|
|
uri = ctx->uri;
|
2013-11-07 12:22:09 +00:00
|
|
|
klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
|
|
|
path = klass->make_path_from_uri (client, uri);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* parse the transport */
|
2009-05-26 17:01:10 +00:00
|
|
|
res =
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_TRANSPORT,
|
2011-01-12 12:16:08 +00:00
|
|
|
&transport, 0);
|
2008-10-09 12:29:12 +00:00
|
|
|
if (res != GST_RTSP_OK)
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_transport;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2017-04-22 12:26:07 +00:00
|
|
|
/* Handle Pipelined-requests if using >= 2.0 */
|
|
|
|
if (ctx->request->type_data.request.version >= GST_RTSP_VERSION_2_0)
|
|
|
|
gst_rtsp_message_get_header (ctx->request,
|
|
|
|
GST_RTSP_HDR_PIPELINED_REQUESTS, &pipelined_request_id, 0);
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* we create the session after parsing stuff so that we don't make
|
|
|
|
* a session for malformed requests */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->session_pool == NULL)
|
2009-01-29 17:51:02 +00:00
|
|
|
goto no_pool;
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
session = ctx->session;
|
2011-01-12 12:16:08 +00:00
|
|
|
|
2009-02-13 18:52:05 +00:00
|
|
|
if (session) {
|
|
|
|
g_object_ref (session);
|
2009-02-04 16:00:42 +00:00
|
|
|
/* get a handle to the configuration of the media in the session, this can
|
|
|
|
* return NULL if this is a new url to manage in this session. */
|
2013-07-03 10:37:48 +00:00
|
|
|
sessmedia = gst_rtsp_session_get_media (session, path, &matched);
|
2009-05-26 17:01:10 +00:00
|
|
|
} else {
|
2013-07-03 13:55:38 +00:00
|
|
|
/* we need a new media configuration in this session */
|
|
|
|
sessmedia = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have no session media, find one and manage it */
|
|
|
|
if (sessmedia == NULL) {
|
|
|
|
/* get a handle to the configuration of the media in the session */
|
2013-09-17 10:21:02 +00:00
|
|
|
media = find_media (client, ctx, path, &matched);
|
2015-11-18 10:14:39 +00:00
|
|
|
/* need to suspend the media, if the protocol has changed */
|
2019-10-16 13:20:54 +00:00
|
|
|
if (media != NULL) {
|
|
|
|
gst_rtsp_media_lock (media);
|
2015-11-18 10:14:39 +00:00
|
|
|
gst_rtsp_media_suspend (media);
|
2019-10-16 13:20:54 +00:00
|
|
|
}
|
2013-07-03 13:55:38 +00:00
|
|
|
} else {
|
2019-10-16 13:20:54 +00:00
|
|
|
if ((media = gst_rtsp_session_media_get_media (sessmedia))) {
|
2013-07-03 13:55:38 +00:00
|
|
|
g_object_ref (media);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_lock (media);
|
|
|
|
} else {
|
2013-09-26 07:41:10 +00:00
|
|
|
goto media_not_found;
|
2019-10-16 13:20:54 +00:00
|
|
|
}
|
2013-07-03 13:55:38 +00:00
|
|
|
}
|
|
|
|
/* no media, not found then */
|
|
|
|
if (media == NULL)
|
2013-09-26 07:41:10 +00:00
|
|
|
goto media_not_found_no_reply;
|
2013-07-03 13:55:38 +00:00
|
|
|
|
2015-01-19 12:09:20 +00:00
|
|
|
if (path[matched] == '\0') {
|
|
|
|
if (gst_rtsp_media_n_streams (media) == 1) {
|
|
|
|
stream = gst_rtsp_media_get_stream (media, 0);
|
|
|
|
} else {
|
|
|
|
goto control_not_found;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* path is what matched. */
|
|
|
|
path[matched] = '\0';
|
|
|
|
/* control is remainder */
|
|
|
|
control = &path[matched + 1];
|
2013-09-19 13:44:26 +00:00
|
|
|
|
2015-01-19 12:09:20 +00:00
|
|
|
/* find the stream now using the control part */
|
|
|
|
stream = gst_rtsp_media_find_stream (media, control);
|
|
|
|
}
|
2013-07-03 13:55:38 +00:00
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
goto stream_not_found;
|
|
|
|
|
|
|
|
/* now we have a uri identifying a valid media and stream */
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->stream = stream;
|
|
|
|
ctx->media = media;
|
2013-07-03 13:55:38 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_SETUP_REQUEST], 0,
|
|
|
|
ctx, &sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
|
|
|
|
2013-07-03 13:55:38 +00:00
|
|
|
if (session == NULL) {
|
2008-10-09 12:29:12 +00:00
|
|
|
/* create a session if this fails we probably reached our session limit or
|
|
|
|
* something. */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (!(session = gst_rtsp_session_pool_create (priv->session_pool)))
|
2008-10-09 12:29:12 +00:00
|
|
|
goto service_unavailable;
|
2009-02-04 16:00:42 +00:00
|
|
|
|
2017-04-22 12:26:07 +00:00
|
|
|
/* Pipelined requests should be cleared between sessions */
|
|
|
|
g_hash_table_remove_all (priv->pipelined_requests);
|
|
|
|
|
2013-06-20 10:20:21 +00:00
|
|
|
/* make sure this client is closed when the session is closed */
|
|
|
|
client_watch_session (client, session);
|
|
|
|
|
2014-07-08 10:36:12 +00:00
|
|
|
new_session = TRUE;
|
2013-06-20 10:16:07 +00:00
|
|
|
/* signal new session */
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_NEW_SESSION], 0,
|
|
|
|
session);
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->session = session;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 12:26:07 +00:00
|
|
|
if (pipelined_request_id) {
|
|
|
|
g_hash_table_insert (client->priv->pipelined_requests,
|
|
|
|
g_strdup (pipelined_request_id),
|
|
|
|
g_strdup (gst_rtsp_session_get_sessionid (session)));
|
|
|
|
}
|
2016-11-21 15:02:39 +00:00
|
|
|
rtsp_ctrl_timeout_remove (priv);
|
|
|
|
|
2013-12-18 14:57:03 +00:00
|
|
|
if (!klass->configure_client_media (client, media, stream, ctx))
|
|
|
|
goto configure_media_failed_no_reply;
|
2009-07-27 17:42:44 +00:00
|
|
|
|
2013-07-03 13:55:38 +00:00
|
|
|
gst_rtsp_transport_new (&ct);
|
|
|
|
|
|
|
|
/* parse and find a usable supported transport */
|
2014-01-07 11:28:47 +00:00
|
|
|
if (!parse_transport (transport, stream, ct))
|
2013-07-03 13:55:38 +00:00
|
|
|
goto unsupported_transports;
|
|
|
|
|
2015-01-28 17:54:01 +00:00
|
|
|
if ((ct->mode_play
|
|
|
|
&& !(gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_PLAY)) || (ct->mode_record
|
|
|
|
&& !(gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_RECORD)))
|
2015-01-09 11:40:47 +00:00
|
|
|
goto unsupported_mode;
|
|
|
|
|
2014-04-03 10:52:51 +00:00
|
|
|
/* parse the keymgmt */
|
|
|
|
if (gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_KEYMGMT,
|
|
|
|
&keymgmt, 0) == GST_RTSP_OK) {
|
2018-03-29 14:06:31 +00:00
|
|
|
if (!gst_rtsp_stream_handle_keymgmt (ctx->stream, keymgmt))
|
2014-04-03 10:52:51 +00:00
|
|
|
goto keymgmt_error;
|
|
|
|
}
|
|
|
|
|
2017-04-22 12:26:07 +00:00
|
|
|
if (gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_ACCEPT_RANGES,
|
|
|
|
&accept_range, 0) == GST_RTSP_OK) {
|
|
|
|
GEnumValue *runit = NULL;
|
|
|
|
gint i;
|
|
|
|
gchar **valid_ranges;
|
|
|
|
GEnumClass *runit_class = g_type_class_ref (GST_TYPE_RTSP_RANGE_UNIT);
|
|
|
|
|
|
|
|
gst_rtsp_message_dump (ctx->request);
|
|
|
|
valid_ranges = g_strsplit (accept_range, ",", -1);
|
|
|
|
|
|
|
|
for (i = 0; valid_ranges[i]; i++) {
|
|
|
|
gchar *range = valid_ranges[i];
|
|
|
|
|
|
|
|
while (*range == ' ')
|
|
|
|
range++;
|
|
|
|
|
|
|
|
runit = g_enum_get_value_by_nick (runit_class, range);
|
|
|
|
if (runit)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_strfreev (valid_ranges);
|
|
|
|
g_type_class_unref (runit_class);
|
|
|
|
|
|
|
|
if (!runit)
|
|
|
|
goto unsupported_range_unit;
|
|
|
|
}
|
|
|
|
|
2014-07-08 10:36:12 +00:00
|
|
|
if (sessmedia == NULL) {
|
|
|
|
/* manage the media in our session now, if not done already */
|
2015-09-25 15:04:00 +00:00
|
|
|
sessmedia =
|
|
|
|
gst_rtsp_session_manage_media (session, path, g_object_ref (media));
|
2014-07-08 10:36:12 +00:00
|
|
|
/* if we stil have no media, error */
|
|
|
|
if (sessmedia == NULL)
|
|
|
|
goto sessmedia_unavailable;
|
2014-10-23 10:54:03 +00:00
|
|
|
|
|
|
|
/* don't cache media anymore */
|
2014-11-07 11:48:53 +00:00
|
|
|
clean_cached_media (client, FALSE);
|
2014-07-08 10:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->sessmedia = sessmedia;
|
|
|
|
|
2014-10-24 10:04:54 +00:00
|
|
|
/* update the client transport */
|
|
|
|
if (!klass->configure_client_transport (client, ctx, ct))
|
|
|
|
goto unsupported_client_transport;
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* set in the session media transport */
|
2012-11-15 15:18:29 +00:00
|
|
|
trans = gst_rtsp_session_media_set_transport (sessmedia, stream, ct);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2014-10-20 22:40:59 +00:00
|
|
|
ctx->trans = trans;
|
|
|
|
|
2013-11-28 16:47:18 +00:00
|
|
|
/* configure the url used to set this transport, this we will use when
|
|
|
|
* generating the response for the PLAY request */
|
|
|
|
gst_rtsp_stream_transport_set_url (trans, uri);
|
2009-05-26 17:01:10 +00:00
|
|
|
/* configure keepalive for this transport */
|
2012-10-25 19:29:58 +00:00
|
|
|
gst_rtsp_stream_transport_set_keepalive (trans,
|
2010-03-16 17:33:23 +00:00
|
|
|
(GstRTSPKeepAliveFunc) do_keepalive, session, NULL);
|
2009-05-26 17:01:10 +00:00
|
|
|
|
2014-09-09 16:11:39 +00:00
|
|
|
if (ct->lower_transport == GST_RTSP_LOWER_TRANS_TCP) {
|
|
|
|
/* our callbacks to send data on this TCP connection */
|
|
|
|
gst_rtsp_stream_transport_set_callbacks (trans,
|
|
|
|
(GstRTSPSendFunc) do_send_data,
|
|
|
|
(GstRTSPSendFunc) do_send_data, client, NULL);
|
2018-06-27 10:17:07 +00:00
|
|
|
gst_rtsp_stream_transport_set_list_callbacks (trans,
|
|
|
|
(GstRTSPSendListFunc) do_send_data_list,
|
|
|
|
(GstRTSPSendListFunc) do_send_data_list, client, NULL);
|
2014-09-09 16:11:39 +00:00
|
|
|
|
2019-10-15 17:08:32 +00:00
|
|
|
gst_rtsp_stream_transport_set_back_pressure_callback (trans,
|
|
|
|
(GstRTSPBackPressureFunc) do_check_back_pressure, client, NULL);
|
|
|
|
|
2014-09-09 16:11:39 +00:00
|
|
|
g_hash_table_insert (priv->transports,
|
|
|
|
GINT_TO_POINTER (ct->interleaved.min), trans);
|
2014-11-28 11:45:14 +00:00
|
|
|
g_object_ref (trans);
|
2014-09-09 16:11:39 +00:00
|
|
|
g_hash_table_insert (priv->transports,
|
|
|
|
GINT_TO_POINTER (ct->interleaved.max), trans);
|
2014-11-28 11:45:14 +00:00
|
|
|
g_object_ref (trans);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
add_data_seq (client, ct->interleaved.min);
|
|
|
|
add_data_seq (client, ct->interleaved.max);
|
2014-09-09 16:11:39 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 21:49:24 +00:00
|
|
|
/* create and serialize the server transport */
|
2015-01-09 11:40:47 +00:00
|
|
|
st = make_server_transport (client, media, ctx, ct);
|
2008-10-09 12:29:12 +00:00
|
|
|
trans_str = gst_rtsp_transport_as_text (st);
|
2009-01-30 16:06:26 +00:00
|
|
|
gst_rtsp_transport_free (st);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* construct the response now */
|
|
|
|
code = GST_RTSP_STS_OK;
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_init_response (ctx->response, code,
|
|
|
|
gst_rtsp_status_as_text (code), ctx->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_TRANSPORT,
|
2011-01-12 14:37:39 +00:00
|
|
|
trans_str);
|
2008-10-09 12:29:12 +00:00
|
|
|
g_free (trans_str);
|
|
|
|
|
2017-04-22 12:26:07 +00:00
|
|
|
if (pipelined_request_id)
|
|
|
|
gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_PIPELINED_REQUESTS,
|
|
|
|
pipelined_request_id);
|
|
|
|
|
|
|
|
if (ctx->request->type_data.request.version >= GST_RTSP_VERSION_2_0) {
|
|
|
|
GstClockTimeDiff seekable = gst_rtsp_media_seekable (media);
|
|
|
|
GString *media_properties = g_string_new (NULL);
|
|
|
|
|
|
|
|
if (seekable == -1)
|
|
|
|
g_string_append (media_properties,
|
|
|
|
"No-Seeking,Time-Progressing,Time-Duration=0.0");
|
|
|
|
else if (seekable == 0)
|
|
|
|
g_string_append (media_properties, "Beginning-Only");
|
|
|
|
else if (seekable == G_MAXINT64)
|
|
|
|
g_string_append (media_properties, "Random-Access");
|
|
|
|
else
|
|
|
|
g_string_append_printf (media_properties,
|
|
|
|
"Random-Access=%f, Unlimited, Immutable",
|
|
|
|
(gdouble) seekable / GST_SECOND);
|
|
|
|
|
|
|
|
gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_MEDIA_PROPERTIES,
|
|
|
|
g_string_free (media_properties, FALSE));
|
|
|
|
/* TODO Check how Accept-Ranges should be filled */
|
|
|
|
gst_rtsp_message_add_header (ctx->request, GST_RTSP_HDR_ACCEPT_RANGES,
|
|
|
|
"npt, clock, smpte, clock");
|
|
|
|
}
|
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* update the state */
|
2012-11-29 10:11:05 +00:00
|
|
|
rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
|
|
|
|
switch (rtspstate) {
|
2009-02-03 18:32:38 +00:00
|
|
|
case GST_RTSP_STATE_PLAYING:
|
|
|
|
case GST_RTSP_STATE_RECORDING:
|
|
|
|
case GST_RTSP_STATE_READY:
|
|
|
|
/* no state change */
|
|
|
|
break;
|
|
|
|
default:
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_READY);
|
2009-02-03 18:32:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-10-16 13:20:54 +00:00
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST], 0, ctx);
|
|
|
|
|
|
|
|
gst_rtsp_media_unlock (media);
|
2015-09-25 15:04:00 +00:00
|
|
|
g_object_unref (media);
|
2009-02-03 18:32:38 +00:00
|
|
|
g_object_unref (session);
|
2013-10-01 12:04:17 +00:00
|
|
|
g_free (path);
|
2009-02-03 18:32:38 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2013-06-20 09:17:29 +00:00
|
|
|
no_uri:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no uri", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2013-06-20 09:17:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-07-03 13:55:38 +00:00
|
|
|
no_transport:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2013-07-03 13:55:38 +00:00
|
|
|
GST_ERROR ("client %p: no transport", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
|
2014-04-03 10:57:13 +00:00
|
|
|
goto cleanup_path;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2013-07-03 13:55:38 +00:00
|
|
|
no_pool:
|
2009-01-22 14:33:29 +00:00
|
|
|
{
|
2013-07-03 13:55:38 +00:00
|
|
|
GST_ERROR ("client %p: no session pool configured", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
|
2014-04-03 10:57:13 +00:00
|
|
|
goto cleanup_path;
|
2013-07-03 13:55:38 +00:00
|
|
|
}
|
2013-09-26 07:41:10 +00:00
|
|
|
media_not_found_no_reply:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: media '%s' not found", client, path);
|
|
|
|
/* error reply is already sent */
|
2016-08-02 12:08:22 +00:00
|
|
|
goto cleanup_session;
|
2013-09-26 07:41:10 +00:00
|
|
|
}
|
2013-07-03 13:55:38 +00:00
|
|
|
media_not_found:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: media '%s' not found", client, path);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
2016-08-02 12:08:22 +00:00
|
|
|
goto cleanup_session;
|
2009-01-22 14:33:29 +00:00
|
|
|
}
|
2013-09-19 13:44:26 +00:00
|
|
|
control_not_found:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no control in path '%s'", client, path);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
2013-09-19 13:44:26 +00:00
|
|
|
g_object_unref (media);
|
2016-08-02 12:08:22 +00:00
|
|
|
goto cleanup_session;
|
2013-09-19 13:44:26 +00:00
|
|
|
}
|
2013-07-03 13:55:38 +00:00
|
|
|
stream_not_found:
|
2012-07-03 11:26:30 +00:00
|
|
|
{
|
2015-01-19 12:09:20 +00:00
|
|
|
GST_ERROR ("client %p: stream '%s' not found", client,
|
|
|
|
GST_STR_NULL (control));
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
2013-07-03 13:55:38 +00:00
|
|
|
g_object_unref (media);
|
2016-08-02 12:08:22 +00:00
|
|
|
goto cleanup_session;
|
2012-07-03 11:26:30 +00:00
|
|
|
}
|
2016-08-24 09:39:13 +00:00
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
2016-08-24 09:39:13 +00:00
|
|
|
g_object_unref (media);
|
|
|
|
goto cleanup_path;
|
|
|
|
}
|
2013-07-03 13:55:38 +00:00
|
|
|
service_unavailable:
|
2012-11-14 16:23:59 +00:00
|
|
|
{
|
2013-07-03 13:55:38 +00:00
|
|
|
GST_ERROR ("client %p: can't create session", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
2013-07-03 13:55:38 +00:00
|
|
|
g_object_unref (media);
|
2016-08-02 12:08:22 +00:00
|
|
|
goto cleanup_session;
|
2013-07-03 13:55:38 +00:00
|
|
|
}
|
|
|
|
sessmedia_unavailable:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: can't create session media", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
|
2015-09-25 15:04:00 +00:00
|
|
|
goto cleanup_transport;
|
2012-11-14 16:23:59 +00:00
|
|
|
}
|
2013-12-18 14:57:03 +00:00
|
|
|
configure_media_failed_no_reply:
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2013-12-18 14:57:03 +00:00
|
|
|
GST_ERROR ("client %p: configure_media failed", client);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
2015-09-25 15:04:00 +00:00
|
|
|
g_object_unref (media);
|
2013-12-18 14:57:03 +00:00
|
|
|
/* error reply is already sent */
|
2014-04-03 10:57:13 +00:00
|
|
|
goto cleanup_session;
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
unsupported_transports:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: unsupported transports", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
|
2014-04-03 10:57:13 +00:00
|
|
|
goto cleanup_transport;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2013-07-03 13:55:38 +00:00
|
|
|
unsupported_client_transport:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2013-07-03 13:55:38 +00:00
|
|
|
GST_ERROR ("client %p: unsupported client transport", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
|
2014-04-03 10:57:13 +00:00
|
|
|
goto cleanup_transport;
|
|
|
|
}
|
2015-01-09 11:40:47 +00:00
|
|
|
unsupported_mode:
|
|
|
|
{
|
2015-01-28 17:54:01 +00:00
|
|
|
GST_ERROR ("client %p: unsupported mode (media play: %d, media record: %d, "
|
|
|
|
"mode play: %d, mode record: %d)", client,
|
|
|
|
! !(gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_PLAY),
|
|
|
|
! !(gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_RECORD), ct->mode_play, ct->mode_record);
|
2015-01-09 11:40:47 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
|
|
|
|
goto cleanup_transport;
|
|
|
|
}
|
2017-04-22 12:26:07 +00:00
|
|
|
unsupported_range_unit:
|
|
|
|
{
|
|
|
|
GST_ERROR ("Client %p: does not support any range format we support",
|
|
|
|
client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, ctx);
|
|
|
|
goto cleanup_transport;
|
|
|
|
}
|
2014-04-03 10:52:51 +00:00
|
|
|
keymgmt_error:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: keymgmt error", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_KEY_MANAGEMENT_FAILURE, ctx);
|
|
|
|
goto cleanup_transport;
|
|
|
|
}
|
2014-04-03 10:57:13 +00:00
|
|
|
{
|
|
|
|
cleanup_transport:
|
2012-06-14 07:59:06 +00:00
|
|
|
gst_rtsp_transport_free (ct);
|
2019-10-16 13:20:54 +00:00
|
|
|
if (media) {
|
|
|
|
gst_rtsp_media_unlock (media);
|
2015-09-25 15:04:00 +00:00
|
|
|
g_object_unref (media);
|
2019-10-16 13:20:54 +00:00
|
|
|
}
|
2014-04-03 10:57:13 +00:00
|
|
|
cleanup_session:
|
2014-07-08 10:36:12 +00:00
|
|
|
if (new_session)
|
|
|
|
gst_rtsp_session_pool_remove (priv->session_pool, session);
|
2016-08-02 12:08:22 +00:00
|
|
|
if (session)
|
|
|
|
g_object_unref (session);
|
2014-04-03 10:57:13 +00:00
|
|
|
cleanup_path:
|
2013-10-01 12:04:17 +00:00
|
|
|
g_free (path);
|
2008-10-09 12:29:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-16 17:33:23 +00:00
|
|
|
static GstSDPMessage *
|
|
|
|
create_sdp (GstRTSPClient * client, GstRTSPMedia * media)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-03-16 17:33:23 +00:00
|
|
|
GstSDPMessage *sdp;
|
|
|
|
GstSDPInfo info;
|
|
|
|
const gchar *proto;
|
2015-01-18 18:08:36 +00:00
|
|
|
guint64 session_id_tmp;
|
|
|
|
gchar session_id[21];
|
2010-03-16 17:33:23 +00:00
|
|
|
|
|
|
|
gst_sdp_message_new (&sdp);
|
|
|
|
|
|
|
|
/* some standard things first */
|
|
|
|
gst_sdp_message_set_version (sdp, "0");
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->is_ipv6)
|
2010-03-16 17:33:23 +00:00
|
|
|
proto = "IP6";
|
|
|
|
else
|
|
|
|
proto = "IP4";
|
|
|
|
|
2015-01-18 18:08:36 +00:00
|
|
|
session_id_tmp = (((guint64) g_random_int ()) << 32) | g_random_int ();
|
|
|
|
g_snprintf (session_id, sizeof (session_id), "%" G_GUINT64_FORMAT,
|
|
|
|
session_id_tmp);
|
|
|
|
|
|
|
|
gst_sdp_message_set_origin (sdp, "-", session_id, "1", "IN", proto,
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->server_ip);
|
2010-03-16 17:33:23 +00:00
|
|
|
|
|
|
|
gst_sdp_message_set_session_name (sdp, "Session streamed with GStreamer");
|
|
|
|
gst_sdp_message_set_information (sdp, "rtsp-server");
|
|
|
|
gst_sdp_message_add_time (sdp, "0", "0", NULL);
|
|
|
|
gst_sdp_message_add_attribute (sdp, "tool", "GStreamer");
|
|
|
|
gst_sdp_message_add_attribute (sdp, "type", "broadcast");
|
|
|
|
gst_sdp_message_add_attribute (sdp, "control", "*");
|
|
|
|
|
2013-06-14 14:05:59 +00:00
|
|
|
info.is_ipv6 = priv->is_ipv6;
|
|
|
|
info.server_ip = priv->server_ip;
|
2010-03-16 17:33:23 +00:00
|
|
|
|
|
|
|
/* create an SDP for the media object */
|
2013-12-18 15:37:27 +00:00
|
|
|
if (!gst_rtsp_media_setup_sdp (media, sdp, &info))
|
2010-03-16 17:33:23 +00:00
|
|
|
goto no_sdp;
|
|
|
|
|
|
|
|
return sdp;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_sdp:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: could not create SDP", client);
|
2010-03-16 17:33:23 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
/* for the describe we must generate an SDP */
|
2008-10-09 12:29:12 +00:00
|
|
|
static gboolean
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_describe_request (GstRTSPClient * client, GstRTSPContext * ctx)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2013-09-17 10:21:02 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPResult res;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstSDPMessage *sdp;
|
2013-09-17 12:39:44 +00:00
|
|
|
guint i;
|
|
|
|
gchar *path, *str;
|
2009-01-22 16:58:19 +00:00
|
|
|
GstRTSPMedia *media;
|
2012-07-18 13:54:49 +00:00
|
|
|
GstRTSPClientClass *klass;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
2012-07-18 13:54:49 +00:00
|
|
|
|
|
|
|
klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
if (!ctx->uri)
|
2013-06-20 09:17:29 +00:00
|
|
|
goto no_uri;
|
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_DESCRIBE_REQUEST],
|
|
|
|
0, ctx, &sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
/* check what kind of format is accepted, we don't really do anything with it
|
|
|
|
* and always return SDP for now. */
|
2013-12-19 13:24:54 +00:00
|
|
|
for (i = 0;; i++) {
|
2009-01-22 16:58:19 +00:00
|
|
|
gchar *accept;
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
res =
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_ACCEPT,
|
2011-01-12 12:16:08 +00:00
|
|
|
&accept, i);
|
2009-01-22 16:58:19 +00:00
|
|
|
if (res == GST_RTSP_ENOTIMPL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (g_ascii_strcasecmp (accept, "application/sdp") == 0)
|
|
|
|
break;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-09-17 10:21:02 +00:00
|
|
|
if (!priv->mount_points)
|
|
|
|
goto no_mount_points;
|
|
|
|
|
|
|
|
if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri)))
|
|
|
|
goto no_path;
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* find the media object for the uri */
|
2013-09-17 10:21:02 +00:00
|
|
|
if (!(media = find_media (client, ctx, path, NULL)))
|
2009-01-22 16:58:19 +00:00
|
|
|
goto no_media;
|
2009-01-22 17:35:17 +00:00
|
|
|
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_lock (media);
|
|
|
|
|
2015-01-28 17:54:01 +00:00
|
|
|
if (!(gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_PLAY))
|
|
|
|
goto unsupported_mode;
|
2015-01-09 11:40:47 +00:00
|
|
|
|
2010-03-16 17:33:23 +00:00
|
|
|
/* create an SDP for the media object on this client */
|
2012-07-18 13:54:49 +00:00
|
|
|
if (!(sdp = klass->create_sdp (client, media)))
|
2009-01-29 12:31:27 +00:00
|
|
|
goto no_sdp;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-11-28 13:14:35 +00:00
|
|
|
/* we suspend after the describe */
|
|
|
|
gst_rtsp_media_suspend (media);
|
2009-02-04 16:00:42 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_init_response (ctx->response, GST_RTSP_STS_OK,
|
|
|
|
gst_rtsp_status_as_text (GST_RTSP_STS_OK), ctx->request);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_CONTENT_TYPE,
|
2009-05-26 17:01:10 +00:00
|
|
|
"application/sdp");
|
2009-01-22 16:58:19 +00:00
|
|
|
|
2009-01-29 16:19:21 +00:00
|
|
|
/* content base for some clients that might screw up creating the setup uri */
|
2013-09-17 12:39:44 +00:00
|
|
|
str = make_base_url (client, ctx->uri, path);
|
|
|
|
g_free (path);
|
2010-03-16 17:33:23 +00:00
|
|
|
|
2013-09-17 12:39:44 +00:00
|
|
|
GST_INFO ("adding content-base: %s", str);
|
|
|
|
gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_CONTENT_BASE, str);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* add SDP to the response body */
|
2009-01-29 12:31:27 +00:00
|
|
|
str = gst_sdp_message_as_text (sdp);
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_take_body (ctx->response, (guint8 *) str, strlen (str));
|
2008-10-09 12:29:12 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-09-03 17:48:14 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_DESCRIBE_REQUEST],
|
2013-07-22 12:25:04 +00:00
|
|
|
0, ctx);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2016-08-24 09:39:13 +00:00
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-06-20 09:17:29 +00:00
|
|
|
no_uri:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no uri", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2013-06-20 09:17:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-09-17 10:21:02 +00:00
|
|
|
no_mount_points:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no mount points configured", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_path:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: can't find path for url", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-22 16:58:19 +00:00
|
|
|
no_media:
|
2009-01-22 14:33:29 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no media", client);
|
2013-09-17 10:21:02 +00:00
|
|
|
g_free (path);
|
2009-01-29 12:31:27 +00:00
|
|
|
/* error reply is already sent */
|
2009-01-22 14:33:29 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-01-28 17:54:01 +00:00
|
|
|
unsupported_mode:
|
2015-01-09 11:40:47 +00:00
|
|
|
{
|
2015-01-28 17:54:01 +00:00
|
|
|
GST_ERROR ("client %p: media does not support DESCRIBE", client);
|
2015-01-09 11:40:47 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_ALLOWED, ctx);
|
|
|
|
g_free (path);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
2015-01-09 11:40:47 +00:00
|
|
|
g_object_unref (media);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
no_sdp:
|
2009-01-22 15:53:16 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: can't create SDP", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
|
2013-09-17 12:39:44 +00:00
|
|
|
g_free (path);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_unref (media);
|
2009-01-22 15:53:16 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
static gboolean
|
|
|
|
handle_sdp (GstRTSPClient * client, GstRTSPContext * ctx, GstRTSPMedia * media,
|
|
|
|
GstSDPMessage * sdp)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
GstRTSPThread *thread;
|
|
|
|
|
|
|
|
/* create an SDP for the media object */
|
|
|
|
if (!gst_rtsp_media_handle_sdp (media, sdp))
|
|
|
|
goto unhandled_sdp;
|
|
|
|
|
|
|
|
thread = gst_rtsp_thread_pool_get_thread (priv->thread_pool,
|
|
|
|
GST_RTSP_THREAD_TYPE_MEDIA, ctx);
|
|
|
|
if (thread == NULL)
|
|
|
|
goto no_thread;
|
|
|
|
|
|
|
|
/* prepare the media */
|
|
|
|
if (!gst_rtsp_media_prepare (media, thread))
|
|
|
|
goto no_prepare;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
unhandled_sdp:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: could not handle SDP", client);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_thread:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: can't create thread", client);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_prepare:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: can't prepare media", client);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
handle_announce_request (GstRTSPClient * client, GstRTSPContext * ctx)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
GstRTSPClientClass *klass;
|
|
|
|
GstSDPResult sres;
|
|
|
|
GstSDPMessage *sdp;
|
|
|
|
GstRTSPMedia *media;
|
|
|
|
gchar *path, *cont = NULL;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
2018-03-29 14:12:26 +00:00
|
|
|
guint i, n_streams;
|
2015-01-09 11:40:47 +00:00
|
|
|
|
|
|
|
klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
|
|
|
|
|
|
|
if (!ctx->uri)
|
|
|
|
goto no_uri;
|
|
|
|
|
|
|
|
if (!priv->mount_points)
|
|
|
|
goto no_mount_points;
|
|
|
|
|
|
|
|
/* check if reply is SDP */
|
|
|
|
gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_CONTENT_TYPE, &cont,
|
|
|
|
0);
|
|
|
|
/* could not be set but since the request returned OK, we assume it
|
|
|
|
* was SDP, else check it. */
|
|
|
|
if (cont) {
|
2015-02-08 12:08:36 +00:00
|
|
|
if (g_ascii_strcasecmp (cont, "application/sdp") != 0)
|
2015-01-09 11:40:47 +00:00
|
|
|
goto wrong_content_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get message body and parse as SDP */
|
|
|
|
gst_rtsp_message_get_body (ctx->request, &data, &size);
|
|
|
|
if (data == NULL || size == 0)
|
|
|
|
goto no_message;
|
|
|
|
|
|
|
|
GST_DEBUG ("client %p: parse SDP...", client);
|
|
|
|
gst_sdp_message_new (&sdp);
|
|
|
|
sres = gst_sdp_message_parse_buffer (data, size, sdp);
|
|
|
|
if (sres != GST_SDP_OK)
|
|
|
|
goto sdp_parse_failed;
|
|
|
|
|
|
|
|
if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri)))
|
|
|
|
goto no_path;
|
|
|
|
|
|
|
|
/* find the media object for the uri */
|
|
|
|
if (!(media = find_media (client, ctx, path, NULL)))
|
|
|
|
goto no_media;
|
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
ctx->media = media;
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_lock (media);
|
2016-08-24 09:39:13 +00:00
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_ANNOUNCE_REQUEST],
|
|
|
|
0, ctx, &sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
|
|
|
|
2015-01-28 17:54:01 +00:00
|
|
|
if (!(gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_RECORD))
|
|
|
|
goto unsupported_mode;
|
2015-01-09 11:40:47 +00:00
|
|
|
|
|
|
|
/* Tell client subclass about the media */
|
|
|
|
if (!klass->handle_sdp (client, ctx, media, sdp))
|
|
|
|
goto unhandled_sdp;
|
|
|
|
|
2018-03-29 14:12:26 +00:00
|
|
|
gst_rtsp_message_init_response (ctx->response, GST_RTSP_STS_OK,
|
|
|
|
gst_rtsp_status_as_text (GST_RTSP_STS_OK), ctx->request);
|
|
|
|
|
|
|
|
n_streams = gst_rtsp_media_n_streams (media);
|
|
|
|
for (i = 0; i < n_streams; i++) {
|
|
|
|
GstRTSPStream *stream = gst_rtsp_media_get_stream (media, i);
|
2019-10-17 10:15:42 +00:00
|
|
|
gchar *uri, *location, *keymgmt;
|
|
|
|
|
|
|
|
uri = gst_rtsp_url_get_request_uri (ctx->uri);
|
|
|
|
location = g_strdup_printf ("%s/stream=%d", uri, i);
|
|
|
|
keymgmt = stream_make_keymgmt (client, location, stream);
|
2018-03-29 14:12:26 +00:00
|
|
|
|
|
|
|
if (keymgmt)
|
2018-04-04 07:06:06 +00:00
|
|
|
gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_KEYMGMT,
|
|
|
|
keymgmt);
|
2018-03-29 14:12:26 +00:00
|
|
|
|
|
|
|
g_free (location);
|
2019-10-17 10:15:42 +00:00
|
|
|
g_free (uri);
|
2018-03-29 14:12:26 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
/* we suspend after the announce */
|
|
|
|
gst_rtsp_media_suspend (media);
|
|
|
|
|
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_ANNOUNCE_REQUEST],
|
|
|
|
0, ctx);
|
|
|
|
|
2015-01-21 16:32:44 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
|
|
|
g_free (path);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
no_uri:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no uri", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_mount_points:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no mount points configured", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_path:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: can't find path for url", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
2015-01-21 16:32:44 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
2015-01-09 11:40:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
wrong_content_type:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: unknown content type", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_message:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: can't find SDP message", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
sdp_parse_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: failed to parse SDP message", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2015-01-21 16:32:44 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
2015-01-09 11:40:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_media:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no media", client);
|
|
|
|
g_free (path);
|
|
|
|
/* error reply is already sent */
|
2015-01-21 16:32:44 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
2015-01-09 11:40:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-08-24 09:39:13 +00:00
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
|
|
|
gst_sdp_message_free (sdp);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
|
|
|
g_object_unref (media);
|
2016-08-24 09:39:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-01-28 17:54:01 +00:00
|
|
|
unsupported_mode:
|
2015-01-09 11:40:47 +00:00
|
|
|
{
|
2015-01-28 17:54:01 +00:00
|
|
|
GST_ERROR ("client %p: media does not support ANNOUNCE", client);
|
2015-01-09 11:40:47 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_ALLOWED, ctx);
|
|
|
|
g_free (path);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
2015-01-09 11:40:47 +00:00
|
|
|
g_object_unref (media);
|
2015-01-21 16:32:44 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
2015-01-09 11:40:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
unhandled_sdp:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: can't handle SDP", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_MEDIA_TYPE, ctx);
|
|
|
|
g_free (path);
|
2019-10-16 13:20:54 +00:00
|
|
|
gst_rtsp_media_unlock (media);
|
2015-01-09 11:40:47 +00:00
|
|
|
g_object_unref (media);
|
2015-01-21 16:32:44 +00:00
|
|
|
gst_sdp_message_free (sdp);
|
2015-01-09 11:40:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
handle_record_request (GstRTSPClient * client, GstRTSPContext * ctx)
|
|
|
|
{
|
|
|
|
GstRTSPSession *session;
|
|
|
|
GstRTSPClientClass *klass;
|
|
|
|
GstRTSPSessionMedia *sessmedia;
|
|
|
|
GstRTSPMedia *media;
|
|
|
|
GstRTSPUrl *uri;
|
|
|
|
GstRTSPState rtspstate;
|
|
|
|
gchar *path;
|
|
|
|
gint matched;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
2017-10-17 08:44:33 +00:00
|
|
|
GPtrArray *transports;
|
2015-01-09 11:40:47 +00:00
|
|
|
|
|
|
|
if (!(session = ctx->session))
|
|
|
|
goto no_session;
|
|
|
|
|
|
|
|
if (!(uri = ctx->uri))
|
|
|
|
goto no_uri;
|
|
|
|
|
|
|
|
klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
|
|
|
path = klass->make_path_from_uri (client, uri);
|
|
|
|
|
|
|
|
/* get a handle to the configuration of the media in the session */
|
|
|
|
sessmedia = gst_rtsp_session_get_media (session, path, &matched);
|
|
|
|
if (!sessmedia)
|
|
|
|
goto not_found;
|
|
|
|
|
|
|
|
if (path[matched] != '\0')
|
|
|
|
goto no_aggregate;
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
ctx->sessmedia = sessmedia;
|
|
|
|
ctx->media = media = gst_rtsp_session_media_get_media (sessmedia);
|
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_RECORD_REQUEST], 0,
|
|
|
|
ctx, &sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
|
|
|
|
2015-01-28 17:54:01 +00:00
|
|
|
if (!(gst_rtsp_media_get_transport_mode (media) &
|
|
|
|
GST_RTSP_TRANSPORT_MODE_RECORD))
|
|
|
|
goto unsupported_mode;
|
2015-01-09 11:40:47 +00:00
|
|
|
|
|
|
|
/* the session state must be playing or ready */
|
|
|
|
rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
|
|
|
|
if (rtspstate != GST_RTSP_STATE_PLAYING && rtspstate != GST_RTSP_STATE_READY)
|
|
|
|
goto invalid_state;
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
/* update the pipeline */
|
|
|
|
transports = gst_rtsp_session_media_get_transports (sessmedia);
|
|
|
|
if (!gst_rtsp_media_complete_pipeline (media, transports)) {
|
|
|
|
g_ptr_array_unref (transports);
|
|
|
|
goto pipeline_error;
|
|
|
|
}
|
|
|
|
g_ptr_array_unref (transports);
|
|
|
|
|
|
|
|
/* in record we first unsuspend, media could be suspended from SDP or PAUSED */
|
2015-01-09 11:40:47 +00:00
|
|
|
if (!gst_rtsp_media_unsuspend (media))
|
|
|
|
goto unsuspend_failed;
|
|
|
|
|
|
|
|
gst_rtsp_message_init_response (ctx->response, GST_RTSP_STS_OK,
|
|
|
|
gst_rtsp_status_as_text (GST_RTSP_STS_OK), ctx->request);
|
|
|
|
|
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
|
|
|
|
|
|
|
/* start playing after sending the response */
|
|
|
|
gst_rtsp_session_media_set_state (sessmedia, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
gst_rtsp_session_media_set_rtsp_state (sessmedia, GST_RTSP_STATE_PLAYING);
|
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_RECORD_REQUEST], 0,
|
|
|
|
ctx);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_session:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no session", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_uri:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no uri supplied", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
not_found:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: media not found", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_aggregate:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no aggregate path %s", client, path);
|
|
|
|
send_generic_response (client,
|
|
|
|
GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
|
|
|
|
g_free (path);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-08-24 09:39:13 +00:00
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-01-28 17:54:01 +00:00
|
|
|
unsupported_mode:
|
2015-01-09 11:40:47 +00:00
|
|
|
{
|
2015-01-28 17:54:01 +00:00
|
|
|
GST_ERROR ("client %p: media does not support RECORD", client);
|
2015-01-09 11:40:47 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_ALLOWED, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_state:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: not PLAYING or READY", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
|
2017-10-17 08:44:33 +00:00
|
|
|
ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pipeline_error:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: failed to configure the pipeline", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
|
2015-01-09 11:40:47 +00:00
|
|
|
ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
unsuspend_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: unsuspend failed", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
static gboolean
|
2017-04-22 12:26:07 +00:00
|
|
|
handle_options_request (GstRTSPClient * client, GstRTSPContext * ctx,
|
|
|
|
GstRTSPVersion version)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPMethod options;
|
2009-01-29 12:31:27 +00:00
|
|
|
gchar *str;
|
2016-08-24 09:39:13 +00:00
|
|
|
GstRTSPStatusCode sig_result;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
options = GST_RTSP_DESCRIBE |
|
2009-05-26 17:01:10 +00:00
|
|
|
GST_RTSP_OPTIONS |
|
|
|
|
GST_RTSP_PAUSE |
|
|
|
|
GST_RTSP_PLAY |
|
|
|
|
GST_RTSP_SETUP |
|
|
|
|
GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2017-04-22 12:26:07 +00:00
|
|
|
if (version < GST_RTSP_VERSION_2_0) {
|
|
|
|
options |= GST_RTSP_RECORD;
|
|
|
|
options |= GST_RTSP_ANNOUNCE;
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
str = gst_rtsp_options_as_text (options);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_init_response (ctx->response, GST_RTSP_STS_OK,
|
|
|
|
gst_rtsp_status_as_text (GST_RTSP_STS_OK), ctx->request);
|
2009-01-22 17:35:17 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_PUBLIC, str);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_free (str);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2016-08-24 09:39:13 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_PRE_OPTIONS_REQUEST], 0,
|
|
|
|
ctx, &sig_result);
|
|
|
|
if (sig_result != GST_RTSP_STS_OK) {
|
|
|
|
goto sig_failed;
|
|
|
|
}
|
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
send_message (client, ctx, ctx->response, FALSE);
|
2009-06-09 22:01:07 +00:00
|
|
|
|
2012-09-03 17:48:14 +00:00
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_OPTIONS_REQUEST],
|
2013-07-22 12:25:04 +00:00
|
|
|
0, ctx);
|
2012-09-03 17:48:14 +00:00
|
|
|
|
2009-06-09 22:01:07 +00:00
|
|
|
return TRUE;
|
2016-08-24 09:39:13 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
sig_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: pre signal returned error: %s", client,
|
|
|
|
gst_rtsp_status_as_text (sig_result));
|
|
|
|
send_generic_response (client, sig_result, ctx);
|
|
|
|
gst_rtsp_message_free (ctx->response);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* remove duplicate and trailing '/' */
|
|
|
|
static void
|
2010-12-28 11:18:41 +00:00
|
|
|
sanitize_uri (GstRTSPUrl * uri)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
gint i, len;
|
|
|
|
gchar *s, *d;
|
|
|
|
gboolean have_slash, prev_slash;
|
|
|
|
|
|
|
|
s = d = uri->abspath;
|
|
|
|
len = strlen (uri->abspath);
|
|
|
|
|
|
|
|
prev_slash = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
have_slash = s[i] == '/';
|
|
|
|
*d = s[i];
|
|
|
|
if (!have_slash || !prev_slash)
|
|
|
|
d++;
|
|
|
|
prev_slash = have_slash;
|
|
|
|
}
|
|
|
|
len = d - uri->abspath;
|
|
|
|
/* don't remove the first slash if that's the only thing left */
|
2009-05-26 17:01:10 +00:00
|
|
|
if (len > 1 && *(d - 1) == '/')
|
2009-01-29 12:31:27 +00:00
|
|
|
d--;
|
|
|
|
*d = '\0';
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 10:13:47 +00:00
|
|
|
/* is called when the session is removed from its session pool. */
|
2009-03-11 18:38:06 +00:00
|
|
|
static void
|
2014-07-01 10:13:47 +00:00
|
|
|
client_session_removed (GstRTSPSessionPool * pool, GstRTSPSession * session,
|
|
|
|
GstRTSPClient * client)
|
2009-03-11 18:38:06 +00:00
|
|
|
{
|
2014-07-01 12:41:14 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
|
2014-07-01 10:13:47 +00:00
|
|
|
GST_INFO ("client %p: session %p removed", client, session);
|
2014-07-01 12:41:14 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2014-07-01 10:13:47 +00:00
|
|
|
client_unwatch_session (client, session, NULL);
|
2014-07-01 12:41:14 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2009-03-11 18:38:06 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 11:12:04 +00:00
|
|
|
/* Check for Require headers. Returns TRUE if there are no Require headers,
|
|
|
|
* otherwise lets the application decide which headers are supported.
|
|
|
|
* By default all headers are unsupported.
|
|
|
|
* If there are unsupported options, FALSE will be returned together with
|
|
|
|
* a newly-allocated string of (comma-separated) unsupported options in
|
|
|
|
* the unsupported_reqs variable.
|
2014-05-02 18:59:23 +00:00
|
|
|
*
|
|
|
|
* There may be multiple Require headers, but we must send one single
|
|
|
|
* Unsupported header with all the unsupported options as response. If
|
|
|
|
* an incoming Require header contained a comma-separated list of options
|
|
|
|
* GstRtspConnection will already have split that list up into multiple
|
|
|
|
* headers.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2015-06-18 11:12:04 +00:00
|
|
|
check_request_requirements (GstRTSPContext * ctx, gchar ** unsupported_reqs)
|
2014-05-02 18:59:23 +00:00
|
|
|
{
|
|
|
|
GstRTSPResult res;
|
|
|
|
GPtrArray *arr = NULL;
|
2015-06-18 11:12:04 +00:00
|
|
|
GstRTSPMessage *msg = ctx->request;
|
2014-05-02 18:59:23 +00:00
|
|
|
gchar *reqs = NULL;
|
|
|
|
gint i;
|
2015-06-18 11:12:04 +00:00
|
|
|
gchar *sig_result = NULL;
|
|
|
|
gboolean result = TRUE;
|
2014-05-02 18:59:23 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
res = gst_rtsp_message_get_header (msg, GST_RTSP_HDR_REQUIRE, &reqs, i++);
|
|
|
|
|
|
|
|
if (res == GST_RTSP_ENOTIMPL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (arr == NULL)
|
|
|
|
arr = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
|
|
|
|
|
|
|
|
g_ptr_array_add (arr, g_strdup (reqs));
|
|
|
|
}
|
|
|
|
while (TRUE);
|
|
|
|
|
|
|
|
/* if we don't have any Require headers at all, all is fine */
|
|
|
|
if (i == 1)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* otherwise we've now processed at all the Require headers */
|
|
|
|
g_ptr_array_add (arr, NULL);
|
|
|
|
|
2015-06-18 11:12:04 +00:00
|
|
|
g_signal_emit (ctx->client,
|
|
|
|
gst_rtsp_client_signals[SIGNAL_CHECK_REQUIREMENTS], 0, ctx,
|
|
|
|
(gchar **) arr->pdata, &sig_result);
|
2014-05-02 18:59:23 +00:00
|
|
|
|
2015-06-18 11:12:04 +00:00
|
|
|
if (sig_result == NULL) {
|
|
|
|
/* no supported options, just report all of the required ones as
|
|
|
|
* unsupported */
|
|
|
|
*unsupported_reqs = g_strjoinv (", ", (gchar **) arr->pdata);
|
|
|
|
result = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen (sig_result) == 0)
|
|
|
|
g_free (sig_result);
|
|
|
|
else {
|
|
|
|
*unsupported_reqs = sig_result;
|
|
|
|
result = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2014-05-02 18:59:23 +00:00
|
|
|
g_ptr_array_unref (arr);
|
2015-06-18 11:12:04 +00:00
|
|
|
return result;
|
2014-05-02 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_request (GstRTSPClient * client, GstRTSPMessage * request)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPMethod method;
|
2009-01-22 16:58:19 +00:00
|
|
|
const gchar *uristr;
|
2012-11-27 11:24:21 +00:00
|
|
|
GstRTSPUrl *uri = NULL;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPVersion version;
|
2009-02-18 17:57:31 +00:00
|
|
|
GstRTSPResult res;
|
2012-11-27 11:24:21 +00:00
|
|
|
GstRTSPSession *session = NULL;
|
2013-07-22 12:25:04 +00:00
|
|
|
GstRTSPContext sctx = { NULL }, *ctx;
|
2011-01-12 14:37:39 +00:00
|
|
|
GstRTSPMessage response = { 0 };
|
2014-05-02 18:59:23 +00:00
|
|
|
gchar *unsupported_reqs = NULL;
|
2017-04-22 12:26:07 +00:00
|
|
|
gchar *sessid = NULL, *pipelined_request_id = NULL;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
if (!(ctx = gst_rtsp_context_get_current ())) {
|
|
|
|
ctx = &sctx;
|
|
|
|
ctx->auth = priv->auth;
|
|
|
|
gst_rtsp_context_push_current (ctx);
|
2013-07-15 09:57:49 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->conn = priv->connection;
|
|
|
|
ctx->client = client;
|
|
|
|
ctx->request = request;
|
|
|
|
ctx->response = &response;
|
2011-01-12 12:16:08 +00:00
|
|
|
|
2009-11-21 00:17:25 +00:00
|
|
|
if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
|
|
|
|
gst_rtsp_message_dump (request);
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
gst_rtsp_message_parse_request (request, &method, &uristr, &version);
|
2009-01-22 16:58:19 +00:00
|
|
|
|
2013-11-29 09:53:08 +00:00
|
|
|
GST_INFO ("client %p: received a request %s %s %s", client,
|
|
|
|
gst_rtsp_method_as_text (method), uristr,
|
|
|
|
gst_rtsp_version_as_text (version));
|
|
|
|
|
2012-11-27 11:24:21 +00:00
|
|
|
/* we can only handle 1.0 requests */
|
2017-04-22 12:26:07 +00:00
|
|
|
if (version != GST_RTSP_VERSION_1_0 && version != GST_RTSP_VERSION_2_0)
|
2012-11-27 11:24:21 +00:00
|
|
|
goto not_supported;
|
|
|
|
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->method = method;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* we always try to parse the url first */
|
2013-06-20 09:17:29 +00:00
|
|
|
if (strcmp (uristr, "*") == 0) {
|
|
|
|
/* special case where we have * as uri, keep uri = NULL */
|
2013-11-12 09:55:14 +00:00
|
|
|
} else if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK) {
|
|
|
|
/* check if the uristr is an absolute path <=> scheme and host information
|
|
|
|
* is missing */
|
|
|
|
gchar *scheme;
|
|
|
|
|
|
|
|
scheme = g_uri_parse_scheme (uristr);
|
|
|
|
if (scheme == NULL && g_str_has_prefix (uristr, "/")) {
|
|
|
|
gchar *absolute_uristr = NULL;
|
|
|
|
|
|
|
|
GST_WARNING_OBJECT (client, "request doesn't contain absolute url");
|
|
|
|
if (priv->server_ip == NULL) {
|
|
|
|
GST_WARNING_OBJECT (client, "host information missing");
|
|
|
|
goto bad_request;
|
|
|
|
}
|
|
|
|
|
2013-11-15 15:35:05 +00:00
|
|
|
absolute_uristr =
|
|
|
|
g_strdup_printf ("rtsp://%s%s", priv->server_ip, uristr);
|
2013-11-12 09:55:14 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (client, "absolute url: %s", absolute_uristr);
|
|
|
|
if (gst_rtsp_url_parse (absolute_uristr, &uri) != GST_RTSP_OK) {
|
|
|
|
g_free (absolute_uristr);
|
|
|
|
goto bad_request;
|
|
|
|
}
|
|
|
|
g_free (absolute_uristr);
|
|
|
|
} else {
|
|
|
|
g_free (scheme);
|
|
|
|
goto bad_request;
|
|
|
|
}
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* get the session if there is any */
|
2017-04-22 12:26:07 +00:00
|
|
|
res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_PIPELINED_REQUESTS,
|
|
|
|
&pipelined_request_id, 0);
|
|
|
|
if (res == GST_RTSP_OK) {
|
|
|
|
sessid = g_hash_table_lookup (client->priv->pipelined_requests,
|
|
|
|
pipelined_request_id);
|
|
|
|
|
|
|
|
if (!sessid)
|
|
|
|
res = GST_RTSP_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
res =
|
|
|
|
gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
if (res == GST_RTSP_OK) {
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->session_pool == NULL)
|
2009-02-18 17:57:31 +00:00
|
|
|
goto no_pool;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* we had a session in the request, find it again */
|
2012-11-29 10:11:05 +00:00
|
|
|
if (!(session = gst_rtsp_session_pool_find (priv->session_pool, sessid)))
|
2009-02-18 17:57:31 +00:00
|
|
|
goto session_not_found;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-03-11 19:03:06 +00:00
|
|
|
/* we add the session to the client list of watched sessions. When a session
|
|
|
|
* disappears because it times out, we will be notified. If all sessions are
|
|
|
|
* gone, we will close the connection */
|
2009-03-11 18:38:06 +00:00
|
|
|
client_watch_session (client, session);
|
2012-11-27 11:24:21 +00:00
|
|
|
}
|
2009-01-20 12:57:47 +00:00
|
|
|
|
2012-11-27 11:24:21 +00:00
|
|
|
/* sanitize the uri */
|
2013-06-20 09:17:29 +00:00
|
|
|
if (uri)
|
|
|
|
sanitize_uri (uri);
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx->uri = uri;
|
|
|
|
ctx->session = session;
|
2011-01-12 12:16:08 +00:00
|
|
|
|
2013-07-09 14:04:35 +00:00
|
|
|
if (!gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_URL))
|
|
|
|
goto not_authorized;
|
2011-01-11 23:17:54 +00:00
|
|
|
|
2014-05-02 18:59:23 +00:00
|
|
|
/* handle any 'Require' headers */
|
2015-06-18 11:12:04 +00:00
|
|
|
if (!check_request_requirements (ctx, &unsupported_reqs))
|
2014-05-02 18:59:23 +00:00
|
|
|
goto unsupported_requirement;
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
/* now see what is asked and dispatch to a dedicated handler */
|
|
|
|
switch (method) {
|
|
|
|
case GST_RTSP_OPTIONS:
|
2017-04-22 12:26:07 +00:00
|
|
|
priv->version = version;
|
|
|
|
handle_options_request (client, ctx, version);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_DESCRIBE:
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_describe_request (client, ctx);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_SETUP:
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_setup_request (client, ctx);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_PLAY:
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_play_request (client, ctx);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_PAUSE:
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_pause_request (client, ctx);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_TEARDOWN:
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_teardown_request (client, ctx);
|
2009-02-18 17:57:31 +00:00
|
|
|
break;
|
2009-05-26 15:25:59 +00:00
|
|
|
case GST_RTSP_SET_PARAMETER:
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_set_param_request (client, ctx);
|
2009-06-09 22:01:07 +00:00
|
|
|
break;
|
2009-02-18 17:57:31 +00:00
|
|
|
case GST_RTSP_GET_PARAMETER:
|
2013-07-22 12:25:04 +00:00
|
|
|
handle_get_param_request (client, ctx);
|
2009-05-26 15:25:59 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_ANNOUNCE:
|
2017-04-22 12:26:07 +00:00
|
|
|
if (version >= GST_RTSP_VERSION_2_0)
|
|
|
|
goto invalid_command_for_version;
|
2015-01-09 11:40:47 +00:00
|
|
|
handle_announce_request (client, ctx);
|
|
|
|
break;
|
2009-02-18 17:57:31 +00:00
|
|
|
case GST_RTSP_RECORD:
|
2017-04-22 12:26:07 +00:00
|
|
|
if (version >= GST_RTSP_VERSION_2_0)
|
|
|
|
goto invalid_command_for_version;
|
2015-01-09 11:40:47 +00:00
|
|
|
handle_record_request (client, ctx);
|
|
|
|
break;
|
2009-02-18 17:57:31 +00:00
|
|
|
case GST_RTSP_REDIRECT:
|
2012-11-27 11:33:02 +00:00
|
|
|
goto not_implemented;
|
2009-02-18 17:57:31 +00:00
|
|
|
case GST_RTSP_INVALID:
|
|
|
|
default:
|
2012-11-27 11:33:02 +00:00
|
|
|
goto bad_request;
|
2009-02-18 17:57:31 +00:00
|
|
|
}
|
2012-11-27 11:24:21 +00:00
|
|
|
|
|
|
|
done:
|
2013-07-22 12:25:04 +00:00
|
|
|
if (ctx == &sctx)
|
|
|
|
gst_rtsp_context_pop_current (ctx);
|
2009-02-18 17:57:31 +00:00
|
|
|
if (session)
|
|
|
|
g_object_unref (session);
|
2012-11-27 11:24:21 +00:00
|
|
|
if (uri)
|
|
|
|
gst_rtsp_url_free (uri);
|
2009-02-18 17:57:31 +00:00
|
|
|
return;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2012-11-27 11:24:21 +00:00
|
|
|
not_supported:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: version %d not supported", client, version);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
|
2013-07-22 12:25:04 +00:00
|
|
|
ctx);
|
2012-11-27 11:24:21 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2017-04-22 12:26:07 +00:00
|
|
|
invalid_command_for_version:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: invalid command for version", client);
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
|
|
|
goto done;
|
|
|
|
}
|
2012-11-27 11:24:21 +00:00
|
|
|
bad_request:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: bad request", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
2012-11-27 11:24:21 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2009-02-18 17:57:31 +00:00
|
|
|
no_pool:
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no pool configured", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
|
2012-11-27 11:24:21 +00:00
|
|
|
goto done;
|
2009-02-18 17:57:31 +00:00
|
|
|
}
|
|
|
|
session_not_found:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: session not found", client);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
|
2012-11-27 11:24:21 +00:00
|
|
|
goto done;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
2011-01-11 23:17:54 +00:00
|
|
|
not_authorized:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: not allowed", client);
|
2013-09-26 07:41:10 +00:00
|
|
|
/* error reply is already sent */
|
2012-11-27 11:24:21 +00:00
|
|
|
goto done;
|
2011-01-11 23:17:54 +00:00
|
|
|
}
|
2014-05-02 18:59:23 +00:00
|
|
|
unsupported_requirement:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: Required option is not supported (%s)", client,
|
|
|
|
unsupported_reqs);
|
|
|
|
send_option_not_supported_response (client, ctx, unsupported_reqs);
|
|
|
|
g_free (unsupported_reqs);
|
|
|
|
goto done;
|
|
|
|
}
|
2012-11-27 11:33:02 +00:00
|
|
|
not_implemented:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: method %d not implemented", client, method);
|
2013-07-22 12:25:04 +00:00
|
|
|
send_generic_response (client, GST_RTSP_STS_NOT_IMPLEMENTED, ctx);
|
2012-11-27 11:33:02 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2013-08-08 14:57:42 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
handle_response (GstRTSPClient * client, GstRTSPMessage * response)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
GstRTSPResult res;
|
|
|
|
GstRTSPSession *session = NULL;
|
|
|
|
GstRTSPContext sctx = { NULL }, *ctx;
|
|
|
|
gchar *sessid;
|
|
|
|
|
|
|
|
if (!(ctx = gst_rtsp_context_get_current ())) {
|
|
|
|
ctx = &sctx;
|
|
|
|
ctx->auth = priv->auth;
|
|
|
|
gst_rtsp_context_push_current (ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->conn = priv->connection;
|
|
|
|
ctx->client = client;
|
|
|
|
ctx->request = NULL;
|
|
|
|
ctx->uri = NULL;
|
|
|
|
ctx->method = GST_RTSP_INVALID;
|
|
|
|
ctx->response = response;
|
|
|
|
|
|
|
|
if (gst_debug_category_get_threshold (rtsp_client_debug) >= GST_LEVEL_LOG) {
|
|
|
|
gst_rtsp_message_dump (response);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_INFO ("client %p: received a response", client);
|
|
|
|
|
|
|
|
/* get the session if there is any */
|
|
|
|
res =
|
|
|
|
gst_rtsp_message_get_header (response, GST_RTSP_HDR_SESSION, &sessid, 0);
|
|
|
|
if (res == GST_RTSP_OK) {
|
|
|
|
if (priv->session_pool == NULL)
|
|
|
|
goto no_pool;
|
|
|
|
|
|
|
|
/* we had a session in the request, find it again */
|
|
|
|
if (!(session = gst_rtsp_session_pool_find (priv->session_pool, sessid)))
|
|
|
|
goto session_not_found;
|
|
|
|
|
|
|
|
/* we add the session to the client list of watched sessions. When a session
|
|
|
|
* disappears because it times out, we will be notified. If all sessions are
|
|
|
|
* gone, we will close the connection */
|
|
|
|
client_watch_session (client, session);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->session = session;
|
|
|
|
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_HANDLE_RESPONSE],
|
|
|
|
0, ctx);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (ctx == &sctx)
|
|
|
|
gst_rtsp_context_pop_current (ctx);
|
|
|
|
if (session)
|
|
|
|
g_object_unref (session);
|
|
|
|
return;
|
|
|
|
|
|
|
|
no_pool:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: no pool configured", client);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
session_not_found:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: session not found", client);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
static void
|
2009-05-26 17:01:10 +00:00
|
|
|
handle_data (GstRTSPClient * client, GstRTSPMessage * message)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-11 15:45:12 +00:00
|
|
|
GstRTSPResult res;
|
|
|
|
guint8 channel;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
|
|
|
GstBuffer *buffer;
|
2014-09-09 16:11:39 +00:00
|
|
|
GstRTSPStreamTransport *trans;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
/* find the stream for this message */
|
2009-03-11 15:45:12 +00:00
|
|
|
res = gst_rtsp_message_parse_data (message, &channel);
|
|
|
|
if (res != GST_RTSP_OK)
|
|
|
|
return;
|
|
|
|
|
2015-01-16 19:04:01 +00:00
|
|
|
gst_rtsp_message_get_body (message, &data, &size);
|
|
|
|
if (size < 2)
|
|
|
|
goto invalid_length;
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
gst_rtsp_message_steal_body (message, &data, &size);
|
|
|
|
|
2015-01-19 20:35:15 +00:00
|
|
|
/* Strip trailing \0 (which GstRTSPConnection adds) */
|
|
|
|
--size;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new_wrapped (data, size);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2014-09-22 07:30:39 +00:00
|
|
|
trans =
|
|
|
|
g_hash_table_lookup (priv->transports, GINT_TO_POINTER ((gint) channel));
|
2014-09-09 16:11:39 +00:00
|
|
|
if (trans) {
|
2018-02-28 19:12:43 +00:00
|
|
|
GSocketAddress *addr;
|
|
|
|
|
|
|
|
/* Only create the socket address once for the transport, we don't really
|
|
|
|
* want to do that for every single packet.
|
|
|
|
*
|
|
|
|
* The netaddress meta is later used by the RTP stack to know where
|
|
|
|
* packets came from and allows us to match it again to a stream transport
|
|
|
|
*
|
|
|
|
* In theory we could use the remote socket address of the RTSP connection
|
|
|
|
* here, but this would fail with a custom configure_client_transport()
|
|
|
|
* implementation.
|
|
|
|
*/
|
|
|
|
if (!(addr =
|
|
|
|
g_object_get_data (G_OBJECT (trans), "rtsp-client.remote-addr"))) {
|
|
|
|
const GstRTSPTransport *tr;
|
|
|
|
GInetAddress *iaddr;
|
|
|
|
|
|
|
|
tr = gst_rtsp_stream_transport_get_transport (trans);
|
|
|
|
iaddr = g_inet_address_new_from_string (tr->destination);
|
|
|
|
if (iaddr) {
|
|
|
|
addr = g_inet_socket_address_new (iaddr, tr->client_port.min);
|
|
|
|
g_object_unref (iaddr);
|
|
|
|
g_object_set_data_full (G_OBJECT (trans), "rtsp-client.remote-addr",
|
|
|
|
addr, (GDestroyNotify) g_object_unref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr) {
|
|
|
|
gst_buffer_add_net_address_meta (buffer, addr);
|
|
|
|
}
|
|
|
|
|
2014-09-09 16:11:39 +00:00
|
|
|
/* dispatch to the stream based on the channel number */
|
2015-01-19 20:35:15 +00:00
|
|
|
GST_LOG_OBJECT (client, "%u bytes of data on channel %u", size, channel);
|
2014-09-09 16:11:39 +00:00
|
|
|
gst_rtsp_stream_transport_recv_data (trans, channel, buffer);
|
|
|
|
} else {
|
2015-01-19 20:35:15 +00:00
|
|
|
GST_DEBUG_OBJECT (client, "received %u bytes of data for "
|
|
|
|
"unknown channel %u", size, channel);
|
2009-04-14 21:38:58 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2014-09-09 16:11:39 +00:00
|
|
|
}
|
2015-01-19 20:18:20 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2015-01-16 19:04:01 +00:00
|
|
|
invalid_length:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("client %p: Short message received, ignoring", client);
|
|
|
|
return;
|
|
|
|
}
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_session_pool:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-09 23:07:25 +00:00
|
|
|
* @pool: (transfer none) (nullable): a #GstRTSPSessionPool
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
|
|
|
* Set @pool as the sessionpool for @client which it will use to find
|
2009-01-22 14:33:29 +00:00
|
|
|
* or allocate sessions. the sessionpool is usually inherited from the server
|
|
|
|
* that created the client but can be overridden later.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
void
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_set_session_pool (GstRTSPClient * client,
|
|
|
|
GstRTSPSessionPool * pool)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPSessionPool *old;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (pool)
|
|
|
|
g_object_ref (pool);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
old = priv->session_pool;
|
|
|
|
priv->session_pool = pool;
|
2014-07-01 10:13:47 +00:00
|
|
|
|
2014-07-09 13:01:31 +00:00
|
|
|
if (priv->session_removed_id) {
|
2014-07-01 10:13:47 +00:00
|
|
|
g_signal_handler_disconnect (old, priv->session_removed_id);
|
|
|
|
priv->session_removed_id = 0;
|
2014-07-09 13:01:31 +00:00
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-26 15:30:16 +00:00
|
|
|
|
2014-07-01 10:13:47 +00:00
|
|
|
/* FIXME, should remove all sessions from the old pool for this client */
|
2012-11-26 15:30:16 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_get_session_pool:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPSessionPool object that @client uses to manage its sessions.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): a #GstRTSPSessionPool, unref after usage.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
GstRTSPSessionPool *
|
2009-05-26 17:01:10 +00:00
|
|
|
gst_rtsp_client_get_session_pool (GstRTSPClient * client)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPSessionPool *result;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->session_pool))
|
2008-10-09 12:29:12 +00:00
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
return result;
|
2011-01-12 09:42:52 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 18:46:21 +00:00
|
|
|
/**
|
2012-11-26 11:34:05 +00:00
|
|
|
* gst_rtsp_client_set_mount_points:
|
2009-01-20 18:46:21 +00:00
|
|
|
* @client: a #GstRTSPClient
|
2018-02-09 23:07:25 +00:00
|
|
|
* @mounts: (transfer none) (nullable): a #GstRTSPMountPoints
|
2009-01-20 18:46:21 +00:00
|
|
|
*
|
2012-11-26 11:34:05 +00:00
|
|
|
* Set @mounts as the mount points for @client which it will use to map urls
|
|
|
|
* to media streams. These mount points are usually inherited from the server that
|
2009-01-22 14:33:29 +00:00
|
|
|
* created the client but can be overriden later.
|
2009-01-20 18:46:21 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-11-26 11:34:05 +00:00
|
|
|
gst_rtsp_client_set_mount_points (GstRTSPClient * client,
|
|
|
|
GstRTSPMountPoints * mounts)
|
2009-01-20 18:46:21 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *old;
|
2009-01-20 18:46:21 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (mounts)
|
|
|
|
g_object_ref (mounts);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
old = priv->mount_points;
|
|
|
|
priv->mount_points = mounts;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2009-01-20 18:46:21 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2009-01-20 18:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-26 11:34:05 +00:00
|
|
|
* gst_rtsp_client_get_mount_points:
|
2009-01-20 18:46:21 +00:00
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
2012-11-26 11:34:05 +00:00
|
|
|
* Get the #GstRTSPMountPoints object that @client uses to manage its sessions.
|
2009-01-20 18:46:21 +00:00
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): a #GstRTSPMountPoints, unref after usage.
|
2009-01-20 18:46:21 +00:00
|
|
|
*/
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *
|
|
|
|
gst_rtsp_client_get_mount_points (GstRTSPClient * client)
|
2009-01-20 18:46:21 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *result;
|
2009-01-20 18:46:21 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->mount_points))
|
2009-01-20 18:46:21 +00:00
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2009-01-20 18:46:21 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-03-27 15:21:03 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_content_length_limit:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @limit: Content-Length limit
|
|
|
|
*
|
|
|
|
* Configure @client to use the specified Content-Length limit.
|
|
|
|
*
|
|
|
|
* Define an appropriate request size limit and reject requests exceeding the
|
|
|
|
* limit with response status 413 Request Entity Too Large
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_client_set_content_length_limit (GstRTSPClient * client, guint limit)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
|
|
|
priv = client->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->content_length_limit = limit;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_get_content_length_limit:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
|
|
|
* Get the Content-Length limit of @client.
|
|
|
|
*
|
|
|
|
* Returns: the Content-Length limit.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_client_get_content_length_limit (GstRTSPClient * client)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
glong content_length_limit;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), -1);
|
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
content_length_limit = priv->content_length_limit;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return content_length_limit;
|
|
|
|
}
|
|
|
|
|
2011-01-11 23:17:54 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_auth:
|
|
|
|
* @client: a #GstRTSPClient
|
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 @client.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_client_set_auth (GstRTSPClient * client, GstRTSPAuth * auth)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2011-01-11 23:17:54 +00:00
|
|
|
GstRTSPAuth *old;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (auth)
|
|
|
|
g_object_ref (auth);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
old = priv->auth;
|
|
|
|
priv->auth = auth;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2011-01-11 23:17:54 +00:00
|
|
|
|
2012-11-26 15:30:16 +00:00
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
2011-01-11 23:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_get_auth:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPAuth used as the authentication manager of @client.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstRTSPAuth of @client.
|
|
|
|
* g_object_unref() after usage.
|
2011-01-11 23:17:54 +00:00
|
|
|
*/
|
|
|
|
GstRTSPAuth *
|
|
|
|
gst_rtsp_client_get_auth (GstRTSPClient * client)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2011-01-11 23:17:54 +00:00
|
|
|
GstRTSPAuth *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->auth))
|
2011-01-11 23:17:54 +00:00
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2011-01-11 23:17:54 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-07-10 15:06:36 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_thread_pool:
|
|
|
|
* @client: a #GstRTSPClient
|
2018-02-09 23:07:25 +00:00
|
|
|
* @pool: (transfer none) (nullable): a #GstRTSPThreadPool
|
2013-07-10 15:06:36 +00:00
|
|
|
*
|
|
|
|
* configure @pool to be used as the thread pool of @client.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_client_set_thread_pool (GstRTSPClient * client,
|
|
|
|
GstRTSPThreadPool * pool)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
GstRTSPThreadPool *old;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
if (pool)
|
|
|
|
g_object_ref (pool);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
old = priv->thread_pool;
|
|
|
|
priv->thread_pool = pool;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_get_thread_pool:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPThreadPool used as the thread pool of @client.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstRTSPThreadPool of @client. g_object_unref() after
|
2013-07-10 15:06:36 +00:00
|
|
|
* usage.
|
|
|
|
*/
|
|
|
|
GstRTSPThreadPool *
|
|
|
|
gst_rtsp_client_get_thread_pool (GstRTSPClient * client)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
GstRTSPThreadPool *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
|
|
|
|
|
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->thread_pool))
|
|
|
|
g_object_ref (result);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-05-30 05:18:22 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_connection:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @conn: (transfer full): a #GstRTSPConnection
|
|
|
|
*
|
|
|
|
* Set the #GstRTSPConnection of @client. This function takes ownership of
|
|
|
|
* @conn.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_client_set_connection (GstRTSPClient * client,
|
|
|
|
GstRTSPConnection * conn)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
GSocket *read_socket;
|
|
|
|
GSocketAddress *address;
|
|
|
|
GstRTSPUrl *url;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), FALSE);
|
|
|
|
g_return_val_if_fail (conn != NULL, FALSE);
|
|
|
|
|
|
|
|
priv = client->priv;
|
|
|
|
|
2019-03-27 15:21:03 +00:00
|
|
|
gst_rtsp_connection_set_content_length_limit (conn,
|
|
|
|
priv->content_length_limit);
|
2013-05-30 05:18:22 +00:00
|
|
|
read_socket = gst_rtsp_connection_get_read_socket (conn);
|
|
|
|
|
2013-06-12 08:56:16 +00:00
|
|
|
if (!(address = g_socket_get_local_address (read_socket, &error)))
|
2013-05-30 05:18:22 +00:00
|
|
|
goto no_address;
|
|
|
|
|
|
|
|
g_free (priv->server_ip);
|
|
|
|
/* keep the original ip that the client connected to */
|
|
|
|
if (G_IS_INET_SOCKET_ADDRESS (address)) {
|
|
|
|
GInetAddress *iaddr;
|
|
|
|
|
|
|
|
iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (address));
|
|
|
|
|
|
|
|
/* socket might be ipv6 but adress still ipv4 */
|
|
|
|
priv->is_ipv6 = g_inet_address_get_family (iaddr) == G_SOCKET_FAMILY_IPV6;
|
|
|
|
priv->server_ip = g_inet_address_to_string (iaddr);
|
|
|
|
g_object_unref (address);
|
|
|
|
} else {
|
|
|
|
priv->is_ipv6 = g_socket_get_family (read_socket) == G_SOCKET_FAMILY_IPV6;
|
|
|
|
priv->server_ip = g_strdup ("unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_INFO ("client %p connected to server ip %s, ipv6 = %d", client,
|
|
|
|
priv->server_ip, priv->is_ipv6);
|
|
|
|
|
|
|
|
url = gst_rtsp_connection_get_url (conn);
|
|
|
|
GST_INFO ("added new client %p ip %s:%d", client, url->host, url->port);
|
|
|
|
|
|
|
|
priv->connection = conn;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_address:
|
|
|
|
{
|
2013-07-01 13:18:43 +00:00
|
|
|
GST_ERROR ("could not get local address %s", error->message);
|
2013-05-30 05:18:22 +00:00
|
|
|
g_error_free (error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-15 10:17:34 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_get_connection:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPConnection of @client.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer none) (nullable): the #GstRTSPConnection of @client.
|
2013-04-15 10:17:34 +00:00
|
|
|
* The connection object returned remains valid until the client is freed.
|
|
|
|
*/
|
|
|
|
GstRTSPConnection *
|
|
|
|
gst_rtsp_client_get_connection (GstRTSPClient * client)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
|
|
|
|
|
|
|
|
return client->priv->connection;
|
|
|
|
}
|
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_send_func:
|
|
|
|
* @client: a #GstRTSPClient
|
2014-03-23 20:24:48 +00:00
|
|
|
* @func: (scope notified): a #GstRTSPClientSendFunc
|
|
|
|
* @user_data: (closure): user data passed to @func
|
|
|
|
* @notify: (allow-none): called when @user_data is no longer in use
|
2012-11-26 16:20:39 +00:00
|
|
|
*
|
|
|
|
* Set @func as the callback that will be called when a new message needs to be
|
|
|
|
* sent to the client. @user_data is passed to @func and @notify is called when
|
|
|
|
* @user_data is no longer in use.
|
2013-07-11 14:57:14 +00:00
|
|
|
*
|
|
|
|
* By default, the client will send the messages on the #GstRTSPConnection that
|
|
|
|
* was configured with gst_rtsp_client_attach() was called.
|
2019-01-25 12:22:42 +00:00
|
|
|
*
|
|
|
|
* It is only allowed to set either a `send_func` or a `send_messages_func`
|
|
|
|
* but not both at the same time.
|
2012-11-26 16:20:39 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_client_set_send_func (GstRTSPClient * client,
|
|
|
|
GstRTSPClientSendFunc func, gpointer user_data, GDestroyNotify notify)
|
2009-02-18 17:57:31 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2012-11-26 16:35:51 +00:00
|
|
|
GDestroyNotify old_notify;
|
2012-11-26 16:28:29 +00:00
|
|
|
gpointer old_data;
|
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
2013-01-28 09:31:50 +00:00
|
|
|
g_mutex_lock (&priv->send_lock);
|
2019-01-25 12:22:42 +00:00
|
|
|
g_assert (func == NULL || priv->send_messages_func == NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->send_func = func;
|
|
|
|
old_notify = priv->send_notify;
|
|
|
|
old_data = priv->send_data;
|
|
|
|
priv->send_notify = notify;
|
|
|
|
priv->send_data = user_data;
|
2013-01-28 09:31:50 +00:00
|
|
|
g_mutex_unlock (&priv->send_lock);
|
2012-11-26 16:28:29 +00:00
|
|
|
|
2012-11-26 16:35:51 +00:00
|
|
|
if (old_notify)
|
|
|
|
old_notify (old_data);
|
2012-11-26 16:20:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 19:18:46 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_set_send_messages_func:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @func: (scope notified): a #GstRTSPClientSendMessagesFunc
|
|
|
|
* @user_data: (closure): user data passed to @func
|
|
|
|
* @notify: (allow-none): called when @user_data is no longer in use
|
|
|
|
*
|
|
|
|
* Set @func as the callback that will be called when new messages needs to be
|
|
|
|
* sent to the client. @user_data is passed to @func and @notify is called when
|
|
|
|
* @user_data is no longer in use.
|
|
|
|
*
|
|
|
|
* By default, the client will send the messages on the #GstRTSPConnection that
|
|
|
|
* was configured with gst_rtsp_client_attach() was called.
|
|
|
|
*
|
2019-01-25 12:22:42 +00:00
|
|
|
* It is only allowed to set either a `send_func` or a `send_messages_func`
|
|
|
|
* but not both at the same time.
|
|
|
|
*
|
2018-09-17 19:18:46 +00:00
|
|
|
* Since: 1.16
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_client_set_send_messages_func (GstRTSPClient * client,
|
|
|
|
GstRTSPClientSendMessagesFunc func, gpointer user_data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
GDestroyNotify old_notify;
|
|
|
|
gpointer old_data;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_CLIENT (client));
|
|
|
|
|
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->send_lock);
|
2019-01-25 12:22:42 +00:00
|
|
|
g_assert (func == NULL || priv->send_func == NULL);
|
2018-09-17 19:18:46 +00:00
|
|
|
priv->send_messages_func = func;
|
|
|
|
old_notify = priv->send_messages_notify;
|
|
|
|
old_data = priv->send_messages_data;
|
|
|
|
priv->send_messages_notify = notify;
|
|
|
|
priv->send_messages_data = user_data;
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
|
|
|
|
if (old_notify)
|
|
|
|
old_notify (old_data);
|
|
|
|
}
|
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_handle_message:
|
|
|
|
* @client: a #GstRTSPClient
|
2014-03-23 20:24:48 +00:00
|
|
|
* @message: (transfer none): an #GstRTSPMessage
|
2012-11-26 16:20:39 +00:00
|
|
|
*
|
|
|
|
* Let the client handle @message.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPResult.
|
|
|
|
*/
|
|
|
|
GstRTSPResult
|
|
|
|
gst_rtsp_client_handle_message (GstRTSPClient * client,
|
|
|
|
GstRTSPMessage * message)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), GST_RTSP_EINVAL);
|
|
|
|
g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2009-03-04 11:44:01 +00:00
|
|
|
switch (message->type) {
|
|
|
|
case GST_RTSP_MESSAGE_REQUEST:
|
|
|
|
handle_request (client, message);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_MESSAGE_RESPONSE:
|
2013-08-08 14:57:42 +00:00
|
|
|
handle_response (client, message);
|
2009-03-04 11:44:01 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_MESSAGE_DATA:
|
2009-03-11 15:45:12 +00:00
|
|
|
handle_data (client, message);
|
2009-03-04 11:44:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-02-18 17:57:31 +00:00
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-10 21:32:12 +00:00
|
|
|
/**
|
2013-07-12 13:13:48 +00:00
|
|
|
* gst_rtsp_client_send_message:
|
2013-06-10 21:32:12 +00:00
|
|
|
* @client: a #GstRTSPClient
|
2014-06-11 23:42:08 +00:00
|
|
|
* @session: (allow-none) (transfer none): a #GstRTSPSession to send
|
|
|
|
* the message to or %NULL
|
2014-03-23 20:24:48 +00:00
|
|
|
* @message: (transfer none): The #GstRTSPMessage to send
|
2013-06-10 21:32:12 +00:00
|
|
|
*
|
2013-07-12 13:13:48 +00:00
|
|
|
* Send a message message to the remote end. @message must be a
|
|
|
|
* #GST_RTSP_MESSAGE_REQUEST or a #GST_RTSP_MESSAGE_RESPONSE.
|
2013-06-10 21:32:12 +00:00
|
|
|
*/
|
2013-06-25 13:09:13 +00:00
|
|
|
GstRTSPResult
|
2013-07-12 13:13:48 +00:00
|
|
|
gst_rtsp_client_send_message (GstRTSPClient * client, GstRTSPSession * session,
|
|
|
|
GstRTSPMessage * message)
|
2013-06-10 21:32:12 +00:00
|
|
|
{
|
2014-05-01 04:07:08 +00:00
|
|
|
GstRTSPContext sctx = { NULL }
|
|
|
|
, *ctx;
|
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
|
2013-06-25 13:09:13 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), GST_RTSP_EINVAL);
|
2013-07-12 13:13:48 +00:00
|
|
|
g_return_val_if_fail (message != NULL, GST_RTSP_EINVAL);
|
|
|
|
g_return_val_if_fail (message->type == GST_RTSP_MESSAGE_REQUEST ||
|
|
|
|
message->type == GST_RTSP_MESSAGE_RESPONSE, GST_RTSP_EINVAL);
|
2013-06-25 13:09:13 +00:00
|
|
|
|
2014-05-01 04:07:08 +00:00
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
if (!(ctx = gst_rtsp_context_get_current ())) {
|
|
|
|
ctx = &sctx;
|
|
|
|
ctx->auth = priv->auth;
|
|
|
|
gst_rtsp_context_push_current (ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->conn = priv->connection;
|
|
|
|
ctx->client = client;
|
|
|
|
ctx->session = session;
|
|
|
|
|
|
|
|
send_message (client, ctx, message, FALSE);
|
|
|
|
|
|
|
|
if (ctx == &sctx)
|
|
|
|
gst_rtsp_context_pop_current (ctx);
|
2013-06-25 13:09:13 +00:00
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
2013-06-10 21:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 14:34:20 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_get_stream_transport:
|
|
|
|
*
|
|
|
|
* This is useful when providing a send function through
|
|
|
|
* gst_rtsp_client_set_send_func() when doing RTSP over TCP:
|
|
|
|
* the send function must call gst_rtsp_stream_transport_message_sent ()
|
|
|
|
* on the appropriate transport when data has been received for streaming
|
|
|
|
* to continue.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none) (nullable): the #GstRTSPStreamTransport associated with @channel.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
GstRTSPStreamTransport *
|
|
|
|
gst_rtsp_client_get_stream_transport (GstRTSPClient * self, guint8 channel)
|
|
|
|
{
|
|
|
|
return g_hash_table_lookup (self->priv->transports,
|
|
|
|
GINT_TO_POINTER ((gint) channel));
|
|
|
|
}
|
|
|
|
|
2018-09-17 19:18:46 +00:00
|
|
|
static gboolean
|
|
|
|
do_send_messages (GstRTSPClient * client, GstRTSPMessage * messages,
|
|
|
|
guint n_messages, gboolean close, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
|
|
|
guint id = 0;
|
|
|
|
GstRTSPResult ret;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* send the message */
|
|
|
|
ret = gst_rtsp_watch_send_messages (priv->watch, messages, n_messages, &id);
|
|
|
|
if (ret != GST_RTSP_OK)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* if close flag is set, store the seq number so we can wait until it's
|
|
|
|
* written to the client to close the connection */
|
|
|
|
if (close)
|
|
|
|
priv->close_seq = id;
|
|
|
|
|
|
|
|
for (i = 0; i < n_messages; i++) {
|
|
|
|
if (gst_rtsp_message_get_type (&messages[i]) == GST_RTSP_MESSAGE_DATA) {
|
|
|
|
guint8 channel = 0;
|
|
|
|
GstRTSPResult r;
|
|
|
|
|
|
|
|
/* We assume that all data messages in the list are for the
|
|
|
|
* same channel */
|
|
|
|
r = gst_rtsp_message_parse_data (&messages[i], &channel);
|
|
|
|
if (r != GST_RTSP_OK) {
|
|
|
|
ret = r;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if the message has been queued for transmission in watch */
|
|
|
|
if (id) {
|
|
|
|
/* store the seq number so we can wait until it has been sent */
|
|
|
|
GST_DEBUG_OBJECT (client, "wait for message %d, channel %d", id,
|
|
|
|
channel);
|
|
|
|
set_data_seq (client, channel, id);
|
|
|
|
} else {
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
trans =
|
|
|
|
g_hash_table_lookup (priv->transports,
|
|
|
|
GINT_TO_POINTER ((gint) channel));
|
|
|
|
if (trans) {
|
|
|
|
GST_DEBUG_OBJECT (client, "emit 'message-sent' signal");
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
gst_rtsp_stream_transport_message_sent (trans);
|
|
|
|
g_mutex_lock (&priv->send_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret == GST_RTSP_OK;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (client, "got error %d", ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-26 16:20:39 +00:00
|
|
|
static GstRTSPResult
|
|
|
|
message_received (GstRTSPWatch * watch, GstRTSPMessage * message,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
return gst_rtsp_client_handle_message (GST_RTSP_CLIENT (user_data), message);
|
|
|
|
}
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
static GstRTSPResult
|
2009-05-26 17:01:10 +00:00
|
|
|
message_sent (GstRTSPWatch * watch, guint cseq, gpointer user_data)
|
2009-02-18 17:57:31 +00:00
|
|
|
{
|
2012-11-26 15:45:04 +00:00
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
GstRTSPStreamTransport *trans = NULL;
|
|
|
|
guint8 channel = 0;
|
|
|
|
gboolean close = FALSE;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->send_lock);
|
|
|
|
|
|
|
|
if (get_data_channel (client, cseq, &channel)) {
|
|
|
|
trans = g_hash_table_lookup (priv->transports, GINT_TO_POINTER (channel));
|
|
|
|
set_data_seq (client, channel, 0);
|
|
|
|
}
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->close_seq && priv->close_seq == cseq) {
|
2014-07-01 10:13:47 +00:00
|
|
|
GST_INFO ("client %p: send close message", client);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
close = TRUE;
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->close_seq = 0;
|
2012-11-17 13:51:52 +00:00
|
|
|
}
|
2009-02-18 17:57:31 +00:00
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
|
|
|
|
if (trans) {
|
|
|
|
GST_DEBUG_OBJECT (client, "emit 'message-sent' signal");
|
|
|
|
gst_rtsp_stream_transport_message_sent (trans);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (close)
|
|
|
|
gst_rtsp_client_close (client);
|
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPResult
|
2009-05-26 17:01:10 +00:00
|
|
|
closed (GstRTSPWatch * watch, gpointer user_data)
|
2009-02-18 17:57:31 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-04 11:44:01 +00:00
|
|
|
const gchar *tunnelid;
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: connection closed", client);
|
2009-02-18 17:57:31 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if ((tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection))) {
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_lock (&tunnels_lock);
|
2010-04-06 09:13:51 +00:00
|
|
|
/* remove from tunnelids */
|
2009-03-04 15:33:21 +00:00
|
|
|
g_hash_table_remove (tunnels, tunnelid);
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2009-03-04 15:33:21 +00:00
|
|
|
}
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2014-04-01 11:04:21 +00:00
|
|
|
gst_rtsp_watch_set_flushing (watch, TRUE);
|
2014-08-28 11:35:15 +00:00
|
|
|
g_mutex_lock (&priv->watch_lock);
|
2013-01-28 09:31:50 +00:00
|
|
|
gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
|
2018-09-17 19:18:46 +00:00
|
|
|
gst_rtsp_client_set_send_messages_func (client, NULL, NULL, NULL);
|
2014-08-28 11:35:15 +00:00
|
|
|
g_mutex_unlock (&priv->watch_lock);
|
2013-01-28 09:31:50 +00:00
|
|
|
|
2009-02-18 17:57:31 +00:00
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPResult
|
2009-05-26 17:01:10 +00:00
|
|
|
error (GstRTSPWatch * watch, GstRTSPResult result, gpointer user_data)
|
2009-02-18 17:57:31 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = gst_rtsp_strresult (result);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("client %p: received an error %s", client, str);
|
2009-02-18 17:57:31 +00:00
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-27 17:38:27 +00:00
|
|
|
static GstRTSPResult
|
2010-03-16 17:33:23 +00:00
|
|
|
error_full (GstRTSPWatch * watch, GstRTSPResult result,
|
|
|
|
GstRTSPMessage * message, guint id, gpointer user_data)
|
2010-01-27 17:38:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
gchar *str;
|
2019-03-27 15:21:03 +00:00
|
|
|
GstRTSPContext sctx = { NULL }, *ctx;
|
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
GstRTSPMessage response = { 0 };
|
|
|
|
priv = client->priv;
|
|
|
|
|
|
|
|
if (!(ctx = gst_rtsp_context_get_current ())) {
|
|
|
|
ctx = &sctx;
|
|
|
|
ctx->auth = priv->auth;
|
|
|
|
gst_rtsp_context_push_current (ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->conn = priv->connection;
|
|
|
|
ctx->client = client;
|
|
|
|
ctx->request = message;
|
|
|
|
ctx->method = GST_RTSP_INVALID;
|
|
|
|
ctx->response = &response;
|
2010-01-27 17:38:27 +00:00
|
|
|
|
2019-03-27 15:21:03 +00:00
|
|
|
/* only return error response if it is a request */
|
|
|
|
if (!message || message->type != GST_RTSP_MESSAGE_REQUEST)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (result == GST_RTSP_ENOMEM) {
|
|
|
|
send_generic_response (client, GST_RTSP_STS_REQUEST_ENTITY_TOO_LARGE, ctx);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (result == GST_RTSP_EPARSE) {
|
|
|
|
send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (ctx == &sctx)
|
|
|
|
gst_rtsp_context_pop_current (ctx);
|
2010-01-27 17:38:27 +00:00
|
|
|
str = gst_rtsp_strresult (result);
|
2010-03-16 17:33:23 +00:00
|
|
|
GST_INFO
|
2013-05-30 08:52:46 +00:00
|
|
|
("client %p: error when handling message %p with id %d: %s",
|
|
|
|
client, message, id, str);
|
2010-01-27 17:38:27 +00:00
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
static gboolean
|
|
|
|
remember_tunnel (GstRTSPClient * client)
|
2009-03-04 11:44:01 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-04 11:44:01 +00:00
|
|
|
const gchar *tunnelid;
|
|
|
|
|
|
|
|
/* store client in the pending tunnels */
|
2012-11-29 10:11:05 +00:00
|
|
|
tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
|
2009-07-24 10:49:41 +00:00
|
|
|
if (tunnelid == NULL)
|
|
|
|
goto no_tunnelid;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* we can't have two clients connecting with the same tunnelid */
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_lock (&tunnels_lock);
|
2009-03-04 11:44:01 +00:00
|
|
|
if (g_hash_table_lookup (tunnels, tunnelid))
|
|
|
|
goto tunnel_existed;
|
|
|
|
|
|
|
|
g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
return TRUE;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-07-24 10:49:41 +00:00
|
|
|
no_tunnelid:
|
|
|
|
{
|
2010-04-06 09:13:51 +00:00
|
|
|
GST_ERROR ("client %p: no tunnelid provided", client);
|
|
|
|
return FALSE;
|
2009-07-24 10:49:41 +00:00
|
|
|
}
|
2009-03-04 11:44:01 +00:00
|
|
|
tunnel_existed:
|
|
|
|
{
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2010-12-11 09:48:42 +00:00
|
|
|
GST_ERROR ("client %p: tunnel session %s already existed", client,
|
|
|
|
tunnelid);
|
2010-04-06 09:13:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPResult
|
|
|
|
tunnel_lost (GstRTSPWatch * watch, gpointer user_data)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2010-04-06 09:13:51 +00:00
|
|
|
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_WARNING ("client %p: tunnel lost (connection %p)", client,
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->connection);
|
2010-04-06 09:13:51 +00:00
|
|
|
|
|
|
|
/* ignore error, it'll only be a problem when the client does a POST again */
|
|
|
|
remember_tunnel (client);
|
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-15 12:26:16 +00:00
|
|
|
static GstRTSPStatusCode
|
2014-04-03 10:19:51 +00:00
|
|
|
handle_tunnel (GstRTSPClient * client)
|
2009-03-04 11:44:01 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2009-03-04 11:44:01 +00:00
|
|
|
GstRTSPClient *oclient;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *opriv;
|
2014-04-03 10:19:51 +00:00
|
|
|
const gchar *tunnelid;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
tunnelid = gst_rtsp_connection_get_tunnelid (priv->connection);
|
2009-07-24 10:49:41 +00:00
|
|
|
if (tunnelid == NULL)
|
|
|
|
goto no_tunnelid;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2014-04-03 10:19:51 +00:00
|
|
|
/* check for previous tunnel */
|
2012-05-11 07:42:47 +00:00
|
|
|
g_mutex_lock (&tunnels_lock);
|
2014-04-03 10:19:51 +00:00
|
|
|
oclient = g_hash_table_lookup (tunnels, tunnelid);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2014-04-03 10:19:51 +00:00
|
|
|
if (oclient == NULL) {
|
|
|
|
/* no previous tunnel, remember tunnel */
|
|
|
|
g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
|
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2010-04-06 13:45:56 +00:00
|
|
|
|
2014-04-03 10:19:51 +00:00
|
|
|
GST_INFO ("client %p: no previous tunnel found, remembering tunnel (%p)",
|
|
|
|
client, priv->connection);
|
|
|
|
} else {
|
|
|
|
/* merge both tunnels into the first client */
|
|
|
|
/* remove the old client from the table. ref before because removing it will
|
|
|
|
* remove the ref to it. */
|
|
|
|
g_object_ref (oclient);
|
|
|
|
g_hash_table_remove (tunnels, tunnelid);
|
|
|
|
g_mutex_unlock (&tunnels_lock);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2014-04-03 10:19:51 +00:00
|
|
|
opriv = oclient->priv;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2014-08-28 11:35:15 +00:00
|
|
|
g_mutex_lock (&opriv->watch_lock);
|
2014-04-03 10:19:51 +00:00
|
|
|
if (opriv->watch == NULL)
|
|
|
|
goto tunnel_closed;
|
2018-02-15 12:26:16 +00:00
|
|
|
if (opriv->tstate == priv->tstate)
|
|
|
|
goto tunnel_duplicate_id;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2014-04-03 10:19:51 +00:00
|
|
|
GST_INFO ("client %p: found previous tunnel %p (old %p, new %p)", client,
|
|
|
|
oclient, opriv->connection, priv->connection);
|
2009-03-04 11:44:01 +00:00
|
|
|
|
2014-04-03 10:19:51 +00:00
|
|
|
gst_rtsp_connection_do_tunnel (opriv->connection, priv->connection);
|
|
|
|
gst_rtsp_watch_reset (priv->watch);
|
|
|
|
gst_rtsp_watch_reset (opriv->watch);
|
2014-08-28 11:35:15 +00:00
|
|
|
g_mutex_unlock (&opriv->watch_lock);
|
2014-04-03 10:19:51 +00:00
|
|
|
g_object_unref (oclient);
|
2014-04-02 10:03:32 +00:00
|
|
|
|
2014-04-03 10:19:51 +00:00
|
|
|
/* the old client owns the tunnel now, the new one will be freed */
|
|
|
|
g_source_destroy ((GSource *) priv->watch);
|
|
|
|
priv->watch = NULL;
|
|
|
|
gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
|
2018-09-17 19:18:46 +00:00
|
|
|
gst_rtsp_client_set_send_messages_func (client, NULL, NULL, NULL);
|
2014-04-03 10:19:51 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 12:26:16 +00:00
|
|
|
return GST_RTSP_STS_OK;
|
2009-03-04 11:44:01 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2009-07-24 10:49:41 +00:00
|
|
|
no_tunnelid:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: no tunnelid provided", client);
|
2018-02-15 12:26:16 +00:00
|
|
|
return GST_RTSP_STS_SERVICE_UNAVAILABLE;
|
2009-03-04 11:44:01 +00:00
|
|
|
}
|
2010-04-06 13:45:56 +00:00
|
|
|
tunnel_closed:
|
|
|
|
{
|
2012-11-26 12:37:20 +00:00
|
|
|
GST_ERROR ("client %p: tunnel session %s was closed", client, tunnelid);
|
2014-08-28 11:35:15 +00:00
|
|
|
g_mutex_unlock (&opriv->watch_lock);
|
2010-04-06 13:45:56 +00:00
|
|
|
g_object_unref (oclient);
|
2018-02-15 12:26:16 +00:00
|
|
|
return GST_RTSP_STS_SERVICE_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
tunnel_duplicate_id:
|
|
|
|
{
|
|
|
|
GST_ERROR ("client %p: tunnel session %s was duplicate", client, tunnelid);
|
|
|
|
g_mutex_unlock (&opriv->watch_lock);
|
|
|
|
g_object_unref (oclient);
|
|
|
|
return GST_RTSP_STS_BAD_REQUEST;
|
2014-04-03 10:19:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPStatusCode
|
|
|
|
tunnel_get (GstRTSPWatch * watch, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
|
|
|
|
GST_INFO ("client %p: tunnel get (connection %p)", client,
|
|
|
|
client->priv->connection);
|
|
|
|
|
2018-02-15 12:26:16 +00:00
|
|
|
g_mutex_lock (&client->priv->lock);
|
|
|
|
client->priv->tstate = TUNNEL_STATE_GET;
|
|
|
|
g_mutex_unlock (&client->priv->lock);
|
2014-04-03 10:19:51 +00:00
|
|
|
|
2018-02-15 12:26:16 +00:00
|
|
|
return handle_tunnel (client);
|
2014-04-03 10:19:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPResult
|
|
|
|
tunnel_post (GstRTSPWatch * watch, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
|
|
|
|
GST_INFO ("client %p: tunnel post (connection %p)", client,
|
|
|
|
client->priv->connection);
|
|
|
|
|
2018-02-15 12:26:16 +00:00
|
|
|
g_mutex_lock (&client->priv->lock);
|
|
|
|
client->priv->tstate = TUNNEL_STATE_POST;
|
|
|
|
g_mutex_unlock (&client->priv->lock);
|
|
|
|
|
|
|
|
if (handle_tunnel (client) != GST_RTSP_STS_OK)
|
2012-04-13 13:27:22 +00:00
|
|
|
return GST_RTSP_ERROR;
|
2014-04-03 10:19:51 +00:00
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
2009-03-04 11:44:01 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 12:52:02 +00:00
|
|
|
static GstRTSPResult
|
|
|
|
tunnel_http_response (GstRTSPWatch * watch, GstRTSPMessage * request,
|
|
|
|
GstRTSPMessage * response, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPClientClass *klass;
|
|
|
|
|
|
|
|
GstRTSPClient *client = GST_RTSP_CLIENT (user_data);
|
|
|
|
klass = GST_RTSP_CLIENT_GET_CLASS (client);
|
|
|
|
|
|
|
|
if (klass->tunnel_http_response) {
|
|
|
|
klass->tunnel_http_response (client, request, response);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_RTSP_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-19 14:53:50 +00:00
|
|
|
static GstRTSPWatchFuncs watch_funcs = {
|
2009-02-18 17:57:31 +00:00
|
|
|
message_received,
|
|
|
|
message_sent,
|
|
|
|
closed,
|
2009-03-04 11:44:01 +00:00
|
|
|
error,
|
2014-04-03 10:19:51 +00:00
|
|
|
tunnel_get,
|
|
|
|
tunnel_post,
|
2010-04-06 09:13:51 +00:00
|
|
|
error_full,
|
2014-03-06 12:52:02 +00:00
|
|
|
tunnel_lost,
|
|
|
|
tunnel_http_response
|
2009-02-18 17:57:31 +00:00
|
|
|
};
|
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
static void
|
|
|
|
client_watch_notify (GstRTSPClient * client)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv = client->priv;
|
2015-12-09 16:24:24 +00:00
|
|
|
gboolean closed = TRUE;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2010-04-06 09:13:51 +00:00
|
|
|
GST_INFO ("client %p: watch destroyed", client);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->watch = NULL;
|
2015-12-09 16:24:24 +00:00
|
|
|
/* remove all sessions if the media says so and so drop the extra client ref */
|
2016-11-21 15:02:39 +00:00
|
|
|
rtsp_ctrl_timeout_remove (priv);
|
2015-12-09 16:24:24 +00:00
|
|
|
gst_rtsp_client_session_filter (client, cleanup_session, &closed);
|
|
|
|
if (closed)
|
|
|
|
g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_CLOSED], 0, NULL);
|
2010-04-06 09:13:51 +00:00
|
|
|
g_object_unref (client);
|
|
|
|
}
|
|
|
|
|
2012-11-12 13:09:09 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_client_attach:
|
|
|
|
* @client: a #GstRTSPClient
|
|
|
|
* @context: (allow-none): a #GMainContext
|
|
|
|
*
|
|
|
|
* Attaches @client to @context. When the mainloop for @context is run, the
|
2013-11-22 01:28:28 +00:00
|
|
|
* client will be dispatched. When @context is %NULL, the default context will be
|
2012-11-12 13:09:09 +00:00
|
|
|
* used).
|
|
|
|
*
|
|
|
|
* This function should be called when the client properties and urls are fully
|
|
|
|
* configured and the client is ready to start.
|
|
|
|
*
|
|
|
|
* Returns: the ID (greater than 0) for the source within the GMainContext.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPClientPrivate *priv;
|
2016-11-21 15:02:39 +00:00
|
|
|
GSource *timer_src;
|
2012-11-12 13:09:09 +00:00
|
|
|
guint res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), 0);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = client->priv;
|
2013-07-11 14:57:14 +00:00
|
|
|
g_return_val_if_fail (priv->connection != NULL, 0);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_val_if_fail (priv->watch == NULL, 0);
|
2012-11-12 13:09:09 +00:00
|
|
|
|
2014-06-12 11:49:17 +00:00
|
|
|
/* make sure noone will free the context before the watch is destroyed */
|
|
|
|
priv->watch_context = g_main_context_ref (context);
|
|
|
|
|
2012-11-12 13:09:09 +00:00
|
|
|
/* create watch for the connection and attach */
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->watch = gst_rtsp_watch_new (priv->connection, &watch_funcs,
|
2012-11-12 13:09:09 +00:00
|
|
|
g_object_ref (client), (GDestroyNotify) client_watch_notify);
|
2019-01-25 12:22:42 +00:00
|
|
|
gst_rtsp_client_set_send_func (client, NULL, NULL, NULL);
|
2018-09-17 19:18:46 +00:00
|
|
|
gst_rtsp_client_set_send_messages_func (client, do_send_messages, priv->watch,
|
|
|
|
(GDestroyNotify) gst_rtsp_watch_unref);
|
2012-11-12 13:09:09 +00:00
|
|
|
|
2014-09-16 09:29:38 +00:00
|
|
|
gst_rtsp_watch_set_send_backlog (priv->watch, 0, WATCH_BACKLOG_SIZE);
|
2012-12-14 10:58:29 +00:00
|
|
|
|
2014-07-01 14:12:13 +00:00
|
|
|
GST_INFO ("client %p: attaching to context %p", client, context);
|
2012-11-29 10:11:05 +00:00
|
|
|
res = gst_rtsp_watch_attach (priv->watch, context);
|
2012-11-12 13:09:09 +00:00
|
|
|
|
2016-11-21 15:02:39 +00:00
|
|
|
/* Setting up a timeout for the RTSP control channel until a session
|
|
|
|
* is up where it is handling timeouts. */
|
|
|
|
rtsp_ctrl_timeout_remove (priv); /* removing old if any */
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
|
|
|
timer_src = g_timeout_source_new_seconds (RTSP_CTRL_CB_INTERVAL);
|
|
|
|
g_source_set_callback (timer_src, rtsp_ctrl_timeout_cb, client, NULL);
|
|
|
|
priv->rtsp_ctrl_timeout_id = g_source_attach (timer_src, priv->watch_context);
|
|
|
|
g_source_unref (timer_src);
|
|
|
|
GST_DEBUG ("rtsp control setting up session timeout id=%u.",
|
|
|
|
priv->rtsp_ctrl_timeout_id);
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2012-11-12 13:09:09 +00:00
|
|
|
return res;
|
|
|
|
}
|
2013-06-26 15:18:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_client_session_filter:
|
2013-08-02 15:15:09 +00:00
|
|
|
* @client: a #GstRTSPClient
|
2013-11-18 10:47:04 +00:00
|
|
|
* @func: (scope call) (allow-none): a callback
|
2013-06-26 15:18:33 +00:00
|
|
|
* @user_data: user data passed to @func
|
|
|
|
*
|
|
|
|
* Call @func for each session managed by @client. The result value of @func
|
|
|
|
* determines what happens to the session. @func will be called with @client
|
|
|
|
* locked so no further actions on @client can be performed from @func.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REMOVE, the session will be removed from
|
|
|
|
* @client.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_KEEP, the session will remain in @client.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REF, the session will remain in @client 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 session.
|
|
|
|
*
|
2013-06-26 15:18:33 +00:00
|
|
|
* Returns: (element-type GstRTSPSession) (transfer full): a #GList with all
|
|
|
|
* sessions 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_client_session_filter (GstRTSPClient * client,
|
|
|
|
GstRTSPClientSessionFilterFunc func, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPClientPrivate *priv;
|
|
|
|
GList *result, *walk, *next;
|
2014-07-10 09:32:20 +00:00
|
|
|
GHashTable *visited;
|
|
|
|
guint cookie;
|
2013-06-26 15:18:33 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
|
|
|
|
|
|
|
|
priv = client->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-06-26 15:18:33 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2014-07-10 09:32:20 +00:00
|
|
|
restart:
|
|
|
|
cookie = priv->sessions_cookie;
|
2013-06-26 15:18:33 +00:00
|
|
|
for (walk = priv->sessions; walk; walk = next) {
|
|
|
|
GstRTSPSession *sess = walk->data;
|
2013-11-15 15:35:05 +00:00
|
|
|
GstRTSPFilterResult res;
|
2014-07-10 09:32:20 +00:00
|
|
|
gboolean changed;
|
2013-06-26 15:18:33 +00:00
|
|
|
|
|
|
|
next = g_list_next (walk);
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func) {
|
|
|
|
/* only visit each session once */
|
|
|
|
if (g_hash_table_contains (visited, sess))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_hash_table_add (visited, g_object_ref (sess));
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2013-11-15 15:35:05 +00:00
|
|
|
res = func (client, sess, user_data);
|
2014-07-10 09:32:20 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
} 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->sessions_cookie);
|
|
|
|
|
2013-11-15 15:35:05 +00:00
|
|
|
switch (res) {
|
2013-06-26 15:18:33 +00:00
|
|
|
case GST_RTSP_FILTER_REMOVE:
|
2014-07-10 09:32:20 +00:00
|
|
|
/* stop watching the session and pretend it went away, if the list was
|
|
|
|
* changed, we can't use the current list position, try to see if we
|
|
|
|
* still have the session */
|
|
|
|
client_unwatch_session (client, sess, changed ? NULL : walk);
|
|
|
|
cookie = priv->sessions_cookie;
|
2013-06-26 15:18:33 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_REF:
|
|
|
|
result = g_list_prepend (result, g_object_ref (sess));
|
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_KEEP:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-07-10 09:32:20 +00:00
|
|
|
if (changed)
|
|
|
|
goto restart;
|
2013-06-26 15:18:33 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func)
|
|
|
|
g_hash_table_unref (visited);
|
|
|
|
|
2013-06-26 15:18:33 +00:00
|
|
|
return result;
|
|
|
|
}
|