2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
3 * Copyright (C) 2015 Centricular Ltd
4 * Author: Sebastian Dröge <sebastian@centricular.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 * @short_description: A media stream
24 * @see_also: #GstRTSPMedia
26 * The #GstRTSPStream object manages the data transport for one stream. It
27 * is created from a payloader element and a source pad that produce the RTP
28 * packets for the stream.
30 * With gst_rtsp_stream_join_bin() the streaming elements are added to the bin
31 * and rtpbin. gst_rtsp_stream_leave_bin() removes the elements again.
33 * The #GstRTSPStream will use the configured addresspool, as set with
34 * gst_rtsp_stream_set_address_pool(), to allocate multicast addresses for the
35 * stream. With gst_rtsp_stream_get_multicast_address() you can get the
38 * With gst_rtsp_stream_get_server_port () you can get the port that the server
39 * will use to receive RTCP. This is the part that the clients will use to send
42 * With gst_rtsp_stream_add_transport() destinations can be added where the
43 * stream should be sent to. Use gst_rtsp_stream_remove_transport() to remove
44 * the destination again.
46 * Last reviewed on 2013-07-16 (1.0.0)
55 #include <gst/app/gstappsrc.h>
56 #include <gst/app/gstappsink.h>
58 #include "rtsp-stream.h"
60 #define GST_RTSP_STREAM_GET_PRIVATE(obj) \
61 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_STREAM, GstRTSPStreamPrivate))
65 GstRTSPStreamTransport *transport;
67 /* RTP and RTCP source */
68 GstElement *udpsrc[2];
70 } GstRTSPMulticastTransportSource;
72 struct _GstRTSPStreamPrivate
76 /* Only one pad is ever set */
77 GstPad *srcpad, *sinkpad;
78 GstElement *payloader;
83 GstRTSPProfile profiles;
84 GstRTSPLowerTrans protocols;
86 /* pads on the rtpbin */
87 GstPad *send_rtp_sink;
92 /* the RTPSession object */
95 /* SRTP encoder/decoder */
100 /* sinks used for sending and receiving RTP and RTCP over ipv4, they share
102 GstElement *udpsrc_v4[2];
104 /* sinks used for sending and receiving RTP and RTCP over ipv6, they share
106 GstElement *udpsrc_v6[2];
108 GstElement *udpsink[2];
110 /* for TCP transport */
111 GstElement *appsrc[2];
112 GstClockTime appsrc_base_time[2];
113 GstElement *appqueue[2];
114 GstElement *appsink[2];
117 GstElement *funnel[2];
122 GstClockTime rtx_time;
124 /* server ports for sending/receiving over ipv4 */
125 GstRTSPRange server_port_v4;
126 GstRTSPAddress *server_addr_v4;
129 /* server ports for sending/receiving over ipv6 */
130 GstRTSPRange server_port_v6;
131 GstRTSPAddress *server_addr_v6;
134 /* multicast addresses */
135 GstRTSPAddressPool *pool;
136 GstRTSPAddress *addr_v4;
137 GstRTSPAddress *addr_v6;
139 /* the caps of the stream */
143 /* transports we stream to */
146 guint transports_cookie;
148 GList *tr_cache_rtcp;
149 guint tr_cache_cookie_rtp;
150 guint tr_cache_cookie_rtcp;
153 /* UDP sources for UDP multicast transports */
154 GList *transport_sources;
158 /* stream blocking */
162 /* pt->caps map for RECORD streams */
166 #define DEFAULT_CONTROL NULL
167 #define DEFAULT_PROFILES GST_RTSP_PROFILE_AVP
168 #define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | \
169 GST_RTSP_LOWER_TRANS_TCP
182 SIGNAL_NEW_RTP_ENCODER,
183 SIGNAL_NEW_RTCP_ENCODER,
187 GST_DEBUG_CATEGORY_STATIC (rtsp_stream_debug);
188 #define GST_CAT_DEFAULT rtsp_stream_debug
190 static GQuark ssrc_stream_map_key;
192 static void gst_rtsp_stream_get_property (GObject * object, guint propid,
193 GValue * value, GParamSpec * pspec);
194 static void gst_rtsp_stream_set_property (GObject * object, guint propid,
195 const GValue * value, GParamSpec * pspec);
197 static void gst_rtsp_stream_finalize (GObject * obj);
199 static guint gst_rtsp_stream_signals[SIGNAL_LAST] = { 0 };
201 G_DEFINE_TYPE (GstRTSPStream, gst_rtsp_stream, G_TYPE_OBJECT);
204 gst_rtsp_stream_class_init (GstRTSPStreamClass * klass)
206 GObjectClass *gobject_class;
208 g_type_class_add_private (klass, sizeof (GstRTSPStreamPrivate));
210 gobject_class = G_OBJECT_CLASS (klass);
212 gobject_class->get_property = gst_rtsp_stream_get_property;
213 gobject_class->set_property = gst_rtsp_stream_set_property;
214 gobject_class->finalize = gst_rtsp_stream_finalize;
216 g_object_class_install_property (gobject_class, PROP_CONTROL,
217 g_param_spec_string ("control", "Control",
218 "The control string for this stream", DEFAULT_CONTROL,
219 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
221 g_object_class_install_property (gobject_class, PROP_PROFILES,
222 g_param_spec_flags ("profiles", "Profiles",
223 "Allowed transfer profiles", GST_TYPE_RTSP_PROFILE,
224 DEFAULT_PROFILES, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
226 g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
227 g_param_spec_flags ("protocols", "Protocols",
228 "Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
229 DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
231 gst_rtsp_stream_signals[SIGNAL_NEW_RTP_ENCODER] =
232 g_signal_new ("new-rtp-encoder", G_TYPE_FROM_CLASS (klass),
233 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
234 G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
236 gst_rtsp_stream_signals[SIGNAL_NEW_RTCP_ENCODER] =
237 g_signal_new ("new-rtcp-encoder", G_TYPE_FROM_CLASS (klass),
238 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
239 G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
241 GST_DEBUG_CATEGORY_INIT (rtsp_stream_debug, "rtspstream", 0, "GstRTSPStream");
243 ssrc_stream_map_key = g_quark_from_static_string ("GstRTSPServer.stream");
247 gst_rtsp_stream_init (GstRTSPStream * stream)
249 GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
251 GST_DEBUG ("new stream %p", stream);
256 priv->control = g_strdup (DEFAULT_CONTROL);
257 priv->profiles = DEFAULT_PROFILES;
258 priv->protocols = DEFAULT_PROTOCOLS;
260 g_mutex_init (&priv->lock);
262 priv->keys = g_hash_table_new_full (g_direct_hash, g_direct_equal,
263 NULL, (GDestroyNotify) gst_caps_unref);
264 priv->ptmap = g_hash_table_new_full (NULL, NULL, NULL,
265 (GDestroyNotify) gst_caps_unref);
269 gst_rtsp_stream_finalize (GObject * obj)
271 GstRTSPStream *stream;
272 GstRTSPStreamPrivate *priv;
274 stream = GST_RTSP_STREAM (obj);
277 GST_DEBUG ("finalize stream %p", stream);
279 /* we really need to be unjoined now */
280 g_return_if_fail (!priv->is_joined);
283 gst_rtsp_address_free (priv->addr_v4);
285 gst_rtsp_address_free (priv->addr_v6);
286 if (priv->server_addr_v4)
287 gst_rtsp_address_free (priv->server_addr_v4);
288 if (priv->server_addr_v6)
289 gst_rtsp_address_free (priv->server_addr_v6);
291 g_object_unref (priv->pool);
293 g_object_unref (priv->rtxsend);
295 gst_object_unref (priv->payloader);
297 gst_object_unref (priv->srcpad);
299 gst_object_unref (priv->sinkpad);
300 g_free (priv->control);
301 g_mutex_clear (&priv->lock);
303 g_hash_table_unref (priv->keys);
304 g_hash_table_destroy (priv->ptmap);
306 G_OBJECT_CLASS (gst_rtsp_stream_parent_class)->finalize (obj);
310 gst_rtsp_stream_get_property (GObject * object, guint propid,
311 GValue * value, GParamSpec * pspec)
313 GstRTSPStream *stream = GST_RTSP_STREAM (object);
317 g_value_take_string (value, gst_rtsp_stream_get_control (stream));
320 g_value_set_flags (value, gst_rtsp_stream_get_profiles (stream));
323 g_value_set_flags (value, gst_rtsp_stream_get_protocols (stream));
326 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
331 gst_rtsp_stream_set_property (GObject * object, guint propid,
332 const GValue * value, GParamSpec * pspec)
334 GstRTSPStream *stream = GST_RTSP_STREAM (object);
338 gst_rtsp_stream_set_control (stream, g_value_get_string (value));
341 gst_rtsp_stream_set_profiles (stream, g_value_get_flags (value));
344 gst_rtsp_stream_set_protocols (stream, g_value_get_flags (value));
347 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
352 * gst_rtsp_stream_new:
355 * @payloader: a #GstElement
357 * Create a new media stream with index @idx that handles RTP data on
358 * @pad and has a payloader element @payloader if @pad is a source pad
359 * or a depayloader element @payloader if @pad is a sink pad.
361 * Returns: (transfer full): a new #GstRTSPStream
364 gst_rtsp_stream_new (guint idx, GstElement * payloader, GstPad * pad)
366 GstRTSPStreamPrivate *priv;
367 GstRTSPStream *stream;
369 g_return_val_if_fail (GST_IS_ELEMENT (payloader), NULL);
370 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
372 stream = g_object_new (GST_TYPE_RTSP_STREAM, NULL);
375 priv->payloader = gst_object_ref (payloader);
376 if (GST_PAD_IS_SRC (pad))
377 priv->srcpad = gst_object_ref (pad);
379 priv->sinkpad = gst_object_ref (pad);
385 * gst_rtsp_stream_get_index:
386 * @stream: a #GstRTSPStream
388 * Get the stream index.
390 * Return: the stream index.
393 gst_rtsp_stream_get_index (GstRTSPStream * stream)
395 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
397 return stream->priv->idx;
401 * gst_rtsp_stream_get_pt:
402 * @stream: a #GstRTSPStream
404 * Get the stream payload type.
406 * Return: the stream payload type.
409 gst_rtsp_stream_get_pt (GstRTSPStream * stream)
411 GstRTSPStreamPrivate *priv;
414 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
418 g_object_get (G_OBJECT (priv->payloader), "pt", &pt, NULL);
424 * gst_rtsp_stream_get_srcpad:
425 * @stream: a #GstRTSPStream
427 * Get the srcpad associated with @stream.
429 * Returns: (transfer full): the srcpad. Unref after usage.
432 gst_rtsp_stream_get_srcpad (GstRTSPStream * stream)
434 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
436 if (!stream->priv->srcpad)
439 return gst_object_ref (stream->priv->srcpad);
443 * gst_rtsp_stream_get_sinkpad:
444 * @stream: a #GstRTSPStream
446 * Get the sinkpad associated with @stream.
448 * Returns: (transfer full): the sinkpad. Unref after usage.
451 gst_rtsp_stream_get_sinkpad (GstRTSPStream * stream)
453 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
455 if (!stream->priv->sinkpad)
458 return gst_object_ref (stream->priv->sinkpad);
462 * gst_rtsp_stream_get_control:
463 * @stream: a #GstRTSPStream
465 * Get the control string to identify this stream.
467 * Returns: (transfer full): the control string. g_free() after usage.
470 gst_rtsp_stream_get_control (GstRTSPStream * stream)
472 GstRTSPStreamPrivate *priv;
475 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
479 g_mutex_lock (&priv->lock);
480 if ((result = g_strdup (priv->control)) == NULL)
481 result = g_strdup_printf ("stream=%u", priv->idx);
482 g_mutex_unlock (&priv->lock);
488 * gst_rtsp_stream_set_control:
489 * @stream: a #GstRTSPStream
490 * @control: a control string
492 * Set the control string in @stream.
495 gst_rtsp_stream_set_control (GstRTSPStream * stream, const gchar * control)
497 GstRTSPStreamPrivate *priv;
499 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
503 g_mutex_lock (&priv->lock);
504 g_free (priv->control);
505 priv->control = g_strdup (control);
506 g_mutex_unlock (&priv->lock);
510 * gst_rtsp_stream_has_control:
511 * @stream: a #GstRTSPStream
512 * @control: a control string
514 * Check if @stream has the control string @control.
516 * Returns: %TRUE is @stream has @control as the control string
519 gst_rtsp_stream_has_control (GstRTSPStream * stream, const gchar * control)
521 GstRTSPStreamPrivate *priv;
524 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
528 g_mutex_lock (&priv->lock);
530 res = (g_strcmp0 (priv->control, control) == 0);
534 if (sscanf (control, "stream=%u", &streamid) > 0)
535 res = (streamid == priv->idx);
539 g_mutex_unlock (&priv->lock);
545 * gst_rtsp_stream_set_mtu:
546 * @stream: a #GstRTSPStream
549 * Configure the mtu in the payloader of @stream to @mtu.
552 gst_rtsp_stream_set_mtu (GstRTSPStream * stream, guint mtu)
554 GstRTSPStreamPrivate *priv;
556 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
560 GST_LOG_OBJECT (stream, "set MTU %u", mtu);
562 g_object_set (G_OBJECT (priv->payloader), "mtu", mtu, NULL);
566 * gst_rtsp_stream_get_mtu:
567 * @stream: a #GstRTSPStream
569 * Get the configured MTU in the payloader of @stream.
571 * Returns: the MTU of the payloader.
574 gst_rtsp_stream_get_mtu (GstRTSPStream * stream)
576 GstRTSPStreamPrivate *priv;
579 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
583 g_object_get (G_OBJECT (priv->payloader), "mtu", &mtu, NULL);
588 /* Update the dscp qos property on the udp sinks */
590 update_dscp_qos (GstRTSPStream * stream)
592 GstRTSPStreamPrivate *priv;
594 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
598 if (priv->udpsink[0]) {
599 g_object_set (G_OBJECT (priv->udpsink[0]), "qos-dscp", priv->dscp_qos,
603 if (priv->udpsink[1]) {
604 g_object_set (G_OBJECT (priv->udpsink[1]), "qos-dscp", priv->dscp_qos,
610 * gst_rtsp_stream_set_dscp_qos:
611 * @stream: a #GstRTSPStream
612 * @dscp_qos: a new dscp qos value (0-63, or -1 to disable)
614 * Configure the dscp qos of the outgoing sockets to @dscp_qos.
617 gst_rtsp_stream_set_dscp_qos (GstRTSPStream * stream, gint dscp_qos)
619 GstRTSPStreamPrivate *priv;
621 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
625 GST_LOG_OBJECT (stream, "set DSCP QoS %d", dscp_qos);
627 if (dscp_qos < -1 || dscp_qos > 63) {
628 GST_WARNING_OBJECT (stream, "trying to set illegal dscp qos %d", dscp_qos);
632 priv->dscp_qos = dscp_qos;
634 update_dscp_qos (stream);
638 * gst_rtsp_stream_get_dscp_qos:
639 * @stream: a #GstRTSPStream
641 * Get the configured DSCP QoS in of the outgoing sockets.
643 * Returns: the DSCP QoS value of the outgoing sockets, or -1 if disbled.
646 gst_rtsp_stream_get_dscp_qos (GstRTSPStream * stream)
648 GstRTSPStreamPrivate *priv;
650 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
654 return priv->dscp_qos;
658 * gst_rtsp_stream_is_transport_supported:
659 * @stream: a #GstRTSPStream
660 * @transport: (transfer none): a #GstRTSPTransport
662 * Check if @transport can be handled by stream
664 * Returns: %TRUE if @transport can be handled by @stream.
667 gst_rtsp_stream_is_transport_supported (GstRTSPStream * stream,
668 GstRTSPTransport * transport)
670 GstRTSPStreamPrivate *priv;
672 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
676 g_mutex_lock (&priv->lock);
677 if (transport->trans != GST_RTSP_TRANS_RTP)
678 goto unsupported_transmode;
680 if (!(transport->profile & priv->profiles))
681 goto unsupported_profile;
683 if (!(transport->lower_transport & priv->protocols))
684 goto unsupported_ltrans;
686 g_mutex_unlock (&priv->lock);
691 unsupported_transmode:
693 GST_DEBUG ("unsupported transport mode %d", transport->trans);
694 g_mutex_unlock (&priv->lock);
699 GST_DEBUG ("unsupported profile %d", transport->profile);
700 g_mutex_unlock (&priv->lock);
705 GST_DEBUG ("unsupported lower transport %d", transport->lower_transport);
706 g_mutex_unlock (&priv->lock);
712 * gst_rtsp_stream_set_profiles:
713 * @stream: a #GstRTSPStream
714 * @profiles: the new profiles
716 * Configure the allowed profiles for @stream.
719 gst_rtsp_stream_set_profiles (GstRTSPStream * stream, GstRTSPProfile profiles)
721 GstRTSPStreamPrivate *priv;
723 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
727 g_mutex_lock (&priv->lock);
728 priv->profiles = profiles;
729 g_mutex_unlock (&priv->lock);
733 * gst_rtsp_stream_get_profiles:
734 * @stream: a #GstRTSPStream
736 * Get the allowed profiles of @stream.
738 * Returns: a #GstRTSPProfile
741 gst_rtsp_stream_get_profiles (GstRTSPStream * stream)
743 GstRTSPStreamPrivate *priv;
746 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_RTSP_PROFILE_UNKNOWN);
750 g_mutex_lock (&priv->lock);
751 res = priv->profiles;
752 g_mutex_unlock (&priv->lock);
758 * gst_rtsp_stream_set_protocols:
759 * @stream: a #GstRTSPStream
760 * @protocols: the new flags
762 * Configure the allowed lower transport for @stream.
765 gst_rtsp_stream_set_protocols (GstRTSPStream * stream,
766 GstRTSPLowerTrans protocols)
768 GstRTSPStreamPrivate *priv;
770 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
774 g_mutex_lock (&priv->lock);
775 priv->protocols = protocols;
776 g_mutex_unlock (&priv->lock);
780 * gst_rtsp_stream_get_protocols:
781 * @stream: a #GstRTSPStream
783 * Get the allowed protocols of @stream.
785 * Returns: a #GstRTSPLowerTrans
788 gst_rtsp_stream_get_protocols (GstRTSPStream * stream)
790 GstRTSPStreamPrivate *priv;
791 GstRTSPLowerTrans res;
793 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream),
794 GST_RTSP_LOWER_TRANS_UNKNOWN);
798 g_mutex_lock (&priv->lock);
799 res = priv->protocols;
800 g_mutex_unlock (&priv->lock);
806 * gst_rtsp_stream_set_address_pool:
807 * @stream: a #GstRTSPStream
808 * @pool: (transfer none): a #GstRTSPAddressPool
810 * configure @pool to be used as the address pool of @stream.
813 gst_rtsp_stream_set_address_pool (GstRTSPStream * stream,
814 GstRTSPAddressPool * pool)
816 GstRTSPStreamPrivate *priv;
817 GstRTSPAddressPool *old;
819 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
823 GST_LOG_OBJECT (stream, "set address pool %p", pool);
825 g_mutex_lock (&priv->lock);
826 if ((old = priv->pool) != pool)
827 priv->pool = pool ? g_object_ref (pool) : NULL;
830 g_mutex_unlock (&priv->lock);
833 g_object_unref (old);
837 * gst_rtsp_stream_get_address_pool:
838 * @stream: a #GstRTSPStream
840 * Get the #GstRTSPAddressPool used as the address pool of @stream.
842 * Returns: (transfer full): the #GstRTSPAddressPool of @stream. g_object_unref() after
846 gst_rtsp_stream_get_address_pool (GstRTSPStream * stream)
848 GstRTSPStreamPrivate *priv;
849 GstRTSPAddressPool *result;
851 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
855 g_mutex_lock (&priv->lock);
856 if ((result = priv->pool))
857 g_object_ref (result);
858 g_mutex_unlock (&priv->lock);
864 * gst_rtsp_stream_get_multicast_address:
865 * @stream: a #GstRTSPStream
866 * @family: the #GSocketFamily
868 * Get the multicast address of @stream for @family.
870 * Returns: (transfer full) (nullable): the #GstRTSPAddress of @stream
871 * or %NULL when no address could be allocated. gst_rtsp_address_free()
875 gst_rtsp_stream_get_multicast_address (GstRTSPStream * stream,
876 GSocketFamily family)
878 GstRTSPStreamPrivate *priv;
879 GstRTSPAddress *result;
880 GstRTSPAddress **addrp;
881 GstRTSPAddressFlags flags;
883 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
887 if (family == G_SOCKET_FAMILY_IPV6) {
888 flags = GST_RTSP_ADDRESS_FLAG_IPV6;
889 addrp = &priv->addr_v6;
891 flags = GST_RTSP_ADDRESS_FLAG_IPV4;
892 addrp = &priv->addr_v4;
895 g_mutex_lock (&priv->lock);
896 if (*addrp == NULL) {
897 if (priv->pool == NULL)
900 flags |= GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST;
902 *addrp = gst_rtsp_address_pool_acquire_address (priv->pool, flags, 2);
906 result = gst_rtsp_address_copy (*addrp);
907 g_mutex_unlock (&priv->lock);
914 GST_ERROR_OBJECT (stream, "no address pool specified");
915 g_mutex_unlock (&priv->lock);
920 GST_ERROR_OBJECT (stream, "failed to acquire address from pool");
921 g_mutex_unlock (&priv->lock);
927 * gst_rtsp_stream_reserve_address:
928 * @stream: a #GstRTSPStream
929 * @address: an address
934 * Reserve @address and @port as the address and port of @stream.
936 * Returns: (nullable): the #GstRTSPAddress of @stream or %NULL when
937 * the address could be reserved. gst_rtsp_address_free() after usage.
940 gst_rtsp_stream_reserve_address (GstRTSPStream * stream,
941 const gchar * address, guint port, guint n_ports, guint ttl)
943 GstRTSPStreamPrivate *priv;
944 GstRTSPAddress *result;
946 GSocketFamily family;
947 GstRTSPAddress **addrp;
949 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
950 g_return_val_if_fail (address != NULL, NULL);
951 g_return_val_if_fail (port > 0, NULL);
952 g_return_val_if_fail (n_ports > 0, NULL);
953 g_return_val_if_fail (ttl > 0, NULL);
957 addr = g_inet_address_new_from_string (address);
959 GST_ERROR ("failed to get inet addr from %s", address);
960 family = G_SOCKET_FAMILY_IPV4;
962 family = g_inet_address_get_family (addr);
963 g_object_unref (addr);
966 if (family == G_SOCKET_FAMILY_IPV6)
967 addrp = &priv->addr_v6;
969 addrp = &priv->addr_v4;
971 g_mutex_lock (&priv->lock);
972 if (*addrp == NULL) {
973 GstRTSPAddressPoolResult res;
975 if (priv->pool == NULL)
978 res = gst_rtsp_address_pool_reserve_address (priv->pool, address,
979 port, n_ports, ttl, addrp);
980 if (res != GST_RTSP_ADDRESS_POOL_OK)
983 if (strcmp ((*addrp)->address, address) ||
984 (*addrp)->port != port || (*addrp)->n_ports != n_ports ||
985 (*addrp)->ttl != ttl)
986 goto different_address;
988 result = gst_rtsp_address_copy (*addrp);
989 g_mutex_unlock (&priv->lock);
996 GST_ERROR_OBJECT (stream, "no address pool specified");
997 g_mutex_unlock (&priv->lock);
1002 GST_ERROR_OBJECT (stream, "failed to acquire address %s from pool",
1004 g_mutex_unlock (&priv->lock);
1009 GST_ERROR_OBJECT (stream, "address %s is not the same that was already"
1010 " reserved", address);
1011 g_mutex_unlock (&priv->lock);
1017 alloc_ports_one_family (GstRTSPStream * stream, GstRTSPAddressPool * pool,
1018 gint buffer_size, GSocketFamily family, GstElement * udpsrc_out[2],
1019 GstElement * udpsink_out[2], GstRTSPRange * server_port_out,
1020 GstRTSPAddress ** server_addr_out)
1022 GstRTSPStreamPrivate *priv = stream->priv;
1023 GstStateChangeReturn ret;
1024 GstElement *udpsrc0, *udpsrc1;
1025 GstElement *udpsink0, *udpsink1;
1026 GSocket *rtp_socket = NULL;
1027 GSocket *rtcp_socket;
1028 gint tmp_rtp, tmp_rtcp;
1030 gint rtpport, rtcpport;
1031 GList *rejected_addresses = NULL;
1032 GstRTSPAddress *addr = NULL;
1033 GInetAddress *inetaddr = NULL;
1034 GSocketAddress *rtp_sockaddr = NULL;
1035 GSocketAddress *rtcp_sockaddr = NULL;
1036 const gchar *multisink_socket;
1038 if (family == G_SOCKET_FAMILY_IPV6)
1039 multisink_socket = "socket-v6";
1041 multisink_socket = "socket";
1049 /* Start with random port */
1052 rtcp_socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
1053 G_SOCKET_PROTOCOL_UDP, NULL);
1055 goto no_udp_protocol;
1057 if (*server_addr_out)
1058 gst_rtsp_address_free (*server_addr_out);
1060 /* try to allocate 2 UDP ports, the RTP port should be an even
1061 * number and the RTCP port should be the next (uneven) port */
1064 if (rtp_socket == NULL) {
1065 rtp_socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
1066 G_SOCKET_PROTOCOL_UDP, NULL);
1068 goto no_udp_protocol;
1071 if (pool && gst_rtsp_address_pool_has_unicast_addresses (pool)) {
1072 GstRTSPAddressFlags flags;
1075 rejected_addresses = g_list_prepend (rejected_addresses, addr);
1077 flags = GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_UNICAST;
1078 if (family == G_SOCKET_FAMILY_IPV6)
1079 flags |= GST_RTSP_ADDRESS_FLAG_IPV6;
1081 flags |= GST_RTSP_ADDRESS_FLAG_IPV4;
1083 addr = gst_rtsp_address_pool_acquire_address (pool, flags, 2);
1088 tmp_rtp = addr->port;
1090 g_clear_object (&inetaddr);
1091 inetaddr = g_inet_address_new_from_string (addr->address);
1099 if (inetaddr == NULL)
1100 inetaddr = g_inet_address_new_any (family);
1103 rtp_sockaddr = g_inet_socket_address_new (inetaddr, tmp_rtp);
1104 if (!g_socket_bind (rtp_socket, rtp_sockaddr, FALSE, NULL)) {
1105 g_object_unref (rtp_sockaddr);
1108 g_object_unref (rtp_sockaddr);
1110 rtp_sockaddr = g_socket_get_local_address (rtp_socket, NULL);
1111 if (rtp_sockaddr == NULL || !G_IS_INET_SOCKET_ADDRESS (rtp_sockaddr)) {
1112 g_clear_object (&rtp_sockaddr);
1117 g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (rtp_sockaddr));
1118 g_object_unref (rtp_sockaddr);
1120 /* check if port is even */
1121 if ((tmp_rtp & 1) != 0) {
1122 /* port not even, close and allocate another */
1124 g_clear_object (&rtp_socket);
1129 tmp_rtcp = tmp_rtp + 1;
1131 rtcp_sockaddr = g_inet_socket_address_new (inetaddr, tmp_rtcp);
1132 if (!g_socket_bind (rtcp_socket, rtcp_sockaddr, FALSE, NULL)) {
1133 g_object_unref (rtcp_sockaddr);
1134 g_clear_object (&rtp_socket);
1137 g_object_unref (rtcp_sockaddr);
1139 g_clear_object (&inetaddr);
1141 udpsrc0 = gst_element_factory_make ("udpsrc", NULL);
1142 udpsrc1 = gst_element_factory_make ("udpsrc", NULL);
1144 if (udpsrc0 == NULL || udpsrc1 == NULL)
1145 goto no_udp_protocol;
1147 g_object_set (G_OBJECT (udpsrc0), "socket", rtp_socket, NULL);
1148 g_object_set (G_OBJECT (udpsrc1), "socket", rtcp_socket, NULL);
1150 ret = gst_element_set_state (udpsrc0, GST_STATE_READY);
1151 if (ret == GST_STATE_CHANGE_FAILURE)
1153 ret = gst_element_set_state (udpsrc1, GST_STATE_READY);
1154 if (ret == GST_STATE_CHANGE_FAILURE)
1157 /* all fine, do port check */
1158 g_object_get (G_OBJECT (udpsrc0), "port", &rtpport, NULL);
1159 g_object_get (G_OBJECT (udpsrc1), "port", &rtcpport, NULL);
1161 /* this should not happen... */
1162 if (rtpport != tmp_rtp || rtcpport != tmp_rtcp)
1166 udpsink0 = udpsink_out[0];
1168 udpsink0 = gst_element_factory_make ("multiudpsink", NULL);
1171 goto no_udp_protocol;
1173 g_object_set (G_OBJECT (udpsink0), "close-socket", FALSE, NULL);
1174 g_object_set (G_OBJECT (udpsink0), multisink_socket, rtp_socket, NULL);
1177 udpsink1 = udpsink_out[1];
1179 udpsink1 = gst_element_factory_make ("multiudpsink", NULL);
1182 goto no_udp_protocol;
1184 g_object_set (G_OBJECT (udpsink0), "send-duplicates", FALSE, NULL);
1185 g_object_set (G_OBJECT (udpsink1), "send-duplicates", FALSE, NULL);
1186 g_object_set (G_OBJECT (udpsink0), "buffer-size", buffer_size, NULL);
1188 g_object_set (G_OBJECT (udpsink1), "close-socket", FALSE, NULL);
1189 g_object_set (G_OBJECT (udpsink1), multisink_socket, rtcp_socket, NULL);
1190 g_object_set (G_OBJECT (udpsink1), "sync", FALSE, NULL);
1191 /* Needs to be async for RECORD streams, otherwise we will never go to
1192 * PLAYING because the sinks will wait for data while the udpsrc can't
1193 * provide data with timestamps in PAUSED. */
1195 g_object_set (G_OBJECT (udpsink0), "async", FALSE, NULL);
1196 g_object_set (G_OBJECT (udpsink1), "async", FALSE, NULL);
1197 g_object_set (G_OBJECT (udpsink0), "auto-multicast", FALSE, NULL);
1198 g_object_set (G_OBJECT (udpsink0), "loop", FALSE, NULL);
1199 g_object_set (G_OBJECT (udpsink1), "auto-multicast", FALSE, NULL);
1200 g_object_set (G_OBJECT (udpsink1), "loop", FALSE, NULL);
1202 /* we keep these elements, we will further configure them when the
1203 * client told us to really use the UDP ports. */
1204 udpsrc_out[0] = udpsrc0;
1205 udpsrc_out[1] = udpsrc1;
1206 udpsink_out[0] = udpsink0;
1207 udpsink_out[1] = udpsink1;
1209 server_port_out->min = rtpport;
1210 server_port_out->max = rtcpport;
1212 *server_addr_out = addr;
1213 g_list_free_full (rejected_addresses, (GDestroyNotify) gst_rtsp_address_free);
1215 g_object_unref (rtp_socket);
1216 g_object_unref (rtcp_socket);
1244 gst_element_set_state (udpsrc0, GST_STATE_NULL);
1245 gst_object_unref (udpsrc0);
1248 gst_element_set_state (udpsrc1, GST_STATE_NULL);
1249 gst_object_unref (udpsrc1);
1252 gst_element_set_state (udpsink0, GST_STATE_NULL);
1253 gst_object_unref (udpsink0);
1256 g_object_unref (inetaddr);
1257 g_list_free_full (rejected_addresses,
1258 (GDestroyNotify) gst_rtsp_address_free);
1260 gst_rtsp_address_free (addr);
1262 g_object_unref (rtp_socket);
1264 g_object_unref (rtcp_socket);
1269 /* must be called with lock */
1271 alloc_ports (GstRTSPStream * stream)
1273 GstRTSPStreamPrivate *priv = stream->priv;
1276 alloc_ports_one_family (stream, priv->pool, priv->buffer_size,
1277 G_SOCKET_FAMILY_IPV4, priv->udpsrc_v4, priv->udpsink,
1278 &priv->server_port_v4, &priv->server_addr_v4);
1281 alloc_ports_one_family (stream, priv->pool, priv->buffer_size,
1282 G_SOCKET_FAMILY_IPV6, priv->udpsrc_v6, priv->udpsink,
1283 &priv->server_port_v6, &priv->server_addr_v6);
1285 return priv->have_ipv4 || priv->have_ipv6;
1289 * gst_rtsp_stream_get_server_port:
1290 * @stream: a #GstRTSPStream
1291 * @server_port: (out): result server port
1292 * @family: the port family to get
1294 * Fill @server_port with the port pair used by the server. This function can
1295 * only be called when @stream has been joined.
1298 gst_rtsp_stream_get_server_port (GstRTSPStream * stream,
1299 GstRTSPRange * server_port, GSocketFamily family)
1301 GstRTSPStreamPrivate *priv;
1303 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
1304 priv = stream->priv;
1305 g_return_if_fail (priv->is_joined);
1307 g_mutex_lock (&priv->lock);
1308 if (family == G_SOCKET_FAMILY_IPV4) {
1310 *server_port = priv->server_port_v4;
1313 *server_port = priv->server_port_v6;
1315 g_mutex_unlock (&priv->lock);
1319 * gst_rtsp_stream_get_rtpsession:
1320 * @stream: a #GstRTSPStream
1322 * Get the RTP session of this stream.
1324 * Returns: (transfer full): The RTP session of this stream. Unref after usage.
1327 gst_rtsp_stream_get_rtpsession (GstRTSPStream * stream)
1329 GstRTSPStreamPrivate *priv;
1332 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
1334 priv = stream->priv;
1336 g_mutex_lock (&priv->lock);
1337 if ((session = priv->session))
1338 g_object_ref (session);
1339 g_mutex_unlock (&priv->lock);
1345 * gst_rtsp_stream_get_ssrc:
1346 * @stream: a #GstRTSPStream
1347 * @ssrc: (out): result ssrc
1349 * Get the SSRC used by the RTP session of this stream. This function can only
1350 * be called when @stream has been joined.
1353 gst_rtsp_stream_get_ssrc (GstRTSPStream * stream, guint * ssrc)
1355 GstRTSPStreamPrivate *priv;
1357 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
1358 priv = stream->priv;
1359 g_return_if_fail (priv->is_joined);
1361 g_mutex_lock (&priv->lock);
1362 if (ssrc && priv->session)
1363 g_object_get (priv->session, "internal-ssrc", ssrc, NULL);
1364 g_mutex_unlock (&priv->lock);
1368 * gst_rtsp_stream_set_retransmission_time:
1369 * @stream: a #GstRTSPStream
1370 * @time: a #GstClockTime
1372 * Set the amount of time to store retransmission packets.
1375 gst_rtsp_stream_set_retransmission_time (GstRTSPStream * stream,
1378 GST_DEBUG_OBJECT (stream, "set retransmission time %" G_GUINT64_FORMAT, time);
1380 g_mutex_lock (&stream->priv->lock);
1381 stream->priv->rtx_time = time;
1382 if (stream->priv->rtxsend)
1383 g_object_set (stream->priv->rtxsend, "max-size-time",
1384 GST_TIME_AS_MSECONDS (time), NULL);
1385 g_mutex_unlock (&stream->priv->lock);
1389 * gst_rtsp_media_get_retransmission_time:
1390 * @media: a #GstRTSPMedia
1392 * Get the amount of time to store retransmission data.
1394 * Returns: the amount of time to store retransmission data.
1397 gst_rtsp_stream_get_retransmission_time (GstRTSPStream * stream)
1401 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
1403 g_mutex_lock (&stream->priv->lock);
1404 ret = stream->priv->rtx_time;
1405 g_mutex_unlock (&stream->priv->lock);
1411 gst_rtsp_stream_set_retransmission_pt (GstRTSPStream * stream, guint rtx_pt)
1413 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
1415 GST_DEBUG_OBJECT (stream, "set retransmission pt %u", rtx_pt);
1417 g_mutex_lock (&stream->priv->lock);
1418 stream->priv->rtx_pt = rtx_pt;
1419 if (stream->priv->rtxsend) {
1420 guint pt = gst_rtsp_stream_get_pt (stream);
1421 gchar *pt_s = g_strdup_printf ("%d", pt);
1422 GstStructure *rtx_pt_map = gst_structure_new ("application/x-rtp-pt-map",
1423 pt_s, G_TYPE_UINT, rtx_pt, NULL);
1424 g_object_set (stream->priv->rtxsend, "payload-type-map", rtx_pt_map, NULL);
1426 gst_structure_free (rtx_pt_map);
1428 g_mutex_unlock (&stream->priv->lock);
1432 gst_rtsp_stream_get_retransmission_pt (GstRTSPStream * stream)
1436 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
1438 g_mutex_lock (&stream->priv->lock);
1439 rtx_pt = stream->priv->rtx_pt;
1440 g_mutex_unlock (&stream->priv->lock);
1445 /* executed from streaming thread */
1447 caps_notify (GstPad * pad, GParamSpec * unused, GstRTSPStream * stream)
1449 GstRTSPStreamPrivate *priv = stream->priv;
1450 GstCaps *newcaps, *oldcaps;
1452 newcaps = gst_pad_get_current_caps (pad);
1454 GST_INFO ("stream %p received caps %p, %" GST_PTR_FORMAT, stream, newcaps,
1457 g_mutex_lock (&priv->lock);
1458 oldcaps = priv->caps;
1459 priv->caps = newcaps;
1460 g_mutex_unlock (&priv->lock);
1463 gst_caps_unref (oldcaps);
1467 dump_structure (const GstStructure * s)
1471 sstr = gst_structure_to_string (s);
1472 GST_INFO ("structure: %s", sstr);
1476 static GstRTSPStreamTransport *
1477 find_transport (GstRTSPStream * stream, const gchar * rtcp_from)
1479 GstRTSPStreamPrivate *priv = stream->priv;
1481 GstRTSPStreamTransport *result = NULL;
1486 if (rtcp_from == NULL)
1489 tmp = g_strrstr (rtcp_from, ":");
1493 port = atoi (tmp + 1);
1494 dest = g_strndup (rtcp_from, tmp - rtcp_from);
1496 g_mutex_lock (&priv->lock);
1497 GST_INFO ("finding %s:%d in %d transports", dest, port,
1498 g_list_length (priv->transports));
1500 for (walk = priv->transports; walk; walk = g_list_next (walk)) {
1501 GstRTSPStreamTransport *trans = walk->data;
1502 const GstRTSPTransport *tr;
1505 tr = gst_rtsp_stream_transport_get_transport (trans);
1507 min = tr->client_port.min;
1508 max = tr->client_port.max;
1510 if ((strcmp (tr->destination, dest) == 0) && (min == port || max == port)) {
1516 g_object_ref (result);
1517 g_mutex_unlock (&priv->lock);
1524 static GstRTSPStreamTransport *
1525 check_transport (GObject * source, GstRTSPStream * stream)
1527 GstStructure *stats;
1528 GstRTSPStreamTransport *trans;
1530 /* see if we have a stream to match with the origin of the RTCP packet */
1531 trans = g_object_get_qdata (source, ssrc_stream_map_key);
1532 if (trans == NULL) {
1533 g_object_get (source, "stats", &stats, NULL);
1535 const gchar *rtcp_from;
1537 dump_structure (stats);
1539 rtcp_from = gst_structure_get_string (stats, "rtcp-from");
1540 if ((trans = find_transport (stream, rtcp_from))) {
1541 GST_INFO ("%p: found transport %p for source %p", stream, trans,
1543 g_object_set_qdata_full (source, ssrc_stream_map_key, trans,
1546 gst_structure_free (stats);
1554 on_new_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
1556 GstRTSPStreamTransport *trans;
1558 GST_INFO ("%p: new source %p", stream, source);
1560 trans = check_transport (source, stream);
1563 GST_INFO ("%p: source %p for transport %p", stream, source, trans);
1567 on_ssrc_sdes (GObject * session, GObject * source, GstRTSPStream * stream)
1569 GST_INFO ("%p: new SDES %p", stream, source);
1573 on_ssrc_active (GObject * session, GObject * source, GstRTSPStream * stream)
1575 GstRTSPStreamTransport *trans;
1577 trans = check_transport (source, stream);
1580 GST_INFO ("%p: source %p in transport %p is active", stream, source, trans);
1581 gst_rtsp_stream_transport_keep_alive (trans);
1585 GstStructure *stats;
1586 g_object_get (source, "stats", &stats, NULL);
1588 dump_structure (stats);
1589 gst_structure_free (stats);
1596 on_bye_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
1598 GST_INFO ("%p: source %p bye", stream, source);
1602 on_bye_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
1604 GstRTSPStreamTransport *trans;
1606 GST_INFO ("%p: source %p bye timeout", stream, source);
1608 if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
1609 gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
1610 g_object_set_qdata (source, ssrc_stream_map_key, NULL);
1615 on_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
1617 GstRTSPStreamTransport *trans;
1619 GST_INFO ("%p: source %p timeout", stream, source);
1621 if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
1622 gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
1623 g_object_set_qdata (source, ssrc_stream_map_key, NULL);
1628 clear_tr_cache (GstRTSPStreamPrivate * priv, gboolean is_rtp)
1631 g_list_foreach (priv->tr_cache_rtp, (GFunc) g_object_unref, NULL);
1632 g_list_free (priv->tr_cache_rtp);
1633 priv->tr_cache_rtp = NULL;
1635 g_list_foreach (priv->tr_cache_rtcp, (GFunc) g_object_unref, NULL);
1636 g_list_free (priv->tr_cache_rtcp);
1637 priv->tr_cache_rtcp = NULL;
1641 static GstFlowReturn
1642 handle_new_sample (GstAppSink * sink, gpointer user_data)
1644 GstRTSPStreamPrivate *priv;
1648 GstRTSPStream *stream;
1651 sample = gst_app_sink_pull_sample (sink);
1655 stream = (GstRTSPStream *) user_data;
1656 priv = stream->priv;
1657 buffer = gst_sample_get_buffer (sample);
1659 is_rtp = GST_ELEMENT_CAST (sink) == priv->appsink[0];
1661 g_mutex_lock (&priv->lock);
1663 if (priv->tr_cache_cookie_rtp != priv->transports_cookie) {
1664 clear_tr_cache (priv, is_rtp);
1665 for (walk = priv->transports; walk; walk = g_list_next (walk)) {
1666 GstRTSPStreamTransport *tr = (GstRTSPStreamTransport *) walk->data;
1667 priv->tr_cache_rtp =
1668 g_list_prepend (priv->tr_cache_rtp, g_object_ref (tr));
1670 priv->tr_cache_cookie_rtp = priv->transports_cookie;
1673 if (priv->tr_cache_cookie_rtcp != priv->transports_cookie) {
1674 clear_tr_cache (priv, is_rtp);
1675 for (walk = priv->transports; walk; walk = g_list_next (walk)) {
1676 GstRTSPStreamTransport *tr = (GstRTSPStreamTransport *) walk->data;
1677 priv->tr_cache_rtcp =
1678 g_list_prepend (priv->tr_cache_rtcp, g_object_ref (tr));
1680 priv->tr_cache_cookie_rtcp = priv->transports_cookie;
1683 g_mutex_unlock (&priv->lock);
1686 for (walk = priv->tr_cache_rtp; walk; walk = g_list_next (walk)) {
1687 GstRTSPStreamTransport *tr = (GstRTSPStreamTransport *) walk->data;
1688 gst_rtsp_stream_transport_send_rtp (tr, buffer);
1691 for (walk = priv->tr_cache_rtcp; walk; walk = g_list_next (walk)) {
1692 GstRTSPStreamTransport *tr = (GstRTSPStreamTransport *) walk->data;
1693 gst_rtsp_stream_transport_send_rtcp (tr, buffer);
1696 gst_sample_unref (sample);
1701 static GstAppSinkCallbacks sink_cb = {
1702 NULL, /* not interested in EOS */
1703 NULL, /* not interested in preroll samples */
1708 get_rtp_encoder (GstRTSPStream * stream, guint session)
1710 GstRTSPStreamPrivate *priv = stream->priv;
1712 if (priv->srtpenc == NULL) {
1715 name = g_strdup_printf ("srtpenc_%u", session);
1716 priv->srtpenc = gst_element_factory_make ("srtpenc", name);
1719 g_object_set (priv->srtpenc, "random-key", TRUE, NULL);
1721 return gst_object_ref (priv->srtpenc);
1725 request_rtp_encoder (GstElement * rtpbin, guint session, GstRTSPStream * stream)
1727 GstRTSPStreamPrivate *priv = stream->priv;
1728 GstElement *oldenc, *enc;
1732 if (priv->idx != session)
1735 GST_DEBUG_OBJECT (stream, "make RTP encoder for session %u", session);
1737 oldenc = priv->srtpenc;
1738 enc = get_rtp_encoder (stream, session);
1739 name = g_strdup_printf ("rtp_sink_%d", session);
1740 pad = gst_element_get_request_pad (enc, name);
1742 gst_object_unref (pad);
1745 g_signal_emit (stream, gst_rtsp_stream_signals[SIGNAL_NEW_RTP_ENCODER], 0,
1752 request_rtcp_encoder (GstElement * rtpbin, guint session,
1753 GstRTSPStream * stream)
1755 GstRTSPStreamPrivate *priv = stream->priv;
1756 GstElement *oldenc, *enc;
1760 if (priv->idx != session)
1763 GST_DEBUG_OBJECT (stream, "make RTCP encoder for session %u", session);
1765 oldenc = priv->srtpenc;
1766 enc = get_rtp_encoder (stream, session);
1767 name = g_strdup_printf ("rtcp_sink_%d", session);
1768 pad = gst_element_get_request_pad (enc, name);
1770 gst_object_unref (pad);
1773 g_signal_emit (stream, gst_rtsp_stream_signals[SIGNAL_NEW_RTCP_ENCODER], 0,
1780 request_key (GstElement * srtpdec, guint ssrc, GstRTSPStream * stream)
1782 GstRTSPStreamPrivate *priv = stream->priv;
1785 GST_DEBUG ("request key %08x", ssrc);
1787 g_mutex_lock (&priv->lock);
1788 if ((caps = g_hash_table_lookup (priv->keys, GINT_TO_POINTER (ssrc))))
1789 gst_caps_ref (caps);
1790 g_mutex_unlock (&priv->lock);
1796 request_rtp_rtcp_decoder (GstElement * rtpbin, guint session,
1797 GstRTSPStream * stream)
1799 GstRTSPStreamPrivate *priv = stream->priv;
1801 if (priv->idx != session)
1804 if (priv->srtpdec == NULL) {
1807 name = g_strdup_printf ("srtpdec_%u", session);
1808 priv->srtpdec = gst_element_factory_make ("srtpdec", name);
1811 g_signal_connect (priv->srtpdec, "request-key",
1812 (GCallback) request_key, stream);
1814 return gst_object_ref (priv->srtpdec);
1818 request_aux_sender (GstElement * rtpbin, guint sessid, GstRTSPStream * stream)
1822 GstStructure *pt_map;
1827 pt = gst_rtsp_stream_get_pt (stream);
1828 pt_s = g_strdup_printf ("%u", pt);
1829 rtx_pt = stream->priv->rtx_pt;
1831 GST_INFO ("creating rtxsend with pt %u to %u", pt, rtx_pt);
1833 bin = gst_bin_new (NULL);
1834 stream->priv->rtxsend = gst_element_factory_make ("rtprtxsend", NULL);
1835 pt_map = gst_structure_new ("application/x-rtp-pt-map",
1836 pt_s, G_TYPE_UINT, rtx_pt, NULL);
1837 g_object_set (stream->priv->rtxsend, "payload-type-map", pt_map,
1838 "max-size-time", GST_TIME_AS_MSECONDS (stream->priv->rtx_time), NULL);
1840 gst_structure_free (pt_map);
1841 gst_bin_add (GST_BIN (bin), gst_object_ref (stream->priv->rtxsend));
1843 pad = gst_element_get_static_pad (stream->priv->rtxsend, "src");
1844 name = g_strdup_printf ("src_%u", sessid);
1845 gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
1847 gst_object_unref (pad);
1849 pad = gst_element_get_static_pad (stream->priv->rtxsend, "sink");
1850 name = g_strdup_printf ("sink_%u", sessid);
1851 gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
1853 gst_object_unref (pad);
1859 * gst_rtsp_stream_set_pt_map:
1860 * @stream: a #GstRTSPStream
1864 * Configure a pt map between @pt and @caps.
1867 gst_rtsp_stream_set_pt_map (GstRTSPStream * stream, guint pt, GstCaps * caps)
1869 GstRTSPStreamPrivate *priv = stream->priv;
1871 g_mutex_lock (&priv->lock);
1872 g_hash_table_insert (priv->ptmap, GINT_TO_POINTER (pt), gst_caps_ref (caps));
1873 g_mutex_unlock (&priv->lock);
1877 request_pt_map (GstElement * rtpbin, guint session, guint pt,
1878 GstRTSPStream * stream)
1880 GstRTSPStreamPrivate *priv = stream->priv;
1881 GstCaps *caps = NULL;
1883 g_mutex_lock (&priv->lock);
1885 if (priv->idx == session) {
1886 caps = g_hash_table_lookup (priv->ptmap, GINT_TO_POINTER (pt));
1888 GST_DEBUG ("Stream %p, pt %u: caps %" GST_PTR_FORMAT, stream, pt, caps);
1889 gst_caps_ref (caps);
1891 GST_DEBUG ("Stream %p, pt %u: no caps", stream, pt);
1895 g_mutex_unlock (&priv->lock);
1901 pad_added (GstElement * rtpbin, GstPad * pad, GstRTSPStream * stream)
1903 GstRTSPStreamPrivate *priv = stream->priv;
1905 GstPadLinkReturn ret;
1908 GST_DEBUG ("Stream %p added pad %s:%s for pad %s:%s", stream,
1909 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (priv->sinkpad));
1911 name = gst_pad_get_name (pad);
1912 if (sscanf (name, "recv_rtp_src_%u", &sessid) != 1) {
1918 if (priv->idx != sessid)
1921 if (gst_pad_is_linked (priv->sinkpad)) {
1922 GST_WARNING ("Stream %p: Pad %s:%s is linked already", stream,
1923 GST_DEBUG_PAD_NAME (priv->sinkpad));
1927 /* link the RTP pad to the session manager, it should not really fail unless
1928 * this is not really an RTP pad */
1929 ret = gst_pad_link (pad, priv->sinkpad);
1930 if (ret != GST_PAD_LINK_OK)
1932 priv->recv_rtp_src = gst_object_ref (pad);
1939 GST_ERROR ("Stream %p: Failed to link pads %s:%s and %s:%s", stream,
1940 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (priv->sinkpad));
1945 on_npt_stop (GstElement * rtpbin, guint session, guint ssrc,
1946 GstRTSPStream * stream)
1948 /* TODO: What to do here other than this? */
1949 GST_DEBUG ("Stream %p: Got EOS", stream);
1950 gst_pad_send_event (stream->priv->sinkpad, gst_event_new_eos ());
1954 * gst_rtsp_stream_join_bin:
1955 * @stream: a #GstRTSPStream
1956 * @bin: (transfer none): a #GstBin to join
1957 * @rtpbin: (transfer none): a rtpbin element in @bin
1958 * @state: the target state of the new elements
1960 * Join the #GstBin @bin that contains the element @rtpbin.
1962 * @stream will link to @rtpbin, which must be inside @bin. The elements
1963 * added to @bin will be set to the state given in @state.
1965 * Returns: %TRUE on success.
1968 gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
1969 GstElement * rtpbin, GstState state)
1971 GstRTSPStreamPrivate *priv;
1975 GstPad *pad, *sinkpad, *selpad;
1976 GstPadLinkReturn ret;
1978 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
1979 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
1980 g_return_val_if_fail (GST_IS_ELEMENT (rtpbin), FALSE);
1982 priv = stream->priv;
1984 g_mutex_lock (&priv->lock);
1985 if (priv->is_joined)
1988 /* create a session with the same index as the stream */
1991 GST_INFO ("stream %p joining bin as session %u", stream, idx);
1993 if (!alloc_ports (stream))
1996 /* update the dscp qos field in the sinks */
1997 update_dscp_qos (stream);
1999 if (priv->profiles & GST_RTSP_PROFILE_SAVP
2000 || priv->profiles & GST_RTSP_PROFILE_SAVPF) {
2002 g_signal_connect (rtpbin, "request-rtp-encoder",
2003 (GCallback) request_rtp_encoder, stream);
2004 g_signal_connect (rtpbin, "request-rtcp-encoder",
2005 (GCallback) request_rtcp_encoder, stream);
2006 g_signal_connect (rtpbin, "request-rtp-decoder",
2007 (GCallback) request_rtp_rtcp_decoder, stream);
2008 g_signal_connect (rtpbin, "request-rtcp-decoder",
2009 (GCallback) request_rtp_rtcp_decoder, stream);
2012 if (priv->rtx_time > 0 && priv->srcpad) {
2013 /* enable retransmission by setting rtprtxsend as the "aux" element of rtpbin */
2014 g_signal_connect (rtpbin, "request-aux-sender",
2015 (GCallback) request_aux_sender, stream);
2017 if (priv->sinkpad) {
2018 g_signal_connect (rtpbin, "request-pt-map",
2019 (GCallback) request_pt_map, stream);
2022 /* get a pad for sending RTP */
2023 name = g_strdup_printf ("send_rtp_sink_%u", idx);
2024 priv->send_rtp_sink = gst_element_get_request_pad (rtpbin, name);
2028 /* link the RTP pad to the session manager, it should not really fail unless
2029 * this is not really an RTP pad */
2030 ret = gst_pad_link (priv->srcpad, priv->send_rtp_sink);
2031 if (ret != GST_PAD_LINK_OK)
2034 /* Need to connect our sinkpad from here */
2035 g_signal_connect (rtpbin, "pad-added", (GCallback) pad_added, stream);
2037 g_signal_connect (rtpbin, "on-npt-stop", (GCallback) on_npt_stop, stream);
2040 /* get pads from the RTP session element for sending and receiving
2042 name = g_strdup_printf ("send_rtp_src_%u", idx);
2043 priv->send_src[0] = gst_element_get_static_pad (rtpbin, name);
2045 name = g_strdup_printf ("recv_rtp_sink_%u", idx);
2046 priv->recv_sink[0] = gst_element_get_request_pad (rtpbin, name);
2049 name = g_strdup_printf ("send_rtcp_src_%u", idx);
2050 priv->send_src[1] = gst_element_get_request_pad (rtpbin, name);
2052 name = g_strdup_printf ("recv_rtcp_sink_%u", idx);
2053 priv->recv_sink[1] = gst_element_get_request_pad (rtpbin, name);
2056 /* get the session */
2057 g_signal_emit_by_name (rtpbin, "get-internal-session", idx, &priv->session);
2059 g_signal_connect (priv->session, "on-new-ssrc", (GCallback) on_new_ssrc,
2061 g_signal_connect (priv->session, "on-ssrc-sdes", (GCallback) on_ssrc_sdes,
2063 g_signal_connect (priv->session, "on-ssrc-active",
2064 (GCallback) on_ssrc_active, stream);
2065 g_signal_connect (priv->session, "on-bye-ssrc", (GCallback) on_bye_ssrc,
2067 g_signal_connect (priv->session, "on-bye-timeout",
2068 (GCallback) on_bye_timeout, stream);
2069 g_signal_connect (priv->session, "on-timeout", (GCallback) on_timeout,
2072 for (i = 0; i < 2; i++) {
2073 GstPad *teepad, *queuepad;
2074 /* For the sender we create this bit of pipeline for both
2075 * RTP and RTCP. Sync and preroll are enabled on udpsink so
2076 * we need to add a queue before appsink to make the pipeline
2077 * not block. For the TCP case, we want to pump data to the
2078 * client as fast as possible anyway.
2080 * .--------. .-----. .---------.
2081 * | rtpbin | | tee | | udpsink |
2082 * | send->sink src->sink |
2083 * '--------' | | '---------'
2084 * | | .---------. .---------.
2085 * | | | queue | | appsink |
2086 * | src->sink src->sink |
2087 * '-----' '---------' '---------'
2089 * When only UDP is allowed, we skip the tee, queue and appsink and link the
2090 * udpsink directly to the session.
2093 gst_bin_add (bin, priv->udpsink[i]);
2094 sinkpad = gst_element_get_static_pad (priv->udpsink[i], "sink");
2096 if (priv->protocols & GST_RTSP_LOWER_TRANS_TCP) {
2097 /* make tee for RTP/RTCP */
2098 priv->tee[i] = gst_element_factory_make ("tee", NULL);
2099 gst_bin_add (bin, priv->tee[i]);
2101 /* and link to rtpbin send pad */
2102 pad = gst_element_get_static_pad (priv->tee[i], "sink");
2103 gst_pad_link (priv->send_src[i], pad);
2104 gst_object_unref (pad);
2106 /* link tee to udpsink */
2107 teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
2108 gst_pad_link (teepad, sinkpad);
2109 gst_object_unref (teepad);
2112 priv->appqueue[i] = gst_element_factory_make ("queue", NULL);
2113 gst_bin_add (bin, priv->appqueue[i]);
2114 /* and link to tee */
2115 teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
2116 pad = gst_element_get_static_pad (priv->appqueue[i], "sink");
2117 gst_pad_link (teepad, pad);
2118 gst_object_unref (pad);
2119 gst_object_unref (teepad);
2122 priv->appsink[i] = gst_element_factory_make ("appsink", NULL);
2123 g_object_set (priv->appsink[i], "async", FALSE, "sync", FALSE, NULL);
2124 g_object_set (priv->appsink[i], "emit-signals", FALSE, NULL);
2125 gst_bin_add (bin, priv->appsink[i]);
2126 gst_app_sink_set_callbacks (GST_APP_SINK_CAST (priv->appsink[i]),
2127 &sink_cb, stream, NULL);
2128 /* and link to queue */
2129 queuepad = gst_element_get_static_pad (priv->appqueue[i], "src");
2130 pad = gst_element_get_static_pad (priv->appsink[i], "sink");
2131 gst_pad_link (queuepad, pad);
2132 gst_object_unref (pad);
2133 gst_object_unref (queuepad);
2135 /* else only udpsink needed, link it to the session */
2136 gst_pad_link (priv->send_src[i], sinkpad);
2138 gst_object_unref (sinkpad);
2140 /* For the receiver we create this bit of pipeline for both
2141 * RTP and RTCP. We receive RTP/RTCP on appsrc and udpsrc
2142 * and it is all funneled into the rtpbin receive pad.
2144 * .--------. .--------. .--------.
2145 * | udpsrc | | funnel | | rtpbin |
2146 * | src->sink src->sink |
2147 * '--------' | | '--------'
2151 * '--------' '--------'
2153 /* make funnel for the RTP/RTCP receivers */
2154 priv->funnel[i] = gst_element_factory_make ("funnel", NULL);
2155 gst_bin_add (bin, priv->funnel[i]);
2157 pad = gst_element_get_static_pad (priv->funnel[i], "src");
2158 gst_pad_link (pad, priv->recv_sink[i]);
2159 gst_object_unref (pad);
2161 if (priv->udpsrc_v4[i]) {
2163 /* we set and keep these to playing so that they don't cause NO_PREROLL return
2164 * values. This is only relevant for PLAY pipelines */
2165 gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_PLAYING);
2166 gst_element_set_locked_state (priv->udpsrc_v4[i], TRUE);
2169 gst_bin_add (bin, priv->udpsrc_v4[i]);
2171 /* and link to the funnel v4 */
2172 selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
2173 pad = gst_element_get_static_pad (priv->udpsrc_v4[i], "src");
2174 gst_pad_link (pad, selpad);
2175 gst_object_unref (pad);
2176 gst_object_unref (selpad);
2179 if (priv->udpsrc_v6[i]) {
2181 gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_PLAYING);
2182 gst_element_set_locked_state (priv->udpsrc_v6[i], TRUE);
2184 gst_bin_add (bin, priv->udpsrc_v6[i]);
2186 /* and link to the funnel v6 */
2187 selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
2188 pad = gst_element_get_static_pad (priv->udpsrc_v6[i], "src");
2189 gst_pad_link (pad, selpad);
2190 gst_object_unref (pad);
2191 gst_object_unref (selpad);
2194 if (priv->protocols & GST_RTSP_LOWER_TRANS_TCP) {
2195 /* make and add appsrc */
2196 priv->appsrc[i] = gst_element_factory_make ("appsrc", NULL);
2197 priv->appsrc_base_time[i] = -1;
2198 g_object_set (priv->appsrc[i], "format", GST_FORMAT_TIME, NULL);
2199 gst_bin_add (bin, priv->appsrc[i]);
2200 /* and link to the funnel */
2201 selpad = gst_element_get_request_pad (priv->funnel[i], "sink_%u");
2202 pad = gst_element_get_static_pad (priv->appsrc[i], "src");
2203 gst_pad_link (pad, selpad);
2204 gst_object_unref (pad);
2205 gst_object_unref (selpad);
2208 /* check if we need to set to a special state */
2209 if (state != GST_STATE_NULL) {
2210 if (priv->udpsink[i])
2211 gst_element_set_state (priv->udpsink[i], state);
2212 if (priv->appsink[i])
2213 gst_element_set_state (priv->appsink[i], state);
2214 if (priv->appqueue[i])
2215 gst_element_set_state (priv->appqueue[i], state);
2217 gst_element_set_state (priv->tee[i], state);
2218 if (priv->funnel[i])
2219 gst_element_set_state (priv->funnel[i], state);
2220 if (priv->appsrc[i])
2221 gst_element_set_state (priv->appsrc[i], state);
2225 /* be notified of caps changes */
2226 priv->caps_sig = g_signal_connect (priv->send_src[0], "notify::caps",
2227 (GCallback) caps_notify, stream);
2229 priv->is_joined = TRUE;
2230 g_mutex_unlock (&priv->lock);
2237 g_mutex_unlock (&priv->lock);
2242 g_mutex_unlock (&priv->lock);
2243 GST_WARNING ("failed to allocate ports %u", idx);
2248 GST_WARNING ("failed to link stream %u", idx);
2249 gst_object_unref (priv->send_rtp_sink);
2250 priv->send_rtp_sink = NULL;
2251 g_mutex_unlock (&priv->lock);
2257 * gst_rtsp_stream_leave_bin:
2258 * @stream: a #GstRTSPStream
2259 * @bin: (transfer none): a #GstBin
2260 * @rtpbin: (transfer none): a rtpbin #GstElement
2262 * Remove the elements of @stream from @bin.
2264 * Return: %TRUE on success.
2267 gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
2268 GstElement * rtpbin)
2270 GstRTSPStreamPrivate *priv;
2274 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
2275 g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
2276 g_return_val_if_fail (GST_IS_ELEMENT (rtpbin), FALSE);
2278 priv = stream->priv;
2280 g_mutex_lock (&priv->lock);
2281 if (!priv->is_joined)
2282 goto was_not_joined;
2284 /* all transports must be removed by now */
2285 if (priv->transports != NULL)
2286 goto transports_not_removed;
2288 clear_tr_cache (priv, TRUE);
2289 clear_tr_cache (priv, FALSE);
2291 GST_INFO ("stream %p leaving bin", stream);
2294 gst_pad_unlink (priv->srcpad, priv->send_rtp_sink);
2295 } else if (priv->recv_rtp_src) {
2296 gst_pad_unlink (priv->recv_rtp_src, priv->sinkpad);
2297 gst_object_unref (priv->recv_rtp_src);
2298 priv->recv_rtp_src = NULL;
2300 g_signal_handler_disconnect (priv->send_src[0], priv->caps_sig);
2301 gst_element_release_request_pad (rtpbin, priv->send_rtp_sink);
2302 gst_object_unref (priv->send_rtp_sink);
2303 priv->send_rtp_sink = NULL;
2305 for (i = 0; i < 2; i++) {
2306 if (priv->udpsink[i])
2307 gst_element_set_state (priv->udpsink[i], GST_STATE_NULL);
2308 if (priv->appsink[i])
2309 gst_element_set_state (priv->appsink[i], GST_STATE_NULL);
2310 if (priv->appqueue[i])
2311 gst_element_set_state (priv->appqueue[i], GST_STATE_NULL);
2313 gst_element_set_state (priv->tee[i], GST_STATE_NULL);
2314 if (priv->funnel[i])
2315 gst_element_set_state (priv->funnel[i], GST_STATE_NULL);
2316 if (priv->appsrc[i])
2317 gst_element_set_state (priv->appsrc[i], GST_STATE_NULL);
2318 if (priv->udpsrc_v4[i]) {
2319 /* and set udpsrc to NULL now before removing */
2320 gst_element_set_locked_state (priv->udpsrc_v4[i], FALSE);
2321 gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_NULL);
2322 /* removing them should also nicely release the request
2323 * pads when they finalize */
2324 gst_bin_remove (bin, priv->udpsrc_v4[i]);
2326 if (priv->udpsrc_v6[i]) {
2327 gst_element_set_locked_state (priv->udpsrc_v6[i], FALSE);
2328 gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_NULL);
2329 gst_bin_remove (bin, priv->udpsrc_v6[i]);
2332 for (l = priv->transport_sources; l; l = l->next) {
2333 GstRTSPMulticastTransportSource *s = l->data;
2338 gst_element_set_locked_state (s->udpsrc[i], FALSE);
2339 gst_element_set_state (s->udpsrc[i], GST_STATE_NULL);
2340 gst_bin_remove (bin, s->udpsrc[i]);
2343 if (priv->udpsink[i])
2344 gst_bin_remove (bin, priv->udpsink[i]);
2345 if (priv->appsrc[i])
2346 gst_bin_remove (bin, priv->appsrc[i]);
2347 if (priv->appsink[i])
2348 gst_bin_remove (bin, priv->appsink[i]);
2349 if (priv->appqueue[i])
2350 gst_bin_remove (bin, priv->appqueue[i]);
2352 gst_bin_remove (bin, priv->tee[i]);
2353 if (priv->funnel[i])
2354 gst_bin_remove (bin, priv->funnel[i]);
2356 gst_element_release_request_pad (rtpbin, priv->recv_sink[i]);
2357 gst_object_unref (priv->recv_sink[i]);
2358 priv->recv_sink[i] = NULL;
2360 priv->udpsrc_v4[i] = NULL;
2361 priv->udpsrc_v6[i] = NULL;
2362 priv->udpsink[i] = NULL;
2363 priv->appsrc[i] = NULL;
2364 priv->appsink[i] = NULL;
2365 priv->appqueue[i] = NULL;
2366 priv->tee[i] = NULL;
2367 priv->funnel[i] = NULL;
2370 for (l = priv->transport_sources; l; l = l->next) {
2371 GstRTSPMulticastTransportSource *s = l->data;
2372 g_slice_free (GstRTSPMulticastTransportSource, s);
2374 g_list_free (priv->transport_sources);
2375 priv->transport_sources = NULL;
2377 gst_object_unref (priv->send_src[0]);
2378 priv->send_src[0] = NULL;
2380 gst_element_release_request_pad (rtpbin, priv->send_src[1]);
2381 gst_object_unref (priv->send_src[1]);
2382 priv->send_src[1] = NULL;
2384 g_object_unref (priv->session);
2385 priv->session = NULL;
2387 gst_caps_unref (priv->caps);
2391 gst_object_unref (priv->srtpenc);
2393 gst_object_unref (priv->srtpdec);
2395 priv->is_joined = FALSE;
2396 g_mutex_unlock (&priv->lock);
2402 g_mutex_unlock (&priv->lock);
2405 transports_not_removed:
2407 GST_ERROR_OBJECT (stream, "can't leave bin (transports not removed)");
2408 g_mutex_unlock (&priv->lock);
2414 * gst_rtsp_stream_get_rtpinfo:
2415 * @stream: a #GstRTSPStream
2416 * @rtptime: (allow-none): result RTP timestamp
2417 * @seq: (allow-none): result RTP seqnum
2418 * @clock_rate: (allow-none): the clock rate
2419 * @running_time: (allow-none): result running-time
2421 * Retrieve the current rtptime, seq and running-time. This is used to
2422 * construct a RTPInfo reply header.
2424 * Returns: %TRUE when rtptime, seq and running-time could be determined.
2427 gst_rtsp_stream_get_rtpinfo (GstRTSPStream * stream,
2428 guint * rtptime, guint * seq, guint * clock_rate,
2429 GstClockTime * running_time)
2431 GstRTSPStreamPrivate *priv;
2432 GstStructure *stats;
2433 GObjectClass *payobjclass;
2435 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
2437 priv = stream->priv;
2439 payobjclass = G_OBJECT_GET_CLASS (priv->payloader);
2441 g_mutex_lock (&priv->lock);
2443 if (g_object_class_find_property (payobjclass, "stats")) {
2444 g_object_get (priv->payloader, "stats", &stats, NULL);
2449 gst_structure_get_uint (stats, "seqnum", seq);
2452 gst_structure_get_uint (stats, "timestamp", rtptime);
2455 gst_structure_get_clock_time (stats, "running-time", running_time);
2458 gst_structure_get_uint (stats, "clock-rate", clock_rate);
2459 if (*clock_rate == 0 && running_time)
2460 *running_time = GST_CLOCK_TIME_NONE;
2462 gst_structure_free (stats);
2464 if (!g_object_class_find_property (payobjclass, "seqnum") ||
2465 !g_object_class_find_property (payobjclass, "timestamp"))
2469 g_object_get (priv->payloader, "seqnum", seq, NULL);
2472 g_object_get (priv->payloader, "timestamp", rtptime, NULL);
2475 *running_time = GST_CLOCK_TIME_NONE;
2477 g_mutex_unlock (&priv->lock);
2484 GST_WARNING ("Could not get payloader stats");
2485 g_mutex_unlock (&priv->lock);
2491 * gst_rtsp_stream_get_caps:
2492 * @stream: a #GstRTSPStream
2494 * Retrieve the current caps of @stream.
2496 * Returns: (transfer full): the #GstCaps of @stream. use gst_caps_unref()
2500 gst_rtsp_stream_get_caps (GstRTSPStream * stream)
2502 GstRTSPStreamPrivate *priv;
2505 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
2507 priv = stream->priv;
2509 g_mutex_lock (&priv->lock);
2510 if ((result = priv->caps))
2511 gst_caps_ref (result);
2512 g_mutex_unlock (&priv->lock);
2518 * gst_rtsp_stream_recv_rtp:
2519 * @stream: a #GstRTSPStream
2520 * @buffer: (transfer full): a #GstBuffer
2522 * Handle an RTP buffer for the stream. This method is usually called when a
2523 * message has been received from a client using the TCP transport.
2525 * This function takes ownership of @buffer.
2527 * Returns: a GstFlowReturn.
2530 gst_rtsp_stream_recv_rtp (GstRTSPStream * stream, GstBuffer * buffer)
2532 GstRTSPStreamPrivate *priv;
2534 GstElement *element;
2536 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_FLOW_ERROR);
2537 priv = stream->priv;
2538 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
2539 g_return_val_if_fail (priv->is_joined, FALSE);
2541 g_mutex_lock (&priv->lock);
2542 if (priv->appsrc[0])
2543 element = gst_object_ref (priv->appsrc[0]);
2546 g_mutex_unlock (&priv->lock);
2549 if (priv->appsrc_base_time[0] == -1) {
2550 /* Take current running_time. This timestamp will be put on
2551 * the first buffer of each stream because we are a live source and so we
2552 * timestamp with the running_time. When we are dealing with TCP, we also
2553 * only timestamp the first buffer (using the DISCONT flag) because a server
2554 * typically bursts data, for which we don't want to compensate by speeding
2555 * up the media. The other timestamps will be interpollated from this one
2556 * using the RTP timestamps. */
2557 GST_OBJECT_LOCK (element);
2558 if (GST_ELEMENT_CLOCK (element)) {
2560 GstClockTime base_time;
2562 now = gst_clock_get_time (GST_ELEMENT_CLOCK (element));
2563 base_time = GST_ELEMENT_CAST (element)->base_time;
2565 priv->appsrc_base_time[0] = now - base_time;
2566 GST_BUFFER_TIMESTAMP (buffer) = priv->appsrc_base_time[0];
2567 GST_DEBUG ("stream %p: first buffer at time %" GST_TIME_FORMAT
2568 ", base %" GST_TIME_FORMAT, stream, GST_TIME_ARGS (now),
2569 GST_TIME_ARGS (base_time));
2571 GST_OBJECT_UNLOCK (element);
2574 ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
2575 gst_object_unref (element);
2583 * gst_rtsp_stream_recv_rtcp:
2584 * @stream: a #GstRTSPStream
2585 * @buffer: (transfer full): a #GstBuffer
2587 * Handle an RTCP buffer for the stream. This method is usually called when a
2588 * message has been received from a client using the TCP transport.
2590 * This function takes ownership of @buffer.
2592 * Returns: a GstFlowReturn.
2595 gst_rtsp_stream_recv_rtcp (GstRTSPStream * stream, GstBuffer * buffer)
2597 GstRTSPStreamPrivate *priv;
2599 GstElement *element;
2601 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_FLOW_ERROR);
2602 priv = stream->priv;
2603 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
2605 if (!priv->is_joined) {
2606 gst_buffer_unref (buffer);
2607 return GST_FLOW_NOT_LINKED;
2609 g_mutex_lock (&priv->lock);
2610 if (priv->appsrc[1])
2611 element = gst_object_ref (priv->appsrc[1]);
2614 g_mutex_unlock (&priv->lock);
2617 if (priv->appsrc_base_time[1] == -1) {
2618 /* Take current running_time. This timestamp will be put on
2619 * the first buffer of each stream because we are a live source and so we
2620 * timestamp with the running_time. When we are dealing with TCP, we also
2621 * only timestamp the first buffer (using the DISCONT flag) because a server
2622 * typically bursts data, for which we don't want to compensate by speeding
2623 * up the media. The other timestamps will be interpollated from this one
2624 * using the RTP timestamps. */
2625 GST_OBJECT_LOCK (element);
2626 if (GST_ELEMENT_CLOCK (element)) {
2628 GstClockTime base_time;
2630 now = gst_clock_get_time (GST_ELEMENT_CLOCK (element));
2631 base_time = GST_ELEMENT_CAST (element)->base_time;
2633 priv->appsrc_base_time[1] = now - base_time;
2634 GST_BUFFER_TIMESTAMP (buffer) = priv->appsrc_base_time[1];
2635 GST_DEBUG ("stream %p: first buffer at time %" GST_TIME_FORMAT
2636 ", base %" GST_TIME_FORMAT, stream, GST_TIME_ARGS (now),
2637 GST_TIME_ARGS (base_time));
2639 GST_OBJECT_UNLOCK (element);
2642 ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
2643 gst_object_unref (element);
2646 gst_buffer_unref (buffer);
2651 /* must be called with lock */
2653 update_transport (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
2656 GstRTSPStreamPrivate *priv = stream->priv;
2657 const GstRTSPTransport *tr;
2659 tr = gst_rtsp_stream_transport_get_transport (trans);
2661 switch (tr->lower_transport) {
2662 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
2664 GstRTSPMulticastTransportSource *source;
2667 bin = GST_BIN (gst_object_get_parent (GST_OBJECT (priv->funnel[0])));
2672 GstPad *selpad, *pad;
2674 source = g_slice_new0 (GstRTSPMulticastTransportSource);
2675 source->transport = trans;
2677 for (i = 0; i < 2; i++) {
2679 g_strdup_printf ("udp://%s:%d", tr->destination,
2680 (i == 0) ? tr->port.min : tr->port.max);
2682 gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
2686 /* we set and keep these to playing so that they don't cause NO_PREROLL return
2687 * values. This is only relevant for PLAY pipelines */
2688 gst_element_set_state (source->udpsrc[i], GST_STATE_PLAYING);
2689 gst_element_set_locked_state (source->udpsrc[i], TRUE);
2692 gst_bin_add (bin, source->udpsrc[i]);
2694 /* and link to the funnel v4 */
2695 source->selpad[i] = selpad =
2696 gst_element_get_request_pad (priv->funnel[i], "sink_%u");
2697 pad = gst_element_get_static_pad (source->udpsrc[i], "src");
2698 gst_pad_link (pad, selpad);
2699 gst_object_unref (pad);
2700 gst_object_unref (selpad);
2702 gst_object_unref (bin);
2704 priv->transport_sources =
2705 g_list_prepend (priv->transport_sources, source);
2709 for (l = priv->transport_sources; l; l = l->next) {
2712 if (source->transport == trans) {
2713 priv->transport_sources =
2714 g_list_delete_link (priv->transport_sources, l);
2722 for (i = 0; i < 2; i++) {
2723 /* Will automatically unlink everything */
2724 gst_bin_remove (bin,
2725 GST_ELEMENT (gst_object_ref (source->udpsrc[i])));
2727 gst_element_set_state (source->udpsrc[i], GST_STATE_NULL);
2728 gst_object_unref (source->udpsrc[i]);
2730 gst_element_release_request_pad (priv->funnel[i],
2734 g_slice_free (GstRTSPMulticastTransportSource, source);
2738 /* fall through for the generic case */
2740 case GST_RTSP_LOWER_TRANS_UDP:
2746 dest = tr->destination;
2747 if (tr->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
2752 min = tr->client_port.min;
2753 max = tr->client_port.max;
2758 GST_INFO ("setting ttl-mc %d", ttl);
2759 g_object_set (G_OBJECT (priv->udpsink[0]), "ttl-mc", ttl, NULL);
2760 g_object_set (G_OBJECT (priv->udpsink[1]), "ttl-mc", ttl, NULL);
2762 GST_INFO ("adding %s:%d-%d", dest, min, max);
2763 g_signal_emit_by_name (priv->udpsink[0], "add", dest, min, NULL);
2764 g_signal_emit_by_name (priv->udpsink[1], "add", dest, max, NULL);
2765 priv->transports = g_list_prepend (priv->transports, trans);
2767 GST_INFO ("removing %s:%d-%d", dest, min, max);
2768 g_signal_emit_by_name (priv->udpsink[0], "remove", dest, min, NULL);
2769 g_signal_emit_by_name (priv->udpsink[1], "remove", dest, max, NULL);
2770 priv->transports = g_list_remove (priv->transports, trans);
2772 priv->transports_cookie++;
2775 case GST_RTSP_LOWER_TRANS_TCP:
2777 GST_INFO ("adding TCP %s", tr->destination);
2778 priv->transports = g_list_prepend (priv->transports, trans);
2780 GST_INFO ("removing TCP %s", tr->destination);
2781 priv->transports = g_list_remove (priv->transports, trans);
2783 priv->transports_cookie++;
2786 goto unknown_transport;
2793 GST_INFO ("Unknown transport %d", tr->lower_transport);
2800 * gst_rtsp_stream_add_transport:
2801 * @stream: a #GstRTSPStream
2802 * @trans: (transfer none): a #GstRTSPStreamTransport
2804 * Add the transport in @trans to @stream. The media of @stream will
2805 * then also be send to the values configured in @trans.
2807 * @stream must be joined to a bin.
2809 * @trans must contain a valid #GstRTSPTransport.
2811 * Returns: %TRUE if @trans was added
2814 gst_rtsp_stream_add_transport (GstRTSPStream * stream,
2815 GstRTSPStreamTransport * trans)
2817 GstRTSPStreamPrivate *priv;
2820 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
2821 priv = stream->priv;
2822 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
2823 g_return_val_if_fail (priv->is_joined, FALSE);
2825 g_mutex_lock (&priv->lock);
2826 res = update_transport (stream, trans, TRUE);
2827 g_mutex_unlock (&priv->lock);
2833 * gst_rtsp_stream_remove_transport:
2834 * @stream: a #GstRTSPStream
2835 * @trans: (transfer none): a #GstRTSPStreamTransport
2837 * Remove the transport in @trans from @stream. The media of @stream will
2838 * not be sent to the values configured in @trans.
2840 * @stream must be joined to a bin.
2842 * @trans must contain a valid #GstRTSPTransport.
2844 * Returns: %TRUE if @trans was removed
2847 gst_rtsp_stream_remove_transport (GstRTSPStream * stream,
2848 GstRTSPStreamTransport * trans)
2850 GstRTSPStreamPrivate *priv;
2853 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
2854 priv = stream->priv;
2855 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
2856 g_return_val_if_fail (priv->is_joined, FALSE);
2858 g_mutex_lock (&priv->lock);
2859 res = update_transport (stream, trans, FALSE);
2860 g_mutex_unlock (&priv->lock);
2866 * gst_rtsp_stream_update_crypto:
2867 * @stream: a #GstRTSPStream
2869 * @crypto: (transfer none) (allow-none): a #GstCaps with crypto info
2871 * Update the new crypto information for @ssrc in @stream. If information
2872 * for @ssrc did not exist, it will be added. If information
2873 * for @ssrc existed, it will be replaced. If @crypto is %NULL, it will
2874 * be removed from @stream.
2876 * Returns: %TRUE if @crypto could be updated
2879 gst_rtsp_stream_update_crypto (GstRTSPStream * stream,
2880 guint ssrc, GstCaps * crypto)
2882 GstRTSPStreamPrivate *priv;
2884 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
2885 g_return_val_if_fail (crypto == NULL || GST_IS_CAPS (crypto), FALSE);
2887 priv = stream->priv;
2889 GST_DEBUG_OBJECT (stream, "update key for %08x", ssrc);
2891 g_mutex_lock (&priv->lock);
2893 g_hash_table_insert (priv->keys, GINT_TO_POINTER (ssrc),
2894 gst_caps_ref (crypto));
2896 g_hash_table_remove (priv->keys, GINT_TO_POINTER (ssrc));
2897 g_mutex_unlock (&priv->lock);
2903 * gst_rtsp_stream_get_rtp_socket:
2904 * @stream: a #GstRTSPStream
2905 * @family: the socket family
2907 * Get the RTP socket from @stream for a @family.
2909 * @stream must be joined to a bin.
2911 * Returns: (transfer full) (nullable): the RTP socket or %NULL if no
2912 * socket could be allocated for @family. Unref after usage
2915 gst_rtsp_stream_get_rtp_socket (GstRTSPStream * stream, GSocketFamily family)
2917 GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
2921 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
2922 g_return_val_if_fail (family == G_SOCKET_FAMILY_IPV4 ||
2923 family == G_SOCKET_FAMILY_IPV6, NULL);
2924 g_return_val_if_fail (priv->udpsink[0], NULL);
2926 if (family == G_SOCKET_FAMILY_IPV6)
2931 g_object_get (priv->udpsink[0], name, &socket, NULL);
2937 * gst_rtsp_stream_get_rtcp_socket:
2938 * @stream: a #GstRTSPStream
2939 * @family: the socket family
2941 * Get the RTCP socket from @stream for a @family.
2943 * @stream must be joined to a bin.
2945 * Returns: (transfer full) (nullable): the RTCP socket or %NULL if no
2946 * socket could be allocated for @family. Unref after usage
2949 gst_rtsp_stream_get_rtcp_socket (GstRTSPStream * stream, GSocketFamily family)
2951 GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
2955 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
2956 g_return_val_if_fail (family == G_SOCKET_FAMILY_IPV4 ||
2957 family == G_SOCKET_FAMILY_IPV6, NULL);
2958 g_return_val_if_fail (priv->udpsink[1], NULL);
2960 if (family == G_SOCKET_FAMILY_IPV6)
2965 g_object_get (priv->udpsink[1], name, &socket, NULL);
2971 * gst_rtsp_stream_set_seqnum:
2972 * @stream: a #GstRTSPStream
2973 * @seqnum: a new sequence number
2975 * Configure the sequence number in the payloader of @stream to @seqnum.
2978 gst_rtsp_stream_set_seqnum_offset (GstRTSPStream * stream, guint16 seqnum)
2980 GstRTSPStreamPrivate *priv;
2982 g_return_if_fail (GST_IS_RTSP_STREAM (stream));
2984 priv = stream->priv;
2986 g_object_set (G_OBJECT (priv->payloader), "seqnum-offset", seqnum, NULL);
2990 * gst_rtsp_stream_get_seqnum:
2991 * @stream: a #GstRTSPStream
2993 * Get the configured sequence number in the payloader of @stream.
2995 * Returns: the sequence number of the payloader.
2998 gst_rtsp_stream_get_current_seqnum (GstRTSPStream * stream)
3000 GstRTSPStreamPrivate *priv;
3003 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
3005 priv = stream->priv;
3007 g_object_get (G_OBJECT (priv->payloader), "seqnum", &seqnum, NULL);
3013 * gst_rtsp_stream_transport_filter:
3014 * @stream: a #GstRTSPStream
3015 * @func: (scope call) (allow-none): a callback
3016 * @user_data: (closure): user data passed to @func
3018 * Call @func for each transport managed by @stream. The result value of @func
3019 * determines what happens to the transport. @func will be called with @stream
3020 * locked so no further actions on @stream can be performed from @func.
3022 * If @func returns #GST_RTSP_FILTER_REMOVE, the transport will be removed from
3025 * If @func returns #GST_RTSP_FILTER_KEEP, the transport will remain in @stream.
3027 * If @func returns #GST_RTSP_FILTER_REF, the transport will remain in @stream but
3028 * will also be added with an additional ref to the result #GList of this
3031 * When @func is %NULL, #GST_RTSP_FILTER_REF will be assumed for each transport.
3033 * Returns: (element-type GstRTSPStreamTransport) (transfer full): a #GList with all
3034 * transports for which @func returned #GST_RTSP_FILTER_REF. After usage, each
3035 * element in the #GList should be unreffed before the list is freed.
3038 gst_rtsp_stream_transport_filter (GstRTSPStream * stream,
3039 GstRTSPStreamTransportFilterFunc func, gpointer user_data)
3041 GstRTSPStreamPrivate *priv;
3042 GList *result, *walk, *next;
3043 GHashTable *visited = NULL;
3046 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
3048 priv = stream->priv;
3052 visited = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL);
3054 g_mutex_lock (&priv->lock);
3056 cookie = priv->transports_cookie;
3057 for (walk = priv->transports; walk; walk = next) {
3058 GstRTSPStreamTransport *trans = walk->data;
3059 GstRTSPFilterResult res;
3062 next = g_list_next (walk);
3065 /* only visit each transport once */
3066 if (g_hash_table_contains (visited, trans))
3069 g_hash_table_add (visited, g_object_ref (trans));
3070 g_mutex_unlock (&priv->lock);
3072 res = func (stream, trans, user_data);
3074 g_mutex_lock (&priv->lock);
3076 res = GST_RTSP_FILTER_REF;
3078 changed = (cookie != priv->transports_cookie);
3081 case GST_RTSP_FILTER_REMOVE:
3082 update_transport (stream, trans, FALSE);
3084 case GST_RTSP_FILTER_REF:
3085 result = g_list_prepend (result, g_object_ref (trans));
3087 case GST_RTSP_FILTER_KEEP:
3094 g_mutex_unlock (&priv->lock);
3097 g_hash_table_unref (visited);
3102 static GstPadProbeReturn
3103 pad_blocking (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
3105 GstRTSPStreamPrivate *priv;
3106 GstRTSPStream *stream;
3109 priv = stream->priv;
3111 GST_DEBUG_OBJECT (pad, "now blocking");
3113 g_mutex_lock (&priv->lock);
3114 priv->blocking = TRUE;
3115 g_mutex_unlock (&priv->lock);
3117 gst_element_post_message (priv->payloader,
3118 gst_message_new_element (GST_OBJECT_CAST (priv->payloader),
3119 gst_structure_new_empty ("GstRTSPStreamBlocking")));
3121 return GST_PAD_PROBE_OK;
3125 * gst_rtsp_stream_set_blocked:
3126 * @stream: a #GstRTSPStream
3127 * @blocked: boolean indicating we should block or unblock
3129 * Blocks or unblocks the dataflow on @stream.
3131 * Returns: %TRUE on success
3134 gst_rtsp_stream_set_blocked (GstRTSPStream * stream, gboolean blocked)
3136 GstRTSPStreamPrivate *priv;
3138 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
3140 priv = stream->priv;
3142 g_mutex_lock (&priv->lock);
3144 priv->blocking = FALSE;
3145 if (priv->blocked_id == 0) {
3146 priv->blocked_id = gst_pad_add_probe (priv->srcpad,
3147 GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER |
3148 GST_PAD_PROBE_TYPE_BUFFER_LIST, pad_blocking,
3149 g_object_ref (stream), g_object_unref);
3152 if (priv->blocked_id != 0) {
3153 gst_pad_remove_probe (priv->srcpad, priv->blocked_id);
3154 priv->blocked_id = 0;
3155 priv->blocking = FALSE;
3158 g_mutex_unlock (&priv->lock);
3164 * gst_rtsp_stream_is_blocking:
3165 * @stream: a #GstRTSPStream
3167 * Check if @stream is blocking on a #GstBuffer.
3169 * Returns: %TRUE if @stream is blocking
3172 gst_rtsp_stream_is_blocking (GstRTSPStream * stream)
3174 GstRTSPStreamPrivate *priv;
3177 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
3179 priv = stream->priv;
3181 g_mutex_lock (&priv->lock);
3182 result = priv->blocking;
3183 g_mutex_unlock (&priv->lock);
3189 * gst_rtsp_stream_query_position:
3190 * @stream: a #GstRTSPStream
3192 * Query the position of the stream in %GST_FORMAT_TIME. This only considers
3193 * the RTP parts of the pipeline and not the RTCP parts.
3195 * Returns: %TRUE if the position could be queried
3198 gst_rtsp_stream_query_position (GstRTSPStream * stream, gint64 * position)
3200 GstRTSPStreamPrivate *priv;
3204 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
3206 priv = stream->priv;
3208 g_mutex_lock (&priv->lock);
3209 if ((sink = priv->udpsink[0]))
3210 gst_object_ref (sink);
3211 g_mutex_unlock (&priv->lock);
3216 ret = gst_element_query_position (sink, GST_FORMAT_TIME, position);
3217 gst_object_unref (sink);
3223 * gst_rtsp_stream_query_stop:
3224 * @stream: a #GstRTSPStream
3226 * Query the stop of the stream in %GST_FORMAT_TIME. This only considers
3227 * the RTP parts of the pipeline and not the RTCP parts.
3229 * Returns: %TRUE if the stop could be queried
3232 gst_rtsp_stream_query_stop (GstRTSPStream * stream, gint64 * stop)
3234 GstRTSPStreamPrivate *priv;
3239 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
3241 priv = stream->priv;
3243 g_mutex_lock (&priv->lock);
3244 if ((sink = priv->udpsink[0]))
3245 gst_object_ref (sink);
3246 g_mutex_unlock (&priv->lock);
3251 query = gst_query_new_segment (GST_FORMAT_TIME);
3252 if ((ret = gst_element_query (sink, query))) {
3255 gst_query_parse_segment (query, NULL, &format, NULL, stop);
3256 if (format != GST_FORMAT_TIME)
3259 gst_query_unref (query);
3260 gst_object_unref (sink);