2 * Copyright (C) <2005,2006> Wim Taymans <wim at fluendo dot com>
3 * <2006> Lutz Mueller <lutz at topfrose dot de>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 * Unless otherwise indicated, Source Code is licensed under MIT license.
22 * See further explanation attached in License Statement (distributed in the file
25 * Permission is hereby granted, free of charge, to any person obtaining a copy of
26 * this software and associated documentation files (the "Software"), to deal in
27 * the Software without restriction, including without limitation the rights to
28 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
29 * of the Software, and to permit persons to whom the Software is furnished to do
30 * so, subject to the following conditions:
32 * The above copyright notice and this permission notice shall be included in all
33 * copies or substantial portions of the Software.
35 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 * SECTION:element-rtspsrc
46 * Makes a connection to an RTSP server and read the data.
47 * rtspsrc strictly follows RFC 2326 and therefore does not (yet) support
48 * RealMedia/Quicktime/Microsoft extensions.
50 * RTSP supports transport over TCP or UDP in unicast or multicast mode. By
51 * default rtspsrc will negotiate a connection in the following order:
52 * UDP unicast/UDP multicast/TCP. The order cannot be changed but the allowed
53 * protocols can be controlled with the #GstRTSPSrc:protocols property.
55 * rtspsrc currently understands SDP as the format of the session description.
56 * For each stream listed in the SDP a new rtp_stream\%d pad will be created
57 * with caps derived from the SDP media description. This is a caps of mime type
58 * "application/x-rtp" that can be connected to any available RTP depayloader
61 * rtspsrc will internally instantiate an RTP session manager element
62 * that will handle the RTCP messages to and from the server, jitter removal,
63 * packet reordering along with providing a clock for the pipeline.
64 * This feature is implemented using the gstrtpbin element.
66 * rtspsrc acts like a live source and will therefore only generate data in the
70 * <title>Example launch line</title>
72 * gst-launch-1.0 rtspsrc location=rtsp://some.server/url ! fakesink
73 * ]| Establish a connection to an RTSP server and send the raw RTP packets to a
84 #endif /* HAVE_UNISTD_H */
90 #include <gst/net/gstnet.h>
91 #include <gst/sdp/gstsdpmessage.h>
92 #include <gst/sdp/gstmikey.h>
93 #include <gst/rtp/rtp.h>
95 #include "gst/gst-i18n-plugin.h"
97 #include "gstrtspsrc.h"
99 GST_DEBUG_CATEGORY_STATIC (rtspsrc_debug);
100 #define GST_CAT_DEFAULT (rtspsrc_debug)
102 static GstStaticPadTemplate rtptemplate = GST_STATIC_PAD_TEMPLATE ("stream_%u",
105 GST_STATIC_CAPS ("application/x-rtp; application/x-rdt"));
107 /* templates used internally */
108 static GstStaticPadTemplate anysrctemplate =
109 GST_STATIC_PAD_TEMPLATE ("internalsrc_%u",
112 GST_STATIC_CAPS_ANY);
114 static GstStaticPadTemplate anysinktemplate =
115 GST_STATIC_PAD_TEMPLATE ("internalsink_%u",
118 GST_STATIC_CAPS_ANY);
122 SIGNAL_HANDLE_REQUEST,
124 SIGNAL_SELECT_STREAM,
126 SIGNAL_REQUEST_RTCP_KEY,
130 enum _GstRtspSrcRtcpSyncMode
137 enum _GstRtspSrcBufferMode
146 #define GST_TYPE_RTSP_SRC_BUFFER_MODE (gst_rtsp_src_buffer_mode_get_type())
148 gst_rtsp_src_buffer_mode_get_type (void)
150 static GType buffer_mode_type = 0;
151 static const GEnumValue buffer_modes[] = {
152 {BUFFER_MODE_NONE, "Only use RTP timestamps", "none"},
153 {BUFFER_MODE_SLAVE, "Slave receiver to sender clock", "slave"},
154 {BUFFER_MODE_BUFFER, "Do low/high watermark buffering", "buffer"},
155 {BUFFER_MODE_AUTO, "Choose mode depending on stream live", "auto"},
156 {BUFFER_MODE_SYNCED, "Synchronized sender and receiver clocks", "synced"},
160 if (!buffer_mode_type) {
162 g_enum_register_static ("GstRTSPSrcBufferMode", buffer_modes);
164 return buffer_mode_type;
167 enum _GstRtspSrcNtpTimeSource
170 NTP_TIME_SOURCE_UNIX,
171 NTP_TIME_SOURCE_RUNNING_TIME,
172 NTP_TIME_SOURCE_CLOCK_TIME
175 #define GST_TYPE_RTSP_SRC_NTP_TIME_SOURCE (gst_rtsp_src_ntp_time_source_get_type())
177 gst_rtsp_src_ntp_time_source_get_type (void)
179 static GType ntp_time_source_type = 0;
180 static const GEnumValue ntp_time_source_values[] = {
181 {NTP_TIME_SOURCE_NTP, "NTP time based on realtime clock", "ntp"},
182 {NTP_TIME_SOURCE_UNIX, "UNIX time based on realtime clock", "unix"},
183 {NTP_TIME_SOURCE_RUNNING_TIME,
184 "Running time based on pipeline clock",
186 {NTP_TIME_SOURCE_CLOCK_TIME, "Pipeline clock time", "clock-time"},
190 if (!ntp_time_source_type) {
191 ntp_time_source_type =
192 g_enum_register_static ("GstRTSPSrcNtpTimeSource",
193 ntp_time_source_values);
195 return ntp_time_source_type;
198 #define DEFAULT_LOCATION NULL
199 #define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP
200 #define DEFAULT_DEBUG FALSE
201 #define DEFAULT_RETRY 20
202 #define DEFAULT_TIMEOUT 5000000
203 #define DEFAULT_UDP_BUFFER_SIZE 0x80000
204 #define DEFAULT_TCP_TIMEOUT 20000000
205 #define DEFAULT_LATENCY_MS 2000
206 #define DEFAULT_DROP_ON_LATENCY FALSE
207 #define DEFAULT_CONNECTION_SPEED 0
208 #define DEFAULT_NAT_METHOD GST_RTSP_NAT_DUMMY
209 #define DEFAULT_DO_RTCP TRUE
210 #define DEFAULT_DO_RTSP_KEEP_ALIVE TRUE
211 #define DEFAULT_PROXY NULL
212 #define DEFAULT_RTP_BLOCKSIZE 0
213 #define DEFAULT_USER_ID NULL
214 #define DEFAULT_USER_PW NULL
215 #define DEFAULT_BUFFER_MODE BUFFER_MODE_AUTO
216 #define DEFAULT_PORT_RANGE NULL
217 #define DEFAULT_SHORT_HEADER FALSE
218 #define DEFAULT_PROBATION 2
219 #define DEFAULT_UDP_RECONNECT TRUE
220 #define DEFAULT_MULTICAST_IFACE NULL
221 #define DEFAULT_NTP_SYNC FALSE
222 #define DEFAULT_USE_PIPELINE_CLOCK FALSE
223 #define DEFAULT_TLS_VALIDATION_FLAGS G_TLS_CERTIFICATE_VALIDATE_ALL
224 #define DEFAULT_TLS_DATABASE NULL
225 #define DEFAULT_TLS_INTERACTION NULL
226 #define DEFAULT_DO_RETRANSMISSION TRUE
227 #define DEFAULT_NTP_TIME_SOURCE NTP_TIME_SOURCE_NTP
228 #define DEFAULT_USER_AGENT "GStreamer/" PACKAGE_VERSION
229 #define DEFAULT_MAX_RTCP_RTP_TIME_DIFF 1000
241 PROP_DROP_ON_LATENCY,
242 PROP_CONNECTION_SPEED,
245 PROP_DO_RTSP_KEEP_ALIVE,
254 PROP_UDP_BUFFER_SIZE,
258 PROP_MULTICAST_IFACE,
260 PROP_USE_PIPELINE_CLOCK,
262 PROP_TLS_VALIDATION_FLAGS,
264 PROP_TLS_INTERACTION,
265 PROP_DO_RETRANSMISSION,
266 PROP_NTP_TIME_SOURCE,
268 PROP_MAX_RTCP_RTP_TIME_DIFF
271 #define GST_TYPE_RTSP_NAT_METHOD (gst_rtsp_nat_method_get_type())
273 gst_rtsp_nat_method_get_type (void)
275 static GType rtsp_nat_method_type = 0;
276 static const GEnumValue rtsp_nat_method[] = {
277 {GST_RTSP_NAT_NONE, "None", "none"},
278 {GST_RTSP_NAT_DUMMY, "Send Dummy packets", "dummy"},
282 if (!rtsp_nat_method_type) {
283 rtsp_nat_method_type =
284 g_enum_register_static ("GstRTSPNatMethod", rtsp_nat_method);
286 return rtsp_nat_method_type;
289 static void gst_rtspsrc_finalize (GObject * object);
291 static void gst_rtspsrc_set_property (GObject * object, guint prop_id,
292 const GValue * value, GParamSpec * pspec);
293 static void gst_rtspsrc_get_property (GObject * object, guint prop_id,
294 GValue * value, GParamSpec * pspec);
296 static GstClock *gst_rtspsrc_provide_clock (GstElement * element);
298 static void gst_rtspsrc_uri_handler_init (gpointer g_iface,
299 gpointer iface_data);
301 static gboolean gst_rtspsrc_set_proxy (GstRTSPSrc * rtsp, const gchar * proxy);
302 static void gst_rtspsrc_set_tcp_timeout (GstRTSPSrc * rtspsrc, guint64 timeout);
304 static GstStateChangeReturn gst_rtspsrc_change_state (GstElement * element,
305 GstStateChange transition);
306 static gboolean gst_rtspsrc_send_event (GstElement * element, GstEvent * event);
307 static void gst_rtspsrc_handle_message (GstBin * bin, GstMessage * message);
309 static gboolean gst_rtspsrc_setup_auth (GstRTSPSrc * src,
310 GstRTSPMessage * response);
312 static gboolean gst_rtspsrc_loop_send_cmd (GstRTSPSrc * src, gint cmd,
314 static GstRTSPResult gst_rtspsrc_send_cb (GstRTSPExtension * ext,
315 GstRTSPMessage * request, GstRTSPMessage * response, GstRTSPSrc * src);
317 static GstRTSPResult gst_rtspsrc_open (GstRTSPSrc * src, gboolean async);
318 static GstRTSPResult gst_rtspsrc_play (GstRTSPSrc * src, GstSegment * segment,
320 static GstRTSPResult gst_rtspsrc_pause (GstRTSPSrc * src, gboolean async);
321 static GstRTSPResult gst_rtspsrc_close (GstRTSPSrc * src, gboolean async,
322 gboolean only_close);
324 static gboolean gst_rtspsrc_uri_set_uri (GstURIHandler * handler,
325 const gchar * uri, GError ** error);
326 static gchar *gst_rtspsrc_uri_get_uri (GstURIHandler * handler);
328 static gboolean gst_rtspsrc_activate_streams (GstRTSPSrc * src);
329 static gboolean gst_rtspsrc_loop (GstRTSPSrc * src);
330 static gboolean gst_rtspsrc_stream_push_event (GstRTSPSrc * src,
331 GstRTSPStream * stream, GstEvent * event);
332 static gboolean gst_rtspsrc_push_event (GstRTSPSrc * src, GstEvent * event);
333 static void gst_rtspsrc_connection_flush (GstRTSPSrc * src, gboolean flush);
334 static GstRTSPResult gst_rtsp_conninfo_close (GstRTSPSrc * src,
335 GstRTSPConnInfo * info, gboolean free);
343 /* commands we send to out loop to notify it of events */
344 #define CMD_OPEN (1 << 0)
345 #define CMD_PLAY (1 << 1)
346 #define CMD_PAUSE (1 << 2)
347 #define CMD_CLOSE (1 << 3)
348 #define CMD_WAIT (1 << 4)
349 #define CMD_RECONNECT (1 << 5)
350 #define CMD_LOOP (1 << 6)
352 /* mask for all commands */
353 #define CMD_ALL ((CMD_LOOP << 1) - 1)
355 #define GST_ELEMENT_PROGRESS(el, type, code, text) \
357 gchar *__txt = _gst_element_error_printf text; \
358 gst_element_post_message (GST_ELEMENT_CAST (el), \
359 gst_message_new_progress (GST_OBJECT_CAST (el), \
360 GST_PROGRESS_TYPE_ ##type, code, __txt)); \
364 static guint gst_rtspsrc_signals[LAST_SIGNAL] = { 0 };
366 #define gst_rtspsrc_parent_class parent_class
367 G_DEFINE_TYPE_WITH_CODE (GstRTSPSrc, gst_rtspsrc, GST_TYPE_BIN,
368 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_rtspsrc_uri_handler_init));
370 #ifndef GST_DISABLE_GST_DEBUG
371 static inline const char *
372 cmd_to_string (guint cmd)
396 default_select_stream (GstRTSPSrc * src, guint id, GstCaps * caps)
398 GST_DEBUG_OBJECT (src, "default handler");
403 select_stream_accum (GSignalInvocationHint * ihint,
404 GValue * return_accu, const GValue * handler_return, gpointer data)
408 myboolean = g_value_get_boolean (handler_return);
409 GST_DEBUG ("accum %d", myboolean);
410 g_value_set_boolean (return_accu, myboolean);
412 /* stop emission if FALSE */
417 gst_rtspsrc_class_init (GstRTSPSrcClass * klass)
419 GObjectClass *gobject_class;
420 GstElementClass *gstelement_class;
421 GstBinClass *gstbin_class;
423 gobject_class = (GObjectClass *) klass;
424 gstelement_class = (GstElementClass *) klass;
425 gstbin_class = (GstBinClass *) klass;
427 GST_DEBUG_CATEGORY_INIT (rtspsrc_debug, "rtspsrc", 0, "RTSP src");
429 gobject_class->set_property = gst_rtspsrc_set_property;
430 gobject_class->get_property = gst_rtspsrc_get_property;
432 gobject_class->finalize = gst_rtspsrc_finalize;
434 g_object_class_install_property (gobject_class, PROP_LOCATION,
435 g_param_spec_string ("location", "RTSP Location",
436 "Location of the RTSP url to read",
437 DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
439 g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
440 g_param_spec_flags ("protocols", "Protocols",
441 "Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
442 DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
444 g_object_class_install_property (gobject_class, PROP_DEBUG,
445 g_param_spec_boolean ("debug", "Debug",
446 "Dump request and response messages to stdout",
447 DEFAULT_DEBUG, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
449 g_object_class_install_property (gobject_class, PROP_RETRY,
450 g_param_spec_uint ("retry", "Retry",
451 "Max number of retries when allocating RTP ports.",
452 0, G_MAXUINT16, DEFAULT_RETRY,
453 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
455 g_object_class_install_property (gobject_class, PROP_TIMEOUT,
456 g_param_spec_uint64 ("timeout", "Timeout",
457 "Retry TCP transport after UDP timeout microseconds (0 = disabled)",
458 0, G_MAXUINT64, DEFAULT_TIMEOUT,
459 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
461 g_object_class_install_property (gobject_class, PROP_TCP_TIMEOUT,
462 g_param_spec_uint64 ("tcp-timeout", "TCP Timeout",
463 "Fail after timeout microseconds on TCP connections (0 = disabled)",
464 0, G_MAXUINT64, DEFAULT_TCP_TIMEOUT,
465 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
467 g_object_class_install_property (gobject_class, PROP_LATENCY,
468 g_param_spec_uint ("latency", "Buffer latency in ms",
469 "Amount of ms to buffer", 0, G_MAXUINT, DEFAULT_LATENCY_MS,
470 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
472 g_object_class_install_property (gobject_class, PROP_DROP_ON_LATENCY,
473 g_param_spec_boolean ("drop-on-latency",
474 "Drop buffers when maximum latency is reached",
475 "Tells the jitterbuffer to never exceed the given latency in size",
476 DEFAULT_DROP_ON_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
478 g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
479 g_param_spec_uint64 ("connection-speed", "Connection Speed",
480 "Network connection speed in kbps (0 = unknown)",
481 0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
482 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
484 g_object_class_install_property (gobject_class, PROP_NAT_METHOD,
485 g_param_spec_enum ("nat-method", "NAT Method",
486 "Method to use for traversing firewalls and NAT",
487 GST_TYPE_RTSP_NAT_METHOD, DEFAULT_NAT_METHOD,
488 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
491 * GstRTSPSrc:do-rtcp:
493 * Enable RTCP support. Some old server don't like RTCP and then this property
494 * needs to be set to FALSE.
496 g_object_class_install_property (gobject_class, PROP_DO_RTCP,
497 g_param_spec_boolean ("do-rtcp", "Do RTCP",
498 "Send RTCP packets, disable for old incompatible server.",
499 DEFAULT_DO_RTCP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
502 * GstRTSPSrc:do-rtsp-keep-alive:
504 * Enable RTSP keep alive support. Some old server don't like RTSP
505 * keep alive and then this property needs to be set to FALSE.
507 g_object_class_install_property (gobject_class, PROP_DO_RTSP_KEEP_ALIVE,
508 g_param_spec_boolean ("do-rtsp-keep-alive", "Do RTSP Keep Alive",
509 "Send RTSP keep alive packets, disable for old incompatible server.",
510 DEFAULT_DO_RTSP_KEEP_ALIVE,
511 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
516 * Set the proxy parameters. This has to be a string of the format
517 * [http://][user:passwd@]host[:port].
519 g_object_class_install_property (gobject_class, PROP_PROXY,
520 g_param_spec_string ("proxy", "Proxy",
521 "Proxy settings for HTTP tunneling. Format: [http://][user:passwd@]host[:port]",
522 DEFAULT_PROXY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
524 * GstRTSPSrc:proxy-id:
526 * Sets the proxy URI user id for authentication. If the URI set via the
527 * "proxy" property contains a user-id already, that will take precedence.
531 g_object_class_install_property (gobject_class, PROP_PROXY_ID,
532 g_param_spec_string ("proxy-id", "proxy-id",
533 "HTTP proxy URI user id for authentication", "",
534 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
536 * GstRTSPSrc:proxy-pw:
538 * Sets the proxy URI password for authentication. If the URI set via the
539 * "proxy" property contains a password already, that will take precedence.
543 g_object_class_install_property (gobject_class, PROP_PROXY_PW,
544 g_param_spec_string ("proxy-pw", "proxy-pw",
545 "HTTP proxy URI user password for authentication", "",
546 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
549 * GstRTSPSrc:rtp-blocksize:
551 * RTP package size to suggest to server.
553 g_object_class_install_property (gobject_class, PROP_RTP_BLOCKSIZE,
554 g_param_spec_uint ("rtp-blocksize", "RTP Blocksize",
555 "RTP package size to suggest to server (0 = disabled)",
556 0, 65536, DEFAULT_RTP_BLOCKSIZE,
557 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
559 g_object_class_install_property (gobject_class,
561 g_param_spec_string ("user-id", "user-id",
562 "RTSP location URI user id for authentication", DEFAULT_USER_ID,
563 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
564 g_object_class_install_property (gobject_class, PROP_USER_PW,
565 g_param_spec_string ("user-pw", "user-pw",
566 "RTSP location URI user password for authentication", DEFAULT_USER_PW,
567 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
570 * GstRTSPSrc:buffer-mode:
572 * Control the buffering and timestamping mode used by the jitterbuffer.
574 g_object_class_install_property (gobject_class, PROP_BUFFER_MODE,
575 g_param_spec_enum ("buffer-mode", "Buffer Mode",
576 "Control the buffering algorithm in use",
577 GST_TYPE_RTSP_SRC_BUFFER_MODE, DEFAULT_BUFFER_MODE,
578 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
581 * GstRTSPSrc:port-range:
583 * Configure the client port numbers that can be used to recieve RTP and
586 g_object_class_install_property (gobject_class, PROP_PORT_RANGE,
587 g_param_spec_string ("port-range", "Port range",
588 "Client port range that can be used to receive RTP and RTCP data, "
589 "eg. 3000-3005 (NULL = no restrictions)", DEFAULT_PORT_RANGE,
590 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
593 * GstRTSPSrc:udp-buffer-size:
595 * Size of the kernel UDP receive buffer in bytes.
597 g_object_class_install_property (gobject_class, PROP_UDP_BUFFER_SIZE,
598 g_param_spec_int ("udp-buffer-size", "UDP Buffer Size",
599 "Size of the kernel UDP receive buffer in bytes, 0=default",
600 0, G_MAXINT, DEFAULT_UDP_BUFFER_SIZE,
601 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
604 * GstRTSPSrc:short-header:
606 * Only send the basic RTSP headers for broken encoders.
608 g_object_class_install_property (gobject_class, PROP_SHORT_HEADER,
609 g_param_spec_boolean ("short-header", "Short Header",
610 "Only send the basic RTSP headers for broken encoders",
611 DEFAULT_SHORT_HEADER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
613 g_object_class_install_property (gobject_class, PROP_PROBATION,
614 g_param_spec_uint ("probation", "Number of probations",
615 "Consecutive packet sequence numbers to accept the source",
616 0, G_MAXUINT, DEFAULT_PROBATION,
617 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
619 g_object_class_install_property (gobject_class, PROP_UDP_RECONNECT,
620 g_param_spec_boolean ("udp-reconnect", "Reconnect to the server",
621 "Reconnect to the server if RTSP connection is closed when doing UDP",
622 DEFAULT_UDP_RECONNECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
624 g_object_class_install_property (gobject_class, PROP_MULTICAST_IFACE,
625 g_param_spec_string ("multicast-iface", "Multicast Interface",
626 "The network interface on which to join the multicast group",
627 DEFAULT_MULTICAST_IFACE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
629 g_object_class_install_property (gobject_class, PROP_NTP_SYNC,
630 g_param_spec_boolean ("ntp-sync", "Sync on NTP clock",
631 "Synchronize received streams to the NTP clock", DEFAULT_NTP_SYNC,
632 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
634 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
635 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
636 "Use the pipeline running-time to set the NTP time in the RTCP SR messages"
637 "(DEPRECATED: Use ntp-time-source property)",
638 DEFAULT_USE_PIPELINE_CLOCK,
639 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
641 g_object_class_install_property (gobject_class, PROP_SDES,
642 g_param_spec_boxed ("sdes", "SDES",
643 "The SDES items of this session",
644 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
647 * GstRTSPSrc::tls-validation-flags:
649 * TLS certificate validation flags used to validate server
654 g_object_class_install_property (gobject_class, PROP_TLS_VALIDATION_FLAGS,
655 g_param_spec_flags ("tls-validation-flags", "TLS validation flags",
656 "TLS certificate validation flags used to validate the server certificate",
657 G_TYPE_TLS_CERTIFICATE_FLAGS, DEFAULT_TLS_VALIDATION_FLAGS,
658 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
661 * GstRTSPSrc::tls-database:
663 * TLS database with anchor certificate authorities used to validate
664 * the server certificate.
668 g_object_class_install_property (gobject_class, PROP_TLS_DATABASE,
669 g_param_spec_object ("tls-database", "TLS database",
670 "TLS database with anchor certificate authorities used to validate the server certificate",
671 G_TYPE_TLS_DATABASE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
674 * GstRTSPSrc::tls-interaction:
676 * A #GTlsInteraction object to be used when the connection or certificate
677 * database need to interact with the user. This will be used to prompt the
678 * user for passwords where necessary.
682 g_object_class_install_property (gobject_class, PROP_TLS_INTERACTION,
683 g_param_spec_object ("tls-interaction", "TLS interaction",
684 "A GTlsInteraction object to promt the user for password or certificate",
685 G_TYPE_TLS_INTERACTION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
688 * GstRTSPSrc::do-retransmission:
690 * Attempt to ask the server to retransmit lost packets according to RFC4588.
692 * Note: currently only works with SSRC-multiplexed retransmission streams
696 g_object_class_install_property (gobject_class, PROP_DO_RETRANSMISSION,
697 g_param_spec_boolean ("do-retransmission", "Retransmission",
698 "Ask the server to retransmit lost packets",
699 DEFAULT_DO_RETRANSMISSION,
700 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
703 * GstRTSPSrc::ntp-time-source:
705 * allows to select the time source that should be used
706 * for the NTP time in RTCP packets
710 g_object_class_install_property (gobject_class, PROP_NTP_TIME_SOURCE,
711 g_param_spec_enum ("ntp-time-source", "NTP Time Source",
712 "NTP time source for RTCP packets",
713 GST_TYPE_RTSP_SRC_NTP_TIME_SOURCE, DEFAULT_NTP_TIME_SOURCE,
714 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
717 * GstRTSPSrc::user-agent:
719 * The string to set in the User-Agent header.
723 g_object_class_install_property (gobject_class, PROP_USER_AGENT,
724 g_param_spec_string ("user-agent", "User Agent",
725 "The User-Agent string to send to the server",
726 DEFAULT_USER_AGENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
728 g_object_class_install_property (gobject_class, PROP_MAX_RTCP_RTP_TIME_DIFF,
729 g_param_spec_int ("max-rtcp-rtp-time-diff", "Max RTCP RTP Time Diff",
730 "Maximum amount of time in ms that the RTP time in RTCP SRs "
731 "is allowed to be ahead (-1 disabled)", -1, G_MAXINT,
732 DEFAULT_MAX_RTCP_RTP_TIME_DIFF,
733 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
736 * GstRTSPSrc::handle-request:
737 * @rtspsrc: a #GstRTSPSrc
738 * @request: a #GstRTSPMessage
739 * @response: a #GstRTSPMessage
741 * Handle a server request in @request and prepare @response.
743 * This signal is called from the streaming thread, you should therefore not
744 * do any state changes on @rtspsrc because this might deadlock. If you want
745 * to modify the state as a result of this signal, post a
746 * #GST_MESSAGE_REQUEST_STATE message on the bus or signal the main thread
751 gst_rtspsrc_signals[SIGNAL_HANDLE_REQUEST] =
752 g_signal_new ("handle-request", G_TYPE_FROM_CLASS (klass), 0,
753 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2,
754 G_TYPE_POINTER, G_TYPE_POINTER);
757 * GstRTSPSrc::on-sdp:
758 * @rtspsrc: a #GstRTSPSrc
759 * @sdp: a #GstSDPMessage
761 * Emited when the client has retrieved the SDP and before it configures the
762 * streams in the SDP. @sdp can be inspected and modified.
764 * This signal is called from the streaming thread, you should therefore not
765 * do any state changes on @rtspsrc because this might deadlock. If you want
766 * to modify the state as a result of this signal, post a
767 * #GST_MESSAGE_REQUEST_STATE message on the bus or signal the main thread
772 gst_rtspsrc_signals[SIGNAL_ON_SDP] =
773 g_signal_new ("on-sdp", G_TYPE_FROM_CLASS (klass), 0,
774 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
775 GST_TYPE_SDP_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE);
778 * GstRTSPSrc::select-stream:
779 * @rtspsrc: a #GstRTSPSrc
780 * @num: the stream number
781 * @caps: the stream caps
783 * Emited before the client decides to configure the stream @num with
786 * Returns: %TRUE when the stream should be selected, %FALSE when the stream
791 gst_rtspsrc_signals[SIGNAL_SELECT_STREAM] =
792 g_signal_new_class_handler ("select-stream", G_TYPE_FROM_CLASS (klass),
793 G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_CLEANUP,
794 (GCallback) default_select_stream, select_stream_accum, NULL,
795 g_cclosure_marshal_generic, G_TYPE_BOOLEAN, 2, G_TYPE_UINT,
798 * GstRTSPSrc::new-manager:
799 * @rtspsrc: a #GstRTSPSrc
800 * @manager: a #GstElement
802 * Emited after a new manager (like rtpbin) was created and the default
803 * properties were configured.
807 gst_rtspsrc_signals[SIGNAL_NEW_MANAGER] =
808 g_signal_new_class_handler ("new-manager", G_TYPE_FROM_CLASS (klass),
809 G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_CLEANUP, 0, NULL, NULL,
810 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
813 * GstRTSPSrc::request-rtcp-key:
814 * @rtspsrc: a #GstRTSPSrc
815 * @num: the stream number
817 * Signal emited to get the crypto parameters relevant to the RTCP
818 * stream. User should provide the key and the RTCP encryption ciphers
819 * and authentication, and return them wrapped in a GstCaps.
823 gst_rtspsrc_signals[SIGNAL_REQUEST_RTCP_KEY] =
824 g_signal_new ("request-rtcp-key", G_TYPE_FROM_CLASS (klass),
825 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, GST_TYPE_CAPS, 1, G_TYPE_UINT);
827 gstelement_class->send_event = gst_rtspsrc_send_event;
828 gstelement_class->provide_clock = gst_rtspsrc_provide_clock;
829 gstelement_class->change_state = gst_rtspsrc_change_state;
831 gst_element_class_add_static_pad_template (gstelement_class, &rtptemplate);
833 gst_element_class_set_static_metadata (gstelement_class,
834 "RTSP packet receiver", "Source/Network",
835 "Receive data over the network via RTSP (RFC 2326)",
836 "Wim Taymans <wim@fluendo.com>, "
837 "Thijs Vermeir <thijs.vermeir@barco.com>, "
838 "Lutz Mueller <lutz@topfrose.de>");
840 gstbin_class->handle_message = gst_rtspsrc_handle_message;
842 gst_rtsp_ext_list_init ();
846 gst_rtspsrc_init (GstRTSPSrc * src)
848 src->conninfo.location = g_strdup (DEFAULT_LOCATION);
849 src->protocols = DEFAULT_PROTOCOLS;
850 src->debug = DEFAULT_DEBUG;
851 src->retry = DEFAULT_RETRY;
852 src->udp_timeout = DEFAULT_TIMEOUT;
853 gst_rtspsrc_set_tcp_timeout (src, DEFAULT_TCP_TIMEOUT);
854 src->latency = DEFAULT_LATENCY_MS;
855 src->drop_on_latency = DEFAULT_DROP_ON_LATENCY;
856 src->connection_speed = DEFAULT_CONNECTION_SPEED;
857 src->nat_method = DEFAULT_NAT_METHOD;
858 src->do_rtcp = DEFAULT_DO_RTCP;
859 src->do_rtsp_keep_alive = DEFAULT_DO_RTSP_KEEP_ALIVE;
860 gst_rtspsrc_set_proxy (src, DEFAULT_PROXY);
861 src->rtp_blocksize = DEFAULT_RTP_BLOCKSIZE;
862 src->user_id = g_strdup (DEFAULT_USER_ID);
863 src->user_pw = g_strdup (DEFAULT_USER_PW);
864 src->buffer_mode = DEFAULT_BUFFER_MODE;
865 src->client_port_range.min = 0;
866 src->client_port_range.max = 0;
867 src->udp_buffer_size = DEFAULT_UDP_BUFFER_SIZE;
868 src->short_header = DEFAULT_SHORT_HEADER;
869 src->probation = DEFAULT_PROBATION;
870 src->udp_reconnect = DEFAULT_UDP_RECONNECT;
871 src->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
872 src->ntp_sync = DEFAULT_NTP_SYNC;
873 src->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
875 src->tls_validation_flags = DEFAULT_TLS_VALIDATION_FLAGS;
876 src->tls_database = DEFAULT_TLS_DATABASE;
877 src->tls_interaction = DEFAULT_TLS_INTERACTION;
878 src->do_retransmission = DEFAULT_DO_RETRANSMISSION;
879 src->ntp_time_source = DEFAULT_NTP_TIME_SOURCE;
880 src->user_agent = g_strdup (DEFAULT_USER_AGENT);
881 src->max_rtcp_rtp_time_diff = DEFAULT_MAX_RTCP_RTP_TIME_DIFF;
883 /* get a list of all extensions */
884 src->extensions = gst_rtsp_ext_list_get ();
886 /* connect to send signal */
887 gst_rtsp_ext_list_connect (src->extensions, "send",
888 (GCallback) gst_rtspsrc_send_cb, src);
890 /* protects the streaming thread in interleaved mode or the polling
891 * thread in UDP mode. */
892 g_rec_mutex_init (&src->stream_rec_lock);
894 /* protects our state changes from multiple invocations */
895 g_rec_mutex_init (&src->state_rec_lock);
897 src->state = GST_RTSP_STATE_INVALID;
899 GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_SOURCE);
903 gst_rtspsrc_finalize (GObject * object)
907 rtspsrc = GST_RTSPSRC (object);
909 gst_rtsp_ext_list_free (rtspsrc->extensions);
910 g_free (rtspsrc->conninfo.location);
911 gst_rtsp_url_free (rtspsrc->conninfo.url);
912 g_free (rtspsrc->conninfo.url_str);
913 g_free (rtspsrc->user_id);
914 g_free (rtspsrc->user_pw);
915 g_free (rtspsrc->multi_iface);
916 g_free (rtspsrc->user_agent);
919 gst_sdp_message_free (rtspsrc->sdp);
922 if (rtspsrc->provided_clock)
923 gst_object_unref (rtspsrc->provided_clock);
926 gst_structure_free (rtspsrc->sdes);
928 if (rtspsrc->tls_database)
929 g_object_unref (rtspsrc->tls_database);
931 if (rtspsrc->tls_interaction)
932 g_object_unref (rtspsrc->tls_interaction);
935 g_rec_mutex_clear (&rtspsrc->stream_rec_lock);
936 g_rec_mutex_clear (&rtspsrc->state_rec_lock);
938 G_OBJECT_CLASS (parent_class)->finalize (object);
942 gst_rtspsrc_provide_clock (GstElement * element)
944 GstRTSPSrc *src = GST_RTSPSRC (element);
947 if ((clock = src->provided_clock) != NULL)
948 gst_object_ref (clock);
953 /* a proxy string of the format [user:passwd@]host[:port] */
955 gst_rtspsrc_set_proxy (GstRTSPSrc * rtsp, const gchar * proxy)
959 g_free (rtsp->proxy_user);
960 rtsp->proxy_user = NULL;
961 g_free (rtsp->proxy_passwd);
962 rtsp->proxy_passwd = NULL;
963 g_free (rtsp->proxy_host);
964 rtsp->proxy_host = NULL;
965 rtsp->proxy_port = 0;
972 /* we allow http:// in front but ignore it */
973 if (g_str_has_prefix (p, "http://"))
976 at = strchr (p, '@');
978 /* look for user:passwd */
979 col = strchr (proxy, ':');
980 if (col == NULL || col > at)
983 rtsp->proxy_user = g_strndup (p, col - p);
985 rtsp->proxy_passwd = g_strndup (col, at - col);
990 if (rtsp->prop_proxy_id != NULL && *rtsp->prop_proxy_id != '\0')
991 rtsp->proxy_user = g_strdup (rtsp->prop_proxy_id);
992 if (rtsp->prop_proxy_pw != NULL && *rtsp->prop_proxy_pw != '\0')
993 rtsp->proxy_passwd = g_strdup (rtsp->prop_proxy_pw);
994 if (rtsp->proxy_user != NULL || rtsp->proxy_passwd != NULL) {
995 GST_LOG_OBJECT (rtsp, "set proxy user/pw from properties: %s:%s",
996 GST_STR_NULL (rtsp->proxy_user), GST_STR_NULL (rtsp->proxy_passwd));
999 col = strchr (p, ':');
1002 /* everything before the colon is the hostname */
1003 rtsp->proxy_host = g_strndup (p, col - p);
1005 rtsp->proxy_port = strtoul (p, (char **) &p, 10);
1007 rtsp->proxy_host = g_strdup (p);
1008 rtsp->proxy_port = 8080;
1014 gst_rtspsrc_set_tcp_timeout (GstRTSPSrc * rtspsrc, guint64 timeout)
1016 rtspsrc->tcp_timeout.tv_sec = timeout / G_USEC_PER_SEC;
1017 rtspsrc->tcp_timeout.tv_usec = timeout % G_USEC_PER_SEC;
1020 rtspsrc->ptcp_timeout = &rtspsrc->tcp_timeout;
1022 rtspsrc->ptcp_timeout = NULL;
1026 gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value,
1029 GstRTSPSrc *rtspsrc;
1031 rtspsrc = GST_RTSPSRC (object);
1035 gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (rtspsrc),
1036 g_value_get_string (value), NULL);
1038 case PROP_PROTOCOLS:
1039 rtspsrc->protocols = g_value_get_flags (value);
1042 rtspsrc->debug = g_value_get_boolean (value);
1045 rtspsrc->retry = g_value_get_uint (value);
1048 rtspsrc->udp_timeout = g_value_get_uint64 (value);
1050 case PROP_TCP_TIMEOUT:
1051 gst_rtspsrc_set_tcp_timeout (rtspsrc, g_value_get_uint64 (value));
1054 rtspsrc->latency = g_value_get_uint (value);
1056 case PROP_DROP_ON_LATENCY:
1057 rtspsrc->drop_on_latency = g_value_get_boolean (value);
1059 case PROP_CONNECTION_SPEED:
1060 rtspsrc->connection_speed = g_value_get_uint64 (value);
1062 case PROP_NAT_METHOD:
1063 rtspsrc->nat_method = g_value_get_enum (value);
1066 rtspsrc->do_rtcp = g_value_get_boolean (value);
1068 case PROP_DO_RTSP_KEEP_ALIVE:
1069 rtspsrc->do_rtsp_keep_alive = g_value_get_boolean (value);
1072 gst_rtspsrc_set_proxy (rtspsrc, g_value_get_string (value));
1075 g_free (rtspsrc->prop_proxy_id);
1076 rtspsrc->prop_proxy_id = g_value_dup_string (value);
1079 g_free (rtspsrc->prop_proxy_pw);
1080 rtspsrc->prop_proxy_pw = g_value_dup_string (value);
1082 case PROP_RTP_BLOCKSIZE:
1083 rtspsrc->rtp_blocksize = g_value_get_uint (value);
1086 g_free (rtspsrc->user_id);
1087 rtspsrc->user_id = g_value_dup_string (value);
1090 g_free (rtspsrc->user_pw);
1091 rtspsrc->user_pw = g_value_dup_string (value);
1093 case PROP_BUFFER_MODE:
1094 rtspsrc->buffer_mode = g_value_get_enum (value);
1096 case PROP_PORT_RANGE:
1100 str = g_value_get_string (value);
1101 if (sscanf (str, "%u-%u", &rtspsrc->client_port_range.min,
1102 &rtspsrc->client_port_range.max) != 2) {
1103 rtspsrc->client_port_range.min = 0;
1104 rtspsrc->client_port_range.max = 0;
1108 case PROP_UDP_BUFFER_SIZE:
1109 rtspsrc->udp_buffer_size = g_value_get_int (value);
1111 case PROP_SHORT_HEADER:
1112 rtspsrc->short_header = g_value_get_boolean (value);
1114 case PROP_PROBATION:
1115 rtspsrc->probation = g_value_get_uint (value);
1117 case PROP_UDP_RECONNECT:
1118 rtspsrc->udp_reconnect = g_value_get_boolean (value);
1120 case PROP_MULTICAST_IFACE:
1121 g_free (rtspsrc->multi_iface);
1123 if (g_value_get_string (value) == NULL)
1124 rtspsrc->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
1126 rtspsrc->multi_iface = g_value_dup_string (value);
1129 rtspsrc->ntp_sync = g_value_get_boolean (value);
1131 case PROP_USE_PIPELINE_CLOCK:
1132 rtspsrc->use_pipeline_clock = g_value_get_boolean (value);
1135 rtspsrc->sdes = g_value_dup_boxed (value);
1137 case PROP_TLS_VALIDATION_FLAGS:
1138 rtspsrc->tls_validation_flags = g_value_get_flags (value);
1140 case PROP_TLS_DATABASE:
1141 g_clear_object (&rtspsrc->tls_database);
1142 rtspsrc->tls_database = g_value_dup_object (value);
1144 case PROP_TLS_INTERACTION:
1145 g_clear_object (&rtspsrc->tls_interaction);
1146 rtspsrc->tls_interaction = g_value_dup_object (value);
1148 case PROP_DO_RETRANSMISSION:
1149 rtspsrc->do_retransmission = g_value_get_boolean (value);
1151 case PROP_NTP_TIME_SOURCE:
1152 rtspsrc->ntp_time_source = g_value_get_enum (value);
1154 case PROP_USER_AGENT:
1155 g_free (rtspsrc->user_agent);
1156 rtspsrc->user_agent = g_value_dup_string (value);
1158 case PROP_MAX_RTCP_RTP_TIME_DIFF:
1159 rtspsrc->max_rtcp_rtp_time_diff = g_value_get_int (value);
1162 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1168 gst_rtspsrc_get_property (GObject * object, guint prop_id, GValue * value,
1171 GstRTSPSrc *rtspsrc;
1173 rtspsrc = GST_RTSPSRC (object);
1177 g_value_set_string (value, rtspsrc->conninfo.location);
1179 case PROP_PROTOCOLS:
1180 g_value_set_flags (value, rtspsrc->protocols);
1183 g_value_set_boolean (value, rtspsrc->debug);
1186 g_value_set_uint (value, rtspsrc->retry);
1189 g_value_set_uint64 (value, rtspsrc->udp_timeout);
1191 case PROP_TCP_TIMEOUT:
1195 timeout = ((guint64) rtspsrc->tcp_timeout.tv_sec) * G_USEC_PER_SEC +
1196 rtspsrc->tcp_timeout.tv_usec;
1197 g_value_set_uint64 (value, timeout);
1201 g_value_set_uint (value, rtspsrc->latency);
1203 case PROP_DROP_ON_LATENCY:
1204 g_value_set_boolean (value, rtspsrc->drop_on_latency);
1206 case PROP_CONNECTION_SPEED:
1207 g_value_set_uint64 (value, rtspsrc->connection_speed);
1209 case PROP_NAT_METHOD:
1210 g_value_set_enum (value, rtspsrc->nat_method);
1213 g_value_set_boolean (value, rtspsrc->do_rtcp);
1215 case PROP_DO_RTSP_KEEP_ALIVE:
1216 g_value_set_boolean (value, rtspsrc->do_rtsp_keep_alive);
1222 if (rtspsrc->proxy_host) {
1224 g_strdup_printf ("%s:%d", rtspsrc->proxy_host, rtspsrc->proxy_port);
1228 g_value_take_string (value, str);
1232 g_value_set_string (value, rtspsrc->prop_proxy_id);
1235 g_value_set_string (value, rtspsrc->prop_proxy_pw);
1237 case PROP_RTP_BLOCKSIZE:
1238 g_value_set_uint (value, rtspsrc->rtp_blocksize);
1241 g_value_set_string (value, rtspsrc->user_id);
1244 g_value_set_string (value, rtspsrc->user_pw);
1246 case PROP_BUFFER_MODE:
1247 g_value_set_enum (value, rtspsrc->buffer_mode);
1249 case PROP_PORT_RANGE:
1253 if (rtspsrc->client_port_range.min != 0) {
1254 str = g_strdup_printf ("%u-%u", rtspsrc->client_port_range.min,
1255 rtspsrc->client_port_range.max);
1259 g_value_take_string (value, str);
1262 case PROP_UDP_BUFFER_SIZE:
1263 g_value_set_int (value, rtspsrc->udp_buffer_size);
1265 case PROP_SHORT_HEADER:
1266 g_value_set_boolean (value, rtspsrc->short_header);
1268 case PROP_PROBATION:
1269 g_value_set_uint (value, rtspsrc->probation);
1271 case PROP_UDP_RECONNECT:
1272 g_value_set_boolean (value, rtspsrc->udp_reconnect);
1274 case PROP_MULTICAST_IFACE:
1275 g_value_set_string (value, rtspsrc->multi_iface);
1278 g_value_set_boolean (value, rtspsrc->ntp_sync);
1280 case PROP_USE_PIPELINE_CLOCK:
1281 g_value_set_boolean (value, rtspsrc->use_pipeline_clock);
1284 g_value_set_boxed (value, rtspsrc->sdes);
1286 case PROP_TLS_VALIDATION_FLAGS:
1287 g_value_set_flags (value, rtspsrc->tls_validation_flags);
1289 case PROP_TLS_DATABASE:
1290 g_value_set_object (value, rtspsrc->tls_database);
1292 case PROP_TLS_INTERACTION:
1293 g_value_set_object (value, rtspsrc->tls_interaction);
1295 case PROP_DO_RETRANSMISSION:
1296 g_value_set_boolean (value, rtspsrc->do_retransmission);
1298 case PROP_NTP_TIME_SOURCE:
1299 g_value_set_enum (value, rtspsrc->ntp_time_source);
1301 case PROP_USER_AGENT:
1302 g_value_set_string (value, rtspsrc->user_agent);
1304 case PROP_MAX_RTCP_RTP_TIME_DIFF:
1305 g_value_set_int (value, rtspsrc->max_rtcp_rtp_time_diff);
1308 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1314 find_stream_by_id (GstRTSPStream * stream, gint * id)
1316 if (stream->id == *id)
1323 find_stream_by_channel (GstRTSPStream * stream, gint * channel)
1325 if (stream->channel[0] == *channel || stream->channel[1] == *channel)
1332 find_stream_by_udpsrc (GstRTSPStream * stream, gconstpointer a)
1334 GstElement *src = (GstElement *) a;
1336 if (stream->udpsrc[0] == src)
1338 if (stream->udpsrc[1] == src)
1345 find_stream_by_setup (GstRTSPStream * stream, gconstpointer a)
1347 if (stream->conninfo.location) {
1348 /* check qualified setup_url */
1349 if (!strcmp (stream->conninfo.location, (gchar *) a))
1352 if (stream->control_url) {
1353 /* check original control_url */
1354 if (!strcmp (stream->control_url, (gchar *) a))
1357 /* check if qualified setup_url ends with string */
1358 if (g_str_has_suffix (stream->control_url, (gchar *) a))
1365 static GstRTSPStream *
1366 find_stream (GstRTSPSrc * src, gconstpointer data, gconstpointer func)
1370 /* find and get stream */
1371 if ((lstream = g_list_find_custom (src->streams, data, (GCompareFunc) func)))
1372 return (GstRTSPStream *) lstream->data;
1377 static const GstSDPBandwidth *
1378 gst_rtspsrc_get_bandwidth (GstRTSPSrc * src, const GstSDPMessage * sdp,
1379 const GstSDPMedia * media, const gchar * type)
1383 /* first look in the media specific section */
1384 len = gst_sdp_media_bandwidths_len (media);
1385 for (i = 0; i < len; i++) {
1386 const GstSDPBandwidth *bw = gst_sdp_media_get_bandwidth (media, i);
1388 if (strcmp (bw->bwtype, type) == 0)
1391 /* then look in the message specific section */
1392 len = gst_sdp_message_bandwidths_len (sdp);
1393 for (i = 0; i < len; i++) {
1394 const GstSDPBandwidth *bw = gst_sdp_message_get_bandwidth (sdp, i);
1396 if (strcmp (bw->bwtype, type) == 0)
1403 gst_rtspsrc_collect_bandwidth (GstRTSPSrc * src, const GstSDPMessage * sdp,
1404 const GstSDPMedia * media, GstRTSPStream * stream)
1406 const GstSDPBandwidth *bw;
1408 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_AS)))
1409 stream->as_bandwidth = bw->bandwidth;
1411 stream->as_bandwidth = -1;
1413 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_RR)))
1414 stream->rr_bandwidth = bw->bandwidth;
1416 stream->rr_bandwidth = -1;
1418 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_RS)))
1419 stream->rs_bandwidth = bw->bandwidth;
1421 stream->rs_bandwidth = -1;
1425 gst_rtspsrc_do_stream_connection (GstRTSPSrc * src, GstRTSPStream * stream,
1426 const GstSDPConnection * conn)
1428 if (conn->nettype == NULL || strcmp (conn->nettype, "IN") != 0)
1431 if (conn->addrtype == NULL)
1434 /* check for IPV6 */
1435 if (strcmp (conn->addrtype, "IP4") == 0)
1436 stream->is_ipv6 = FALSE;
1437 else if (strcmp (conn->addrtype, "IP6") == 0)
1438 stream->is_ipv6 = TRUE;
1443 g_free (stream->destination);
1444 stream->destination = g_strdup (conn->address);
1446 /* check for multicast */
1447 stream->is_multicast =
1448 gst_sdp_address_is_multicast (conn->nettype, conn->addrtype,
1450 stream->ttl = conn->ttl;
1453 /* Go over the connections for a stream.
1454 * - If we are dealing with IPV6, we will setup IPV6 sockets for sending and
1456 * - If we are dealing with a localhost address, we disable multicast
1459 gst_rtspsrc_collect_connections (GstRTSPSrc * src, const GstSDPMessage * sdp,
1460 const GstSDPMedia * media, GstRTSPStream * stream)
1462 const GstSDPConnection *conn;
1465 /* first look in the media specific section */
1466 len = gst_sdp_media_connections_len (media);
1467 for (i = 0; i < len; i++) {
1468 conn = gst_sdp_media_get_connection (media, i);
1470 gst_rtspsrc_do_stream_connection (src, stream, conn);
1472 /* then look in the message specific section */
1473 if ((conn = gst_sdp_message_get_connection (sdp))) {
1474 gst_rtspsrc_do_stream_connection (src, stream, conn);
1478 /* m=<media> <UDP port> RTP/AVP <payload>
1481 gst_rtspsrc_collect_payloads (GstRTSPSrc * src, const GstSDPMessage * sdp,
1482 const GstSDPMedia * media, GstRTSPStream * stream)
1486 GstCaps *global_caps;
1489 proto = gst_sdp_media_get_proto (media);
1493 if (g_str_equal (proto, "RTP/AVP"))
1494 stream->profile = GST_RTSP_PROFILE_AVP;
1495 else if (g_str_equal (proto, "RTP/SAVP"))
1496 stream->profile = GST_RTSP_PROFILE_SAVP;
1497 else if (g_str_equal (proto, "RTP/AVPF"))
1498 stream->profile = GST_RTSP_PROFILE_AVPF;
1499 else if (g_str_equal (proto, "RTP/SAVPF"))
1500 stream->profile = GST_RTSP_PROFILE_SAVPF;
1504 /* Parse global SDP attributes once */
1505 global_caps = gst_caps_new_empty_simple ("application/x-unknown");
1506 GST_DEBUG ("mapping sdp session level attributes to caps");
1507 gst_sdp_message_attributes_to_caps (sdp, global_caps);
1508 GST_DEBUG ("mapping sdp media level attributes to caps");
1509 gst_sdp_media_attributes_to_caps (media, global_caps);
1511 len = gst_sdp_media_formats_len (media);
1512 for (i = 0; i < len; i++) {
1514 GstCaps *caps, *outcaps;
1519 pt = atoi (gst_sdp_media_get_format (media, i));
1521 GST_DEBUG_OBJECT (src, " looking at %d pt: %d", i, pt);
1524 caps = gst_sdp_media_get_caps_from_media (media, pt);
1526 GST_WARNING_OBJECT (src, " skipping pt %d without caps", pt);
1530 /* do some tweaks */
1531 s = gst_caps_get_structure (caps, 0);
1532 if ((enc = gst_structure_get_string (s, "encoding-name"))) {
1533 stream->is_real = (strstr (enc, "-REAL") != NULL);
1534 if (strcmp (enc, "X-ASF-PF") == 0)
1535 stream->container = TRUE;
1538 /* Merge in global caps */
1539 /* Intersect will merge in missing fields to the current caps */
1540 outcaps = gst_caps_intersect (caps, global_caps);
1541 gst_caps_unref (caps);
1543 /* the first pt will be the default */
1544 if (stream->ptmap->len == 0)
1545 stream->default_pt = pt;
1548 item.caps = outcaps;
1550 g_array_append_val (stream->ptmap, item);
1553 gst_caps_unref (global_caps);
1558 GST_ERROR_OBJECT (src, "can't find proto in media");
1563 GST_ERROR_OBJECT (src, "unknown proto in media %s", proto);
1568 static const gchar *
1569 get_aggregate_control (GstRTSPSrc * src)
1574 base = src->control;
1575 else if (src->content_base)
1576 base = src->content_base;
1577 else if (src->conninfo.url_str)
1578 base = src->conninfo.url_str;
1586 clear_ptmap_item (PtMapItem * item)
1589 gst_caps_unref (item->caps);
1592 static GstRTSPStream *
1593 gst_rtspsrc_create_stream (GstRTSPSrc * src, GstSDPMessage * sdp, gint idx)
1595 GstRTSPStream *stream;
1596 const gchar *control_url;
1597 const GstSDPMedia *media;
1599 /* get media, should not return NULL */
1600 media = gst_sdp_message_get_media (sdp, idx);
1604 stream = g_new0 (GstRTSPStream, 1);
1605 stream->parent = src;
1606 /* we mark the pad as not linked, we will mark it as OK when we add the pad to
1608 stream->last_ret = GST_FLOW_NOT_LINKED;
1609 stream->added = FALSE;
1610 stream->setup = FALSE;
1611 stream->skipped = FALSE;
1613 stream->eos = FALSE;
1614 stream->discont = TRUE;
1615 stream->seqbase = -1;
1616 stream->timebase = -1;
1617 stream->send_ssrc = g_random_int ();
1618 stream->profile = GST_RTSP_PROFILE_AVP;
1619 stream->ptmap = g_array_new (FALSE, FALSE, sizeof (PtMapItem));
1620 g_array_set_clear_func (stream->ptmap, (GDestroyNotify) clear_ptmap_item);
1622 /* collect bandwidth information for this steam. FIXME, configure in the RTP
1623 * session manager to scale RTCP. */
1624 gst_rtspsrc_collect_bandwidth (src, sdp, media, stream);
1626 /* collect connection info */
1627 gst_rtspsrc_collect_connections (src, sdp, media, stream);
1629 /* make the payload type map */
1630 gst_rtspsrc_collect_payloads (src, sdp, media, stream);
1632 /* collect port number */
1633 stream->port = gst_sdp_media_get_port (media);
1635 /* get control url to construct the setup url. The setup url is used to
1636 * configure the transport of the stream and is used to identity the stream in
1637 * the RTP-Info header field returned from PLAY. */
1638 control_url = gst_sdp_media_get_attribute_val (media, "control");
1639 if (control_url == NULL)
1640 control_url = gst_sdp_message_get_attribute_val_n (sdp, "control", 0);
1642 GST_DEBUG_OBJECT (src, "stream %d, (%p)", stream->id, stream);
1643 GST_DEBUG_OBJECT (src, " port: %d", stream->port);
1644 GST_DEBUG_OBJECT (src, " container: %d", stream->container);
1645 GST_DEBUG_OBJECT (src, " control: %s", GST_STR_NULL (control_url));
1647 if (control_url != NULL) {
1648 stream->control_url = g_strdup (control_url);
1649 /* Build a fully qualified url using the content_base if any or by prefixing
1650 * the original request.
1651 * If the control_url starts with a '/' or a non rtsp: protocol we will most
1652 * likely build a URL that the server will fail to understand, this is ok,
1653 * we will fail then. */
1654 if (g_str_has_prefix (control_url, "rtsp://"))
1655 stream->conninfo.location = g_strdup (control_url);
1660 if (g_strcmp0 (control_url, "*") == 0)
1663 base = get_aggregate_control (src);
1665 /* check if the base ends or control starts with / */
1666 has_slash = g_str_has_prefix (control_url, "/");
1667 has_slash = has_slash || g_str_has_suffix (base, "/");
1669 /* concatenate the two strings, insert / when not present */
1670 stream->conninfo.location =
1671 g_strdup_printf ("%s%s%s", base, has_slash ? "" : "/", control_url);
1674 GST_DEBUG_OBJECT (src, " setup: %s",
1675 GST_STR_NULL (stream->conninfo.location));
1677 /* we keep track of all streams */
1678 src->streams = g_list_append (src->streams, stream);
1686 gst_rtspsrc_stream_free (GstRTSPSrc * src, GstRTSPStream * stream)
1690 GST_DEBUG_OBJECT (src, "free stream %p", stream);
1692 g_array_free (stream->ptmap, TRUE);
1694 g_free (stream->destination);
1695 g_free (stream->control_url);
1696 g_free (stream->conninfo.location);
1698 for (i = 0; i < 2; i++) {
1699 if (stream->udpsrc[i]) {
1700 gst_element_set_state (stream->udpsrc[i], GST_STATE_NULL);
1701 gst_bin_remove (GST_BIN_CAST (src), stream->udpsrc[i]);
1702 gst_object_unref (stream->udpsrc[i]);
1704 if (stream->channelpad[i])
1705 gst_object_unref (stream->channelpad[i]);
1707 if (stream->udpsink[i]) {
1708 gst_element_set_state (stream->udpsink[i], GST_STATE_NULL);
1709 gst_bin_remove (GST_BIN_CAST (src), stream->udpsink[i]);
1710 gst_object_unref (stream->udpsink[i]);
1713 if (stream->fakesrc) {
1714 gst_element_set_state (stream->fakesrc, GST_STATE_NULL);
1715 gst_bin_remove (GST_BIN_CAST (src), stream->fakesrc);
1716 gst_object_unref (stream->fakesrc);
1718 if (stream->srcpad) {
1719 gst_pad_set_active (stream->srcpad, FALSE);
1721 gst_element_remove_pad (GST_ELEMENT_CAST (src), stream->srcpad);
1723 if (stream->srtpenc)
1724 gst_object_unref (stream->srtpenc);
1725 if (stream->srtpdec)
1726 gst_object_unref (stream->srtpdec);
1727 if (stream->srtcpparams)
1728 gst_caps_unref (stream->srtcpparams);
1729 if (stream->rtcppad)
1730 gst_object_unref (stream->rtcppad);
1731 if (stream->session)
1732 g_object_unref (stream->session);
1733 if (stream->rtx_pt_map)
1734 gst_structure_free (stream->rtx_pt_map);
1739 gst_rtspsrc_cleanup (GstRTSPSrc * src)
1743 GST_DEBUG_OBJECT (src, "cleanup");
1745 for (walk = src->streams; walk; walk = g_list_next (walk)) {
1746 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
1748 gst_rtspsrc_stream_free (src, stream);
1750 g_list_free (src->streams);
1751 src->streams = NULL;
1753 if (src->manager_sig_id) {
1754 g_signal_handler_disconnect (src->manager, src->manager_sig_id);
1755 src->manager_sig_id = 0;
1757 gst_element_set_state (src->manager, GST_STATE_NULL);
1758 gst_bin_remove (GST_BIN_CAST (src), src->manager);
1759 src->manager = NULL;
1762 gst_structure_free (src->props);
1765 g_free (src->content_base);
1766 src->content_base = NULL;
1768 g_free (src->control);
1769 src->control = NULL;
1772 gst_rtsp_range_free (src->range);
1775 /* don't clear the SDP when it was used in the url */
1776 if (src->sdp && !src->from_sdp) {
1777 gst_sdp_message_free (src->sdp);
1781 src->need_segment = FALSE;
1783 if (src->provided_clock) {
1784 gst_object_unref (src->provided_clock);
1785 src->provided_clock = NULL;
1790 gst_rtspsrc_alloc_udp_ports (GstRTSPStream * stream,
1791 gint * rtpport, gint * rtcpport)
1794 GstStateChangeReturn ret;
1795 GstElement *udpsrc0, *udpsrc1;
1796 gint tmp_rtp, tmp_rtcp;
1800 src = stream->parent;
1806 /* Start at next port */
1807 tmp_rtp = src->next_port_num;
1809 if (stream->is_ipv6)
1810 host = "udp://[::0]";
1812 host = "udp://0.0.0.0";
1814 /* try to allocate 2 UDP ports, the RTP port should be an even
1815 * number and the RTCP port should be the next (uneven) port */
1818 if (tmp_rtp != 0 && src->client_port_range.max > 0 &&
1819 tmp_rtp >= src->client_port_range.max)
1822 udpsrc0 = gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
1823 if (udpsrc0 == NULL)
1824 goto no_udp_protocol;
1825 g_object_set (G_OBJECT (udpsrc0), "port", tmp_rtp, "reuse", FALSE, NULL);
1827 if (src->udp_buffer_size != 0)
1828 g_object_set (G_OBJECT (udpsrc0), "buffer-size", src->udp_buffer_size,
1831 ret = gst_element_set_state (udpsrc0, GST_STATE_READY);
1832 if (ret == GST_STATE_CHANGE_FAILURE) {
1834 GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTP port %d", tmp_rtp);
1837 if (++count > src->retry)
1840 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
1841 gst_element_set_state (udpsrc0, GST_STATE_NULL);
1842 gst_object_unref (udpsrc0);
1845 GST_DEBUG_OBJECT (src, "retry %d", count);
1848 goto no_udp_protocol;
1851 g_object_get (G_OBJECT (udpsrc0), "port", &tmp_rtp, NULL);
1852 GST_DEBUG_OBJECT (src, "got RTP port %d", tmp_rtp);
1854 /* check if port is even */
1855 if ((tmp_rtp & 0x01) != 0) {
1856 /* port not even, close and allocate another */
1857 if (++count > src->retry)
1860 GST_DEBUG_OBJECT (src, "RTP port not even");
1862 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
1863 gst_element_set_state (udpsrc0, GST_STATE_NULL);
1864 gst_object_unref (udpsrc0);
1867 GST_DEBUG_OBJECT (src, "retry %d", count);
1872 /* allocate port+1 for RTCP now */
1873 udpsrc1 = gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
1874 if (udpsrc1 == NULL)
1875 goto no_udp_rtcp_protocol;
1878 tmp_rtcp = tmp_rtp + 1;
1879 if (src->client_port_range.max > 0 && tmp_rtcp > src->client_port_range.max)
1882 g_object_set (G_OBJECT (udpsrc1), "port", tmp_rtcp, "reuse", FALSE, NULL);
1884 GST_DEBUG_OBJECT (src, "starting RTCP on port %d", tmp_rtcp);
1885 ret = gst_element_set_state (udpsrc1, GST_STATE_READY);
1886 /* tmp_rtcp port is busy already : retry to make rtp/rtcp pair */
1887 if (ret == GST_STATE_CHANGE_FAILURE) {
1888 GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTCP port %d", tmp_rtcp);
1890 if (++count > src->retry)
1893 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
1894 gst_element_set_state (udpsrc0, GST_STATE_NULL);
1895 gst_object_unref (udpsrc0);
1898 GST_DEBUG_OBJECT (src, "free RTCP udpsrc");
1899 gst_element_set_state (udpsrc1, GST_STATE_NULL);
1900 gst_object_unref (udpsrc1);
1904 GST_DEBUG_OBJECT (src, "retry %d", count);
1908 /* all fine, do port check */
1909 g_object_get (G_OBJECT (udpsrc0), "port", rtpport, NULL);
1910 g_object_get (G_OBJECT (udpsrc1), "port", rtcpport, NULL);
1912 /* this should not happen... */
1913 if (*rtpport != tmp_rtp || *rtcpport != tmp_rtcp)
1916 /* we keep these elements, we configure all in configure_transport when the
1917 * server told us to really use the UDP ports. */
1918 stream->udpsrc[0] = gst_object_ref_sink (udpsrc0);
1919 stream->udpsrc[1] = gst_object_ref_sink (udpsrc1);
1920 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
1921 gst_element_set_locked_state (stream->udpsrc[1], TRUE);
1923 /* keep track of next available port number when we have a range
1925 if (src->next_port_num != 0)
1926 src->next_port_num = tmp_rtcp + 1;
1933 GST_DEBUG_OBJECT (src, "could not get UDP source");
1938 GST_DEBUG_OBJECT (src, "could not allocate UDP port pair after %d retries",
1942 no_udp_rtcp_protocol:
1944 GST_DEBUG_OBJECT (src, "could not get UDP source for RTCP");
1949 GST_DEBUG_OBJECT (src, "ports don't match rtp: %d<->%d, rtcp: %d<->%d",
1950 tmp_rtp, *rtpport, tmp_rtcp, *rtcpport);
1956 gst_element_set_state (udpsrc0, GST_STATE_NULL);
1957 gst_object_unref (udpsrc0);
1960 gst_element_set_state (udpsrc1, GST_STATE_NULL);
1961 gst_object_unref (udpsrc1);
1968 gst_rtspsrc_set_state (GstRTSPSrc * src, GstState state)
1973 gst_element_set_state (GST_ELEMENT_CAST (src->manager), state);
1975 for (walk = src->streams; walk; walk = g_list_next (walk)) {
1976 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
1979 for (i = 0; i < 2; i++) {
1980 if (stream->udpsrc[i])
1981 gst_element_set_state (stream->udpsrc[i], state);
1987 gst_rtspsrc_flush (GstRTSPSrc * src, gboolean flush, gboolean playing)
1994 event = gst_event_new_flush_start ();
1995 GST_DEBUG_OBJECT (src, "start flush");
1997 state = GST_STATE_PAUSED;
1999 event = gst_event_new_flush_stop (FALSE);
2000 GST_DEBUG_OBJECT (src, "stop flush; playing %d", playing);
2003 state = GST_STATE_PLAYING;
2005 state = GST_STATE_PAUSED;
2007 gst_rtspsrc_push_event (src, event);
2008 gst_rtspsrc_loop_send_cmd (src, cmd, CMD_LOOP);
2009 gst_rtspsrc_set_state (src, state);
2012 static GstRTSPResult
2013 gst_rtspsrc_connection_send (GstRTSPSrc * src, GstRTSPConnection * conn,
2014 GstRTSPMessage * message, GTimeVal * timeout)
2019 ret = gst_rtsp_connection_send (conn, message, timeout);
2021 ret = GST_RTSP_ERROR;
2026 static GstRTSPResult
2027 gst_rtspsrc_connection_receive (GstRTSPSrc * src, GstRTSPConnection * conn,
2028 GstRTSPMessage * message, GTimeVal * timeout)
2033 ret = gst_rtsp_connection_receive (conn, message, timeout);
2035 ret = GST_RTSP_ERROR;
2041 gst_rtspsrc_get_position (GstRTSPSrc * src)
2046 query = gst_query_new_position (GST_FORMAT_TIME);
2047 /* should be known somewhere down the stream (e.g. jitterbuffer) */
2048 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2049 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2053 if (stream->srcpad) {
2054 if (gst_pad_query (stream->srcpad, query)) {
2055 gst_query_parse_position (query, &fmt, &pos);
2056 GST_DEBUG_OBJECT (src, "retaining position %" GST_TIME_FORMAT,
2057 GST_TIME_ARGS (pos));
2058 src->last_pos = pos;
2068 gst_query_unref (query);
2072 gst_rtspsrc_perform_seek (GstRTSPSrc * src, GstEvent * event)
2077 GstSeekType cur_type = GST_SEEK_TYPE_NONE, stop_type;
2079 gboolean flush, skip;
2082 GstSegment seeksegment = { 0, };
2086 GST_DEBUG_OBJECT (src, "doing seek with event");
2088 gst_event_parse_seek (event, &rate, &format, &flags,
2089 &cur_type, &cur, &stop_type, &stop);
2091 /* no negative rates yet */
2095 /* we need TIME format */
2096 if (format != src->segment.format)
2099 GST_DEBUG_OBJECT (src, "doing seek without event");
2101 cur_type = GST_SEEK_TYPE_SET;
2102 stop_type = GST_SEEK_TYPE_SET;
2105 /* get flush flag */
2106 flush = flags & GST_SEEK_FLAG_FLUSH;
2107 skip = flags & GST_SEEK_FLAG_SKIP;
2109 /* now we need to make sure the streaming thread is stopped. We do this by
2110 * either sending a FLUSH_START event downstream which will cause the
2111 * streaming thread to stop with a WRONG_STATE.
2112 * For a non-flushing seek we simply pause the task, which will happen as soon
2113 * as it completes one iteration (and thus might block when the sink is
2114 * blocking in preroll). */
2116 GST_DEBUG_OBJECT (src, "starting flush");
2117 gst_rtspsrc_flush (src, TRUE, FALSE);
2120 gst_task_pause (src->task);
2124 /* we should now be able to grab the streaming thread because we stopped it
2125 * with the above flush/pause code */
2126 GST_RTSP_STREAM_LOCK (src);
2128 GST_DEBUG_OBJECT (src, "stopped streaming");
2130 /* stop flushing the rtsp connection so we can send PAUSE/PLAY below */
2131 gst_rtspsrc_connection_flush (src, FALSE);
2133 /* copy segment, we need this because we still need the old
2134 * segment when we close the current segment. */
2135 memcpy (&seeksegment, &src->segment, sizeof (GstSegment));
2137 /* configure the seek parameters in the seeksegment. We will then have the
2138 * right values in the segment to perform the seek */
2140 GST_DEBUG_OBJECT (src, "configuring seek");
2141 gst_segment_do_seek (&seeksegment, rate, format, flags,
2142 cur_type, cur, stop_type, stop, &update);
2145 /* figure out the last position we need to play. If it's configured (stop !=
2146 * -1), use that, else we play until the total duration of the file */
2147 if ((stop = seeksegment.stop) == -1)
2148 stop = seeksegment.duration;
2150 playing = (src->state == GST_RTSP_STATE_PLAYING);
2152 /* if we were playing, pause first */
2154 /* obtain current position in case seek fails */
2155 gst_rtspsrc_get_position (src);
2156 gst_rtspsrc_pause (src, FALSE);
2160 src->state = GST_RTSP_STATE_SEEKING;
2162 /* PLAY will add the range header now. */
2163 src->need_range = TRUE;
2165 /* and continue playing */
2167 gst_rtspsrc_play (src, &seeksegment, FALSE);
2169 /* prepare for streaming again */
2171 /* if we started flush, we stop now */
2172 GST_DEBUG_OBJECT (src, "stopping flush");
2173 gst_rtspsrc_flush (src, FALSE, playing);
2176 /* now we did the seek and can activate the new segment values */
2177 memcpy (&src->segment, &seeksegment, sizeof (GstSegment));
2179 /* if we're doing a segment seek, post a SEGMENT_START message */
2180 if (src->segment.flags & GST_SEEK_FLAG_SEGMENT) {
2181 gst_element_post_message (GST_ELEMENT_CAST (src),
2182 gst_message_new_segment_start (GST_OBJECT_CAST (src),
2183 src->segment.format, src->segment.position));
2186 /* now create the newsegment */
2187 GST_DEBUG_OBJECT (src, "Creating newsegment from %" G_GINT64_FORMAT
2188 " to %" G_GINT64_FORMAT, src->segment.position, stop);
2191 GST_DEBUG_OBJECT (src, "mark DISCONT, we did a seek to another position");
2192 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2193 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2194 stream->discont = TRUE;
2197 GST_RTSP_STREAM_UNLOCK (src);
2204 GST_DEBUG_OBJECT (src, "negative playback rates are not supported yet.");
2209 GST_DEBUG_OBJECT (src, "unsupported format given, seek aborted.");
2215 gst_rtspsrc_handle_src_event (GstPad * pad, GstObject * parent,
2219 gboolean res = TRUE;
2222 src = GST_RTSPSRC_CAST (parent);
2224 GST_DEBUG_OBJECT (src, "pad %s:%s received event %s",
2225 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
2227 switch (GST_EVENT_TYPE (event)) {
2228 case GST_EVENT_SEEK:
2229 res = gst_rtspsrc_perform_seek (src, event);
2233 case GST_EVENT_NAVIGATION:
2234 case GST_EVENT_LATENCY:
2242 if ((target = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (pad)))) {
2243 res = gst_pad_send_event (target, event);
2244 gst_object_unref (target);
2246 gst_event_unref (event);
2249 gst_event_unref (event);
2255 /* this is the final event function we receive on the internal source pad when
2256 * we deal with TCP connections */
2258 gst_rtspsrc_handle_internal_src_event (GstPad * pad, GstObject * parent,
2263 GST_DEBUG_OBJECT (pad, "received event %s", GST_EVENT_TYPE_NAME (event));
2265 switch (GST_EVENT_TYPE (event)) {
2266 case GST_EVENT_SEEK:
2268 case GST_EVENT_NAVIGATION:
2269 case GST_EVENT_LATENCY:
2271 gst_event_unref (event);
2278 /* this is the final query function we receive on the internal source pad when
2279 * we deal with TCP connections */
2281 gst_rtspsrc_handle_internal_src_query (GstPad * pad, GstObject * parent,
2285 gboolean res = TRUE;
2287 src = GST_RTSPSRC_CAST (gst_pad_get_element_private (pad));
2289 GST_DEBUG_OBJECT (src, "pad %s:%s received query %s",
2290 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
2292 switch (GST_QUERY_TYPE (query)) {
2293 case GST_QUERY_POSITION:
2298 case GST_QUERY_DURATION:
2302 gst_query_parse_duration (query, &format, NULL);
2305 case GST_FORMAT_TIME:
2306 gst_query_set_duration (query, format, src->segment.duration);
2314 case GST_QUERY_LATENCY:
2316 /* we are live with a min latency of 0 and unlimited max latency, this
2317 * result will be updated by the session manager if there is any. */
2318 gst_query_set_latency (query, TRUE, 0, -1);
2328 /* this query is executed on the ghost source pad exposed on rtspsrc. */
2330 gst_rtspsrc_handle_src_query (GstPad * pad, GstObject * parent,
2334 gboolean res = FALSE;
2336 src = GST_RTSPSRC_CAST (parent);
2338 GST_DEBUG_OBJECT (src, "pad %s:%s received query %s",
2339 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
2341 switch (GST_QUERY_TYPE (query)) {
2342 case GST_QUERY_DURATION:
2346 gst_query_parse_duration (query, &format, NULL);
2349 case GST_FORMAT_TIME:
2350 gst_query_set_duration (query, format, src->segment.duration);
2358 case GST_QUERY_SEEKING:
2362 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
2363 if (format == GST_FORMAT_TIME) {
2365 src->cur_protocols != GST_RTSP_LOWER_TRANS_UDP_MCAST;
2367 /* seeking without duration is unlikely */
2368 seekable = seekable && src->seekable && src->segment.duration &&
2369 GST_CLOCK_TIME_IS_VALID (src->segment.duration);
2371 gst_query_set_seeking (query, GST_FORMAT_TIME, seekable, 0,
2372 src->segment.duration);
2381 uri = gst_rtspsrc_uri_get_uri (GST_URI_HANDLER (src));
2383 gst_query_set_uri (query, uri);
2391 GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (pad));
2393 /* forward the query to the proxy target pad */
2395 res = gst_pad_query (target, query);
2396 gst_object_unref (target);
2405 /* callback for RTCP messages to be sent to the server when operating in TCP
2407 static GstFlowReturn
2408 gst_rtspsrc_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
2411 GstRTSPStream *stream;
2412 GstFlowReturn res = GST_FLOW_OK;
2417 GstRTSPMessage message = { 0 };
2418 GstRTSPConnection *conn;
2420 stream = (GstRTSPStream *) gst_pad_get_element_private (pad);
2421 src = stream->parent;
2423 gst_buffer_map (buffer, &map, GST_MAP_READ);
2427 gst_rtsp_message_init_data (&message, stream->channel[1]);
2429 /* lend the body data to the message */
2430 gst_rtsp_message_take_body (&message, data, size);
2432 if (stream->conninfo.connection)
2433 conn = stream->conninfo.connection;
2435 conn = src->conninfo.connection;
2437 GST_DEBUG_OBJECT (src, "sending %u bytes RTCP", size);
2438 ret = gst_rtspsrc_connection_send (src, conn, &message, NULL);
2439 GST_DEBUG_OBJECT (src, "sent RTCP, %d", ret);
2441 /* and steal it away again because we will free it when unreffing the
2443 gst_rtsp_message_steal_body (&message, &data, &size);
2444 gst_rtsp_message_unset (&message);
2446 gst_buffer_unmap (buffer, &map);
2447 gst_buffer_unref (buffer);
2452 static GstPadProbeReturn
2453 pad_blocked (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
2455 GstRTSPSrc *src = user_data;
2457 GST_DEBUG_OBJECT (src, "pad %s:%s blocked, activating streams",
2458 GST_DEBUG_PAD_NAME (pad));
2460 /* activate the streams */
2461 GST_OBJECT_LOCK (src);
2462 if (!src->need_activate)
2465 src->need_activate = FALSE;
2466 GST_OBJECT_UNLOCK (src);
2468 gst_rtspsrc_activate_streams (src);
2470 return GST_PAD_PROBE_OK;
2474 GST_OBJECT_UNLOCK (src);
2475 return GST_PAD_PROBE_OK;
2480 copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
2482 GstPad *gpad = GST_PAD_CAST (user_data);
2484 GST_DEBUG_OBJECT (gpad, "store sticky event %" GST_PTR_FORMAT, *event);
2485 gst_pad_store_sticky_event (gpad, *event);
2490 /* this callback is called when the session manager generated a new src pad with
2491 * payloaded RTP packets. We simply ghost the pad here. */
2493 new_manager_pad (GstElement * manager, GstPad * pad, GstRTSPSrc * src)
2496 GstPadTemplate *template;
2499 GstRTSPStream *stream;
2502 GST_DEBUG_OBJECT (src, "got new manager pad %" GST_PTR_FORMAT, pad);
2504 GST_RTSP_STATE_LOCK (src);
2506 name = gst_object_get_name (GST_OBJECT_CAST (pad));
2507 if (sscanf (name, "recv_rtp_src_%u_%u_%u", &id, &ssrc, &pt) != 3)
2508 goto unknown_stream;
2510 GST_DEBUG_OBJECT (src, "stream: %u, SSRC %08x, PT %d", id, ssrc, pt);
2512 stream = find_stream (src, &id, (gpointer) find_stream_by_id);
2514 goto unknown_stream;
2517 stream->ssrc = ssrc;
2519 /* we'll add it later see below */
2520 stream->added = TRUE;
2522 /* check if we added all streams */
2524 for (ostreams = src->streams; ostreams; ostreams = g_list_next (ostreams)) {
2525 GstRTSPStream *ostream = (GstRTSPStream *) ostreams->data;
2527 GST_DEBUG_OBJECT (src, "stream %p, container %d, added %d, setup %d",
2528 ostream, ostream->container, ostream->added, ostream->setup);
2530 /* if we find a stream for which we did a setup that is not added, we
2531 * need to wait some more */
2532 if (ostream->setup && !ostream->added) {
2537 GST_RTSP_STATE_UNLOCK (src);
2539 /* create a new pad we will use to stream to */
2540 template = gst_static_pad_template_get (&rtptemplate);
2541 stream->srcpad = gst_ghost_pad_new_from_template (name, pad, template);
2542 gst_object_unref (template);
2545 gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
2546 gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
2547 gst_pad_set_active (stream->srcpad, TRUE);
2548 gst_pad_sticky_events_foreach (pad, copy_sticky_events, stream->srcpad);
2549 gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
2552 GST_DEBUG_OBJECT (src, "We added all streams");
2553 /* when we get here, all stream are added and we can fire the no-more-pads
2555 gst_element_no_more_pads (GST_ELEMENT_CAST (src));
2563 GST_DEBUG_OBJECT (src, "ignoring unknown stream");
2564 GST_RTSP_STATE_UNLOCK (src);
2571 stream_get_caps_for_pt (GstRTSPStream * stream, guint pt)
2575 len = stream->ptmap->len;
2576 for (i = 0; i < len; i++) {
2577 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
2585 request_pt_map (GstElement * manager, guint session, guint pt, GstRTSPSrc * src)
2587 GstRTSPStream *stream;
2590 GST_DEBUG_OBJECT (src, "getting pt map for pt %d in session %d", pt, session);
2592 GST_RTSP_STATE_LOCK (src);
2593 stream = find_stream (src, &session, (gpointer) find_stream_by_id);
2595 goto unknown_stream;
2597 if ((caps = stream_get_caps_for_pt (stream, pt)))
2598 gst_caps_ref (caps);
2599 GST_RTSP_STATE_UNLOCK (src);
2605 GST_DEBUG_OBJECT (src, "unknown stream %d", session);
2606 GST_RTSP_STATE_UNLOCK (src);
2612 gst_rtspsrc_do_stream_eos (GstRTSPSrc * src, GstRTSPStream * stream)
2614 GST_DEBUG_OBJECT (src, "setting stream for session %u to EOS", stream->id);
2620 gst_rtspsrc_stream_push_event (src, stream, gst_event_new_eos ());
2626 GST_DEBUG_OBJECT (src, "stream for session %u was already EOS", stream->id);
2632 on_bye_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
2634 GstRTSPSrc *src = stream->parent;
2637 g_object_get (source, "ssrc", &ssrc, NULL);
2639 GST_DEBUG_OBJECT (src, "source %08x, stream %08x, session %u received BYE",
2640 ssrc, stream->ssrc, stream->id);
2642 if (ssrc == stream->ssrc)
2643 gst_rtspsrc_do_stream_eos (src, stream);
2647 on_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
2649 GstRTSPSrc *src = stream->parent;
2652 g_object_get (source, "ssrc", &ssrc, NULL);
2654 GST_WARNING_OBJECT (src, "source %08x, stream %08x in session %u timed out",
2655 ssrc, stream->ssrc, stream->id);
2657 if (ssrc == stream->ssrc)
2658 gst_rtspsrc_do_stream_eos (src, stream);
2662 on_npt_stop (GstElement * rtpbin, guint session, guint ssrc, GstRTSPSrc * src)
2664 GstRTSPStream *stream;
2666 GST_DEBUG_OBJECT (src, "source in session %u reached NPT stop", session);
2668 /* get stream for session */
2669 stream = find_stream (src, &session, (gpointer) find_stream_by_id);
2671 gst_rtspsrc_do_stream_eos (src, stream);
2676 on_ssrc_active (GObject * session, GObject * source, GstRTSPStream * stream)
2678 GST_DEBUG_OBJECT (stream->parent, "source in session %u is active",
2683 set_manager_buffer_mode (GstRTSPSrc * src)
2685 GObjectClass *klass;
2687 if (src->manager == NULL)
2690 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
2692 if (!g_object_class_find_property (klass, "buffer-mode"))
2695 if (src->buffer_mode != BUFFER_MODE_AUTO) {
2696 g_object_set (src->manager, "buffer-mode", src->buffer_mode, NULL);
2701 GST_DEBUG_OBJECT (src,
2702 "auto buffering mode, have clock %" GST_PTR_FORMAT, src->provided_clock);
2704 if (src->provided_clock) {
2705 GstClock *clock = gst_element_get_clock (GST_ELEMENT_CAST (src));
2707 if (clock == src->provided_clock) {
2708 GST_DEBUG_OBJECT (src, "selected synced");
2709 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_SYNCED, NULL);
2712 gst_object_unref (clock);
2717 /* Otherwise fall-through and use another buffer mode */
2719 gst_object_unref (clock);
2722 GST_DEBUG_OBJECT (src, "auto buffering mode");
2723 if (src->use_buffering) {
2724 GST_DEBUG_OBJECT (src, "selected buffer");
2725 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_BUFFER, NULL);
2727 GST_DEBUG_OBJECT (src, "selected slave");
2728 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_SLAVE, NULL);
2733 request_key (GstElement * srtpdec, guint ssrc, GstRTSPStream * stream)
2735 GST_DEBUG ("request key %u", ssrc);
2736 return gst_caps_ref (stream_get_caps_for_pt (stream, stream->default_pt));
2740 request_rtp_decoder (GstElement * rtpbin, guint session, GstRTSPStream * stream)
2742 GST_DEBUG ("decoder session %u, stream %p, %d", session, stream, stream->id);
2743 if (stream->id != session)
2746 if (stream->profile != GST_RTSP_PROFILE_SAVP &&
2747 stream->profile != GST_RTSP_PROFILE_SAVPF)
2750 if (stream->srtpdec == NULL) {
2753 name = g_strdup_printf ("srtpdec_%u", session);
2754 stream->srtpdec = gst_element_factory_make ("srtpdec", name);
2757 g_signal_connect (stream->srtpdec, "request-key",
2758 (GCallback) request_key, stream);
2760 return gst_object_ref (stream->srtpdec);
2764 request_rtcp_encoder (GstElement * rtpbin, guint session,
2765 GstRTSPStream * stream)
2770 GST_DEBUG ("decoder session %u, stream %p, %d", session, stream, stream->id);
2771 if (stream->id != session)
2774 if (stream->profile != GST_RTSP_PROFILE_SAVP &&
2775 stream->profile != GST_RTSP_PROFILE_SAVPF)
2778 if (stream->srtpenc == NULL) {
2781 name = g_strdup_printf ("srtpenc_%u", session);
2782 stream->srtpenc = gst_element_factory_make ("srtpenc", name);
2785 /* get RTCP crypto parameters from caps */
2786 s = gst_caps_get_structure (stream->srtcpparams, 0);
2790 GType ciphertype, authtype;
2791 GValue rtcp_cipher = G_VALUE_INIT, rtcp_auth = G_VALUE_INIT;
2793 ciphertype = g_type_from_name ("GstSrtpCipherType");
2794 authtype = g_type_from_name ("GstSrtpAuthType");
2795 g_value_init (&rtcp_cipher, ciphertype);
2796 g_value_init (&rtcp_auth, authtype);
2798 str = gst_structure_get_string (s, "srtcp-cipher");
2799 gst_value_deserialize (&rtcp_cipher, str);
2800 str = gst_structure_get_string (s, "srtcp-auth");
2801 gst_value_deserialize (&rtcp_auth, str);
2802 gst_structure_get (s, "srtp-key", GST_TYPE_BUFFER, &buf, NULL);
2804 g_object_set_property (G_OBJECT (stream->srtpenc), "rtcp-cipher",
2806 g_object_set_property (G_OBJECT (stream->srtpenc), "rtcp-auth",
2808 g_object_set (stream->srtpenc, "key", buf, NULL);
2810 g_value_unset (&rtcp_cipher);
2811 g_value_unset (&rtcp_auth);
2812 gst_buffer_unref (buf);
2815 name = g_strdup_printf ("rtcp_sink_%d", session);
2816 pad = gst_element_get_request_pad (stream->srtpenc, name);
2818 gst_object_unref (pad);
2820 return gst_object_ref (stream->srtpenc);
2824 request_aux_receiver (GstElement * rtpbin, guint sessid, GstRTSPSrc * src)
2826 GstElement *rtx, *bin;
2829 GstRTSPStream *stream;
2831 stream = find_stream (src, &sessid, (gpointer) find_stream_by_id);
2833 GST_WARNING_OBJECT (src, "Stream %u not found", sessid);
2837 GST_INFO_OBJECT (src, "creating retransmision receiver for session %u "
2838 "with map %" GST_PTR_FORMAT, sessid, stream->rtx_pt_map);
2839 bin = gst_bin_new (NULL);
2840 rtx = gst_element_factory_make ("rtprtxreceive", NULL);
2841 g_object_set (rtx, "payload-type-map", stream->rtx_pt_map, NULL);
2842 gst_bin_add (GST_BIN (bin), rtx);
2844 pad = gst_element_get_static_pad (rtx, "src");
2845 name = g_strdup_printf ("src_%u", sessid);
2846 gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
2848 gst_object_unref (pad);
2850 pad = gst_element_get_static_pad (rtx, "sink");
2851 name = g_strdup_printf ("sink_%u", sessid);
2852 gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
2854 gst_object_unref (pad);
2860 add_retransmission (GstRTSPSrc * src, GstRTSPTransport * transport)
2864 gboolean do_retransmission = FALSE;
2866 if (transport->trans != GST_RTSP_TRANS_RTP)
2868 if (transport->profile != GST_RTSP_PROFILE_AVPF &&
2869 transport->profile != GST_RTSP_PROFILE_SAVPF)
2872 signal_id = g_signal_lookup ("request-aux-receiver",
2873 G_OBJECT_TYPE (src->manager));
2874 /* there's already something connected */
2875 if (g_signal_handler_find (src->manager, G_SIGNAL_MATCH_ID, signal_id, 0,
2876 NULL, NULL, NULL) != 0) {
2877 GST_DEBUG_OBJECT (src, "Not adding RTX AUX element as "
2878 "\"request-aux-receiver\" signal is "
2879 "already used by the application");
2883 /* build the retransmission payload type map */
2884 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2885 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2886 gboolean do_retransmission_stream = FALSE;
2889 if (stream->rtx_pt_map)
2890 gst_structure_free (stream->rtx_pt_map);
2891 stream->rtx_pt_map = gst_structure_new_empty ("application/x-rtp-pt-map");
2893 for (i = 0; i < stream->ptmap->len; i++) {
2894 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
2895 GstStructure *s = gst_caps_get_structure (item->caps, 0);
2896 const gchar *encoding;
2898 /* we only care about RTX streams */
2899 if ((encoding = gst_structure_get_string (s, "encoding-name"))
2900 && g_strcmp0 (encoding, "RTX") == 0) {
2901 const gchar *stream_pt_s;
2904 if (gst_structure_get_int (s, "payload", &rtx_pt)
2905 && (stream_pt_s = gst_structure_get_string (s, "apt"))) {
2908 gst_structure_set (stream->rtx_pt_map, stream_pt_s, G_TYPE_UINT,
2910 do_retransmission_stream = TRUE;
2916 if (do_retransmission_stream) {
2917 GST_DEBUG_OBJECT (src, "built retransmission payload map for stream "
2918 "id %i: %" GST_PTR_FORMAT, stream->id, stream->rtx_pt_map);
2919 do_retransmission = TRUE;
2921 GST_DEBUG_OBJECT (src, "no retransmission payload map for stream "
2922 "id %i", stream->id);
2923 gst_structure_free (stream->rtx_pt_map);
2924 stream->rtx_pt_map = NULL;
2928 if (do_retransmission) {
2929 GST_DEBUG_OBJECT (src, "Enabling retransmissions");
2931 g_object_set (src->manager, "do-retransmission", TRUE, NULL);
2933 /* enable RFC4588 retransmission handling by setting rtprtxreceive
2934 * as the "aux" element of rtpbin */
2935 g_signal_connect (src->manager, "request-aux-receiver",
2936 (GCallback) request_aux_receiver, src);
2938 GST_DEBUG_OBJECT (src,
2939 "Not enabling retransmissions as no stream had a retransmission payload map");
2943 /* try to get and configure a manager */
2945 gst_rtspsrc_stream_configure_manager (GstRTSPSrc * src, GstRTSPStream * stream,
2946 GstRTSPTransport * transport)
2948 const gchar *manager;
2950 GstStateChangeReturn ret;
2952 /* find a manager */
2953 if (gst_rtsp_transport_get_manager (transport->trans, &manager, 0) < 0)
2957 GST_DEBUG_OBJECT (src, "using manager %s", manager);
2959 /* configure the manager */
2960 if (src->manager == NULL) {
2961 GObjectClass *klass;
2963 if (!(src->manager = gst_element_factory_make (manager, "manager"))) {
2965 if (gst_rtsp_transport_get_manager (transport->trans, &manager, 1) < 0)
2969 goto use_no_manager;
2971 if (!(src->manager = gst_element_factory_make (manager, "manager")))
2972 goto manager_failed;
2975 /* we manage this element */
2976 gst_element_set_locked_state (src->manager, TRUE);
2977 gst_bin_add (GST_BIN_CAST (src), src->manager);
2979 ret = gst_element_set_state (src->manager, GST_STATE_PAUSED);
2980 if (ret == GST_STATE_CHANGE_FAILURE)
2981 goto start_manager_failure;
2983 g_object_set (src->manager, "latency", src->latency, NULL);
2985 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
2987 if (g_object_class_find_property (klass, "ntp-sync")) {
2988 g_object_set (src->manager, "ntp-sync", src->ntp_sync, NULL);
2991 if (src->use_pipeline_clock) {
2992 if (g_object_class_find_property (klass, "use-pipeline-clock")) {
2993 g_object_set (src->manager, "use-pipeline-clock", TRUE, NULL);
2996 if (g_object_class_find_property (klass, "ntp-time-source")) {
2997 g_object_set (src->manager, "ntp-time-source", src->ntp_time_source,
3002 if (src->sdes && g_object_class_find_property (klass, "sdes")) {
3003 g_object_set (src->manager, "sdes", src->sdes, NULL);
3006 if (g_object_class_find_property (klass, "drop-on-latency")) {
3007 g_object_set (src->manager, "drop-on-latency", src->drop_on_latency,
3011 if (g_object_class_find_property (klass, "max-rtcp-rtp-time-diff")) {
3012 g_object_set (src->manager, "max-rtcp-rtp-time-diff",
3013 src->max_rtcp_rtp_time_diff, NULL);
3016 /* buffer mode pauses are handled by adding offsets to buffer times,
3017 * but some depayloaders may have a hard time syncing output times
3018 * with such input times, e.g. container ones, most notably ASF */
3019 /* TODO alternatives are having an event that indicates these shifts,
3020 * or having rtsp extensions provide suggestion on buffer mode */
3021 /* valid duration implies not likely live pipeline,
3022 * so slaving in jitterbuffer does not make much sense
3023 * (and might mess things up due to bursts) */
3024 if (GST_CLOCK_TIME_IS_VALID (src->segment.duration) &&
3025 src->segment.duration && stream->container) {
3026 src->use_buffering = TRUE;
3028 src->use_buffering = FALSE;
3031 set_manager_buffer_mode (src);
3033 /* connect to signals */
3034 GST_DEBUG_OBJECT (src, "connect to signals on session manager, stream %p",
3036 src->manager_sig_id =
3037 g_signal_connect (src->manager, "pad-added",
3038 (GCallback) new_manager_pad, src);
3039 src->manager_ptmap_id =
3040 g_signal_connect (src->manager, "request-pt-map",
3041 (GCallback) request_pt_map, src);
3043 g_signal_connect (src->manager, "on-npt-stop", (GCallback) on_npt_stop,
3046 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_NEW_MANAGER], 0,
3049 if (src->do_retransmission)
3050 add_retransmission (src, transport);
3052 g_signal_connect (src->manager, "request-rtp-decoder",
3053 (GCallback) request_rtp_decoder, stream);
3054 g_signal_connect (src->manager, "request-rtcp-decoder",
3055 (GCallback) request_rtp_decoder, stream);
3056 g_signal_connect (src->manager, "request-rtcp-encoder",
3057 (GCallback) request_rtcp_encoder, stream);
3059 /* we stream directly to the manager, get some pads. Each RTSP stream goes
3060 * into a separate RTP session. */
3061 name = g_strdup_printf ("recv_rtp_sink_%u", stream->id);
3062 stream->channelpad[0] = gst_element_get_request_pad (src->manager, name);
3064 name = g_strdup_printf ("recv_rtcp_sink_%u", stream->id);
3065 stream->channelpad[1] = gst_element_get_request_pad (src->manager, name);
3068 /* now configure the bandwidth in the manager */
3069 if (g_signal_lookup ("get-internal-session",
3070 G_OBJECT_TYPE (src->manager)) != 0) {
3071 GObject *rtpsession;
3073 g_signal_emit_by_name (src->manager, "get-internal-session", stream->id,
3076 GstRTPProfile rtp_profile;
3078 GST_INFO_OBJECT (src, "configure bandwidth in session %p", rtpsession);
3080 stream->session = rtpsession;
3082 if (stream->as_bandwidth != -1) {
3083 GST_INFO_OBJECT (src, "setting AS: %f",
3084 (gdouble) (stream->as_bandwidth * 1000));
3085 g_object_set (rtpsession, "bandwidth",
3086 (gdouble) (stream->as_bandwidth * 1000), NULL);
3088 if (stream->rr_bandwidth != -1) {
3089 GST_INFO_OBJECT (src, "setting RR: %u", stream->rr_bandwidth);
3090 g_object_set (rtpsession, "rtcp-rr-bandwidth", stream->rr_bandwidth,
3093 if (stream->rs_bandwidth != -1) {
3094 GST_INFO_OBJECT (src, "setting RS: %u", stream->rs_bandwidth);
3095 g_object_set (rtpsession, "rtcp-rs-bandwidth", stream->rs_bandwidth,
3099 switch (stream->profile) {
3100 case GST_RTSP_PROFILE_AVPF:
3101 rtp_profile = GST_RTP_PROFILE_AVPF;
3103 case GST_RTSP_PROFILE_SAVP:
3104 rtp_profile = GST_RTP_PROFILE_SAVP;
3106 case GST_RTSP_PROFILE_SAVPF:
3107 rtp_profile = GST_RTP_PROFILE_SAVPF;
3109 case GST_RTSP_PROFILE_AVP:
3111 rtp_profile = GST_RTP_PROFILE_AVP;
3115 g_object_set (rtpsession, "rtp-profile", rtp_profile, NULL);
3117 g_object_set (rtpsession, "probation", src->probation, NULL);
3119 g_object_set (rtpsession, "internal-ssrc", stream->send_ssrc, NULL);
3121 g_signal_connect (rtpsession, "on-bye-ssrc", (GCallback) on_bye_ssrc,
3123 g_signal_connect (rtpsession, "on-bye-timeout", (GCallback) on_timeout,
3125 g_signal_connect (rtpsession, "on-timeout", (GCallback) on_timeout,
3127 g_signal_connect (rtpsession, "on-ssrc-active",
3128 (GCallback) on_ssrc_active, stream);
3139 GST_DEBUG_OBJECT (src, "cannot get a session manager");
3144 GST_DEBUG_OBJECT (src, "no session manager element %s found", manager);
3147 start_manager_failure:
3149 GST_DEBUG_OBJECT (src, "could not start session manager");
3154 /* free the UDP sources allocated when negotiating a transport.
3155 * This function is called when the server negotiated to a transport where the
3156 * UDP sources are not needed anymore, such as TCP or multicast. */
3158 gst_rtspsrc_stream_free_udp (GstRTSPStream * stream)
3162 for (i = 0; i < 2; i++) {
3163 if (stream->udpsrc[i]) {
3164 GST_DEBUG ("free UDP source %d for stream %p", i, stream);
3165 gst_element_set_state (stream->udpsrc[i], GST_STATE_NULL);
3166 gst_object_unref (stream->udpsrc[i]);
3167 stream->udpsrc[i] = NULL;
3172 /* for TCP, create pads to send and receive data to and from the manager and to
3173 * intercept various events and queries
3176 gst_rtspsrc_stream_configure_tcp (GstRTSPSrc * src, GstRTSPStream * stream,
3177 GstRTSPTransport * transport, GstPad ** outpad)
3180 GstPadTemplate *template;
3181 GstPad *pad0, *pad1;
3183 /* configure for interleaved delivery, nothing needs to be done
3184 * here, the loop function will call the chain functions of the
3185 * session manager. */
3186 stream->channel[0] = transport->interleaved.min;
3187 stream->channel[1] = transport->interleaved.max;
3188 GST_DEBUG_OBJECT (src, "stream %p on channels %d-%d", stream,
3189 stream->channel[0], stream->channel[1]);
3191 /* we can remove the allocated UDP ports now */
3192 gst_rtspsrc_stream_free_udp (stream);
3194 /* no session manager, send data to srcpad directly */
3195 if (!stream->channelpad[0]) {
3196 GST_DEBUG_OBJECT (src, "no manager, creating pad");
3198 /* create a new pad we will use to stream to */
3199 name = g_strdup_printf ("stream_%u", stream->id);
3200 template = gst_static_pad_template_get (&rtptemplate);
3201 stream->channelpad[0] = gst_pad_new_from_template (template, name);
3202 gst_object_unref (template);
3205 /* set caps and activate */
3206 gst_pad_use_fixed_caps (stream->channelpad[0]);
3207 gst_pad_set_active (stream->channelpad[0], TRUE);
3209 *outpad = gst_object_ref (stream->channelpad[0]);
3211 GST_DEBUG_OBJECT (src, "using manager source pad");
3213 template = gst_static_pad_template_get (&anysrctemplate);
3215 /* allocate pads for sending the channel data into the manager */
3216 pad0 = gst_pad_new_from_template (template, "internalsrc_0");
3217 gst_pad_link_full (pad0, stream->channelpad[0], GST_PAD_LINK_CHECK_NOTHING);
3218 gst_object_unref (stream->channelpad[0]);
3219 stream->channelpad[0] = pad0;
3220 gst_pad_set_event_function (pad0, gst_rtspsrc_handle_internal_src_event);
3221 gst_pad_set_query_function (pad0, gst_rtspsrc_handle_internal_src_query);
3222 gst_pad_set_element_private (pad0, src);
3223 gst_pad_set_active (pad0, TRUE);
3225 if (stream->channelpad[1]) {
3226 /* if we have a sinkpad for the other channel, create a pad and link to the
3228 pad1 = gst_pad_new_from_template (template, "internalsrc_1");
3229 gst_pad_set_event_function (pad1, gst_rtspsrc_handle_internal_src_event);
3230 gst_pad_link_full (pad1, stream->channelpad[1],
3231 GST_PAD_LINK_CHECK_NOTHING);
3232 gst_object_unref (stream->channelpad[1]);
3233 stream->channelpad[1] = pad1;
3234 gst_pad_set_active (pad1, TRUE);
3236 gst_object_unref (template);
3238 /* setup RTCP transport back to the server if we have to. */
3239 if (src->manager && src->do_rtcp) {
3242 template = gst_static_pad_template_get (&anysinktemplate);
3244 stream->rtcppad = gst_pad_new_from_template (template, "internalsink_0");
3245 gst_pad_set_chain_function (stream->rtcppad, gst_rtspsrc_sink_chain);
3246 gst_pad_set_element_private (stream->rtcppad, stream);
3247 gst_pad_set_active (stream->rtcppad, TRUE);
3249 /* get session RTCP pad */
3250 name = g_strdup_printf ("send_rtcp_src_%u", stream->id);
3251 pad = gst_element_get_request_pad (src->manager, name);
3256 gst_pad_link_full (pad, stream->rtcppad, GST_PAD_LINK_CHECK_NOTHING);
3257 gst_object_unref (pad);
3260 gst_object_unref (template);
3266 gst_rtspsrc_get_transport_info (GstRTSPSrc * src, GstRTSPStream * stream,
3267 GstRTSPTransport * transport, const gchar ** destination, gint * min,
3268 gint * max, guint * ttl)
3270 if (transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
3272 if (!(*destination = transport->destination))
3273 *destination = stream->destination;
3276 /* transport first */
3277 *min = transport->port.min;
3278 *max = transport->port.max;
3279 if (*min == -1 && *max == -1) {
3280 /* then try from SDP */
3281 if (stream->port != 0) {
3282 *min = stream->port;
3283 *max = stream->port + 1;
3289 if (!(*ttl = transport->ttl))
3294 /* first take the source, then the endpoint to figure out where to send
3296 if (!(*destination = transport->source)) {
3297 if (src->conninfo.connection)
3298 *destination = gst_rtsp_connection_get_ip (src->conninfo.connection);
3299 else if (stream->conninfo.connection)
3301 gst_rtsp_connection_get_ip (stream->conninfo.connection);
3305 /* for unicast we only expect the ports here */
3306 *min = transport->server_port.min;
3307 *max = transport->server_port.max;
3312 /* For multicast create UDP sources and join the multicast group. */
3314 gst_rtspsrc_stream_configure_mcast (GstRTSPSrc * src, GstRTSPStream * stream,
3315 GstRTSPTransport * transport, GstPad ** outpad)
3318 const gchar *destination;
3321 GST_DEBUG_OBJECT (src, "creating UDP sources for multicast");
3323 /* we can remove the allocated UDP ports now */
3324 gst_rtspsrc_stream_free_udp (stream);
3326 gst_rtspsrc_get_transport_info (src, stream, transport, &destination, &min,
3329 /* we need a destination now */
3330 if (destination == NULL)
3331 goto no_destination;
3333 /* we really need ports now or we won't be able to receive anything at all */
3334 if (min == -1 && max == -1)
3337 GST_DEBUG_OBJECT (src, "have destination '%s' and ports (%d)-(%d)",
3338 destination, min, max);
3340 /* creating UDP source for RTP */
3342 uri = g_strdup_printf ("udp://%s:%d", destination, min);
3344 gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
3346 if (stream->udpsrc[0] == NULL)
3349 /* take ownership */
3350 gst_object_ref_sink (stream->udpsrc[0]);
3352 if (src->udp_buffer_size != 0)
3353 g_object_set (G_OBJECT (stream->udpsrc[0]), "buffer-size",
3354 src->udp_buffer_size, NULL);
3356 if (src->multi_iface != NULL)
3357 g_object_set (G_OBJECT (stream->udpsrc[0]), "multicast-iface",
3358 src->multi_iface, NULL);
3361 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
3362 gst_element_set_state (stream->udpsrc[0], GST_STATE_READY);
3365 /* creating another UDP source for RTCP */
3369 uri = g_strdup_printf ("udp://%s:%d", destination, max);
3371 gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
3373 if (stream->udpsrc[1] == NULL)
3376 if (stream->profile == GST_RTSP_PROFILE_SAVP ||
3377 stream->profile == GST_RTSP_PROFILE_SAVPF)
3378 caps = gst_caps_new_empty_simple ("application/x-srtcp");
3380 caps = gst_caps_new_empty_simple ("application/x-rtcp");
3381 g_object_set (stream->udpsrc[1], "caps", caps, NULL);
3382 gst_caps_unref (caps);
3384 /* take ownership */
3385 gst_object_ref_sink (stream->udpsrc[1]);
3387 if (src->multi_iface != NULL)
3388 g_object_set (G_OBJECT (stream->udpsrc[0]), "multicast-iface",
3389 src->multi_iface, NULL);
3391 gst_element_set_state (stream->udpsrc[1], GST_STATE_READY);
3398 GST_DEBUG_OBJECT (src, "no UDP source element found");
3403 GST_DEBUG_OBJECT (src, "no destination found");
3408 GST_DEBUG_OBJECT (src, "no ports found");
3413 /* configure the remainder of the UDP ports */
3415 gst_rtspsrc_stream_configure_udp (GstRTSPSrc * src, GstRTSPStream * stream,
3416 GstRTSPTransport * transport, GstPad ** outpad)
3418 /* we manage the UDP elements now. For unicast, the UDP sources where
3419 * allocated in the stream when we suggested a transport. */
3420 if (stream->udpsrc[0]) {
3423 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
3424 gst_bin_add (GST_BIN_CAST (src), stream->udpsrc[0]);
3426 GST_DEBUG_OBJECT (src, "setting up UDP source");
3428 /* configure a timeout on the UDP port. When the timeout message is
3429 * posted, we assume UDP transport is not possible. We reconnect using TCP
3431 g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout",
3432 src->udp_timeout * 1000, NULL);
3434 if ((caps = stream_get_caps_for_pt (stream, stream->default_pt)))
3435 g_object_set (stream->udpsrc[0], "caps", caps, NULL);
3437 /* get output pad of the UDP source. */
3438 *outpad = gst_element_get_static_pad (stream->udpsrc[0], "src");
3440 /* save it so we can unblock */
3441 stream->blockedpad = *outpad;
3443 /* configure pad block on the pad. As soon as there is dataflow on the
3444 * UDP source, we know that UDP is not blocked by a firewall and we can
3445 * configure all the streams to let the application autoplug decoders. */
3447 gst_pad_add_probe (stream->blockedpad,
3448 GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER |
3449 GST_PAD_PROBE_TYPE_BUFFER_LIST, pad_blocked, src, NULL);
3451 if (stream->channelpad[0]) {
3452 GST_DEBUG_OBJECT (src, "connecting UDP source 0 to manager");
3453 /* configure for UDP delivery, we need to connect the UDP pads to
3454 * the session plugin. */
3455 gst_pad_link_full (*outpad, stream->channelpad[0],
3456 GST_PAD_LINK_CHECK_NOTHING);
3457 gst_object_unref (*outpad);
3459 /* we connected to pad-added signal to get pads from the manager */
3461 GST_DEBUG_OBJECT (src, "using UDP src pad as output");
3466 if (stream->udpsrc[1]) {
3469 gst_element_set_locked_state (stream->udpsrc[1], TRUE);
3470 gst_bin_add (GST_BIN_CAST (src), stream->udpsrc[1]);
3472 if (stream->profile == GST_RTSP_PROFILE_SAVP ||
3473 stream->profile == GST_RTSP_PROFILE_SAVPF)
3474 caps = gst_caps_new_empty_simple ("application/x-srtcp");
3476 caps = gst_caps_new_empty_simple ("application/x-rtcp");
3477 g_object_set (stream->udpsrc[1], "caps", caps, NULL);
3478 gst_caps_unref (caps);
3480 if (stream->channelpad[1]) {
3483 GST_DEBUG_OBJECT (src, "connecting UDP source 1 to manager");
3485 pad = gst_element_get_static_pad (stream->udpsrc[1], "src");
3486 gst_pad_link_full (pad, stream->channelpad[1],
3487 GST_PAD_LINK_CHECK_NOTHING);
3488 gst_object_unref (pad);
3490 /* leave unlinked */
3496 /* configure the UDP sink back to the server for status reports */
3498 gst_rtspsrc_stream_configure_udp_sinks (GstRTSPSrc * src,
3499 GstRTSPStream * stream, GstRTSPTransport * transport)
3502 gint rtp_port, rtcp_port;
3503 gboolean do_rtp, do_rtcp;
3504 const gchar *destination;
3509 /* get transport info */
3510 gst_rtspsrc_get_transport_info (src, stream, transport, &destination,
3511 &rtp_port, &rtcp_port, &ttl);
3513 /* see what we need to do */
3514 do_rtp = (rtp_port != -1);
3515 /* it's possible that the server does not want us to send RTCP in which case
3517 do_rtcp = (rtcp_port != -1 && src->manager != NULL && src->do_rtcp);
3519 /* we need a destination when we have RTP or RTCP ports */
3520 if (destination == NULL && (do_rtp || do_rtcp))
3521 goto no_destination;
3523 /* try to construct the fakesrc to the RTP port of the server to open up any
3526 GST_DEBUG_OBJECT (src, "configure RTP UDP sink for %s:%d", destination,
3529 uri = g_strdup_printf ("udp://%s:%d", destination, rtp_port);
3530 stream->udpsink[0] =
3531 gst_element_make_from_uri (GST_URI_SINK, uri, NULL, NULL);
3533 if (stream->udpsink[0] == NULL)
3534 goto no_sink_element;
3536 /* don't join multicast group, we will have the source socket do that */
3537 /* no sync or async state changes needed */
3538 g_object_set (G_OBJECT (stream->udpsink[0]), "auto-multicast", FALSE,
3539 "loop", FALSE, "sync", FALSE, "async", FALSE, NULL);
3541 g_object_set (G_OBJECT (stream->udpsink[0]), "ttl", ttl, NULL);
3543 if (stream->udpsrc[0]) {
3544 /* configure socket, we give it the same UDP socket as the udpsrc for RTP
3545 * so that NAT firewalls will open a hole for us */
3546 g_object_get (G_OBJECT (stream->udpsrc[0]), "used-socket", &socket, NULL);
3550 GST_DEBUG_OBJECT (src, "RTP UDP src has sock %p", socket);
3551 /* configure socket and make sure udpsink does not close it when shutting
3552 * down, it belongs to udpsrc after all. */
3553 g_object_set (G_OBJECT (stream->udpsink[0]), "socket", socket,
3554 "close-socket", FALSE, NULL);
3555 g_object_unref (socket);
3558 /* the source for the dummy packets to open up NAT */
3559 stream->fakesrc = gst_element_factory_make ("fakesrc", NULL);
3560 if (stream->fakesrc == NULL)
3561 goto no_fakesrc_element;
3563 /* random data in 5 buffers, a size of 200 bytes should be fine */
3564 g_object_set (G_OBJECT (stream->fakesrc), "filltype", 3, "num-buffers", 5,
3565 "sizetype", 2, "sizemax", 200, "silent", TRUE, NULL);
3567 /* we don't want to consider this a sink */
3568 GST_OBJECT_FLAG_UNSET (stream->udpsink[0], GST_ELEMENT_FLAG_SINK);
3570 /* keep everything locked */
3571 gst_element_set_locked_state (stream->udpsink[0], TRUE);
3572 gst_element_set_locked_state (stream->fakesrc, TRUE);
3574 gst_object_ref (stream->udpsink[0]);
3575 gst_bin_add (GST_BIN_CAST (src), stream->udpsink[0]);
3576 gst_object_ref (stream->fakesrc);
3577 gst_bin_add (GST_BIN_CAST (src), stream->fakesrc);
3579 gst_element_link_pads_full (stream->fakesrc, "src", stream->udpsink[0],
3580 "sink", GST_PAD_LINK_CHECK_NOTHING);
3583 GST_DEBUG_OBJECT (src, "configure RTCP UDP sink for %s:%d", destination,
3586 uri = g_strdup_printf ("udp://%s:%d", destination, rtcp_port);
3587 stream->udpsink[1] =
3588 gst_element_make_from_uri (GST_URI_SINK, uri, NULL, NULL);
3590 if (stream->udpsink[1] == NULL)
3591 goto no_sink_element;
3593 /* don't join multicast group, we will have the source socket do that */
3594 /* no sync or async state changes needed */
3595 g_object_set (G_OBJECT (stream->udpsink[1]), "auto-multicast", FALSE,
3596 "loop", FALSE, "sync", FALSE, "async", FALSE, NULL);
3598 g_object_set (G_OBJECT (stream->udpsink[0]), "ttl", ttl, NULL);
3600 if (stream->udpsrc[1]) {
3601 /* configure socket, we give it the same UDP socket as the udpsrc for RTCP
3602 * because some servers check the port number of where it sends RTCP to identify
3603 * the RTCP packets it receives */
3604 g_object_get (G_OBJECT (stream->udpsrc[1]), "used-socket", &socket, NULL);
3608 GST_DEBUG_OBJECT (src, "RTCP UDP src has sock %p", socket);
3609 /* configure socket and make sure udpsink does not close it when shutting
3610 * down, it belongs to udpsrc after all. */
3611 g_object_set (G_OBJECT (stream->udpsink[1]), "socket", socket,
3612 "close-socket", FALSE, NULL);
3613 g_object_unref (socket);
3616 /* we don't want to consider this a sink */
3617 GST_OBJECT_FLAG_UNSET (stream->udpsink[1], GST_ELEMENT_FLAG_SINK);
3619 /* we keep this playing always */
3620 gst_element_set_locked_state (stream->udpsink[1], TRUE);
3621 gst_element_set_state (stream->udpsink[1], GST_STATE_PLAYING);
3623 gst_object_ref (stream->udpsink[1]);
3624 gst_bin_add (GST_BIN_CAST (src), stream->udpsink[1]);
3626 stream->rtcppad = gst_element_get_static_pad (stream->udpsink[1], "sink");
3628 /* get session RTCP pad */
3629 name = g_strdup_printf ("send_rtcp_src_%u", stream->id);
3630 pad = gst_element_get_request_pad (src->manager, name);
3635 gst_pad_link_full (pad, stream->rtcppad, GST_PAD_LINK_CHECK_NOTHING);
3636 gst_object_unref (pad);
3645 GST_ERROR_OBJECT (src, "no destination address specified");
3650 GST_ERROR_OBJECT (src, "no UDP sink element found");
3655 GST_ERROR_OBJECT (src, "no fakesrc element found");
3660 GST_ERROR_OBJECT (src, "failed to create socket");
3665 /* sets up all elements needed for streaming over the specified transport.
3666 * Does not yet expose the element pads, this will be done when there is actuall
3667 * dataflow detected, which might never happen when UDP is blocked in a
3668 * firewall, for example.
3671 gst_rtspsrc_stream_configure_transport (GstRTSPStream * stream,
3672 GstRTSPTransport * transport)
3675 GstPad *outpad = NULL;
3676 GstPadTemplate *template;
3678 const gchar *media_type;
3681 src = stream->parent;
3683 GST_DEBUG_OBJECT (src, "configuring transport for stream %p", stream);
3685 /* get the proper media type for this stream now */
3686 if (gst_rtsp_transport_get_media_type (transport, &media_type) < 0)
3687 goto unknown_transport;
3689 goto unknown_transport;
3691 /* configure the final media type */
3692 GST_DEBUG_OBJECT (src, "setting media type to %s", media_type);
3694 len = stream->ptmap->len;
3695 for (i = 0; i < len; i++) {
3697 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
3699 if (item->caps == NULL)
3702 s = gst_caps_get_structure (item->caps, 0);
3703 gst_structure_set_name (s, media_type);
3704 /* set ssrc if known */
3705 if (transport->ssrc)
3706 gst_structure_set (s, "ssrc", G_TYPE_UINT, transport->ssrc, NULL);
3709 /* try to get and configure a manager, channelpad[0-1] will be configured with
3710 * the pads for the manager, or NULL when no manager is needed. */
3711 if (!gst_rtspsrc_stream_configure_manager (src, stream, transport))
3714 switch (transport->lower_transport) {
3715 case GST_RTSP_LOWER_TRANS_TCP:
3716 if (!gst_rtspsrc_stream_configure_tcp (src, stream, transport, &outpad))
3717 goto transport_failed;
3719 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
3720 if (!gst_rtspsrc_stream_configure_mcast (src, stream, transport, &outpad))
3721 goto transport_failed;
3722 /* fallthrough, the rest is the same for UDP and MCAST */
3723 case GST_RTSP_LOWER_TRANS_UDP:
3724 if (!gst_rtspsrc_stream_configure_udp (src, stream, transport, &outpad))
3725 goto transport_failed;
3726 /* configure udpsinks back to the server for RTCP messages and for the
3727 * dummy RTP messages to open NAT. */
3728 if (!gst_rtspsrc_stream_configure_udp_sinks (src, stream, transport))
3729 goto transport_failed;
3732 goto unknown_transport;
3736 GST_DEBUG_OBJECT (src, "creating ghostpad");
3738 gst_pad_use_fixed_caps (outpad);
3740 /* create ghostpad, don't add just yet, this will be done when we activate
3742 name = g_strdup_printf ("stream_%u", stream->id);
3743 template = gst_static_pad_template_get (&rtptemplate);
3744 stream->srcpad = gst_ghost_pad_new_from_template (name, outpad, template);
3745 gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
3746 gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
3747 gst_object_unref (template);
3750 gst_object_unref (outpad);
3752 /* mark pad as ok */
3753 stream->last_ret = GST_FLOW_OK;
3760 GST_DEBUG_OBJECT (src, "failed to configure transport");
3765 GST_DEBUG_OBJECT (src, "unknown transport");
3770 GST_DEBUG_OBJECT (src, "cannot get a session manager");
3775 /* send a couple of dummy random packets on the receiver RTP port to the server,
3776 * this should make a firewall think we initiated the data transfer and
3777 * hopefully allow packets to go from the sender port to our RTP receiver port */
3779 gst_rtspsrc_send_dummy_packets (GstRTSPSrc * src)
3783 if (src->nat_method != GST_RTSP_NAT_DUMMY)
3786 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3787 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3789 if (stream->fakesrc && stream->udpsink[0]) {
3790 GST_DEBUG_OBJECT (src, "sending dummy packet to stream %p", stream);
3791 gst_element_set_state (stream->udpsink[0], GST_STATE_NULL);
3792 gst_element_set_state (stream->fakesrc, GST_STATE_NULL);
3793 gst_element_set_state (stream->udpsink[0], GST_STATE_PLAYING);
3794 gst_element_set_state (stream->fakesrc, GST_STATE_PLAYING);
3800 /* Adds the source pads of all configured streams to the element.
3801 * This code is performed when we detected dataflow.
3803 * We detect dataflow from either the _loop function or with pad probes on the
3807 gst_rtspsrc_activate_streams (GstRTSPSrc * src)
3811 GST_DEBUG_OBJECT (src, "activating streams");
3813 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3814 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3816 if (stream->udpsrc[0]) {
3817 /* remove timeout, we are streaming now and timeouts will be handled by
3818 * the session manager and jitter buffer */
3819 g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout", (guint64) 0, NULL);
3821 if (stream->srcpad) {
3822 GST_DEBUG_OBJECT (src, "activating stream pad %p", stream);
3823 gst_pad_set_active (stream->srcpad, TRUE);
3825 /* if we don't have a session manager, set the caps now. If we have a
3826 * session, we will get a notification of the pad and the caps. */
3827 if (!src->manager) {
3830 caps = stream_get_caps_for_pt (stream, stream->default_pt);
3831 GST_DEBUG_OBJECT (src, "setting pad caps for stream %p", stream);
3832 gst_pad_set_caps (stream->srcpad, caps);
3835 if (!stream->added) {
3836 GST_DEBUG_OBJECT (src, "adding stream pad %p", stream);
3837 gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
3838 stream->added = TRUE;
3843 /* unblock all pads */
3844 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3845 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3847 if (stream->blockid) {
3848 GST_DEBUG_OBJECT (src, "unblocking stream pad %p", stream);
3849 gst_pad_remove_probe (stream->blockedpad, stream->blockid);
3850 stream->blockid = 0;
3858 gst_rtspsrc_configure_caps (GstRTSPSrc * src, GstSegment * segment,
3859 gboolean reset_manager)
3862 guint64 start, stop;
3863 gdouble play_speed, play_scale;
3865 GST_DEBUG_OBJECT (src, "configuring stream caps");
3867 start = segment->position;
3868 stop = segment->duration;
3869 play_speed = segment->rate;
3870 play_scale = segment->applied_rate;
3872 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3873 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3879 len = stream->ptmap->len;
3880 for (j = 0; j < len; j++) {
3882 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, j);
3884 if (item->caps == NULL)
3887 caps = gst_caps_make_writable (item->caps);
3889 if (stream->timebase != -1)
3890 gst_caps_set_simple (caps, "clock-base", G_TYPE_UINT,
3891 (guint) stream->timebase, NULL);
3892 if (stream->seqbase != -1)
3893 gst_caps_set_simple (caps, "seqnum-base", G_TYPE_UINT,
3894 (guint) stream->seqbase, NULL);
3895 gst_caps_set_simple (caps, "npt-start", G_TYPE_UINT64, start, NULL);
3897 gst_caps_set_simple (caps, "npt-stop", G_TYPE_UINT64, stop, NULL);
3898 gst_caps_set_simple (caps, "play-speed", G_TYPE_DOUBLE, play_speed, NULL);
3899 gst_caps_set_simple (caps, "play-scale", G_TYPE_DOUBLE, play_scale, NULL);
3902 GST_DEBUG_OBJECT (src, "stream %p, pt %d, caps %" GST_PTR_FORMAT, stream,
3905 if (item->pt == stream->default_pt && stream->udpsrc[0]) {
3906 g_object_set (stream->udpsrc[0], "caps", caps, NULL);
3910 if (reset_manager && src->manager) {
3911 GST_DEBUG_OBJECT (src, "clear session");
3912 g_signal_emit_by_name (src->manager, "clear-pt-map", NULL);
3916 static GstFlowReturn
3917 gst_rtspsrc_combine_flows (GstRTSPSrc * src, GstRTSPStream * stream,
3922 /* store the value */
3923 stream->last_ret = ret;
3925 /* if it's success we can return the value right away */
3926 if (ret == GST_FLOW_OK)
3929 /* any other error that is not-linked can be returned right
3931 if (ret != GST_FLOW_NOT_LINKED)
3934 /* only return NOT_LINKED if all other pads returned NOT_LINKED */
3935 for (streams = src->streams; streams; streams = g_list_next (streams)) {
3936 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
3938 ret = ostream->last_ret;
3939 /* some other return value (must be SUCCESS but we can return
3940 * other values as well) */
3941 if (ret != GST_FLOW_NOT_LINKED)
3944 /* if we get here, all other pads were unlinked and we return
3945 * NOT_LINKED then */
3951 gst_rtspsrc_stream_push_event (GstRTSPSrc * src, GstRTSPStream * stream,
3954 gboolean res = TRUE;
3956 /* only streams that have a connection to the outside world */
3960 if (stream->udpsrc[0]) {
3961 gst_event_ref (event);
3962 res = gst_element_send_event (stream->udpsrc[0], event);
3963 } else if (stream->channelpad[0]) {
3964 gst_event_ref (event);
3965 if (GST_PAD_IS_SRC (stream->channelpad[0]))
3966 res = gst_pad_push_event (stream->channelpad[0], event);
3968 res = gst_pad_send_event (stream->channelpad[0], event);
3971 if (stream->udpsrc[1]) {
3972 gst_event_ref (event);
3973 res &= gst_element_send_event (stream->udpsrc[1], event);
3974 } else if (stream->channelpad[1]) {
3975 gst_event_ref (event);
3976 if (GST_PAD_IS_SRC (stream->channelpad[1]))
3977 res &= gst_pad_push_event (stream->channelpad[1], event);
3979 res &= gst_pad_send_event (stream->channelpad[1], event);
3983 gst_event_unref (event);
3989 gst_rtspsrc_push_event (GstRTSPSrc * src, GstEvent * event)
3992 gboolean res = TRUE;
3994 for (streams = src->streams; streams; streams = g_list_next (streams)) {
3995 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
3997 gst_event_ref (event);
3998 res &= gst_rtspsrc_stream_push_event (src, ostream, event);
4000 gst_event_unref (event);
4005 static GstRTSPResult
4006 gst_rtsp_conninfo_connect (GstRTSPSrc * src, GstRTSPConnInfo * info,
4010 GstRTSPMessage response;
4011 gboolean retry = FALSE;
4012 memset (&response, 0, sizeof (response));
4013 gst_rtsp_message_init (&response);
4015 if (info->connection == NULL) {
4016 if (info->url == NULL) {
4017 GST_DEBUG_OBJECT (src, "parsing uri (%s)...", info->location);
4018 if ((res = gst_rtsp_url_parse (info->location, &info->url)) < 0)
4021 /* create connection */
4022 GST_DEBUG_OBJECT (src, "creating connection (%s)...", info->location);
4023 if ((res = gst_rtsp_connection_create (info->url, &info->connection)) < 0)
4024 goto could_not_create;
4027 gst_rtspsrc_setup_auth (src, &response);
4030 g_free (info->url_str);
4031 info->url_str = gst_rtsp_url_get_request_uri (info->url);
4033 GST_DEBUG_OBJECT (src, "sanitized uri %s", info->url_str);
4035 if (info->url->transports & GST_RTSP_LOWER_TRANS_TLS) {
4036 if (!gst_rtsp_connection_set_tls_validation_flags (info->connection,
4037 src->tls_validation_flags))
4038 GST_WARNING_OBJECT (src, "Unable to set TLS validation flags");
4040 if (src->tls_database)
4041 gst_rtsp_connection_set_tls_database (info->connection,
4044 if (src->tls_interaction)
4045 gst_rtsp_connection_set_tls_interaction (info->connection,
4046 src->tls_interaction);
4049 if (info->url->transports & GST_RTSP_LOWER_TRANS_HTTP)
4050 gst_rtsp_connection_set_tunneled (info->connection, TRUE);
4052 if (src->proxy_host) {
4053 GST_DEBUG_OBJECT (src, "setting proxy %s:%d", src->proxy_host,
4055 gst_rtsp_connection_set_proxy (info->connection, src->proxy_host,
4060 if (!info->connected) {
4063 GST_ELEMENT_PROGRESS (src, CONTINUE, "connect",
4064 ("Connecting to %s", info->location));
4065 GST_DEBUG_OBJECT (src, "connecting (%s)...", info->location);
4066 res = gst_rtsp_connection_connect_with_response (info->connection,
4067 src->ptcp_timeout, &response);
4069 if (response.type == GST_RTSP_MESSAGE_HTTP_RESPONSE &&
4070 response.type_data.response.code == GST_RTSP_STS_UNAUTHORIZED) {
4071 gst_rtsp_conninfo_close (src, info, TRUE);
4075 retry = FALSE; // we should not retry more than once
4080 if (res == GST_RTSP_OK)
4081 info->connected = TRUE;
4083 goto could_not_connect;
4085 } while (!info->connected && retry);
4086 gst_rtsp_message_unset (&response);
4092 GST_ERROR_OBJECT (src, "No valid RTSP URL was provided");
4093 gst_rtsp_message_unset (&response);
4098 gchar *str = gst_rtsp_strresult (res);
4099 GST_ERROR_OBJECT (src, "Could not create connection. (%s)", str);
4101 gst_rtsp_message_unset (&response);
4106 gchar *str = gst_rtsp_strresult (res);
4107 GST_ERROR_OBJECT (src, "Could not connect to server. (%s)", str);
4109 gst_rtsp_message_unset (&response);
4114 static GstRTSPResult
4115 gst_rtsp_conninfo_close (GstRTSPSrc * src, GstRTSPConnInfo * info,
4118 GST_RTSP_STATE_LOCK (src);
4119 if (info->connected) {
4120 GST_DEBUG_OBJECT (src, "closing connection...");
4121 gst_rtsp_connection_close (info->connection);
4122 info->connected = FALSE;
4124 if (free && info->connection) {
4125 /* free connection */
4126 GST_DEBUG_OBJECT (src, "freeing connection...");
4127 gst_rtsp_connection_free (info->connection);
4128 info->connection = NULL;
4130 GST_RTSP_STATE_UNLOCK (src);
4134 static GstRTSPResult
4135 gst_rtsp_conninfo_reconnect (GstRTSPSrc * src, GstRTSPConnInfo * info,
4140 GST_DEBUG_OBJECT (src, "reconnecting connection...");
4141 gst_rtsp_conninfo_close (src, info, FALSE);
4142 res = gst_rtsp_conninfo_connect (src, info, async);
4148 gst_rtspsrc_connection_flush (GstRTSPSrc * src, gboolean flush)
4152 GST_DEBUG_OBJECT (src, "set flushing %d", flush);
4153 GST_RTSP_STATE_LOCK (src);
4154 if (src->conninfo.connection && src->conninfo.flushing != flush) {
4155 GST_DEBUG_OBJECT (src, "connection flush");
4156 gst_rtsp_connection_flush (src->conninfo.connection, flush);
4157 src->conninfo.flushing = flush;
4159 for (walk = src->streams; walk; walk = g_list_next (walk)) {
4160 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
4161 if (stream->conninfo.connection && stream->conninfo.flushing != flush) {
4162 GST_DEBUG_OBJECT (src, "stream %p flush", stream);
4163 gst_rtsp_connection_flush (stream->conninfo.connection, flush);
4164 stream->conninfo.flushing = flush;
4167 GST_RTSP_STATE_UNLOCK (src);
4170 static GstRTSPResult
4171 gst_rtspsrc_init_request (GstRTSPSrc * src, GstRTSPMessage * msg,
4172 GstRTSPMethod method, const gchar * uri)
4176 res = gst_rtsp_message_init_request (msg, method, uri);
4180 /* set user-agent */
4181 if (src->user_agent)
4182 gst_rtsp_message_add_header (msg, GST_RTSP_HDR_USER_AGENT, src->user_agent);
4187 /* FIXME, handle server request, reply with OK, for now */
4188 static GstRTSPResult
4189 gst_rtspsrc_handle_request (GstRTSPSrc * src, GstRTSPConnection * conn,
4190 GstRTSPMessage * request)
4192 GstRTSPMessage response = { 0 };
4195 GST_DEBUG_OBJECT (src, "got server request message");
4198 gst_rtsp_message_dump (request);
4200 res = gst_rtsp_ext_list_receive_request (src->extensions, request);
4202 if (res == GST_RTSP_ENOTIMPL) {
4203 /* default implementation, send OK */
4204 GST_DEBUG_OBJECT (src, "prepare OK reply");
4206 gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK, "OK",
4211 /* let app parse and reply */
4212 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_HANDLE_REQUEST],
4213 0, request, &response);
4216 gst_rtsp_message_dump (&response);
4218 res = gst_rtspsrc_connection_send (src, conn, &response, NULL);
4222 gst_rtsp_message_unset (&response);
4223 } else if (res == GST_RTSP_EEOF)
4231 gst_rtsp_message_unset (&response);
4236 /* send server keep-alive */
4237 static GstRTSPResult
4238 gst_rtspsrc_send_keep_alive (GstRTSPSrc * src)
4240 GstRTSPMessage request = { 0 };
4242 GstRTSPMethod method;
4243 const gchar *control;
4245 if (src->do_rtsp_keep_alive == FALSE) {
4246 GST_DEBUG_OBJECT (src, "do-rtsp-keep-alive is FALSE, not sending.");
4247 gst_rtsp_connection_reset_timeout (src->conninfo.connection);
4251 GST_DEBUG_OBJECT (src, "creating server keep-alive");
4253 /* find a method to use for keep-alive */
4254 if (src->methods & GST_RTSP_GET_PARAMETER)
4255 method = GST_RTSP_GET_PARAMETER;
4257 method = GST_RTSP_OPTIONS;
4259 control = get_aggregate_control (src);
4260 if (control == NULL)
4263 res = gst_rtspsrc_init_request (src, &request, method, control);
4268 gst_rtsp_message_dump (&request);
4271 gst_rtspsrc_connection_send (src, src->conninfo.connection, &request,
4276 gst_rtsp_connection_reset_timeout (src->conninfo.connection);
4277 gst_rtsp_message_unset (&request);
4284 GST_WARNING_OBJECT (src, "no control url to send keepalive");
4289 gchar *str = gst_rtsp_strresult (res);
4291 gst_rtsp_message_unset (&request);
4292 GST_ELEMENT_WARNING (src, RESOURCE, WRITE, (NULL),
4293 ("Could not send keep-alive. (%s)", str));
4299 static GstFlowReturn
4300 gst_rtspsrc_handle_data (GstRTSPSrc * src, GstRTSPMessage * message)
4302 GstFlowReturn ret = GST_FLOW_OK;
4304 GstRTSPStream *stream;
4305 GstPad *outpad = NULL;
4311 channel = message->type_data.data.channel;
4313 stream = find_stream (src, &channel, (gpointer) find_stream_by_channel);
4315 goto unknown_stream;
4317 if (channel == stream->channel[0]) {
4318 outpad = stream->channelpad[0];
4320 } else if (channel == stream->channel[1]) {
4321 outpad = stream->channelpad[1];
4327 /* take a look at the body to figure out what we have */
4328 gst_rtsp_message_get_body (message, &data, &size);
4330 goto invalid_length;
4332 /* channels are not correct on some servers, do extra check */
4333 if (data[1] >= 200 && data[1] <= 204) {
4334 /* hmm RTCP message switch to the RTCP pad of the same stream. */
4335 outpad = stream->channelpad[1];
4339 /* we have no clue what this is, just ignore then. */
4341 goto unknown_stream;
4343 /* take the message body for further processing */
4344 gst_rtsp_message_steal_body (message, &data, &size);
4346 /* strip the trailing \0 */
4349 buf = gst_buffer_new ();
4350 gst_buffer_append_memory (buf,
4351 gst_memory_new_wrapped (0, data, size, 0, size, data, g_free));
4353 /* don't need message anymore */
4354 gst_rtsp_message_unset (message);
4356 GST_DEBUG_OBJECT (src, "pushing data of size %d on channel %d", size,
4359 if (src->need_activate) {
4365 guint group_id = gst_util_group_id_next ();
4367 /* generate an SHA256 sum of the URI */
4368 cs = g_checksum_new (G_CHECKSUM_SHA256);
4369 uri = src->conninfo.location;
4370 g_checksum_update (cs, (const guchar *) uri, strlen (uri));
4372 for (streams = src->streams; streams; streams = g_list_next (streams)) {
4373 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
4377 g_strdup_printf ("%s/%d", g_checksum_get_string (cs), ostream->id);
4378 event = gst_event_new_stream_start (stream_id);
4379 gst_event_set_group_id (event, group_id);
4382 gst_rtspsrc_stream_push_event (src, ostream, event);
4384 if ((caps = stream_get_caps_for_pt (ostream, ostream->default_pt))) {
4385 /* only streams that have a connection to the outside world */
4386 if (ostream->setup) {
4387 if (ostream->udpsrc[0]) {
4388 gst_element_send_event (ostream->udpsrc[0],
4389 gst_event_new_caps (caps));
4390 } else if (ostream->channelpad[0]) {
4391 if (GST_PAD_IS_SRC (ostream->channelpad[0]))
4392 gst_pad_push_event (ostream->channelpad[0],
4393 gst_event_new_caps (caps));
4395 gst_pad_send_event (ostream->channelpad[0],
4396 gst_event_new_caps (caps));
4399 if (ostream->profile == GST_RTSP_PROFILE_SAVP ||
4400 ostream->profile == GST_RTSP_PROFILE_SAVPF)
4401 caps = gst_caps_new_empty_simple ("application/x-srtcp");
4403 caps = gst_caps_new_empty_simple ("application/x-rtcp");
4405 if (ostream->udpsrc[1]) {
4406 gst_element_send_event (ostream->udpsrc[1],
4407 gst_event_new_caps (caps));
4408 } else if (ostream->channelpad[1]) {
4409 if (GST_PAD_IS_SRC (ostream->channelpad[1]))
4410 gst_pad_push_event (ostream->channelpad[1],
4411 gst_event_new_caps (caps));
4413 gst_pad_send_event (ostream->channelpad[1],
4414 gst_event_new_caps (caps));
4417 gst_caps_unref (caps);
4421 g_checksum_free (cs);
4423 gst_rtspsrc_activate_streams (src);
4424 src->need_activate = FALSE;
4425 src->need_segment = TRUE;
4428 if (src->base_time == -1) {
4429 /* Take current running_time. This timestamp will be put on
4430 * the first buffer of each stream because we are a live source and so we
4431 * timestamp with the running_time. When we are dealing with TCP, we also
4432 * only timestamp the first buffer (using the DISCONT flag) because a server
4433 * typically bursts data, for which we don't want to compensate by speeding
4434 * up the media. The other timestamps will be interpollated from this one
4435 * using the RTP timestamps. */
4436 GST_OBJECT_LOCK (src);
4437 if (GST_ELEMENT_CLOCK (src)) {
4439 GstClockTime base_time;
4441 now = gst_clock_get_time (GST_ELEMENT_CLOCK (src));
4442 base_time = GST_ELEMENT_CAST (src)->base_time;
4444 src->base_time = now - base_time;
4446 GST_DEBUG_OBJECT (src, "first buffer at time %" GST_TIME_FORMAT ", base %"
4447 GST_TIME_FORMAT, GST_TIME_ARGS (now), GST_TIME_ARGS (base_time));
4449 GST_OBJECT_UNLOCK (src);
4452 /* If needed send a new segment, don't forget we are live and buffer are
4453 * timestamped with running time */
4454 if (src->need_segment) {
4456 src->need_segment = FALSE;
4457 gst_segment_init (&segment, GST_FORMAT_TIME);
4458 gst_rtspsrc_push_event (src, gst_event_new_segment (&segment));
4461 if (stream->discont && !is_rtcp) {
4462 /* mark first RTP buffer as discont */
4463 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
4464 stream->discont = FALSE;
4465 /* first buffer gets the timestamp, other buffers are not timestamped and
4466 * their presentation time will be interpollated from the rtp timestamps. */
4467 GST_DEBUG_OBJECT (src, "setting timestamp %" GST_TIME_FORMAT,
4468 GST_TIME_ARGS (src->base_time));
4470 GST_BUFFER_TIMESTAMP (buf) = src->base_time;
4473 /* chain to the peer pad */
4474 if (GST_PAD_IS_SINK (outpad))
4475 ret = gst_pad_chain (outpad, buf);
4477 ret = gst_pad_push (outpad, buf);
4480 /* combine all stream flows for the data transport */
4481 ret = gst_rtspsrc_combine_flows (src, stream, ret);
4488 GST_DEBUG_OBJECT (src, "unknown stream on channel %d, ignored", channel);
4489 gst_rtsp_message_unset (message);
4494 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4495 ("Short message received, ignoring."));
4496 gst_rtsp_message_unset (message);
4501 static GstFlowReturn
4502 gst_rtspsrc_loop_interleaved (GstRTSPSrc * src)
4504 GstRTSPMessage message = { 0 };
4506 GstFlowReturn ret = GST_FLOW_OK;
4507 GTimeVal tv_timeout;
4510 /* get the next timeout interval */
4511 gst_rtsp_connection_next_timeout (src->conninfo.connection, &tv_timeout);
4513 /* see if the timeout period expired */
4514 if ((tv_timeout.tv_sec | tv_timeout.tv_usec) == 0) {
4515 GST_DEBUG_OBJECT (src, "timout, sending keep-alive");
4516 /* send keep-alive, only act on interrupt, a warning will be posted for
4518 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
4520 /* get new timeout */
4521 gst_rtsp_connection_next_timeout (src->conninfo.connection, &tv_timeout);
4524 GST_DEBUG_OBJECT (src, "doing receive with timeout %ld seconds, %ld usec",
4525 tv_timeout.tv_sec, tv_timeout.tv_usec);
4527 /* protect the connection with the connection lock so that we can see when
4528 * we are finished doing server communication */
4530 gst_rtspsrc_connection_receive (src, src->conninfo.connection,
4531 &message, src->ptcp_timeout);
4535 GST_DEBUG_OBJECT (src, "we received a server message");
4537 case GST_RTSP_EINTR:
4538 /* we got interrupted this means we need to stop */
4540 case GST_RTSP_ETIMEOUT:
4541 /* no reply, send keep alive */
4542 GST_DEBUG_OBJECT (src, "timeout, sending keep-alive");
4543 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
4547 /* go EOS when the server closed the connection */
4553 switch (message.type) {
4554 case GST_RTSP_MESSAGE_REQUEST:
4555 /* server sends us a request message, handle it */
4557 gst_rtspsrc_handle_request (src, src->conninfo.connection,
4559 if (res == GST_RTSP_EEOF)
4562 goto handle_request_failed;
4564 case GST_RTSP_MESSAGE_RESPONSE:
4565 /* we ignore response messages */
4566 GST_DEBUG_OBJECT (src, "ignoring response message");
4568 gst_rtsp_message_dump (&message);
4570 case GST_RTSP_MESSAGE_DATA:
4571 GST_DEBUG_OBJECT (src, "got data message");
4572 ret = gst_rtspsrc_handle_data (src, &message);
4573 if (ret != GST_FLOW_OK)
4574 goto handle_data_failed;
4577 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
4582 g_assert_not_reached ();
4587 GST_DEBUG_OBJECT (src, "we got an eof from the server");
4588 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4589 ("The server closed the connection."));
4590 src->conninfo.connected = FALSE;
4591 gst_rtsp_message_unset (&message);
4592 return GST_FLOW_EOS;
4596 gst_rtsp_message_unset (&message);
4597 GST_DEBUG_OBJECT (src, "got interrupted");
4598 return GST_FLOW_FLUSHING;
4602 gchar *str = gst_rtsp_strresult (res);
4604 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
4605 ("Could not receive message. (%s)", str));
4608 gst_rtsp_message_unset (&message);
4609 return GST_FLOW_ERROR;
4611 handle_request_failed:
4613 gchar *str = gst_rtsp_strresult (res);
4615 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
4616 ("Could not handle server message. (%s)", str));
4618 gst_rtsp_message_unset (&message);
4619 return GST_FLOW_ERROR;
4623 GST_DEBUG_OBJECT (src, "could no handle data message");
4628 static GstFlowReturn
4629 gst_rtspsrc_loop_udp (GstRTSPSrc * src)
4632 GstRTSPMessage message = { 0 };
4636 GTimeVal tv_timeout;
4638 /* get the next timeout interval */
4639 gst_rtsp_connection_next_timeout (src->conninfo.connection, &tv_timeout);
4641 GST_DEBUG_OBJECT (src, "doing receive with timeout %d seconds",
4642 (gint) tv_timeout.tv_sec);
4644 gst_rtsp_message_unset (&message);
4646 /* we should continue reading the TCP socket because the server might
4647 * send us requests. When the session timeout expires, we need to send a
4648 * keep-alive request to keep the session open. */
4649 res = gst_rtspsrc_connection_receive (src, src->conninfo.connection,
4650 &message, &tv_timeout);
4654 GST_DEBUG_OBJECT (src, "we received a server message");
4656 case GST_RTSP_EINTR:
4657 /* we got interrupted, see what we have to do */
4659 case GST_RTSP_ETIMEOUT:
4660 /* send keep-alive, ignore the result, a warning will be posted. */
4661 GST_DEBUG_OBJECT (src, "timeout, sending keep-alive");
4662 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
4666 /* server closed the connection. not very fatal for UDP, reconnect and
4667 * see what happens. */
4668 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4669 ("The server closed the connection."));
4670 if (src->udp_reconnect) {
4672 gst_rtsp_conninfo_reconnect (src, &src->conninfo, FALSE)) < 0)
4679 GST_DEBUG_OBJECT (src, "An ethernet problem occured.");
4681 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4682 ("Unhandled return value %d.", res));
4686 switch (message.type) {
4687 case GST_RTSP_MESSAGE_REQUEST:
4688 /* server sends us a request message, handle it */
4690 gst_rtspsrc_handle_request (src, src->conninfo.connection,
4692 if (res == GST_RTSP_EEOF)
4695 goto handle_request_failed;
4697 case GST_RTSP_MESSAGE_RESPONSE:
4698 /* we ignore response and data messages */
4699 GST_DEBUG_OBJECT (src, "ignoring response message");
4701 gst_rtsp_message_dump (&message);
4702 if (message.type_data.response.code == GST_RTSP_STS_UNAUTHORIZED) {
4703 GST_DEBUG_OBJECT (src, "but is Unauthorized response ...");
4704 if (gst_rtspsrc_setup_auth (src, &message) && !(retry++)) {
4705 GST_DEBUG_OBJECT (src, "so retrying keep-alive");
4706 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
4713 case GST_RTSP_MESSAGE_DATA:
4714 /* we ignore response and data messages */
4715 GST_DEBUG_OBJECT (src, "ignoring data message");
4718 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
4723 g_assert_not_reached ();
4725 /* we get here when the connection got interrupted */
4728 gst_rtsp_message_unset (&message);
4729 GST_DEBUG_OBJECT (src, "got interrupted");
4730 return GST_FLOW_FLUSHING;
4734 gchar *str = gst_rtsp_strresult (res);
4737 src->conninfo.connected = FALSE;
4738 if (res != GST_RTSP_EINTR) {
4739 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
4740 ("Could not connect to server. (%s)", str));
4742 ret = GST_FLOW_ERROR;
4744 ret = GST_FLOW_FLUSHING;
4750 gchar *str = gst_rtsp_strresult (res);
4752 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
4753 ("Could not receive message. (%s)", str));
4755 return GST_FLOW_ERROR;
4757 handle_request_failed:
4759 gchar *str = gst_rtsp_strresult (res);
4762 gst_rtsp_message_unset (&message);
4763 if (res != GST_RTSP_EINTR) {
4764 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
4765 ("Could not handle server message. (%s)", str));
4767 ret = GST_FLOW_ERROR;
4769 ret = GST_FLOW_FLUSHING;
4775 GST_DEBUG_OBJECT (src, "we got an eof from the server");
4776 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4777 ("The server closed the connection."));
4778 src->conninfo.connected = FALSE;
4779 gst_rtsp_message_unset (&message);
4780 return GST_FLOW_EOS;
4784 static GstRTSPResult
4785 gst_rtspsrc_reconnect (GstRTSPSrc * src, gboolean async)
4787 GstRTSPResult res = GST_RTSP_OK;
4790 GST_DEBUG_OBJECT (src, "doing reconnect");
4792 GST_OBJECT_LOCK (src);
4793 /* only restart when the pads were not yet activated, else we were
4794 * streaming over UDP */
4795 restart = src->need_activate;
4796 GST_OBJECT_UNLOCK (src);
4798 /* no need to restart, we're done */
4802 /* we can try only TCP now */
4803 src->cur_protocols = GST_RTSP_LOWER_TRANS_TCP;
4805 /* close and cleanup our state */
4806 if ((res = gst_rtspsrc_close (src, async, FALSE)) < 0)
4809 /* see if we have TCP left to try. Also don't try TCP when we were configured
4811 if (!(src->protocols & GST_RTSP_LOWER_TRANS_TCP) || src->from_sdp)
4814 /* We post a warning message now to inform the user
4815 * that nothing happened. It's most likely a firewall thing. */
4816 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4817 ("Could not receive any UDP packets for %.4f seconds, maybe your "
4818 "firewall is blocking it. Retrying using a TCP connection.",
4819 gst_guint64_to_gdouble (src->udp_timeout / 1000000.0)));
4821 /* open new connection using tcp */
4822 if (gst_rtspsrc_open (src, async) < 0)
4825 /* start playback */
4826 if (gst_rtspsrc_play (src, &src->segment, async) < 0)
4835 src->cur_protocols = 0;
4836 /* no transport possible, post an error and stop */
4837 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
4838 ("Could not receive any UDP packets for %.4f seconds, maybe your "
4839 "firewall is blocking it. No other protocols to try.",
4840 gst_guint64_to_gdouble (src->udp_timeout / 1000000.0)));
4841 return GST_RTSP_ERROR;
4845 GST_DEBUG_OBJECT (src, "open failed");
4850 GST_DEBUG_OBJECT (src, "play failed");
4856 gst_rtspsrc_loop_start_cmd (GstRTSPSrc * src, gint cmd)
4860 GST_ELEMENT_PROGRESS (src, START, "open", ("Opening Stream"));
4863 GST_ELEMENT_PROGRESS (src, START, "request", ("Sending PLAY request"));
4866 GST_ELEMENT_PROGRESS (src, START, "request", ("Sending PAUSE request"));
4869 GST_ELEMENT_PROGRESS (src, START, "close", ("Closing Stream"));
4877 gst_rtspsrc_loop_complete_cmd (GstRTSPSrc * src, gint cmd)
4881 GST_ELEMENT_PROGRESS (src, COMPLETE, "open", ("Opened Stream"));
4884 GST_ELEMENT_PROGRESS (src, COMPLETE, "request", ("Sent PLAY request"));
4887 GST_ELEMENT_PROGRESS (src, COMPLETE, "request", ("Sent PAUSE request"));
4890 GST_ELEMENT_PROGRESS (src, COMPLETE, "close", ("Closed Stream"));
4898 gst_rtspsrc_loop_cancel_cmd (GstRTSPSrc * src, gint cmd)
4902 GST_ELEMENT_PROGRESS (src, CANCELED, "open", ("Open canceled"));
4905 GST_ELEMENT_PROGRESS (src, CANCELED, "request", ("PLAY canceled"));
4908 GST_ELEMENT_PROGRESS (src, CANCELED, "request", ("PAUSE canceled"));
4911 GST_ELEMENT_PROGRESS (src, CANCELED, "close", ("Close canceled"));
4919 gst_rtspsrc_loop_error_cmd (GstRTSPSrc * src, gint cmd)
4923 GST_ELEMENT_PROGRESS (src, ERROR, "open", ("Open failed"));
4926 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("PLAY failed"));
4929 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("PAUSE failed"));
4932 GST_ELEMENT_PROGRESS (src, ERROR, "close", ("Close failed"));
4940 gst_rtspsrc_loop_end_cmd (GstRTSPSrc * src, gint cmd, GstRTSPResult ret)
4942 if (ret == GST_RTSP_OK)
4943 gst_rtspsrc_loop_complete_cmd (src, cmd);
4944 else if (ret == GST_RTSP_EINTR)
4945 gst_rtspsrc_loop_cancel_cmd (src, cmd);
4947 gst_rtspsrc_loop_error_cmd (src, cmd);
4951 gst_rtspsrc_loop_send_cmd (GstRTSPSrc * src, gint cmd, gint mask)
4954 gboolean flushed = FALSE;
4956 /* start new request */
4957 gst_rtspsrc_loop_start_cmd (src, cmd);
4959 GST_DEBUG_OBJECT (src, "sending cmd %s", cmd_to_string (cmd));
4961 GST_OBJECT_LOCK (src);
4962 old = src->pending_cmd;
4963 if (old == CMD_RECONNECT) {
4964 GST_DEBUG_OBJECT (src, "ignore, we were reconnecting");
4965 cmd = CMD_RECONNECT;
4967 if (old != CMD_WAIT) {
4968 src->pending_cmd = CMD_WAIT;
4969 GST_OBJECT_UNLOCK (src);
4970 /* cancel previous request */
4971 GST_DEBUG_OBJECT (src, "cancel previous request %s", cmd_to_string (old));
4972 gst_rtspsrc_loop_cancel_cmd (src, old);
4973 GST_OBJECT_LOCK (src);
4975 src->pending_cmd = cmd;
4976 /* interrupt if allowed */
4977 if (src->busy_cmd & mask) {
4978 GST_DEBUG_OBJECT (src, "connection flush busy %s",
4979 cmd_to_string (src->busy_cmd));
4980 gst_rtspsrc_connection_flush (src, TRUE);
4983 GST_DEBUG_OBJECT (src, "not interrupting busy cmd %s",
4984 cmd_to_string (src->busy_cmd));
4987 gst_task_start (src->task);
4988 GST_OBJECT_UNLOCK (src);
4994 gst_rtspsrc_loop (GstRTSPSrc * src)
4998 if (!src->conninfo.connection || !src->conninfo.connected)
5001 if (src->interleaved)
5002 ret = gst_rtspsrc_loop_interleaved (src);
5004 ret = gst_rtspsrc_loop_udp (src);
5006 if (ret != GST_FLOW_OK)
5014 GST_WARNING_OBJECT (src, "we are not connected");
5015 ret = GST_FLOW_FLUSHING;
5020 const gchar *reason = gst_flow_get_name (ret);
5022 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
5023 src->running = FALSE;
5024 if (ret == GST_FLOW_EOS) {
5025 /* perform EOS logic */
5026 if (src->segment.flags & GST_SEEK_FLAG_SEGMENT) {
5027 gst_element_post_message (GST_ELEMENT_CAST (src),
5028 gst_message_new_segment_done (GST_OBJECT_CAST (src),
5029 src->segment.format, src->segment.position));
5030 gst_rtspsrc_push_event (src,
5031 gst_event_new_segment_done (src->segment.format,
5032 src->segment.position));
5034 gst_rtspsrc_push_event (src, gst_event_new_eos ());
5036 } else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS) {
5037 /* for fatal errors we post an error message, post the error before the
5038 * EOS so the app knows about the error first. */
5039 GST_ELEMENT_ERROR (src, STREAM, FAILED,
5040 ("Internal data flow error."),
5041 ("streaming task paused, reason %s (%d)", reason, ret));
5042 gst_rtspsrc_push_event (src, gst_event_new_eos ());
5044 gst_rtspsrc_loop_send_cmd (src, CMD_WAIT, CMD_LOOP);
5049 #ifndef GST_DISABLE_GST_DEBUG
5050 static const gchar *
5051 gst_rtsp_auth_method_to_string (GstRTSPAuthMethod method)
5055 while (method != 0) {
5072 static const gchar *
5073 gst_rtspsrc_skip_lws (const gchar * s)
5075 while (g_ascii_isspace (*s))
5080 static const gchar *
5081 gst_rtspsrc_unskip_lws (const gchar * s, const gchar * start)
5083 while (s > start && g_ascii_isspace (*(s - 1)))
5088 static const gchar *
5089 gst_rtspsrc_skip_commas (const gchar * s)
5091 /* The grammar allows for multiple commas */
5092 while (g_ascii_isspace (*s) || *s == ',')
5097 static const gchar *
5098 gst_rtspsrc_skip_item (const gchar * s)
5100 gboolean quoted = FALSE;
5101 const gchar *start = s;
5103 /* A list item ends at the last non-whitespace character
5104 * before a comma which is not inside a quoted-string. Or at
5105 * the end of the string.
5111 if (*s == '\\' && *(s + 1))
5120 return gst_rtspsrc_unskip_lws (s, start);
5124 gst_rtsp_decode_quoted_string (gchar * quoted_string)
5128 src = quoted_string + 1;
5129 dst = quoted_string;
5130 while (*src && *src != '"') {
5131 if (*src == '\\' && *(src + 1))
5138 /* Extract the authentication tokens that the server provided for each method
5139 * into an array of structures and give those to the connection object.
5142 gst_rtspsrc_parse_digest_challenge (GstRTSPConnection * conn,
5143 const gchar * header, gboolean * stale)
5145 GSList *list = NULL, *iter;
5147 gchar *item, *eq, *name_end, *value;
5149 g_return_if_fail (stale != NULL);
5151 gst_rtsp_connection_clear_auth_params (conn);
5154 /* Parse a header whose content is described by RFC2616 as
5155 * "#something", where "something" does not itself contain commas,
5156 * except as part of quoted-strings, into a list of allocated strings.
5158 header = gst_rtspsrc_skip_commas (header);
5160 end = gst_rtspsrc_skip_item (header);
5161 list = g_slist_prepend (list, g_strndup (header, end - header));
5162 header = gst_rtspsrc_skip_commas (end);
5167 list = g_slist_reverse (list);
5168 for (iter = list; iter; iter = iter->next) {
5171 eq = strchr (item, '=');
5173 name_end = (gchar *) gst_rtspsrc_unskip_lws (eq, item);
5174 if (name_end == item) {
5175 /* That's no good... */
5182 value = (gchar *) gst_rtspsrc_skip_lws (eq + 1);
5184 gst_rtsp_decode_quoted_string (value);
5188 if (value && strcmp (item, "stale") == 0 && strcmp (value, "TRUE") == 0)
5190 gst_rtsp_connection_set_auth_param (conn, item, value);
5194 g_slist_free (list);
5197 /* Parse a WWW-Authenticate Response header and determine the
5198 * available authentication methods
5200 * This code should also cope with the fact that each WWW-Authenticate
5201 * header can contain multiple challenge methods + tokens
5203 * At the moment, for Basic auth, we just do a minimal check and don't
5204 * even parse out the realm */
5206 gst_rtspsrc_parse_auth_hdr (gchar * hdr, GstRTSPAuthMethod * methods,
5207 GstRTSPConnection * conn, gboolean * stale)
5211 g_return_if_fail (hdr != NULL);
5212 g_return_if_fail (methods != NULL);
5213 g_return_if_fail (stale != NULL);
5215 /* Skip whitespace at the start of the string */
5216 for (start = hdr; start[0] != '\0' && g_ascii_isspace (start[0]); start++);
5218 if (g_ascii_strncasecmp (start, "basic", 5) == 0)
5219 *methods |= GST_RTSP_AUTH_BASIC;
5220 else if (g_ascii_strncasecmp (start, "digest ", 7) == 0) {
5221 *methods |= GST_RTSP_AUTH_DIGEST;
5222 gst_rtspsrc_parse_digest_challenge (conn, &start[7], stale);
5227 * gst_rtspsrc_setup_auth:
5228 * @src: the rtsp source
5230 * Configure a username and password and auth method on the
5231 * connection object based on a response we received from the
5234 * Currently, this requires that a username and password were supplied
5235 * in the uri. In the future, they may be requested on demand by sending
5236 * a message up the bus.
5238 * Returns: TRUE if authentication information could be set up correctly.
5241 gst_rtspsrc_setup_auth (GstRTSPSrc * src, GstRTSPMessage * response)
5245 GstRTSPAuthMethod avail_methods = GST_RTSP_AUTH_NONE;
5246 GstRTSPAuthMethod method;
5247 GstRTSPResult auth_result;
5249 GstRTSPConnection *conn;
5251 gboolean stale = FALSE;
5253 conn = src->conninfo.connection;
5255 /* Identify the available auth methods and see if any are supported */
5256 if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_WWW_AUTHENTICATE,
5257 &hdr, 0) == GST_RTSP_OK) {
5258 gst_rtspsrc_parse_auth_hdr (hdr, &avail_methods, conn, &stale);
5261 if (avail_methods == GST_RTSP_AUTH_NONE)
5262 goto no_auth_available;
5264 /* For digest auth, if the response indicates that the session
5265 * data are stale, we just update them in the connection object and
5266 * return TRUE to retry the request */
5268 src->tried_url_auth = FALSE;
5270 url = gst_rtsp_connection_get_url (conn);
5272 /* Do we have username and password available? */
5273 if (url != NULL && !src->tried_url_auth && url->user != NULL
5274 && url->passwd != NULL) {
5277 src->tried_url_auth = TRUE;
5278 GST_DEBUG_OBJECT (src,
5279 "Attempting authentication using credentials from the URL");
5281 user = src->user_id;
5282 pass = src->user_pw;
5283 GST_DEBUG_OBJECT (src,
5284 "Attempting authentication using credentials from the properties");
5287 /* FIXME: If the url didn't contain username and password or we tried them
5288 * already, request a username and passwd from the application via some kind
5289 * of credentials request message */
5291 /* If we don't have a username and passwd at this point, bail out. */
5292 if (user == NULL || pass == NULL)
5295 /* Try to configure for each available authentication method, strongest to
5297 for (method = GST_RTSP_AUTH_MAX; method != GST_RTSP_AUTH_NONE; method >>= 1) {
5298 /* Check if this method is available on the server */
5299 if ((method & avail_methods) == 0)
5302 /* Pass the credentials to the connection to try on the next request */
5303 auth_result = gst_rtsp_connection_set_auth (conn, method, user, pass);
5304 /* INVAL indicates an invalid username/passwd were supplied, so we'll just
5305 * ignore it and end up retrying later */
5306 if (auth_result == GST_RTSP_OK || auth_result == GST_RTSP_EINVAL) {
5307 GST_DEBUG_OBJECT (src, "Attempting %s authentication",
5308 gst_rtsp_auth_method_to_string (method));
5313 if (method == GST_RTSP_AUTH_NONE)
5314 goto no_auth_available;
5320 /* Output an error indicating that we couldn't connect because there were
5321 * no supported authentication protocols */
5322 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
5323 ("No supported authentication protocol was found"));
5328 /* We don't fire an error message, we just return FALSE and let the
5329 * normal NOT_AUTHORIZED error be propagated */
5334 static GstRTSPResult
5335 gst_rtspsrc_try_send (GstRTSPSrc * src, GstRTSPConnection * conn,
5336 GstRTSPMessage * request, GstRTSPMessage * response,
5337 GstRTSPStatusCode * code)
5340 GstRTSPStatusCode thecode;
5341 gchar *content_base = NULL;
5345 if (!src->short_header)
5346 gst_rtsp_ext_list_before_send (src->extensions, request);
5348 GST_DEBUG_OBJECT (src, "sending message");
5351 gst_rtsp_message_dump (request);
5353 res = gst_rtspsrc_connection_send (src, conn, request, src->ptcp_timeout);
5357 gst_rtsp_connection_reset_timeout (conn);
5360 res = gst_rtspsrc_connection_receive (src, conn, response, src->ptcp_timeout);
5365 gst_rtsp_message_dump (response);
5367 switch (response->type) {
5368 case GST_RTSP_MESSAGE_REQUEST:
5369 res = gst_rtspsrc_handle_request (src, conn, response);
5370 if (res == GST_RTSP_EEOF)
5373 goto handle_request_failed;
5375 case GST_RTSP_MESSAGE_RESPONSE:
5376 /* ok, a response is good */
5377 GST_DEBUG_OBJECT (src, "received response message");
5379 case GST_RTSP_MESSAGE_DATA:
5380 /* get next response */
5381 GST_DEBUG_OBJECT (src, "handle data response message");
5382 gst_rtspsrc_handle_data (src, response);
5385 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
5390 thecode = response->type_data.response.code;
5392 GST_DEBUG_OBJECT (src, "got response message %d", thecode);
5394 /* if the caller wanted the result code, we store it. */
5398 /* If the request didn't succeed, bail out before doing any more */
5399 if (thecode != GST_RTSP_STS_OK)
5402 /* store new content base if any */
5403 gst_rtsp_message_get_header (response, GST_RTSP_HDR_CONTENT_BASE,
5406 g_free (src->content_base);
5407 src->content_base = g_strdup (content_base);
5409 gst_rtsp_ext_list_after_send (src->extensions, request, response);
5416 gchar *str = gst_rtsp_strresult (res);
5418 if (res != GST_RTSP_EINTR) {
5419 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
5420 ("Could not send message. (%s)", str));
5422 GST_WARNING_OBJECT (src, "send interrupted");
5431 GST_WARNING_OBJECT (src, "server closed connection");
5432 if ((try == 0) && !src->interleaved && src->udp_reconnect) {
5434 /* if reconnect succeeds, try again */
5436 gst_rtsp_conninfo_reconnect (src, &src->conninfo,
5440 /* only try once after reconnect, then fallthrough and error out */
5443 gchar *str = gst_rtsp_strresult (res);
5445 if (res != GST_RTSP_EINTR) {
5446 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5447 ("Could not receive message. (%s)", str));
5449 GST_WARNING_OBJECT (src, "receive interrupted");
5457 handle_request_failed:
5459 /* ERROR was posted */
5460 gst_rtsp_message_unset (response);
5465 GST_DEBUG_OBJECT (src, "we got an eof from the server");
5466 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5467 ("The server closed the connection."));
5468 gst_rtsp_message_unset (response);
5475 * @src: the rtsp source
5476 * @conn: the connection to send on
5477 * @request: must point to a valid request
5478 * @response: must point to an empty #GstRTSPMessage
5479 * @code: an optional code result
5481 * send @request and retrieve the response in @response. optionally @code can be
5482 * non-NULL in which case it will contain the status code of the response.
5484 * If This function returns #GST_RTSP_OK, @response will contain a valid response
5485 * message that should be cleaned with gst_rtsp_message_unset() after usage.
5487 * If @code is NULL, this function will return #GST_RTSP_ERROR (with an invalid
5488 * @response message) if the response code was not 200 (OK).
5490 * If the attempt results in an authentication failure, then this will attempt
5491 * to retrieve authentication credentials via gst_rtspsrc_setup_auth and retry
5494 * Returns: #GST_RTSP_OK if the processing was successful.
5496 static GstRTSPResult
5497 gst_rtspsrc_send (GstRTSPSrc * src, GstRTSPConnection * conn,
5498 GstRTSPMessage * request, GstRTSPMessage * response,
5499 GstRTSPStatusCode * code)
5501 GstRTSPStatusCode int_code = GST_RTSP_STS_OK;
5502 GstRTSPResult res = GST_RTSP_ERROR;
5505 GstRTSPMethod method = GST_RTSP_INVALID;
5511 /* make sure we don't loop forever */
5515 /* save method so we can disable it when the server complains */
5516 method = request->type_data.request.method;
5519 gst_rtspsrc_try_send (src, conn, request, response, &int_code)) < 0)
5523 case GST_RTSP_STS_UNAUTHORIZED:
5524 case GST_RTSP_STS_NOT_FOUND:
5525 if (gst_rtspsrc_setup_auth (src, response)) {
5526 /* Try the request/response again after configuring the auth info
5534 } while (retry == TRUE);
5536 /* If the user requested the code, let them handle errors, otherwise
5537 * post an error below */
5540 else if (int_code != GST_RTSP_STS_OK)
5541 goto error_response;
5548 GST_DEBUG_OBJECT (src, "got error %d", res);
5553 res = GST_RTSP_ERROR;
5555 switch (response->type_data.response.code) {
5556 case GST_RTSP_STS_NOT_FOUND:
5557 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), ("%s",
5558 response->type_data.response.reason));
5560 case GST_RTSP_STS_UNAUTHORIZED:
5561 GST_ELEMENT_ERROR (src, RESOURCE, NOT_AUTHORIZED, (NULL), ("%s",
5562 response->type_data.response.reason));
5564 case GST_RTSP_STS_MOVED_PERMANENTLY:
5565 case GST_RTSP_STS_MOVE_TEMPORARILY:
5567 gchar *new_location;
5568 GstRTSPLowerTrans transports;
5570 GST_DEBUG_OBJECT (src, "got redirection");
5571 /* if we don't have a Location Header, we must error */
5572 if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_LOCATION,
5573 &new_location, 0) < 0)
5576 /* When we receive a redirect result, we go back to the INIT state after
5577 * parsing the new URI. The caller should do the needed steps to issue
5578 * a new setup when it detects this state change. */
5579 GST_DEBUG_OBJECT (src, "redirection to %s", new_location);
5581 /* save current transports */
5582 if (src->conninfo.url)
5583 transports = src->conninfo.url->transports;
5585 transports = GST_RTSP_LOWER_TRANS_UNKNOWN;
5587 gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (src), new_location, NULL);
5589 /* set old transports */
5590 if (src->conninfo.url && transports != GST_RTSP_LOWER_TRANS_UNKNOWN)
5591 src->conninfo.url->transports = transports;
5593 src->need_redirect = TRUE;
5594 src->state = GST_RTSP_STATE_INIT;
5598 case GST_RTSP_STS_NOT_ACCEPTABLE:
5599 case GST_RTSP_STS_NOT_IMPLEMENTED:
5600 case GST_RTSP_STS_METHOD_NOT_ALLOWED:
5601 GST_WARNING_OBJECT (src, "got NOT IMPLEMENTED, disable method %s",
5602 gst_rtsp_method_as_text (method));
5603 src->methods &= ~method;
5607 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5608 ("Got error response: %d (%s).", response->type_data.response.code,
5609 response->type_data.response.reason));
5612 /* if we return ERROR we should unset the response ourselves */
5613 if (res == GST_RTSP_ERROR)
5614 gst_rtsp_message_unset (response);
5620 static GstRTSPResult
5621 gst_rtspsrc_send_cb (GstRTSPExtension * ext, GstRTSPMessage * request,
5622 GstRTSPMessage * response, GstRTSPSrc * src)
5624 return gst_rtspsrc_send (src, src->conninfo.connection, request, response,
5629 /* parse the response and collect all the supported methods. We need this
5630 * information so that we don't try to send an unsupported request to the
5634 gst_rtspsrc_parse_methods (GstRTSPSrc * src, GstRTSPMessage * response)
5636 GstRTSPHeaderField field;
5640 /* reset supported methods */
5643 /* Try Allow Header first */
5644 field = GST_RTSP_HDR_ALLOW;
5647 gst_rtsp_message_get_header (response, field, &respoptions, indx);
5648 if (indx == 0 && !respoptions) {
5649 /* if no Allow header was found then try the Public header... */
5650 field = GST_RTSP_HDR_PUBLIC;
5651 gst_rtsp_message_get_header (response, field, &respoptions, indx);
5656 src->methods |= gst_rtsp_options_from_text (respoptions);
5661 if (src->methods == 0) {
5662 /* neither Allow nor Public are required, assume the server supports
5663 * at least DESCRIBE, SETUP, we always assume it supports PLAY as
5665 GST_DEBUG_OBJECT (src, "could not get OPTIONS");
5666 src->methods = GST_RTSP_DESCRIBE | GST_RTSP_SETUP;
5668 /* always assume PLAY, FIXME, extensions should be able to override
5670 src->methods |= GST_RTSP_PLAY;
5671 /* also assume it will support Range */
5672 src->seekable = TRUE;
5674 /* we need describe and setup */
5675 if (!(src->methods & GST_RTSP_DESCRIBE))
5677 if (!(src->methods & GST_RTSP_SETUP))
5685 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
5686 ("Server does not support DESCRIBE."));
5691 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
5692 ("Server does not support SETUP."));
5697 /* masks to be kept in sync with the hardcoded protocol order of preference
5699 static const guint protocol_masks[] = {
5700 GST_RTSP_LOWER_TRANS_UDP,
5701 GST_RTSP_LOWER_TRANS_UDP_MCAST,
5702 GST_RTSP_LOWER_TRANS_TCP,
5706 static GstRTSPResult
5707 gst_rtspsrc_create_transports_string (GstRTSPSrc * src,
5708 GstRTSPLowerTrans protocols, GstRTSPProfile profile, gchar ** transports)
5712 gboolean add_udp_str;
5717 gst_rtsp_ext_list_get_transports (src->extensions, protocols, transports);
5722 GST_DEBUG_OBJECT (src, "got transports %s", GST_STR_NULL (*transports));
5724 /* extension listed transports, use those */
5725 if (*transports != NULL)
5728 /* it's the default */
5729 add_udp_str = FALSE;
5731 /* the default RTSP transports */
5732 result = g_string_new ("RTP");
5735 case GST_RTSP_PROFILE_AVP:
5736 g_string_append (result, "/AVP");
5738 case GST_RTSP_PROFILE_SAVP:
5739 g_string_append (result, "/SAVP");
5741 case GST_RTSP_PROFILE_AVPF:
5742 g_string_append (result, "/AVPF");
5744 case GST_RTSP_PROFILE_SAVPF:
5745 g_string_append (result, "/SAVPF");
5751 if (protocols & GST_RTSP_LOWER_TRANS_UDP) {
5752 GST_DEBUG_OBJECT (src, "adding UDP unicast");
5754 g_string_append (result, "/UDP");
5755 g_string_append (result, ";unicast;client_port=%%u1-%%u2");
5756 } else if (protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST) {
5757 GST_DEBUG_OBJECT (src, "adding UDP multicast");
5758 /* we don't have to allocate any UDP ports yet, if the selected transport
5759 * turns out to be multicast we can create them and join the multicast
5760 * group indicated in the transport reply */
5762 g_string_append (result, "/UDP");
5763 g_string_append (result, ";multicast");
5764 if (src->next_port_num != 0) {
5765 if (src->client_port_range.max > 0 &&
5766 src->next_port_num >= src->client_port_range.max)
5769 g_string_append_printf (result, ";client_port=%d-%d",
5770 src->next_port_num, src->next_port_num + 1);
5772 } else if (protocols & GST_RTSP_LOWER_TRANS_TCP) {
5773 GST_DEBUG_OBJECT (src, "adding TCP");
5775 g_string_append (result, "/TCP;unicast;interleaved=%%i1-%%i2");
5777 *transports = g_string_free (result, FALSE);
5779 GST_DEBUG_OBJECT (src, "prepared transports %s", GST_STR_NULL (*transports));
5786 GST_ERROR ("extension gave error %d", res);
5791 GST_ERROR ("no more ports available");
5792 return GST_RTSP_ERROR;
5796 static GstRTSPResult
5797 gst_rtspsrc_prepare_transports (GstRTSPStream * stream, gchar ** transports,
5798 gint orig_rtpport, gint orig_rtcpport)
5801 gint nr_udp, nr_int;
5803 gint rtpport = 0, rtcpport = 0;
5806 src = stream->parent;
5808 /* find number of placeholders first */
5809 if (strstr (*transports, "%%i2"))
5811 else if (strstr (*transports, "%%i1"))
5816 if (strstr (*transports, "%%u2"))
5818 else if (strstr (*transports, "%%u1"))
5823 if (nr_udp == 0 && nr_int == 0)
5827 if (!orig_rtpport || !orig_rtcpport) {
5828 if (!gst_rtspsrc_alloc_udp_ports (stream, &rtpport, &rtcpport))
5831 rtpport = orig_rtpport;
5832 rtcpport = orig_rtcpport;
5836 str = g_string_new ("");
5838 while ((next = strstr (p, "%%"))) {
5839 g_string_append_len (str, p, next - p);
5840 if (next[2] == 'u') {
5842 g_string_append_printf (str, "%d", rtpport);
5843 else if (next[3] == '2')
5844 g_string_append_printf (str, "%d", rtcpport);
5846 if (next[2] == 'i') {
5848 g_string_append_printf (str, "%d", src->free_channel);
5849 else if (next[3] == '2')
5850 g_string_append_printf (str, "%d", src->free_channel + 1);
5855 /* append final part */
5856 g_string_append (str, p);
5858 g_free (*transports);
5859 *transports = g_string_free (str, FALSE);
5867 GST_ERROR ("failed to allocate udp ports");
5868 return GST_RTSP_ERROR;
5873 signal_get_srtcp_params (GstRTSPSrc * src, GstRTSPStream * stream)
5875 GstCaps *caps = NULL;
5877 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_REQUEST_RTCP_KEY], 0,
5881 GST_DEBUG_OBJECT (src, "SRTP parameters received");
5887 default_srtcp_params (void)
5894 guint data_size = GST_ROUND_UP_4 (KEY_SIZE);
5896 /* create a random key */
5897 key_data = g_malloc (data_size);
5898 for (i = 0; i < data_size; i += 4)
5899 GST_WRITE_UINT32_BE (key_data + i, g_random_int ());
5901 buf = gst_buffer_new_wrapped (key_data, KEY_SIZE);
5903 caps = gst_caps_new_simple ("application/x-srtp",
5904 "srtp-key", GST_TYPE_BUFFER, buf,
5905 "srtcp-cipher", G_TYPE_STRING, "aes-128-icm",
5906 "srtcp-auth", G_TYPE_STRING, "hmac-sha1-80", NULL);
5908 gst_buffer_unref (buf);
5914 gst_rtspsrc_stream_make_keymgmt (GstRTSPSrc * src, GstRTSPStream * stream)
5916 gchar *base64, *result = NULL;
5917 GstMIKEYMessage *mikey_msg;
5919 stream->srtcpparams = signal_get_srtcp_params (src, stream);
5920 if (stream->srtcpparams == NULL)
5921 stream->srtcpparams = default_srtcp_params ();
5923 mikey_msg = gst_mikey_message_new_from_caps (stream->srtcpparams);
5925 /* add policy '0' for our SSRC */
5926 gst_mikey_message_add_cs_srtp (mikey_msg, 0, stream->send_ssrc, 0);
5928 base64 = gst_mikey_message_base64_encode (mikey_msg);
5929 gst_mikey_message_unref (mikey_msg);
5932 result = gst_sdp_make_keymgmt (stream->conninfo.location, base64);
5940 /* Perform the SETUP request for all the streams.
5942 * We ask the server for a specific transport, which initially includes all the
5943 * ones we can support (UDP/TCP/MULTICAST). For the UDP transport we allocate
5944 * two local UDP ports that we send to the server.
5946 * Once the server replied with a transport, we configure the other streams
5947 * with the same transport.
5949 * This function will also configure the stream for the selected transport,
5950 * which basically means creating the pipeline.
5952 static GstRTSPResult
5953 gst_rtspsrc_setup_streams (GstRTSPSrc * src, gboolean async)
5956 GstRTSPResult res = GST_RTSP_ERROR;
5957 GstRTSPMessage request = { 0 };
5958 GstRTSPMessage response = { 0 };
5959 GstRTSPStream *stream = NULL;
5960 GstRTSPLowerTrans protocols;
5961 GstRTSPStatusCode code;
5962 gboolean unsupported_real = FALSE;
5963 gint rtpport, rtcpport;
5967 if (src->conninfo.connection) {
5968 url = gst_rtsp_connection_get_url (src->conninfo.connection);
5969 /* we initially allow all configured lower transports. based on the URL
5970 * transports and the replies from the server we narrow them down. */
5971 protocols = url->transports & src->cur_protocols;
5974 protocols = src->cur_protocols;
5980 /* reset some state */
5981 src->free_channel = 0;
5982 src->interleaved = FALSE;
5983 src->need_activate = FALSE;
5984 /* keep track of next port number, 0 is random */
5985 src->next_port_num = src->client_port_range.min;
5986 rtpport = rtcpport = 0;
5988 if (G_UNLIKELY (src->streams == NULL))
5991 for (walk = src->streams; walk; walk = g_list_next (walk)) {
5992 GstRTSPConnection *conn;
5999 stream = (GstRTSPStream *) walk->data;
6001 caps = stream_get_caps_for_pt (stream, stream->default_pt);
6003 GST_DEBUG_OBJECT (src, "skipping stream %p, no caps", stream);
6007 if (stream->skipped) {
6008 GST_DEBUG_OBJECT (src, "skipping stream %p", stream);
6012 /* see if we need to configure this stream */
6013 if (!gst_rtsp_ext_list_configure_stream (src->extensions, caps)) {
6014 GST_DEBUG_OBJECT (src, "skipping stream %p, disabled by extension",
6019 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_SELECT_STREAM], 0,
6020 stream->id, caps, &selected);
6022 GST_DEBUG_OBJECT (src, "skipping stream %p, disabled by signal", stream);
6026 /* merge/overwrite global caps */
6031 s = gst_caps_get_structure (caps, 0);
6033 num = gst_structure_n_fields (src->props);
6034 for (j = 0; j < num; j++) {
6038 name = gst_structure_nth_field_name (src->props, j);
6039 val = gst_structure_get_value (src->props, name);
6040 gst_structure_set_value (s, name, val);
6042 GST_DEBUG_OBJECT (src, "copied %s", name);
6046 /* skip setup if we have no URL for it */
6047 if (stream->conninfo.location == NULL) {
6048 GST_DEBUG_OBJECT (src, "skipping stream %p, no setup", stream);
6052 if (src->conninfo.connection == NULL) {
6053 if (!gst_rtsp_conninfo_connect (src, &stream->conninfo, async)) {
6054 GST_DEBUG_OBJECT (src, "skipping stream %p, failed to connect", stream);
6057 conn = stream->conninfo.connection;
6059 conn = src->conninfo.connection;
6061 GST_DEBUG_OBJECT (src, "doing setup of stream %p with %s", stream,
6062 stream->conninfo.location);
6064 /* if we have a multicast connection, only suggest multicast from now on */
6065 if (stream->is_multicast)
6066 protocols &= GST_RTSP_LOWER_TRANS_UDP_MCAST;
6069 /* first selectable protocol */
6070 while (protocol_masks[mask] && !(protocols & protocol_masks[mask]))
6072 if (!protocol_masks[mask])
6076 GST_DEBUG_OBJECT (src, "protocols = 0x%x, protocol mask = 0x%x", protocols,
6077 protocol_masks[mask]);
6078 /* create a string with first transport in line */
6080 res = gst_rtspsrc_create_transports_string (src,
6081 protocols & protocol_masks[mask], stream->profile, &transports);
6082 if (res < 0 || transports == NULL)
6083 goto setup_transport_failed;
6085 if (strlen (transports) == 0) {
6086 g_free (transports);
6087 GST_DEBUG_OBJECT (src, "no transports found");
6092 GST_DEBUG_OBJECT (src, "replace ports in %s", GST_STR_NULL (transports));
6094 /* replace placeholders with real values, this function will optionally
6095 * allocate UDP ports and other info needed to execute the setup request */
6096 res = gst_rtspsrc_prepare_transports (stream, &transports,
6097 retry > 0 ? rtpport : 0, retry > 0 ? rtcpport : 0);
6099 g_free (transports);
6100 goto setup_transport_failed;
6103 GST_DEBUG_OBJECT (src, "transport is now %s", GST_STR_NULL (transports));
6105 /* create SETUP request */
6107 gst_rtspsrc_init_request (src, &request, GST_RTSP_SETUP,
6108 stream->conninfo.location);
6110 g_free (transports);
6111 goto create_request_failed;
6114 /* select transport */
6115 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_TRANSPORT, transports);
6118 if (stream->profile == GST_RTSP_PROFILE_SAVP ||
6119 stream->profile == GST_RTSP_PROFILE_SAVPF) {
6120 hval = gst_rtspsrc_stream_make_keymgmt (src, stream);
6121 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_KEYMGMT, hval);
6124 /* if the user wants a non default RTP packet size we add the blocksize
6126 if (src->rtp_blocksize > 0) {
6127 hval = g_strdup_printf ("%d", src->rtp_blocksize);
6128 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_BLOCKSIZE, hval);
6132 GST_ELEMENT_PROGRESS (src, CONTINUE, "request", ("SETUP stream %d",
6135 /* handle the code ourselves */
6136 res = gst_rtspsrc_send (src, conn, &request, &response, &code);
6141 case GST_RTSP_STS_OK:
6143 case GST_RTSP_STS_UNSUPPORTED_TRANSPORT:
6144 gst_rtsp_message_unset (&request);
6145 gst_rtsp_message_unset (&response);
6146 /* cleanup of leftover transport */
6147 gst_rtspsrc_stream_free_udp (stream);
6148 /* MS WMServer RTSP MUST use same UDP pair in all SETUP requests;
6149 * we might be in this case */
6150 if (stream->container && rtpport && rtcpport && !retry) {
6151 GST_DEBUG_OBJECT (src, "retrying with original port pair %u-%u",
6156 /* this transport did not go down well, but we may have others to try
6157 * that we did not send yet, try those and only give up then
6158 * but not without checking for lost cause/extension so we can
6159 * post a nicer/more useful error message later */
6160 if (!unsupported_real)
6161 unsupported_real = stream->is_real;
6162 /* select next available protocol, give up on this stream if none */
6164 while (protocol_masks[mask] && !(protocols & protocol_masks[mask]))
6166 if (!protocol_masks[mask] || unsupported_real)
6171 /* cleanup of leftover transport and move to the next stream */
6172 gst_rtspsrc_stream_free_udp (stream);
6173 goto response_error;
6176 /* parse response transport */
6178 gchar *resptrans = NULL;
6179 GstRTSPTransport transport = { 0 };
6181 gst_rtsp_message_get_header (&response, GST_RTSP_HDR_TRANSPORT,
6184 gst_rtspsrc_stream_free_udp (stream);
6188 /* parse transport, go to next stream on parse error */
6189 if (gst_rtsp_transport_parse (resptrans, &transport) != GST_RTSP_OK) {
6190 GST_WARNING_OBJECT (src, "failed to parse transport %s", resptrans);
6194 /* update allowed transports for other streams. once the transport of
6195 * one stream has been determined, we make sure that all other streams
6196 * are configured in the same way */
6197 switch (transport.lower_transport) {
6198 case GST_RTSP_LOWER_TRANS_TCP:
6199 GST_DEBUG_OBJECT (src, "stream %p as TCP interleaved", stream);
6200 protocols = GST_RTSP_LOWER_TRANS_TCP;
6201 src->interleaved = TRUE;
6202 /* update free channels */
6204 MAX (transport.interleaved.min, src->free_channel);
6206 MAX (transport.interleaved.max, src->free_channel);
6207 src->free_channel++;
6209 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
6210 /* only allow multicast for other streams */
6211 GST_DEBUG_OBJECT (src, "stream %p as UDP multicast", stream);
6212 protocols = GST_RTSP_LOWER_TRANS_UDP_MCAST;
6213 /* if the server selected our ports, increment our counters so that
6214 * we select a new port later */
6215 if (src->next_port_num == transport.port.min &&
6216 src->next_port_num + 1 == transport.port.max) {
6217 src->next_port_num += 2;
6220 case GST_RTSP_LOWER_TRANS_UDP:
6221 /* only allow unicast for other streams */
6222 GST_DEBUG_OBJECT (src, "stream %p as UDP unicast", stream);
6223 protocols = GST_RTSP_LOWER_TRANS_UDP;
6226 GST_DEBUG_OBJECT (src, "stream %p unknown transport %d", stream,
6227 transport.lower_transport);
6231 if (!src->interleaved || !retry) {
6232 /* now configure the stream with the selected transport */
6233 if (!gst_rtspsrc_stream_configure_transport (stream, &transport)) {
6234 GST_DEBUG_OBJECT (src,
6235 "could not configure stream %p transport, skipping stream",
6238 } else if (stream->udpsrc[0] && stream->udpsrc[1]) {
6239 /* retain the first allocated UDP port pair */
6240 g_object_get (G_OBJECT (stream->udpsrc[0]), "port", &rtpport, NULL);
6241 g_object_get (G_OBJECT (stream->udpsrc[1]), "port", &rtcpport, NULL);
6244 /* we need to activate at least one streams when we detect activity */
6245 src->need_activate = TRUE;
6247 /* stream is setup now */
6248 stream->setup = TRUE;
6253 GstRTSPStream *sskip;
6255 skip = g_list_next (skip);
6259 sskip = (GstRTSPStream *) skip->data;
6261 /* skip all streams with the same control url */
6262 if (g_str_equal (stream->conninfo.location, sskip->conninfo.location)) {
6263 GST_DEBUG_OBJECT (src, "found stream %p with same control %s",
6264 sskip, sskip->conninfo.location);
6265 sskip->skipped = TRUE;
6270 /* clean up our transport struct */
6271 gst_rtsp_transport_init (&transport);
6272 /* clean up used RTSP messages */
6273 gst_rtsp_message_unset (&request);
6274 gst_rtsp_message_unset (&response);
6278 /* store the transport protocol that was configured */
6279 src->cur_protocols = protocols;
6281 gst_rtsp_ext_list_stream_select (src->extensions, url);
6283 /* if there is nothing to activate, error out */
6284 if (!src->need_activate)
6285 goto nothing_to_activate;
6292 /* no transport possible, post an error and stop */
6293 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
6294 ("Could not connect to server, no protocols left"));
6295 return GST_RTSP_ERROR;
6299 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
6300 ("SDP contains no streams"));
6301 return GST_RTSP_ERROR;
6303 create_request_failed:
6305 gchar *str = gst_rtsp_strresult (res);
6307 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
6308 ("Could not create request. (%s)", str));
6312 setup_transport_failed:
6314 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
6315 ("Could not setup transport."));
6316 res = GST_RTSP_ERROR;
6321 const gchar *str = gst_rtsp_status_as_text (code);
6323 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
6324 ("Error (%d): %s", code, GST_STR_NULL (str)));
6325 res = GST_RTSP_ERROR;
6330 gchar *str = gst_rtsp_strresult (res);
6332 if (res != GST_RTSP_EINTR) {
6333 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
6334 ("Could not send message. (%s)", str));
6336 GST_WARNING_OBJECT (src, "send interrupted");
6343 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
6344 ("Server did not select transport."));
6345 res = GST_RTSP_ERROR;
6348 nothing_to_activate:
6350 /* none of the available error codes is really right .. */
6351 if (unsupported_real) {
6352 GST_ELEMENT_ERROR (src, STREAM, CODEC_NOT_FOUND,
6353 (_("No supported stream was found. You might need to install a "
6354 "GStreamer RTSP extension plugin for Real media streams.")),
6357 GST_ELEMENT_ERROR (src, STREAM, CODEC_NOT_FOUND,
6358 (_("No supported stream was found. You might need to allow "
6359 "more transport protocols or may otherwise be missing "
6360 "the right GStreamer RTSP extension plugin.")), (NULL));
6362 return GST_RTSP_ERROR;
6366 gst_rtsp_message_unset (&request);
6367 gst_rtsp_message_unset (&response);
6373 gst_rtspsrc_parse_range (GstRTSPSrc * src, const gchar * range,
6374 GstSegment * segment)
6377 GstRTSPTimeRange *therange;
6380 gst_rtsp_range_free (src->range);
6382 if (gst_rtsp_range_parse (range, &therange) == GST_RTSP_OK) {
6383 GST_DEBUG_OBJECT (src, "parsed range %s", range);
6384 src->range = therange;
6386 GST_DEBUG_OBJECT (src, "failed to parse range %s", range);
6388 gst_segment_init (segment, GST_FORMAT_TIME);
6392 GST_DEBUG_OBJECT (src, "range: type %d, min %f - type %d, max %f ",
6393 therange->min.type, therange->min.seconds, therange->max.type,
6394 therange->max.seconds);
6396 if (therange->min.type == GST_RTSP_TIME_NOW)
6398 else if (therange->min.type == GST_RTSP_TIME_END)
6401 seconds = therange->min.seconds * GST_SECOND;
6403 GST_DEBUG_OBJECT (src, "range: min %" GST_TIME_FORMAT,
6404 GST_TIME_ARGS (seconds));
6406 /* we need to start playback without clipping from the position reported by
6408 segment->start = seconds;
6409 segment->position = seconds;
6411 if (therange->max.type == GST_RTSP_TIME_NOW)
6413 else if (therange->max.type == GST_RTSP_TIME_END)
6416 seconds = therange->max.seconds * GST_SECOND;
6418 GST_DEBUG_OBJECT (src, "range: max %" GST_TIME_FORMAT,
6419 GST_TIME_ARGS (seconds));
6421 /* live (WMS) server might send overflowed large max as its idea of infinity,
6422 * compensate to prevent problems later on */
6423 if (seconds != -1 && seconds < 0) {
6425 GST_DEBUG_OBJECT (src, "insane range, set to NONE");
6428 /* live (WMS) might send min == max, which is not worth recording */
6429 if (segment->duration == -1 && seconds == segment->start)
6432 /* don't change duration with unknown value, we might have a valid value
6433 * there that we want to keep. */
6435 segment->duration = seconds;
6440 /* Parse clock profived by the server with following syntax:
6442 * "GstNetTimeProvider <wrapped-clock> <server-IP:port> <clock-time>"
6445 gst_rtspsrc_parse_gst_clock (GstRTSPSrc * src, const gchar * gstclock)
6447 gboolean res = FALSE;
6449 if (g_str_has_prefix (gstclock, "GstNetTimeProvider ")) {
6450 gchar **fields = NULL, **parts = NULL;
6451 gchar *remote_ip, *str;
6453 GstClockTime base_time;
6456 fields = g_strsplit (gstclock, " ", 0);
6458 /* wrapped clock, not very interesting for now */
6459 if (fields[1] == NULL)
6462 /* remote IP address and port */
6463 if ((str = fields[2]) == NULL)
6466 parts = g_strsplit (str, ":", 0);
6468 if ((remote_ip = parts[0]) == NULL)
6471 if ((str = parts[1]) == NULL)
6479 if ((str = fields[3]) == NULL)
6482 base_time = g_ascii_strtoull (str, NULL, 10);
6485 gst_net_client_clock_new ((gchar *) "GstRTSPClock", remote_ip, port,
6488 if (src->provided_clock)
6489 gst_object_unref (src->provided_clock);
6490 src->provided_clock = netclock;
6492 gst_element_post_message (GST_ELEMENT_CAST (src),
6493 gst_message_new_clock_provide (GST_OBJECT_CAST (src),
6494 src->provided_clock, TRUE));
6498 g_strfreev (fields);
6504 /* must be called with the RTSP state lock */
6505 static GstRTSPResult
6506 gst_rtspsrc_open_from_sdp (GstRTSPSrc * src, GstSDPMessage * sdp,
6512 /* prepare global stream caps properties */
6514 gst_structure_remove_all_fields (src->props);
6516 src->props = gst_structure_new_empty ("RTSPProperties");
6519 gst_sdp_message_dump (sdp);
6521 gst_rtsp_ext_list_parse_sdp (src->extensions, sdp, src->props);
6523 /* let the app inspect and change the SDP */
6524 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_ON_SDP], 0, sdp);
6526 gst_segment_init (&src->segment, GST_FORMAT_TIME);
6528 /* parse range for duration reporting. */
6533 range = gst_sdp_message_get_attribute_val_n (sdp, "range", i);
6537 /* keep track of the range and configure it in the segment */
6538 if (gst_rtspsrc_parse_range (src, range, &src->segment))
6542 /* parse clock information. This is GStreamer specific, a server can tell the
6543 * client what clock it is using and wrap that in a network clock. The
6544 * advantage of that is that we can slave to it. */
6546 const gchar *gstclock;
6549 gstclock = gst_sdp_message_get_attribute_val_n (sdp, "x-gst-clock", i);
6550 if (gstclock == NULL)
6553 /* parse the clock and expose it in the provide_clock method */
6554 if (gst_rtspsrc_parse_gst_clock (src, gstclock))
6558 /* try to find a global control attribute. Note that a '*' means that we should
6559 * do aggregate control with the current url (so we don't do anything and
6560 * leave the current connection as is) */
6562 const gchar *control;
6565 control = gst_sdp_message_get_attribute_val_n (sdp, "control", i);
6566 if (control == NULL)
6569 /* only take fully qualified urls */
6570 if (g_str_has_prefix (control, "rtsp://"))
6574 g_free (src->conninfo.location);
6575 src->conninfo.location = g_strdup (control);
6576 /* make a connection for this, if there was a connection already, nothing
6578 if (gst_rtsp_conninfo_connect (src, &src->conninfo, async) < 0) {
6579 GST_ERROR_OBJECT (src, "could not connect");
6582 /* we need to keep the control url separate from the connection url because
6583 * the rules for constructing the media control url need it */
6584 g_free (src->control);
6585 src->control = g_strdup (control);
6588 /* create streams */
6589 n_streams = gst_sdp_message_medias_len (sdp);
6590 for (i = 0; i < n_streams; i++) {
6591 gst_rtspsrc_create_stream (src, sdp, i);
6594 src->state = GST_RTSP_STATE_INIT;
6597 if ((res = gst_rtspsrc_setup_streams (src, async)) < 0)
6600 /* reset our state */
6601 src->need_range = TRUE;
6604 src->state = GST_RTSP_STATE_READY;
6611 GST_ERROR_OBJECT (src, "setup failed");
6612 gst_rtspsrc_cleanup (src);
6617 static GstRTSPResult
6618 gst_rtspsrc_retrieve_sdp (GstRTSPSrc * src, GstSDPMessage ** sdp,
6622 GstRTSPMessage request = { 0 };
6623 GstRTSPMessage response = { 0 };
6626 gchar *respcont = NULL;
6629 src->need_redirect = FALSE;
6631 /* can't continue without a valid url */
6632 if (G_UNLIKELY (src->conninfo.url == NULL)) {
6633 res = GST_RTSP_EINVAL;
6636 src->tried_url_auth = FALSE;
6638 if ((res = gst_rtsp_conninfo_connect (src, &src->conninfo, async)) < 0)
6639 goto connect_failed;
6641 /* create OPTIONS */
6642 GST_DEBUG_OBJECT (src, "create options...");
6644 gst_rtspsrc_init_request (src, &request, GST_RTSP_OPTIONS,
6645 src->conninfo.url_str);
6647 goto create_request_failed;
6650 GST_DEBUG_OBJECT (src, "send options...");
6653 GST_ELEMENT_PROGRESS (src, CONTINUE, "open", ("Retrieving server options"));
6656 gst_rtspsrc_send (src, src->conninfo.connection, &request, &response,
6661 if (!gst_rtspsrc_parse_methods (src, &response))
6664 /* create DESCRIBE */
6665 GST_DEBUG_OBJECT (src, "create describe...");
6667 gst_rtspsrc_init_request (src, &request, GST_RTSP_DESCRIBE,
6668 src->conninfo.url_str);
6670 goto create_request_failed;
6672 /* we only accept SDP for now */
6673 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_ACCEPT,
6677 GST_DEBUG_OBJECT (src, "send describe...");
6680 GST_ELEMENT_PROGRESS (src, CONTINUE, "open", ("Retrieving media info"));
6683 gst_rtspsrc_send (src, src->conninfo.connection, &request, &response,
6687 /* we only perform redirect for the describe, currently */
6688 if (src->need_redirect) {
6689 /* close connection, we don't have to send a TEARDOWN yet, ignore the
6691 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
6693 gst_rtsp_message_unset (&request);
6694 gst_rtsp_message_unset (&response);
6700 /* it could be that the DESCRIBE method was not implemented */
6701 if (!(src->methods & GST_RTSP_DESCRIBE))
6704 /* check if reply is SDP */
6705 gst_rtsp_message_get_header (&response, GST_RTSP_HDR_CONTENT_TYPE, &respcont,
6707 /* could not be set but since the request returned OK, we assume it
6708 * was SDP, else check it. */
6710 if (g_ascii_strcasecmp (respcont, "application/sdp") != 0)
6711 goto wrong_content_type;
6714 /* get message body and parse as SDP */
6715 gst_rtsp_message_get_body (&response, &data, &size);
6716 if (data == NULL || size == 0)
6719 GST_DEBUG_OBJECT (src, "parse SDP...");
6720 gst_sdp_message_new (sdp);
6721 gst_sdp_message_parse_buffer (data, size, *sdp);
6723 /* clean up any messages */
6724 gst_rtsp_message_unset (&request);
6725 gst_rtsp_message_unset (&response);
6732 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
6733 ("No valid RTSP URL was provided"));
6738 gchar *str = gst_rtsp_strresult (res);
6740 if (res != GST_RTSP_EINTR) {
6741 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
6742 ("Failed to connect. (%s)", str));
6744 GST_WARNING_OBJECT (src, "connect interrupted");
6749 create_request_failed:
6751 gchar *str = gst_rtsp_strresult (res);
6753 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
6754 ("Could not create request. (%s)", str));
6760 /* Don't post a message - the rtsp_send method will have
6761 * taken care of it because we passed NULL for the response code */
6766 /* error was posted */
6767 res = GST_RTSP_ERROR;
6772 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
6773 ("Server does not support SDP, got %s.", respcont));
6774 res = GST_RTSP_ERROR;
6779 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
6780 ("Server can not provide an SDP."));
6781 res = GST_RTSP_ERROR;
6786 if (src->conninfo.connection) {
6787 GST_DEBUG_OBJECT (src, "free connection");
6788 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
6790 gst_rtsp_message_unset (&request);
6791 gst_rtsp_message_unset (&response);
6796 static GstRTSPResult
6797 gst_rtspsrc_open (GstRTSPSrc * src, gboolean async)
6802 GST_RTSP_SETUP | GST_RTSP_PLAY | GST_RTSP_PAUSE | GST_RTSP_TEARDOWN;
6804 if (src->sdp == NULL) {
6805 if ((ret = gst_rtspsrc_retrieve_sdp (src, &src->sdp, async)) < 0)
6809 if ((ret = gst_rtspsrc_open_from_sdp (src, src->sdp, async)) < 0)
6814 gst_rtspsrc_loop_end_cmd (src, CMD_OPEN, ret);
6821 GST_WARNING_OBJECT (src, "can't get sdp");
6822 src->open_error = TRUE;
6827 GST_WARNING_OBJECT (src, "can't setup streaming from sdp");
6828 src->open_error = TRUE;
6833 static GstRTSPResult
6834 gst_rtspsrc_close (GstRTSPSrc * src, gboolean async, gboolean only_close)
6836 GstRTSPMessage request = { 0 };
6837 GstRTSPMessage response = { 0 };
6838 GstRTSPResult res = GST_RTSP_OK;
6840 const gchar *control;
6842 GST_DEBUG_OBJECT (src, "TEARDOWN...");
6844 gst_rtspsrc_set_state (src, GST_STATE_READY);
6846 if (src->state < GST_RTSP_STATE_READY) {
6847 GST_DEBUG_OBJECT (src, "not ready, doing cleanup");
6854 /* construct a control url */
6855 control = get_aggregate_control (src);
6857 if (!(src->methods & (GST_RTSP_PLAY | GST_RTSP_TEARDOWN)))
6860 for (walk = src->streams; walk; walk = g_list_next (walk)) {
6861 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
6862 const gchar *setup_url;
6863 GstRTSPConnInfo *info;
6865 /* try aggregate control first but do non-aggregate control otherwise */
6867 setup_url = control;
6868 else if ((setup_url = stream->conninfo.location) == NULL)
6871 if (src->conninfo.connection) {
6872 info = &src->conninfo;
6873 } else if (stream->conninfo.connection) {
6874 info = &stream->conninfo;
6878 if (!info->connected)
6883 gst_rtspsrc_init_request (src, &request, GST_RTSP_TEARDOWN, setup_url);
6885 goto create_request_failed;
6888 GST_ELEMENT_PROGRESS (src, CONTINUE, "close", ("Closing stream"));
6891 gst_rtspsrc_send (src, info->connection, &request, &response,
6895 /* FIXME, parse result? */
6896 gst_rtsp_message_unset (&request);
6897 gst_rtsp_message_unset (&response);
6900 /* early exit when we did aggregate control */
6906 /* close connections */
6907 GST_DEBUG_OBJECT (src, "closing connection...");
6908 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
6909 for (walk = src->streams; walk; walk = g_list_next (walk)) {
6910 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
6911 gst_rtsp_conninfo_close (src, &stream->conninfo, TRUE);
6915 gst_rtspsrc_cleanup (src);
6917 src->state = GST_RTSP_STATE_INVALID;
6920 gst_rtspsrc_loop_end_cmd (src, CMD_CLOSE, res);
6925 create_request_failed:
6927 gchar *str = gst_rtsp_strresult (res);
6929 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
6930 ("Could not create request. (%s)", str));
6936 gchar *str = gst_rtsp_strresult (res);
6938 gst_rtsp_message_unset (&request);
6939 if (res != GST_RTSP_EINTR) {
6940 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
6941 ("Could not send message. (%s)", str));
6943 GST_WARNING_OBJECT (src, "TEARDOWN interrupted");
6950 GST_DEBUG_OBJECT (src,
6951 "TEARDOWN and PLAY not supported, can't do TEARDOWN");
6956 /* RTP-Info is of the format:
6958 * url=<URL>;[seq=<seqbase>;rtptime=<timebase>] [, url=...]
6960 * rtptime corresponds to the timestamp for the NPT time given in the header
6961 * seqbase corresponds to the next sequence number we received. This number
6962 * indicates the first seqnum after the seek and should be used to discard
6963 * packets that are from before the seek.
6966 gst_rtspsrc_parse_rtpinfo (GstRTSPSrc * src, gchar * rtpinfo)
6971 GST_DEBUG_OBJECT (src, "parsing RTP-Info %s", rtpinfo);
6973 infos = g_strsplit (rtpinfo, ",", 0);
6974 for (i = 0; infos[i]; i++) {
6976 GstRTSPStream *stream;
6980 GST_DEBUG_OBJECT (src, "parsing info %s", infos[i]);
6982 /* init values, types of seqbase and timebase are bigger than needed so we
6983 * can store -1 as uninitialized values */
6988 /* parse url, find stream for url.
6989 * parse seq and rtptime. The seq number should be configured in the rtp
6990 * depayloader or session manager to detect gaps. Same for the rtptime, it
6991 * should be used to create an initial time newsegment. */
6992 fields = g_strsplit (infos[i], ";", 0);
6993 for (j = 0; fields[j]; j++) {
6994 GST_DEBUG_OBJECT (src, "parsing field %s", fields[j]);
6995 /* remove leading whitespace */
6996 fields[j] = g_strchug (fields[j]);
6997 if (g_str_has_prefix (fields[j], "url=")) {
6998 /* get the url and the stream */
7000 find_stream (src, (fields[j] + 4), (gpointer) find_stream_by_setup);
7001 } else if (g_str_has_prefix (fields[j], "seq=")) {
7002 seqbase = atoi (fields[j] + 4);
7003 } else if (g_str_has_prefix (fields[j], "rtptime=")) {
7004 timebase = g_ascii_strtoll (fields[j] + 8, NULL, 10);
7007 g_strfreev (fields);
7008 /* now we need to store the values for the caps of the stream */
7009 if (stream != NULL) {
7010 GST_DEBUG_OBJECT (src,
7011 "found stream %p, setting: seqbase %d, timebase %" G_GINT64_FORMAT,
7012 stream, seqbase, timebase);
7014 /* we have a stream, configure detected params */
7015 stream->seqbase = seqbase;
7016 stream->timebase = timebase;
7025 gst_rtspsrc_handle_rtcp_interval (GstRTSPSrc * src, gchar * rtcp)
7030 interval = strtoul (rtcp, NULL, 10);
7031 GST_DEBUG_OBJECT (src, "rtcp interval: %" G_GUINT64_FORMAT " ms", interval);
7036 interval *= GST_MSECOND;
7038 for (walk = src->streams; walk; walk = g_list_next (walk)) {
7039 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
7041 /* already (optionally) retrieved this when configuring manager */
7042 if (stream->session) {
7043 GObject *rtpsession = stream->session;
7045 GST_DEBUG_OBJECT (src, "configure rtcp interval in session %p",
7047 g_object_set (rtpsession, "rtcp-min-interval", interval, NULL);
7051 /* now it happens that (Xenon) server sending this may also provide bogus
7052 * RTCP SR sync data (i.e. with quite some jitter), so never mind those
7053 * and just use RTP-Info to sync */
7055 GObjectClass *klass;
7057 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
7058 if (g_object_class_find_property (klass, "rtcp-sync")) {
7059 GST_DEBUG_OBJECT (src, "configuring rtp sync method");
7060 g_object_set (src->manager, "rtcp-sync", RTCP_SYNC_RTP, NULL);
7066 gst_rtspsrc_get_float (const gchar * dstr)
7068 gchar s[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
7070 /* canonicalise floating point string so we can handle float strings
7071 * in the form "24.930" or "24,930" irrespective of the current locale */
7072 g_strlcpy (s, dstr, sizeof (s));
7073 g_strdelimit (s, ",", '.');
7074 return g_ascii_strtod (s, NULL);
7078 gen_range_header (GstRTSPSrc * src, GstSegment * segment)
7080 gchar val_str[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
7082 if (src->range && src->range->min.type == GST_RTSP_TIME_NOW) {
7083 g_strlcpy (val_str, "now", sizeof (val_str));
7085 if (segment->position == 0) {
7086 g_strlcpy (val_str, "0", sizeof (val_str));
7088 g_ascii_dtostr (val_str, sizeof (val_str),
7089 ((gdouble) segment->position) / GST_SECOND);
7092 return g_strdup_printf ("npt=%s-", val_str);
7096 clear_rtp_base (GstRTSPSrc * src, GstRTSPStream * stream)
7100 stream->timebase = -1;
7101 stream->seqbase = -1;
7103 len = stream->ptmap->len;
7104 for (i = 0; i < len; i++) {
7105 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
7108 if (item->caps == NULL)
7111 item->caps = gst_caps_make_writable (item->caps);
7112 s = gst_caps_get_structure (item->caps, 0);
7113 gst_structure_remove_fields (s, "clock-base", "seqnum-base", NULL);
7117 static GstRTSPResult
7118 gst_rtspsrc_ensure_open (GstRTSPSrc * src, gboolean async)
7120 GstRTSPResult res = GST_RTSP_OK;
7122 if (src->state < GST_RTSP_STATE_READY) {
7123 res = GST_RTSP_ERROR;
7124 if (src->open_error) {
7125 GST_DEBUG_OBJECT (src, "the stream was in error");
7129 gst_rtspsrc_loop_start_cmd (src, CMD_OPEN);
7131 if ((res = gst_rtspsrc_open (src, async)) < 0) {
7132 GST_DEBUG_OBJECT (src, "failed to open stream");
7141 static GstRTSPResult
7142 gst_rtspsrc_play (GstRTSPSrc * src, GstSegment * segment, gboolean async)
7144 GstRTSPMessage request = { 0 };
7145 GstRTSPMessage response = { 0 };
7146 GstRTSPResult res = GST_RTSP_OK;
7150 const gchar *control;
7152 GST_DEBUG_OBJECT (src, "PLAY...");
7154 if ((res = gst_rtspsrc_ensure_open (src, async)) < 0)
7157 if (!(src->methods & GST_RTSP_PLAY))
7160 if (src->state == GST_RTSP_STATE_PLAYING)
7163 if (!src->conninfo.connection || !src->conninfo.connected)
7166 /* send some dummy packets before we activate the receive in the
7168 gst_rtspsrc_send_dummy_packets (src);
7170 /* require new SR packets */
7172 g_signal_emit_by_name (src->manager, "reset-sync", NULL);
7174 /* construct a control url */
7175 control = get_aggregate_control (src);
7177 for (walk = src->streams; walk; walk = g_list_next (walk)) {
7178 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
7179 const gchar *setup_url;
7180 GstRTSPConnection *conn;
7182 /* try aggregate control first but do non-aggregate control otherwise */
7184 setup_url = control;
7185 else if ((setup_url = stream->conninfo.location) == NULL)
7188 if (src->conninfo.connection) {
7189 conn = src->conninfo.connection;
7190 } else if (stream->conninfo.connection) {
7191 conn = stream->conninfo.connection;
7197 res = gst_rtspsrc_init_request (src, &request, GST_RTSP_PLAY, setup_url);
7199 goto create_request_failed;
7201 if (src->need_range) {
7202 hval = gen_range_header (src, segment);
7204 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_RANGE, hval);
7206 /* store the newsegment event so it can be sent from the streaming thread. */
7207 src->need_segment = TRUE;
7210 if (segment->rate != 1.0) {
7211 gchar hval[G_ASCII_DTOSTR_BUF_SIZE];
7213 g_ascii_dtostr (hval, sizeof (hval), segment->rate);
7215 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SCALE, hval);
7217 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SPEED, hval);
7221 GST_ELEMENT_PROGRESS (src, CONTINUE, "request", ("Sending PLAY request"));
7223 if ((res = gst_rtspsrc_send (src, conn, &request, &response, NULL)) < 0)
7226 /* seek may have silently failed as it is not supported */
7227 if (!(src->methods & GST_RTSP_PLAY)) {
7228 GST_DEBUG_OBJECT (src, "PLAY Range not supported; re-enable PLAY");
7229 /* obviously it is supported as we made it here */
7230 src->methods |= GST_RTSP_PLAY;
7231 src->seekable = FALSE;
7232 /* but there is nothing to parse in the response,
7233 * so convey we have no idea and not to expect anything particular */
7234 clear_rtp_base (src, stream);
7238 /* need to do for all streams */
7239 for (run = src->streams; run; run = g_list_next (run))
7240 clear_rtp_base (src, (GstRTSPStream *) run->data);
7242 /* NOTE the above also disables npt based eos detection */
7243 /* and below forces position to 0,
7244 * which is visible feedback we lost the plot */
7245 segment->start = segment->position = src->last_pos;
7248 gst_rtsp_message_unset (&request);
7250 /* parse RTP npt field. This is the current position in the stream (Normal
7251 * Play Time) and should be put in the NEWSEGMENT position field. */
7252 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RANGE, &hval,
7254 gst_rtspsrc_parse_range (src, hval, segment);
7256 /* assume 1.0 rate now, overwrite when the SCALE or SPEED headers are present. */
7257 segment->rate = 1.0;
7259 /* parse Speed header. This is the intended playback rate of the stream
7260 * and should be put in the NEWSEGMENT rate field. */
7261 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_SPEED, &hval,
7262 0) == GST_RTSP_OK) {
7263 segment->rate = gst_rtspsrc_get_float (hval);
7264 } else if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_SCALE,
7265 &hval, 0) == GST_RTSP_OK) {
7266 segment->rate = gst_rtspsrc_get_float (hval);
7269 /* parse the RTP-Info header field (if ANY) to get the base seqnum and timestamp
7270 * for the RTP packets. If this is not present, we assume all starts from 0...
7271 * This is info for the RTP session manager that we pass to it in caps. */
7273 while (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RTP_INFO,
7274 &hval, hval_idx++) == GST_RTSP_OK)
7275 gst_rtspsrc_parse_rtpinfo (src, hval);
7277 /* some servers indicate RTCP parameters in PLAY response,
7278 * rather than properly in SDP */
7279 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RTCP_INTERVAL,
7280 &hval, 0) == GST_RTSP_OK)
7281 gst_rtspsrc_handle_rtcp_interval (src, hval);
7283 gst_rtsp_message_unset (&response);
7285 /* early exit when we did aggregate control */
7289 /* configure the caps of the streams after we parsed all headers. Only reset
7290 * the manager object when we set a new Range header (we did a seek) */
7291 gst_rtspsrc_configure_caps (src, segment, src->need_range);
7293 /* set to PLAYING after we have configured the caps, otherwise we
7294 * might end up calling request_key (with SRTP) while caps are still
7295 * being configured. */
7296 gst_rtspsrc_set_state (src, GST_STATE_PLAYING);
7298 /* set again when needed */
7299 src->need_range = FALSE;
7301 src->running = TRUE;
7302 src->base_time = -1;
7303 src->state = GST_RTSP_STATE_PLAYING;
7306 GST_DEBUG_OBJECT (src, "mark DISCONT, we did a seek to another position");
7307 for (walk = src->streams; walk; walk = g_list_next (walk)) {
7308 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
7309 stream->discont = TRUE;
7314 gst_rtspsrc_loop_end_cmd (src, CMD_PLAY, res);
7321 GST_DEBUG_OBJECT (src, "failed to open stream");
7326 GST_DEBUG_OBJECT (src, "PLAY is not supported");
7331 GST_DEBUG_OBJECT (src, "we were already PLAYING");
7334 create_request_failed:
7336 gchar *str = gst_rtsp_strresult (res);
7338 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
7339 ("Could not create request. (%s)", str));
7345 gchar *str = gst_rtsp_strresult (res);
7347 gst_rtsp_message_unset (&request);
7348 if (res != GST_RTSP_EINTR) {
7349 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
7350 ("Could not send message. (%s)", str));
7352 GST_WARNING_OBJECT (src, "PLAY interrupted");
7359 static GstRTSPResult
7360 gst_rtspsrc_pause (GstRTSPSrc * src, gboolean async)
7362 GstRTSPResult res = GST_RTSP_OK;
7363 GstRTSPMessage request = { 0 };
7364 GstRTSPMessage response = { 0 };
7366 const gchar *control;
7368 GST_DEBUG_OBJECT (src, "PAUSE...");
7370 if ((res = gst_rtspsrc_ensure_open (src, async)) < 0)
7373 if (!(src->methods & GST_RTSP_PAUSE))
7376 if (src->state == GST_RTSP_STATE_READY)
7379 if (!src->conninfo.connection || !src->conninfo.connected)
7382 /* construct a control url */
7383 control = get_aggregate_control (src);
7385 /* loop over the streams. We might exit the loop early when we could do an
7386 * aggregate control */
7387 for (walk = src->streams; walk; walk = g_list_next (walk)) {
7388 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
7389 GstRTSPConnection *conn;
7390 const gchar *setup_url;
7392 /* try aggregate control first but do non-aggregate control otherwise */
7394 setup_url = control;
7395 else if ((setup_url = stream->conninfo.location) == NULL)
7398 if (src->conninfo.connection) {
7399 conn = src->conninfo.connection;
7400 } else if (stream->conninfo.connection) {
7401 conn = stream->conninfo.connection;
7407 GST_ELEMENT_PROGRESS (src, CONTINUE, "request",
7408 ("Sending PAUSE request"));
7411 gst_rtspsrc_init_request (src, &request, GST_RTSP_PAUSE,
7413 goto create_request_failed;
7415 if ((res = gst_rtspsrc_send (src, conn, &request, &response, NULL)) < 0)
7418 gst_rtsp_message_unset (&request);
7419 gst_rtsp_message_unset (&response);
7421 /* exit early when we did agregate control */
7426 /* change element states now */
7427 gst_rtspsrc_set_state (src, GST_STATE_PAUSED);
7430 src->state = GST_RTSP_STATE_READY;
7434 gst_rtspsrc_loop_end_cmd (src, CMD_PAUSE, res);
7441 GST_DEBUG_OBJECT (src, "failed to open stream");
7446 GST_DEBUG_OBJECT (src, "PAUSE is not supported");
7451 GST_DEBUG_OBJECT (src, "we were already PAUSED");
7454 create_request_failed:
7456 gchar *str = gst_rtsp_strresult (res);
7458 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
7459 ("Could not create request. (%s)", str));
7465 gchar *str = gst_rtsp_strresult (res);
7467 gst_rtsp_message_unset (&request);
7468 if (res != GST_RTSP_EINTR) {
7469 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
7470 ("Could not send message. (%s)", str));
7472 GST_WARNING_OBJECT (src, "PAUSE interrupted");
7480 gst_rtspsrc_handle_message (GstBin * bin, GstMessage * message)
7482 GstRTSPSrc *rtspsrc;
7484 rtspsrc = GST_RTSPSRC (bin);
7486 switch (GST_MESSAGE_TYPE (message)) {
7487 case GST_MESSAGE_EOS:
7488 gst_message_unref (message);
7490 case GST_MESSAGE_ELEMENT:
7492 const GstStructure *s = gst_message_get_structure (message);
7494 if (gst_structure_has_name (s, "GstUDPSrcTimeout")) {
7495 gboolean ignore_timeout;
7497 GST_DEBUG_OBJECT (bin, "timeout on UDP port");
7499 GST_OBJECT_LOCK (rtspsrc);
7500 ignore_timeout = rtspsrc->ignore_timeout;
7501 rtspsrc->ignore_timeout = TRUE;
7502 GST_OBJECT_UNLOCK (rtspsrc);
7504 /* we only act on the first udp timeout message, others are irrelevant
7505 * and can be ignored. */
7506 if (!ignore_timeout)
7507 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_RECONNECT, CMD_LOOP);
7509 gst_message_unref (message);
7512 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
7515 case GST_MESSAGE_ERROR:
7518 GstRTSPStream *stream;
7521 udpsrc = GST_MESSAGE_SRC (message);
7523 GST_DEBUG_OBJECT (rtspsrc, "got error from %s",
7524 GST_ELEMENT_NAME (udpsrc));
7526 stream = find_stream (rtspsrc, udpsrc, (gpointer) find_stream_by_udpsrc);
7530 /* we ignore the RTCP udpsrc */
7531 if (stream->udpsrc[1] == GST_ELEMENT_CAST (udpsrc))
7534 /* if we get error messages from the udp sources, that's not a problem as
7535 * long as not all of them error out. We also don't really know what the
7536 * problem is, the message does not give enough detail... */
7537 ret = gst_rtspsrc_combine_flows (rtspsrc, stream, GST_FLOW_NOT_LINKED);
7538 GST_DEBUG_OBJECT (rtspsrc, "combined flows: %s", gst_flow_get_name (ret));
7539 if (ret != GST_FLOW_OK)
7543 gst_message_unref (message);
7547 /* fatal but not our message, forward */
7548 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
7553 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
7559 /* the thread where everything happens */
7561 gst_rtspsrc_thread (GstRTSPSrc * src)
7565 GST_OBJECT_LOCK (src);
7566 cmd = src->pending_cmd;
7567 if (cmd == CMD_RECONNECT || cmd == CMD_PLAY || cmd == CMD_PAUSE
7568 || cmd == CMD_LOOP || cmd == CMD_OPEN)
7569 src->pending_cmd = CMD_LOOP;
7571 src->pending_cmd = CMD_WAIT;
7572 GST_DEBUG_OBJECT (src, "got command %s", cmd_to_string (cmd));
7574 /* we got the message command, so ensure communication is possible again */
7575 gst_rtspsrc_connection_flush (src, FALSE);
7577 src->busy_cmd = cmd;
7578 GST_OBJECT_UNLOCK (src);
7582 gst_rtspsrc_open (src, TRUE);
7585 gst_rtspsrc_play (src, &src->segment, TRUE);
7588 gst_rtspsrc_pause (src, TRUE);
7591 gst_rtspsrc_close (src, TRUE, FALSE);
7594 gst_rtspsrc_loop (src);
7597 gst_rtspsrc_reconnect (src, FALSE);
7603 GST_OBJECT_LOCK (src);
7604 /* and go back to sleep */
7605 if (src->pending_cmd == CMD_WAIT) {
7607 gst_task_pause (src->task);
7610 src->busy_cmd = CMD_WAIT;
7611 GST_OBJECT_UNLOCK (src);
7615 gst_rtspsrc_start (GstRTSPSrc * src)
7617 GST_DEBUG_OBJECT (src, "starting");
7619 GST_OBJECT_LOCK (src);
7621 src->pending_cmd = CMD_WAIT;
7623 if (src->task == NULL) {
7624 src->task = gst_task_new ((GstTaskFunction) gst_rtspsrc_thread, src, NULL);
7625 if (src->task == NULL)
7628 gst_task_set_lock (src->task, GST_RTSP_STREAM_GET_LOCK (src));
7630 GST_OBJECT_UNLOCK (src);
7637 GST_OBJECT_UNLOCK (src);
7638 GST_ERROR_OBJECT (src, "failed to create task");
7644 gst_rtspsrc_stop (GstRTSPSrc * src)
7648 GST_DEBUG_OBJECT (src, "stopping");
7650 /* also cancels pending task */
7651 gst_rtspsrc_loop_send_cmd (src, CMD_WAIT, CMD_ALL);
7653 GST_OBJECT_LOCK (src);
7654 if ((task = src->task)) {
7656 GST_OBJECT_UNLOCK (src);
7658 gst_task_stop (task);
7660 /* make sure it is not running */
7661 GST_RTSP_STREAM_LOCK (src);
7662 GST_RTSP_STREAM_UNLOCK (src);
7664 /* now wait for the task to finish */
7665 gst_task_join (task);
7667 /* and free the task */
7668 gst_object_unref (GST_OBJECT (task));
7670 GST_OBJECT_LOCK (src);
7672 GST_OBJECT_UNLOCK (src);
7674 /* ensure synchronously all is closed and clean */
7675 gst_rtspsrc_close (src, FALSE, TRUE);
7680 static GstStateChangeReturn
7681 gst_rtspsrc_change_state (GstElement * element, GstStateChange transition)
7683 GstRTSPSrc *rtspsrc;
7684 GstStateChangeReturn ret;
7686 rtspsrc = GST_RTSPSRC (element);
7688 switch (transition) {
7689 case GST_STATE_CHANGE_NULL_TO_READY:
7690 if (!gst_rtspsrc_start (rtspsrc))
7693 case GST_STATE_CHANGE_READY_TO_PAUSED:
7694 /* init some state */
7695 rtspsrc->cur_protocols = rtspsrc->protocols;
7696 /* first attempt, don't ignore timeouts */
7697 rtspsrc->ignore_timeout = FALSE;
7698 rtspsrc->open_error = FALSE;
7699 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_OPEN, 0);
7701 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
7702 set_manager_buffer_mode (rtspsrc);
7704 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
7705 /* unblock the tcp tasks and make the loop waiting */
7706 if (gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_WAIT, CMD_LOOP)) {
7707 /* make sure it is waiting before we send PAUSE or PLAY below */
7708 GST_RTSP_STREAM_LOCK (rtspsrc);
7709 GST_RTSP_STREAM_UNLOCK (rtspsrc);
7712 case GST_STATE_CHANGE_PAUSED_TO_READY:
7718 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
7719 if (ret == GST_STATE_CHANGE_FAILURE)
7722 switch (transition) {
7723 case GST_STATE_CHANGE_NULL_TO_READY:
7724 ret = GST_STATE_CHANGE_SUCCESS;
7726 case GST_STATE_CHANGE_READY_TO_PAUSED:
7727 ret = GST_STATE_CHANGE_NO_PREROLL;
7729 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
7730 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_PLAY, 0);
7731 ret = GST_STATE_CHANGE_SUCCESS;
7733 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
7734 /* send pause request and keep the idle task around */
7735 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_PAUSE, CMD_LOOP);
7736 ret = GST_STATE_CHANGE_NO_PREROLL;
7738 case GST_STATE_CHANGE_PAUSED_TO_READY:
7739 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_CLOSE, CMD_PAUSE);
7740 ret = GST_STATE_CHANGE_SUCCESS;
7742 case GST_STATE_CHANGE_READY_TO_NULL:
7743 gst_rtspsrc_stop (rtspsrc);
7744 ret = GST_STATE_CHANGE_SUCCESS;
7755 GST_DEBUG_OBJECT (rtspsrc, "start failed");
7756 return GST_STATE_CHANGE_FAILURE;
7761 gst_rtspsrc_send_event (GstElement * element, GstEvent * event)
7764 GstRTSPSrc *rtspsrc;
7766 rtspsrc = GST_RTSPSRC (element);
7768 if (GST_EVENT_IS_DOWNSTREAM (event)) {
7769 res = gst_rtspsrc_push_event (rtspsrc, event);
7771 res = GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
7778 /*** GSTURIHANDLER INTERFACE *************************************************/
7781 gst_rtspsrc_uri_get_type (GType type)
7786 static const gchar *const *
7787 gst_rtspsrc_uri_get_protocols (GType type)
7789 static const gchar *protocols[] =
7790 { "rtsp", "rtspu", "rtspt", "rtsph", "rtsp-sdp",
7791 "rtsps", "rtspsu", "rtspst", "rtspsh", NULL
7798 gst_rtspsrc_uri_get_uri (GstURIHandler * handler)
7800 GstRTSPSrc *src = GST_RTSPSRC (handler);
7802 /* FIXME: make thread-safe */
7803 return g_strdup (src->conninfo.location);
7807 gst_rtspsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri,
7813 GstRTSPUrl *newurl = NULL;
7814 GstSDPMessage *sdp = NULL;
7816 src = GST_RTSPSRC (handler);
7818 /* same URI, we're fine */
7819 if (src->conninfo.location && uri && !strcmp (uri, src->conninfo.location))
7822 if (g_str_has_prefix (uri, "rtsp-sdp://")) {
7823 sres = gst_sdp_message_new (&sdp);
7827 GST_DEBUG_OBJECT (src, "parsing SDP message");
7828 sres = gst_sdp_message_parse_uri (uri, sdp);
7833 GST_DEBUG_OBJECT (src, "parsing URI");
7834 if ((res = gst_rtsp_url_parse (uri, &newurl)) < 0)
7838 /* if worked, free previous and store new url object along with the original
7840 GST_DEBUG_OBJECT (src, "configuring URI");
7841 g_free (src->conninfo.location);
7842 src->conninfo.location = g_strdup (uri);
7843 gst_rtsp_url_free (src->conninfo.url);
7844 src->conninfo.url = newurl;
7845 g_free (src->conninfo.url_str);
7847 src->conninfo.url_str = gst_rtsp_url_get_request_uri (src->conninfo.url);
7849 src->conninfo.url_str = NULL;
7852 gst_sdp_message_free (src->sdp);
7854 src->from_sdp = sdp != NULL;
7856 GST_DEBUG_OBJECT (src, "set uri: %s", GST_STR_NULL (uri));
7857 GST_DEBUG_OBJECT (src, "request uri is: %s",
7858 GST_STR_NULL (src->conninfo.url_str));
7865 GST_DEBUG_OBJECT (src, "URI was ok: '%s'", GST_STR_NULL (uri));
7870 GST_ERROR_OBJECT (src, "Could not create new SDP (%d)", sres);
7871 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
7872 "Could not create SDP");
7877 GST_ERROR_OBJECT (src, "Not a valid SDP (%d) '%s'", sres,
7878 GST_STR_NULL (uri));
7879 gst_sdp_message_free (sdp);
7880 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
7886 GST_ERROR_OBJECT (src, "Not a valid RTSP url '%s' (%d)",
7887 GST_STR_NULL (uri), res);
7888 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
7889 "Invalid RTSP URI");
7895 gst_rtspsrc_uri_handler_init (gpointer g_iface, gpointer iface_data)
7897 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
7899 iface->get_type = gst_rtspsrc_uri_get_type;
7900 iface->get_protocols = gst_rtspsrc_uri_get_protocols;
7901 iface->get_uri = gst_rtspsrc_uri_get_uri;
7902 iface->set_uri = gst_rtspsrc_uri_set_uri;