* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
+/**
+ * SECTION:rtsp-stream
+ * @short_description: A media stream
+ * @see_also: #GstRTSPMedia
+ *
+ * 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)
+ */
-#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
#include <gio/gio.h>
guint idx;
GstPad *srcpad;
GstElement *payloader;
- gboolean is_ipv6;
guint buffer_size;
gboolean is_joined;
+ gchar *control;
+
+ GstRTSPLowerTrans protocols;
/* pads on the rtpbin */
GstPad *send_rtp_sink;
/* the RTPSession object */
GObject *session;
- /* sinks used for sending and receiving RTP and RTCP, they share
+ /* sinks used for sending and receiving RTP and RTCP over ipv4, they share
* sockets */
- GstElement *udpsrc[2];
+ GstElement *udpsrc_v4[2];
+
+ /* sinks used for sending and receiving RTP and RTCP over ipv6, they share
+ * sockets */
+ GstElement *udpsrc_v6[2];
+
GstElement *udpsink[2];
+
/* for TCP transport */
GstElement *appsrc[2];
GstElement *appqueue[2];
GstElement *tee[2];
GstElement *funnel[2];
- /* server ports for sending/receiving */
- GstRTSPRange server_port;
- GstRTSPAddress *server_addr;
+ /* server ports for sending/receiving over ipv4 */
+ GstRTSPRange server_port_v4;
+ GstRTSPAddress *server_addr_v4;
+ gboolean have_ipv4;
+
+ /* server ports for sending/receiving over ipv6 */
+ GstRTSPRange server_port_v6;
+ GstRTSPAddress *server_addr_v6;
+ gboolean have_ipv6;
/* multicast addresses */
GstRTSPAddressPool *pool;
- GstRTSPAddress *addr;
+ GstRTSPAddress *addr_v4;
+ GstRTSPAddress *addr_v6;
/* the caps of the stream */
gulong caps_sig;
/* transports we stream to */
guint n_active;
GList *transports;
+
+ gint dscp_qos;
};
+#define DEFAULT_CONTROL NULL
+#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | \
+ GST_RTSP_LOWER_TRANS_TCP
enum
{
PROP_0,
+ PROP_CONTROL,
+ PROP_PROTOCOLS,
PROP_LAST
};
static GQuark ssrc_stream_map_key;
+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);
+
static void gst_rtsp_stream_finalize (GObject * obj);
G_DEFINE_TYPE (GstRTSPStream, gst_rtsp_stream, G_TYPE_OBJECT);
gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->get_property = gst_rtsp_stream_get_property;
+ gobject_class->set_property = gst_rtsp_stream_set_property;
gobject_class->finalize = gst_rtsp_stream_finalize;
+ 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));
+
+ 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));
+
GST_DEBUG_CATEGORY_INIT (rtsp_stream_debug, "rtspstream", 0, "GstRTSPStream");
ssrc_stream_map_key = g_quark_from_static_string ("GstRTSPServer.stream");
stream->priv = priv;
+ priv->dscp_qos = -1;
+ priv->control = g_strdup (DEFAULT_CONTROL);
+ priv->protocols = DEFAULT_PROTOCOLS;
+
g_mutex_init (&priv->lock);
}
/* we really need to be unjoined now */
g_return_if_fail (!priv->is_joined);
- if (priv->addr)
- gst_rtsp_address_free (priv->addr);
- if (priv->server_addr)
- gst_rtsp_address_free (priv->server_addr);
+ if (priv->addr_v4)
+ gst_rtsp_address_free (priv->addr_v4);
+ if (priv->addr_v6)
+ gst_rtsp_address_free (priv->addr_v6);
+ 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);
if (priv->pool)
g_object_unref (priv->pool);
gst_object_unref (priv->payloader);
gst_object_unref (priv->srcpad);
+ g_free (priv->control);
g_mutex_clear (&priv->lock);
G_OBJECT_CLASS (gst_rtsp_stream_parent_class)->finalize (obj);
}
+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;
+ case PROP_PROTOCOLS:
+ g_value_set_flags (value, gst_rtsp_stream_get_protocols (stream));
+ break;
+ 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;
+ case PROP_PROTOCOLS:
+ gst_rtsp_stream_set_protocols (stream, g_value_get_flags (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
+ }
+}
+
/**
* gst_rtsp_stream_new:
* @idx: an index
}
/**
+ * gst_rtsp_stream_get_srcpad:
+ * @stream: a #GstRTSPStream
+ *
+ * Get the srcpad associated with @stream.
+ *
+ * Returns: (transfer full): the srcpad. Unref after usage.
+ */
+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);
+}
+
+/**
+ * gst_rtsp_stream_get_control:
+ * @stream: a #GstRTSPStream
+ *
+ * Get the control string to identify this stream.
+ *
+ * Returns: (transfer full): the control string. free after usage.
+ */
+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)
+ result = g_strdup_printf ("stream=%u", priv->idx);
+ 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);
+}
+
+/**
+ * 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)
+ res = (g_strcmp0 (priv->control, control) == 0);
+ else {
+ guint streamid;
+ sscanf (control, "stream=%u", &streamid);
+ res = (streamid == priv->idx);
+ }
+ g_mutex_unlock (&priv->lock);
+
+ return res;
+}
+
+/**
* gst_rtsp_stream_set_mtu:
* @stream: a #GstRTSPStream
* @mtu: a new MTU
return mtu;
}
+/* Update the dscp qos property on the udp sinks */
+static void
+update_dscp_qos (GstRTSPStream * stream)
+{
+ 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
+gst_rtsp_stream_set_dscp_qos (GstRTSPStream * stream, gint dscp_qos)
+{
+ 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
+gst_rtsp_stream_get_dscp_qos (GstRTSPStream * stream)
+{
+ GstRTSPStreamPrivate *priv;
+
+ g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
+
+ priv = stream->priv;
+
+ return priv->dscp_qos;
+}
+
+/**
+ * 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;
+}
+
/**
* gst_rtsp_stream_set_address_pool:
* @stream: a #GstRTSPStream
}
/**
- * gst_rtsp_stream_get_address:
+ * gst_rtsp_stream_get_multicast_address:
* @stream: a #GstRTSPStream
+ * @family: the #GSocketFamily
*
- * Get the multicast address of @stream.
+ * Get the multicast address of @stream for @family.
*
* Returns: the #GstRTSPAddress of @stream or %NULL when no address could be
* allocated. gst_rtsp_address_free() after usage.
*/
GstRTSPAddress *
-gst_rtsp_stream_get_address (GstRTSPStream * stream)
+gst_rtsp_stream_get_multicast_address (GstRTSPStream * stream,
+ GSocketFamily family)
{
GstRTSPStreamPrivate *priv;
GstRTSPAddress *result;
+ GstRTSPAddress **addrp;
+ GstRTSPAddressFlags flags;
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
priv = stream->priv;
+ if (family == G_SOCKET_FAMILY_IPV6) {
+ flags = GST_RTSP_ADDRESS_FLAG_IPV6;
+ addrp = &priv->addr_v4;
+ } else {
+ flags = GST_RTSP_ADDRESS_FLAG_IPV4;
+ addrp = &priv->addr_v6;
+ }
+
g_mutex_lock (&priv->lock);
- if (priv->addr == NULL) {
+ if (*addrp == NULL) {
if (priv->pool == NULL)
goto no_pool;
- priv->addr = gst_rtsp_address_pool_acquire_address (priv->pool,
- GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
- if (priv->addr == NULL)
+ 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)
goto no_address;
}
- result = gst_rtsp_address_copy (priv->addr);
+ result = gst_rtsp_address_copy (*addrp);
g_mutex_unlock (&priv->lock);
return result;
/**
* gst_rtsp_stream_reserve_address:
* @stream: a #GstRTSPStream
+ * @address: an address
+ * @port: a port
+ * @n_ports: n_ports
+ * @ttl: a TTL
*
- * Get a specific multicast address of @stream.
+ * Reserve @address and @port as the address and port of @stream.
*
- * Returns: the #GstRTSPAddress of @stream or %NULL when no address could be
- * allocated. gst_rtsp_address_free() after usage.
+ * Returns: the #GstRTSPAddress of @stream or %NULL when the address could be
+ * reserved. gst_rtsp_address_free() after usage.
*/
GstRTSPAddress *
gst_rtsp_stream_reserve_address (GstRTSPStream * stream,
{
GstRTSPStreamPrivate *priv;
GstRTSPAddress *result;
+ GInetAddress *addr;
+ GSocketFamily family;
+ GstRTSPAddress **addrp;
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
g_return_val_if_fail (address != NULL, NULL);
priv = stream->priv;
+ 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_v4;
+ else
+ addrp = &priv->addr_v6;
+
g_mutex_lock (&priv->lock);
- if (priv->addr == NULL) {
+ if (*addrp == NULL) {
+ GstRTSPAddressPoolResult res;
+
if (priv->pool == NULL)
goto no_pool;
- priv->addr = gst_rtsp_address_pool_reserve_address (priv->pool, address,
- port, n_ports, ttl);
- if (priv->addr == NULL)
+ res = gst_rtsp_address_pool_reserve_address (priv->pool, address,
+ port, n_ports, ttl, addrp);
+ if (res != GST_RTSP_ADDRESS_POOL_OK)
goto no_address;
} else {
- if (strcmp (priv->addr->address, address) ||
- priv->addr->port != port || priv->addr->n_ports != n_ports ||
- priv->addr->ttl != ttl)
+ if (strcmp ((*addrp)->address, address) ||
+ (*addrp)->port != port || (*addrp)->n_ports != n_ports ||
+ (*addrp)->ttl != ttl)
goto different_address;
}
- result = gst_rtsp_address_copy (priv->addr);
+ result = gst_rtsp_address_copy (*addrp);
g_mutex_unlock (&priv->lock);
return result;
}
}
-/* must be called with lock */
static gboolean
-alloc_ports (GstRTSPStream * stream)
+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)
{
- GstRTSPStreamPrivate *priv = stream->priv;
GstStateChangeReturn ret;
GstElement *udpsrc0, *udpsrc1;
GstElement *udpsink0, *udpsink1;
gint rtpport, rtcpport;
GList *rejected_addresses = NULL;
GstRTSPAddress *addr = NULL;
- GSocketFamily family;
GInetAddress *inetaddr = NULL;
GSocketAddress *rtp_sockaddr = NULL;
GSocketAddress *rtcp_sockaddr = NULL;
+ const gchar *multisink_socket;
+
+ if (family == G_SOCKET_FAMILY_IPV6)
+ multisink_socket = "socket-v6";
+ else
+ multisink_socket = "socket";
udpsrc0 = NULL;
udpsrc1 = NULL;
/* Start with random port */
tmp_rtp = 0;
- if (priv->is_ipv6) {
- family = G_SOCKET_FAMILY_IPV6;
- } else {
- family = G_SOCKET_FAMILY_IPV4;
- }
-
rtcp_socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
G_SOCKET_PROTOCOL_UDP, NULL);
if (!rtcp_socket)
goto no_udp_protocol;
- if (priv->server_addr)
- gst_rtsp_address_free (priv->server_addr);
+ if (*server_addr_out)
+ gst_rtsp_address_free (*server_addr_out);
/* try to allocate 2 UDP ports, the RTP port should be an even
* number and the RTCP port should be the next (uneven) port */
goto no_udp_protocol;
}
- if (priv->pool && gst_rtsp_address_pool_has_unicast_addresses (priv->pool)) {
+ if (pool && gst_rtsp_address_pool_has_unicast_addresses (pool)) {
GstRTSPAddressFlags flags;
if (addr)
rejected_addresses = g_list_prepend (rejected_addresses, addr);
flags = GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_UNICAST;
- if (priv->is_ipv6)
+ if (family == G_SOCKET_FAMILY_IPV6)
flags |= GST_RTSP_ADDRESS_FLAG_IPV6;
else
flags |= GST_RTSP_ADDRESS_FLAG_IPV4;
- addr = gst_rtsp_address_pool_acquire_address (priv->pool, flags, 2);
+ addr = gst_rtsp_address_pool_acquire_address (pool, flags, 2);
if (addr == NULL)
goto no_ports;
if (rtpport != tmp_rtp || rtcpport != tmp_rtcp)
goto port_error;
- udpsink0 = gst_element_factory_make ("multiudpsink", NULL);
+ if (udpsink_out[0])
+ udpsink0 = udpsink_out[0];
+ else
+ udpsink0 = gst_element_factory_make ("multiudpsink", NULL);
+
if (!udpsink0)
goto no_udp_protocol;
g_object_set (G_OBJECT (udpsink0), "close-socket", FALSE, NULL);
- g_object_set (G_OBJECT (udpsink0), "socket", rtp_socket, NULL);
+ 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);
- udpsink1 = gst_element_factory_make ("multiudpsink", NULL);
if (!udpsink1)
goto no_udp_protocol;
g_object_set (G_OBJECT (udpsink0), "send-duplicates", FALSE, NULL);
g_object_set (G_OBJECT (udpsink1), "send-duplicates", FALSE, NULL);
- g_object_set (G_OBJECT (udpsink0), "buffer-size", priv->buffer_size, NULL);
+ g_object_set (G_OBJECT (udpsink0), "buffer-size", buffer_size, NULL);
g_object_set (G_OBJECT (udpsink1), "close-socket", FALSE, NULL);
- g_object_set (G_OBJECT (udpsink1), "socket", rtcp_socket, NULL);
+ g_object_set (G_OBJECT (udpsink1), multisink_socket, rtcp_socket, NULL);
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);
/* we keep these elements, we will further configure them when the
* client told us to really use the UDP ports. */
- priv->udpsrc[0] = udpsrc0;
- priv->udpsrc[1] = udpsrc1;
- priv->udpsink[0] = udpsink0;
- priv->udpsink[1] = udpsink1;
- priv->server_port.min = rtpport;
- priv->server_port.max = rtcpport;
-
- priv->server_addr = addr;
+ udpsrc_out[0] = udpsrc0;
+ udpsrc_out[1] = udpsrc1;
+ udpsink_out[0] = udpsink0;
+ udpsink_out[1] = udpsink1;
+ server_port_out->min = rtpport;
+ server_port_out->max = rtcpport;
+
+ *server_addr_out = addr;
g_list_free_full (rejected_addresses, (GDestroyNotify) gst_rtsp_address_free);
g_object_unref (rtp_socket);
}
}
+/* must be called with lock */
+static gboolean
+alloc_ports (GstRTSPStream * stream)
+{
+ GstRTSPStreamPrivate *priv = stream->priv;
+
+ priv->have_ipv4 = alloc_ports_one_family (priv->pool, priv->buffer_size,
+ G_SOCKET_FAMILY_IPV4, priv->udpsrc_v4, priv->udpsink,
+ &priv->server_port_v4, &priv->server_addr_v4);
+
+ priv->have_ipv6 = alloc_ports_one_family (priv->pool, priv->buffer_size,
+ G_SOCKET_FAMILY_IPV6, priv->udpsrc_v6, priv->udpsink,
+ &priv->server_port_v6, &priv->server_addr_v6);
+
+ return priv->have_ipv4 || priv->have_ipv6;
+}
+
/**
* gst_rtsp_stream_get_server_port:
* @stream: a #GstRTSPStream
* @server_port: (out): result server port
+ * @family: the port family to get
*
* 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,
- GstRTSPRange * server_port)
+ GstRTSPRange * server_port, GSocketFamily family)
{
GstRTSPStreamPrivate *priv;
g_return_if_fail (priv->is_joined);
g_mutex_lock (&priv->lock);
- if (server_port)
- *server_port = priv->server_port;
+ 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;
+ }
+ g_mutex_unlock (&priv->lock);
+}
+
+/**
+ * gst_rtsp_stream_get_rtpsession:
+ * @stream: a #GstRTSPStream
+ *
+ * Get the RTP session of this stream.
+ *
+ * Returns: (transfer full): The RTP session of this stream. Unref after usage.
+ */
+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;
}
/**
break;
}
}
+ if (result)
+ g_object_ref (result);
g_mutex_unlock (&priv->lock);
g_free (dest);
if ((trans = find_transport (stream, rtcp_from))) {
GST_INFO ("%p: found transport %p for source %p", stream, trans,
source);
- g_object_set_qdata (source, ssrc_stream_map_key, trans);
+ g_object_set_qdata_full (source, ssrc_stream_map_key, trans,
+ g_object_unref);
}
gst_structure_free (stats);
}
if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
+ g_object_set_qdata (source, ssrc_stream_map_key, NULL);
}
}
if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
+ g_object_set_qdata (source, ssrc_stream_map_key, NULL);
}
}
GstElement * rtpbin, GstState state)
{
GstRTSPStreamPrivate *priv;
- gint i, idx;
+ gint i;
+ guint idx;
gchar *name;
- GstPad *pad, *teepad, *queuepad, *selpad;
+ GstPad *pad, *sinkpad, *selpad;
GstPadLinkReturn ret;
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
/* create a session with the same index as the stream */
idx = priv->idx;
- GST_INFO ("stream %p joining bin as session %d", stream, idx);
+ GST_INFO ("stream %p joining bin as session %u", stream, idx);
if (!alloc_ports (stream))
goto no_ports;
+ /* update the dscp qos field in the sinks */
+ update_dscp_qos (stream);
+
/* get a pad for sending RTP */
name = g_strdup_printf ("send_rtp_sink_%u", idx);
priv->send_rtp_sink = gst_element_get_request_pad (rtpbin, name);
stream);
for (i = 0; i < 2; i++) {
+ GstPad *teepad, *queuepad;
/* 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
* | | | queue | | appsink |
* | src->sink src->sink |
* '-----' '---------' '---------'
+ *
+ * When only UDP is allowed, we skip the tee, queue and appsink and link the
+ * udpsink directly to the session.
*/
- /* 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);
-
/* add udpsink */
gst_bin_add (bin, priv->udpsink[i]);
-
- /* link tee to udpsink */
- teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
- pad = gst_element_get_static_pad (priv->udpsink[i], "sink");
- gst_pad_link (teepad, pad);
- gst_object_unref (pad);
- 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);
+ sinkpad = gst_element_get_static_pad (priv->udpsink[i], "sink");
+
+ 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);
/* For the receiver we create this bit of pipeline for both
* RTP and RTCP. We receive RTP/RTCP on appsrc and udpsrc
gst_pad_link (pad, priv->recv_sink[i]);
gst_object_unref (pad);
- /* we set and keep these to playing so that they don't cause NO_PREROLL return
- * values */
- gst_element_set_state (priv->udpsrc[i], GST_STATE_PLAYING);
- gst_element_set_locked_state (priv->udpsrc[i], TRUE);
- /* add udpsrc */
- gst_bin_add (bin, priv->udpsrc[i]);
- /* and link to the funnel */
- selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
- pad = gst_element_get_static_pad (priv->udpsrc[i], "src");
- gst_pad_link (pad, selpad);
- gst_object_unref (pad);
- gst_object_unref (selpad);
-
- /* 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);
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
/* check if we need to set to a special state */
if (state != GST_STATE_NULL) {
- gst_element_set_state (priv->udpsink[i], state);
- gst_element_set_state (priv->appsink[i], state);
- gst_element_set_state (priv->appqueue[i], state);
- gst_element_set_state (priv->tee[i], state);
- gst_element_set_state (priv->funnel[i], state);
- gst_element_set_state (priv->appsrc[i], state);
+ 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);
}
}
no_ports:
{
g_mutex_unlock (&priv->lock);
- GST_WARNING ("failed to allocate ports %d", idx);
+ GST_WARNING ("failed to allocate ports %u", idx);
return FALSE;
}
link_failed:
{
- GST_WARNING ("failed to link stream %d", idx);
+ GST_WARNING ("failed to link stream %u", idx);
gst_object_unref (priv->send_rtp_sink);
priv->send_rtp_sink = NULL;
g_mutex_unlock (&priv->lock);
* @bin: a #GstBin
* @rtpbin: a rtpbin #GstElement
*
- * Remove the elements of @stream from @bin. @bin must be set
- * to the NULL state before calling this.
+ * Remove the elements of @stream from @bin.
*
* Return: %TRUE on success.
*/
priv->send_rtp_sink = NULL;
for (i = 0; i < 2; i++) {
- /* and set udpsrc to NULL now before removing */
- gst_element_set_locked_state (priv->udpsrc[i], FALSE);
- gst_element_set_state (priv->udpsrc[i], GST_STATE_NULL);
-
- /* removing them should also nicely release the request
- * pads when they finalize */
- gst_bin_remove (bin, priv->udpsrc[i]);
- gst_bin_remove (bin, priv->udpsink[i]);
- gst_bin_remove (bin, priv->appsrc[i]);
- gst_bin_remove (bin, priv->appsink[i]);
- gst_bin_remove (bin, priv->appqueue[i]);
- gst_bin_remove (bin, priv->tee[i]);
- gst_bin_remove (bin, priv->funnel[i]);
+ 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);
+ 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]);
+ }
+ 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]);
gst_element_release_request_pad (rtpbin, priv->recv_sink[i]);
gst_object_unref (priv->recv_sink[i]);
priv->recv_sink[i] = NULL;
- priv->udpsrc[i] = NULL;
+ priv->udpsrc_v4[i] = NULL;
+ priv->udpsrc_v6[i] = NULL;
priv->udpsink[i] = NULL;
priv->appsrc[i] = NULL;
priv->appsink[i] = NULL;
priv->send_src[1] = NULL;
g_object_unref (priv->session);
+ priv->session = NULL;
if (priv->caps)
gst_caps_unref (priv->caps);
+ priv->caps = NULL;
priv->is_joined = FALSE;
g_mutex_unlock (&priv->lock);
g_return_val_if_fail (priv->is_joined, FALSE);
g_mutex_lock (&priv->lock);
- element = gst_object_ref (priv->appsrc[0]);
+ if (priv->appsrc[0])
+ element = gst_object_ref (priv->appsrc[0]);
+ else
+ element = NULL;
g_mutex_unlock (&priv->lock);
- ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
-
- gst_object_unref (element);
-
+ if (element) {
+ ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
+ gst_object_unref (element);
+ } else {
+ ret = GST_FLOW_OK;
+ }
return ret;
}
g_return_val_if_fail (priv->is_joined, FALSE);
g_mutex_lock (&priv->lock);
- element = gst_object_ref (priv->appsrc[1]);
+ if (priv->appsrc[1])
+ element = gst_object_ref (priv->appsrc[1]);
+ else
+ element = NULL;
g_mutex_unlock (&priv->lock);
- ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
-
- gst_object_unref (element);
-
+ if (element) {
+ ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
+ gst_object_unref (element);
+ } else {
+ ret = GST_FLOW_OK;
+ }
return ret;
}