#define GST_RTSP_STREAM_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_STREAM, GstRTSPStreamPrivate))
-/* Container for udpsrc elements created for a specific RTSPTransport. */
-typedef struct
-{
- GstElement *udpsrc[2];
-} GstRTSPStreamUDPSrcs;
-
-static void
-destroy_udp_srcs_func (gpointer data)
-{
- g_slice_free (GstRTSPStreamUDPSrcs, (GstRTSPStreamUDPSrcs *) data);
-}
-
struct _GstRTSPStreamPrivate
{
GMutex lock;
GstPad *srcpad, *sinkpad;
GstElement *payloader;
guint buffer_size;
- gboolean is_joined;
GstBin *joined_bin;
/* TRUE if this stream is running on
GstElement *srtpdec;
GHashTable *keys;
- /* Unicast UDP sources associated with RTSPTransports */
- GHashTable *udpsrcs;
-
- /* Only allow one set of IPV4 and IPV6 multicast udpsrcs */
- GstElement *udpsrc_mcast_v4[2];
- GstElement *udpsrc_mcast_v6[2];
-
+ /* for UDP unicast */
+ GstElement *udpsrc_v4[2];
+ GstElement *udpsrc_v6[2];
GstElement *udpqueue[2];
GstElement *udpsink[2];
+ /* for UDP multicast */
+ GstElement *mcast_udpsrc_v4[2];
+ GstElement *mcast_udpsrc_v6[2];
+ GstElement *mcast_udpqueue[2];
+ GstElement *mcast_udpsink[2];
+
/* for TCP transport */
GstElement *appsrc[2];
GstClockTime appsrc_base_time[2];
guint rtx_pt;
GstClockTime rtx_time;
- /* server ports for sending/receiving over ipv4 */
- GstRTSPRange server_port_v4;
- GstRTSPAddress *server_addr_v4;
+ /* pool used to manage unicast and multicast addresses */
+ GstRTSPAddressPool *pool;
- /* server ports for sending/receiving over ipv6 */
- GstRTSPRange server_port_v6;
+ /* unicast server addr/port */
+ GstRTSPAddress *server_addr_v4;
GstRTSPAddress *server_addr_v6;
/* multicast addresses */
- GstRTSPAddressPool *pool;
- GstRTSPAddress *addr_v4;
- GstRTSPAddress *addr_v6;
- gboolean have_ipv4_mcast;
- gboolean have_ipv6_mcast;
+ GstRTSPAddress *mcast_addr_v4;
+ GstRTSPAddress *mcast_addr_v6;
gchar *multicast_iface;
guint tr_cache_cookie_rtp;
guint tr_cache_cookie_rtcp;
-
gint dscp_qos;
/* stream blocking */
NULL, (GDestroyNotify) gst_caps_unref);
priv->ptmap = g_hash_table_new_full (NULL, NULL, NULL,
(GDestroyNotify) gst_caps_unref);
- priv->udpsrcs = g_hash_table_new_full (g_direct_hash, g_direct_equal,
- NULL, (GDestroyNotify) destroy_udp_srcs_func);
}
static void
GST_DEBUG ("finalize stream %p", stream);
/* we really need to be unjoined now */
- g_return_if_fail (!priv->is_joined);
+ g_return_if_fail (priv->joined_bin == NULL);
- if (priv->addr_v4)
- gst_rtsp_address_free (priv->addr_v4);
- if (priv->addr_v6)
- gst_rtsp_address_free (priv->addr_v6);
+ if (priv->mcast_addr_v4)
+ gst_rtsp_address_free (priv->mcast_addr_v4);
+ if (priv->mcast_addr_v6)
+ gst_rtsp_address_free (priv->mcast_addr_v6);
if (priv->server_addr_v4)
gst_rtsp_address_free (priv->server_addr_v4);
if (priv->server_addr_v6)
g_hash_table_unref (priv->keys);
g_hash_table_destroy (priv->ptmap);
- /* We expect all udpsrcs to be cleaned up by this point. */
- if (g_hash_table_size (priv->udpsrcs) > 0)
- g_critical ("Unreffing udpsrcs hash table that contains elements.");
- g_hash_table_unref (priv->udpsrcs);
-
G_OBJECT_CLASS (gst_rtsp_stream_parent_class)->finalize (obj);
}
/* Update the dscp qos property on the udp sinks */
static void
-update_dscp_qos (GstRTSPStream * stream)
+update_dscp_qos (GstRTSPStream * stream, GstElement * udpsink[2])
{
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 (udpsink[0]) {
+ g_object_set (G_OBJECT (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);
+ if (udpsink[1]) {
+ g_object_set (G_OBJECT (udpsink[1]), "qos-dscp", priv->dscp_qos, NULL);
}
}
priv->dscp_qos = dscp_qos;
- update_dscp_qos (stream);
+ update_dscp_qos (stream, priv->udpsink);
}
/**
return result;
}
-/**
- * gst_rtsp_stream_get_multicast_address:
- * @stream: a #GstRTSPStream
- * @family: the #GSocketFamily
- *
- * Get the multicast address of @stream for @family.
- *
- * Returns: (transfer full) (nullable): the #GstRTSPAddress of @stream
- * or %NULL when no address could be allocated. gst_rtsp_address_free()
- * after usage.
- */
-GstRTSPAddress *
-gst_rtsp_stream_get_multicast_address (GstRTSPStream * stream,
+
+static GstRTSPAddress *
+gst_rtsp_stream_get_multicast_address_locked (GstRTSPStream * stream,
GSocketFamily family)
{
GstRTSPStreamPrivate *priv;
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_v6;
+ addrp = &priv->mcast_addr_v6;
} else {
flags = GST_RTSP_ADDRESS_FLAG_IPV4;
- addrp = &priv->addr_v4;
+ addrp = &priv->mcast_addr_v4;
}
- g_mutex_lock (&priv->lock);
if (*addrp == NULL) {
if (priv->pool == NULL)
goto no_pool;
*addrp = gst_rtsp_address_pool_acquire_address (priv->pool, flags, 2);
if (*addrp == NULL)
goto no_address;
+
+ /* FIXME: Also reserve the same port with unicast ANY address, since that's
+ * where we are going to bind our socket. Probably loop until we find a port
+ * available in both mcast and unicast pools. Maybe GstRTSPAddressPool
+ * should do it for us when both GST_RTSP_ADDRESS_FLAG_MULTICAST and
+ * GST_RTSP_ADDRESS_FLAG_UNICAST are givent. */
}
result = gst_rtsp_address_copy (*addrp);
- g_mutex_unlock (&priv->lock);
return result;
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 from pool");
- g_mutex_unlock (&priv->lock);
return NULL;
}
}
/**
+ * gst_rtsp_stream_get_multicast_address:
+ * @stream: a #GstRTSPStream
+ * @family: the #GSocketFamily
+ *
+ * Get the multicast address of @stream for @family. The original
+ * #GstRTSPAddress is cached and copy is returned, so freeing the return value
+ * won't release the address from the pool.
+ *
+ * Returns: (transfer full) (nullable): the #GstRTSPAddress of @stream
+ * or %NULL when no address could be allocated. gst_rtsp_address_free()
+ * after usage.
+ */
+GstRTSPAddress *
+gst_rtsp_stream_get_multicast_address (GstRTSPStream * stream,
+ GSocketFamily family)
+{
+ GstRTSPAddress *result;
+
+ g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
+
+ g_mutex_lock (&stream->priv->lock);
+ result = gst_rtsp_stream_get_multicast_address_locked (stream, family);
+ g_mutex_unlock (&stream->priv->lock);
+
+ return result;
+}
+
+/**
* gst_rtsp_stream_reserve_address:
* @stream: a #GstRTSPStream
* @address: an address
* @n_ports: n_ports
* @ttl: a TTL
*
- * Reserve @address and @port as the address and port of @stream.
+ * Reserve @address and @port as the address and port of @stream. The original
+ * #GstRTSPAddress is cached and copy is returned, so freeing the return value
+ * won't release the address from the pool.
*
* Returns: (nullable): the #GstRTSPAddress of @stream or %NULL when
* the address could be reserved. gst_rtsp_address_free() after usage.
}
if (family == G_SOCKET_FAMILY_IPV6)
- addrp = &priv->addr_v6;
+ addrp = &priv->mcast_addr_v6;
else
- addrp = &priv->addr_v4;
+ addrp = &priv->mcast_addr_v4;
g_mutex_lock (&priv->lock);
if (*addrp == NULL) {
port, n_ports, ttl, addrp);
if (res != GST_RTSP_ADDRESS_POOL_OK)
goto no_address;
+
+ /* FIXME: Also reserve the same port with unicast ANY address, since that's
+ * where we are going to bind our socket. */
} else {
- if (strcmp ((*addrp)->address, address) ||
+ if (g_ascii_strcasecmp ((*addrp)->address, address) ||
(*addrp)->port != port || (*addrp)->n_ports != n_ports ||
(*addrp)->ttl != ttl)
goto different_address;
}
different_address:
{
- GST_ERROR_OBJECT (stream, "address %s is not the same that was already"
- " reserved", address);
+ GST_ERROR_OBJECT (stream,
+ "address %s is not the same as %s that was already" " reserved",
+ address, (*addrp)->address);
g_mutex_unlock (&priv->lock);
return NULL;
}
/* must be called with lock */
static void
-set_sockets_for_udpsinks (GstRTSPStream * stream, GSocket * rtp_socket,
+set_sockets_for_udpsinks (GstElement * udpsink[2], GSocket * rtp_socket,
GSocket * rtcp_socket, GSocketFamily family)
{
- GstRTSPStreamPrivate *priv = stream->priv;
const gchar *multisink_socket;
if (family == G_SOCKET_FAMILY_IPV6)
else
multisink_socket = "socket";
- g_object_set (G_OBJECT (priv->udpsink[0]), multisink_socket, rtp_socket,
- NULL);
- g_object_set (G_OBJECT (priv->udpsink[1]), multisink_socket, rtcp_socket,
- NULL);
+ g_object_set (G_OBJECT (udpsink[0]), multisink_socket, rtp_socket, NULL);
+ g_object_set (G_OBJECT (udpsink[1]), multisink_socket, rtcp_socket, NULL);
}
-/* must be called with lock */
static gboolean
-create_and_configure_udpsinks (GstRTSPStream * stream)
+create_and_configure_udpsinks (GstRTSPStream * stream, GstElement * udpsink[2])
{
GstRTSPStreamPrivate *priv = stream->priv;
GstElement *udpsink0, *udpsink1;
- udpsink0 = NULL;
- udpsink1 = NULL;
-
- if (priv->udpsink[0])
- udpsink0 = priv->udpsink[0];
- else
- udpsink0 = gst_element_factory_make ("multiudpsink", NULL);
+ udpsink0 = gst_element_factory_make ("multiudpsink", NULL);
+ udpsink1 = gst_element_factory_make ("multiudpsink", NULL);
- if (!udpsink0)
- goto no_udp_protocol;
-
- if (priv->udpsink[1])
- udpsink1 = priv->udpsink[1];
- else
- udpsink1 = gst_element_factory_make ("multiudpsink", NULL);
-
- if (!udpsink1)
+ if (!udpsink0 || !udpsink1)
goto no_udp_protocol;
/* configure sinks */
g_object_set (G_OBJECT (udpsink0), "async", 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 (udpsink1), "auto-multicast", FALSE, NULL);
+ /* join multicast group when adding clients, so we'll start receiving from it.
+ * We cannot rely on the udpsrc to join the group since its socket is always a
+ * local unicast one. */
+ g_object_set (G_OBJECT (udpsink0), "auto-multicast", TRUE, NULL);
+ g_object_set (G_OBJECT (udpsink1), "auto-multicast", TRUE, NULL);
g_object_set (G_OBJECT (udpsink0), "loop", FALSE, NULL);
g_object_set (G_OBJECT (udpsink1), "loop", FALSE, NULL);
- /* update the dscp qos field in the sinks */
- update_dscp_qos (stream);
+ udpsink[0] = udpsink0;
+ udpsink[1] = udpsink1;
- priv->udpsink[0] = udpsink0;
- priv->udpsink[1] = udpsink1;
+ /* update the dscp qos field in the sinks */
+ update_dscp_qos (stream, udpsink);
return TRUE;
}
/* must be called with lock */
-static void
-play_udpsources_one_family (GstRTSPStream * stream, GstElement * udpsrc_out[2],
- GSocketFamily family)
-{
- GstRTSPStreamPrivate *priv;
- GstPad *pad, *selpad;
- guint i;
- GstBin *bin;
-
- priv = stream->priv;
- bin = GST_BIN (gst_object_get_parent (GST_OBJECT (priv->funnel[1])));
-
- for (i = 0; i < 2; i++) {
- if (priv->sinkpad || i == 1) {
- if (priv->srcpad) {
- /* we set and keep these to playing so that they don't cause NO_PREROLL return
- * values. This is only relevant for PLAY pipelines */
- gst_element_set_state (udpsrc_out[i], GST_STATE_PLAYING);
- gst_element_set_locked_state (udpsrc_out[i], TRUE);
- }
- /* add udpsrc */
- gst_bin_add (bin, udpsrc_out[i]);
-
- /* and link to the funnel */
- selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
- pad = gst_element_get_static_pad (udpsrc_out[i], "src");
- gst_pad_link (pad, selpad);
- gst_object_unref (pad);
- gst_object_unref (selpad);
-
- /* otherwise sync state with parent in case it's running already
- * at this point */
- if (!priv->srcpad) {
- gst_element_sync_state_with_parent (udpsrc_out[i]);
- }
- }
- }
-
- gst_object_unref (bin);
-}
-
-/* must be called with lock */
static gboolean
-create_and_configure_udpsources_one_family (GstElement * udpsrc_out[2],
- GSocket * rtp_socket, GSocket * rtcp_socket, GSocketFamily family,
- const gchar * address, gint rtpport, gint rtcpport,
- const gchar * multicast_iface, GstRTSPLowerTrans transport)
+create_and_configure_udpsources (GstElement * udpsrc_out[2],
+ GSocket * rtp_socket, GSocket * rtcp_socket)
{
GstStateChangeReturn ret;
if (udpsrc_out[0] == NULL || udpsrc_out[1] == NULL)
goto error;
- if (transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
- g_object_set (G_OBJECT (udpsrc_out[0]), "address", address, NULL);
- g_object_set (G_OBJECT (udpsrc_out[1]), "address", address, NULL);
- g_object_set (G_OBJECT (udpsrc_out[0]), "port", rtpport, NULL);
- g_object_set (G_OBJECT (udpsrc_out[1]), "port", rtcpport, NULL);
- g_object_set (G_OBJECT (udpsrc_out[0]), "multicast-iface", multicast_iface,
- NULL);
- g_object_set (G_OBJECT (udpsrc_out[1]), "multicast-iface", multicast_iface,
- NULL);
- g_object_set (G_OBJECT (udpsrc_out[0]), "loop", FALSE, NULL);
- g_object_set (G_OBJECT (udpsrc_out[1]), "loop", FALSE, NULL);
- }
-
g_object_set (G_OBJECT (udpsrc_out[0]), "socket", rtp_socket, NULL);
g_object_set (G_OBJECT (udpsrc_out[1]), "socket", rtcp_socket, NULL);
+ /* The udpsrc cannot do the join because its socket is always a local unicast
+ * one. The udpsink sharing the same socket will do it for us. */
+ g_object_set (G_OBJECT (udpsrc_out[0]), "auto-multicast", FALSE, NULL);
+ g_object_set (G_OBJECT (udpsrc_out[1]), "auto-multicast", FALSE, NULL);
+
+ g_object_set (G_OBJECT (udpsrc_out[0]), "loop", FALSE, NULL);
+ g_object_set (G_OBJECT (udpsrc_out[1]), "loop", FALSE, NULL);
+
ret = gst_element_set_state (udpsrc_out[0], GST_STATE_READY);
if (ret == GST_STATE_CHANGE_FAILURE)
goto error;
goto error;
return TRUE;
- return TRUE;
/* ERRORS */
error:
{
- if (udpsrc_out[0])
- gst_object_unref (udpsrc_out[0]);
- if (udpsrc_out[1])
- gst_object_unref (udpsrc_out[1]);
+ if (udpsrc_out[0]) {
+ gst_element_set_state (udpsrc_out[0], GST_STATE_NULL);
+ g_clear_object (&udpsrc_out[0]);
+ }
+ if (udpsrc_out[1]) {
+ gst_element_set_state (udpsrc_out[1], GST_STATE_NULL);
+ g_clear_object (&udpsrc_out[1]);
+ }
return FALSE;
}
}
static gboolean
alloc_ports_one_family (GstRTSPStream * stream, GSocketFamily family,
- GstElement * udpsrc_out[2], GstRTSPRange * server_port_out,
- GstRTSPTransport * ct, GstRTSPAddress ** server_addr_out,
- gboolean use_client_settings)
+ GstElement * udpsrc_out[2], GstElement * udpsink_out[2],
+ GstRTSPAddress ** server_addr_out, gboolean multicast)
{
GstRTSPStreamPrivate *priv = stream->priv;
GSocket *rtp_socket = NULL;
GSocketAddress *rtp_sockaddr = NULL;
GSocketAddress *rtcp_sockaddr = NULL;
GstRTSPAddressPool *pool;
- GstRTSPLowerTrans transport;
- const gchar *multicast_iface = priv->multicast_iface;
+
+ g_assert (!udpsrc_out[0]);
+ g_assert (!udpsrc_out[1]);
+ g_assert ((!udpsink_out[0] && !udpsink_out[1]) ||
+ (udpsink_out[0] && udpsink_out[1]));
+ g_assert (*server_addr_out == NULL);
pool = priv->pool;
count = 0;
- transport = ct->lower_transport;
/* Start with random port */
tmp_rtp = 0;
goto no_udp_protocol;
g_socket_set_multicast_loopback (rtcp_socket, FALSE);
- 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 */
again:
g_socket_set_multicast_loopback (rtp_socket, FALSE);
}
- if (pool && ((transport == GST_RTSP_LOWER_TRANS_UDP &&
- gst_rtsp_address_pool_has_unicast_addresses (pool))
- || transport == GST_RTSP_LOWER_TRANS_UDP_MCAST)) {
- GstRTSPAddressFlags flags = GST_RTSP_ADDRESS_FLAG_EVEN_PORT;
-
- if (transport == GST_RTSP_LOWER_TRANS_UDP)
- flags |= GST_RTSP_ADDRESS_FLAG_UNICAST;
- else
- flags |= GST_RTSP_ADDRESS_FLAG_MULTICAST;
+ if ((pool && gst_rtsp_address_pool_has_unicast_addresses (pool)) || multicast) {
+ GstRTSPAddressFlags flags;
if (addr)
rejected_addresses = g_list_prepend (rejected_addresses, addr);
+ if (!pool)
+ goto no_ports;
+
+ flags = GST_RTSP_ADDRESS_FLAG_EVEN_PORT;
+ if (multicast)
+ flags |= GST_RTSP_ADDRESS_FLAG_MULTICAST;
+ else
+ flags |= GST_RTSP_ADDRESS_FLAG_UNICAST;
+
if (family == G_SOCKET_FAMILY_IPV6)
flags |= GST_RTSP_ADDRESS_FLAG_IPV6;
else
flags |= GST_RTSP_ADDRESS_FLAG_IPV4;
- if (ct->destination && transport == GST_RTSP_LOWER_TRANS_UDP_MCAST
- && use_client_settings)
- gst_rtsp_address_pool_reserve_address (pool, ct->destination,
- ct->port.min, 2, ct->ttl, &addr);
- else
- addr = gst_rtsp_address_pool_acquire_address (pool, flags, 2);
+ addr = gst_rtsp_address_pool_acquire_address (pool, flags, 2);
if (addr == NULL)
goto no_ports;
tmp_rtp = addr->port;
g_clear_object (&inetaddr);
- inetaddr = g_inet_address_new_from_string (addr->address);
-
- /* If we're supposed to bind to a multicast address, instead bind
- * to ANY and let udpsrc later join the relevant multicast group
- */
- if (g_inet_address_get_is_multicast (inetaddr)) {
- g_object_unref (inetaddr);
+ if (multicast)
inetaddr = g_inet_address_new_any (family);
- }
+ else
+ inetaddr = g_inet_address_new_from_string (addr->address);
} else {
if (tmp_rtp != 0) {
tmp_rtp += 2;
}
g_object_unref (rtcp_sockaddr);
- if (addr == NULL)
- addr_str = g_inet_address_to_string (inetaddr);
- else
- addr_str = addr->address;
+ if (!addr) {
+ addr = g_slice_new0 (GstRTSPAddress);
+ addr->address = g_inet_address_to_string (inetaddr);
+ addr->port = tmp_rtp;
+ addr->n_ports = 2;
+ }
+
+ addr_str = addr->address;
g_clear_object (&inetaddr);
- if (!create_and_configure_udpsources_one_family (udpsrc_out, rtp_socket,
- rtcp_socket, family, addr_str, tmp_rtp, tmp_rtcp, multicast_iface,
- transport)) {
- if (addr == NULL)
- g_free (addr_str);
+ if (!create_and_configure_udpsources (udpsrc_out, rtp_socket, rtcp_socket)) {
goto no_udp_protocol;
}
- if (addr == NULL)
- g_free (addr_str);
-
- play_udpsources_one_family (stream, udpsrc_out, family);
-
g_object_get (G_OBJECT (udpsrc_out[0]), "port", &rtpport, NULL);
g_object_get (G_OBJECT (udpsrc_out[1]), "port", &rtcpport, NULL);
if (rtpport != tmp_rtp || rtcpport != tmp_rtcp)
goto port_error;
- /* set RTP and RTCP sockets */
- set_sockets_for_udpsinks (stream, rtp_socket, rtcp_socket, family);
+ /* This function is called twice (for v4 and v6) but we create only one pair
+ * of udpsinks. */
+ if (!udpsink_out[0]
+ && !create_and_configure_udpsinks (stream, udpsink_out))
+ goto no_udp_protocol;
+
+ if (multicast) {
+ g_object_set (G_OBJECT (udpsink_out[0]), "multicast-iface",
+ priv->multicast_iface, NULL);
+ g_object_set (G_OBJECT (udpsink_out[1]), "multicast-iface",
+ priv->multicast_iface, NULL);
+
+ g_signal_emit_by_name (udpsink_out[0], "add", addr_str, rtpport, NULL);
+ g_signal_emit_by_name (udpsink_out[1], "add", addr_str, rtcpport, NULL);
+ }
- server_port_out->min = rtpport;
- server_port_out->max = rtcpport;
+ set_sockets_for_udpsinks (udpsink_out, rtp_socket, rtcp_socket, family);
*server_addr_out = addr;
+
g_list_free_full (rejected_addresses, (GDestroyNotify) gst_rtsp_address_free);
g_object_unref (rtp_socket);
* Allocates RTP and RTCP ports.
*
* Returns: %TRUE if the RTP and RTCP sockets have been succeccully allocated.
+ * Deprecated: This function shouldn't have been made public
*/
gboolean
gst_rtsp_stream_allocate_udp_sockets (GstRTSPStream * stream,
GSocketFamily family, GstRTSPTransport * ct, gboolean use_client_settings)
{
- GstRTSPStreamPrivate *priv;
- gboolean result = FALSE;
- GstRTSPLowerTrans transport = ct->lower_transport;
-
- g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
- priv = stream->priv;
- g_return_val_if_fail (priv->is_joined, FALSE);
-
- g_mutex_lock (&priv->lock);
-
- if (transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
- if (family == G_SOCKET_FAMILY_IPV4) {
- /* Multicast IPV4 */
- if (priv->have_ipv4_mcast) {
- result = TRUE;
- goto done;
- }
-
- priv->have_ipv4_mcast =
- alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV4,
- priv->udpsrc_mcast_v4, &priv->server_port_v4, ct, &priv->addr_v4,
- use_client_settings);
- result = priv->have_ipv4_mcast;
-
- } else {
- /* Multicast IPV6 */
- if (priv->have_ipv6_mcast) {
- result = TRUE;
- goto done;
- }
-
- priv->have_ipv6_mcast =
- alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV6,
- priv->udpsrc_mcast_v6, &priv->server_port_v6, ct, &priv->addr_v6,
- use_client_settings);
- result = priv->have_ipv6_mcast;
- }
- } else {
- /* We allow multiple unicast transports, so we must maintain a table of the
- * udpsrcs created for them. */
- GstRTSPStreamUDPSrcs *transport_udpsrcs =
- g_slice_new0 (GstRTSPStreamUDPSrcs);
-
- if (family == G_SOCKET_FAMILY_IPV4) {
- /* Unicast IPV4 */
- result =
- alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV4,
- transport_udpsrcs->udpsrc, &priv->server_port_v4, ct,
- &priv->server_addr_v4, use_client_settings);
- } else {
- /* Unicast IPV6 */
- result =
- alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV6,
- transport_udpsrcs->udpsrc, &priv->server_port_v6, ct,
- &priv->server_addr_v6, use_client_settings);
- }
-
- /* If we didn't create any unicast udpsrcs, free the transport_udpsrcs struct.
- * Otherwise, add it to the hash table */
- if (transport_udpsrcs->udpsrc[0] == NULL
- && transport_udpsrcs->udpsrc[1] == NULL)
- g_slice_free (GstRTSPStreamUDPSrcs, transport_udpsrcs);
- else
- g_hash_table_insert (priv->udpsrcs, ct, transport_udpsrcs);
- }
-
-done:
- g_mutex_unlock (&priv->lock);
-
- return result;
+ g_warn_if_reached ();
+ return FALSE;
}
/**
return ret;
}
+/* must be called with lock */
+static gboolean
+alloc_ports (GstRTSPStream * stream)
+{
+ GstRTSPStreamPrivate *priv = stream->priv;
+ gboolean ret = TRUE;
+
+ if (priv->protocols & GST_RTSP_LOWER_TRANS_UDP) {
+ ret = alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV4,
+ priv->udpsrc_v4, priv->udpsink, &priv->server_addr_v4, FALSE);
+
+ ret |= alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV6,
+ priv->udpsrc_v6, priv->udpsink, &priv->server_addr_v6, FALSE);
+ }
+
+ /* FIXME: Maybe actually consider the return values? */
+ if (priv->protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST) {
+ ret |= alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV4,
+ priv->mcast_udpsrc_v4, priv->mcast_udpsink, &priv->mcast_addr_v4, TRUE);
+
+ ret |= alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV6,
+ priv->mcast_udpsrc_v6, priv->mcast_udpsink, &priv->mcast_addr_v6, TRUE);
+ }
+
+ return ret;
+}
+
/**
* gst_rtsp_stream_get_server_port:
* @stream: a #GstRTSPStream
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
priv = stream->priv;
- g_return_if_fail (priv->is_joined);
+ g_return_if_fail (priv->joined_bin != NULL);
g_mutex_lock (&priv->lock);
if (family == G_SOCKET_FAMILY_IPV4) {
- if (server_port)
- *server_port = priv->server_port_v4;
+ if (server_port) {
+ server_port->min = priv->server_addr_v4->port;
+ server_port->max =
+ priv->server_addr_v4->port + priv->server_addr_v4->n_ports - 1;
+ }
} else {
- if (server_port)
- *server_port = priv->server_port_v6;
+ if (server_port) {
+ server_port->min = priv->server_addr_v6->port;
+ server_port->max =
+ priv->server_addr_v6->port + priv->server_addr_v6->n_ports - 1;
+ }
}
g_mutex_unlock (&priv->lock);
}
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
priv = stream->priv;
- g_return_if_fail (priv->is_joined);
+ g_return_if_fail (priv->joined_bin != NULL);
g_mutex_lock (&priv->lock);
if (ssrc && priv->session)
gst_pad_send_event (stream->priv->sinkpad, gst_event_new_eos ());
}
+static void
+plug_sink (GstBin * bin, GstElement * tee, GstElement * sink,
+ GstElement ** queue_out)
+{
+ GstPad *pad;
+ GstPad *teepad;
+ GstPad *queuepad;
+
+ gst_bin_add (bin, sink);
+
+ *queue_out = gst_element_factory_make ("queue", NULL);
+ g_object_set (*queue_out, "max-size-buffers", 1, "max-size-bytes", 0,
+ "max-size-time", G_GINT64_CONSTANT (0), NULL);
+ gst_bin_add (bin, *queue_out);
+
+ /* link tee to queue */
+ teepad = gst_element_get_request_pad (tee, "src_%u");
+ pad = gst_element_get_static_pad (*queue_out, "sink");
+ gst_pad_link (teepad, pad);
+ gst_object_unref (pad);
+ gst_object_unref (teepad);
+
+ /* link queue to sink */
+ queuepad = gst_element_get_static_pad (*queue_out, "src");
+ pad = gst_element_get_static_pad (sink, "sink");
+ gst_pad_link (queuepad, pad);
+ gst_object_unref (queuepad);
+ gst_object_unref (pad);
+}
+
/* must be called with lock */
-static gboolean
+static void
create_sender_part (GstRTSPStream * stream, GstBin * bin, GstState state)
{
GstRTSPStreamPrivate *priv;
- GstPad *pad, *sinkpad = NULL;
- gboolean is_tcp = FALSE, is_udp = FALSE;
+ GstPad *pad;
+ gboolean is_tcp, is_udp;
gint i;
priv = stream->priv;
is_udp = ((priv->protocols & GST_RTSP_LOWER_TRANS_UDP) ||
(priv->protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST));
- if (is_udp && !create_and_configure_udpsinks (stream))
- goto no_udp_protocol;
-
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 and udpsink to make
* and link the udpsink (for UDP) or appsink (for TCP) directly to
* the session.
*/
+
/* Only link the RTP send src if we're going to send RTP, link
* the RTCP send src always */
- if (priv->srcpad || i == 1) {
- if (is_udp) {
- /* add udpsink */
- gst_bin_add (bin, priv->udpsink[i]);
- sinkpad = gst_element_get_static_pad (priv->udpsink[i], "sink");
- }
+ if (!priv->srcpad && i == 0)
+ continue;
+
+ if (is_tcp) {
+ /* make appsink */
+ priv->appsink[i] = gst_element_factory_make ("appsink", NULL);
+ g_object_set (priv->appsink[i], "emit-signals", FALSE, NULL);
+ gst_app_sink_set_callbacks (GST_APP_SINK_CAST (priv->appsink[i]),
+ &sink_cb, stream, NULL);
+ }
+
+ /* If we have udp always use a tee because we could have mcast clients
+ * requesting different ports, in which case we'll have to plug more
+ * udpsinks. */
+ if (is_udp) {
+ /* 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);
+
+ if (priv->udpsink[i])
+ plug_sink (bin, priv->tee[i], priv->udpsink[i], &priv->udpqueue[i]);
+
+ if (priv->mcast_udpsink[i])
+ plug_sink (bin, priv->tee[i], priv->mcast_udpsink[i],
+ &priv->mcast_udpqueue[i]);
if (is_tcp) {
- /* make appsink */
- priv->appsink[i] = gst_element_factory_make ("appsink", 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);
+ g_object_set (priv->appsink[i], "async", FALSE, "sync", FALSE, NULL);
+ plug_sink (bin, priv->tee[i], priv->appsink[i], &priv->appqueue[i]);
}
+ } else if (is_tcp) {
+ /* only appsink needed, link it to the session */
+ pad = gst_element_get_static_pad (priv->appsink[i], "sink");
+ gst_pad_link (priv->send_src[i], pad);
+ gst_object_unref (pad);
- if (is_udp && is_tcp) {
+ /* when its only TCP, we need to set sync and preroll to FALSE
+ * for the sink to avoid deadlock. And this is only needed for
+ * sink used for RTCP data, not the RTP data. */
+ if (i == 1)
g_object_set (priv->appsink[i], "async", FALSE, "sync", FALSE, NULL);
-
- /* 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);
-
- priv->udpqueue[i] = gst_element_factory_make ("queue", NULL);
- g_object_set (priv->udpqueue[i], "max-size-buffers",
- 1, "max-size-bytes", 0, "max-size-time", G_GINT64_CONSTANT (0),
- NULL);
- gst_bin_add (bin, priv->udpqueue[i]);
- /* link tee to udpqueue */
- teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
- pad = gst_element_get_static_pad (priv->udpqueue[i], "sink");
- gst_pad_link (teepad, pad);
- gst_object_unref (pad);
- gst_object_unref (teepad);
-
- /* link udpqueue to udpsink */
- queuepad = gst_element_get_static_pad (priv->udpqueue[i], "src");
- gst_pad_link (queuepad, sinkpad);
- gst_object_unref (queuepad);
- gst_object_unref (sinkpad);
-
- /* make appqueue */
- priv->appqueue[i] = gst_element_factory_make ("queue", NULL);
- g_object_set (priv->appqueue[i], "max-size-buffers",
- 1, "max-size-bytes", 0, "max-size-time", G_GINT64_CONSTANT (0),
- NULL);
- gst_bin_add (bin, priv->appqueue[i]);
- /* and link tee to appqueue */
- 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);
-
- /* and link appqueue to appsink */
- 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 if (is_tcp) {
- /* only appsink needed, link it to the session */
- pad = gst_element_get_static_pad (priv->appsink[i], "sink");
- gst_pad_link (priv->send_src[i], pad);
- gst_object_unref (pad);
-
- /* when its only TCP, we need to set sync and preroll to FALSE
- * for the sink to avoid deadlock. And this is only needed for
- * sink used for RTCP data, not the RTP data. */
- if (i == 1)
- g_object_set (priv->appsink[i], "async", FALSE, "sync", FALSE, NULL);
- } else {
- /* else only udpsink needed, link it to the session */
- gst_pad_link (priv->send_src[i], sinkpad);
- gst_object_unref (sinkpad);
- }
}
/* check if we need to set to a special state */
if (state != GST_STATE_NULL) {
- if (priv->udpsink[i] && (priv->srcpad || i == 1))
+ if (priv->udpsink[i])
gst_element_set_state (priv->udpsink[i], state);
- if (priv->appsink[i] && (priv->srcpad || i == 1))
+ if (priv->mcast_udpsink[i])
+ gst_element_set_state (priv->mcast_udpsink[i], state);
+ if (priv->appsink[i])
gst_element_set_state (priv->appsink[i], state);
- if (priv->appqueue[i] && (priv->srcpad || i == 1))
+ if (priv->appqueue[i])
gst_element_set_state (priv->appqueue[i], state);
- if (priv->udpqueue[i] && (priv->srcpad || i == 1))
+ if (priv->udpqueue[i])
gst_element_set_state (priv->udpqueue[i], state);
- if (priv->tee[i] && (priv->srcpad || i == 1))
+ if (priv->mcast_udpqueue[i])
+ gst_element_set_state (priv->mcast_udpqueue[i], state);
+ if (priv->tee[i])
gst_element_set_state (priv->tee[i], state);
}
}
+}
- return TRUE;
+/* must be called with lock */
+static void
+plug_src (GstRTSPStream * stream, GstBin * bin, GstElement * src,
+ GstElement * funnel)
+{
+ GstRTSPStreamPrivate *priv;
+ GstPad *pad, *selpad;
- /* ERRORS */
-no_udp_protocol:
- {
- return FALSE;
+ priv = stream->priv;
+
+ if (priv->srcpad) {
+ /* we set and keep these to playing so that they don't cause NO_PREROLL return
+ * values. This is only relevant for PLAY pipelines */
+ gst_element_set_state (src, GST_STATE_PLAYING);
+ gst_element_set_locked_state (src, TRUE);
}
+
+ /* add src */
+ gst_bin_add (bin, src);
+
+ /* and link to the funnel */
+ selpad = gst_element_get_request_pad (funnel, "sink_%u");
+ pad = gst_element_get_static_pad (src, "src");
+ gst_pad_link (pad, selpad);
+ gst_object_unref (pad);
+ gst_object_unref (selpad);
}
/* must be called with lock */
create_receiver_part (GstRTSPStream * stream, GstBin * bin, GstState state)
{
GstRTSPStreamPrivate *priv;
- GstPad *pad, *selpad;
+ GstPad *pad;
gboolean is_tcp;
gint i;
is_tcp = priv->protocols & GST_RTSP_LOWER_TRANS_TCP;
for (i = 0; i < 2; i++) {
- /* Only connect recv RTP sink if we expect to receive RTP. Connect recv
- * RTCP sink always */
- if (priv->sinkpad || i == 1) {
- /* 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 */
- priv->funnel[i] = gst_element_factory_make ("funnel", NULL);
- gst_bin_add (bin, priv->funnel[i]);
-
- pad = gst_element_get_static_pad (priv->funnel[i], "src");
- gst_pad_link (pad, priv->recv_sink[i]);
- gst_object_unref (pad);
+ /* 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 |
+ * '--------' '--------'
+ */
- if (is_tcp) {
- /* make and add appsrc */
- priv->appsrc[i] = gst_element_factory_make ("appsrc", NULL);
- priv->appsrc_base_time[i] = -1;
- if (priv->srcpad) {
- gst_element_set_state (priv->appsrc[i], GST_STATE_PLAYING);
- gst_element_set_locked_state (priv->appsrc[i], TRUE);
- }
- g_object_set (priv->appsrc[i], "format", GST_FORMAT_TIME, "is-live",
- TRUE, 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->sinkpad && i == 0) {
+ /* Only connect recv RTP sink if we expect to receive RTP. Connect recv
+ * RTCP sink always */
+ continue;
+ }
+
+ /* make funnel for the RTP/RTCP receivers */
+ priv->funnel[i] = gst_element_factory_make ("funnel", NULL);
+ gst_bin_add (bin, priv->funnel[i]);
+
+ pad = gst_element_get_static_pad (priv->funnel[i], "src");
+ gst_pad_link (pad, priv->recv_sink[i]);
+ gst_object_unref (pad);
+
+ if (priv->udpsrc_v4[i])
+ plug_src (stream, bin, priv->udpsrc_v4[i], priv->funnel[i]);
+
+ if (priv->udpsrc_v6[i])
+ plug_src (stream, bin, priv->udpsrc_v6[i], priv->funnel[i]);
+
+ if (priv->mcast_udpsrc_v4[i])
+ plug_src (stream, bin, priv->mcast_udpsrc_v4[i], priv->funnel[i]);
+
+ if (priv->mcast_udpsrc_v6[i])
+ plug_src (stream, bin, priv->mcast_udpsrc_v6[i], priv->funnel[i]);
+
+ if (is_tcp) {
+ /* make and add appsrc */
+ priv->appsrc[i] = gst_element_factory_make ("appsrc", NULL);
+ priv->appsrc_base_time[i] = -1;
+ g_object_set (priv->appsrc[i], "format", GST_FORMAT_TIME, "is-live",
+ TRUE, NULL);
+ plug_src (stream, bin, priv->appsrc[i], priv->funnel[i]);
}
/* check if we need to set to a special state */
if (state != GST_STATE_NULL) {
- if (priv->funnel[i] && (priv->sinkpad || i == 1))
- gst_element_set_state (priv->funnel[i], state);
+ gst_element_set_state (priv->funnel[i], state);
}
}
}
+static gboolean
+check_mcast_part_for_transport (GstRTSPStream * stream,
+ const GstRTSPTransport * tr)
+{
+ GstRTSPStreamPrivate *priv = stream->priv;
+ GInetAddress *inetaddr;
+ GSocketFamily family;
+ GstRTSPAddress *mcast_addr;
+
+ /* Check if it's a ipv4 or ipv6 transport */
+ inetaddr = g_inet_address_new_from_string (tr->destination);
+ family = g_inet_address_get_family (inetaddr);
+ g_object_unref (inetaddr);
+
+ /* Select fields corresponding to the family */
+ if (family == G_SOCKET_FAMILY_IPV4) {
+ mcast_addr = priv->mcast_addr_v4;
+ } else {
+ mcast_addr = priv->mcast_addr_v6;
+ }
+
+ /* We support only one mcast group per family, make sure this transport
+ * matches it. */
+ if (!mcast_addr)
+ goto no_addr;
+
+ if (!g_str_equal (tr->destination, mcast_addr->address) ||
+ tr->port.min != mcast_addr->port ||
+ tr->port.max != mcast_addr->port + mcast_addr->n_ports - 1 ||
+ tr->ttl != mcast_addr->ttl)
+ goto wrong_addr;
+
+ return TRUE;
+
+no_addr:
+ {
+ GST_WARNING_OBJECT (stream, "Adding mcast transport, but no mcast address "
+ "has been reserved");
+ return FALSE;
+ }
+wrong_addr:
+ {
+ GST_WARNING_OBJECT (stream, "Adding mcast transport, but it doesn't match "
+ "the reserved address");
+ return FALSE;
+ }
+}
+
/**
* gst_rtsp_stream_join_bin:
* @stream: a #GstRTSPStream
priv = stream->priv;
g_mutex_lock (&priv->lock);
- if (priv->is_joined)
+ if (priv->joined_bin != NULL)
goto was_joined;
/* create a session with the same index as the stream */
GST_INFO ("stream %p joining bin as session %u", stream, idx);
+ if (!alloc_ports (stream))
+ goto no_ports;
+
if (priv->profiles & GST_RTSP_PROFILE_SAVP
|| priv->profiles & GST_RTSP_PROFILE_SAVPF) {
/* For SRTP */
g_signal_connect (priv->session, "on-sender-ssrc-active",
(GCallback) on_sender_ssrc_active, stream);
- if (!create_sender_part (stream, bin, state))
- goto no_udp_protocol;
-
+ create_sender_part (stream, bin, state);
create_receiver_part (stream, bin, state);
if (priv->srcpad) {
(GCallback) caps_notify, stream);
}
- priv->joined_bin = bin;
- priv->is_joined = TRUE;
+ priv->joined_bin = gst_object_ref (bin);
g_mutex_unlock (&priv->lock);
return TRUE;
g_mutex_unlock (&priv->lock);
return TRUE;
}
-link_failed:
+no_ports:
{
- 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);
+ GST_WARNING ("failed to allocate ports %u", idx);
return FALSE;
}
-no_udp_protocol:
+link_failed:
{
- GST_WARNING ("failed to allocate ports %u", idx);
+ GST_WARNING ("failed to link stream %u", idx);
gst_object_unref (priv->send_rtp_sink);
priv->send_rtp_sink = NULL;
- gst_object_unref (priv->send_src[0]);
- priv->send_src[0] = NULL;
- gst_object_unref (priv->send_src[1]);
- priv->send_src[1] = NULL;
- gst_object_unref (priv->recv_sink[0]);
- priv->recv_sink[0] = NULL;
- gst_object_unref (priv->recv_sink[1]);
- priv->recv_sink[1] = NULL;
- if (priv->udpsink[0])
- gst_element_set_state (priv->udpsink[0], GST_STATE_NULL);
- if (priv->udpsink[1])
- gst_element_set_state (priv->udpsink[1], GST_STATE_NULL);
-
g_mutex_unlock (&priv->lock);
return FALSE;
}
}
-/* Must be called with priv->lock. */
static void
-remove_all_unicast_udpsrcs (GstRTSPStream * stream, GstBin * bin)
+clear_element (GstBin * bin, GstElement ** elementptr)
{
- GstRTSPStreamPrivate *priv;
- GHashTableIter iter;
- gpointer iter_key, iter_value;
-
- priv = stream->priv;
-
- /* Remove all of the unicast udpsrcs */
- g_hash_table_iter_init (&iter, priv->udpsrcs);
- while (g_hash_table_iter_next (&iter, &iter_key, &iter_value)) {
- GstRTSPStreamUDPSrcs *transport_udpsrcs =
- (GstRTSPStreamUDPSrcs *) iter_value;
-
- for (int i = 0; i < 2; i++) {
- if (transport_udpsrcs->udpsrc[i]) {
- if (priv->sinkpad || i == 1) {
- /* Set udpsrc to NULL now before removing */
- gst_element_set_locked_state (transport_udpsrcs->udpsrc[i], FALSE);
- gst_element_set_state (transport_udpsrcs->udpsrc[i], GST_STATE_NULL);
-
- /* removing them should also nicely release the request
- * pads when they finalize */
- gst_bin_remove (bin, transport_udpsrcs->udpsrc[i]);
- } else {
- /* we need to set the state to NULL before unref */
- gst_element_set_state (transport_udpsrcs->udpsrc[i], GST_STATE_NULL);
- gst_object_unref (transport_udpsrcs->udpsrc[i]);
- }
- }
- }
+ if (*elementptr) {
+ gst_element_set_locked_state (*elementptr, FALSE);
+ gst_element_set_state (*elementptr, GST_STATE_NULL);
+ if (GST_ELEMENT_PARENT (*elementptr))
+ gst_bin_remove (bin, *elementptr);
+ else
+ gst_object_unref (*elementptr);
+ *elementptr = NULL;
}
-
- g_hash_table_remove_all (priv->udpsrcs);
}
/**
{
GstRTSPStreamPrivate *priv;
gint i;
- gboolean is_tcp, is_udp;
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
priv = stream->priv;
g_mutex_lock (&priv->lock);
- if (!priv->is_joined)
+ if (priv->joined_bin == NULL)
goto was_not_joined;
+ if (priv->joined_bin != bin)
+ goto wrong_bin;
priv->joined_bin = NULL;
priv->recv_rtp_src = NULL;
}
- is_tcp = priv->protocols & GST_RTSP_LOWER_TRANS_TCP;
-
- is_udp = ((priv->protocols & GST_RTSP_LOWER_TRANS_UDP) ||
- (priv->protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST));
-
- remove_all_unicast_udpsrcs (stream, bin);
-
for (i = 0; i < 2; 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->udpqueue[i])
- gst_element_set_state (priv->udpqueue[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_mcast_v4[i]) {
- if (priv->sinkpad || i == 1) {
- /* and set udpsrc to NULL now before removing */
- gst_element_set_locked_state (priv->udpsrc_mcast_v4[i], FALSE);
- gst_element_set_state (priv->udpsrc_mcast_v4[i], GST_STATE_NULL);
- /* removing them should also nicely release the request
- * pads when they finalize */
- gst_bin_remove (bin, priv->udpsrc_mcast_v4[i]);
- } else {
- gst_element_set_state (priv->udpsrc_mcast_v4[i], GST_STATE_NULL);
- gst_object_unref (priv->udpsrc_mcast_v4[i]);
- }
- }
+ clear_element (bin, &priv->udpsrc_v4[i]);
+ clear_element (bin, &priv->udpsrc_v6[i]);
+ clear_element (bin, &priv->udpqueue[i]);
+ clear_element (bin, &priv->udpsink[i]);
- if (priv->udpsrc_mcast_v6[i]) {
- if (priv->sinkpad || i == 1) {
- gst_element_set_locked_state (priv->udpsrc_mcast_v6[i], FALSE);
- gst_element_set_state (priv->udpsrc_mcast_v6[i], GST_STATE_NULL);
- gst_bin_remove (bin, priv->udpsrc_mcast_v6[i]);
- } else {
- gst_element_set_state (priv->udpsrc_mcast_v6[i], GST_STATE_NULL);
- gst_object_unref (priv->udpsrc_mcast_v6[i]);
- }
- }
+ clear_element (bin, &priv->mcast_udpsrc_v4[i]);
+ clear_element (bin, &priv->mcast_udpsrc_v6[i]);
+ clear_element (bin, &priv->mcast_udpqueue[i]);
+ clear_element (bin, &priv->mcast_udpsink[i]);
- if (priv->udpsink[i] && is_udp && (priv->srcpad || i == 1))
- gst_bin_remove (bin, priv->udpsink[i]);
- if (priv->appsrc[i]) {
- if (priv->sinkpad || i == 1) {
- gst_element_set_locked_state (priv->appsrc[i], FALSE);
- gst_element_set_state (priv->appsrc[i], GST_STATE_NULL);
- gst_bin_remove (bin, priv->appsrc[i]);
- } else {
- gst_element_set_state (priv->appsrc[i], GST_STATE_NULL);
- gst_object_unref (priv->appsrc[i]);
- }
- }
- if (priv->appsink[i] && is_tcp && (priv->srcpad || i == 1))
- gst_bin_remove (bin, priv->appsink[i]);
- if (priv->appqueue[i] && is_tcp && is_udp && (priv->srcpad || i == 1))
- gst_bin_remove (bin, priv->appqueue[i]);
- if (priv->udpqueue[i] && is_tcp && is_udp && (priv->srcpad || i == 1))
- gst_bin_remove (bin, priv->udpqueue[i]);
- if (priv->tee[i] && is_tcp && is_udp && (priv->srcpad || i == 1))
- gst_bin_remove (bin, priv->tee[i]);
- if (priv->funnel[i] && (priv->sinkpad || i == 1))
- gst_bin_remove (bin, priv->funnel[i]);
+ clear_element (bin, &priv->appsrc[i]);
+ clear_element (bin, &priv->appqueue[i]);
+ clear_element (bin, &priv->appsink[i]);
+
+ clear_element (bin, &priv->tee[i]);
+ clear_element (bin, &priv->funnel[i]);
if (priv->sinkpad || i == 1) {
gst_element_release_request_pad (rtpbin, priv->recv_sink[i]);
gst_object_unref (priv->recv_sink[i]);
priv->recv_sink[i] = NULL;
}
-
- priv->udpsrc_mcast_v4[i] = NULL;
- priv->udpsrc_mcast_v6[i] = NULL;
- priv->udpsink[i] = NULL;
- priv->appsrc[i] = NULL;
- priv->appsink[i] = NULL;
- priv->appqueue[i] = NULL;
- priv->udpqueue[i] = NULL;
- priv->tee[i] = NULL;
- priv->funnel[i] = NULL;
}
if (priv->srcpad) {
if (priv->srtpdec)
gst_object_unref (priv->srtpdec);
- priv->is_joined = FALSE;
+ if (priv->mcast_addr_v4)
+ gst_rtsp_address_free (priv->mcast_addr_v4);
+ priv->mcast_addr_v4 = NULL;
+ if (priv->mcast_addr_v6)
+ gst_rtsp_address_free (priv->mcast_addr_v6);
+ priv->mcast_addr_v6 = NULL;
+ if (priv->server_addr_v4)
+ gst_rtsp_address_free (priv->server_addr_v4);
+ priv->server_addr_v4 = NULL;
+ if (priv->server_addr_v6)
+ gst_rtsp_address_free (priv->server_addr_v6);
+ priv->server_addr_v6 = NULL;
+
+ g_clear_object (&priv->joined_bin);
g_mutex_unlock (&priv->lock);
return TRUE;
g_mutex_unlock (&priv->lock);
return FALSE;
}
+wrong_bin:
+ {
+ GST_ERROR_OBJECT (stream, "leaving the wrong bin");
+ g_mutex_unlock (&priv->lock);
+ return FALSE;
+ }
}
/**
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_FLOW_ERROR);
priv = stream->priv;
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
- g_return_val_if_fail (priv->is_joined, FALSE);
+ g_return_val_if_fail (priv->joined_bin != NULL, FALSE);
g_mutex_lock (&priv->lock);
if (priv->appsrc[0])
priv = stream->priv;
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
- if (!priv->is_joined) {
+ if (priv->joined_bin == NULL) {
gst_buffer_unref (buffer);
return GST_FLOW_NOT_LINKED;
}
return ret;
}
-/* Properly dispose udpsrcs that were created for a given transport. */
-/* Must be called with priv->lock. */
-static void
-remove_transport_udpsrcs (GstRTSPStreamPrivate * priv,
- const GstRTSPTransport * tr)
-{
- /* Remove the udpsrcs associated with this transport. */
- GstRTSPStreamUDPSrcs *transport_udpsrcs =
- g_hash_table_lookup (priv->udpsrcs, tr);
- if (transport_udpsrcs != NULL) {
- for (int i = 0; i < 2; i++) {
- if (transport_udpsrcs->udpsrc[i]) {
- if (priv->sinkpad || i == 1) {
- GstBin *bin;
- GstPad *udpsrc_srcpad, *funnel_sinkpad;
-
- /* We know these udpsrcs are all linked to funnels. Explicitely
- * get the funnel src pads so we can properly release them. */
- udpsrc_srcpad =
- gst_element_get_static_pad (transport_udpsrcs->udpsrc[i], "src");
- funnel_sinkpad = gst_pad_get_peer (udpsrc_srcpad);
-
- if (funnel_sinkpad != NULL) {
- /* Unlink pads and release funnel's request pad. */
- gst_pad_unlink (udpsrc_srcpad, funnel_sinkpad);
- gst_element_release_request_pad (priv->funnel[i], funnel_sinkpad);
- gst_object_unref (funnel_sinkpad);
- }
- gst_object_unref (udpsrc_srcpad);
-
- /* Set udpsrc to NULL now before removing */
- gst_element_set_locked_state (transport_udpsrcs->udpsrc[i], FALSE);
- gst_element_set_state (transport_udpsrcs->udpsrc[i], GST_STATE_NULL);
-
- /* This udpsrc is expected to be owned by a bin. Get the bin and
- * remove our element. */
- bin = GST_BIN (gst_element_get_parent (transport_udpsrcs->udpsrc[i]));
- if (bin != NULL) {
- gst_bin_remove (bin, transport_udpsrcs->udpsrc[i]);
- gst_object_unref (bin);
- } else {
- GST_ERROR ("Expected this udpsrc element to be part of a bin.");
- gst_object_unref (transport_udpsrcs->udpsrc[i]);
- }
-
- } else {
- /* we need to set the state to NULL before unref */
- gst_element_set_state (transport_udpsrcs->udpsrc[i], GST_STATE_NULL);
- gst_object_unref (transport_udpsrcs->udpsrc[i]);
- }
- }
- }
-
- /* The udpsrcs are now properly cleaned up. Remove them from the table */
- g_hash_table_remove (priv->udpsrcs, tr);
-
- } else {
- /* This can happen if we're dealing with a multicast transport. */
- GST_INFO ("Could not find udpsrcs associated with this transport.");
- }
-}
-
/* must be called with lock */
static gboolean
update_transport (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
switch (tr->lower_transport) {
case GST_RTSP_LOWER_TRANS_UDP_MCAST:
+ {
+ if (add) {
+ if (!check_mcast_part_for_transport (stream, tr))
+ goto mcast_error;
+ priv->transports = g_list_prepend (priv->transports, trans);
+ } else {
+ priv->transports = g_list_remove (priv->transports, trans);
+ }
+ break;
+ }
case GST_RTSP_LOWER_TRANS_UDP:
{
gchar *dest;
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);
-
- remove_transport_udpsrcs (priv, tr);
}
priv->transports_cookie++;
break;
GST_INFO ("Unknown transport %d", tr->lower_transport);
return FALSE;
}
+mcast_error:
+ {
+ return FALSE;
+ }
}
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
priv = stream->priv;
g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
- g_return_val_if_fail (priv->is_joined, FALSE);
+ g_return_val_if_fail (priv->joined_bin != NULL, FALSE);
g_mutex_lock (&priv->lock);
res = update_transport (stream, trans, TRUE);
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
priv = stream->priv;
g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
- g_return_val_if_fail (priv->is_joined, FALSE);
+ g_return_val_if_fail (priv->joined_bin != NULL, FALSE);
g_mutex_lock (&priv->lock);
res = update_transport (stream, trans, FALSE);