2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
25 #include <gst/app/gstappsrc.h>
26 #include <gst/app/gstappsink.h>
28 #include "rtsp-stream.h"
30 #define GST_RTSP_STREAM_GET_PRIVATE(obj) \
31 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_STREAM, GstRTSPStreamPrivate))
33 struct _GstRTSPStreamPrivate
38 GstElement *payloader;
42 /* pads on the rtpbin */
43 GstPad *send_rtp_sink;
47 /* the RTPSession object */
50 /* sinks used for sending and receiving RTP and RTCP over ipv4, they share
52 GstElement *udpsrc_v4[2];
54 /* sinks used for sending and receiving RTP and RTCP over ipv6, they share
56 GstElement *udpsrc_v6[2];
58 GstElement *udpsink[2];
60 /* for TCP transport */
61 GstElement *appsrc[2];
62 GstElement *appqueue[2];
63 GstElement *appsink[2];
66 GstElement *funnel[2];
68 /* server ports for sending/receiving over ipv4 */
69 GstRTSPRange server_port_v4;
70 GstRTSPAddress *server_addr_v4;
72 /* server ports for sending/receiving over ipv6 */
73 GstRTSPRange server_port_v6;
74 GstRTSPAddress *server_addr_v6;
76 /* multicast addresses */
77 GstRTSPAddressPool *pool;
80 /* the caps of the stream */
84 /* transports we stream to */
98 GST_DEBUG_CATEGORY_STATIC (rtsp_stream_debug);
99 #define GST_CAT_DEFAULT rtsp_stream_debug
101 static GQuark ssrc_stream_map_key;
103 static void gst_rtsp_stream_finalize (GObject * obj);
105 G_DEFINE_TYPE (GstRTSPStream, gst_rtsp_stream, G_TYPE_OBJECT);
108 gst_rtsp_stream_class_init (GstRTSPStreamClass * klass)
110 GObjectClass *gobject_class;
112 g_type_class_add_private (klass, sizeof (GstRTSPStreamPrivate));
114 gobject_class = G_OBJECT_CLASS (klass);
116 gobject_class->finalize = gst_rtsp_stream_finalize;
118 GST_DEBUG_CATEGORY_INIT (rtsp_stream_debug, "rtspstream", 0, "GstRTSPStream");
120 ssrc_stream_map_key = g_quark_from_static_string ("GstRTSPServer.stream");
124 gst_rtsp_stream_init (GstRTSPStream * stream)
126 GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
128 GST_DEBUG ("new stream %p", stream);
132 stream->priv->dscp_qos = -1;
134 g_mutex_init (&priv->lock);
138 gst_rtsp_stream_finalize (GObject * obj)
140 GstRTSPStream *stream;
141 GstRTSPStreamPrivate *priv;
143 stream = GST_RTSP_STREAM (obj);
146 GST_DEBUG ("finalize stream %p", stream);
148 /* we really need to be unjoined now */
149 g_return_if_fail (!priv->is_joined);
152 gst_rtsp_address_free (priv->addr);
153 if (priv->server_addr_v4)
154 gst_rtsp_address_free (priv->server_addr_v4);
155 if (priv->server_addr_v6)
156 gst_rtsp_address_free (priv->server_addr_v6);
158 g_object_unref (priv->pool);
159 gst_object_unref (priv->payloader);
160 gst_object_unref (priv->srcpad);
161 g_mutex_clear (&priv->lock);
163 G_OBJECT_CLASS (gst_rtsp_stream_parent_class)->finalize (obj);
167 * gst_rtsp_stream_new:
170 * @payloader: a #GstElement
172 * Create a new media stream with index @idx that handles RTP data on
173 * @srcpad and has a payloader element @payloader.
175 * Returns: a new #GstRTSPStream
178 gst_rtsp_stream_new (guint idx, GstElement * payloader, GstPad * srcpad)
180 GstRTSPStreamPrivate *priv;
181 GstRTSPStream *stream;
183 g_return_val_if_fail (GST_IS_ELEMENT (payloader), NULL);
184 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
185 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), NULL);
187 stream = g_object_new (GST_TYPE_RTSP_STREAM, NULL);
190 priv->payloader = gst_object_ref (payloader);
191 priv->srcpad = gst_object_ref (srcpad);
197 * gst_rtsp_stream_get_index:
198 * @stream: a #GstRTSPStream
200 * Get the stream index.
202 * Return: the stream index.
205 gst_rtsp_stream_get_index (GstRTSPStream * stream)
207 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
209 return stream->priv->idx;
213 * gst_rtsp_stream_get_srcpad:
214 * @stream: a #GstRTSPStream
216 * Get the srcpad associated with @stream.
218 * Return: the srcpad. Unref after usage.
221 gst_rtsp_stream_get_srcpad (GstRTSPStream * stream)
223 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
225 return gst_object_ref (stream->priv->srcpad);
229 * gst_rtsp_stream_set_mtu:
230 * @stream: a #GstRTSPStream
233 * Configure the mtu in the payloader of @stream to @mtu.
236 gst_rtsp_stream_set_mtu (GstRTSPStream * stream, guint mtu)
238 GstRTSPStreamPrivate *priv;
240 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
244 GST_LOG_OBJECT (stream, "set MTU %u", mtu);
246 g_object_set (G_OBJECT (priv->payloader), "mtu", mtu, NULL);
250 * gst_rtsp_stream_get_mtu:
251 * @stream: a #GstRTSPStream
253 * Get the configured MTU in the payloader of @stream.
255 * Returns: the MTU of the payloader.
258 gst_rtsp_stream_get_mtu (GstRTSPStream * stream)
260 GstRTSPStreamPrivate *priv;
263 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
267 g_object_get (G_OBJECT (priv->payloader), "mtu", &mtu, NULL);
272 /* Update the dscp qos property on the udp sinks */
274 update_dscp_qos (GstRTSPStream * stream)
276 GstRTSPStreamPrivate *priv;
278 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
282 if (priv->udpsink[0]) {
283 g_object_set (G_OBJECT (priv->udpsink[0]), "qos-dscp", priv->dscp_qos,
287 if (priv->udpsink[1]) {
288 g_object_set (G_OBJECT (priv->udpsink[1]), "qos-dscp", priv->dscp_qos,
294 * gst_rtsp_stream_set_dscp_qos:
295 * @stream: a #GstRTSPStream
296 * @dscp_qos: a new dscp qos value (0-63, or -1 to disable)
298 * Configure the dscp qos of the outgoing sockets to @dscp_qos.
301 gst_rtsp_stream_set_dscp_qos (GstRTSPStream * stream, gint dscp_qos)
303 GstRTSPStreamPrivate *priv;
305 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
309 GST_LOG_OBJECT (stream, "set DSCP QoS %d", dscp_qos);
311 if (dscp_qos < -1 || dscp_qos > 63) {
312 GST_WARNING_OBJECT (stream, "trying to set illegal dscp qos %d", dscp_qos);
316 priv->dscp_qos = dscp_qos;
318 update_dscp_qos (stream);
322 * gst_rtsp_stream_get_dscp_qos:
323 * @stream: a #GstRTSPStream
325 * Get the configured DSCP QoS in of the outgoing sockets.
327 * Returns: the DSCP QoS value of the outgoing sockets, or -1 if disbled.
330 gst_rtsp_stream_get_dscp_qos (GstRTSPStream * stream)
332 GstRTSPStreamPrivate *priv;
334 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
338 return priv->dscp_qos;
343 * gst_rtsp_stream_set_address_pool:
344 * @stream: a #GstRTSPStream
345 * @pool: a #GstRTSPAddressPool
347 * configure @pool to be used as the address pool of @stream.
350 gst_rtsp_stream_set_address_pool (GstRTSPStream * stream,
351 GstRTSPAddressPool * pool)
353 GstRTSPStreamPrivate *priv;
354 GstRTSPAddressPool *old;
356 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
360 GST_LOG_OBJECT (stream, "set address pool %p", pool);
362 g_mutex_lock (&priv->lock);
363 if ((old = priv->pool) != pool)
364 priv->pool = pool ? g_object_ref (pool) : NULL;
367 g_mutex_unlock (&priv->lock);
370 g_object_unref (old);
374 * gst_rtsp_stream_get_address_pool:
375 * @stream: a #GstRTSPStream
377 * Get the #GstRTSPAddressPool used as the address pool of @stream.
379 * Returns: (transfer full): the #GstRTSPAddressPool of @stream. g_object_unref() after
383 gst_rtsp_stream_get_address_pool (GstRTSPStream * stream)
385 GstRTSPStreamPrivate *priv;
386 GstRTSPAddressPool *result;
388 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
392 g_mutex_lock (&priv->lock);
393 if ((result = priv->pool))
394 g_object_ref (result);
395 g_mutex_unlock (&priv->lock);
401 * gst_rtsp_stream_get_address:
402 * @stream: a #GstRTSPStream
404 * Get the multicast address of @stream.
406 * Returns: the #GstRTSPAddress of @stream or %NULL when no address could be
407 * allocated. gst_rtsp_address_free() after usage.
410 gst_rtsp_stream_get_address (GstRTSPStream * stream)
412 GstRTSPStreamPrivate *priv;
413 GstRTSPAddress *result;
415 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
419 g_mutex_lock (&priv->lock);
420 if (priv->addr == NULL) {
421 if (priv->pool == NULL)
424 priv->addr = gst_rtsp_address_pool_acquire_address (priv->pool,
425 GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST, 2);
426 if (priv->addr == NULL)
429 result = gst_rtsp_address_copy (priv->addr);
430 g_mutex_unlock (&priv->lock);
437 GST_ERROR_OBJECT (stream, "no address pool specified");
438 g_mutex_unlock (&priv->lock);
443 GST_ERROR_OBJECT (stream, "failed to acquire address from pool");
444 g_mutex_unlock (&priv->lock);
450 * gst_rtsp_stream_reserve_address:
451 * @stream: a #GstRTSPStream
453 * Get a specific multicast address of @stream.
455 * Returns: the #GstRTSPAddress of @stream or %NULL when no address could be
456 * allocated. gst_rtsp_address_free() after usage.
459 gst_rtsp_stream_reserve_address (GstRTSPStream * stream,
460 const gchar * address, guint port, guint n_ports, guint ttl)
462 GstRTSPStreamPrivate *priv;
463 GstRTSPAddress *result;
465 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
466 g_return_val_if_fail (address != NULL, NULL);
467 g_return_val_if_fail (port > 0, NULL);
468 g_return_val_if_fail (n_ports > 0, NULL);
469 g_return_val_if_fail (ttl > 0, NULL);
473 g_mutex_lock (&priv->lock);
474 if (priv->addr == NULL) {
475 if (priv->pool == NULL)
478 priv->addr = gst_rtsp_address_pool_reserve_address (priv->pool, address,
480 if (priv->addr == NULL)
483 if (strcmp (priv->addr->address, address) ||
484 priv->addr->port != port || priv->addr->n_ports != n_ports ||
485 priv->addr->ttl != ttl)
486 goto different_address;
488 result = gst_rtsp_address_copy (priv->addr);
489 g_mutex_unlock (&priv->lock);
496 GST_ERROR_OBJECT (stream, "no address pool specified");
497 g_mutex_unlock (&priv->lock);
502 GST_ERROR_OBJECT (stream, "failed to acquire address %s from pool",
504 g_mutex_unlock (&priv->lock);
509 GST_ERROR_OBJECT (stream, "address %s is not the same that was already"
510 " reserved", address);
511 g_mutex_unlock (&priv->lock);
517 alloc_ports_one_family (GstRTSPAddressPool * pool, gint buffer_size,
518 GSocketFamily family, GstElement * udpsrc_out[2],
519 GstElement * udpsink_out[2], GstRTSPRange * server_port_out,
520 GstRTSPAddress ** server_addr_out)
522 GstStateChangeReturn ret;
523 GstElement *udpsrc0, *udpsrc1;
524 GstElement *udpsink0, *udpsink1;
525 GSocket *rtp_socket = NULL;
526 GSocket *rtcp_socket;
527 gint tmp_rtp, tmp_rtcp;
529 gint rtpport, rtcpport;
530 GList *rejected_addresses = NULL;
531 GstRTSPAddress *addr = NULL;
532 GInetAddress *inetaddr = NULL;
533 GSocketAddress *rtp_sockaddr = NULL;
534 GSocketAddress *rtcp_sockaddr = NULL;
535 const gchar *multisink_socket = "socket";
537 if (family == G_SOCKET_FAMILY_IPV6) {
538 multisink_socket = "socket-v6";
547 /* Start with random port */
550 rtcp_socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
551 G_SOCKET_PROTOCOL_UDP, NULL);
553 goto no_udp_protocol;
555 if (*server_addr_out)
556 gst_rtsp_address_free (*server_addr_out);
558 /* try to allocate 2 UDP ports, the RTP port should be an even
559 * number and the RTCP port should be the next (uneven) port */
562 if (rtp_socket == NULL) {
563 rtp_socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
564 G_SOCKET_PROTOCOL_UDP, NULL);
566 goto no_udp_protocol;
569 if (pool && gst_rtsp_address_pool_has_unicast_addresses (pool)) {
570 GstRTSPAddressFlags flags;
573 rejected_addresses = g_list_prepend (rejected_addresses, addr);
575 flags = GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_UNICAST;
576 if (family == G_SOCKET_FAMILY_IPV6)
577 flags |= GST_RTSP_ADDRESS_FLAG_IPV6;
579 flags |= GST_RTSP_ADDRESS_FLAG_IPV4;
581 addr = gst_rtsp_address_pool_acquire_address (pool, flags, 2);
586 tmp_rtp = addr->port;
588 g_clear_object (&inetaddr);
589 inetaddr = g_inet_address_new_from_string (addr->address);
597 if (inetaddr == NULL)
598 inetaddr = g_inet_address_new_any (family);
601 rtp_sockaddr = g_inet_socket_address_new (inetaddr, tmp_rtp);
602 if (!g_socket_bind (rtp_socket, rtp_sockaddr, FALSE, NULL)) {
603 g_object_unref (rtp_sockaddr);
606 g_object_unref (rtp_sockaddr);
608 rtp_sockaddr = g_socket_get_local_address (rtp_socket, NULL);
609 if (rtp_sockaddr == NULL || !G_IS_INET_SOCKET_ADDRESS (rtp_sockaddr)) {
610 g_clear_object (&rtp_sockaddr);
615 g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (rtp_sockaddr));
616 g_object_unref (rtp_sockaddr);
618 /* check if port is even */
619 if ((tmp_rtp & 1) != 0) {
620 /* port not even, close and allocate another */
622 g_clear_object (&rtp_socket);
627 tmp_rtcp = tmp_rtp + 1;
629 rtcp_sockaddr = g_inet_socket_address_new (inetaddr, tmp_rtcp);
630 if (!g_socket_bind (rtcp_socket, rtcp_sockaddr, FALSE, NULL)) {
631 g_object_unref (rtcp_sockaddr);
632 g_clear_object (&rtp_socket);
635 g_object_unref (rtcp_sockaddr);
637 g_clear_object (&inetaddr);
639 udpsrc0 = gst_element_factory_make ("udpsrc", NULL);
640 udpsrc1 = gst_element_factory_make ("udpsrc", NULL);
642 if (udpsrc0 == NULL || udpsrc1 == NULL)
643 goto no_udp_protocol;
645 g_object_set (G_OBJECT (udpsrc0), "socket", rtp_socket, NULL);
646 g_object_set (G_OBJECT (udpsrc1), "socket", rtcp_socket, NULL);
648 ret = gst_element_set_state (udpsrc0, GST_STATE_PAUSED);
649 if (ret == GST_STATE_CHANGE_FAILURE)
651 ret = gst_element_set_state (udpsrc1, GST_STATE_PAUSED);
652 if (ret == GST_STATE_CHANGE_FAILURE)
655 /* all fine, do port check */
656 g_object_get (G_OBJECT (udpsrc0), "port", &rtpport, NULL);
657 g_object_get (G_OBJECT (udpsrc1), "port", &rtcpport, NULL);
659 /* this should not happen... */
660 if (rtpport != tmp_rtp || rtcpport != tmp_rtcp)
664 udpsink0 = udpsink_out[0];
666 udpsink0 = gst_element_factory_make ("multiudpsink", NULL);
669 goto no_udp_protocol;
671 g_object_set (G_OBJECT (udpsink0), "close-socket", FALSE, NULL);
672 g_object_set (G_OBJECT (udpsink0), multisink_socket, rtp_socket, NULL);
675 udpsink1 = udpsink_out[1];
677 udpsink1 = gst_element_factory_make ("multiudpsink", NULL);
680 goto no_udp_protocol;
682 g_object_set (G_OBJECT (udpsink0), "send-duplicates", FALSE, NULL);
683 g_object_set (G_OBJECT (udpsink1), "send-duplicates", FALSE, NULL);
684 g_object_set (G_OBJECT (udpsink0), "buffer-size", buffer_size, NULL);
686 g_object_set (G_OBJECT (udpsink1), "close-socket", FALSE, NULL);
687 g_object_set (G_OBJECT (udpsink1), multisink_socket, rtcp_socket, NULL);
688 g_object_set (G_OBJECT (udpsink1), "sync", FALSE, NULL);
689 g_object_set (G_OBJECT (udpsink1), "async", FALSE, NULL);
690 g_object_set (G_OBJECT (udpsink0), "auto-multicast", FALSE, NULL);
691 g_object_set (G_OBJECT (udpsink0), "loop", FALSE, NULL);
692 g_object_set (G_OBJECT (udpsink1), "auto-multicast", FALSE, NULL);
693 g_object_set (G_OBJECT (udpsink1), "loop", FALSE, NULL);
695 /* we keep these elements, we will further configure them when the
696 * client told us to really use the UDP ports. */
697 udpsrc_out[0] = udpsrc0;
698 udpsrc_out[1] = udpsrc1;
699 udpsink_out[0] = udpsink0;
700 udpsink_out[1] = udpsink1;
701 server_port_out->min = rtpport;
702 server_port_out->max = rtcpport;
704 *server_addr_out = addr;
705 g_list_free_full (rejected_addresses, (GDestroyNotify) gst_rtsp_address_free);
707 g_object_unref (rtp_socket);
708 g_object_unref (rtcp_socket);
736 gst_element_set_state (udpsrc0, GST_STATE_NULL);
737 gst_object_unref (udpsrc0);
740 gst_element_set_state (udpsrc1, GST_STATE_NULL);
741 gst_object_unref (udpsrc1);
744 gst_element_set_state (udpsink0, GST_STATE_NULL);
745 gst_object_unref (udpsink0);
748 gst_element_set_state (udpsink1, GST_STATE_NULL);
749 gst_object_unref (udpsink1);
752 g_object_unref (inetaddr);
753 g_list_free_full (rejected_addresses,
754 (GDestroyNotify) gst_rtsp_address_free);
756 gst_rtsp_address_free (addr);
758 g_object_unref (rtp_socket);
760 g_object_unref (rtcp_socket);
765 /* must be called with lock */
767 alloc_ports (GstRTSPStream * stream)
769 GstRTSPStreamPrivate *priv = stream->priv;
771 return alloc_ports_one_family (priv->pool, priv->buffer_size,
772 G_SOCKET_FAMILY_IPV4, priv->udpsrc_v4, priv->udpsink,
773 &priv->server_port_v4, &priv->server_addr_v4) &&
774 alloc_ports_one_family (priv->pool, priv->buffer_size,
775 G_SOCKET_FAMILY_IPV6, priv->udpsrc_v6, priv->udpsink,
776 &priv->server_port_v6, &priv->server_addr_v6);
780 * gst_rtsp_stream_get_server_port:
781 * @stream: a #GstRTSPStream
782 * @server_port: (out): result server port
784 * Fill @server_port with the port pair used by the server. This function can
785 * only be called when @stream has been joined.
788 gst_rtsp_stream_get_server_port (GstRTSPStream * stream,
789 GstRTSPRange * server_port, GSocketFamily family)
791 GstRTSPStreamPrivate *priv;
793 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
795 g_return_if_fail (priv->is_joined);
797 g_mutex_lock (&priv->lock);
798 if (family == G_SOCKET_FAMILY_IPV4) {
800 *server_port = priv->server_port_v4;
803 *server_port = priv->server_port_v6;
805 g_mutex_unlock (&priv->lock);
809 * gst_rtsp_stream_get_rtpsession:
810 * @stream: a #GstRTSPStream
812 * Get the RTP session of this stream.
814 * Returns: The RTP session of this stream. Unref after usage.
817 gst_rtsp_stream_get_rtpsession (GstRTSPStream * stream)
819 GstRTSPStreamPrivate *priv;
822 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
826 g_mutex_lock (&priv->lock);
827 if ((session = priv->session))
828 g_object_ref (session);
829 g_mutex_unlock (&priv->lock);
835 * gst_rtsp_stream_get_ssrc:
836 * @stream: a #GstRTSPStream
837 * @ssrc: (out): result ssrc
839 * Get the SSRC used by the RTP session of this stream. This function can only
840 * be called when @stream has been joined.
843 gst_rtsp_stream_get_ssrc (GstRTSPStream * stream, guint * ssrc)
845 GstRTSPStreamPrivate *priv;
847 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
849 g_return_if_fail (priv->is_joined);
851 g_mutex_lock (&priv->lock);
852 if (ssrc && priv->session)
853 g_object_get (priv->session, "internal-ssrc", ssrc, NULL);
854 g_mutex_unlock (&priv->lock);
857 /* executed from streaming thread */
859 caps_notify (GstPad * pad, GParamSpec * unused, GstRTSPStream * stream)
861 GstRTSPStreamPrivate *priv = stream->priv;
862 GstCaps *newcaps, *oldcaps;
864 newcaps = gst_pad_get_current_caps (pad);
866 GST_INFO ("stream %p received caps %p, %" GST_PTR_FORMAT, stream, newcaps,
869 g_mutex_lock (&priv->lock);
870 oldcaps = priv->caps;
871 priv->caps = newcaps;
872 g_mutex_unlock (&priv->lock);
875 gst_caps_unref (oldcaps);
879 dump_structure (const GstStructure * s)
883 sstr = gst_structure_to_string (s);
884 GST_INFO ("structure: %s", sstr);
888 static GstRTSPStreamTransport *
889 find_transport (GstRTSPStream * stream, const gchar * rtcp_from)
891 GstRTSPStreamPrivate *priv = stream->priv;
893 GstRTSPStreamTransport *result = NULL;
898 if (rtcp_from == NULL)
901 tmp = g_strrstr (rtcp_from, ":");
905 port = atoi (tmp + 1);
906 dest = g_strndup (rtcp_from, tmp - rtcp_from);
908 g_mutex_lock (&priv->lock);
909 GST_INFO ("finding %s:%d in %d transports", dest, port,
910 g_list_length (priv->transports));
912 for (walk = priv->transports; walk; walk = g_list_next (walk)) {
913 GstRTSPStreamTransport *trans = walk->data;
914 const GstRTSPTransport *tr;
917 tr = gst_rtsp_stream_transport_get_transport (trans);
919 min = tr->client_port.min;
920 max = tr->client_port.max;
922 if ((strcmp (tr->destination, dest) == 0) && (min == port || max == port)) {
928 g_object_ref (result);
929 g_mutex_unlock (&priv->lock);
936 static GstRTSPStreamTransport *
937 check_transport (GObject * source, GstRTSPStream * stream)
940 GstRTSPStreamTransport *trans;
942 /* see if we have a stream to match with the origin of the RTCP packet */
943 trans = g_object_get_qdata (source, ssrc_stream_map_key);
945 g_object_get (source, "stats", &stats, NULL);
947 const gchar *rtcp_from;
949 dump_structure (stats);
951 rtcp_from = gst_structure_get_string (stats, "rtcp-from");
952 if ((trans = find_transport (stream, rtcp_from))) {
953 GST_INFO ("%p: found transport %p for source %p", stream, trans,
955 g_object_set_qdata_full (source, ssrc_stream_map_key, trans,
958 gst_structure_free (stats);
966 on_new_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
968 GstRTSPStreamTransport *trans;
970 GST_INFO ("%p: new source %p", stream, source);
972 trans = check_transport (source, stream);
975 GST_INFO ("%p: source %p for transport %p", stream, source, trans);
979 on_ssrc_sdes (GObject * session, GObject * source, GstRTSPStream * stream)
981 GST_INFO ("%p: new SDES %p", stream, source);
985 on_ssrc_active (GObject * session, GObject * source, GstRTSPStream * stream)
987 GstRTSPStreamTransport *trans;
989 trans = check_transport (source, stream);
992 GST_INFO ("%p: source %p in transport %p is active", stream, source, trans);
993 gst_rtsp_stream_transport_keep_alive (trans);
998 g_object_get (source, "stats", &stats, NULL);
1000 dump_structure (stats);
1001 gst_structure_free (stats);
1008 on_bye_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
1010 GST_INFO ("%p: source %p bye", stream, source);
1014 on_bye_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
1016 GstRTSPStreamTransport *trans;
1018 GST_INFO ("%p: source %p bye timeout", stream, source);
1020 if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
1021 gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
1022 g_object_set_qdata (source, ssrc_stream_map_key, NULL);
1027 on_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
1029 GstRTSPStreamTransport *trans;
1031 GST_INFO ("%p: source %p timeout", stream, source);
1033 if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
1034 gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
1035 g_object_set_qdata (source, ssrc_stream_map_key, NULL);
1039 static GstFlowReturn
1040 handle_new_sample (GstAppSink * sink, gpointer user_data)
1042 GstRTSPStreamPrivate *priv;
1046 GstRTSPStream *stream;
1048 sample = gst_app_sink_pull_sample (sink);
1052 stream = (GstRTSPStream *) user_data;
1053 priv = stream->priv;
1054 buffer = gst_sample_get_buffer (sample);
1056 g_mutex_lock (&priv->lock);
1057 for (walk = priv->transports; walk; walk = g_list_next (walk)) {
1058 GstRTSPStreamTransport *tr = (GstRTSPStreamTransport *) walk->data;
1060 if (GST_ELEMENT_CAST (sink) == priv->appsink[0]) {
1061 gst_rtsp_stream_transport_send_rtp (tr, buffer);
1063 gst_rtsp_stream_transport_send_rtcp (tr, buffer);
1066 g_mutex_unlock (&priv->lock);
1068 gst_sample_unref (sample);
1073 static GstAppSinkCallbacks sink_cb = {
1074 NULL, /* not interested in EOS */
1075 NULL, /* not interested in preroll samples */
1080 * gst_rtsp_stream_join_bin:
1081 * @stream: a #GstRTSPStream
1082 * @bin: a #GstBin to join
1083 * @rtpbin: a rtpbin element in @bin
1084 * @state: the target state of the new elements
1086 * Join the #Gstbin @bin that contains the element @rtpbin.
1088 * @stream will link to @rtpbin, which must be inside @bin. The elements
1089 * added to @bin will be set to the state given in @state.
1091 * Returns: %TRUE on success.
1094 gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
1095 GstElement * rtpbin, GstState state)
1097 GstRTSPStreamPrivate *priv;
1100 GstPad *pad, *teepad, *queuepad, *selpad;
1101 GstPadLinkReturn ret;
1103 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
1104 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
1105 g_return_val_if_fail (GST_IS_ELEMENT (rtpbin), FALSE);
1107 priv = stream->priv;
1109 g_mutex_lock (&priv->lock);
1110 if (priv->is_joined)
1113 /* create a session with the same index as the stream */
1116 GST_INFO ("stream %p joining bin as session %d", stream, idx);
1118 if (!alloc_ports (stream))
1121 /* update the dscp qos field in the sinks */
1122 update_dscp_qos (stream);
1124 /* get a pad for sending RTP */
1125 name = g_strdup_printf ("send_rtp_sink_%u", idx);
1126 priv->send_rtp_sink = gst_element_get_request_pad (rtpbin, name);
1128 /* link the RTP pad to the session manager, it should not really fail unless
1129 * this is not really an RTP pad */
1130 ret = gst_pad_link (priv->srcpad, priv->send_rtp_sink);
1131 if (ret != GST_PAD_LINK_OK)
1134 /* get pads from the RTP session element for sending and receiving
1136 name = g_strdup_printf ("send_rtp_src_%u", idx);
1137 priv->send_src[0] = gst_element_get_static_pad (rtpbin, name);
1139 name = g_strdup_printf ("send_rtcp_src_%u", idx);
1140 priv->send_src[1] = gst_element_get_request_pad (rtpbin, name);
1142 name = g_strdup_printf ("recv_rtp_sink_%u", idx);
1143 priv->recv_sink[0] = gst_element_get_request_pad (rtpbin, name);
1145 name = g_strdup_printf ("recv_rtcp_sink_%u", idx);
1146 priv->recv_sink[1] = gst_element_get_request_pad (rtpbin, name);
1149 /* get the session */
1150 g_signal_emit_by_name (rtpbin, "get-internal-session", idx, &priv->session);
1152 g_signal_connect (priv->session, "on-new-ssrc", (GCallback) on_new_ssrc,
1154 g_signal_connect (priv->session, "on-ssrc-sdes", (GCallback) on_ssrc_sdes,
1156 g_signal_connect (priv->session, "on-ssrc-active",
1157 (GCallback) on_ssrc_active, stream);
1158 g_signal_connect (priv->session, "on-bye-ssrc", (GCallback) on_bye_ssrc,
1160 g_signal_connect (priv->session, "on-bye-timeout",
1161 (GCallback) on_bye_timeout, stream);
1162 g_signal_connect (priv->session, "on-timeout", (GCallback) on_timeout,
1165 for (i = 0; i < 2; i++) {
1166 /* For the sender we create this bit of pipeline for both
1167 * RTP and RTCP. Sync and preroll are enabled on udpsink so
1168 * we need to add a queue before appsink to make the pipeline
1169 * not block. For the TCP case, we want to pump data to the
1170 * client as fast as possible anyway.
1172 * .--------. .-----. .---------.
1173 * | rtpbin | | tee | | udpsink |
1174 * | send->sink src->sink |
1175 * '--------' | | '---------'
1176 * | | .---------. .---------.
1177 * | | | queue | | appsink |
1178 * | src->sink src->sink |
1179 * '-----' '---------' '---------'
1181 /* make tee for RTP/RTCP */
1182 priv->tee[i] = gst_element_factory_make ("tee", NULL);
1183 gst_bin_add (bin, priv->tee[i]);
1185 /* and link to rtpbin send pad */
1186 pad = gst_element_get_static_pad (priv->tee[i], "sink");
1187 gst_pad_link (priv->send_src[i], pad);
1188 gst_object_unref (pad);
1191 gst_bin_add (bin, priv->udpsink[i]);
1193 /* link tee to udpsink */
1194 teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
1195 pad = gst_element_get_static_pad (priv->udpsink[i], "sink");
1196 gst_pad_link (teepad, pad);
1197 gst_object_unref (pad);
1198 gst_object_unref (teepad);
1201 priv->appqueue[i] = gst_element_factory_make ("queue", NULL);
1202 gst_bin_add (bin, priv->appqueue[i]);
1203 /* and link to tee */
1204 teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
1205 pad = gst_element_get_static_pad (priv->appqueue[i], "sink");
1206 gst_pad_link (teepad, pad);
1207 gst_object_unref (pad);
1208 gst_object_unref (teepad);
1211 priv->appsink[i] = gst_element_factory_make ("appsink", NULL);
1212 g_object_set (priv->appsink[i], "async", FALSE, "sync", FALSE, NULL);
1213 g_object_set (priv->appsink[i], "emit-signals", FALSE, NULL);
1214 gst_bin_add (bin, priv->appsink[i]);
1215 gst_app_sink_set_callbacks (GST_APP_SINK_CAST (priv->appsink[i]),
1216 &sink_cb, stream, NULL);
1217 /* and link to queue */
1218 queuepad = gst_element_get_static_pad (priv->appqueue[i], "src");
1219 pad = gst_element_get_static_pad (priv->appsink[i], "sink");
1220 gst_pad_link (queuepad, pad);
1221 gst_object_unref (pad);
1222 gst_object_unref (queuepad);
1224 /* For the receiver we create this bit of pipeline for both
1225 * RTP and RTCP. We receive RTP/RTCP on appsrc and udpsrc
1226 * and it is all funneled into the rtpbin receive pad.
1228 * .--------. .--------. .--------.
1229 * | udpsrc | | funnel | | rtpbin |
1230 * | src->sink src->sink |
1231 * '--------' | | '--------'
1235 * '--------' '--------'
1237 /* make funnel for the RTP/RTCP receivers */
1238 priv->funnel[i] = gst_element_factory_make ("funnel", NULL);
1239 gst_bin_add (bin, priv->funnel[i]);
1241 pad = gst_element_get_static_pad (priv->funnel[i], "src");
1242 gst_pad_link (pad, priv->recv_sink[i]);
1243 gst_object_unref (pad);
1245 /* we set and keep these to playing so that they don't cause NO_PREROLL return
1247 gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_PLAYING);
1248 gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_PLAYING);
1249 gst_element_set_locked_state (priv->udpsrc_v4[i], TRUE);
1250 gst_element_set_locked_state (priv->udpsrc_v6[i], TRUE);
1252 gst_bin_add (bin, priv->udpsrc_v4[i]);
1253 gst_bin_add (bin, priv->udpsrc_v6[i]);
1254 /* and link to the funnel v4 */
1255 selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
1256 pad = gst_element_get_static_pad (priv->udpsrc_v4[i], "src");
1257 gst_pad_link (pad, selpad);
1258 gst_object_unref (pad);
1259 gst_object_unref (selpad);
1261 /* and link to the funnel v6 */
1262 selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
1263 pad = gst_element_get_static_pad (priv->udpsrc_v6[i], "src");
1264 gst_pad_link (pad, selpad);
1265 gst_object_unref (pad);
1266 gst_object_unref (selpad);
1268 /* make and add appsrc */
1269 priv->appsrc[i] = gst_element_factory_make ("appsrc", NULL);
1270 gst_bin_add (bin, priv->appsrc[i]);
1271 /* and link to the funnel */
1272 selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
1273 pad = gst_element_get_static_pad (priv->appsrc[i], "src");
1274 gst_pad_link (pad, selpad);
1275 gst_object_unref (pad);
1276 gst_object_unref (selpad);
1278 /* check if we need to set to a special state */
1279 if (state != GST_STATE_NULL) {
1280 gst_element_set_state (priv->udpsink[i], state);
1281 gst_element_set_state (priv->appsink[i], state);
1282 gst_element_set_state (priv->appqueue[i], state);
1283 gst_element_set_state (priv->tee[i], state);
1284 gst_element_set_state (priv->funnel[i], state);
1285 gst_element_set_state (priv->appsrc[i], state);
1289 /* be notified of caps changes */
1290 priv->caps_sig = g_signal_connect (priv->send_rtp_sink, "notify::caps",
1291 (GCallback) caps_notify, stream);
1293 priv->is_joined = TRUE;
1294 g_mutex_unlock (&priv->lock);
1301 g_mutex_unlock (&priv->lock);
1306 g_mutex_unlock (&priv->lock);
1307 GST_WARNING ("failed to allocate ports %d", idx);
1312 GST_WARNING ("failed to link stream %d", idx);
1313 gst_object_unref (priv->send_rtp_sink);
1314 priv->send_rtp_sink = NULL;
1315 g_mutex_unlock (&priv->lock);
1321 * gst_rtsp_stream_leave_bin:
1322 * @stream: a #GstRTSPStream
1324 * @rtpbin: a rtpbin #GstElement
1326 * Remove the elements of @stream from @bin.
1328 * Return: %TRUE on success.
1331 gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
1332 GstElement * rtpbin)
1334 GstRTSPStreamPrivate *priv;
1337 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
1338 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
1339 g_return_val_if_fail (GST_IS_ELEMENT (rtpbin), FALSE);
1341 priv = stream->priv;
1343 g_mutex_lock (&priv->lock);
1344 if (!priv->is_joined)
1345 goto was_not_joined;
1347 /* all transports must be removed by now */
1348 g_return_val_if_fail (priv->transports == NULL, FALSE);
1350 GST_INFO ("stream %p leaving bin", stream);
1352 gst_pad_unlink (priv->srcpad, priv->send_rtp_sink);
1353 g_signal_handler_disconnect (priv->send_rtp_sink, priv->caps_sig);
1354 gst_element_release_request_pad (rtpbin, priv->send_rtp_sink);
1355 gst_object_unref (priv->send_rtp_sink);
1356 priv->send_rtp_sink = NULL;
1358 for (i = 0; i < 2; i++) {
1359 gst_element_set_state (priv->udpsink[i], GST_STATE_NULL);
1360 gst_element_set_state (priv->appsink[i], GST_STATE_NULL);
1361 gst_element_set_state (priv->appqueue[i], GST_STATE_NULL);
1362 gst_element_set_state (priv->tee[i], GST_STATE_NULL);
1363 gst_element_set_state (priv->funnel[i], GST_STATE_NULL);
1364 gst_element_set_state (priv->appsrc[i], GST_STATE_NULL);
1365 /* and set udpsrc to NULL now before removing */
1366 gst_element_set_locked_state (priv->udpsrc_v4[i], FALSE);
1367 gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_NULL);
1368 gst_element_set_locked_state (priv->udpsrc_v6[i], FALSE);
1369 gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_NULL);
1371 /* removing them should also nicely release the request
1372 * pads when they finalize */
1373 gst_bin_remove (bin, priv->udpsrc_v4[i]);
1374 gst_bin_remove (bin, priv->udpsrc_v6[i]);
1375 gst_bin_remove (bin, priv->udpsink[i]);
1376 gst_bin_remove (bin, priv->appsrc[i]);
1377 gst_bin_remove (bin, priv->appsink[i]);
1378 gst_bin_remove (bin, priv->appqueue[i]);
1379 gst_bin_remove (bin, priv->tee[i]);
1380 gst_bin_remove (bin, priv->funnel[i]);
1382 gst_element_release_request_pad (rtpbin, priv->recv_sink[i]);
1383 gst_object_unref (priv->recv_sink[i]);
1384 priv->recv_sink[i] = NULL;
1386 priv->udpsrc_v4[i] = NULL;
1387 priv->udpsrc_v6[i] = NULL;
1388 priv->udpsink[i] = NULL;
1389 priv->appsrc[i] = NULL;
1390 priv->appsink[i] = NULL;
1391 priv->appqueue[i] = NULL;
1392 priv->tee[i] = NULL;
1393 priv->funnel[i] = NULL;
1395 gst_object_unref (priv->send_src[0]);
1396 priv->send_src[0] = NULL;
1398 gst_element_release_request_pad (rtpbin, priv->send_src[1]);
1399 gst_object_unref (priv->send_src[1]);
1400 priv->send_src[1] = NULL;
1402 g_object_unref (priv->session);
1403 priv->session = NULL;
1405 gst_caps_unref (priv->caps);
1408 priv->is_joined = FALSE;
1409 g_mutex_unlock (&priv->lock);
1420 * gst_rtsp_stream_get_rtpinfo:
1421 * @stream: a #GstRTSPStream
1422 * @rtptime: result RTP timestamp
1423 * @seq: result RTP seqnum
1425 * Retrieve the current rtptime and seq. This is used to
1426 * construct a RTPInfo reply header.
1428 * Returns: %TRUE when rtptime and seq could be determined.
1431 gst_rtsp_stream_get_rtpinfo (GstRTSPStream * stream,
1432 guint * rtptime, guint * seq)
1434 GstRTSPStreamPrivate *priv;
1435 GObjectClass *payobjclass;
1437 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
1438 g_return_val_if_fail (rtptime != NULL, FALSE);
1439 g_return_val_if_fail (seq != NULL, FALSE);
1441 priv = stream->priv;
1443 payobjclass = G_OBJECT_GET_CLASS (priv->payloader);
1445 if (!g_object_class_find_property (payobjclass, "seqnum") ||
1446 !g_object_class_find_property (payobjclass, "timestamp"))
1449 g_object_get (priv->payloader, "seqnum", seq, "timestamp", rtptime, NULL);
1455 * gst_rtsp_stream_get_caps:
1456 * @stream: a #GstRTSPStream
1458 * Retrieve the current caps of @stream.
1460 * Returns: (transfer full): the #GstCaps of @stream. use gst_caps_unref()
1464 gst_rtsp_stream_get_caps (GstRTSPStream * stream)
1466 GstRTSPStreamPrivate *priv;
1469 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
1471 priv = stream->priv;
1473 g_mutex_lock (&priv->lock);
1474 if ((result = priv->caps))
1475 gst_caps_ref (result);
1476 g_mutex_unlock (&priv->lock);
1482 * gst_rtsp_stream_recv_rtp:
1483 * @stream: a #GstRTSPStream
1484 * @buffer: (transfer full): a #GstBuffer
1486 * Handle an RTP buffer for the stream. This method is usually called when a
1487 * message has been received from a client using the TCP transport.
1489 * This function takes ownership of @buffer.
1491 * Returns: a GstFlowReturn.
1494 gst_rtsp_stream_recv_rtp (GstRTSPStream * stream, GstBuffer * buffer)
1496 GstRTSPStreamPrivate *priv;
1498 GstElement *element;
1500 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_FLOW_ERROR);
1501 priv = stream->priv;
1502 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
1503 g_return_val_if_fail (priv->is_joined, FALSE);
1505 g_mutex_lock (&priv->lock);
1506 element = gst_object_ref (priv->appsrc[0]);
1507 g_mutex_unlock (&priv->lock);
1509 ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
1511 gst_object_unref (element);
1517 * gst_rtsp_stream_recv_rtcp:
1518 * @stream: a #GstRTSPStream
1519 * @buffer: (transfer full): a #GstBuffer
1521 * Handle an RTCP buffer for the stream. This method is usually called when a
1522 * message has been received from a client using the TCP transport.
1524 * This function takes ownership of @buffer.
1526 * Returns: a GstFlowReturn.
1529 gst_rtsp_stream_recv_rtcp (GstRTSPStream * stream, GstBuffer * buffer)
1531 GstRTSPStreamPrivate *priv;
1533 GstElement *element;
1535 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_FLOW_ERROR);
1536 priv = stream->priv;
1537 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
1538 g_return_val_if_fail (priv->is_joined, FALSE);
1540 g_mutex_lock (&priv->lock);
1541 element = gst_object_ref (priv->appsrc[1]);
1542 g_mutex_unlock (&priv->lock);
1544 ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
1546 gst_object_unref (element);
1551 /* must be called with lock */
1553 update_transport (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
1556 GstRTSPStreamPrivate *priv = stream->priv;
1557 const GstRTSPTransport *tr;
1559 tr = gst_rtsp_stream_transport_get_transport (trans);
1561 switch (tr->lower_transport) {
1562 case GST_RTSP_LOWER_TRANS_UDP:
1563 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
1569 dest = tr->destination;
1570 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
1575 min = tr->client_port.min;
1576 max = tr->client_port.max;
1580 GST_INFO ("adding %s:%d-%d", dest, min, max);
1581 g_signal_emit_by_name (priv->udpsink[0], "add", dest, min, NULL);
1582 g_signal_emit_by_name (priv->udpsink[1], "add", dest, max, NULL);
1584 GST_INFO ("setting ttl-mc %d", ttl);
1585 g_object_set (G_OBJECT (priv->udpsink[0]), "ttl-mc", ttl, NULL);
1586 g_object_set (G_OBJECT (priv->udpsink[1]), "ttl-mc", ttl, NULL);
1588 priv->transports = g_list_prepend (priv->transports, trans);
1590 GST_INFO ("removing %s:%d-%d", dest, min, max);
1591 g_signal_emit_by_name (priv->udpsink[0], "remove", dest, min, NULL);
1592 g_signal_emit_by_name (priv->udpsink[1], "remove", dest, max, NULL);
1593 priv->transports = g_list_remove (priv->transports, trans);
1597 case GST_RTSP_LOWER_TRANS_TCP:
1599 GST_INFO ("adding TCP %s", tr->destination);
1600 priv->transports = g_list_prepend (priv->transports, trans);
1602 GST_INFO ("removing TCP %s", tr->destination);
1603 priv->transports = g_list_remove (priv->transports, trans);
1607 goto unknown_transport;
1614 GST_INFO ("Unknown transport %d", tr->lower_transport);
1621 * gst_rtsp_stream_add_transport:
1622 * @stream: a #GstRTSPStream
1623 * @trans: a #GstRTSPStreamTransport
1625 * Add the transport in @trans to @stream. The media of @stream will
1626 * then also be send to the values configured in @trans.
1628 * @stream must be joined to a bin.
1630 * @trans must contain a valid #GstRTSPTransport.
1632 * Returns: %TRUE if @trans was added
1635 gst_rtsp_stream_add_transport (GstRTSPStream * stream,
1636 GstRTSPStreamTransport * trans)
1638 GstRTSPStreamPrivate *priv;
1641 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
1642 priv = stream->priv;
1643 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
1644 g_return_val_if_fail (priv->is_joined, FALSE);
1646 g_mutex_lock (&priv->lock);
1647 res = update_transport (stream, trans, TRUE);
1648 g_mutex_unlock (&priv->lock);
1654 * gst_rtsp_stream_remove_transport:
1655 * @stream: a #GstRTSPStream
1656 * @trans: a #GstRTSPStreamTransport
1658 * Remove the transport in @trans from @stream. The media of @stream will
1659 * not be sent to the values configured in @trans.
1661 * @stream must be joined to a bin.
1663 * @trans must contain a valid #GstRTSPTransport.
1665 * Returns: %TRUE if @trans was removed
1668 gst_rtsp_stream_remove_transport (GstRTSPStream * stream,
1669 GstRTSPStreamTransport * trans)
1671 GstRTSPStreamPrivate *priv;
1674 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
1675 priv = stream->priv;
1676 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
1677 g_return_val_if_fail (priv->is_joined, FALSE);
1679 g_mutex_lock (&priv->lock);
1680 res = update_transport (stream, trans, FALSE);
1681 g_mutex_unlock (&priv->lock);