2012-10-25 19:29:58 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:14:25 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
2013-07-11 14:57:14 +00:00
|
|
|
/**
|
|
|
|
* SECTION:rtsp-stream
|
|
|
|
* @short_description: A media stream
|
|
|
|
* @see_also: #GstRTSPMedia
|
|
|
|
*
|
2013-07-16 10:32:51 +00:00
|
|
|
* The #GstRTSPStream object manages the data transport for one stream. It
|
|
|
|
* is created from a payloader element and a source pad that produce the RTP
|
|
|
|
* packets for the stream.
|
|
|
|
*
|
|
|
|
* With gst_rtsp_stream_join_bin() the streaming elements are added to the bin
|
|
|
|
* and rtpbin. gst_rtsp_stream_leave_bin() removes the elements again.
|
|
|
|
*
|
|
|
|
* The #GstRTSPStream will use the configured addresspool, as set with
|
|
|
|
* gst_rtsp_stream_set_address_pool(), to allocate multicast addresses for the
|
|
|
|
* stream. With gst_rtsp_stream_get_multicast_address() you can get the
|
|
|
|
* configured address.
|
|
|
|
*
|
|
|
|
* With gst_rtsp_stream_get_server_port () you can get the port that the server
|
|
|
|
* will use to receive RTCP. This is the part that the clients will use to send
|
|
|
|
* RTCP to.
|
|
|
|
*
|
|
|
|
* With gst_rtsp_stream_add_transport() destinations can be added where the
|
|
|
|
* stream should be sent to. Use gst_rtsp_stream_remove_transport() to remove
|
|
|
|
* the destination again.
|
|
|
|
*
|
|
|
|
* Last reviewed on 2013-07-16 (1.0.0)
|
2013-07-11 14:57:14 +00:00
|
|
|
*/
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2013-07-03 13:13:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
|
|
#include <gst/app/gstappsrc.h>
|
|
|
|
#include <gst/app/gstappsink.h>
|
|
|
|
|
|
|
|
#include "rtsp-stream.h"
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
#define GST_RTSP_STREAM_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_STREAM, GstRTSPStreamPrivate))
|
|
|
|
|
2014-06-25 16:23:10 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *transport;
|
|
|
|
|
|
|
|
/* RTP and RTCP source */
|
|
|
|
GstElement *udpsrc[2];
|
|
|
|
GstPad *selpad[2];
|
|
|
|
} GstRTSPMulticastTransportSource;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
struct _GstRTSPStreamPrivate
|
|
|
|
{
|
|
|
|
GMutex lock;
|
|
|
|
guint idx;
|
|
|
|
GstPad *srcpad;
|
|
|
|
GstElement *payloader;
|
|
|
|
guint buffer_size;
|
|
|
|
gboolean is_joined;
|
2013-07-02 12:44:35 +00:00
|
|
|
gchar *control;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2014-01-07 11:21:09 +00:00
|
|
|
GstRTSPProfile profiles;
|
2013-08-16 14:08:43 +00:00
|
|
|
GstRTSPLowerTrans protocols;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/* pads on the rtpbin */
|
|
|
|
GstPad *send_rtp_sink;
|
|
|
|
GstPad *recv_sink[2];
|
|
|
|
GstPad *send_src[2];
|
|
|
|
|
|
|
|
/* the RTPSession object */
|
|
|
|
GObject *session;
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
/* SRTP encoder/decoder */
|
|
|
|
GstElement *srtpenc;
|
|
|
|
GstElement *srtpdec;
|
2014-04-02 10:36:16 +00:00
|
|
|
GHashTable *keys;
|
2014-03-13 16:35:21 +00:00
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
/* sinks used for sending and receiving RTP and RTCP over ipv4, they share
|
2012-11-29 10:11:05 +00:00
|
|
|
* sockets */
|
2013-05-30 06:07:48 +00:00
|
|
|
GstElement *udpsrc_v4[2];
|
|
|
|
|
|
|
|
/* sinks used for sending and receiving RTP and RTCP over ipv6, they share
|
|
|
|
* sockets */
|
|
|
|
GstElement *udpsrc_v6[2];
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
GstElement *udpsink[2];
|
2013-05-30 06:07:48 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/* for TCP transport */
|
|
|
|
GstElement *appsrc[2];
|
|
|
|
GstElement *appqueue[2];
|
|
|
|
GstElement *appsink[2];
|
|
|
|
|
|
|
|
GstElement *tee[2];
|
|
|
|
GstElement *funnel[2];
|
|
|
|
|
2014-11-26 14:12:36 +00:00
|
|
|
/* retransmission */
|
|
|
|
GstElement *rtxsend;
|
|
|
|
guint rtx_pt;
|
|
|
|
GstClockTime rtx_time;
|
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
/* server ports for sending/receiving over ipv4 */
|
|
|
|
GstRTSPRange server_port_v4;
|
|
|
|
GstRTSPAddress *server_addr_v4;
|
2013-07-01 12:45:49 +00:00
|
|
|
gboolean have_ipv4;
|
2013-05-30 06:07:48 +00:00
|
|
|
|
|
|
|
/* server ports for sending/receiving over ipv6 */
|
|
|
|
GstRTSPRange server_port_v6;
|
|
|
|
GstRTSPAddress *server_addr_v6;
|
2013-07-01 12:45:49 +00:00
|
|
|
gboolean have_ipv6;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
/* multicast addresses */
|
|
|
|
GstRTSPAddressPool *pool;
|
2013-07-01 14:46:07 +00:00
|
|
|
GstRTSPAddress *addr_v4;
|
|
|
|
GstRTSPAddress *addr_v6;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
/* the caps of the stream */
|
|
|
|
gulong caps_sig;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
/* transports we stream to */
|
|
|
|
guint n_active;
|
|
|
|
GList *transports;
|
2014-07-10 09:32:20 +00:00
|
|
|
guint transports_cookie;
|
2014-03-13 13:20:17 +00:00
|
|
|
GList *tr_cache;
|
2014-07-10 09:32:20 +00:00
|
|
|
guint tr_cache_cookie;
|
2013-06-24 08:43:59 +00:00
|
|
|
|
2014-06-25 16:23:10 +00:00
|
|
|
/* UDP sources for UDP multicast transports */
|
|
|
|
GList *transport_sources;
|
|
|
|
|
2013-06-24 08:43:59 +00:00
|
|
|
gint dscp_qos;
|
2013-11-28 12:42:21 +00:00
|
|
|
|
|
|
|
/* stream blocking */
|
|
|
|
gulong blocked_id;
|
|
|
|
gboolean blocking;
|
2012-11-29 10:11:05 +00:00
|
|
|
};
|
|
|
|
|
2013-08-16 14:08:43 +00:00
|
|
|
#define DEFAULT_CONTROL NULL
|
2014-01-07 11:21:09 +00:00
|
|
|
#define DEFAULT_PROFILES GST_RTSP_PROFILE_AVP
|
2013-08-16 14:16:00 +00:00
|
|
|
#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | \
|
|
|
|
GST_RTSP_LOWER_TRANS_TCP
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2013-07-02 12:44:35 +00:00
|
|
|
PROP_CONTROL,
|
2014-01-07 11:21:09 +00:00
|
|
|
PROP_PROFILES,
|
2013-08-16 14:08:43 +00:00
|
|
|
PROP_PROTOCOLS,
|
2012-10-25 19:29:58 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_NEW_RTP_ENCODER,
|
|
|
|
SIGNAL_NEW_RTCP_ENCODER,
|
|
|
|
SIGNAL_LAST
|
|
|
|
};
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_stream_debug);
|
|
|
|
#define GST_CAT_DEFAULT rtsp_stream_debug
|
|
|
|
|
|
|
|
static GQuark ssrc_stream_map_key;
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
static void gst_rtsp_stream_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_stream_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
static void gst_rtsp_stream_finalize (GObject * obj);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
static guint gst_rtsp_stream_signals[SIGNAL_LAST] = { 0 };
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
G_DEFINE_TYPE (GstRTSPStream, gst_rtsp_stream, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_stream_class_init (GstRTSPStreamClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstRTSPStreamPrivate));
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
gobject_class->get_property = gst_rtsp_stream_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_stream_set_property;
|
2012-10-25 19:29:58 +00:00
|
|
|
gobject_class->finalize = gst_rtsp_stream_finalize;
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CONTROL,
|
|
|
|
g_param_spec_string ("control", "Control",
|
|
|
|
"The control string for this stream", DEFAULT_CONTROL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2014-01-07 11:21:09 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PROFILES,
|
|
|
|
g_param_spec_flags ("profiles", "Profiles",
|
|
|
|
"Allowed transfer profiles", GST_TYPE_RTSP_PROFILE,
|
|
|
|
DEFAULT_PROFILES, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2013-08-16 14:08:43 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
|
|
|
|
g_param_spec_flags ("protocols", "Protocols",
|
|
|
|
"Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
|
|
|
|
DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
gst_rtsp_stream_signals[SIGNAL_NEW_RTP_ENCODER] =
|
|
|
|
g_signal_new ("new-rtp-encoder", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
|
|
|
G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
gst_rtsp_stream_signals[SIGNAL_NEW_RTCP_ENCODER] =
|
|
|
|
g_signal_new ("new-rtcp-encoder", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
|
|
|
G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_stream_debug, "rtspstream", 0, "GstRTSPStream");
|
|
|
|
|
|
|
|
ssrc_stream_map_key = g_quark_from_static_string ("GstRTSPServer.stream");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-13 10:14:49 +00:00
|
|
|
gst_rtsp_stream_init (GstRTSPStream * stream)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
|
|
|
|
|
2012-11-28 11:40:18 +00:00
|
|
|
GST_DEBUG ("new stream %p", stream);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
stream->priv = priv;
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
priv->dscp_qos = -1;
|
|
|
|
priv->control = g_strdup (DEFAULT_CONTROL);
|
2014-01-07 11:21:09 +00:00
|
|
|
priv->profiles = DEFAULT_PROFILES;
|
2013-08-16 14:08:43 +00:00
|
|
|
priv->protocols = DEFAULT_PROTOCOLS;
|
2013-06-24 08:43:59 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_init (&priv->lock);
|
2014-04-02 10:36:16 +00:00
|
|
|
|
|
|
|
priv->keys = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
NULL, (GDestroyNotify) gst_caps_unref);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_stream_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstRTSPStream *stream;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
stream = GST_RTSP_STREAM (obj);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-28 11:40:18 +00:00
|
|
|
GST_DEBUG ("finalize stream %p", stream);
|
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
/* we really need to be unjoined now */
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_if_fail (!priv->is_joined);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-07-01 14:46:07 +00:00
|
|
|
if (priv->addr_v4)
|
|
|
|
gst_rtsp_address_free (priv->addr_v4);
|
|
|
|
if (priv->addr_v6)
|
|
|
|
gst_rtsp_address_free (priv->addr_v6);
|
2013-05-30 06:07:48 +00:00
|
|
|
if (priv->server_addr_v4)
|
|
|
|
gst_rtsp_address_free (priv->server_addr_v4);
|
|
|
|
if (priv->server_addr_v6)
|
|
|
|
gst_rtsp_address_free (priv->server_addr_v6);
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->pool)
|
|
|
|
g_object_unref (priv->pool);
|
2014-11-26 14:12:36 +00:00
|
|
|
if (priv->rtxsend)
|
|
|
|
g_object_unref (priv->rtxsend);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_object_unref (priv->payloader);
|
|
|
|
gst_object_unref (priv->srcpad);
|
2013-07-02 12:44:35 +00:00
|
|
|
g_free (priv->control);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_clear (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2014-04-02 10:36:16 +00:00
|
|
|
g_hash_table_unref (priv->keys);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtsp_stream_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
static void
|
|
|
|
gst_rtsp_stream_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTSPStream *stream = GST_RTSP_STREAM (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_CONTROL:
|
|
|
|
g_value_take_string (value, gst_rtsp_stream_get_control (stream));
|
|
|
|
break;
|
2014-01-07 11:21:09 +00:00
|
|
|
case PROP_PROFILES:
|
|
|
|
g_value_set_flags (value, gst_rtsp_stream_get_profiles (stream));
|
|
|
|
break;
|
2013-08-16 14:08:43 +00:00
|
|
|
case PROP_PROTOCOLS:
|
|
|
|
g_value_set_flags (value, gst_rtsp_stream_get_protocols (stream));
|
|
|
|
break;
|
2013-07-02 12:44:35 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_stream_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTSPStream *stream = GST_RTSP_STREAM (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_CONTROL:
|
|
|
|
gst_rtsp_stream_set_control (stream, g_value_get_string (value));
|
|
|
|
break;
|
2014-01-07 11:21:09 +00:00
|
|
|
case PROP_PROFILES:
|
|
|
|
gst_rtsp_stream_set_profiles (stream, g_value_get_flags (value));
|
|
|
|
break;
|
2013-08-16 14:08:43 +00:00
|
|
|
case PROP_PROTOCOLS:
|
|
|
|
gst_rtsp_stream_set_protocols (stream, g_value_get_flags (value));
|
|
|
|
break;
|
2013-07-02 12:44:35 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_new:
|
|
|
|
* @idx: an index
|
|
|
|
* @srcpad: a #GstPad
|
|
|
|
* @payloader: a #GstElement
|
|
|
|
*
|
|
|
|
* Create a new media stream with index @idx that handles RTP data on
|
|
|
|
* @srcpad and has a payloader element @payloader.
|
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): a new #GstRTSPStream
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
|
|
|
GstRTSPStream *
|
|
|
|
gst_rtsp_stream_new (guint idx, GstElement * payloader, GstPad * srcpad)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStream *stream;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (payloader), NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
|
|
|
|
g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), NULL);
|
|
|
|
|
|
|
|
stream = g_object_new (GST_TYPE_RTSP_STREAM, NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
priv->idx = idx;
|
|
|
|
priv->payloader = gst_object_ref (payloader);
|
|
|
|
priv->srcpad = gst_object_ref (srcpad);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_index:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the stream index.
|
|
|
|
*
|
|
|
|
* Return: the stream index.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_index (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
|
|
|
|
|
|
|
|
return stream->priv->idx;
|
|
|
|
}
|
|
|
|
|
2013-11-15 20:14:32 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_pt:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the stream payload type.
|
|
|
|
*
|
|
|
|
* Return: the stream payload type.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_pt (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
guint pt;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (priv->payloader), "pt", &pt, NULL);
|
|
|
|
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
/**
|
2013-04-22 15:32:31 +00:00
|
|
|
* gst_rtsp_stream_get_srcpad:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the srcpad associated with @stream.
|
|
|
|
*
|
2013-10-12 21:56:00 +00:00
|
|
|
* Returns: (transfer full): the srcpad. Unref after usage.
|
2013-04-22 15:32:31 +00:00
|
|
|
*/
|
|
|
|
GstPad *
|
|
|
|
gst_rtsp_stream_get_srcpad (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
return gst_object_ref (stream->priv->srcpad);
|
|
|
|
}
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_control:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the control string to identify this stream.
|
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): the control string. g_free() after usage.
|
2013-07-02 12:44:35 +00:00
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_stream_get_control (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = g_strdup (priv->control)) == NULL)
|
2013-07-03 13:13:45 +00:00
|
|
|
result = g_strdup_printf ("stream=%u", priv->idx);
|
2013-07-02 12:44:35 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_control:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @control: a control string
|
|
|
|
*
|
|
|
|
* Set the control string in @stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_control (GstRTSPStream * stream, const gchar * control)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
g_free (priv->control);
|
|
|
|
priv->control = g_strdup (control);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
2013-07-03 13:13:45 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_has_control:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @control: a control string
|
|
|
|
*
|
|
|
|
* Check if @stream has the control string @control.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE is @stream has @control as the control string
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_has_control (GstRTSPStream * stream, const gchar * control)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (priv->control)
|
2013-10-01 11:15:19 +00:00
|
|
|
res = (g_strcmp0 (priv->control, control) == 0);
|
2013-07-03 13:13:45 +00:00
|
|
|
else {
|
|
|
|
guint streamid;
|
2013-12-19 13:26:34 +00:00
|
|
|
|
|
|
|
if (sscanf (control, "stream=%u", &streamid) > 0)
|
|
|
|
res = (streamid == priv->idx);
|
|
|
|
else
|
|
|
|
res = FALSE;
|
2013-07-03 13:13:45 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-10-26 10:04:02 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_mtu:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @mtu: a new MTU
|
|
|
|
*
|
|
|
|
* Configure the mtu in the payloader of @stream to @mtu.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_mtu (GstRTSPStream * stream, guint mtu)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
2012-10-26 10:04:02 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
2012-11-15 15:15:20 +00:00
|
|
|
GST_LOG_OBJECT (stream, "set MTU %u", mtu);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_object_set (G_OBJECT (priv->payloader), "mtu", mtu, NULL);
|
2012-10-26 10:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_mtu:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the configured MTU in the payloader of @stream.
|
|
|
|
*
|
|
|
|
* Returns: the MTU of the payloader.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_mtu (GstRTSPStream * stream)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-26 10:04:02 +00:00
|
|
|
guint mtu;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (priv->payloader), "mtu", &mtu, NULL);
|
2012-10-26 10:04:02 +00:00
|
|
|
|
|
|
|
return mtu;
|
|
|
|
}
|
|
|
|
|
2013-06-24 08:43:59 +00:00
|
|
|
/* Update the dscp qos property on the udp sinks */
|
|
|
|
static void
|
2013-06-24 18:41:27 +00:00
|
|
|
update_dscp_qos (GstRTSPStream * stream)
|
2013-06-24 08:43:59 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
if (priv->udpsink[0]) {
|
|
|
|
g_object_set (G_OBJECT (priv->udpsink[0]), "qos-dscp", priv->dscp_qos,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->udpsink[1]) {
|
|
|
|
g_object_set (G_OBJECT (priv->udpsink[1]), "qos-dscp", priv->dscp_qos,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_dscp_qos:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @dscp_qos: a new dscp qos value (0-63, or -1 to disable)
|
|
|
|
*
|
|
|
|
* Configure the dscp qos of the outgoing sockets to @dscp_qos.
|
|
|
|
*/
|
|
|
|
void
|
2013-06-24 18:41:27 +00:00
|
|
|
gst_rtsp_stream_set_dscp_qos (GstRTSPStream * stream, gint dscp_qos)
|
2013-06-24 08:43:59 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (stream, "set DSCP QoS %d", dscp_qos);
|
|
|
|
|
|
|
|
if (dscp_qos < -1 || dscp_qos > 63) {
|
|
|
|
GST_WARNING_OBJECT (stream, "trying to set illegal dscp qos %d", dscp_qos);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->dscp_qos = dscp_qos;
|
|
|
|
|
|
|
|
update_dscp_qos (stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_dscp_qos:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the configured DSCP QoS in of the outgoing sockets.
|
|
|
|
*
|
|
|
|
* Returns: the DSCP QoS value of the outgoing sockets, or -1 if disbled.
|
|
|
|
*/
|
|
|
|
gint
|
2013-06-24 18:41:27 +00:00
|
|
|
gst_rtsp_stream_get_dscp_qos (GstRTSPStream * stream)
|
2013-06-24 08:43:59 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
return priv->dscp_qos;
|
|
|
|
}
|
|
|
|
|
2014-01-07 11:14:15 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_is_transport_supported:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @transport: (transfer none): a #GstRTSPTransport
|
2014-01-07 11:14:15 +00:00
|
|
|
*
|
|
|
|
* Check if @transport can be handled by stream
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @transport can be handled by @stream.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_transport_supported (GstRTSPStream * stream,
|
|
|
|
GstRTSPTransport * transport)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
2014-01-07 14:28:05 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
2014-01-07 11:14:15 +00:00
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (transport->trans != GST_RTSP_TRANS_RTP)
|
|
|
|
goto unsupported_transmode;
|
|
|
|
|
2014-01-07 11:21:09 +00:00
|
|
|
if (!(transport->profile & priv->profiles))
|
2014-01-07 11:14:15 +00:00
|
|
|
goto unsupported_profile;
|
|
|
|
|
|
|
|
if (!(transport->lower_transport & priv->protocols))
|
|
|
|
goto unsupported_ltrans;
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
unsupported_transmode:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("unsupported transport mode %d", transport->trans);
|
2014-03-03 11:17:48 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2014-01-07 11:14:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
unsupported_profile:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("unsupported profile %d", transport->profile);
|
2014-03-03 11:17:48 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2014-01-07 11:14:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
unsupported_ltrans:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("unsupported lower transport %d", transport->lower_transport);
|
2014-03-03 11:17:48 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2014-01-07 11:14:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-07 11:21:09 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_profiles:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @profiles: the new profiles
|
|
|
|
*
|
|
|
|
* Configure the allowed profiles for @stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_profiles (GstRTSPStream * stream, GstRTSPProfile profiles)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->profiles = profiles;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_profiles:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the allowed profiles of @stream.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPProfile
|
|
|
|
*/
|
|
|
|
GstRTSPProfile
|
|
|
|
gst_rtsp_stream_get_profiles (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPProfile res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_RTSP_PROFILE_UNKNOWN);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->profiles;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-08-16 14:08:43 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_protocols:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @protocols: the new flags
|
|
|
|
*
|
|
|
|
* Configure the allowed lower transport for @stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_protocols (GstRTSPStream * stream,
|
|
|
|
GstRTSPLowerTrans protocols)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->protocols = protocols;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_protocols:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the allowed protocols of @stream.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPLowerTrans
|
|
|
|
*/
|
|
|
|
GstRTSPLowerTrans
|
|
|
|
gst_rtsp_stream_get_protocols (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPLowerTrans res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream),
|
|
|
|
GST_RTSP_LOWER_TRANS_UNKNOWN);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->protocols;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2013-06-24 08:43:59 +00:00
|
|
|
|
2012-11-15 14:36:21 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_address_pool:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @pool: (transfer none): a #GstRTSPAddressPool
|
2012-11-15 14:36:21 +00:00
|
|
|
*
|
|
|
|
* configure @pool to be used as the address pool of @stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_address_pool (GstRTSPStream * stream,
|
|
|
|
GstRTSPAddressPool * pool)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-15 14:36:21 +00:00
|
|
|
GstRTSPAddressPool *old;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
2012-11-15 15:15:20 +00:00
|
|
|
GST_LOG_OBJECT (stream, "set address pool %p", pool);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((old = priv->pool) != pool)
|
|
|
|
priv->pool = pool ? g_object_ref (pool) : NULL;
|
2012-11-15 14:36:21 +00:00
|
|
|
else
|
|
|
|
old = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-15 14:36:21 +00:00
|
|
|
|
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_address_pool:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPAddressPool used as the address pool of @stream.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the #GstRTSPAddressPool of @stream. g_object_unref() after
|
|
|
|
* usage.
|
|
|
|
*/
|
|
|
|
GstRTSPAddressPool *
|
|
|
|
gst_rtsp_stream_get_address_pool (GstRTSPStream * stream)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-15 14:36:21 +00:00
|
|
|
GstRTSPAddressPool *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->pool))
|
2012-11-15 14:36:21 +00:00
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-15 14:36:21 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-01 14:46:07 +00:00
|
|
|
* gst_rtsp_stream_get_multicast_address:
|
2012-11-15 14:36:21 +00:00
|
|
|
* @stream: a #GstRTSPStream
|
2013-07-01 14:46:07 +00:00
|
|
|
* @family: the #GSocketFamily
|
2012-11-15 14:36:21 +00:00
|
|
|
*
|
2013-07-01 14:46:07 +00:00
|
|
|
* Get the multicast address of @stream for @family.
|
2012-11-15 14:36:21 +00:00
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstRTSPAddress of @stream
|
|
|
|
* or %NULL when no address could be allocated. gst_rtsp_address_free()
|
|
|
|
* after usage.
|
2012-11-15 14:36:21 +00:00
|
|
|
*/
|
|
|
|
GstRTSPAddress *
|
2013-07-01 14:46:07 +00:00
|
|
|
gst_rtsp_stream_get_multicast_address (GstRTSPStream * stream,
|
|
|
|
GSocketFamily family)
|
2012-11-15 14:36:21 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-15 14:36:21 +00:00
|
|
|
GstRTSPAddress *result;
|
2013-07-01 14:46:07 +00:00
|
|
|
GstRTSPAddress **addrp;
|
|
|
|
GstRTSPAddressFlags flags;
|
2012-11-15 14:36:21 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
2013-07-01 14:46:07 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6) {
|
|
|
|
flags = GST_RTSP_ADDRESS_FLAG_IPV6;
|
2014-03-14 18:03:24 +00:00
|
|
|
addrp = &priv->addr_v6;
|
2013-07-01 14:46:07 +00:00
|
|
|
} else {
|
|
|
|
flags = GST_RTSP_ADDRESS_FLAG_IPV4;
|
2014-03-14 18:03:24 +00:00
|
|
|
addrp = &priv->addr_v4;
|
2013-07-01 14:46:07 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-07-01 14:46:07 +00:00
|
|
|
if (*addrp == NULL) {
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->pool == NULL)
|
2012-11-15 14:36:21 +00:00
|
|
|
goto no_pool;
|
|
|
|
|
2013-07-01 14:46:07 +00:00
|
|
|
flags |= GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST;
|
|
|
|
|
|
|
|
*addrp = gst_rtsp_address_pool_acquire_address (priv->pool, flags, 2);
|
|
|
|
if (*addrp == NULL)
|
2012-11-15 14:36:21 +00:00
|
|
|
goto no_address;
|
|
|
|
}
|
2013-07-01 14:46:07 +00:00
|
|
|
result = gst_rtsp_address_copy (*addrp);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-15 14:36:21 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_pool:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "no address pool specified");
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-15 14:36:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
no_address:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "failed to acquire address from pool");
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-15 14:36:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 23:32:20 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_reserve_address:
|
|
|
|
* @stream: a #GstRTSPStream
|
2013-07-01 10:20:50 +00:00
|
|
|
* @address: an address
|
|
|
|
* @port: a port
|
|
|
|
* @n_ports: n_ports
|
|
|
|
* @ttl: a TTL
|
2013-02-13 23:32:20 +00:00
|
|
|
*
|
2013-07-01 10:20:50 +00:00
|
|
|
* Reserve @address and @port as the address and port of @stream.
|
2013-02-13 23:32:20 +00:00
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (nullable): the #GstRTSPAddress of @stream or %NULL when
|
|
|
|
* the address could be reserved. gst_rtsp_address_free() after usage.
|
2013-02-13 23:32:20 +00:00
|
|
|
*/
|
|
|
|
GstRTSPAddress *
|
|
|
|
gst_rtsp_stream_reserve_address (GstRTSPStream * stream,
|
|
|
|
const gchar * address, guint port, guint n_ports, guint ttl)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPAddress *result;
|
2013-07-01 14:46:07 +00:00
|
|
|
GInetAddress *addr;
|
|
|
|
GSocketFamily family;
|
|
|
|
GstRTSPAddress **addrp;
|
2013-02-13 23:32:20 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
g_return_val_if_fail (address != NULL, NULL);
|
|
|
|
g_return_val_if_fail (port > 0, NULL);
|
|
|
|
g_return_val_if_fail (n_ports > 0, NULL);
|
|
|
|
g_return_val_if_fail (ttl > 0, NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
2013-07-01 14:46:07 +00:00
|
|
|
addr = g_inet_address_new_from_string (address);
|
|
|
|
if (!addr) {
|
|
|
|
GST_ERROR ("failed to get inet addr from %s", address);
|
|
|
|
family = G_SOCKET_FAMILY_IPV4;
|
|
|
|
} else {
|
|
|
|
family = g_inet_address_get_family (addr);
|
|
|
|
g_object_unref (addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
|
|
|
addrp = &priv->addr_v6;
|
2014-03-14 18:03:24 +00:00
|
|
|
else
|
|
|
|
addrp = &priv->addr_v4;
|
2013-07-01 14:46:07 +00:00
|
|
|
|
2013-02-13 23:32:20 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-07-01 14:46:07 +00:00
|
|
|
if (*addrp == NULL) {
|
2013-09-24 15:30:18 +00:00
|
|
|
GstRTSPAddressPoolResult res;
|
|
|
|
|
2013-02-13 23:32:20 +00:00
|
|
|
if (priv->pool == NULL)
|
|
|
|
goto no_pool;
|
|
|
|
|
2013-09-24 15:30:18 +00:00
|
|
|
res = gst_rtsp_address_pool_reserve_address (priv->pool, address,
|
|
|
|
port, n_ports, ttl, addrp);
|
|
|
|
if (res != GST_RTSP_ADDRESS_POOL_OK)
|
2013-02-13 23:32:20 +00:00
|
|
|
goto no_address;
|
|
|
|
} else {
|
2013-07-01 14:46:07 +00:00
|
|
|
if (strcmp ((*addrp)->address, address) ||
|
|
|
|
(*addrp)->port != port || (*addrp)->n_ports != n_ports ||
|
|
|
|
(*addrp)->ttl != ttl)
|
2013-02-13 23:32:20 +00:00
|
|
|
goto different_address;
|
|
|
|
}
|
2013-07-01 14:46:07 +00:00
|
|
|
result = gst_rtsp_address_copy (*addrp);
|
2013-02-13 23:32:20 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_pool:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "no address pool specified");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
no_address:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "failed to acquire address %s from pool",
|
|
|
|
address);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
different_address:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "address %s is not the same that was already"
|
|
|
|
" reserved", address);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
static gboolean
|
2013-05-30 06:07:48 +00:00
|
|
|
alloc_ports_one_family (GstRTSPAddressPool * pool, gint buffer_size,
|
|
|
|
GSocketFamily family, GstElement * udpsrc_out[2],
|
|
|
|
GstElement * udpsink_out[2], GstRTSPRange * server_port_out,
|
|
|
|
GstRTSPAddress ** server_addr_out)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
GstElement *udpsrc0, *udpsrc1;
|
|
|
|
GstElement *udpsink0, *udpsink1;
|
2013-02-19 23:27:20 +00:00
|
|
|
GSocket *rtp_socket = NULL;
|
|
|
|
GSocket *rtcp_socket;
|
2012-10-25 19:29:58 +00:00
|
|
|
gint tmp_rtp, tmp_rtcp;
|
|
|
|
guint count;
|
|
|
|
gint rtpport, rtcpport;
|
2013-02-19 23:27:20 +00:00
|
|
|
GList *rejected_addresses = NULL;
|
|
|
|
GstRTSPAddress *addr = NULL;
|
|
|
|
GInetAddress *inetaddr = NULL;
|
|
|
|
GSocketAddress *rtp_sockaddr = NULL;
|
|
|
|
GSocketAddress *rtcp_sockaddr = NULL;
|
2013-07-01 12:45:49 +00:00
|
|
|
const gchar *multisink_socket;
|
2013-05-30 06:07:48 +00:00
|
|
|
|
2013-07-01 12:45:49 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
2013-05-30 06:07:48 +00:00
|
|
|
multisink_socket = "socket-v6";
|
2013-07-01 12:45:49 +00:00
|
|
|
else
|
|
|
|
multisink_socket = "socket";
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
udpsrc0 = NULL;
|
|
|
|
udpsrc1 = NULL;
|
|
|
|
udpsink0 = NULL;
|
|
|
|
udpsink1 = NULL;
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
/* Start with random port */
|
|
|
|
tmp_rtp = 0;
|
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
rtcp_socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
|
|
|
|
G_SOCKET_PROTOCOL_UDP, NULL);
|
|
|
|
if (!rtcp_socket)
|
|
|
|
goto no_udp_protocol;
|
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
if (*server_addr_out)
|
|
|
|
gst_rtsp_address_free (*server_addr_out);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
/* try to allocate 2 UDP ports, the RTP port should be an even
|
|
|
|
* number and the RTCP port should be the next (uneven) port */
|
|
|
|
again:
|
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
if (rtp_socket == NULL) {
|
|
|
|
rtp_socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
|
|
|
|
G_SOCKET_PROTOCOL_UDP, NULL);
|
|
|
|
if (!rtp_socket)
|
|
|
|
goto no_udp_protocol;
|
|
|
|
}
|
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
if (pool && gst_rtsp_address_pool_has_unicast_addresses (pool)) {
|
2013-02-19 23:27:20 +00:00
|
|
|
GstRTSPAddressFlags flags;
|
|
|
|
|
|
|
|
if (addr)
|
|
|
|
rejected_addresses = g_list_prepend (rejected_addresses, addr);
|
|
|
|
|
|
|
|
flags = GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_UNICAST;
|
2013-05-30 06:07:48 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
2013-02-19 23:27:20 +00:00
|
|
|
flags |= GST_RTSP_ADDRESS_FLAG_IPV6;
|
|
|
|
else
|
|
|
|
flags |= GST_RTSP_ADDRESS_FLAG_IPV4;
|
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
addr = gst_rtsp_address_pool_acquire_address (pool, flags, 2);
|
2013-02-19 23:27:20 +00:00
|
|
|
|
|
|
|
if (addr == NULL)
|
|
|
|
goto no_ports;
|
|
|
|
|
|
|
|
tmp_rtp = addr->port;
|
|
|
|
|
|
|
|
g_clear_object (&inetaddr);
|
|
|
|
inetaddr = g_inet_address_new_from_string (addr->address);
|
|
|
|
} else {
|
2012-10-25 19:29:58 +00:00
|
|
|
if (tmp_rtp != 0) {
|
|
|
|
tmp_rtp += 2;
|
|
|
|
if (++count > 20)
|
|
|
|
goto no_ports;
|
2013-02-19 23:27:20 +00:00
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
if (inetaddr == NULL)
|
|
|
|
inetaddr = g_inet_address_new_any (family);
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
rtp_sockaddr = g_inet_socket_address_new (inetaddr, tmp_rtp);
|
|
|
|
if (!g_socket_bind (rtp_socket, rtp_sockaddr, FALSE, NULL)) {
|
|
|
|
g_object_unref (rtp_sockaddr);
|
|
|
|
goto again;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
g_object_unref (rtp_sockaddr);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
rtp_sockaddr = g_socket_get_local_address (rtp_socket, NULL);
|
|
|
|
if (rtp_sockaddr == NULL || !G_IS_INET_SOCKET_ADDRESS (rtp_sockaddr)) {
|
|
|
|
g_clear_object (&rtp_sockaddr);
|
|
|
|
goto socket_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_rtp =
|
|
|
|
g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (rtp_sockaddr));
|
|
|
|
g_object_unref (rtp_sockaddr);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
/* check if port is even */
|
|
|
|
if ((tmp_rtp & 1) != 0) {
|
|
|
|
/* port not even, close and allocate another */
|
|
|
|
tmp_rtp++;
|
2013-02-19 23:27:20 +00:00
|
|
|
g_clear_object (&rtp_socket);
|
2012-10-25 19:29:58 +00:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set port */
|
|
|
|
tmp_rtcp = tmp_rtp + 1;
|
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
rtcp_sockaddr = g_inet_socket_address_new (inetaddr, tmp_rtcp);
|
|
|
|
if (!g_socket_bind (rtcp_socket, rtcp_sockaddr, FALSE, NULL)) {
|
|
|
|
g_object_unref (rtcp_sockaddr);
|
|
|
|
g_clear_object (&rtp_socket);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
g_object_unref (rtcp_sockaddr);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
g_clear_object (&inetaddr);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
udpsrc0 = gst_element_factory_make ("udpsrc", NULL);
|
|
|
|
udpsrc1 = gst_element_factory_make ("udpsrc", NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
if (udpsrc0 == NULL || udpsrc1 == NULL)
|
|
|
|
goto no_udp_protocol;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (udpsrc0), "socket", rtp_socket, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsrc1), "socket", rtcp_socket, NULL);
|
|
|
|
|
2014-04-02 10:36:16 +00:00
|
|
|
ret = gst_element_set_state (udpsrc0, GST_STATE_READY);
|
2013-02-19 23:27:20 +00:00
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto element_error;
|
2014-04-02 10:36:16 +00:00
|
|
|
ret = gst_element_set_state (udpsrc1, GST_STATE_READY);
|
2013-02-19 23:27:20 +00:00
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto element_error;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
/* all fine, do port check */
|
|
|
|
g_object_get (G_OBJECT (udpsrc0), "port", &rtpport, NULL);
|
|
|
|
g_object_get (G_OBJECT (udpsrc1), "port", &rtcpport, NULL);
|
|
|
|
|
|
|
|
/* this should not happen... */
|
|
|
|
if (rtpport != tmp_rtp || rtcpport != tmp_rtcp)
|
|
|
|
goto port_error;
|
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
if (udpsink_out[0])
|
|
|
|
udpsink0 = udpsink_out[0];
|
|
|
|
else
|
|
|
|
udpsink0 = gst_element_factory_make ("multiudpsink", NULL);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
if (!udpsink0)
|
|
|
|
goto no_udp_protocol;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (udpsink0), "close-socket", FALSE, NULL);
|
2013-05-30 06:07:48 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink0), multisink_socket, rtp_socket, NULL);
|
|
|
|
|
|
|
|
if (udpsink_out[1])
|
|
|
|
udpsink1 = udpsink_out[1];
|
|
|
|
else
|
|
|
|
udpsink1 = gst_element_factory_make ("multiudpsink", NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
if (!udpsink1)
|
|
|
|
goto no_udp_protocol;
|
|
|
|
|
2013-02-19 21:43:08 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink0), "send-duplicates", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "send-duplicates", FALSE, NULL);
|
2013-05-30 06:07:48 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink0), "buffer-size", buffer_size, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "close-socket", FALSE, NULL);
|
2013-05-30 06:07:48 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink1), multisink_socket, rtcp_socket, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink1), "sync", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "async", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink0), "auto-multicast", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink0), "loop", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "auto-multicast", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "loop", FALSE, NULL);
|
|
|
|
|
|
|
|
/* we keep these elements, we will further configure them when the
|
|
|
|
* client told us to really use the UDP ports. */
|
2013-05-30 06:07:48 +00:00
|
|
|
udpsrc_out[0] = udpsrc0;
|
|
|
|
udpsrc_out[1] = udpsrc1;
|
|
|
|
udpsink_out[0] = udpsink0;
|
|
|
|
udpsink_out[1] = udpsink1;
|
2014-06-25 16:23:10 +00:00
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
server_port_out->min = rtpport;
|
|
|
|
server_port_out->max = rtcpport;
|
|
|
|
|
|
|
|
*server_addr_out = addr;
|
2013-02-19 23:27:20 +00:00
|
|
|
g_list_free_full (rejected_addresses, (GDestroyNotify) gst_rtsp_address_free);
|
|
|
|
|
|
|
|
g_object_unref (rtp_socket);
|
|
|
|
g_object_unref (rtcp_socket);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_udp_protocol:
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
no_ports:
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
port_error:
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
socket_error:
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
element_error:
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
cleanup:
|
|
|
|
{
|
|
|
|
if (udpsrc0) {
|
|
|
|
gst_element_set_state (udpsrc0, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsrc0);
|
|
|
|
}
|
|
|
|
if (udpsrc1) {
|
|
|
|
gst_element_set_state (udpsrc1, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsrc1);
|
|
|
|
}
|
|
|
|
if (udpsink0) {
|
|
|
|
gst_element_set_state (udpsink0, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsink0);
|
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
if (inetaddr)
|
|
|
|
g_object_unref (inetaddr);
|
|
|
|
g_list_free_full (rejected_addresses,
|
|
|
|
(GDestroyNotify) gst_rtsp_address_free);
|
|
|
|
if (addr)
|
|
|
|
gst_rtsp_address_free (addr);
|
|
|
|
if (rtp_socket)
|
|
|
|
g_object_unref (rtp_socket);
|
|
|
|
if (rtcp_socket)
|
|
|
|
g_object_unref (rtcp_socket);
|
2012-10-25 19:29:58 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
/* must be called with lock */
|
|
|
|
static gboolean
|
|
|
|
alloc_ports (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
2013-07-01 12:45:49 +00:00
|
|
|
priv->have_ipv4 = alloc_ports_one_family (priv->pool, priv->buffer_size,
|
2013-05-30 06:07:48 +00:00
|
|
|
G_SOCKET_FAMILY_IPV4, priv->udpsrc_v4, priv->udpsink,
|
2013-07-01 12:45:49 +00:00
|
|
|
&priv->server_port_v4, &priv->server_addr_v4);
|
|
|
|
|
|
|
|
priv->have_ipv6 = alloc_ports_one_family (priv->pool, priv->buffer_size,
|
2013-05-30 06:07:48 +00:00
|
|
|
G_SOCKET_FAMILY_IPV6, priv->udpsrc_v6, priv->udpsink,
|
|
|
|
&priv->server_port_v6, &priv->server_addr_v6);
|
2013-07-01 12:45:49 +00:00
|
|
|
|
|
|
|
return priv->have_ipv4 || priv->have_ipv6;
|
2013-05-30 06:07:48 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_server_port:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @server_port: (out): result server port
|
2013-07-11 10:18:26 +00:00
|
|
|
* @family: the port family to get
|
2012-11-29 10:11:05 +00:00
|
|
|
*
|
|
|
|
* Fill @server_port with the port pair used by the server. This function can
|
|
|
|
* only be called when @stream has been joined.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_get_server_port (GstRTSPStream * stream,
|
2013-05-30 06:07:48 +00:00
|
|
|
GstRTSPRange * server_port, GSocketFamily family)
|
2012-11-29 10:11:05 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
priv = stream->priv;
|
|
|
|
g_return_if_fail (priv->is_joined);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2013-05-30 06:07:48 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV4) {
|
|
|
|
if (server_port)
|
|
|
|
*server_port = priv->server_port_v4;
|
|
|
|
} else {
|
|
|
|
if (server_port)
|
|
|
|
*server_port = priv->server_port_v6;
|
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
2013-06-24 18:41:27 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rtpsession:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the RTP session of this stream.
|
|
|
|
*
|
2013-10-12 21:56:00 +00:00
|
|
|
* Returns: (transfer full): The RTP session of this stream. Unref after usage.
|
2013-06-24 18:41:27 +00:00
|
|
|
*/
|
|
|
|
GObject *
|
|
|
|
gst_rtsp_stream_get_rtpsession (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GObject *session;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((session = priv->session))
|
|
|
|
g_object_ref (session);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_ssrc:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @ssrc: (out): result ssrc
|
|
|
|
*
|
|
|
|
* Get the SSRC used by the RTP session of this stream. This function can only
|
|
|
|
* be called when @stream has been joined.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_get_ssrc (GstRTSPStream * stream, guint * ssrc)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
priv = stream->priv;
|
|
|
|
g_return_if_fail (priv->is_joined);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (ssrc && priv->session)
|
|
|
|
g_object_get (priv->session, "internal-ssrc", ssrc, NULL);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
2014-11-26 14:12:36 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_retransmission_time:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @time: a #GstClockTime
|
|
|
|
*
|
|
|
|
* Set the amount of time to store retransmission packets.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_retransmission_time (GstRTSPStream * stream,
|
|
|
|
GstClockTime time)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (stream, "set retransmission time %" G_GUINT64_FORMAT, time);
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->rtx_time = time;
|
|
|
|
if (stream->priv->rtxsend)
|
|
|
|
g_object_set (stream->priv->rtxsend, "max-size-time",
|
|
|
|
GST_TIME_AS_MSECONDS (time), NULL);
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_retransmission_time:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the amount of time to store retransmission data.
|
|
|
|
*
|
|
|
|
* Returns: the amount of time to store retransmission data.
|
|
|
|
*/
|
|
|
|
GstClockTime
|
|
|
|
gst_rtsp_stream_get_retransmission_time (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstClockTime ret;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
ret = stream->priv->rtx_time;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_retransmission_pt (GstRTSPStream * stream, guint rtx_pt)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "set retransmission pt %u", rtx_pt);
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->rtx_pt = rtx_pt;
|
|
|
|
if (stream->priv->rtxsend) {
|
|
|
|
guint pt = gst_rtsp_stream_get_pt (stream);
|
|
|
|
gchar *pt_s = g_strdup_printf ("%d", pt);
|
|
|
|
GstStructure *rtx_pt_map = gst_structure_new ("application/x-rtp-pt-map",
|
|
|
|
pt_s, G_TYPE_UINT, rtx_pt, NULL);
|
|
|
|
g_object_set (stream->priv->rtxsend, "payload-type-map", rtx_pt_map, NULL);
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_retransmission_pt (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
guint rtx_pt;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
rtx_pt = stream->priv->rtx_pt;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return rtx_pt;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/* executed from streaming thread */
|
|
|
|
static void
|
|
|
|
caps_notify (GstPad * pad, GParamSpec * unused, GstRTSPStream * stream)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstCaps *newcaps, *oldcaps;
|
|
|
|
|
|
|
|
newcaps = gst_pad_get_current_caps (pad);
|
|
|
|
|
2012-11-13 10:14:49 +00:00
|
|
|
GST_INFO ("stream %p received caps %p, %" GST_PTR_FORMAT, stream, newcaps,
|
|
|
|
newcaps);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
oldcaps = priv->caps;
|
|
|
|
priv->caps = newcaps;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
if (oldcaps)
|
|
|
|
gst_caps_unref (oldcaps);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_structure (const GstStructure * s)
|
|
|
|
{
|
|
|
|
gchar *sstr;
|
|
|
|
|
|
|
|
sstr = gst_structure_to_string (s);
|
|
|
|
GST_INFO ("structure: %s", sstr);
|
|
|
|
g_free (sstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPStreamTransport *
|
|
|
|
find_transport (GstRTSPStream * stream, const gchar * rtcp_from)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GList *walk;
|
|
|
|
GstRTSPStreamTransport *result = NULL;
|
|
|
|
const gchar *tmp;
|
|
|
|
gchar *dest;
|
|
|
|
guint port;
|
|
|
|
|
|
|
|
if (rtcp_from == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tmp = g_strrstr (rtcp_from, ":");
|
|
|
|
if (tmp == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
port = atoi (tmp + 1);
|
|
|
|
dest = g_strndup (rtcp_from, tmp - rtcp_from);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("finding %s:%d in %d transports", dest, port,
|
2012-11-29 10:11:05 +00:00
|
|
|
g_list_length (priv->transports));
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
for (walk = priv->transports; walk; walk = g_list_next (walk)) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStreamTransport *trans = walk->data;
|
2012-11-29 10:11:05 +00:00
|
|
|
const GstRTSPTransport *tr;
|
2012-10-25 19:29:58 +00:00
|
|
|
gint min, max;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
tr = gst_rtsp_stream_transport_get_transport (trans);
|
|
|
|
|
|
|
|
min = tr->client_port.min;
|
|
|
|
max = tr->client_port.max;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if ((strcmp (tr->destination, dest) == 0) && (min == port || max == port)) {
|
2012-10-25 19:29:58 +00:00
|
|
|
result = trans;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-30 04:49:20 +00:00
|
|
|
if (result)
|
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
g_free (dest);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPStreamTransport *
|
|
|
|
check_transport (GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstStructure *stats;
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
/* see if we have a stream to match with the origin of the RTCP packet */
|
|
|
|
trans = g_object_get_qdata (source, ssrc_stream_map_key);
|
|
|
|
if (trans == NULL) {
|
|
|
|
g_object_get (source, "stats", &stats, NULL);
|
|
|
|
if (stats) {
|
|
|
|
const gchar *rtcp_from;
|
|
|
|
|
|
|
|
dump_structure (stats);
|
|
|
|
|
|
|
|
rtcp_from = gst_structure_get_string (stats, "rtcp-from");
|
|
|
|
if ((trans = find_transport (stream, rtcp_from))) {
|
|
|
|
GST_INFO ("%p: found transport %p for source %p", stream, trans,
|
|
|
|
source);
|
2013-05-30 04:49:20 +00:00
|
|
|
g_object_set_qdata_full (source, ssrc_stream_map_key, trans,
|
|
|
|
g_object_unref);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
gst_structure_free (stats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return trans;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_new_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
GST_INFO ("%p: new source %p", stream, source);
|
|
|
|
|
|
|
|
trans = check_transport (source, stream);
|
|
|
|
|
|
|
|
if (trans)
|
|
|
|
GST_INFO ("%p: source %p for transport %p", stream, source, trans);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_ssrc_sdes (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GST_INFO ("%p: new SDES %p", stream, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_ssrc_active (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
trans = check_transport (source, stream);
|
|
|
|
|
2012-11-12 16:11:18 +00:00
|
|
|
if (trans) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("%p: source %p in transport %p is active", stream, source, trans);
|
2012-11-12 16:11:18 +00:00
|
|
|
gst_rtsp_stream_transport_keep_alive (trans);
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
#ifdef DUMP_STATS
|
|
|
|
{
|
|
|
|
GstStructure *stats;
|
|
|
|
g_object_get (source, "stats", &stats, NULL);
|
|
|
|
if (stats) {
|
|
|
|
dump_structure (stats);
|
|
|
|
gst_structure_free (stats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_bye_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GST_INFO ("%p: source %p bye", stream, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_bye_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
GST_INFO ("%p: source %p bye timeout", stream, source);
|
|
|
|
|
|
|
|
if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
|
2013-05-30 04:49:20 +00:00
|
|
|
g_object_set_qdata (source, ssrc_stream_map_key, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
GST_INFO ("%p: source %p timeout", stream, source);
|
|
|
|
|
|
|
|
if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
|
2013-05-30 04:49:20 +00:00
|
|
|
g_object_set_qdata (source, ssrc_stream_map_key, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-13 13:20:17 +00:00
|
|
|
static void
|
|
|
|
clear_tr_cache (GstRTSPStreamPrivate * priv)
|
|
|
|
{
|
|
|
|
g_list_foreach (priv->tr_cache, (GFunc) g_object_unref, NULL);
|
|
|
|
g_list_free (priv->tr_cache);
|
|
|
|
priv->tr_cache = NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
handle_new_sample (GstAppSink * sink, gpointer user_data)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GList *walk;
|
|
|
|
GstSample *sample;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstRTSPStream *stream;
|
2014-03-13 13:20:17 +00:00
|
|
|
gboolean is_rtp;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
sample = gst_app_sink_pull_sample (sink);
|
|
|
|
if (!sample)
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
stream = (GstRTSPStream *) user_data;
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
buffer = gst_sample_get_buffer (sample);
|
|
|
|
|
2014-03-13 13:20:17 +00:00
|
|
|
is_rtp = GST_ELEMENT_CAST (sink) == priv->appsink[0];
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2014-07-10 09:32:20 +00:00
|
|
|
if (priv->tr_cache_cookie != priv->transports_cookie) {
|
2014-03-13 13:20:17 +00:00
|
|
|
clear_tr_cache (priv);
|
|
|
|
for (walk = priv->transports; walk; walk = g_list_next (walk)) {
|
|
|
|
GstRTSPStreamTransport *tr = (GstRTSPStreamTransport *) walk->data;
|
|
|
|
priv->tr_cache = g_list_prepend (priv->tr_cache, g_object_ref (tr));
|
|
|
|
}
|
2014-07-10 09:32:20 +00:00
|
|
|
priv->tr_cache_cookie = priv->transports_cookie;
|
2014-03-13 13:20:17 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
for (walk = priv->tr_cache; walk; walk = g_list_next (walk)) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStreamTransport *tr = (GstRTSPStreamTransport *) walk->data;
|
|
|
|
|
2014-03-13 13:20:17 +00:00
|
|
|
if (is_rtp) {
|
2012-11-12 16:06:42 +00:00
|
|
|
gst_rtsp_stream_transport_send_rtp (tr, buffer);
|
2012-10-25 19:29:58 +00:00
|
|
|
} else {
|
2012-11-12 16:06:42 +00:00
|
|
|
gst_rtsp_stream_transport_send_rtcp (tr, buffer);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_sample_unref (sample);
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstAppSinkCallbacks sink_cb = {
|
|
|
|
NULL, /* not interested in EOS */
|
|
|
|
NULL, /* not interested in preroll samples */
|
|
|
|
handle_new_sample,
|
|
|
|
};
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
static GstElement *
|
|
|
|
get_rtp_encoder (GstRTSPStream * stream, guint session)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
|
|
|
if (priv->srtpenc == NULL) {
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("srtpenc_%u", session);
|
|
|
|
priv->srtpenc = gst_element_factory_make ("srtpenc", name);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
g_object_set (priv->srtpenc, "random-key", TRUE, NULL);
|
|
|
|
}
|
|
|
|
return gst_object_ref (priv->srtpenc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
|
|
|
request_rtp_encoder (GstElement * rtpbin, guint session, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2014-05-16 01:15:04 +00:00
|
|
|
GstElement *oldenc, *enc;
|
2014-03-13 16:35:21 +00:00
|
|
|
GstPad *pad;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
if (priv->idx != session)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "make RTP encoder for session %u", session);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
oldenc = priv->srtpenc;
|
2014-03-13 16:35:21 +00:00
|
|
|
enc = get_rtp_encoder (stream, session);
|
|
|
|
name = g_strdup_printf ("rtp_sink_%d", session);
|
|
|
|
pad = gst_element_get_request_pad (enc, name);
|
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
if (oldenc == NULL)
|
|
|
|
g_signal_emit (stream, gst_rtsp_stream_signals[SIGNAL_NEW_RTP_ENCODER], 0,
|
|
|
|
enc);
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
return enc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
|
|
|
request_rtcp_encoder (GstElement * rtpbin, guint session,
|
|
|
|
GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2014-05-16 01:15:04 +00:00
|
|
|
GstElement *oldenc, *enc;
|
2014-03-13 16:35:21 +00:00
|
|
|
GstPad *pad;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
if (priv->idx != session)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "make RTCP encoder for session %u", session);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
oldenc = priv->srtpenc;
|
2014-03-13 16:35:21 +00:00
|
|
|
enc = get_rtp_encoder (stream, session);
|
|
|
|
name = g_strdup_printf ("rtcp_sink_%d", session);
|
|
|
|
pad = gst_element_get_request_pad (enc, name);
|
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
if (oldenc == NULL)
|
|
|
|
g_signal_emit (stream, gst_rtsp_stream_signals[SIGNAL_NEW_RTCP_ENCODER], 0,
|
|
|
|
enc);
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
return enc;
|
|
|
|
}
|
|
|
|
|
2014-04-02 10:36:16 +00:00
|
|
|
static GstCaps *
|
|
|
|
request_key (GstElement * srtpdec, guint ssrc, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
GST_DEBUG ("request key %08x", ssrc);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((caps = g_hash_table_lookup (priv->keys, GINT_TO_POINTER (ssrc))))
|
|
|
|
gst_caps_ref (caps);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
static GstElement *
|
|
|
|
request_rtcp_decoder (GstElement * rtpbin, guint session,
|
|
|
|
GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
|
|
|
if (priv->idx != session)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (priv->srtpdec == NULL) {
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("srtpdec_%u", session);
|
|
|
|
priv->srtpdec = gst_element_factory_make ("srtpdec", name);
|
|
|
|
g_free (name);
|
2014-04-02 10:36:16 +00:00
|
|
|
|
|
|
|
g_signal_connect (priv->srtpdec, "request-key",
|
|
|
|
(GCallback) request_key, stream);
|
2014-03-13 16:35:21 +00:00
|
|
|
}
|
|
|
|
return gst_object_ref (priv->srtpdec);
|
|
|
|
}
|
|
|
|
|
2014-11-26 14:12:36 +00:00
|
|
|
static GstElement *
|
|
|
|
request_aux_sender (GstElement * rtpbin, guint sessid, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstElement *bin;
|
|
|
|
GstPad *pad;
|
|
|
|
GstStructure *pt_map;
|
|
|
|
gchar *name;
|
|
|
|
guint pt, rtx_pt;
|
|
|
|
gchar *pt_s;
|
|
|
|
|
|
|
|
pt = gst_rtsp_stream_get_pt (stream);
|
|
|
|
pt_s = g_strdup_printf ("%u", pt);
|
|
|
|
rtx_pt = stream->priv->rtx_pt;
|
|
|
|
|
|
|
|
GST_INFO ("creating rtxsend with pt %u to %u", pt, rtx_pt);
|
|
|
|
|
|
|
|
bin = gst_bin_new (NULL);
|
|
|
|
stream->priv->rtxsend = gst_element_factory_make ("rtprtxsend", NULL);
|
|
|
|
pt_map = gst_structure_new ("application/x-rtp-pt-map",
|
|
|
|
pt_s, G_TYPE_UINT, rtx_pt, NULL);
|
|
|
|
g_object_set (stream->priv->rtxsend, "payload-type-map", pt_map,
|
|
|
|
"max-size-time", GST_TIME_AS_MSECONDS (stream->priv->rtx_time), NULL);
|
|
|
|
gst_structure_free (pt_map);
|
|
|
|
gst_bin_add (GST_BIN (bin), gst_object_ref (stream->priv->rtxsend));
|
|
|
|
|
|
|
|
pad = gst_element_get_static_pad (stream->priv->rtxsend, "src");
|
|
|
|
name = g_strdup_printf ("src_%u", sessid);
|
|
|
|
gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
|
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
|
|
|
pad = gst_element_get_static_pad (stream->priv->rtxsend, "sink");
|
|
|
|
name = g_strdup_printf ("sink_%u", sessid);
|
|
|
|
gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
|
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
|
|
|
return bin;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_join_bin:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @bin: (transfer none): a #GstBin to join
|
|
|
|
* @rtpbin: (transfer none): a rtpbin element in @bin
|
2012-10-26 15:28:10 +00:00
|
|
|
* @state: the target state of the new elements
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2013-11-22 02:10:01 +00:00
|
|
|
* Join the #GstBin @bin that contains the element @rtpbin.
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2012-10-26 15:28:10 +00:00
|
|
|
* @stream will link to @rtpbin, which must be inside @bin. The elements
|
|
|
|
* added to @bin will be set to the state given in @state.
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
|
2012-10-26 15:28:10 +00:00
|
|
|
GstElement * rtpbin, GstState state)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2013-07-03 13:13:45 +00:00
|
|
|
gint i;
|
|
|
|
guint idx;
|
2012-10-25 19:29:58 +00:00
|
|
|
gchar *name;
|
2013-08-16 15:05:24 +00:00
|
|
|
GstPad *pad, *sinkpad, *selpad;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstPadLinkReturn ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (rtpbin), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (priv->is_joined)
|
2012-11-13 10:14:49 +00:00
|
|
|
goto was_joined;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
/* create a session with the same index as the stream */
|
2012-11-29 10:11:05 +00:00
|
|
|
idx = priv->idx;
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2013-07-03 13:13:45 +00:00
|
|
|
GST_INFO ("stream %p joining bin as session %u", stream, idx);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
if (!alloc_ports (stream))
|
|
|
|
goto no_ports;
|
|
|
|
|
2013-06-24 08:43:59 +00:00
|
|
|
/* update the dscp qos field in the sinks */
|
|
|
|
update_dscp_qos (stream);
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
if (priv->profiles & GST_RTSP_PROFILE_SAVP
|
|
|
|
|| priv->profiles & GST_RTSP_PROFILE_SAVPF) {
|
|
|
|
/* For SRTP */
|
|
|
|
g_signal_connect (rtpbin, "request-rtp-encoder",
|
|
|
|
(GCallback) request_rtp_encoder, stream);
|
|
|
|
g_signal_connect (rtpbin, "request-rtcp-encoder",
|
|
|
|
(GCallback) request_rtcp_encoder, stream);
|
|
|
|
g_signal_connect (rtpbin, "request-rtcp-decoder",
|
|
|
|
(GCallback) request_rtcp_decoder, stream);
|
|
|
|
}
|
|
|
|
|
2014-11-26 14:12:36 +00:00
|
|
|
if (priv->rtx_time > 0) {
|
|
|
|
/* enable retransmission by setting rtprtxsend as the "aux" element of rtpbin */
|
|
|
|
g_signal_connect (rtpbin, "request-aux-sender",
|
|
|
|
(GCallback) request_aux_sender, stream);
|
|
|
|
}
|
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
/* get a pad for sending RTP */
|
2012-10-25 19:29:58 +00:00
|
|
|
name = g_strdup_printf ("send_rtp_sink_%u", idx);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->send_rtp_sink = gst_element_get_request_pad (rtpbin, name);
|
2012-10-25 19:29:58 +00:00
|
|
|
g_free (name);
|
2012-10-26 15:28:10 +00:00
|
|
|
/* link the RTP pad to the session manager, it should not really fail unless
|
|
|
|
* this is not really an RTP pad */
|
2012-11-29 10:11:05 +00:00
|
|
|
ret = gst_pad_link (priv->srcpad, priv->send_rtp_sink);
|
2012-10-26 15:28:10 +00:00
|
|
|
if (ret != GST_PAD_LINK_OK)
|
|
|
|
goto link_failed;
|
|
|
|
|
|
|
|
/* get pads from the RTP session element for sending and receiving
|
|
|
|
* RTP/RTCP*/
|
2012-10-25 19:29:58 +00:00
|
|
|
name = g_strdup_printf ("send_rtp_src_%u", idx);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->send_src[0] = gst_element_get_static_pad (rtpbin, name);
|
2012-10-25 19:29:58 +00:00
|
|
|
g_free (name);
|
|
|
|
name = g_strdup_printf ("send_rtcp_src_%u", idx);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->send_src[1] = gst_element_get_request_pad (rtpbin, name);
|
2012-10-25 19:29:58 +00:00
|
|
|
g_free (name);
|
|
|
|
name = g_strdup_printf ("recv_rtp_sink_%u", idx);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->recv_sink[0] = gst_element_get_request_pad (rtpbin, name);
|
2012-10-26 15:28:10 +00:00
|
|
|
g_free (name);
|
|
|
|
name = g_strdup_printf ("recv_rtcp_sink_%u", idx);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->recv_sink[1] = gst_element_get_request_pad (rtpbin, name);
|
2012-10-25 19:29:58 +00:00
|
|
|
g_free (name);
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/* get the session */
|
2012-11-29 10:11:05 +00:00
|
|
|
g_signal_emit_by_name (rtpbin, "get-internal-session", idx, &priv->session);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_signal_connect (priv->session, "on-new-ssrc", (GCallback) on_new_ssrc,
|
2012-10-25 19:29:58 +00:00
|
|
|
stream);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_signal_connect (priv->session, "on-ssrc-sdes", (GCallback) on_ssrc_sdes,
|
2012-10-25 19:29:58 +00:00
|
|
|
stream);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_signal_connect (priv->session, "on-ssrc-active",
|
2012-10-25 19:29:58 +00:00
|
|
|
(GCallback) on_ssrc_active, stream);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_signal_connect (priv->session, "on-bye-ssrc", (GCallback) on_bye_ssrc,
|
2012-10-25 19:29:58 +00:00
|
|
|
stream);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_signal_connect (priv->session, "on-bye-timeout",
|
2012-10-25 19:29:58 +00:00
|
|
|
(GCallback) on_bye_timeout, stream);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_signal_connect (priv->session, "on-timeout", (GCallback) on_timeout,
|
2012-10-25 19:29:58 +00:00
|
|
|
stream);
|
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2013-08-16 15:05:24 +00:00
|
|
|
GstPad *teepad, *queuepad;
|
2012-10-26 15:28:10 +00:00
|
|
|
/* For the sender we create this bit of pipeline for both
|
|
|
|
* RTP and RTCP. Sync and preroll are enabled on udpsink so
|
|
|
|
* we need to add a queue before appsink to make the pipeline
|
|
|
|
* not block. For the TCP case, we want to pump data to the
|
|
|
|
* client as fast as possible anyway.
|
|
|
|
*
|
|
|
|
* .--------. .-----. .---------.
|
|
|
|
* | rtpbin | | tee | | udpsink |
|
|
|
|
* | send->sink src->sink |
|
|
|
|
* '--------' | | '---------'
|
|
|
|
* | | .---------. .---------.
|
|
|
|
* | | | queue | | appsink |
|
|
|
|
* | src->sink src->sink |
|
|
|
|
* '-----' '---------' '---------'
|
2013-08-16 15:05:24 +00:00
|
|
|
*
|
|
|
|
* When only UDP is allowed, we skip the tee, queue and appsink and link the
|
|
|
|
* udpsink directly to the session.
|
2012-10-26 15:28:10 +00:00
|
|
|
*/
|
|
|
|
/* add udpsink */
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_bin_add (bin, priv->udpsink[i]);
|
2013-08-16 15:05:24 +00:00
|
|
|
sinkpad = gst_element_get_static_pad (priv->udpsink[i], "sink");
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-08-16 15:05:24 +00:00
|
|
|
if (priv->protocols & GST_RTSP_LOWER_TRANS_TCP) {
|
|
|
|
/* make tee for RTP/RTCP */
|
|
|
|
priv->tee[i] = gst_element_factory_make ("tee", NULL);
|
|
|
|
gst_bin_add (bin, priv->tee[i]);
|
|
|
|
|
|
|
|
/* and link to rtpbin send pad */
|
|
|
|
pad = gst_element_get_static_pad (priv->tee[i], "sink");
|
|
|
|
gst_pad_link (priv->send_src[i], pad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
|
|
|
/* link tee to udpsink */
|
|
|
|
teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
|
|
|
|
gst_pad_link (teepad, sinkpad);
|
|
|
|
gst_object_unref (teepad);
|
|
|
|
|
|
|
|
/* make queue */
|
|
|
|
priv->appqueue[i] = gst_element_factory_make ("queue", NULL);
|
|
|
|
gst_bin_add (bin, priv->appqueue[i]);
|
|
|
|
/* and link to tee */
|
|
|
|
teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
|
|
|
|
pad = gst_element_get_static_pad (priv->appqueue[i], "sink");
|
|
|
|
gst_pad_link (teepad, pad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (teepad);
|
|
|
|
|
|
|
|
/* make appsink */
|
|
|
|
priv->appsink[i] = gst_element_factory_make ("appsink", NULL);
|
|
|
|
g_object_set (priv->appsink[i], "async", FALSE, "sync", FALSE, NULL);
|
|
|
|
g_object_set (priv->appsink[i], "emit-signals", FALSE, NULL);
|
|
|
|
gst_bin_add (bin, priv->appsink[i]);
|
|
|
|
gst_app_sink_set_callbacks (GST_APP_SINK_CAST (priv->appsink[i]),
|
|
|
|
&sink_cb, stream, NULL);
|
|
|
|
/* and link to queue */
|
|
|
|
queuepad = gst_element_get_static_pad (priv->appqueue[i], "src");
|
|
|
|
pad = gst_element_get_static_pad (priv->appsink[i], "sink");
|
|
|
|
gst_pad_link (queuepad, pad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (queuepad);
|
|
|
|
} else {
|
|
|
|
/* else only udpsink needed, link it to the session */
|
|
|
|
gst_pad_link (priv->send_src[i], sinkpad);
|
|
|
|
}
|
|
|
|
gst_object_unref (sinkpad);
|
2012-10-26 15:28:10 +00:00
|
|
|
|
|
|
|
/* For the receiver we create this bit of pipeline for both
|
|
|
|
* RTP and RTCP. We receive RTP/RTCP on appsrc and udpsrc
|
|
|
|
* and it is all funneled into the rtpbin receive pad.
|
|
|
|
*
|
|
|
|
* .--------. .--------. .--------.
|
|
|
|
* | udpsrc | | funnel | | rtpbin |
|
|
|
|
* | src->sink src->sink |
|
|
|
|
* '--------' | | '--------'
|
|
|
|
* .--------. | |
|
|
|
|
* | appsrc | | |
|
|
|
|
* | src->sink |
|
|
|
|
* '--------' '--------'
|
|
|
|
*/
|
|
|
|
/* make funnel for the RTP/RTCP receivers */
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->funnel[i] = gst_element_factory_make ("funnel", NULL);
|
|
|
|
gst_bin_add (bin, priv->funnel[i]);
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
pad = gst_element_get_static_pad (priv->funnel[i], "src");
|
|
|
|
gst_pad_link (pad, priv->recv_sink[i]);
|
2012-10-26 15:28:10 +00:00
|
|
|
gst_object_unref (pad);
|
|
|
|
|
2013-07-01 12:45:49 +00:00
|
|
|
if (priv->udpsrc_v4[i]) {
|
|
|
|
/* we set and keep these to playing so that they don't cause NO_PREROLL return
|
|
|
|
* values */
|
|
|
|
gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_PLAYING);
|
|
|
|
gst_element_set_locked_state (priv->udpsrc_v4[i], TRUE);
|
|
|
|
/* add udpsrc */
|
|
|
|
gst_bin_add (bin, priv->udpsrc_v4[i]);
|
|
|
|
|
|
|
|
/* and link to the funnel v4 */
|
|
|
|
selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
|
|
|
|
pad = gst_element_get_static_pad (priv->udpsrc_v4[i], "src");
|
|
|
|
gst_pad_link (pad, selpad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (selpad);
|
|
|
|
}
|
2013-05-30 06:07:48 +00:00
|
|
|
|
2013-07-01 12:45:49 +00:00
|
|
|
if (priv->udpsrc_v6[i]) {
|
|
|
|
gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_PLAYING);
|
|
|
|
gst_element_set_locked_state (priv->udpsrc_v6[i], TRUE);
|
|
|
|
gst_bin_add (bin, priv->udpsrc_v6[i]);
|
|
|
|
|
|
|
|
/* and link to the funnel v6 */
|
|
|
|
selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
|
|
|
|
pad = gst_element_get_static_pad (priv->udpsrc_v6[i], "src");
|
|
|
|
gst_pad_link (pad, selpad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (selpad);
|
|
|
|
}
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2013-08-16 15:05:24 +00:00
|
|
|
if (priv->protocols & GST_RTSP_LOWER_TRANS_TCP) {
|
|
|
|
/* make and add appsrc */
|
|
|
|
priv->appsrc[i] = gst_element_factory_make ("appsrc", NULL);
|
|
|
|
gst_bin_add (bin, priv->appsrc[i]);
|
|
|
|
/* and link to the funnel */
|
|
|
|
selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
|
|
|
|
pad = gst_element_get_static_pad (priv->appsrc[i], "src");
|
|
|
|
gst_pad_link (pad, selpad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (selpad);
|
|
|
|
}
|
2012-10-26 15:28:10 +00:00
|
|
|
|
|
|
|
/* check if we need to set to a special state */
|
|
|
|
if (state != GST_STATE_NULL) {
|
2013-08-16 15:05:24 +00:00
|
|
|
if (priv->udpsink[i])
|
|
|
|
gst_element_set_state (priv->udpsink[i], state);
|
|
|
|
if (priv->appsink[i])
|
|
|
|
gst_element_set_state (priv->appsink[i], state);
|
|
|
|
if (priv->appqueue[i])
|
|
|
|
gst_element_set_state (priv->appqueue[i], state);
|
|
|
|
if (priv->tee[i])
|
|
|
|
gst_element_set_state (priv->tee[i], state);
|
|
|
|
if (priv->funnel[i])
|
|
|
|
gst_element_set_state (priv->funnel[i], state);
|
|
|
|
if (priv->appsrc[i])
|
|
|
|
gst_element_set_state (priv->appsrc[i], state);
|
2012-10-26 15:28:10 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
/* be notified of caps changes */
|
2014-03-13 13:27:15 +00:00
|
|
|
priv->caps_sig = g_signal_connect (priv->send_src[0], "notify::caps",
|
2012-10-25 19:29:58 +00:00
|
|
|
(GCallback) caps_notify, stream);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->is_joined = TRUE;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-11-13 10:14:49 +00:00
|
|
|
was_joined:
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
no_ports:
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2013-07-03 13:13:45 +00:00
|
|
|
GST_WARNING ("failed to allocate ports %u", idx);
|
2012-10-25 19:29:58 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
link_failed:
|
|
|
|
{
|
2013-07-03 13:13:45 +00:00
|
|
|
GST_WARNING ("failed to link stream %u", idx);
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_object_unref (priv->send_rtp_sink);
|
|
|
|
priv->send_rtp_sink = NULL;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_leave_bin:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @bin: (transfer none): a #GstBin
|
|
|
|
* @rtpbin: (transfer none): a rtpbin #GstElement
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2013-04-23 08:16:17 +00:00
|
|
|
* Remove the elements of @stream from @bin.
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Return: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
|
|
|
|
GstElement * rtpbin)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
gint i;
|
2014-08-13 14:22:16 +00:00
|
|
|
GList *l;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (rtpbin), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (!priv->is_joined)
|
2012-11-13 10:14:49 +00:00
|
|
|
goto was_not_joined;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
/* all transports must be removed by now */
|
2014-10-02 19:02:48 +00:00
|
|
|
if (priv->transports != NULL)
|
|
|
|
goto transports_not_removed;
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2014-03-13 13:20:17 +00:00
|
|
|
clear_tr_cache (priv);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("stream %p leaving bin", stream);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_pad_unlink (priv->srcpad, priv->send_rtp_sink);
|
2014-03-13 13:27:15 +00:00
|
|
|
g_signal_handler_disconnect (priv->send_src[0], priv->caps_sig);
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_element_release_request_pad (rtpbin, priv->send_rtp_sink);
|
|
|
|
gst_object_unref (priv->send_rtp_sink);
|
|
|
|
priv->send_rtp_sink = NULL;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
2013-08-16 15:05:24 +00:00
|
|
|
if (priv->udpsink[i])
|
|
|
|
gst_element_set_state (priv->udpsink[i], GST_STATE_NULL);
|
|
|
|
if (priv->appsink[i])
|
|
|
|
gst_element_set_state (priv->appsink[i], GST_STATE_NULL);
|
|
|
|
if (priv->appqueue[i])
|
|
|
|
gst_element_set_state (priv->appqueue[i], GST_STATE_NULL);
|
|
|
|
if (priv->tee[i])
|
|
|
|
gst_element_set_state (priv->tee[i], GST_STATE_NULL);
|
|
|
|
if (priv->funnel[i])
|
|
|
|
gst_element_set_state (priv->funnel[i], GST_STATE_NULL);
|
|
|
|
if (priv->appsrc[i])
|
|
|
|
gst_element_set_state (priv->appsrc[i], GST_STATE_NULL);
|
2013-07-01 12:45:49 +00:00
|
|
|
if (priv->udpsrc_v4[i]) {
|
|
|
|
/* and set udpsrc to NULL now before removing */
|
|
|
|
gst_element_set_locked_state (priv->udpsrc_v4[i], FALSE);
|
|
|
|
gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_NULL);
|
|
|
|
/* removing them should also nicely release the request
|
|
|
|
* pads when they finalize */
|
|
|
|
gst_bin_remove (bin, priv->udpsrc_v4[i]);
|
|
|
|
}
|
|
|
|
if (priv->udpsrc_v6[i]) {
|
|
|
|
gst_element_set_locked_state (priv->udpsrc_v6[i], FALSE);
|
|
|
|
gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_NULL);
|
|
|
|
gst_bin_remove (bin, priv->udpsrc_v6[i]);
|
|
|
|
}
|
2014-08-13 14:22:16 +00:00
|
|
|
|
|
|
|
for (l = priv->transport_sources; l; l = l->next) {
|
|
|
|
GstRTSPMulticastTransportSource *s = l->data;
|
|
|
|
|
|
|
|
if (!s->udpsrc[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gst_element_set_locked_state (s->udpsrc[i], FALSE);
|
|
|
|
gst_element_set_state (s->udpsrc[i], GST_STATE_NULL);
|
|
|
|
gst_bin_remove (bin, s->udpsrc[i]);
|
|
|
|
}
|
|
|
|
|
2013-08-16 15:05:24 +00:00
|
|
|
if (priv->udpsink[i])
|
|
|
|
gst_bin_remove (bin, priv->udpsink[i]);
|
|
|
|
if (priv->appsrc[i])
|
|
|
|
gst_bin_remove (bin, priv->appsrc[i]);
|
|
|
|
if (priv->appsink[i])
|
|
|
|
gst_bin_remove (bin, priv->appsink[i]);
|
|
|
|
if (priv->appqueue[i])
|
|
|
|
gst_bin_remove (bin, priv->appqueue[i]);
|
|
|
|
if (priv->tee[i])
|
|
|
|
gst_bin_remove (bin, priv->tee[i]);
|
|
|
|
if (priv->funnel[i])
|
|
|
|
gst_bin_remove (bin, priv->funnel[i]);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
gst_element_release_request_pad (rtpbin, priv->recv_sink[i]);
|
|
|
|
gst_object_unref (priv->recv_sink[i]);
|
|
|
|
priv->recv_sink[i] = NULL;
|
|
|
|
|
2013-05-30 06:07:48 +00:00
|
|
|
priv->udpsrc_v4[i] = NULL;
|
|
|
|
priv->udpsrc_v6[i] = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->udpsink[i] = NULL;
|
|
|
|
priv->appsrc[i] = NULL;
|
|
|
|
priv->appsink[i] = NULL;
|
|
|
|
priv->appqueue[i] = NULL;
|
|
|
|
priv->tee[i] = NULL;
|
|
|
|
priv->funnel[i] = NULL;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2014-08-13 14:22:16 +00:00
|
|
|
|
|
|
|
for (l = priv->transport_sources; l; l = l->next) {
|
|
|
|
GstRTSPMulticastTransportSource *s = l->data;
|
|
|
|
g_slice_free (GstRTSPMulticastTransportSource, s);
|
|
|
|
}
|
|
|
|
g_list_free (priv->transport_sources);
|
|
|
|
priv->transport_sources = NULL;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_object_unref (priv->send_src[0]);
|
|
|
|
priv->send_src[0] = NULL;
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_element_release_request_pad (rtpbin, priv->send_src[1]);
|
|
|
|
gst_object_unref (priv->send_src[1]);
|
|
|
|
priv->send_src[1] = NULL;
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_object_unref (priv->session);
|
2013-04-22 14:09:22 +00:00
|
|
|
priv->session = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->caps)
|
|
|
|
gst_caps_unref (priv->caps);
|
2013-04-22 14:09:22 +00:00
|
|
|
priv->caps = NULL;
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
if (priv->srtpenc)
|
|
|
|
gst_object_unref (priv->srtpenc);
|
2014-11-01 06:01:53 +00:00
|
|
|
if (priv->srtpdec)
|
|
|
|
gst_object_unref (priv->srtpdec);
|
2014-03-13 16:35:21 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->is_joined = FALSE;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2012-11-13 10:14:49 +00:00
|
|
|
|
|
|
|
was_not_joined:
|
|
|
|
{
|
2014-03-03 11:17:48 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-02 19:02:48 +00:00
|
|
|
transports_not_removed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "can't leave bin (transports not removed)");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rtpinfo:
|
|
|
|
* @stream: a #GstRTSPStream
|
2013-12-26 13:43:35 +00:00
|
|
|
* @rtptime: (allow-none): result RTP timestamp
|
|
|
|
* @seq: (allow-none): result RTP seqnum
|
2014-03-23 20:24:48 +00:00
|
|
|
* @clock_rate: (allow-none): the clock rate
|
2013-12-26 13:43:35 +00:00
|
|
|
* @running_time: (allow-none): result running-time
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2013-12-26 13:43:35 +00:00
|
|
|
* Retrieve the current rtptime, seq and running-time. This is used to
|
2012-10-25 19:29:58 +00:00
|
|
|
* construct a RTPInfo reply header.
|
|
|
|
*
|
2013-12-26 13:43:35 +00:00
|
|
|
* Returns: %TRUE when rtptime, seq and running-time could be determined.
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_get_rtpinfo (GstRTSPStream * stream,
|
2013-12-26 16:02:50 +00:00
|
|
|
guint * rtptime, guint * seq, guint * clock_rate,
|
|
|
|
GstClockTime * running_time)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2014-01-22 21:03:14 +00:00
|
|
|
GstStructure *stats;
|
2014-02-04 09:14:45 +00:00
|
|
|
GObjectClass *payobjclass;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
payobjclass = G_OBJECT_GET_CLASS (priv->payloader);
|
|
|
|
|
2013-12-26 16:02:50 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-12-26 13:43:35 +00:00
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
if (g_object_class_find_property (payobjclass, "stats")) {
|
|
|
|
g_object_get (priv->payloader, "stats", &stats, NULL);
|
|
|
|
if (stats == NULL)
|
|
|
|
goto no_stats;
|
|
|
|
|
|
|
|
if (seq)
|
|
|
|
gst_structure_get_uint (stats, "seqnum", seq);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
if (rtptime)
|
|
|
|
gst_structure_get_uint (stats, "timestamp", rtptime);
|
2014-01-28 13:51:26 +00:00
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
if (running_time)
|
|
|
|
gst_structure_get_clock_time (stats, "running-time", running_time);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
if (clock_rate) {
|
|
|
|
gst_structure_get_uint (stats, "clock-rate", clock_rate);
|
|
|
|
if (*clock_rate == 0 && running_time)
|
|
|
|
*running_time = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
gst_structure_free (stats);
|
|
|
|
} else {
|
|
|
|
if (!g_object_class_find_property (payobjclass, "seqnum") ||
|
|
|
|
!g_object_class_find_property (payobjclass, "timestamp"))
|
|
|
|
goto no_stats;
|
2013-12-26 16:02:50 +00:00
|
|
|
|
2014-02-04 15:27:12 +00:00
|
|
|
if (seq)
|
|
|
|
g_object_get (priv->payloader, "seqnum", seq, NULL);
|
|
|
|
|
|
|
|
if (rtptime)
|
|
|
|
g_object_get (priv->payloader, "timestamp", rtptime, NULL);
|
2014-01-22 21:03:14 +00:00
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
if (running_time)
|
2014-01-22 21:03:14 +00:00
|
|
|
*running_time = GST_CLOCK_TIME_NONE;
|
2013-12-26 16:02:50 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
return TRUE;
|
2014-01-28 13:51:26 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_stats:
|
|
|
|
{
|
|
|
|
GST_WARNING ("Could not get payloader stats");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_caps:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Retrieve the current caps of @stream.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the #GstCaps of @stream. use gst_caps_unref()
|
2014-03-23 20:24:48 +00:00
|
|
|
* after usage.
|
2012-11-29 10:11:05 +00:00
|
|
|
*/
|
|
|
|
GstCaps *
|
|
|
|
gst_rtsp_stream_get_caps (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstCaps *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->caps))
|
|
|
|
gst_caps_ref (result);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_recv_rtp:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @buffer: (transfer full): a #GstBuffer
|
|
|
|
*
|
|
|
|
* Handle an RTP buffer for the stream. This method is usually called when a
|
|
|
|
* message has been received from a client using the TCP transport.
|
|
|
|
*
|
|
|
|
* This function takes ownership of @buffer.
|
|
|
|
*
|
|
|
|
* Returns: a GstFlowReturn.
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
|
|
|
gst_rtsp_stream_recv_rtp (GstRTSPStream * stream, GstBuffer * buffer)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstFlowReturn ret;
|
2012-11-13 10:14:49 +00:00
|
|
|
GstElement *element;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_FLOW_ERROR);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-26 15:28:10 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_val_if_fail (priv->is_joined, FALSE);
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-08-16 15:05:24 +00:00
|
|
|
if (priv->appsrc[0])
|
|
|
|
element = gst_object_ref (priv->appsrc[0]);
|
|
|
|
else
|
|
|
|
element = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
2013-08-16 15:05:24 +00:00
|
|
|
if (element) {
|
|
|
|
ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
|
|
|
|
gst_object_unref (element);
|
|
|
|
} else {
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_recv_rtcp:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @buffer: (transfer full): a #GstBuffer
|
|
|
|
*
|
|
|
|
* Handle an RTCP buffer for the stream. This method is usually called when a
|
|
|
|
* message has been received from a client using the TCP transport.
|
|
|
|
*
|
|
|
|
* This function takes ownership of @buffer.
|
|
|
|
*
|
|
|
|
* Returns: a GstFlowReturn.
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
|
|
|
gst_rtsp_stream_recv_rtcp (GstRTSPStream * stream, GstBuffer * buffer)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstFlowReturn ret;
|
2012-11-13 10:14:49 +00:00
|
|
|
GstElement *element;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_FLOW_ERROR);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-26 15:28:10 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
|
|
|
|
|
2014-11-28 11:45:14 +00:00
|
|
|
if (!priv->is_joined) {
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_NOT_LINKED;
|
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-08-16 15:05:24 +00:00
|
|
|
if (priv->appsrc[1])
|
|
|
|
element = gst_object_ref (priv->appsrc[1]);
|
|
|
|
else
|
|
|
|
element = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
2013-08-16 15:05:24 +00:00
|
|
|
if (element) {
|
|
|
|
ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
|
|
|
|
gst_object_unref (element);
|
|
|
|
} else {
|
|
|
|
ret = GST_FLOW_OK;
|
2014-03-23 20:24:48 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2013-08-16 15:05:24 +00:00
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-13 10:14:49 +00:00
|
|
|
/* must be called with lock */
|
2012-10-25 19:29:58 +00:00
|
|
|
static gboolean
|
|
|
|
update_transport (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
|
|
|
|
gboolean add)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
const GstRTSPTransport *tr;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
tr = gst_rtsp_stream_transport_get_transport (trans);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
switch (tr->lower_transport) {
|
|
|
|
case GST_RTSP_LOWER_TRANS_UDP_MCAST:
|
2014-06-25 16:23:10 +00:00
|
|
|
{
|
|
|
|
GstRTSPMulticastTransportSource *source;
|
|
|
|
GstBin *bin;
|
|
|
|
|
|
|
|
bin = GST_BIN (gst_object_get_parent (GST_OBJECT (priv->funnel[0])));
|
|
|
|
|
|
|
|
if (add) {
|
|
|
|
gchar *host;
|
|
|
|
gint i;
|
|
|
|
GstPad *selpad, *pad;
|
|
|
|
|
|
|
|
source = g_slice_new0 (GstRTSPMulticastTransportSource);
|
|
|
|
source->transport = trans;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
host =
|
|
|
|
g_strdup_printf ("udp://%s:%d", tr->destination,
|
|
|
|
(i == 0) ? tr->port.min : tr->port.max);
|
|
|
|
source->udpsrc[i] =
|
|
|
|
gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
|
|
|
|
g_free (host);
|
|
|
|
|
|
|
|
/* we set and keep these to playing so that they don't cause NO_PREROLL return
|
|
|
|
* values */
|
|
|
|
gst_element_set_state (source->udpsrc[i], GST_STATE_PLAYING);
|
|
|
|
gst_element_set_locked_state (source->udpsrc[i], TRUE);
|
|
|
|
/* add udpsrc */
|
|
|
|
gst_bin_add (bin, source->udpsrc[i]);
|
|
|
|
|
|
|
|
/* and link to the funnel v4 */
|
|
|
|
source->selpad[i] = selpad =
|
|
|
|
gst_element_get_request_pad (priv->funnel[i], "sink_%u");
|
|
|
|
pad = gst_element_get_static_pad (source->udpsrc[i], "src");
|
|
|
|
gst_pad_link (pad, selpad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (selpad);
|
|
|
|
}
|
|
|
|
gst_object_unref (bin);
|
|
|
|
|
|
|
|
priv->transport_sources =
|
|
|
|
g_list_prepend (priv->transport_sources, source);
|
|
|
|
} else {
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = priv->transport_sources; l; l = l->next) {
|
|
|
|
source = l->data;
|
|
|
|
|
|
|
|
if (source->transport == trans) {
|
|
|
|
priv->transport_sources =
|
|
|
|
g_list_delete_link (priv->transport_sources, l);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l != NULL) {
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
/* Will automatically unlink everything */
|
|
|
|
gst_bin_remove (bin,
|
|
|
|
GST_ELEMENT (gst_object_ref (source->udpsrc[i])));
|
|
|
|
|
|
|
|
gst_element_set_state (source->udpsrc[i], GST_STATE_NULL);
|
|
|
|
gst_object_unref (source->udpsrc[i]);
|
|
|
|
|
|
|
|
gst_element_release_request_pad (priv->funnel[i],
|
|
|
|
source->selpad[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slice_free (GstRTSPMulticastTransportSource, source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fall through for the generic case */
|
|
|
|
}
|
|
|
|
case GST_RTSP_LOWER_TRANS_UDP:
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
|
|
|
gchar *dest;
|
|
|
|
gint min, max;
|
|
|
|
guint ttl = 0;
|
|
|
|
|
|
|
|
dest = tr->destination;
|
|
|
|
if (tr->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
|
|
|
|
min = tr->port.min;
|
|
|
|
max = tr->port.max;
|
|
|
|
ttl = tr->ttl;
|
|
|
|
} else {
|
|
|
|
min = tr->client_port.min;
|
|
|
|
max = tr->client_port.max;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (add) {
|
2012-10-25 19:29:58 +00:00
|
|
|
if (ttl > 0) {
|
|
|
|
GST_INFO ("setting ttl-mc %d", ttl);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_object_set (G_OBJECT (priv->udpsink[0]), "ttl-mc", ttl, NULL);
|
|
|
|
g_object_set (G_OBJECT (priv->udpsink[1]), "ttl-mc", ttl, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2014-02-17 09:43:05 +00:00
|
|
|
GST_INFO ("adding %s:%d-%d", dest, min, max);
|
|
|
|
g_signal_emit_by_name (priv->udpsink[0], "add", dest, min, NULL);
|
|
|
|
g_signal_emit_by_name (priv->udpsink[1], "add", dest, max, NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->transports = g_list_prepend (priv->transports, trans);
|
|
|
|
} else {
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("removing %s:%d-%d", dest, min, max);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_signal_emit_by_name (priv->udpsink[0], "remove", dest, min, NULL);
|
|
|
|
g_signal_emit_by_name (priv->udpsink[1], "remove", dest, max, NULL);
|
|
|
|
priv->transports = g_list_remove (priv->transports, trans);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2014-07-10 09:32:20 +00:00
|
|
|
priv->transports_cookie++;
|
2012-10-25 19:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_RTSP_LOWER_TRANS_TCP:
|
2012-11-29 10:11:05 +00:00
|
|
|
if (add) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("adding TCP %s", tr->destination);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->transports = g_list_prepend (priv->transports, trans);
|
|
|
|
} else {
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("removing TCP %s", tr->destination);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->transports = g_list_remove (priv->transports, trans);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2014-07-10 09:32:20 +00:00
|
|
|
priv->transports_cookie++;
|
2012-10-25 19:29:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-11-29 10:11:05 +00:00
|
|
|
goto unknown_transport;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
unknown_transport:
|
|
|
|
{
|
|
|
|
GST_INFO ("Unknown transport %d", tr->lower_transport);
|
|
|
|
return FALSE;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_add_transport:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @trans: (transfer none): a #GstRTSPStreamTransport
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Add the transport in @trans to @stream. The media of @stream will
|
|
|
|
* then also be send to the values configured in @trans.
|
|
|
|
*
|
2012-10-26 15:28:10 +00:00
|
|
|
* @stream must be joined to a bin.
|
|
|
|
*
|
2012-10-25 19:29:58 +00:00
|
|
|
* @trans must contain a valid #GstRTSPTransport.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @trans was added
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_add_transport (GstRTSPStream * stream,
|
|
|
|
GstRTSPStreamTransport * trans)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-13 10:14:49 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_val_if_fail (priv->is_joined, FALSE);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
res = update_transport (stream, trans, TRUE);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
|
|
|
return res;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_remove_transport:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @trans: (transfer none): a #GstRTSPStreamTransport
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Remove the transport in @trans from @stream. The media of @stream will
|
|
|
|
* not be sent to the values configured in @trans.
|
|
|
|
*
|
2012-10-26 15:28:10 +00:00
|
|
|
* @stream must be joined to a bin.
|
|
|
|
*
|
|
|
|
* @trans must contain a valid #GstRTSPTransport.
|
|
|
|
*
|
2012-10-25 19:29:58 +00:00
|
|
|
* Returns: %TRUE if @trans was removed
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_remove_transport (GstRTSPStream * stream,
|
|
|
|
GstRTSPStreamTransport * trans)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-13 10:14:49 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_val_if_fail (priv->is_joined, FALSE);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
res = update_transport (stream, trans, FALSE);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
|
|
|
return res;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2013-11-12 11:04:55 +00:00
|
|
|
|
2014-04-02 10:36:16 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_update_crypto:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @ssrc: the SSRC
|
2014-06-24 07:48:45 +00:00
|
|
|
* @crypto: (transfer none) (allow-none): a #GstCaps with crypto info
|
2014-04-02 10:36:16 +00:00
|
|
|
*
|
|
|
|
* Update the new crypto information for @ssrc in @stream. If information
|
|
|
|
* for @ssrc did not exist, it will be added. If information
|
|
|
|
* for @ssrc existed, it will be replaced. If @crypto is %NULL, it will
|
|
|
|
* be removed from @stream.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @crypto could be updated
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_update_crypto (GstRTSPStream * stream,
|
|
|
|
guint ssrc, GstCaps * crypto)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
2014-06-27 14:54:22 +00:00
|
|
|
g_return_val_if_fail (crypto == NULL || GST_IS_CAPS (crypto), FALSE);
|
2014-04-02 10:36:16 +00:00
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "update key for %08x", ssrc);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (crypto)
|
|
|
|
g_hash_table_insert (priv->keys, GINT_TO_POINTER (ssrc),
|
|
|
|
gst_caps_ref (crypto));
|
|
|
|
else
|
|
|
|
g_hash_table_remove (priv->keys, GINT_TO_POINTER (ssrc));
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-11-12 11:04:55 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rtp_socket:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @family: the socket family
|
|
|
|
*
|
|
|
|
* Get the RTP socket from @stream for a @family.
|
|
|
|
*
|
|
|
|
* @stream must be joined to a bin.
|
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (transfer full) (nullable): the RTP socket or %NULL if no
|
|
|
|
* socket could be allocated for @family. Unref after usage
|
2013-11-12 11:04:55 +00:00
|
|
|
*/
|
|
|
|
GSocket *
|
|
|
|
gst_rtsp_stream_get_rtp_socket (GstRTSPStream * stream, GSocketFamily family)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
|
|
|
|
GSocket *socket;
|
2014-02-09 09:45:28 +00:00
|
|
|
const gchar *name;
|
2013-11-12 11:04:55 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
g_return_val_if_fail (family == G_SOCKET_FAMILY_IPV4 ||
|
|
|
|
family == G_SOCKET_FAMILY_IPV6, NULL);
|
|
|
|
g_return_val_if_fail (priv->udpsink[0], NULL);
|
|
|
|
|
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
|
|
|
name = "socket-v6";
|
|
|
|
else
|
|
|
|
name = "socket";
|
|
|
|
|
|
|
|
g_object_get (priv->udpsink[0], name, &socket, NULL);
|
|
|
|
|
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rtcp_socket:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @family: the socket family
|
|
|
|
*
|
|
|
|
* Get the RTCP socket from @stream for a @family.
|
|
|
|
*
|
|
|
|
* @stream must be joined to a bin.
|
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (transfer full) (nullable): the RTCP socket or %NULL if no
|
|
|
|
* socket could be allocated for @family. Unref after usage
|
2013-11-12 11:04:55 +00:00
|
|
|
*/
|
|
|
|
GSocket *
|
|
|
|
gst_rtsp_stream_get_rtcp_socket (GstRTSPStream * stream, GSocketFamily family)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
|
|
|
|
GSocket *socket;
|
2014-02-09 09:45:28 +00:00
|
|
|
const gchar *name;
|
2013-11-12 11:04:55 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
g_return_val_if_fail (family == G_SOCKET_FAMILY_IPV4 ||
|
|
|
|
family == G_SOCKET_FAMILY_IPV6, NULL);
|
|
|
|
g_return_val_if_fail (priv->udpsink[1], NULL);
|
|
|
|
|
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
|
|
|
name = "socket-v6";
|
|
|
|
else
|
|
|
|
name = "socket";
|
|
|
|
|
|
|
|
g_object_get (priv->udpsink[1], name, &socket, NULL);
|
|
|
|
|
|
|
|
return socket;
|
|
|
|
}
|
2013-11-18 10:18:15 +00:00
|
|
|
|
2014-09-08 07:26:23 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_seqnum:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @seqnum: a new sequence number
|
|
|
|
*
|
|
|
|
* Configure the sequence number in the payloader of @stream to @seqnum.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_seqnum_offset (GstRTSPStream * stream, guint16 seqnum)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (priv->payloader), "seqnum-offset", seqnum, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_seqnum:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the configured sequence number in the payloader of @stream.
|
|
|
|
*
|
|
|
|
* Returns: the sequence number of the payloader.
|
|
|
|
*/
|
|
|
|
guint16
|
|
|
|
gst_rtsp_stream_get_current_seqnum (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
guint seqnum;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (priv->payloader), "seqnum", &seqnum, NULL);
|
|
|
|
|
|
|
|
return seqnum;
|
|
|
|
}
|
|
|
|
|
2013-11-18 10:18:15 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_transport_filter:
|
|
|
|
* @stream: a #GstRTSPStream
|
2013-11-18 10:47:04 +00:00
|
|
|
* @func: (scope call) (allow-none): a callback
|
2014-03-23 20:24:48 +00:00
|
|
|
* @user_data: (closure): user data passed to @func
|
2013-11-18 10:18:15 +00:00
|
|
|
*
|
|
|
|
* Call @func for each transport managed by @stream. The result value of @func
|
|
|
|
* determines what happens to the transport. @func will be called with @stream
|
|
|
|
* locked so no further actions on @stream can be performed from @func.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REMOVE, the transport will be removed from
|
|
|
|
* @stream.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_KEEP, the transport will remain in @stream.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REF, the transport will remain in @stream but
|
|
|
|
* will also be added with an additional ref to the result #GList of this
|
|
|
|
* function..
|
|
|
|
*
|
|
|
|
* When @func is %NULL, #GST_RTSP_FILTER_REF will be assumed for each transport.
|
|
|
|
*
|
|
|
|
* Returns: (element-type GstRTSPStreamTransport) (transfer full): a #GList with all
|
|
|
|
* transports 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_stream_transport_filter (GstRTSPStream * stream,
|
|
|
|
GstRTSPStreamTransportFilterFunc func, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GList *result, *walk, *next;
|
2014-07-10 09:32:20 +00:00
|
|
|
GHashTable *visited;
|
|
|
|
guint cookie;
|
2013-11-18 10:18:15 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->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-11-18 10:18:15 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2014-07-10 09:32:20 +00:00
|
|
|
restart:
|
|
|
|
cookie = priv->transports_cookie;
|
2013-11-18 10:18:15 +00:00
|
|
|
for (walk = priv->transports; walk; walk = next) {
|
|
|
|
GstRTSPStreamTransport *trans = walk->data;
|
|
|
|
GstRTSPFilterResult res;
|
2014-07-10 09:32:20 +00:00
|
|
|
gboolean changed;
|
2013-11-18 10:18:15 +00:00
|
|
|
|
|
|
|
next = g_list_next (walk);
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func) {
|
|
|
|
/* only visit each transport once */
|
|
|
|
if (g_hash_table_contains (visited, trans))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_hash_table_add (visited, g_object_ref (trans));
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2013-11-18 10:18:15 +00:00
|
|
|
res = func (stream, trans, user_data);
|
2014-07-10 09:32:20 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
} else
|
2013-11-18 10:18:15 +00:00
|
|
|
res = GST_RTSP_FILTER_REF;
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
changed = (cookie != priv->transports_cookie);
|
|
|
|
|
2013-11-18 10:18:15 +00:00
|
|
|
switch (res) {
|
|
|
|
case GST_RTSP_FILTER_REMOVE:
|
|
|
|
update_transport (stream, trans, FALSE);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_REF:
|
|
|
|
result = g_list_prepend (result, g_object_ref (trans));
|
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_KEEP:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-07-10 09:32:20 +00:00
|
|
|
if (changed)
|
|
|
|
goto restart;
|
2013-11-18 10:18:15 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func)
|
|
|
|
g_hash_table_unref (visited);
|
|
|
|
|
2013-11-18 10:18:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
2013-11-28 12:42:21 +00:00
|
|
|
|
|
|
|
static GstPadProbeReturn
|
|
|
|
pad_blocking (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPStream *stream;
|
|
|
|
|
|
|
|
stream = user_data;
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "now blocking");
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->blocking = TRUE;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
gst_element_post_message (priv->payloader,
|
|
|
|
gst_message_new_element (GST_OBJECT_CAST (priv->payloader),
|
|
|
|
gst_structure_new_empty ("GstRTSPStreamBlocking")));
|
|
|
|
|
|
|
|
return GST_PAD_PROBE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_blocked:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @blocked: boolean indicating we should block or unblock
|
|
|
|
*
|
|
|
|
* Blocks or unblocks the dataflow on @stream.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_set_blocked (GstRTSPStream * stream, gboolean blocked)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (blocked) {
|
|
|
|
priv->blocking = FALSE;
|
|
|
|
if (priv->blocked_id == 0) {
|
|
|
|
priv->blocked_id = gst_pad_add_probe (priv->srcpad,
|
|
|
|
GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER |
|
|
|
|
GST_PAD_PROBE_TYPE_BUFFER_LIST, pad_blocking,
|
|
|
|
g_object_ref (stream), g_object_unref);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (priv->blocked_id != 0) {
|
|
|
|
gst_pad_remove_probe (priv->srcpad, priv->blocked_id);
|
|
|
|
priv->blocked_id = 0;
|
|
|
|
priv->blocking = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_is_blocking:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Check if @stream is blocking on a #GstBuffer.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @stream is blocking
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_blocking (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
result = priv->blocking;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2014-08-05 14:12:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_query_position:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Query the position of the stream in %GST_FORMAT_TIME. This only considers
|
|
|
|
* the RTP parts of the pipeline and not the RTCP parts.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the position could be queried
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_query_position (GstRTSPStream * stream, gint64 * position)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstElement *sink;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((sink = priv->udpsink[0]))
|
|
|
|
gst_object_ref (sink);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
if (!sink)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ret = gst_element_query_position (sink, GST_FORMAT_TIME, position);
|
|
|
|
gst_object_unref (sink);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_query_stop:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Query the stop of the stream in %GST_FORMAT_TIME. This only considers
|
|
|
|
* the RTP parts of the pipeline and not the RTCP parts.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the stop could be queried
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_query_stop (GstRTSPStream * stream, gint64 * stop)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstElement *sink;
|
|
|
|
GstQuery *query;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((sink = priv->udpsink[0]))
|
|
|
|
gst_object_ref (sink);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
if (!sink)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
query = gst_query_new_segment (GST_FORMAT_TIME);
|
|
|
|
if ((ret = gst_element_query (sink, query))) {
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
gst_query_parse_segment (query, NULL, &format, NULL, stop);
|
|
|
|
if (format != GST_FORMAT_TIME)
|
|
|
|
*stop = -1;
|
|
|
|
}
|
|
|
|
gst_query_unref (query);
|
|
|
|
gst_object_unref (sink);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|