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
77 * Last reviewed on 2006-08-18 (0.10.5)
86 #endif /* HAVE_UNISTD_H */
92 #include <gst/net/gstnet.h>
93 #include <gst/sdp/gstsdpmessage.h>
94 #include <gst/rtp/gstrtppayloads.h>
96 #include "gst/gst-i18n-plugin.h"
98 #include "gstrtspsrc.h"
100 GST_DEBUG_CATEGORY_STATIC (rtspsrc_debug);
101 #define GST_CAT_DEFAULT (rtspsrc_debug)
103 static GstStaticPadTemplate rtptemplate = GST_STATIC_PAD_TEMPLATE ("stream_%u",
106 GST_STATIC_CAPS ("application/x-rtp; application/x-rdt"));
108 /* templates used internally */
109 static GstStaticPadTemplate anysrctemplate =
110 GST_STATIC_PAD_TEMPLATE ("internalsrc_%u",
113 GST_STATIC_CAPS_ANY);
115 static GstStaticPadTemplate anysinktemplate =
116 GST_STATIC_PAD_TEMPLATE ("internalsink_%u",
119 GST_STATIC_CAPS_ANY);
123 SIGNAL_HANDLE_REQUEST,
125 SIGNAL_SELECT_STREAM,
129 enum _GstRtspSrcRtcpSyncMode
136 enum _GstRtspSrcBufferMode
144 #define GST_TYPE_RTSP_SRC_BUFFER_MODE (gst_rtsp_src_buffer_mode_get_type())
146 gst_rtsp_src_buffer_mode_get_type (void)
148 static GType buffer_mode_type = 0;
149 static const GEnumValue buffer_modes[] = {
150 {BUFFER_MODE_NONE, "Only use RTP timestamps", "none"},
151 {BUFFER_MODE_SLAVE, "Slave receiver to sender clock", "slave"},
152 {BUFFER_MODE_BUFFER, "Do low/high watermark buffering", "buffer"},
153 {BUFFER_MODE_AUTO, "Choose mode depending on stream live", "auto"},
157 if (!buffer_mode_type) {
159 g_enum_register_static ("GstRTSPSrcBufferMode", buffer_modes);
161 return buffer_mode_type;
164 #define DEFAULT_LOCATION NULL
165 #define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP
166 #define DEFAULT_DEBUG FALSE
167 #define DEFAULT_RETRY 20
168 #define DEFAULT_TIMEOUT 5000000
169 #define DEFAULT_UDP_BUFFER_SIZE 0x80000
170 #define DEFAULT_TCP_TIMEOUT 20000000
171 #define DEFAULT_LATENCY_MS 2000
172 #define DEFAULT_DROP_ON_LATENCY FALSE
173 #define DEFAULT_CONNECTION_SPEED 0
174 #define DEFAULT_NAT_METHOD GST_RTSP_NAT_DUMMY
175 #define DEFAULT_DO_RTCP TRUE
176 #define DEFAULT_DO_RTSP_KEEP_ALIVE TRUE
177 #define DEFAULT_PROXY NULL
178 #define DEFAULT_RTP_BLOCKSIZE 0
179 #define DEFAULT_USER_ID NULL
180 #define DEFAULT_USER_PW NULL
181 #define DEFAULT_BUFFER_MODE BUFFER_MODE_AUTO
182 #define DEFAULT_PORT_RANGE NULL
183 #define DEFAULT_SHORT_HEADER FALSE
184 #define DEFAULT_PROBATION 2
185 #define DEFAULT_UDP_RECONNECT TRUE
186 #define DEFAULT_MULTICAST_IFACE NULL
187 #define DEFAULT_NTP_SYNC FALSE
188 #define DEFAULT_USE_PIPELINE_CLOCK FALSE
200 PROP_DROP_ON_LATENCY,
201 PROP_CONNECTION_SPEED,
204 PROP_DO_RTSP_KEEP_ALIVE,
213 PROP_UDP_BUFFER_SIZE,
217 PROP_MULTICAST_IFACE,
219 PROP_USE_PIPELINE_CLOCK,
224 #define GST_TYPE_RTSP_NAT_METHOD (gst_rtsp_nat_method_get_type())
226 gst_rtsp_nat_method_get_type (void)
228 static GType rtsp_nat_method_type = 0;
229 static const GEnumValue rtsp_nat_method[] = {
230 {GST_RTSP_NAT_NONE, "None", "none"},
231 {GST_RTSP_NAT_DUMMY, "Send Dummy packets", "dummy"},
235 if (!rtsp_nat_method_type) {
236 rtsp_nat_method_type =
237 g_enum_register_static ("GstRTSPNatMethod", rtsp_nat_method);
239 return rtsp_nat_method_type;
242 static void gst_rtspsrc_finalize (GObject * object);
244 static void gst_rtspsrc_set_property (GObject * object, guint prop_id,
245 const GValue * value, GParamSpec * pspec);
246 static void gst_rtspsrc_get_property (GObject * object, guint prop_id,
247 GValue * value, GParamSpec * pspec);
249 static GstClock *gst_rtspsrc_provide_clock (GstElement * element);
251 static void gst_rtspsrc_uri_handler_init (gpointer g_iface,
252 gpointer iface_data);
254 static void gst_rtspsrc_sdp_attributes_to_caps (GArray * attributes,
257 static gboolean gst_rtspsrc_set_proxy (GstRTSPSrc * rtsp, const gchar * proxy);
258 static void gst_rtspsrc_set_tcp_timeout (GstRTSPSrc * rtspsrc, guint64 timeout);
260 static GstCaps *gst_rtspsrc_media_to_caps (gint pt, const GstSDPMedia * media);
262 static GstStateChangeReturn gst_rtspsrc_change_state (GstElement * element,
263 GstStateChange transition);
264 static gboolean gst_rtspsrc_send_event (GstElement * element, GstEvent * event);
265 static void gst_rtspsrc_handle_message (GstBin * bin, GstMessage * message);
267 static gboolean gst_rtspsrc_setup_auth (GstRTSPSrc * src,
268 GstRTSPMessage * response);
270 static gboolean gst_rtspsrc_loop_send_cmd (GstRTSPSrc * src, gint cmd,
272 static GstRTSPResult gst_rtspsrc_send_cb (GstRTSPExtension * ext,
273 GstRTSPMessage * request, GstRTSPMessage * response, GstRTSPSrc * src);
275 static GstRTSPResult gst_rtspsrc_open (GstRTSPSrc * src, gboolean async);
276 static GstRTSPResult gst_rtspsrc_play (GstRTSPSrc * src, GstSegment * segment,
278 static GstRTSPResult gst_rtspsrc_pause (GstRTSPSrc * src, gboolean async);
279 static GstRTSPResult gst_rtspsrc_close (GstRTSPSrc * src, gboolean async,
280 gboolean only_close);
282 static gboolean gst_rtspsrc_uri_set_uri (GstURIHandler * handler,
283 const gchar * uri, GError ** error);
284 static gchar *gst_rtspsrc_uri_get_uri (GstURIHandler * handler);
286 static gboolean gst_rtspsrc_activate_streams (GstRTSPSrc * src);
287 static gboolean gst_rtspsrc_loop (GstRTSPSrc * src);
288 static gboolean gst_rtspsrc_stream_push_event (GstRTSPSrc * src,
289 GstRTSPStream * stream, GstEvent * event);
290 static gboolean gst_rtspsrc_push_event (GstRTSPSrc * src, GstEvent * event);
292 /* commands we send to out loop to notify it of events */
293 #define CMD_OPEN (1 << 0)
294 #define CMD_PLAY (1 << 1)
295 #define CMD_PAUSE (1 << 2)
296 #define CMD_CLOSE (1 << 3)
297 #define CMD_WAIT (1 << 4)
298 #define CMD_RECONNECT (1 << 5)
299 #define CMD_LOOP (1 << 6)
301 /* mask for all commands */
302 #define CMD_ALL ((CMD_LOOP << 1) - 1)
304 #define GST_ELEMENT_PROGRESS(el, type, code, text) \
306 gchar *__txt = _gst_element_error_printf text; \
307 gst_element_post_message (GST_ELEMENT_CAST (el), \
308 gst_message_new_progress (GST_OBJECT_CAST (el), \
309 GST_PROGRESS_TYPE_ ##type, code, __txt)); \
313 static guint gst_rtspsrc_signals[LAST_SIGNAL] = { 0 };
315 #define gst_rtspsrc_parent_class parent_class
316 G_DEFINE_TYPE_WITH_CODE (GstRTSPSrc, gst_rtspsrc, GST_TYPE_BIN,
317 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_rtspsrc_uri_handler_init));
320 default_select_stream (GstRTSPSrc * src, guint id, GstCaps * caps)
322 GST_DEBUG_OBJECT (src, "default handler");
327 select_stream_accum (GSignalInvocationHint * ihint,
328 GValue * return_accu, const GValue * handler_return, gpointer data)
332 myboolean = g_value_get_boolean (handler_return);
333 GST_DEBUG ("accum %d", myboolean);
334 g_value_set_boolean (return_accu, myboolean);
336 /* stop emission if FALSE */
341 gst_rtspsrc_class_init (GstRTSPSrcClass * klass)
343 GObjectClass *gobject_class;
344 GstElementClass *gstelement_class;
345 GstBinClass *gstbin_class;
347 gobject_class = (GObjectClass *) klass;
348 gstelement_class = (GstElementClass *) klass;
349 gstbin_class = (GstBinClass *) klass;
351 GST_DEBUG_CATEGORY_INIT (rtspsrc_debug, "rtspsrc", 0, "RTSP src");
353 gobject_class->set_property = gst_rtspsrc_set_property;
354 gobject_class->get_property = gst_rtspsrc_get_property;
356 gobject_class->finalize = gst_rtspsrc_finalize;
358 g_object_class_install_property (gobject_class, PROP_LOCATION,
359 g_param_spec_string ("location", "RTSP Location",
360 "Location of the RTSP url to read",
361 DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
363 g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
364 g_param_spec_flags ("protocols", "Protocols",
365 "Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
366 DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
368 g_object_class_install_property (gobject_class, PROP_DEBUG,
369 g_param_spec_boolean ("debug", "Debug",
370 "Dump request and response messages to stdout",
371 DEFAULT_DEBUG, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
373 g_object_class_install_property (gobject_class, PROP_RETRY,
374 g_param_spec_uint ("retry", "Retry",
375 "Max number of retries when allocating RTP ports.",
376 0, G_MAXUINT16, DEFAULT_RETRY,
377 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
379 g_object_class_install_property (gobject_class, PROP_TIMEOUT,
380 g_param_spec_uint64 ("timeout", "Timeout",
381 "Retry TCP transport after UDP timeout microseconds (0 = disabled)",
382 0, G_MAXUINT64, DEFAULT_TIMEOUT,
383 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
385 g_object_class_install_property (gobject_class, PROP_TCP_TIMEOUT,
386 g_param_spec_uint64 ("tcp-timeout", "TCP Timeout",
387 "Fail after timeout microseconds on TCP connections (0 = disabled)",
388 0, G_MAXUINT64, DEFAULT_TCP_TIMEOUT,
389 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
391 g_object_class_install_property (gobject_class, PROP_LATENCY,
392 g_param_spec_uint ("latency", "Buffer latency in ms",
393 "Amount of ms to buffer", 0, G_MAXUINT, DEFAULT_LATENCY_MS,
394 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
396 g_object_class_install_property (gobject_class, PROP_DROP_ON_LATENCY,
397 g_param_spec_boolean ("drop-on-latency",
398 "Drop buffers when maximum latency is reached",
399 "Tells the jitterbuffer to never exceed the given latency in size",
400 DEFAULT_DROP_ON_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
402 g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
403 g_param_spec_uint64 ("connection-speed", "Connection Speed",
404 "Network connection speed in kbps (0 = unknown)",
405 0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
406 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
408 g_object_class_install_property (gobject_class, PROP_NAT_METHOD,
409 g_param_spec_enum ("nat-method", "NAT Method",
410 "Method to use for traversing firewalls and NAT",
411 GST_TYPE_RTSP_NAT_METHOD, DEFAULT_NAT_METHOD,
412 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
415 * GstRTSPSrc::do-rtcp
417 * Enable RTCP support. Some old server don't like RTCP and then this property
418 * needs to be set to FALSE.
422 g_object_class_install_property (gobject_class, PROP_DO_RTCP,
423 g_param_spec_boolean ("do-rtcp", "Do RTCP",
424 "Send RTCP packets, disable for old incompatible server.",
425 DEFAULT_DO_RTCP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
428 * GstRTSPSrc::do-rtsp-keep-alive
430 * Enable RTSP keep laive support. Some old server don't like RTSP
431 * keep alive and then this property needs to be set to FALSE.
435 g_object_class_install_property (gobject_class, PROP_DO_RTSP_KEEP_ALIVE,
436 g_param_spec_boolean ("do-rtsp-keep-alive", "Do RTSP Keep Alive",
437 "Send RTSP keep alive packets, disable for old incompatible server.",
438 DEFAULT_DO_RTSP_KEEP_ALIVE,
439 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
444 * Set the proxy parameters. This has to be a string of the format
445 * [http://][user:passwd@]host[:port].
449 g_object_class_install_property (gobject_class, PROP_PROXY,
450 g_param_spec_string ("proxy", "Proxy",
451 "Proxy settings for HTTP tunneling. Format: [http://][user:passwd@]host[:port]",
452 DEFAULT_PROXY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
454 * GstRTSPSrc::proxy-id
456 * Sets the proxy URI user id for authentication. If the URI set via the
457 * "proxy" property contains a user-id already, that will take precedence.
461 g_object_class_install_property (gobject_class, PROP_PROXY_ID,
462 g_param_spec_string ("proxy-id", "proxy-id",
463 "HTTP proxy URI user id for authentication", "",
464 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
466 * GstRTSPSrc::proxy-pw
468 * Sets the proxy URI password for authentication. If the URI set via the
469 * "proxy" property contains a password already, that will take precedence.
473 g_object_class_install_property (gobject_class, PROP_PROXY_PW,
474 g_param_spec_string ("proxy-pw", "proxy-pw",
475 "HTTP proxy URI user password for authentication", "",
476 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
479 * GstRTSPSrc::rtp_blocksize
481 * RTP package size to suggest to server.
485 g_object_class_install_property (gobject_class, PROP_RTP_BLOCKSIZE,
486 g_param_spec_uint ("rtp-blocksize", "RTP Blocksize",
487 "RTP package size to suggest to server (0 = disabled)",
488 0, 65536, DEFAULT_RTP_BLOCKSIZE,
489 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
491 g_object_class_install_property (gobject_class,
493 g_param_spec_string ("user-id", "user-id",
494 "RTSP location URI user id for authentication", DEFAULT_USER_ID,
495 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
496 g_object_class_install_property (gobject_class, PROP_USER_PW,
497 g_param_spec_string ("user-pw", "user-pw",
498 "RTSP location URI user password for authentication", DEFAULT_USER_PW,
499 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
502 * GstRTSPSrc::buffer-mode:
504 * Control the buffering and timestamping mode used by the jitterbuffer.
508 g_object_class_install_property (gobject_class, PROP_BUFFER_MODE,
509 g_param_spec_enum ("buffer-mode", "Buffer Mode",
510 "Control the buffering algorithm in use",
511 GST_TYPE_RTSP_SRC_BUFFER_MODE, DEFAULT_BUFFER_MODE,
512 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
515 * GstRTSPSrc::port-range:
517 * Configure the client port numbers that can be used to recieve RTP and
522 g_object_class_install_property (gobject_class, PROP_PORT_RANGE,
523 g_param_spec_string ("port-range", "Port range",
524 "Client port range that can be used to receive RTP and RTCP data, "
525 "eg. 3000-3005 (NULL = no restrictions)", DEFAULT_PORT_RANGE,
526 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
529 * GstRTSPSrc::udp-buffer-size:
531 * Size of the kernel UDP receive buffer in bytes.
535 g_object_class_install_property (gobject_class, PROP_UDP_BUFFER_SIZE,
536 g_param_spec_int ("udp-buffer-size", "UDP Buffer Size",
537 "Size of the kernel UDP receive buffer in bytes, 0=default",
538 0, G_MAXINT, DEFAULT_UDP_BUFFER_SIZE,
539 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
542 * GstRTSPSrc::short-header:
544 * Only send the basic RTSP headers for broken encoders.
548 g_object_class_install_property (gobject_class, PROP_SHORT_HEADER,
549 g_param_spec_boolean ("short-header", "Short Header",
550 "Only send the basic RTSP headers for broken encoders",
551 DEFAULT_SHORT_HEADER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
553 g_object_class_install_property (gobject_class, PROP_PROBATION,
554 g_param_spec_uint ("probation", "Number of probations",
555 "Consecutive packet sequence numbers to accept the source",
556 0, G_MAXUINT, DEFAULT_PROBATION,
557 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
559 g_object_class_install_property (gobject_class, PROP_UDP_RECONNECT,
560 g_param_spec_boolean ("udp-reconnect", "Reconnect to the server",
561 "Reconnect to the server if RTSP connection is closed when doing UDP",
562 DEFAULT_UDP_RECONNECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
564 g_object_class_install_property (gobject_class, PROP_MULTICAST_IFACE,
565 g_param_spec_string ("multicast-iface", "Multicast Interface",
566 "The network interface on which to join the multicast group",
567 DEFAULT_MULTICAST_IFACE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
569 g_object_class_install_property (gobject_class, PROP_NTP_SYNC,
570 g_param_spec_boolean ("ntp-sync", "Sync on NTP clock",
571 "Synchronize received streams to the NTP clock", DEFAULT_NTP_SYNC,
572 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
574 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
575 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
576 "Use the pipeline running-time to set the NTP time in the RTCP SR messages",
577 DEFAULT_USE_PIPELINE_CLOCK,
578 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
580 g_object_class_install_property (gobject_class, PROP_SDES,
581 g_param_spec_boxed ("sdes", "SDES",
582 "The SDES items of this session",
583 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
586 * GstRTSPSrc::handle-request:
587 * @rtspsrc: a #GstRTSPSrc
588 * @request: a #GstRTSPMessage
589 * @response: a #GstRTSPMessage
591 * Handle a server request in @request and prepare @response.
593 * This signal is called from the streaming thread, you should therefore not
594 * do any state changes on @rtspsrc because this might deadlock. If you want
595 * to modify the state as a result of this signal, post a
596 * #GST_MESSAGE_REQUEST_STATE message on the bus or signal the main thread
601 gst_rtspsrc_signals[SIGNAL_HANDLE_REQUEST] =
602 g_signal_new ("handle-request", G_TYPE_FROM_CLASS (klass), 0,
603 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 2,
604 G_TYPE_POINTER, G_TYPE_POINTER);
607 * GstRTSPSrc::on-sdp:
608 * @rtspsrc: a #GstRTSPSrc
609 * @sdp: a #GstSDPMessage
611 * Emited when the client has retrieved the SDP and before it configures the
612 * streams in the SDP. @sdp can be inspected and modified.
614 * This signal is called from the streaming thread, you should therefore not
615 * do any state changes on @rtspsrc because this might deadlock. If you want
616 * to modify the state as a result of this signal, post a
617 * #GST_MESSAGE_REQUEST_STATE message on the bus or signal the main thread
622 gst_rtspsrc_signals[SIGNAL_ON_SDP] =
623 g_signal_new ("on-sdp", G_TYPE_FROM_CLASS (klass), 0,
624 0, NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1,
625 GST_TYPE_SDP_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE);
628 * GstRTSPSrc::select-stream:
629 * @rtspsrc: a #GstRTSPSrc
630 * @num: the stream number
631 * @caps: the stream caps
633 * Emited before the client decides to configure the stream @num with
636 * Returns: %TRUE when the stream should be selected, %FALSE when the stream
641 gst_rtspsrc_signals[SIGNAL_SELECT_STREAM] =
642 g_signal_new_class_handler ("select-stream", G_TYPE_FROM_CLASS (klass),
643 G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_CLEANUP,
644 (GCallback) default_select_stream, select_stream_accum, NULL,
645 g_cclosure_marshal_generic, G_TYPE_BOOLEAN, 2, G_TYPE_UINT,
648 gstelement_class->send_event = gst_rtspsrc_send_event;
649 gstelement_class->provide_clock = gst_rtspsrc_provide_clock;
650 gstelement_class->change_state = gst_rtspsrc_change_state;
652 gst_element_class_add_pad_template (gstelement_class,
653 gst_static_pad_template_get (&rtptemplate));
655 gst_element_class_set_static_metadata (gstelement_class,
656 "RTSP packet receiver", "Source/Network",
657 "Receive data over the network via RTSP (RFC 2326)",
658 "Wim Taymans <wim@fluendo.com>, "
659 "Thijs Vermeir <thijs.vermeir@barco.com>, "
660 "Lutz Mueller <lutz@topfrose.de>");
662 gstbin_class->handle_message = gst_rtspsrc_handle_message;
664 gst_rtsp_ext_list_init ();
668 gst_rtspsrc_init (GstRTSPSrc * src)
670 src->conninfo.location = g_strdup (DEFAULT_LOCATION);
671 src->protocols = DEFAULT_PROTOCOLS;
672 src->debug = DEFAULT_DEBUG;
673 src->retry = DEFAULT_RETRY;
674 src->udp_timeout = DEFAULT_TIMEOUT;
675 gst_rtspsrc_set_tcp_timeout (src, DEFAULT_TCP_TIMEOUT);
676 src->latency = DEFAULT_LATENCY_MS;
677 src->drop_on_latency = DEFAULT_DROP_ON_LATENCY;
678 src->connection_speed = DEFAULT_CONNECTION_SPEED;
679 src->nat_method = DEFAULT_NAT_METHOD;
680 src->do_rtcp = DEFAULT_DO_RTCP;
681 src->do_rtsp_keep_alive = DEFAULT_DO_RTSP_KEEP_ALIVE;
682 gst_rtspsrc_set_proxy (src, DEFAULT_PROXY);
683 src->rtp_blocksize = DEFAULT_RTP_BLOCKSIZE;
684 src->user_id = g_strdup (DEFAULT_USER_ID);
685 src->user_pw = g_strdup (DEFAULT_USER_PW);
686 src->buffer_mode = DEFAULT_BUFFER_MODE;
687 src->client_port_range.min = 0;
688 src->client_port_range.max = 0;
689 src->udp_buffer_size = DEFAULT_UDP_BUFFER_SIZE;
690 src->short_header = DEFAULT_SHORT_HEADER;
691 src->probation = DEFAULT_PROBATION;
692 src->udp_reconnect = DEFAULT_UDP_RECONNECT;
693 src->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
694 src->ntp_sync = DEFAULT_NTP_SYNC;
695 src->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
698 /* get a list of all extensions */
699 src->extensions = gst_rtsp_ext_list_get ();
701 /* connect to send signal */
702 gst_rtsp_ext_list_connect (src->extensions, "send",
703 (GCallback) gst_rtspsrc_send_cb, src);
705 /* protects the streaming thread in interleaved mode or the polling
706 * thread in UDP mode. */
707 g_rec_mutex_init (&src->stream_rec_lock);
709 /* protects our state changes from multiple invocations */
710 g_rec_mutex_init (&src->state_rec_lock);
712 src->state = GST_RTSP_STATE_INVALID;
714 GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_SOURCE);
718 gst_rtspsrc_finalize (GObject * object)
722 rtspsrc = GST_RTSPSRC (object);
724 gst_rtsp_ext_list_free (rtspsrc->extensions);
725 g_free (rtspsrc->conninfo.location);
726 gst_rtsp_url_free (rtspsrc->conninfo.url);
727 g_free (rtspsrc->conninfo.url_str);
728 g_free (rtspsrc->user_id);
729 g_free (rtspsrc->user_pw);
730 g_free (rtspsrc->multi_iface);
733 gst_sdp_message_free (rtspsrc->sdp);
736 if (rtspsrc->provided_clock)
737 gst_object_unref (rtspsrc->provided_clock);
740 gst_structure_free (rtspsrc->sdes);
743 g_rec_mutex_clear (&rtspsrc->stream_rec_lock);
744 g_rec_mutex_clear (&rtspsrc->state_rec_lock);
746 G_OBJECT_CLASS (parent_class)->finalize (object);
750 gst_rtspsrc_provide_clock (GstElement * element)
752 GstRTSPSrc *src = GST_RTSPSRC (element);
755 if ((clock = src->provided_clock) != NULL)
756 gst_object_ref (clock);
761 /* a proxy string of the format [user:passwd@]host[:port] */
763 gst_rtspsrc_set_proxy (GstRTSPSrc * rtsp, const gchar * proxy)
767 g_free (rtsp->proxy_user);
768 rtsp->proxy_user = NULL;
769 g_free (rtsp->proxy_passwd);
770 rtsp->proxy_passwd = NULL;
771 g_free (rtsp->proxy_host);
772 rtsp->proxy_host = NULL;
773 rtsp->proxy_port = 0;
780 /* we allow http:// in front but ignore it */
781 if (g_str_has_prefix (p, "http://"))
784 at = strchr (p, '@');
786 /* look for user:passwd */
787 col = strchr (proxy, ':');
788 if (col == NULL || col > at)
791 rtsp->proxy_user = g_strndup (p, col - p);
793 rtsp->proxy_passwd = g_strndup (col, at - col);
798 if (rtsp->prop_proxy_id != NULL && *rtsp->prop_proxy_id != '\0')
799 rtsp->proxy_user = g_strdup (rtsp->prop_proxy_id);
800 if (rtsp->prop_proxy_pw != NULL && *rtsp->prop_proxy_pw != '\0')
801 rtsp->proxy_passwd = g_strdup (rtsp->prop_proxy_pw);
802 if (rtsp->proxy_user != NULL || rtsp->proxy_passwd != NULL) {
803 GST_LOG_OBJECT (rtsp, "set proxy user/pw from properties: %s:%s",
804 GST_STR_NULL (rtsp->proxy_user), GST_STR_NULL (rtsp->proxy_passwd));
807 col = strchr (p, ':');
810 /* everything before the colon is the hostname */
811 rtsp->proxy_host = g_strndup (p, col - p);
813 rtsp->proxy_port = strtoul (p, (char **) &p, 10);
815 rtsp->proxy_host = g_strdup (p);
816 rtsp->proxy_port = 8080;
822 gst_rtspsrc_set_tcp_timeout (GstRTSPSrc * rtspsrc, guint64 timeout)
824 rtspsrc->tcp_timeout.tv_sec = timeout / G_USEC_PER_SEC;
825 rtspsrc->tcp_timeout.tv_usec = timeout % G_USEC_PER_SEC;
828 rtspsrc->ptcp_timeout = &rtspsrc->tcp_timeout;
830 rtspsrc->ptcp_timeout = NULL;
834 gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value,
839 rtspsrc = GST_RTSPSRC (object);
843 gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (rtspsrc),
844 g_value_get_string (value), NULL);
847 rtspsrc->protocols = g_value_get_flags (value);
850 rtspsrc->debug = g_value_get_boolean (value);
853 rtspsrc->retry = g_value_get_uint (value);
856 rtspsrc->udp_timeout = g_value_get_uint64 (value);
858 case PROP_TCP_TIMEOUT:
859 gst_rtspsrc_set_tcp_timeout (rtspsrc, g_value_get_uint64 (value));
862 rtspsrc->latency = g_value_get_uint (value);
864 case PROP_DROP_ON_LATENCY:
865 rtspsrc->drop_on_latency = g_value_get_boolean (value);
867 case PROP_CONNECTION_SPEED:
868 rtspsrc->connection_speed = g_value_get_uint64 (value);
870 case PROP_NAT_METHOD:
871 rtspsrc->nat_method = g_value_get_enum (value);
874 rtspsrc->do_rtcp = g_value_get_boolean (value);
876 case PROP_DO_RTSP_KEEP_ALIVE:
877 rtspsrc->do_rtsp_keep_alive = g_value_get_boolean (value);
880 gst_rtspsrc_set_proxy (rtspsrc, g_value_get_string (value));
883 if (rtspsrc->prop_proxy_id)
884 g_free (rtspsrc->prop_proxy_id);
885 rtspsrc->prop_proxy_id = g_value_dup_string (value);
888 if (rtspsrc->prop_proxy_pw)
889 g_free (rtspsrc->prop_proxy_pw);
890 rtspsrc->prop_proxy_pw = g_value_dup_string (value);
892 case PROP_RTP_BLOCKSIZE:
893 rtspsrc->rtp_blocksize = g_value_get_uint (value);
896 if (rtspsrc->user_id)
897 g_free (rtspsrc->user_id);
898 rtspsrc->user_id = g_value_dup_string (value);
901 if (rtspsrc->user_pw)
902 g_free (rtspsrc->user_pw);
903 rtspsrc->user_pw = g_value_dup_string (value);
905 case PROP_BUFFER_MODE:
906 rtspsrc->buffer_mode = g_value_get_enum (value);
908 case PROP_PORT_RANGE:
912 str = g_value_get_string (value);
914 sscanf (str, "%u-%u",
915 &rtspsrc->client_port_range.min, &rtspsrc->client_port_range.max);
917 rtspsrc->client_port_range.min = 0;
918 rtspsrc->client_port_range.max = 0;
922 case PROP_UDP_BUFFER_SIZE:
923 rtspsrc->udp_buffer_size = g_value_get_int (value);
925 case PROP_SHORT_HEADER:
926 rtspsrc->short_header = g_value_get_boolean (value);
929 rtspsrc->probation = g_value_get_uint (value);
931 case PROP_UDP_RECONNECT:
932 rtspsrc->udp_reconnect = g_value_get_boolean (value);
934 case PROP_MULTICAST_IFACE:
935 g_free (rtspsrc->multi_iface);
937 if (g_value_get_string (value) == NULL)
938 rtspsrc->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
940 rtspsrc->multi_iface = g_value_dup_string (value);
943 rtspsrc->ntp_sync = g_value_get_boolean (value);
945 case PROP_USE_PIPELINE_CLOCK:
946 rtspsrc->use_pipeline_clock = g_value_get_boolean (value);
949 rtspsrc->sdes = g_value_dup_boxed (value);
952 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
958 gst_rtspsrc_get_property (GObject * object, guint prop_id, GValue * value,
963 rtspsrc = GST_RTSPSRC (object);
967 g_value_set_string (value, rtspsrc->conninfo.location);
970 g_value_set_flags (value, rtspsrc->protocols);
973 g_value_set_boolean (value, rtspsrc->debug);
976 g_value_set_uint (value, rtspsrc->retry);
979 g_value_set_uint64 (value, rtspsrc->udp_timeout);
981 case PROP_TCP_TIMEOUT:
985 timeout = rtspsrc->tcp_timeout.tv_sec * G_USEC_PER_SEC +
986 rtspsrc->tcp_timeout.tv_usec;
987 g_value_set_uint64 (value, timeout);
991 g_value_set_uint (value, rtspsrc->latency);
993 case PROP_DROP_ON_LATENCY:
994 g_value_set_boolean (value, rtspsrc->drop_on_latency);
996 case PROP_CONNECTION_SPEED:
997 g_value_set_uint64 (value, rtspsrc->connection_speed);
999 case PROP_NAT_METHOD:
1000 g_value_set_enum (value, rtspsrc->nat_method);
1003 g_value_set_boolean (value, rtspsrc->do_rtcp);
1005 case PROP_DO_RTSP_KEEP_ALIVE:
1006 g_value_set_boolean (value, rtspsrc->do_rtsp_keep_alive);
1012 if (rtspsrc->proxy_host) {
1014 g_strdup_printf ("%s:%d", rtspsrc->proxy_host, rtspsrc->proxy_port);
1018 g_value_take_string (value, str);
1022 g_value_set_string (value, rtspsrc->prop_proxy_id);
1025 g_value_set_string (value, rtspsrc->prop_proxy_pw);
1027 case PROP_RTP_BLOCKSIZE:
1028 g_value_set_uint (value, rtspsrc->rtp_blocksize);
1031 g_value_set_string (value, rtspsrc->user_id);
1034 g_value_set_string (value, rtspsrc->user_pw);
1036 case PROP_BUFFER_MODE:
1037 g_value_set_enum (value, rtspsrc->buffer_mode);
1039 case PROP_PORT_RANGE:
1043 if (rtspsrc->client_port_range.min != 0) {
1044 str = g_strdup_printf ("%u-%u", rtspsrc->client_port_range.min,
1045 rtspsrc->client_port_range.max);
1049 g_value_take_string (value, str);
1052 case PROP_UDP_BUFFER_SIZE:
1053 g_value_set_int (value, rtspsrc->udp_buffer_size);
1055 case PROP_SHORT_HEADER:
1056 g_value_set_boolean (value, rtspsrc->short_header);
1058 case PROP_PROBATION:
1059 g_value_set_uint (value, rtspsrc->probation);
1061 case PROP_UDP_RECONNECT:
1062 g_value_set_boolean (value, rtspsrc->udp_reconnect);
1064 case PROP_MULTICAST_IFACE:
1065 g_value_set_string (value, rtspsrc->multi_iface);
1068 g_value_set_boolean (value, rtspsrc->ntp_sync);
1070 case PROP_USE_PIPELINE_CLOCK:
1071 g_value_set_boolean (value, rtspsrc->use_pipeline_clock);
1074 g_value_set_boxed (value, rtspsrc->sdes);
1077 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1083 find_stream_by_id (GstRTSPStream * stream, gint * id)
1085 if (stream->id == *id)
1092 find_stream_by_channel (GstRTSPStream * stream, gint * channel)
1094 if (stream->channel[0] == *channel || stream->channel[1] == *channel)
1101 find_stream_by_pt (GstRTSPStream * stream, gint * pt)
1103 if (stream->pt == *pt)
1110 find_stream_by_udpsrc (GstRTSPStream * stream, gconstpointer a)
1112 GstElement *src = (GstElement *) a;
1114 if (stream->udpsrc[0] == src)
1116 if (stream->udpsrc[1] == src)
1123 find_stream_by_setup (GstRTSPStream * stream, gconstpointer a)
1125 /* check qualified setup_url */
1126 if (!strcmp (stream->conninfo.location, (gchar *) a))
1128 /* check original control_url */
1129 if (!strcmp (stream->control_url, (gchar *) a))
1132 /* check if qualified setup_url ends with string */
1133 if (g_str_has_suffix (stream->control_url, (gchar *) a))
1139 static GstRTSPStream *
1140 find_stream (GstRTSPSrc * src, gconstpointer data, gconstpointer func)
1144 /* find and get stream */
1145 if ((lstream = g_list_find_custom (src->streams, data, (GCompareFunc) func)))
1146 return (GstRTSPStream *) lstream->data;
1151 static const GstSDPBandwidth *
1152 gst_rtspsrc_get_bandwidth (GstRTSPSrc * src, const GstSDPMessage * sdp,
1153 const GstSDPMedia * media, const gchar * type)
1157 /* first look in the media specific section */
1158 len = gst_sdp_media_bandwidths_len (media);
1159 for (i = 0; i < len; i++) {
1160 const GstSDPBandwidth *bw = gst_sdp_media_get_bandwidth (media, i);
1162 if (strcmp (bw->bwtype, type) == 0)
1165 /* then look in the message specific section */
1166 len = gst_sdp_message_bandwidths_len (sdp);
1167 for (i = 0; i < len; i++) {
1168 const GstSDPBandwidth *bw = gst_sdp_message_get_bandwidth (sdp, i);
1170 if (strcmp (bw->bwtype, type) == 0)
1177 gst_rtspsrc_collect_bandwidth (GstRTSPSrc * src, const GstSDPMessage * sdp,
1178 const GstSDPMedia * media, GstRTSPStream * stream)
1180 const GstSDPBandwidth *bw;
1182 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_AS)))
1183 stream->as_bandwidth = bw->bandwidth;
1185 stream->as_bandwidth = -1;
1187 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_RR)))
1188 stream->rr_bandwidth = bw->bandwidth;
1190 stream->rr_bandwidth = -1;
1192 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_RS)))
1193 stream->rs_bandwidth = bw->bandwidth;
1195 stream->rs_bandwidth = -1;
1199 gst_rtspsrc_do_stream_connection (GstRTSPSrc * src, GstRTSPStream * stream,
1200 const GstSDPConnection * conn)
1202 if (conn->nettype == NULL || strcmp (conn->nettype, "IN") != 0)
1205 if (conn->addrtype == NULL)
1208 /* check for IPV6 */
1209 if (strcmp (conn->addrtype, "IP4") == 0)
1210 stream->is_ipv6 = FALSE;
1211 else if (strcmp (conn->addrtype, "IP6") == 0)
1212 stream->is_ipv6 = TRUE;
1217 g_free (stream->destination);
1218 stream->destination = g_strdup (conn->address);
1220 /* check for multicast */
1221 stream->is_multicast =
1222 gst_sdp_address_is_multicast (conn->nettype, conn->addrtype,
1224 stream->ttl = conn->ttl;
1227 /* Go over the connections for a stream.
1228 * - If we are dealing with IPV6, we will setup IPV6 sockets for sending and
1230 * - If we are dealing with a localhost address, we disable multicast
1233 gst_rtspsrc_collect_connections (GstRTSPSrc * src, const GstSDPMessage * sdp,
1234 const GstSDPMedia * media, GstRTSPStream * stream)
1236 const GstSDPConnection *conn;
1239 /* first look in the media specific section */
1240 len = gst_sdp_media_connections_len (media);
1241 for (i = 0; i < len; i++) {
1242 conn = gst_sdp_media_get_connection (media, i);
1244 gst_rtspsrc_do_stream_connection (src, stream, conn);
1246 /* then look in the message specific section */
1247 if ((conn = gst_sdp_message_get_connection (sdp))) {
1248 gst_rtspsrc_do_stream_connection (src, stream, conn);
1252 static GstRTSPStream *
1253 gst_rtspsrc_create_stream (GstRTSPSrc * src, GstSDPMessage * sdp, gint idx)
1255 GstRTSPStream *stream;
1256 const gchar *control_url;
1257 const gchar *payload;
1258 const GstSDPMedia *media;
1260 /* get media, should not return NULL */
1261 media = gst_sdp_message_get_media (sdp, idx);
1265 stream = g_new0 (GstRTSPStream, 1);
1266 stream->parent = src;
1267 /* we mark the pad as not linked, we will mark it as OK when we add the pad to
1269 stream->last_ret = GST_FLOW_NOT_LINKED;
1270 stream->added = FALSE;
1271 stream->disabled = FALSE;
1272 stream->id = src->numstreams++;
1273 stream->eos = FALSE;
1274 stream->discont = TRUE;
1275 stream->seqbase = -1;
1276 stream->timebase = -1;
1278 /* collect bandwidth information for this steam. FIXME, configure in the RTP
1279 * session manager to scale RTCP. */
1280 gst_rtspsrc_collect_bandwidth (src, sdp, media, stream);
1282 /* collect connection info */
1283 gst_rtspsrc_collect_connections (src, sdp, media, stream);
1285 /* we must have a payload. No payload means we cannot create caps */
1286 /* FIXME, handle multiple formats. The problem here is that we just want to
1287 * take the first available format that we can handle but in order to do that
1288 * we need to scan for depayloader plugins. Scanning for payloader plugins is
1289 * also suboptimal because the user maybe just wants to save the raw stream
1290 * and then we don't care. */
1291 if ((payload = gst_sdp_media_get_format (media, 0))) {
1292 stream->pt = atoi (payload);
1294 stream->caps = gst_rtspsrc_media_to_caps (stream->pt, media);
1296 GST_DEBUG ("mapping sdp session level attributes to caps");
1297 gst_rtspsrc_sdp_attributes_to_caps (sdp->attributes, stream->caps);
1298 GST_DEBUG ("mapping sdp media level attributes to caps");
1299 gst_rtspsrc_sdp_attributes_to_caps (media->attributes, stream->caps);
1301 if (stream->pt >= 96) {
1302 /* If we have a dynamic payload type, see if we have a stream with the
1303 * same payload number. If there is one, they are part of the same
1304 * container and we only need to add one pad. */
1305 if (find_stream (src, &stream->pt, (gpointer) find_stream_by_pt)) {
1306 stream->container = TRUE;
1307 GST_DEBUG ("found another stream with pt %d, marking as container",
1312 /* collect port number */
1313 stream->port = gst_sdp_media_get_port (media);
1315 /* get control url to construct the setup url. The setup url is used to
1316 * configure the transport of the stream and is used to identity the stream in
1317 * the RTP-Info header field returned from PLAY. */
1318 control_url = gst_sdp_media_get_attribute_val (media, "control");
1319 if (control_url == NULL)
1320 control_url = gst_sdp_message_get_attribute_val_n (sdp, "control", 0);
1322 GST_DEBUG_OBJECT (src, "stream %d, (%p)", stream->id, stream);
1323 GST_DEBUG_OBJECT (src, " pt: %d", stream->pt);
1324 GST_DEBUG_OBJECT (src, " port: %d", stream->port);
1325 GST_DEBUG_OBJECT (src, " container: %d", stream->container);
1326 GST_DEBUG_OBJECT (src, " caps: %" GST_PTR_FORMAT, stream->caps);
1327 GST_DEBUG_OBJECT (src, " control: %s", GST_STR_NULL (control_url));
1329 if (control_url != NULL) {
1330 stream->control_url = g_strdup (control_url);
1331 /* Build a fully qualified url using the content_base if any or by prefixing
1332 * the original request.
1333 * If the control_url starts with a '/' or a non rtsp: protocol we will most
1334 * likely build a URL that the server will fail to understand, this is ok,
1335 * we will fail then. */
1336 if (g_str_has_prefix (control_url, "rtsp://"))
1337 stream->conninfo.location = g_strdup (control_url);
1342 if (g_strcmp0 (control_url, "*") == 0)
1346 base = src->control;
1347 else if (src->content_base)
1348 base = src->content_base;
1349 else if (src->conninfo.url_str)
1350 base = src->conninfo.url_str;
1354 /* check if the base ends or control starts with / */
1355 has_slash = g_str_has_prefix (control_url, "/");
1356 has_slash = has_slash || g_str_has_suffix (base, "/");
1358 /* concatenate the two strings, insert / when not present */
1359 stream->conninfo.location =
1360 g_strdup_printf ("%s%s%s", base, has_slash ? "" : "/", control_url);
1363 GST_DEBUG_OBJECT (src, " setup: %s",
1364 GST_STR_NULL (stream->conninfo.location));
1366 /* we keep track of all streams */
1367 src->streams = g_list_append (src->streams, stream);
1375 gst_rtspsrc_stream_free (GstRTSPSrc * src, GstRTSPStream * stream)
1379 GST_DEBUG_OBJECT (src, "free stream %p", stream);
1382 gst_caps_unref (stream->caps);
1384 g_free (stream->destination);
1385 g_free (stream->control_url);
1386 g_free (stream->conninfo.location);
1388 for (i = 0; i < 2; i++) {
1389 if (stream->udpsrc[i]) {
1390 gst_element_set_state (stream->udpsrc[i], GST_STATE_NULL);
1391 gst_bin_remove (GST_BIN_CAST (src), stream->udpsrc[i]);
1392 gst_object_unref (stream->udpsrc[i]);
1393 stream->udpsrc[i] = NULL;
1395 if (stream->channelpad[i]) {
1396 gst_object_unref (stream->channelpad[i]);
1397 stream->channelpad[i] = NULL;
1399 if (stream->udpsink[i]) {
1400 gst_element_set_state (stream->udpsink[i], GST_STATE_NULL);
1401 gst_bin_remove (GST_BIN_CAST (src), stream->udpsink[i]);
1402 gst_object_unref (stream->udpsink[i]);
1403 stream->udpsink[i] = NULL;
1406 if (stream->fakesrc) {
1407 gst_element_set_state (stream->fakesrc, GST_STATE_NULL);
1408 gst_bin_remove (GST_BIN_CAST (src), stream->fakesrc);
1409 gst_object_unref (stream->fakesrc);
1410 stream->fakesrc = NULL;
1412 if (stream->srcpad) {
1413 gst_pad_set_active (stream->srcpad, FALSE);
1414 if (stream->added) {
1415 gst_element_remove_pad (GST_ELEMENT_CAST (src), stream->srcpad);
1416 stream->added = FALSE;
1418 stream->srcpad = NULL;
1420 if (stream->rtcppad) {
1421 gst_object_unref (stream->rtcppad);
1422 stream->rtcppad = NULL;
1424 if (stream->session) {
1425 g_object_unref (stream->session);
1426 stream->session = NULL;
1432 gst_rtspsrc_cleanup (GstRTSPSrc * src)
1436 GST_DEBUG_OBJECT (src, "cleanup");
1438 for (walk = src->streams; walk; walk = g_list_next (walk)) {
1439 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
1441 gst_rtspsrc_stream_free (src, stream);
1443 g_list_free (src->streams);
1444 src->streams = NULL;
1446 if (src->manager_sig_id) {
1447 g_signal_handler_disconnect (src->manager, src->manager_sig_id);
1448 src->manager_sig_id = 0;
1450 gst_element_set_state (src->manager, GST_STATE_NULL);
1451 gst_bin_remove (GST_BIN_CAST (src), src->manager);
1452 src->manager = NULL;
1454 src->numstreams = 0;
1456 gst_structure_free (src->props);
1459 g_free (src->content_base);
1460 src->content_base = NULL;
1462 g_free (src->control);
1463 src->control = NULL;
1466 gst_rtsp_range_free (src->range);
1469 /* don't clear the SDP when it was used in the url */
1470 if (src->sdp && !src->from_sdp) {
1471 gst_sdp_message_free (src->sdp);
1474 if (src->start_segment) {
1475 gst_event_unref (src->start_segment);
1476 src->start_segment = NULL;
1478 if (src->provided_clock) {
1479 gst_object_unref (src->provided_clock);
1480 src->provided_clock = NULL;
1484 #define PARSE_INT(p, del, res) \
1487 p = strstr (p, del); \
1497 #define PARSE_STRING(p, del, res) \
1500 p = strstr (p, del); \
1512 #define SKIP_SPACES(p) \
1513 while (*p && g_ascii_isspace (*p)) \
1518 * <payload> <encoding_name>/<clock_rate>[/<encoding_params>]
1521 gst_rtspsrc_parse_rtpmap (const gchar * rtpmap, gint * payload, gchar ** name,
1522 gint * rate, gchar ** params)
1526 p = (gchar *) rtpmap;
1528 PARSE_INT (p, " ", *payload);
1536 PARSE_STRING (p, "/", *name);
1537 if (*name == NULL) {
1538 GST_DEBUG ("no rate, name %s", p);
1539 /* no rate, assume -1 then, this is not supposed to happen but RealMedia
1540 * streams seem to omit the rate. */
1547 p = strstr (p, "/");
1565 * Mapping SDP attributes to caps
1567 * prepend 'a-' to IANA registered sdp attributes names
1568 * (ie: not prefixed with 'x-') in order to avoid
1569 * collision with gstreamer standard caps properties names
1572 gst_rtspsrc_sdp_attributes_to_caps (GArray * attributes, GstCaps * caps)
1574 if (attributes->len > 0) {
1578 s = gst_caps_get_structure (caps, 0);
1580 for (i = 0; i < attributes->len; i++) {
1581 GstSDPAttribute *attr = &g_array_index (attributes, GstSDPAttribute, i);
1582 gchar *tofree, *key;
1586 /* skip some of the attribute we already handle */
1587 if (!strcmp (key, "fmtp"))
1589 if (!strcmp (key, "rtpmap"))
1591 if (!strcmp (key, "control"))
1593 if (!strcmp (key, "range"))
1596 /* string must be valid UTF8 */
1597 if (!g_utf8_validate (attr->value, -1, NULL))
1600 if (!g_str_has_prefix (key, "x-"))
1601 tofree = key = g_strdup_printf ("a-%s", key);
1605 GST_DEBUG ("adding caps: %s=%s", key, attr->value);
1606 gst_structure_set (s, key, G_TYPE_STRING, attr->value, NULL);
1613 * Mapping of caps to and from SDP fields:
1615 * m=<media> <UDP port> RTP/AVP <payload>
1616 * a=rtpmap:<payload> <encoding_name>/<clock_rate>[/<encoding_params>]
1617 * a=fmtp:<payload> <param>[=<value>];...
1620 gst_rtspsrc_media_to_caps (gint pt, const GstSDPMedia * media)
1623 const gchar *rtpmap;
1627 gchar *params = NULL;
1633 /* get and parse rtpmap */
1634 if ((rtpmap = gst_sdp_media_get_attribute_val (media, "rtpmap"))) {
1635 ret = gst_rtspsrc_parse_rtpmap (rtpmap, &payload, &name, &rate, ¶ms);
1637 if (payload != pt) {
1638 /* we ignore the rtpmap if the payload type is different. */
1639 g_warning ("rtpmap of wrong payload type, ignoring");
1645 /* if we failed to parse the rtpmap for a dynamic payload type, we have an
1649 /* else we can ignore */
1650 g_warning ("error parsing rtpmap, ignoring");
1653 /* dynamic payloads need rtpmap or we fail */
1657 /* check if we have a rate, if not, we need to look up the rate from the
1658 * default rates based on the payload types. */
1660 const GstRTPPayloadInfo *info;
1662 if (GST_RTP_PAYLOAD_IS_DYNAMIC (pt)) {
1663 /* dynamic types, use media and encoding_name */
1664 tmp = g_ascii_strdown (media->media, -1);
1665 info = gst_rtp_payload_info_for_name (tmp, name);
1668 /* static types, use payload type */
1669 info = gst_rtp_payload_info_for_pt (pt);
1673 if ((rate = info->clock_rate) == 0)
1676 /* we fail if we cannot find one */
1681 tmp = g_ascii_strdown (media->media, -1);
1682 caps = gst_caps_new_simple ("application/x-unknown",
1683 "media", G_TYPE_STRING, tmp, "payload", G_TYPE_INT, pt, NULL);
1685 s = gst_caps_get_structure (caps, 0);
1687 gst_structure_set (s, "clock-rate", G_TYPE_INT, rate, NULL);
1689 /* encoding name must be upper case */
1691 tmp = g_ascii_strup (name, -1);
1692 gst_structure_set (s, "encoding-name", G_TYPE_STRING, tmp, NULL);
1696 /* params must be lower case */
1697 if (params != NULL) {
1698 tmp = g_ascii_strdown (params, -1);
1699 gst_structure_set (s, "encoding-params", G_TYPE_STRING, tmp, NULL);
1703 /* parse optional fmtp: field */
1704 if ((fmtp = gst_sdp_media_get_attribute_val (media, "fmtp"))) {
1710 /* p is now of the format <payload> <param>[=<value>];... */
1711 PARSE_INT (p, " ", payload);
1712 if (payload != -1 && payload == pt) {
1716 /* <param>[=<value>] are separated with ';' */
1717 pairs = g_strsplit (p, ";", 0);
1718 for (i = 0; pairs[i]; i++) {
1720 const gchar *val, *key;
1722 /* the key may not have a '=', the value can have other '='s */
1723 valpos = strstr (pairs[i], "=");
1725 /* we have a '=' and thus a value, remove the '=' with \0 */
1727 /* value is everything between '=' and ';'. We split the pairs at ;
1728 * boundaries so we can take the remainder of the value. Some servers
1729 * put spaces around the value which we strip off here. Alternatively
1730 * we could strip those spaces in the depayloaders should these spaces
1731 * actually carry any meaning in the future. */
1732 val = g_strstrip (valpos + 1);
1734 /* simple <param>;.. is translated into <param>=1;... */
1737 /* strip the key of spaces, convert key to lowercase but not the value. */
1738 key = g_strstrip (pairs[i]);
1739 if (strlen (key) > 1) {
1740 tmp = g_ascii_strdown (key, -1);
1741 gst_structure_set (s, tmp, G_TYPE_STRING, val, NULL);
1753 g_warning ("rtpmap type not given for dynamic payload %d", pt);
1758 g_warning ("rate unknown for payload type %d", pt);
1764 gst_rtspsrc_alloc_udp_ports (GstRTSPStream * stream,
1765 gint * rtpport, gint * rtcpport)
1768 GstStateChangeReturn ret;
1769 GstElement *udpsrc0, *udpsrc1;
1770 gint tmp_rtp, tmp_rtcp;
1774 src = stream->parent;
1780 /* Start at next port */
1781 tmp_rtp = src->next_port_num;
1783 if (stream->is_ipv6)
1784 host = "udp://[::0]";
1786 host = "udp://0.0.0.0";
1788 /* try to allocate 2 UDP ports, the RTP port should be an even
1789 * number and the RTCP port should be the next (uneven) port */
1792 if (tmp_rtp != 0 && src->client_port_range.max > 0 &&
1793 tmp_rtp >= src->client_port_range.max)
1796 udpsrc0 = gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
1797 if (udpsrc0 == NULL)
1798 goto no_udp_protocol;
1799 g_object_set (G_OBJECT (udpsrc0), "port", tmp_rtp, "reuse", FALSE, NULL);
1801 if (src->udp_buffer_size != 0)
1802 g_object_set (G_OBJECT (udpsrc0), "buffer-size", src->udp_buffer_size,
1805 ret = gst_element_set_state (udpsrc0, GST_STATE_PAUSED);
1806 if (ret == GST_STATE_CHANGE_FAILURE) {
1808 GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTP port %d", tmp_rtp);
1811 if (++count > src->retry)
1814 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
1815 gst_element_set_state (udpsrc0, GST_STATE_NULL);
1816 gst_object_unref (udpsrc0);
1819 GST_DEBUG_OBJECT (src, "retry %d", count);
1822 goto no_udp_protocol;
1825 g_object_get (G_OBJECT (udpsrc0), "port", &tmp_rtp, NULL);
1826 GST_DEBUG_OBJECT (src, "got RTP port %d", tmp_rtp);
1828 /* check if port is even */
1829 if ((tmp_rtp & 0x01) != 0) {
1830 /* port not even, close and allocate another */
1831 if (++count > src->retry)
1834 GST_DEBUG_OBJECT (src, "RTP port not even");
1836 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
1837 gst_element_set_state (udpsrc0, GST_STATE_NULL);
1838 gst_object_unref (udpsrc0);
1841 GST_DEBUG_OBJECT (src, "retry %d", count);
1846 /* allocate port+1 for RTCP now */
1847 udpsrc1 = gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
1848 if (udpsrc1 == NULL)
1849 goto no_udp_rtcp_protocol;
1852 tmp_rtcp = tmp_rtp + 1;
1853 if (src->client_port_range.max > 0 && tmp_rtcp > src->client_port_range.max)
1856 g_object_set (G_OBJECT (udpsrc1), "port", tmp_rtcp, "reuse", FALSE, NULL);
1858 GST_DEBUG_OBJECT (src, "starting RTCP on port %d", tmp_rtcp);
1859 ret = gst_element_set_state (udpsrc1, GST_STATE_PAUSED);
1860 /* tmp_rtcp port is busy already : retry to make rtp/rtcp pair */
1861 if (ret == GST_STATE_CHANGE_FAILURE) {
1862 GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTCP port %d", tmp_rtcp);
1864 if (++count > src->retry)
1867 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
1868 gst_element_set_state (udpsrc0, GST_STATE_NULL);
1869 gst_object_unref (udpsrc0);
1872 GST_DEBUG_OBJECT (src, "free RTCP udpsrc");
1873 gst_element_set_state (udpsrc1, GST_STATE_NULL);
1874 gst_object_unref (udpsrc1);
1878 GST_DEBUG_OBJECT (src, "retry %d", count);
1882 /* all fine, do port check */
1883 g_object_get (G_OBJECT (udpsrc0), "port", rtpport, NULL);
1884 g_object_get (G_OBJECT (udpsrc1), "port", rtcpport, NULL);
1886 /* this should not happen... */
1887 if (*rtpport != tmp_rtp || *rtcpport != tmp_rtcp)
1890 /* we keep these elements, we configure all in configure_transport when the
1891 * server told us to really use the UDP ports. */
1892 stream->udpsrc[0] = gst_object_ref_sink (udpsrc0);
1893 stream->udpsrc[1] = gst_object_ref_sink (udpsrc1);
1894 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
1895 gst_element_set_locked_state (stream->udpsrc[1], TRUE);
1897 /* keep track of next available port number when we have a range
1899 if (src->next_port_num != 0)
1900 src->next_port_num = tmp_rtcp + 1;
1907 GST_DEBUG_OBJECT (src, "could not get UDP source");
1912 GST_DEBUG_OBJECT (src, "could not allocate UDP port pair after %d retries",
1916 no_udp_rtcp_protocol:
1918 GST_DEBUG_OBJECT (src, "could not get UDP source for RTCP");
1923 GST_DEBUG_OBJECT (src, "ports don't match rtp: %d<->%d, rtcp: %d<->%d",
1924 tmp_rtp, *rtpport, tmp_rtcp, *rtcpport);
1930 gst_element_set_state (udpsrc0, GST_STATE_NULL);
1931 gst_object_unref (udpsrc0);
1934 gst_element_set_state (udpsrc1, GST_STATE_NULL);
1935 gst_object_unref (udpsrc1);
1942 gst_rtspsrc_set_state (GstRTSPSrc * src, GstState state)
1947 gst_element_set_state (GST_ELEMENT_CAST (src->manager), state);
1949 for (walk = src->streams; walk; walk = g_list_next (walk)) {
1950 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
1953 for (i = 0; i < 2; i++) {
1954 if (stream->udpsrc[i])
1955 gst_element_set_state (stream->udpsrc[i], state);
1961 gst_rtspsrc_flush (GstRTSPSrc * src, gboolean flush, gboolean playing)
1968 event = gst_event_new_flush_start ();
1969 GST_DEBUG_OBJECT (src, "start flush");
1971 state = GST_STATE_PAUSED;
1973 event = gst_event_new_flush_stop (FALSE);
1974 GST_DEBUG_OBJECT (src, "stop flush; playing %d", playing);
1977 state = GST_STATE_PLAYING;
1979 state = GST_STATE_PAUSED;
1981 gst_rtspsrc_push_event (src, event);
1982 gst_rtspsrc_loop_send_cmd (src, cmd, CMD_LOOP);
1983 gst_rtspsrc_set_state (src, state);
1986 static GstRTSPResult
1987 gst_rtspsrc_connection_send (GstRTSPSrc * src, GstRTSPConnection * conn,
1988 GstRTSPMessage * message, GTimeVal * timeout)
1993 ret = gst_rtsp_connection_send (conn, message, timeout);
1995 ret = GST_RTSP_ERROR;
2000 static GstRTSPResult
2001 gst_rtspsrc_connection_receive (GstRTSPSrc * src, GstRTSPConnection * conn,
2002 GstRTSPMessage * message, GTimeVal * timeout)
2007 ret = gst_rtsp_connection_receive (conn, message, timeout);
2009 ret = GST_RTSP_ERROR;
2015 gst_rtspsrc_get_position (GstRTSPSrc * src)
2020 query = gst_query_new_position (GST_FORMAT_TIME);
2021 /* should be known somewhere down the stream (e.g. jitterbuffer) */
2022 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2023 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2027 if (stream->srcpad) {
2028 if (gst_pad_query (stream->srcpad, query)) {
2029 gst_query_parse_position (query, &fmt, &pos);
2030 GST_DEBUG_OBJECT (src, "retaining position %" GST_TIME_FORMAT,
2031 GST_TIME_ARGS (pos));
2032 src->last_pos = pos;
2042 gst_rtspsrc_do_seek (GstRTSPSrc * src, GstSegment * segment)
2044 src->state = GST_RTSP_STATE_SEEKING;
2045 /* PLAY will add the range header now. */
2046 src->need_range = TRUE;
2052 gst_rtspsrc_perform_seek (GstRTSPSrc * src, GstEvent * event)
2057 GstSeekType cur_type = GST_SEEK_TYPE_NONE, stop_type;
2059 gboolean flush, skip;
2062 GstSegment seeksegment = { 0, };
2066 GST_DEBUG_OBJECT (src, "doing seek with event");
2068 gst_event_parse_seek (event, &rate, &format, &flags,
2069 &cur_type, &cur, &stop_type, &stop);
2071 /* no negative rates yet */
2075 /* we need TIME format */
2076 if (format != src->segment.format)
2079 GST_DEBUG_OBJECT (src, "doing seek without event");
2081 cur_type = GST_SEEK_TYPE_SET;
2082 stop_type = GST_SEEK_TYPE_SET;
2085 /* get flush flag */
2086 flush = flags & GST_SEEK_FLAG_FLUSH;
2087 skip = flags & GST_SEEK_FLAG_SKIP;
2089 /* now we need to make sure the streaming thread is stopped. We do this by
2090 * either sending a FLUSH_START event downstream which will cause the
2091 * streaming thread to stop with a WRONG_STATE.
2092 * For a non-flushing seek we simply pause the task, which will happen as soon
2093 * as it completes one iteration (and thus might block when the sink is
2094 * blocking in preroll). */
2096 GST_DEBUG_OBJECT (src, "starting flush");
2097 gst_rtspsrc_flush (src, TRUE, FALSE);
2100 gst_task_pause (src->task);
2104 /* we should now be able to grab the streaming thread because we stopped it
2105 * with the above flush/pause code */
2106 GST_RTSP_STREAM_LOCK (src);
2108 GST_DEBUG_OBJECT (src, "stopped streaming");
2110 /* copy segment, we need this because we still need the old
2111 * segment when we close the current segment. */
2112 memcpy (&seeksegment, &src->segment, sizeof (GstSegment));
2114 /* configure the seek parameters in the seeksegment. We will then have the
2115 * right values in the segment to perform the seek */
2117 GST_DEBUG_OBJECT (src, "configuring seek");
2118 gst_segment_do_seek (&seeksegment, rate, format, flags,
2119 cur_type, cur, stop_type, stop, &update);
2122 /* figure out the last position we need to play. If it's configured (stop !=
2123 * -1), use that, else we play until the total duration of the file */
2124 if ((stop = seeksegment.stop) == -1)
2125 stop = seeksegment.duration;
2127 playing = (src->state == GST_RTSP_STATE_PLAYING);
2129 /* if we were playing, pause first */
2131 /* obtain current position in case seek fails */
2132 gst_rtspsrc_get_position (src);
2133 gst_rtspsrc_pause (src, FALSE);
2137 gst_rtspsrc_do_seek (src, &seeksegment);
2139 /* and continue playing */
2141 gst_rtspsrc_play (src, &seeksegment, FALSE);
2143 /* prepare for streaming again */
2145 /* if we started flush, we stop now */
2146 GST_DEBUG_OBJECT (src, "stopping flush");
2147 gst_rtspsrc_flush (src, FALSE, playing);
2150 /* now we did the seek and can activate the new segment values */
2151 memcpy (&src->segment, &seeksegment, sizeof (GstSegment));
2153 /* if we're doing a segment seek, post a SEGMENT_START message */
2154 if (src->segment.flags & GST_SEEK_FLAG_SEGMENT) {
2155 gst_element_post_message (GST_ELEMENT_CAST (src),
2156 gst_message_new_segment_start (GST_OBJECT_CAST (src),
2157 src->segment.format, src->segment.position));
2160 /* now create the newsegment */
2161 GST_DEBUG_OBJECT (src, "Creating newsegment from %" G_GINT64_FORMAT
2162 " to %" G_GINT64_FORMAT, src->segment.position, stop);
2165 GST_DEBUG_OBJECT (src, "mark DISCONT, we did a seek to another position");
2166 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2167 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2168 stream->discont = TRUE;
2171 GST_RTSP_STREAM_UNLOCK (src);
2178 GST_DEBUG_OBJECT (src, "negative playback rates are not supported yet.");
2183 GST_DEBUG_OBJECT (src, "unsupported format given, seek aborted.");
2189 gst_rtspsrc_handle_src_event (GstPad * pad, GstObject * parent,
2193 gboolean res = TRUE;
2196 src = GST_RTSPSRC_CAST (parent);
2198 GST_DEBUG_OBJECT (src, "pad %s:%s received event %s",
2199 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
2201 switch (GST_EVENT_TYPE (event)) {
2202 case GST_EVENT_SEEK:
2203 res = gst_rtspsrc_perform_seek (src, event);
2207 case GST_EVENT_NAVIGATION:
2208 case GST_EVENT_LATENCY:
2216 if ((target = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (pad)))) {
2217 res = gst_pad_send_event (target, event);
2218 gst_object_unref (target);
2220 gst_event_unref (event);
2223 gst_event_unref (event);
2229 /* this is the final event function we receive on the internal source pad when
2230 * we deal with TCP connections */
2232 gst_rtspsrc_handle_internal_src_event (GstPad * pad, GstObject * parent,
2237 GST_DEBUG_OBJECT (pad, "received event %s", GST_EVENT_TYPE_NAME (event));
2239 switch (GST_EVENT_TYPE (event)) {
2240 case GST_EVENT_SEEK:
2242 case GST_EVENT_NAVIGATION:
2243 case GST_EVENT_LATENCY:
2245 gst_event_unref (event);
2252 /* this is the final query function we receive on the internal source pad when
2253 * we deal with TCP connections */
2255 gst_rtspsrc_handle_internal_src_query (GstPad * pad, GstObject * parent,
2259 gboolean res = TRUE;
2261 src = GST_RTSPSRC_CAST (gst_pad_get_element_private (pad));
2263 GST_DEBUG_OBJECT (src, "pad %s:%s received query %s",
2264 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
2266 switch (GST_QUERY_TYPE (query)) {
2267 case GST_QUERY_POSITION:
2272 case GST_QUERY_DURATION:
2276 gst_query_parse_duration (query, &format, NULL);
2279 case GST_FORMAT_TIME:
2280 gst_query_set_duration (query, format, src->segment.duration);
2288 case GST_QUERY_LATENCY:
2290 /* we are live with a min latency of 0 and unlimited max latency, this
2291 * result will be updated by the session manager if there is any. */
2292 gst_query_set_latency (query, TRUE, 0, -1);
2302 /* this query is executed on the ghost source pad exposed on rtspsrc. */
2304 gst_rtspsrc_handle_src_query (GstPad * pad, GstObject * parent,
2308 gboolean res = FALSE;
2310 src = GST_RTSPSRC_CAST (parent);
2312 GST_DEBUG_OBJECT (src, "pad %s:%s received query %s",
2313 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
2315 switch (GST_QUERY_TYPE (query)) {
2316 case GST_QUERY_DURATION:
2320 gst_query_parse_duration (query, &format, NULL);
2323 case GST_FORMAT_TIME:
2324 gst_query_set_duration (query, format, src->segment.duration);
2332 case GST_QUERY_SEEKING:
2336 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
2337 if (format == GST_FORMAT_TIME) {
2339 src->cur_protocols != GST_RTSP_LOWER_TRANS_UDP_MCAST;
2341 /* seeking without duration is unlikely */
2342 seekable = seekable && src->seekable && src->segment.duration &&
2343 GST_CLOCK_TIME_IS_VALID (src->segment.duration);
2345 /* FIXME ?? should we have 0 and segment.duration here; see demuxers */
2346 gst_query_set_seeking (query, GST_FORMAT_TIME, seekable,
2347 src->segment.start, src->segment.stop);
2356 uri = gst_rtspsrc_uri_get_uri (GST_URI_HANDLER (src));
2358 gst_query_set_uri (query, uri);
2366 GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (pad));
2368 /* forward the query to the proxy target pad */
2370 res = gst_pad_query (target, query);
2371 gst_object_unref (target);
2380 /* callback for RTCP messages to be sent to the server when operating in TCP
2382 static GstFlowReturn
2383 gst_rtspsrc_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
2386 GstRTSPStream *stream;
2387 GstFlowReturn res = GST_FLOW_OK;
2392 GstRTSPMessage message = { 0 };
2393 GstRTSPConnection *conn;
2395 stream = (GstRTSPStream *) gst_pad_get_element_private (pad);
2396 src = stream->parent;
2398 gst_buffer_map (buffer, &map, GST_MAP_READ);
2402 gst_rtsp_message_init_data (&message, stream->channel[1]);
2404 /* lend the body data to the message */
2405 gst_rtsp_message_take_body (&message, data, size);
2407 if (stream->conninfo.connection)
2408 conn = stream->conninfo.connection;
2410 conn = src->conninfo.connection;
2412 GST_DEBUG_OBJECT (src, "sending %u bytes RTCP", size);
2413 ret = gst_rtspsrc_connection_send (src, conn, &message, NULL);
2414 GST_DEBUG_OBJECT (src, "sent RTCP, %d", ret);
2416 /* and steal it away again because we will free it when unreffing the
2418 gst_rtsp_message_steal_body (&message, &data, &size);
2419 gst_rtsp_message_unset (&message);
2421 gst_buffer_unmap (buffer, &map);
2422 gst_buffer_unref (buffer);
2427 static GstPadProbeReturn
2428 pad_blocked (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
2430 GstRTSPSrc *src = user_data;
2432 GST_DEBUG_OBJECT (src, "pad %s:%s blocked, activating streams",
2433 GST_DEBUG_PAD_NAME (pad));
2435 /* activate the streams */
2436 GST_OBJECT_LOCK (src);
2437 if (!src->need_activate)
2440 src->need_activate = FALSE;
2441 GST_OBJECT_UNLOCK (src);
2443 gst_rtspsrc_activate_streams (src);
2445 return GST_PAD_PROBE_OK;
2449 GST_OBJECT_UNLOCK (src);
2450 return GST_PAD_PROBE_OK;
2454 /* this callback is called when the session manager generated a new src pad with
2455 * payloaded RTP packets. We simply ghost the pad here. */
2457 new_manager_pad (GstElement * manager, GstPad * pad, GstRTSPSrc * src)
2460 GstPadTemplate *template;
2463 GstRTSPStream *stream;
2466 GST_DEBUG_OBJECT (src, "got new manager pad %" GST_PTR_FORMAT, pad);
2468 GST_RTSP_STATE_LOCK (src);
2470 name = gst_object_get_name (GST_OBJECT_CAST (pad));
2471 if (sscanf (name, "recv_rtp_src_%u_%u_%u", &id, &ssrc, &pt) != 3)
2472 goto unknown_stream;
2474 GST_DEBUG_OBJECT (src, "stream: %u, SSRC %08x, PT %d", id, ssrc, pt);
2476 stream = find_stream (src, &id, (gpointer) find_stream_by_id);
2478 goto unknown_stream;
2481 stream->ssrc = ssrc;
2483 /* we'll add it later see below */
2484 stream->added = TRUE;
2486 /* check if we added all streams */
2488 for (ostreams = src->streams; ostreams; ostreams = g_list_next (ostreams)) {
2489 GstRTSPStream *ostream = (GstRTSPStream *) ostreams->data;
2491 GST_DEBUG_OBJECT (src, "stream %p, container %d, disabled %d, added %d",
2492 ostream, ostream->container, ostream->disabled, ostream->added);
2494 /* a container stream only needs one pad added. Also disabled streams don't
2496 if (!ostream->container && !ostream->disabled && !ostream->added) {
2501 GST_RTSP_STATE_UNLOCK (src);
2503 /* create a new pad we will use to stream to */
2504 template = gst_static_pad_template_get (&rtptemplate);
2505 stream->srcpad = gst_ghost_pad_new_from_template (name, pad, template);
2506 gst_object_unref (template);
2509 gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
2510 gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
2511 gst_pad_set_active (stream->srcpad, TRUE);
2512 gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
2515 GST_DEBUG_OBJECT (src, "We added all streams");
2516 /* when we get here, all stream are added and we can fire the no-more-pads
2518 gst_element_no_more_pads (GST_ELEMENT_CAST (src));
2526 GST_DEBUG_OBJECT (src, "ignoring unknown stream");
2527 GST_RTSP_STATE_UNLOCK (src);
2534 request_pt_map (GstElement * manager, guint session, guint pt, GstRTSPSrc * src)
2536 GstRTSPStream *stream;
2539 GST_DEBUG_OBJECT (src, "getting pt map for pt %d in session %d", pt, session);
2541 GST_RTSP_STATE_LOCK (src);
2542 stream = find_stream (src, &session, (gpointer) find_stream_by_id);
2544 goto unknown_stream;
2546 caps = stream->caps;
2548 gst_caps_ref (caps);
2549 GST_RTSP_STATE_UNLOCK (src);
2555 GST_DEBUG_OBJECT (src, "unknown stream %d", session);
2556 GST_RTSP_STATE_UNLOCK (src);
2562 gst_rtspsrc_do_stream_eos (GstRTSPSrc * src, GstRTSPStream * stream)
2564 GST_DEBUG_OBJECT (src, "setting stream for session %u to EOS", stream->id);
2570 gst_rtspsrc_stream_push_event (src, stream, gst_event_new_eos ());
2576 GST_DEBUG_OBJECT (src, "stream for session %u was already EOS", stream->id);
2582 on_bye_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
2584 GstRTSPSrc *src = stream->parent;
2587 g_object_get (source, "ssrc", &ssrc, NULL);
2589 GST_DEBUG_OBJECT (src, "source %08x, stream %08x, session %u received BYE",
2590 ssrc, stream->ssrc, stream->id);
2592 if (ssrc == stream->ssrc)
2593 gst_rtspsrc_do_stream_eos (src, stream);
2597 on_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
2599 GstRTSPSrc *src = stream->parent;
2602 g_object_get (source, "ssrc", &ssrc, NULL);
2604 GST_WARNING_OBJECT (src, "source %08x, stream %08x in session %u timed out",
2605 ssrc, stream->ssrc, stream->id);
2607 if (ssrc == stream->ssrc)
2608 gst_rtspsrc_do_stream_eos (src, stream);
2612 on_npt_stop (GstElement * rtpbin, guint session, guint ssrc, GstRTSPSrc * src)
2614 GstRTSPStream *stream;
2616 GST_DEBUG_OBJECT (src, "source in session %u reached NPT stop", session);
2618 /* get stream for session */
2619 stream = find_stream (src, &session, (gpointer) find_stream_by_id);
2621 gst_rtspsrc_do_stream_eos (src, stream);
2626 on_ssrc_active (GObject * session, GObject * source, GstRTSPStream * stream)
2628 GST_DEBUG_OBJECT (stream->parent, "source in session %u is active",
2632 /* try to get and configure a manager */
2634 gst_rtspsrc_stream_configure_manager (GstRTSPSrc * src, GstRTSPStream * stream,
2635 GstRTSPTransport * transport)
2637 const gchar *manager;
2639 GstStateChangeReturn ret;
2641 /* find a manager */
2642 if (gst_rtsp_transport_get_manager (transport->trans, &manager, 0) < 0)
2646 GST_DEBUG_OBJECT (src, "using manager %s", manager);
2648 /* configure the manager */
2649 if (src->manager == NULL) {
2650 GObjectClass *klass;
2652 if (!(src->manager = gst_element_factory_make (manager, "manager"))) {
2654 if (gst_rtsp_transport_get_manager (transport->trans, &manager, 1) < 0)
2658 goto use_no_manager;
2660 if (!(src->manager = gst_element_factory_make (manager, "manager")))
2661 goto manager_failed;
2664 /* we manage this element */
2665 gst_element_set_locked_state (src->manager, TRUE);
2666 gst_bin_add (GST_BIN_CAST (src), src->manager);
2668 ret = gst_element_set_state (src->manager, GST_STATE_PAUSED);
2669 if (ret == GST_STATE_CHANGE_FAILURE)
2670 goto start_manager_failure;
2672 g_object_set (src->manager, "latency", src->latency, NULL);
2674 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
2676 if (g_object_class_find_property (klass, "ntp-sync")) {
2677 g_object_set (src->manager, "ntp-sync", src->ntp_sync, NULL);
2680 if (g_object_class_find_property (klass, "use-pipeline-clock")) {
2681 g_object_set (src->manager, "use-pipeline-clock",
2682 src->use_pipeline_clock, NULL);
2685 if (src->sdes && g_object_class_find_property (klass, "sdes")) {
2686 g_object_set (src->manager, "sdes", src->sdes, NULL);
2689 if (g_object_class_find_property (klass, "drop-on-latency")) {
2690 g_object_set (src->manager, "drop-on-latency", src->drop_on_latency,
2694 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);
2698 gboolean need_slave;
2700 const gchar *encoding;
2702 /* buffer mode pauses are handled by adding offsets to buffer times,
2703 * but some depayloaders may have a hard time syncing output times
2704 * with such input times, e.g. container ones, most notably ASF */
2705 /* TODO alternatives are having an event that indicates these shifts,
2706 * or having rtsp extensions provide suggestion on buffer mode */
2707 need_slave = stream->container;
2708 if (stream->caps && (s = gst_caps_get_structure (stream->caps, 0)) &&
2709 (encoding = gst_structure_get_string (s, "encoding-name")))
2710 need_slave = need_slave || (strcmp (encoding, "X-ASF-PF") == 0);
2711 GST_DEBUG_OBJECT (src, "auto buffering mode, need_slave %d",
2713 /* valid duration implies not likely live pipeline,
2714 * so slaving in jitterbuffer does not make much sense
2715 * (and might mess things up due to bursts) */
2716 if (GST_CLOCK_TIME_IS_VALID (src->segment.duration) &&
2717 src->segment.duration && !need_slave) {
2718 GST_DEBUG_OBJECT (src, "selected buffer");
2719 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_BUFFER,
2722 GST_DEBUG_OBJECT (src, "selected slave");
2723 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_SLAVE, NULL);
2728 /* connect to signals if we did not already do so */
2729 GST_DEBUG_OBJECT (src, "connect to signals on session manager, stream %p",
2731 src->manager_sig_id =
2732 g_signal_connect (src->manager, "pad-added",
2733 (GCallback) new_manager_pad, src);
2734 src->manager_ptmap_id =
2735 g_signal_connect (src->manager, "request-pt-map",
2736 (GCallback) request_pt_map, src);
2738 g_signal_connect (src->manager, "on-npt-stop", (GCallback) on_npt_stop,
2742 /* we stream directly to the manager, get some pads. Each RTSP stream goes
2743 * into a separate RTP session. */
2744 name = g_strdup_printf ("recv_rtp_sink_%u", stream->id);
2745 stream->channelpad[0] = gst_element_get_request_pad (src->manager, name);
2747 name = g_strdup_printf ("recv_rtcp_sink_%u", stream->id);
2748 stream->channelpad[1] = gst_element_get_request_pad (src->manager, name);
2751 /* now configure the bandwidth in the manager */
2752 if (g_signal_lookup ("get-internal-session",
2753 G_OBJECT_TYPE (src->manager)) != 0) {
2754 GObject *rtpsession;
2756 g_signal_emit_by_name (src->manager, "get-internal-session", stream->id,
2759 GST_INFO_OBJECT (src, "configure bandwidth in session %p", rtpsession);
2761 stream->session = rtpsession;
2763 if (stream->as_bandwidth != -1) {
2764 GST_INFO_OBJECT (src, "setting AS: %f",
2765 (gdouble) (stream->as_bandwidth * 1000));
2766 g_object_set (rtpsession, "bandwidth",
2767 (gdouble) (stream->as_bandwidth * 1000), NULL);
2769 if (stream->rr_bandwidth != -1) {
2770 GST_INFO_OBJECT (src, "setting RR: %u", stream->rr_bandwidth);
2771 g_object_set (rtpsession, "rtcp-rr-bandwidth", stream->rr_bandwidth,
2774 if (stream->rs_bandwidth != -1) {
2775 GST_INFO_OBJECT (src, "setting RS: %u", stream->rs_bandwidth);
2776 g_object_set (rtpsession, "rtcp-rs-bandwidth", stream->rs_bandwidth,
2780 g_object_set (rtpsession, "probation", src->probation, NULL);
2782 g_signal_connect (rtpsession, "on-bye-ssrc", (GCallback) on_bye_ssrc,
2784 g_signal_connect (rtpsession, "on-bye-timeout", (GCallback) on_timeout,
2786 g_signal_connect (rtpsession, "on-timeout", (GCallback) on_timeout,
2788 g_signal_connect (rtpsession, "on-ssrc-active",
2789 (GCallback) on_ssrc_active, stream);
2800 GST_DEBUG_OBJECT (src, "cannot get a session manager");
2805 GST_DEBUG_OBJECT (src, "no session manager element %s found", manager);
2808 start_manager_failure:
2810 GST_DEBUG_OBJECT (src, "could not start session manager");
2815 /* free the UDP sources allocated when negotiating a transport.
2816 * This function is called when the server negotiated to a transport where the
2817 * UDP sources are not needed anymore, such as TCP or multicast. */
2819 gst_rtspsrc_stream_free_udp (GstRTSPStream * stream)
2823 for (i = 0; i < 2; i++) {
2824 if (stream->udpsrc[i]) {
2825 GST_DEBUG ("free UDP source %d for stream %p", i, stream);
2826 gst_element_set_state (stream->udpsrc[i], GST_STATE_NULL);
2827 gst_object_unref (stream->udpsrc[i]);
2828 stream->udpsrc[i] = NULL;
2833 /* for TCP, create pads to send and receive data to and from the manager and to
2834 * intercept various events and queries
2837 gst_rtspsrc_stream_configure_tcp (GstRTSPSrc * src, GstRTSPStream * stream,
2838 GstRTSPTransport * transport, GstPad ** outpad)
2841 GstPadTemplate *template;
2842 GstPad *pad0, *pad1;
2844 /* configure for interleaved delivery, nothing needs to be done
2845 * here, the loop function will call the chain functions of the
2846 * session manager. */
2847 stream->channel[0] = transport->interleaved.min;
2848 stream->channel[1] = transport->interleaved.max;
2849 GST_DEBUG_OBJECT (src, "stream %p on channels %d-%d", stream,
2850 stream->channel[0], stream->channel[1]);
2852 /* we can remove the allocated UDP ports now */
2853 gst_rtspsrc_stream_free_udp (stream);
2855 /* no session manager, send data to srcpad directly */
2856 if (!stream->channelpad[0]) {
2857 GST_DEBUG_OBJECT (src, "no manager, creating pad");
2859 /* create a new pad we will use to stream to */
2860 name = g_strdup_printf ("stream_%u", stream->id);
2861 template = gst_static_pad_template_get (&rtptemplate);
2862 stream->channelpad[0] = gst_pad_new_from_template (template, name);
2863 gst_object_unref (template);
2866 /* set caps and activate */
2867 gst_pad_use_fixed_caps (stream->channelpad[0]);
2868 gst_pad_set_active (stream->channelpad[0], TRUE);
2870 *outpad = gst_object_ref (stream->channelpad[0]);
2872 GST_DEBUG_OBJECT (src, "using manager source pad");
2874 template = gst_static_pad_template_get (&anysrctemplate);
2876 /* allocate pads for sending the channel data into the manager */
2877 pad0 = gst_pad_new_from_template (template, "internalsrc_0");
2878 gst_pad_link (pad0, stream->channelpad[0]);
2879 gst_object_unref (stream->channelpad[0]);
2880 stream->channelpad[0] = pad0;
2881 gst_pad_set_event_function (pad0, gst_rtspsrc_handle_internal_src_event);
2882 gst_pad_set_query_function (pad0, gst_rtspsrc_handle_internal_src_query);
2883 gst_pad_set_element_private (pad0, src);
2884 gst_pad_set_active (pad0, TRUE);
2886 if (stream->channelpad[1]) {
2887 /* if we have a sinkpad for the other channel, create a pad and link to the
2889 pad1 = gst_pad_new_from_template (template, "internalsrc_1");
2890 gst_pad_set_event_function (pad1, gst_rtspsrc_handle_internal_src_event);
2891 gst_pad_link (pad1, stream->channelpad[1]);
2892 gst_object_unref (stream->channelpad[1]);
2893 stream->channelpad[1] = pad1;
2894 gst_pad_set_active (pad1, TRUE);
2896 gst_object_unref (template);
2898 /* setup RTCP transport back to the server if we have to. */
2899 if (src->manager && src->do_rtcp) {
2902 template = gst_static_pad_template_get (&anysinktemplate);
2904 stream->rtcppad = gst_pad_new_from_template (template, "internalsink_0");
2905 gst_pad_set_chain_function (stream->rtcppad, gst_rtspsrc_sink_chain);
2906 gst_pad_set_element_private (stream->rtcppad, stream);
2907 gst_pad_set_active (stream->rtcppad, TRUE);
2909 /* get session RTCP pad */
2910 name = g_strdup_printf ("send_rtcp_src_%u", stream->id);
2911 pad = gst_element_get_request_pad (src->manager, name);
2916 gst_pad_link (pad, stream->rtcppad);
2917 gst_object_unref (pad);
2920 gst_object_unref (template);
2926 gst_rtspsrc_get_transport_info (GstRTSPSrc * src, GstRTSPStream * stream,
2927 GstRTSPTransport * transport, const gchar ** destination, gint * min,
2928 gint * max, guint * ttl)
2930 if (transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
2932 if (!(*destination = transport->destination))
2933 *destination = stream->destination;
2936 /* transport first */
2937 *min = transport->port.min;
2938 *max = transport->port.max;
2939 if (*min == -1 && *max == -1) {
2940 /* then try from SDP */
2941 if (stream->port != 0) {
2942 *min = stream->port;
2943 *max = stream->port + 1;
2949 if (!(*ttl = transport->ttl))
2954 /* first take the source, then the endpoint to figure out where to send
2956 if (!(*destination = transport->source)) {
2957 if (src->conninfo.connection)
2958 *destination = gst_rtsp_connection_get_ip (src->conninfo.connection);
2959 else if (stream->conninfo.connection)
2961 gst_rtsp_connection_get_ip (stream->conninfo.connection);
2965 /* for unicast we only expect the ports here */
2966 *min = transport->server_port.min;
2967 *max = transport->server_port.max;
2972 /* For multicast create UDP sources and join the multicast group. */
2974 gst_rtspsrc_stream_configure_mcast (GstRTSPSrc * src, GstRTSPStream * stream,
2975 GstRTSPTransport * transport, GstPad ** outpad)
2978 const gchar *destination;
2981 GST_DEBUG_OBJECT (src, "creating UDP sources for multicast");
2983 /* we can remove the allocated UDP ports now */
2984 gst_rtspsrc_stream_free_udp (stream);
2986 gst_rtspsrc_get_transport_info (src, stream, transport, &destination, &min,
2989 /* we need a destination now */
2990 if (destination == NULL)
2991 goto no_destination;
2993 /* we really need ports now or we won't be able to receive anything at all */
2994 if (min == -1 && max == -1)
2997 GST_DEBUG_OBJECT (src, "have destination '%s' and ports (%d)-(%d)",
2998 destination, min, max);
3000 /* creating UDP source for RTP */
3002 uri = g_strdup_printf ("udp://%s:%d", destination, min);
3004 gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
3006 if (stream->udpsrc[0] == NULL)
3009 /* take ownership */
3010 gst_object_ref_sink (stream->udpsrc[0]);
3012 if (src->udp_buffer_size != 0)
3013 g_object_set (G_OBJECT (stream->udpsrc[0]), "buffer-size",
3014 src->udp_buffer_size, NULL);
3016 if (src->multi_iface != NULL)
3017 g_object_set (G_OBJECT (stream->udpsrc[0]), "multicast-iface",
3018 src->multi_iface, NULL);
3021 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
3022 gst_element_set_state (stream->udpsrc[0], GST_STATE_PAUSED);
3025 /* creating another UDP source for RTCP */
3029 uri = g_strdup_printf ("udp://%s:%d", destination, max);
3031 gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
3033 if (stream->udpsrc[1] == NULL)
3036 caps = gst_caps_new_empty_simple ("application/x-rtcp");
3037 g_object_set (stream->udpsrc[1], "caps", caps, NULL);
3038 gst_caps_unref (caps);
3040 /* take ownership */
3041 gst_object_ref_sink (stream->udpsrc[1]);
3043 if (src->multi_iface != NULL)
3044 g_object_set (G_OBJECT (stream->udpsrc[0]), "multicast-iface",
3045 src->multi_iface, NULL);
3047 gst_element_set_state (stream->udpsrc[1], GST_STATE_PAUSED);
3054 GST_DEBUG_OBJECT (src, "no UDP source element found");
3059 GST_DEBUG_OBJECT (src, "no destination found");
3064 GST_DEBUG_OBJECT (src, "no ports found");
3069 /* configure the remainder of the UDP ports */
3071 gst_rtspsrc_stream_configure_udp (GstRTSPSrc * src, GstRTSPStream * stream,
3072 GstRTSPTransport * transport, GstPad ** outpad)
3074 /* we manage the UDP elements now. For unicast, the UDP sources where
3075 * allocated in the stream when we suggested a transport. */
3076 if (stream->udpsrc[0]) {
3077 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
3078 gst_bin_add (GST_BIN_CAST (src), stream->udpsrc[0]);
3080 GST_DEBUG_OBJECT (src, "setting up UDP source");
3082 /* configure a timeout on the UDP port. When the timeout message is
3083 * posted, we assume UDP transport is not possible. We reconnect using TCP
3085 g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout",
3086 src->udp_timeout * 1000, NULL);
3088 /* get output pad of the UDP source. */
3089 *outpad = gst_element_get_static_pad (stream->udpsrc[0], "src");
3091 /* save it so we can unblock */
3092 stream->blockedpad = *outpad;
3094 /* configure pad block on the pad. As soon as there is dataflow on the
3095 * UDP source, we know that UDP is not blocked by a firewall and we can
3096 * configure all the streams to let the application autoplug decoders. */
3098 gst_pad_add_probe (stream->blockedpad,
3099 GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, pad_blocked, src, NULL);
3101 if (stream->channelpad[0]) {
3102 GST_DEBUG_OBJECT (src, "connecting UDP source 0 to manager");
3103 /* configure for UDP delivery, we need to connect the UDP pads to
3104 * the session plugin. */
3105 gst_pad_link (*outpad, stream->channelpad[0]);
3106 gst_object_unref (*outpad);
3108 /* we connected to pad-added signal to get pads from the manager */
3110 GST_DEBUG_OBJECT (src, "using UDP src pad as output");
3115 if (stream->udpsrc[1]) {
3118 gst_element_set_locked_state (stream->udpsrc[1], TRUE);
3119 gst_bin_add (GST_BIN_CAST (src), stream->udpsrc[1]);
3121 caps = gst_caps_new_empty_simple ("application/x-rtcp");
3122 g_object_set (stream->udpsrc[1], "caps", caps, NULL);
3123 gst_caps_unref (caps);
3125 if (stream->channelpad[1]) {
3128 GST_DEBUG_OBJECT (src, "connecting UDP source 1 to manager");
3130 pad = gst_element_get_static_pad (stream->udpsrc[1], "src");
3131 gst_pad_link (pad, stream->channelpad[1]);
3132 gst_object_unref (pad);
3134 /* leave unlinked */
3140 /* configure the UDP sink back to the server for status reports */
3142 gst_rtspsrc_stream_configure_udp_sinks (GstRTSPSrc * src,
3143 GstRTSPStream * stream, GstRTSPTransport * transport)
3146 gint rtp_port, rtcp_port;
3147 gboolean do_rtp, do_rtcp;
3148 const gchar *destination;
3153 /* get transport info */
3154 gst_rtspsrc_get_transport_info (src, stream, transport, &destination,
3155 &rtp_port, &rtcp_port, &ttl);
3157 /* see what we need to do */
3158 do_rtp = (rtp_port != -1);
3159 /* it's possible that the server does not want us to send RTCP in which case
3161 do_rtcp = (rtcp_port != -1 && src->manager != NULL && src->do_rtcp);
3163 /* we need a destination when we have RTP or RTCP ports */
3164 if (destination == NULL && (do_rtp || do_rtcp))
3165 goto no_destination;
3167 /* try to construct the fakesrc to the RTP port of the server to open up any
3170 GST_DEBUG_OBJECT (src, "configure RTP UDP sink for %s:%d", destination,
3173 uri = g_strdup_printf ("udp://%s:%d", destination, rtp_port);
3174 stream->udpsink[0] =
3175 gst_element_make_from_uri (GST_URI_SINK, uri, NULL, NULL);
3177 if (stream->udpsink[0] == NULL)
3178 goto no_sink_element;
3180 /* don't join multicast group, we will have the source socket do that */
3181 /* no sync or async state changes needed */
3182 g_object_set (G_OBJECT (stream->udpsink[0]), "auto-multicast", FALSE,
3183 "loop", FALSE, "sync", FALSE, "async", FALSE, NULL);
3185 g_object_set (G_OBJECT (stream->udpsink[0]), "ttl", ttl, NULL);
3187 if (stream->udpsrc[0]) {
3188 /* configure socket, we give it the same UDP socket as the udpsrc for RTP
3189 * so that NAT firewalls will open a hole for us */
3190 g_object_get (G_OBJECT (stream->udpsrc[0]), "used-socket", &socket, NULL);
3191 GST_DEBUG_OBJECT (src, "RTP UDP src has sock %p", socket);
3192 /* configure socket and make sure udpsink does not close it when shutting
3193 * down, it belongs to udpsrc after all. */
3194 g_object_set (G_OBJECT (stream->udpsink[0]), "socket", socket,
3195 "close-socket", FALSE, NULL);
3196 g_object_unref (socket);
3199 /* the source for the dummy packets to open up NAT */
3200 stream->fakesrc = gst_element_factory_make ("fakesrc", NULL);
3201 if (stream->fakesrc == NULL)
3202 goto no_fakesrc_element;
3204 /* random data in 5 buffers, a size of 200 bytes should be fine */
3205 g_object_set (G_OBJECT (stream->fakesrc), "filltype", 3, "num-buffers", 5,
3206 "sizetype", 2, "sizemax", 200, "silent", TRUE, NULL);
3208 /* we don't want to consider this a sink */
3209 GST_OBJECT_FLAG_UNSET (stream->udpsink[0], GST_ELEMENT_FLAG_SINK);
3211 /* keep everything locked */
3212 gst_element_set_locked_state (stream->udpsink[0], TRUE);
3213 gst_element_set_locked_state (stream->fakesrc, TRUE);
3215 gst_object_ref (stream->udpsink[0]);
3216 gst_bin_add (GST_BIN_CAST (src), stream->udpsink[0]);
3217 gst_object_ref (stream->fakesrc);
3218 gst_bin_add (GST_BIN_CAST (src), stream->fakesrc);
3220 gst_element_link (stream->fakesrc, stream->udpsink[0]);
3223 GST_DEBUG_OBJECT (src, "configure RTCP UDP sink for %s:%d", destination,
3226 uri = g_strdup_printf ("udp://%s:%d", destination, rtcp_port);
3227 stream->udpsink[1] =
3228 gst_element_make_from_uri (GST_URI_SINK, uri, NULL, NULL);
3230 if (stream->udpsink[1] == NULL)
3231 goto no_sink_element;
3233 /* don't join multicast group, we will have the source socket do that */
3234 /* no sync or async state changes needed */
3235 g_object_set (G_OBJECT (stream->udpsink[1]), "auto-multicast", FALSE,
3236 "loop", FALSE, "sync", FALSE, "async", FALSE, NULL);
3238 g_object_set (G_OBJECT (stream->udpsink[0]), "ttl", ttl, NULL);
3240 if (stream->udpsrc[1]) {
3241 /* configure socket, we give it the same UDP socket as the udpsrc for RTCP
3242 * because some servers check the port number of where it sends RTCP to identify
3243 * the RTCP packets it receives */
3244 g_object_get (G_OBJECT (stream->udpsrc[1]), "used-socket", &socket, NULL);
3245 GST_DEBUG_OBJECT (src, "RTCP UDP src has sock %p", socket);
3246 /* configure socket and make sure udpsink does not close it when shutting
3247 * down, it belongs to udpsrc after all. */
3248 g_object_set (G_OBJECT (stream->udpsink[1]), "socket", socket,
3249 "close-socket", FALSE, NULL);
3250 g_object_unref (socket);
3253 /* we don't want to consider this a sink */
3254 GST_OBJECT_FLAG_UNSET (stream->udpsink[1], GST_ELEMENT_FLAG_SINK);
3256 /* we keep this playing always */
3257 gst_element_set_locked_state (stream->udpsink[1], TRUE);
3258 gst_element_set_state (stream->udpsink[1], GST_STATE_PLAYING);
3260 gst_object_ref (stream->udpsink[1]);
3261 gst_bin_add (GST_BIN_CAST (src), stream->udpsink[1]);
3263 stream->rtcppad = gst_element_get_static_pad (stream->udpsink[1], "sink");
3265 /* get session RTCP pad */
3266 name = g_strdup_printf ("send_rtcp_src_%u", stream->id);
3267 pad = gst_element_get_request_pad (src->manager, name);
3272 gst_pad_link (pad, stream->rtcppad);
3273 gst_object_unref (pad);
3282 GST_DEBUG_OBJECT (src, "no destination address specified");
3287 GST_DEBUG_OBJECT (src, "no UDP sink element found");
3292 GST_DEBUG_OBJECT (src, "no fakesrc element found");
3297 /* sets up all elements needed for streaming over the specified transport.
3298 * Does not yet expose the element pads, this will be done when there is actuall
3299 * dataflow detected, which might never happen when UDP is blocked in a
3300 * firewall, for example.
3303 gst_rtspsrc_stream_configure_transport (GstRTSPStream * stream,
3304 GstRTSPTransport * transport)
3307 GstPad *outpad = NULL;
3308 GstPadTemplate *template;
3313 src = stream->parent;
3315 GST_DEBUG_OBJECT (src, "configuring transport for stream %p", stream);
3317 s = gst_caps_get_structure (stream->caps, 0);
3319 /* get the proper mime type for this stream now */
3320 if (gst_rtsp_transport_get_mime (transport->trans, &mime) < 0)
3321 goto unknown_transport;
3323 goto unknown_transport;
3325 /* configure the final mime type */
3326 GST_DEBUG_OBJECT (src, "setting mime to %s", mime);
3327 gst_structure_set_name (s, mime);
3329 /* try to get and configure a manager, channelpad[0-1] will be configured with
3330 * the pads for the manager, or NULL when no manager is needed. */
3331 if (!gst_rtspsrc_stream_configure_manager (src, stream, transport))
3334 switch (transport->lower_transport) {
3335 case GST_RTSP_LOWER_TRANS_TCP:
3336 if (!gst_rtspsrc_stream_configure_tcp (src, stream, transport, &outpad))
3337 goto transport_failed;
3339 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
3340 if (!gst_rtspsrc_stream_configure_mcast (src, stream, transport, &outpad))
3341 goto transport_failed;
3342 /* fallthrough, the rest is the same for UDP and MCAST */
3343 case GST_RTSP_LOWER_TRANS_UDP:
3344 if (!gst_rtspsrc_stream_configure_udp (src, stream, transport, &outpad))
3345 goto transport_failed;
3346 /* configure udpsinks back to the server for RTCP messages and for the
3347 * dummy RTP messages to open NAT. */
3348 if (!gst_rtspsrc_stream_configure_udp_sinks (src, stream, transport))
3349 goto transport_failed;
3352 goto unknown_transport;
3356 GST_DEBUG_OBJECT (src, "creating ghostpad");
3358 gst_pad_use_fixed_caps (outpad);
3360 /* create ghostpad, don't add just yet, this will be done when we activate
3362 name = g_strdup_printf ("stream_%u", stream->id);
3363 template = gst_static_pad_template_get (&rtptemplate);
3364 stream->srcpad = gst_ghost_pad_new_from_template (name, outpad, template);
3365 gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
3366 gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
3367 gst_object_unref (template);
3370 gst_object_unref (outpad);
3372 /* mark pad as ok */
3373 stream->last_ret = GST_FLOW_OK;
3380 GST_DEBUG_OBJECT (src, "failed to configure transport");
3385 GST_DEBUG_OBJECT (src, "unknown transport");
3390 GST_DEBUG_OBJECT (src, "cannot get a session manager");
3395 /* send a couple of dummy random packets on the receiver RTP port to the server,
3396 * this should make a firewall think we initiated the data transfer and
3397 * hopefully allow packets to go from the sender port to our RTP receiver port */
3399 gst_rtspsrc_send_dummy_packets (GstRTSPSrc * src)
3403 if (src->nat_method != GST_RTSP_NAT_DUMMY)
3406 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3407 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3409 if (stream->fakesrc && stream->udpsink[0]) {
3410 GST_DEBUG_OBJECT (src, "sending dummy packet to stream %p", stream);
3411 gst_element_set_state (stream->udpsink[0], GST_STATE_NULL);
3412 gst_element_set_state (stream->fakesrc, GST_STATE_NULL);
3413 gst_element_set_state (stream->udpsink[0], GST_STATE_PLAYING);
3414 gst_element_set_state (stream->fakesrc, GST_STATE_PLAYING);
3420 /* Adds the source pads of all configured streams to the element.
3421 * This code is performed when we detected dataflow.
3423 * We detect dataflow from either the _loop function or with pad probes on the
3427 gst_rtspsrc_activate_streams (GstRTSPSrc * src)
3431 GST_DEBUG_OBJECT (src, "activating streams");
3433 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3434 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3436 if (stream->udpsrc[0]) {
3437 /* remove timeout, we are streaming now and timeouts will be handled by
3438 * the session manager and jitter buffer */
3439 g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout", (guint64) 0, NULL);
3441 if (stream->srcpad) {
3442 GST_DEBUG_OBJECT (src, "activating stream pad %p", stream);
3443 gst_pad_set_active (stream->srcpad, TRUE);
3445 /* if we don't have a session manager, set the caps now. If we have a
3446 * session, we will get a notification of the pad and the caps. */
3447 if (!src->manager) {
3448 GST_DEBUG_OBJECT (src, "setting pad caps for stream %p", stream);
3449 gst_pad_set_caps (stream->srcpad, stream->caps);
3452 if (!stream->added) {
3453 GST_DEBUG_OBJECT (src, "adding stream pad %p", stream);
3454 gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
3455 stream->added = TRUE;
3460 /* unblock all pads */
3461 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3462 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3464 if (stream->blockid) {
3465 GST_DEBUG_OBJECT (src, "unblocking stream pad %p", stream);
3466 gst_pad_remove_probe (stream->blockedpad, stream->blockid);
3467 stream->blockid = 0;
3475 gst_rtspsrc_configure_caps (GstRTSPSrc * src, GstSegment * segment,
3476 gboolean reset_manager)
3479 guint64 start, stop;
3480 gdouble play_speed, play_scale;
3482 GST_DEBUG_OBJECT (src, "configuring stream caps");
3484 start = segment->position;
3485 stop = segment->duration;
3486 play_speed = segment->rate;
3487 play_scale = segment->applied_rate;
3489 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3490 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3493 if ((caps = stream->caps)) {
3494 caps = gst_caps_make_writable (caps);
3496 if (stream->timebase != -1)
3497 gst_caps_set_simple (caps, "clock-base", G_TYPE_UINT,
3498 (guint) stream->timebase, NULL);
3499 if (stream->seqbase != -1)
3500 gst_caps_set_simple (caps, "seqnum-base", G_TYPE_UINT,
3501 (guint) stream->seqbase, NULL);
3502 gst_caps_set_simple (caps, "npt-start", G_TYPE_UINT64, start, NULL);
3504 gst_caps_set_simple (caps, "npt-stop", G_TYPE_UINT64, stop, NULL);
3505 gst_caps_set_simple (caps, "play-speed", G_TYPE_DOUBLE, play_speed, NULL);
3506 gst_caps_set_simple (caps, "play-scale", G_TYPE_DOUBLE, play_scale, NULL);
3508 stream->caps = caps;
3510 GST_DEBUG_OBJECT (src, "stream %p, caps %" GST_PTR_FORMAT, stream, caps);
3512 if (reset_manager && src->manager) {
3513 GST_DEBUG_OBJECT (src, "clear session");
3514 g_signal_emit_by_name (src->manager, "clear-pt-map", NULL);
3518 static GstFlowReturn
3519 gst_rtspsrc_combine_flows (GstRTSPSrc * src, GstRTSPStream * stream,
3524 /* store the value */
3525 stream->last_ret = ret;
3527 /* if it's success we can return the value right away */
3528 if (ret == GST_FLOW_OK)
3531 /* any other error that is not-linked can be returned right
3533 if (ret != GST_FLOW_NOT_LINKED)
3536 /* only return NOT_LINKED if all other pads returned NOT_LINKED */
3537 for (streams = src->streams; streams; streams = g_list_next (streams)) {
3538 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
3540 ret = ostream->last_ret;
3541 /* some other return value (must be SUCCESS but we can return
3542 * other values as well) */
3543 if (ret != GST_FLOW_NOT_LINKED)
3546 /* if we get here, all other pads were unlinked and we return
3547 * NOT_LINKED then */
3553 gst_rtspsrc_stream_push_event (GstRTSPSrc * src, GstRTSPStream * stream,
3556 gboolean res = TRUE;
3558 /* only streams that have a connection to the outside world */
3559 if (stream->container || stream->disabled)
3562 if (stream->udpsrc[0]) {
3563 gst_event_ref (event);
3564 res = gst_element_send_event (stream->udpsrc[0], event);
3565 } else if (stream->channelpad[0]) {
3566 gst_event_ref (event);
3567 if (GST_PAD_IS_SRC (stream->channelpad[0]))
3568 res = gst_pad_push_event (stream->channelpad[0], event);
3570 res = gst_pad_send_event (stream->channelpad[0], event);
3573 if (stream->udpsrc[1]) {
3574 gst_event_ref (event);
3575 res &= gst_element_send_event (stream->udpsrc[1], event);
3576 } else if (stream->channelpad[1]) {
3577 gst_event_ref (event);
3578 if (GST_PAD_IS_SRC (stream->channelpad[1]))
3579 res &= gst_pad_push_event (stream->channelpad[1], event);
3581 res &= gst_pad_send_event (stream->channelpad[1], event);
3585 gst_event_unref (event);
3591 gst_rtspsrc_push_event (GstRTSPSrc * src, GstEvent * event)
3594 gboolean res = TRUE;
3596 for (streams = src->streams; streams; streams = g_list_next (streams)) {
3597 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
3599 gst_event_ref (event);
3600 res &= gst_rtspsrc_stream_push_event (src, ostream, event);
3602 gst_event_unref (event);
3607 static GstRTSPResult
3608 gst_rtsp_conninfo_connect (GstRTSPSrc * src, GstRTSPConnInfo * info,
3613 if (info->connection == NULL) {
3614 if (info->url == NULL) {
3615 GST_DEBUG_OBJECT (src, "parsing uri (%s)...", info->location);
3616 if ((res = gst_rtsp_url_parse (info->location, &info->url)) < 0)
3620 /* create connection */
3621 GST_DEBUG_OBJECT (src, "creating connection (%s)...", info->location);
3622 if ((res = gst_rtsp_connection_create (info->url, &info->connection)) < 0)
3623 goto could_not_create;
3626 g_free (info->url_str);
3627 info->url_str = gst_rtsp_url_get_request_uri (info->url);
3629 GST_DEBUG_OBJECT (src, "sanitized uri %s", info->url_str);
3631 if (info->url->transports & GST_RTSP_LOWER_TRANS_HTTP)
3632 gst_rtsp_connection_set_tunneled (info->connection, TRUE);
3634 if (src->proxy_host) {
3635 GST_DEBUG_OBJECT (src, "setting proxy %s:%d", src->proxy_host,
3637 gst_rtsp_connection_set_proxy (info->connection, src->proxy_host,
3642 if (!info->connected) {
3645 GST_ELEMENT_PROGRESS (src, CONTINUE, "connect",
3646 ("Connecting to %s", info->location));
3647 GST_DEBUG_OBJECT (src, "connecting (%s)...", info->location);
3649 gst_rtsp_connection_connect (info->connection,
3650 src->ptcp_timeout)) < 0)
3651 goto could_not_connect;
3653 info->connected = TRUE;
3660 GST_ERROR_OBJECT (src, "No valid RTSP URL was provided");
3665 gchar *str = gst_rtsp_strresult (res);
3666 GST_ERROR_OBJECT (src, "Could not create connection. (%s)", str);
3672 gchar *str = gst_rtsp_strresult (res);
3673 GST_ERROR_OBJECT (src, "Could not connect to server. (%s)", str);
3679 static GstRTSPResult
3680 gst_rtsp_conninfo_close (GstRTSPSrc * src, GstRTSPConnInfo * info,
3683 GST_RTSP_STATE_LOCK (src);
3684 if (info->connected) {
3685 GST_DEBUG_OBJECT (src, "closing connection...");
3686 gst_rtsp_connection_close (info->connection);
3687 info->connected = FALSE;
3689 if (free && info->connection) {
3690 /* free connection */
3691 GST_DEBUG_OBJECT (src, "freeing connection...");
3692 gst_rtsp_connection_free (info->connection);
3693 info->connection = NULL;
3695 GST_RTSP_STATE_UNLOCK (src);
3699 static GstRTSPResult
3700 gst_rtsp_conninfo_reconnect (GstRTSPSrc * src, GstRTSPConnInfo * info,
3705 GST_DEBUG_OBJECT (src, "reconnecting connection...");
3706 gst_rtsp_conninfo_close (src, info, FALSE);
3707 res = gst_rtsp_conninfo_connect (src, info, async);
3713 gst_rtspsrc_connection_flush (GstRTSPSrc * src, gboolean flush)
3717 GST_DEBUG_OBJECT (src, "set flushing %d", flush);
3718 GST_RTSP_STATE_LOCK (src);
3719 if (src->conninfo.connection && src->conninfo.flushing != flush) {
3720 GST_DEBUG_OBJECT (src, "connection flush");
3721 gst_rtsp_connection_flush (src->conninfo.connection, flush);
3722 src->conninfo.flushing = flush;
3724 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3725 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3726 if (stream->conninfo.connection && stream->conninfo.flushing != flush) {
3727 GST_DEBUG_OBJECT (src, "stream %p flush", stream);
3728 gst_rtsp_connection_flush (stream->conninfo.connection, flush);
3729 stream->conninfo.flushing = flush;
3732 GST_RTSP_STATE_UNLOCK (src);
3735 /* FIXME, handle server request, reply with OK, for now */
3736 static GstRTSPResult
3737 gst_rtspsrc_handle_request (GstRTSPSrc * src, GstRTSPConnection * conn,
3738 GstRTSPMessage * request)
3740 GstRTSPMessage response = { 0 };
3743 GST_DEBUG_OBJECT (src, "got server request message");
3746 gst_rtsp_message_dump (request);
3748 res = gst_rtsp_ext_list_receive_request (src->extensions, request);
3750 if (res == GST_RTSP_ENOTIMPL) {
3751 /* default implementation, send OK */
3752 GST_DEBUG_OBJECT (src, "prepare OK reply");
3754 gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK, "OK",
3759 /* let app parse and reply */
3760 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_HANDLE_REQUEST],
3761 0, request, &response);
3764 gst_rtsp_message_dump (&response);
3766 res = gst_rtspsrc_connection_send (src, conn, &response, NULL);
3770 gst_rtsp_message_unset (&response);
3771 } else if (res == GST_RTSP_EEOF)
3779 gst_rtsp_message_unset (&response);
3784 /* send server keep-alive */
3785 static GstRTSPResult
3786 gst_rtspsrc_send_keep_alive (GstRTSPSrc * src)
3788 GstRTSPMessage request = { 0 };
3790 GstRTSPMethod method;
3793 if (src->do_rtsp_keep_alive == FALSE) {
3794 GST_DEBUG_OBJECT (src, "do-rtsp-keep-alive is FALSE, not sending.");
3795 gst_rtsp_connection_reset_timeout (src->conninfo.connection);
3799 GST_DEBUG_OBJECT (src, "creating server keep-alive");
3801 /* find a method to use for keep-alive */
3802 if (src->methods & GST_RTSP_GET_PARAMETER)
3803 method = GST_RTSP_GET_PARAMETER;
3805 method = GST_RTSP_OPTIONS;
3808 control = src->control;
3810 control = src->conninfo.url_str;
3812 if (control == NULL)
3815 res = gst_rtsp_message_init_request (&request, method, control);
3820 gst_rtsp_message_dump (&request);
3823 gst_rtspsrc_connection_send (src, src->conninfo.connection, &request,
3828 gst_rtsp_connection_reset_timeout (src->conninfo.connection);
3829 gst_rtsp_message_unset (&request);
3836 GST_WARNING_OBJECT (src, "no control url to send keepalive");
3841 gchar *str = gst_rtsp_strresult (res);
3843 gst_rtsp_message_unset (&request);
3844 GST_ELEMENT_WARNING (src, RESOURCE, WRITE, (NULL),
3845 ("Could not send keep-alive. (%s)", str));
3851 static GstFlowReturn
3852 gst_rtspsrc_handle_data (GstRTSPSrc * src, GstRTSPMessage * message)
3854 GstFlowReturn ret = GST_FLOW_OK;
3856 GstRTSPStream *stream;
3857 GstPad *outpad = NULL;
3864 channel = message->type_data.data.channel;
3866 stream = find_stream (src, &channel, (gpointer) find_stream_by_channel);
3868 goto unknown_stream;
3870 if (channel == stream->channel[0]) {
3871 outpad = stream->channelpad[0];
3873 } else if (channel == stream->channel[1]) {
3874 outpad = stream->channelpad[1];
3880 /* take a look at the body to figure out what we have */
3881 gst_rtsp_message_get_body (message, &data, &size);
3883 goto invalid_length;
3885 /* channels are not correct on some servers, do extra check */
3886 if (data[1] >= 200 && data[1] <= 204) {
3887 /* hmm RTCP message switch to the RTCP pad of the same stream. */
3888 outpad = stream->channelpad[1];
3892 /* we have no clue what this is, just ignore then. */
3894 goto unknown_stream;
3896 /* take the message body for further processing */
3897 gst_rtsp_message_steal_body (message, &data, &size);
3899 /* strip the trailing \0 */
3902 buf = gst_buffer_new ();
3903 gst_buffer_append_memory (buf,
3904 gst_memory_new_wrapped (0, data, size, 0, size, data, g_free));
3906 /* don't need message anymore */
3907 gst_rtsp_message_unset (message);
3909 GST_DEBUG_OBJECT (src, "pushing data of size %d on channel %d", size,
3912 if (src->need_activate) {
3918 guint group_id = gst_util_group_id_next ();
3920 /* generate an SHA256 sum of the URI */
3921 cs = g_checksum_new (G_CHECKSUM_SHA256);
3922 uri = src->conninfo.location;
3923 g_checksum_update (cs, (const guchar *) uri, strlen (uri));
3925 for (streams = src->streams; streams; streams = g_list_next (streams)) {
3926 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
3929 g_strdup_printf ("%s/%d", g_checksum_get_string (cs), ostream->id);
3930 event = gst_event_new_stream_start (stream_id);
3931 gst_event_set_group_id (event, group_id);
3934 gst_rtspsrc_stream_push_event (src, ostream, event);
3936 g_checksum_free (cs);
3938 gst_rtspsrc_activate_streams (src);
3939 src->need_activate = FALSE;
3941 if ((event = src->start_segment) != NULL) {
3942 src->start_segment = NULL;
3943 gst_rtspsrc_push_event (src, event);
3946 if (src->base_time == -1) {
3947 /* Take current running_time. This timestamp will be put on
3948 * the first buffer of each stream because we are a live source and so we
3949 * timestamp with the running_time. When we are dealing with TCP, we also
3950 * only timestamp the first buffer (using the DISCONT flag) because a server
3951 * typically bursts data, for which we don't want to compensate by speeding
3952 * up the media. The other timestamps will be interpollated from this one
3953 * using the RTP timestamps. */
3954 GST_OBJECT_LOCK (src);
3955 if (GST_ELEMENT_CLOCK (src)) {
3957 GstClockTime base_time;
3959 now = gst_clock_get_time (GST_ELEMENT_CLOCK (src));
3960 base_time = GST_ELEMENT_CAST (src)->base_time;
3962 src->base_time = now - base_time;
3964 GST_DEBUG_OBJECT (src, "first buffer at time %" GST_TIME_FORMAT ", base %"
3965 GST_TIME_FORMAT, GST_TIME_ARGS (now), GST_TIME_ARGS (base_time));
3967 GST_OBJECT_UNLOCK (src);
3970 if (stream->discont && !is_rtcp) {
3971 /* mark first RTP buffer as discont */
3972 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
3973 stream->discont = FALSE;
3974 /* first buffer gets the timestamp, other buffers are not timestamped and
3975 * their presentation time will be interpollated from the rtp timestamps. */
3976 GST_DEBUG_OBJECT (src, "setting timestamp %" GST_TIME_FORMAT,
3977 GST_TIME_ARGS (src->base_time));
3979 GST_BUFFER_TIMESTAMP (buf) = src->base_time;
3982 /* chain to the peer pad */
3983 if (GST_PAD_IS_SINK (outpad))
3984 ret = gst_pad_chain (outpad, buf);
3986 ret = gst_pad_push (outpad, buf);
3989 /* combine all stream flows for the data transport */
3990 ret = gst_rtspsrc_combine_flows (src, stream, ret);
3997 GST_DEBUG_OBJECT (src, "unknown stream on channel %d, ignored", channel);
3998 gst_rtsp_message_unset (message);
4003 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4004 ("Short message received, ignoring."));
4005 gst_rtsp_message_unset (message);
4010 static GstFlowReturn
4011 gst_rtspsrc_loop_interleaved (GstRTSPSrc * src)
4013 GstRTSPMessage message = { 0 };
4015 GstFlowReturn ret = GST_FLOW_OK;
4016 GTimeVal tv_timeout;
4019 /* get the next timeout interval */
4020 gst_rtsp_connection_next_timeout (src->conninfo.connection, &tv_timeout);
4022 /* see if the timeout period expired */
4023 if ((tv_timeout.tv_sec | tv_timeout.tv_usec) == 0) {
4024 GST_DEBUG_OBJECT (src, "timout, sending keep-alive");
4025 /* send keep-alive, only act on interrupt, a warning will be posted for
4027 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
4029 /* get new timeout */
4030 gst_rtsp_connection_next_timeout (src->conninfo.connection, &tv_timeout);
4033 GST_DEBUG_OBJECT (src, "doing receive with timeout %ld seconds, %ld usec",
4034 tv_timeout.tv_sec, tv_timeout.tv_usec);
4036 /* protect the connection with the connection lock so that we can see when
4037 * we are finished doing server communication */
4039 gst_rtspsrc_connection_receive (src, src->conninfo.connection,
4040 &message, src->ptcp_timeout);
4044 GST_DEBUG_OBJECT (src, "we received a server message");
4046 case GST_RTSP_EINTR:
4047 /* we got interrupted this means we need to stop */
4049 case GST_RTSP_ETIMEOUT:
4050 /* no reply, send keep alive */
4051 GST_DEBUG_OBJECT (src, "timeout, sending keep-alive");
4052 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
4056 /* go EOS when the server closed the connection */
4062 switch (message.type) {
4063 case GST_RTSP_MESSAGE_REQUEST:
4064 /* server sends us a request message, handle it */
4066 gst_rtspsrc_handle_request (src, src->conninfo.connection,
4068 if (res == GST_RTSP_EEOF)
4071 goto handle_request_failed;
4073 case GST_RTSP_MESSAGE_RESPONSE:
4074 /* we ignore response messages */
4075 GST_DEBUG_OBJECT (src, "ignoring response message");
4077 gst_rtsp_message_dump (&message);
4079 case GST_RTSP_MESSAGE_DATA:
4080 GST_DEBUG_OBJECT (src, "got data message");
4081 ret = gst_rtspsrc_handle_data (src, &message);
4082 if (ret != GST_FLOW_OK)
4083 goto handle_data_failed;
4086 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
4091 g_assert_not_reached ();
4096 GST_DEBUG_OBJECT (src, "we got an eof from the server");
4097 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4098 ("The server closed the connection."));
4099 src->conninfo.connected = FALSE;
4100 gst_rtsp_message_unset (&message);
4101 return GST_FLOW_EOS;
4105 gst_rtsp_message_unset (&message);
4106 GST_DEBUG_OBJECT (src, "got interrupted");
4107 return GST_FLOW_FLUSHING;
4111 gchar *str = gst_rtsp_strresult (res);
4113 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
4114 ("Could not receive message. (%s)", str));
4117 gst_rtsp_message_unset (&message);
4118 return GST_FLOW_ERROR;
4120 handle_request_failed:
4122 gchar *str = gst_rtsp_strresult (res);
4124 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
4125 ("Could not handle server message. (%s)", str));
4127 gst_rtsp_message_unset (&message);
4128 return GST_FLOW_ERROR;
4132 GST_DEBUG_OBJECT (src, "could no handle data message");
4137 static GstFlowReturn
4138 gst_rtspsrc_loop_udp (GstRTSPSrc * src)
4141 GstRTSPMessage message = { 0 };
4145 GTimeVal tv_timeout;
4147 /* get the next timeout interval */
4148 gst_rtsp_connection_next_timeout (src->conninfo.connection, &tv_timeout);
4150 GST_DEBUG_OBJECT (src, "doing receive with timeout %d seconds",
4151 (gint) tv_timeout.tv_sec);
4153 gst_rtsp_message_unset (&message);
4155 /* we should continue reading the TCP socket because the server might
4156 * send us requests. When the session timeout expires, we need to send a
4157 * keep-alive request to keep the session open. */
4158 res = gst_rtspsrc_connection_receive (src, src->conninfo.connection,
4159 &message, &tv_timeout);
4163 GST_DEBUG_OBJECT (src, "we received a server message");
4165 case GST_RTSP_EINTR:
4166 /* we got interrupted, see what we have to do */
4168 case GST_RTSP_ETIMEOUT:
4169 /* send keep-alive, ignore the result, a warning will be posted. */
4170 GST_DEBUG_OBJECT (src, "timeout, sending keep-alive");
4171 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
4175 /* server closed the connection. not very fatal for UDP, reconnect and
4176 * see what happens. */
4177 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4178 ("The server closed the connection."));
4179 if (src->udp_reconnect) {
4181 gst_rtsp_conninfo_reconnect (src, &src->conninfo, FALSE)) < 0)
4188 GST_DEBUG_OBJECT (src, "An ethernet problem occured.");
4190 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4191 ("Unhandled return value %d.", res));
4195 switch (message.type) {
4196 case GST_RTSP_MESSAGE_REQUEST:
4197 /* server sends us a request message, handle it */
4199 gst_rtspsrc_handle_request (src, src->conninfo.connection,
4201 if (res == GST_RTSP_EEOF)
4204 goto handle_request_failed;
4206 case GST_RTSP_MESSAGE_RESPONSE:
4207 /* we ignore response and data messages */
4208 GST_DEBUG_OBJECT (src, "ignoring response message");
4210 gst_rtsp_message_dump (&message);
4211 if (message.type_data.response.code == GST_RTSP_STS_UNAUTHORIZED) {
4212 GST_DEBUG_OBJECT (src, "but is Unauthorized response ...");
4213 if (gst_rtspsrc_setup_auth (src, &message) && !(retry++)) {
4214 GST_DEBUG_OBJECT (src, "so retrying keep-alive");
4215 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
4222 case GST_RTSP_MESSAGE_DATA:
4223 /* we ignore response and data messages */
4224 GST_DEBUG_OBJECT (src, "ignoring data message");
4227 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
4232 g_assert_not_reached ();
4234 /* we get here when the connection got interrupted */
4237 gst_rtsp_message_unset (&message);
4238 GST_DEBUG_OBJECT (src, "got interrupted");
4239 return GST_FLOW_FLUSHING;
4243 gchar *str = gst_rtsp_strresult (res);
4246 src->conninfo.connected = FALSE;
4247 if (res != GST_RTSP_EINTR) {
4248 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
4249 ("Could not connect to server. (%s)", str));
4251 ret = GST_FLOW_ERROR;
4253 ret = GST_FLOW_FLUSHING;
4259 gchar *str = gst_rtsp_strresult (res);
4261 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
4262 ("Could not receive message. (%s)", str));
4264 return GST_FLOW_ERROR;
4266 handle_request_failed:
4268 gchar *str = gst_rtsp_strresult (res);
4271 gst_rtsp_message_unset (&message);
4272 if (res != GST_RTSP_EINTR) {
4273 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
4274 ("Could not handle server message. (%s)", str));
4276 ret = GST_FLOW_ERROR;
4278 ret = GST_FLOW_FLUSHING;
4284 GST_DEBUG_OBJECT (src, "we got an eof from the server");
4285 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4286 ("The server closed the connection."));
4287 src->conninfo.connected = FALSE;
4288 gst_rtsp_message_unset (&message);
4289 return GST_FLOW_EOS;
4293 static GstRTSPResult
4294 gst_rtspsrc_reconnect (GstRTSPSrc * src, gboolean async)
4296 GstRTSPResult res = GST_RTSP_OK;
4299 GST_DEBUG_OBJECT (src, "doing reconnect");
4301 GST_OBJECT_LOCK (src);
4302 /* only restart when the pads were not yet activated, else we were
4303 * streaming over UDP */
4304 restart = src->need_activate;
4305 GST_OBJECT_UNLOCK (src);
4307 /* no need to restart, we're done */
4311 /* we can try only TCP now */
4312 src->cur_protocols = GST_RTSP_LOWER_TRANS_TCP;
4314 /* close and cleanup our state */
4315 if ((res = gst_rtspsrc_close (src, async, FALSE)) < 0)
4318 /* see if we have TCP left to try. Also don't try TCP when we were configured
4320 if (!(src->protocols & GST_RTSP_LOWER_TRANS_TCP) || src->from_sdp)
4323 /* We post a warning message now to inform the user
4324 * that nothing happened. It's most likely a firewall thing. */
4325 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4326 ("Could not receive any UDP packets for %.4f seconds, maybe your "
4327 "firewall is blocking it. Retrying using a TCP connection.",
4328 gst_guint64_to_gdouble (src->udp_timeout / 1000000.0)));
4330 /* open new connection using tcp */
4331 if (gst_rtspsrc_open (src, async) < 0)
4334 /* start playback */
4335 if (gst_rtspsrc_play (src, &src->segment, async) < 0)
4344 src->cur_protocols = 0;
4345 /* no transport possible, post an error and stop */
4346 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
4347 ("Could not receive any UDP packets for %.4f seconds, maybe your "
4348 "firewall is blocking it. No other protocols to try.",
4349 gst_guint64_to_gdouble (src->udp_timeout / 1000000.0)));
4350 return GST_RTSP_ERROR;
4354 GST_DEBUG_OBJECT (src, "open failed");
4359 GST_DEBUG_OBJECT (src, "play failed");
4365 gst_rtspsrc_loop_start_cmd (GstRTSPSrc * src, gint cmd)
4369 GST_ELEMENT_PROGRESS (src, START, "open", ("Opening Stream"));
4372 GST_ELEMENT_PROGRESS (src, START, "request", ("Sending PLAY request"));
4375 GST_ELEMENT_PROGRESS (src, START, "request", ("Sending PAUSE request"));
4378 GST_ELEMENT_PROGRESS (src, START, "close", ("Closing Stream"));
4386 gst_rtspsrc_loop_complete_cmd (GstRTSPSrc * src, gint cmd)
4390 GST_ELEMENT_PROGRESS (src, COMPLETE, "open", ("Opened Stream"));
4393 GST_ELEMENT_PROGRESS (src, COMPLETE, "request", ("Sent PLAY request"));
4396 GST_ELEMENT_PROGRESS (src, COMPLETE, "request", ("Sent PAUSE request"));
4399 GST_ELEMENT_PROGRESS (src, COMPLETE, "close", ("Closed Stream"));
4407 gst_rtspsrc_loop_cancel_cmd (GstRTSPSrc * src, gint cmd)
4411 GST_ELEMENT_PROGRESS (src, CANCELED, "open", ("Open canceled"));
4414 GST_ELEMENT_PROGRESS (src, CANCELED, "request", ("PLAY canceled"));
4417 GST_ELEMENT_PROGRESS (src, CANCELED, "request", ("PAUSE canceled"));
4420 GST_ELEMENT_PROGRESS (src, CANCELED, "close", ("Close canceled"));
4428 gst_rtspsrc_loop_error_cmd (GstRTSPSrc * src, gint cmd)
4432 GST_ELEMENT_PROGRESS (src, ERROR, "open", ("Open failed"));
4435 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("PLAY failed"));
4438 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("PAUSE failed"));
4441 GST_ELEMENT_PROGRESS (src, ERROR, "close", ("Close failed"));
4449 gst_rtspsrc_loop_end_cmd (GstRTSPSrc * src, gint cmd, GstRTSPResult ret)
4451 if (ret == GST_RTSP_OK)
4452 gst_rtspsrc_loop_complete_cmd (src, cmd);
4453 else if (ret == GST_RTSP_EINTR)
4454 gst_rtspsrc_loop_cancel_cmd (src, cmd);
4456 gst_rtspsrc_loop_error_cmd (src, cmd);
4460 gst_rtspsrc_loop_send_cmd (GstRTSPSrc * src, gint cmd, gint mask)
4463 gboolean flushed = FALSE;
4465 /* start new request */
4466 gst_rtspsrc_loop_start_cmd (src, cmd);
4468 GST_DEBUG_OBJECT (src, "sending cmd %d", cmd);
4470 GST_OBJECT_LOCK (src);
4471 old = src->pending_cmd;
4472 if (old == CMD_RECONNECT) {
4473 GST_DEBUG_OBJECT (src, "ignore, we were reconnecting");
4474 cmd = CMD_RECONNECT;
4476 if (old != CMD_WAIT) {
4477 src->pending_cmd = CMD_WAIT;
4478 GST_OBJECT_UNLOCK (src);
4479 /* cancel previous request */
4480 GST_DEBUG_OBJECT (src, "cancel previous request %d", old);
4481 gst_rtspsrc_loop_cancel_cmd (src, old);
4482 GST_OBJECT_LOCK (src);
4484 src->pending_cmd = cmd;
4485 /* interrupt if allowed */
4486 if (src->busy_cmd & mask) {
4487 GST_DEBUG_OBJECT (src, "connection flush busy %d", src->busy_cmd);
4488 gst_rtspsrc_connection_flush (src, TRUE);
4491 GST_DEBUG_OBJECT (src, "not interrupting busy cmd %d", src->busy_cmd);
4494 gst_task_start (src->task);
4495 GST_OBJECT_UNLOCK (src);
4501 gst_rtspsrc_loop (GstRTSPSrc * src)
4505 if (!src->conninfo.connection || !src->conninfo.connected)
4508 if (src->interleaved)
4509 ret = gst_rtspsrc_loop_interleaved (src);
4511 ret = gst_rtspsrc_loop_udp (src);
4513 if (ret != GST_FLOW_OK)
4521 GST_WARNING_OBJECT (src, "we are not connected");
4522 ret = GST_FLOW_FLUSHING;
4527 const gchar *reason = gst_flow_get_name (ret);
4529 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
4530 src->running = FALSE;
4531 if (ret == GST_FLOW_EOS) {
4532 /* perform EOS logic */
4533 if (src->segment.flags & GST_SEEK_FLAG_SEGMENT) {
4534 gst_element_post_message (GST_ELEMENT_CAST (src),
4535 gst_message_new_segment_done (GST_OBJECT_CAST (src),
4536 src->segment.format, src->segment.position));
4537 gst_rtspsrc_push_event (src,
4538 gst_event_new_segment_done (src->segment.format,
4539 src->segment.position));
4541 gst_rtspsrc_push_event (src, gst_event_new_eos ());
4543 } else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS) {
4544 /* for fatal errors we post an error message, post the error before the
4545 * EOS so the app knows about the error first. */
4546 GST_ELEMENT_ERROR (src, STREAM, FAILED,
4547 ("Internal data flow error."),
4548 ("streaming task paused, reason %s (%d)", reason, ret));
4549 gst_rtspsrc_push_event (src, gst_event_new_eos ());
4551 gst_rtspsrc_loop_send_cmd (src, CMD_WAIT, CMD_LOOP);
4556 #ifndef GST_DISABLE_GST_DEBUG
4557 static const gchar *
4558 gst_rtsp_auth_method_to_string (GstRTSPAuthMethod method)
4562 while (method != 0) {
4579 static const gchar *
4580 gst_rtspsrc_skip_lws (const gchar * s)
4582 while (g_ascii_isspace (*s))
4587 static const gchar *
4588 gst_rtspsrc_unskip_lws (const gchar * s, const gchar * start)
4590 while (s > start && g_ascii_isspace (*(s - 1)))
4595 static const gchar *
4596 gst_rtspsrc_skip_commas (const gchar * s)
4598 /* The grammar allows for multiple commas */
4599 while (g_ascii_isspace (*s) || *s == ',')
4604 static const gchar *
4605 gst_rtspsrc_skip_item (const gchar * s)
4607 gboolean quoted = FALSE;
4608 const gchar *start = s;
4610 /* A list item ends at the last non-whitespace character
4611 * before a comma which is not inside a quoted-string. Or at
4612 * the end of the string.
4618 if (*s == '\\' && *(s + 1))
4627 return gst_rtspsrc_unskip_lws (s, start);
4631 gst_rtsp_decode_quoted_string (gchar * quoted_string)
4635 src = quoted_string + 1;
4636 dst = quoted_string;
4637 while (*src && *src != '"') {
4638 if (*src == '\\' && *(src + 1))
4645 /* Extract the authentication tokens that the server provided for each method
4646 * into an array of structures and give those to the connection object.
4649 gst_rtspsrc_parse_digest_challenge (GstRTSPConnection * conn,
4650 const gchar * header, gboolean * stale)
4652 GSList *list = NULL, *iter;
4654 gchar *item, *eq, *name_end, *value;
4656 g_return_if_fail (stale != NULL);
4658 gst_rtsp_connection_clear_auth_params (conn);
4661 /* Parse a header whose content is described by RFC2616 as
4662 * "#something", where "something" does not itself contain commas,
4663 * except as part of quoted-strings, into a list of allocated strings.
4665 header = gst_rtspsrc_skip_commas (header);
4667 end = gst_rtspsrc_skip_item (header);
4668 list = g_slist_prepend (list, g_strndup (header, end - header));
4669 header = gst_rtspsrc_skip_commas (end);
4674 list = g_slist_reverse (list);
4675 for (iter = list; iter; iter = iter->next) {
4678 eq = strchr (item, '=');
4680 name_end = (gchar *) gst_rtspsrc_unskip_lws (eq, item);
4681 if (name_end == item) {
4682 /* That's no good... */
4689 value = (gchar *) gst_rtspsrc_skip_lws (eq + 1);
4691 gst_rtsp_decode_quoted_string (value);
4695 if (item && (strcmp (item, "stale") == 0) &&
4696 value && (strcmp (value, "TRUE") == 0))
4698 gst_rtsp_connection_set_auth_param (conn, item, value);
4702 g_slist_free (list);
4705 /* Parse a WWW-Authenticate Response header and determine the
4706 * available authentication methods
4708 * This code should also cope with the fact that each WWW-Authenticate
4709 * header can contain multiple challenge methods + tokens
4711 * At the moment, for Basic auth, we just do a minimal check and don't
4712 * even parse out the realm */
4714 gst_rtspsrc_parse_auth_hdr (gchar * hdr, GstRTSPAuthMethod * methods,
4715 GstRTSPConnection * conn, gboolean * stale)
4719 g_return_if_fail (hdr != NULL);
4720 g_return_if_fail (methods != NULL);
4721 g_return_if_fail (stale != NULL);
4723 /* Skip whitespace at the start of the string */
4724 for (start = hdr; start[0] != '\0' && g_ascii_isspace (start[0]); start++);
4726 if (g_ascii_strncasecmp (start, "basic", 5) == 0)
4727 *methods |= GST_RTSP_AUTH_BASIC;
4728 else if (g_ascii_strncasecmp (start, "digest ", 7) == 0) {
4729 *methods |= GST_RTSP_AUTH_DIGEST;
4730 gst_rtspsrc_parse_digest_challenge (conn, &start[7], stale);
4735 * gst_rtspsrc_setup_auth:
4736 * @src: the rtsp source
4738 * Configure a username and password and auth method on the
4739 * connection object based on a response we received from the
4742 * Currently, this requires that a username and password were supplied
4743 * in the uri. In the future, they may be requested on demand by sending
4744 * a message up the bus.
4746 * Returns: TRUE if authentication information could be set up correctly.
4749 gst_rtspsrc_setup_auth (GstRTSPSrc * src, GstRTSPMessage * response)
4753 GstRTSPAuthMethod avail_methods = GST_RTSP_AUTH_NONE;
4754 GstRTSPAuthMethod method;
4755 GstRTSPResult auth_result;
4757 GstRTSPConnection *conn;
4759 gboolean stale = FALSE;
4761 conn = src->conninfo.connection;
4763 /* Identify the available auth methods and see if any are supported */
4764 if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_WWW_AUTHENTICATE,
4765 &hdr, 0) == GST_RTSP_OK) {
4766 gst_rtspsrc_parse_auth_hdr (hdr, &avail_methods, conn, &stale);
4769 if (avail_methods == GST_RTSP_AUTH_NONE)
4770 goto no_auth_available;
4772 /* For digest auth, if the response indicates that the session
4773 * data are stale, we just update them in the connection object and
4774 * return TRUE to retry the request */
4776 src->tried_url_auth = FALSE;
4778 url = gst_rtsp_connection_get_url (conn);
4780 /* Do we have username and password available? */
4781 if (url != NULL && !src->tried_url_auth && url->user != NULL
4782 && url->passwd != NULL) {
4785 src->tried_url_auth = TRUE;
4786 GST_DEBUG_OBJECT (src,
4787 "Attempting authentication using credentials from the URL");
4789 user = src->user_id;
4790 pass = src->user_pw;
4791 GST_DEBUG_OBJECT (src,
4792 "Attempting authentication using credentials from the properties");
4795 /* FIXME: If the url didn't contain username and password or we tried them
4796 * already, request a username and passwd from the application via some kind
4797 * of credentials request message */
4799 /* If we don't have a username and passwd at this point, bail out. */
4800 if (user == NULL || pass == NULL)
4803 /* Try to configure for each available authentication method, strongest to
4805 for (method = GST_RTSP_AUTH_MAX; method != GST_RTSP_AUTH_NONE; method >>= 1) {
4806 /* Check if this method is available on the server */
4807 if ((method & avail_methods) == 0)
4810 /* Pass the credentials to the connection to try on the next request */
4811 auth_result = gst_rtsp_connection_set_auth (conn, method, user, pass);
4812 /* INVAL indicates an invalid username/passwd were supplied, so we'll just
4813 * ignore it and end up retrying later */
4814 if (auth_result == GST_RTSP_OK || auth_result == GST_RTSP_EINVAL) {
4815 GST_DEBUG_OBJECT (src, "Attempting %s authentication",
4816 gst_rtsp_auth_method_to_string (method));
4821 if (method == GST_RTSP_AUTH_NONE)
4822 goto no_auth_available;
4828 /* Output an error indicating that we couldn't connect because there were
4829 * no supported authentication protocols */
4830 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
4831 ("No supported authentication protocol was found"));
4836 /* We don't fire an error message, we just return FALSE and let the
4837 * normal NOT_AUTHORIZED error be propagated */
4842 static GstRTSPResult
4843 gst_rtspsrc_try_send (GstRTSPSrc * src, GstRTSPConnection * conn,
4844 GstRTSPMessage * request, GstRTSPMessage * response,
4845 GstRTSPStatusCode * code)
4848 GstRTSPStatusCode thecode;
4849 gchar *content_base = NULL;
4853 if (!src->short_header)
4854 gst_rtsp_ext_list_before_send (src->extensions, request);
4856 GST_DEBUG_OBJECT (src, "sending message");
4859 gst_rtsp_message_dump (request);
4861 res = gst_rtspsrc_connection_send (src, conn, request, src->ptcp_timeout);
4865 gst_rtsp_connection_reset_timeout (conn);
4868 res = gst_rtspsrc_connection_receive (src, conn, response, src->ptcp_timeout);
4873 gst_rtsp_message_dump (response);
4875 switch (response->type) {
4876 case GST_RTSP_MESSAGE_REQUEST:
4877 res = gst_rtspsrc_handle_request (src, conn, response);
4878 if (res == GST_RTSP_EEOF)
4881 goto handle_request_failed;
4883 case GST_RTSP_MESSAGE_RESPONSE:
4884 /* ok, a response is good */
4885 GST_DEBUG_OBJECT (src, "received response message");
4887 case GST_RTSP_MESSAGE_DATA:
4888 /* get next response */
4889 GST_DEBUG_OBJECT (src, "handle data response message");
4890 gst_rtspsrc_handle_data (src, response);
4893 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
4898 thecode = response->type_data.response.code;
4900 GST_DEBUG_OBJECT (src, "got response message %d", thecode);
4902 /* if the caller wanted the result code, we store it. */
4906 /* If the request didn't succeed, bail out before doing any more */
4907 if (thecode != GST_RTSP_STS_OK)
4910 /* store new content base if any */
4911 gst_rtsp_message_get_header (response, GST_RTSP_HDR_CONTENT_BASE,
4914 g_free (src->content_base);
4915 src->content_base = g_strdup (content_base);
4917 gst_rtsp_ext_list_after_send (src->extensions, request, response);
4924 gchar *str = gst_rtsp_strresult (res);
4926 if (res != GST_RTSP_EINTR) {
4927 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
4928 ("Could not send message. (%s)", str));
4930 GST_WARNING_OBJECT (src, "send interrupted");
4939 GST_WARNING_OBJECT (src, "server closed connection");
4940 if ((try == 0) && !src->interleaved && src->udp_reconnect) {
4942 /* if reconnect succeeds, try again */
4944 gst_rtsp_conninfo_reconnect (src, &src->conninfo,
4948 /* only try once after reconnect, then fallthrough and error out */
4951 gchar *str = gst_rtsp_strresult (res);
4953 if (res != GST_RTSP_EINTR) {
4954 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
4955 ("Could not receive message. (%s)", str));
4957 GST_WARNING_OBJECT (src, "receive interrupted");
4965 handle_request_failed:
4967 /* ERROR was posted */
4968 gst_rtsp_message_unset (response);
4973 GST_DEBUG_OBJECT (src, "we got an eof from the server");
4974 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
4975 ("The server closed the connection."));
4976 gst_rtsp_message_unset (response);
4983 * @src: the rtsp source
4984 * @conn: the connection to send on
4985 * @request: must point to a valid request
4986 * @response: must point to an empty #GstRTSPMessage
4987 * @code: an optional code result
4989 * send @request and retrieve the response in @response. optionally @code can be
4990 * non-NULL in which case it will contain the status code of the response.
4992 * If This function returns #GST_RTSP_OK, @response will contain a valid response
4993 * message that should be cleaned with gst_rtsp_message_unset() after usage.
4995 * If @code is NULL, this function will return #GST_RTSP_ERROR (with an invalid
4996 * @response message) if the response code was not 200 (OK).
4998 * If the attempt results in an authentication failure, then this will attempt
4999 * to retrieve authentication credentials via gst_rtspsrc_setup_auth and retry
5002 * Returns: #GST_RTSP_OK if the processing was successful.
5004 static GstRTSPResult
5005 gst_rtspsrc_send (GstRTSPSrc * src, GstRTSPConnection * conn,
5006 GstRTSPMessage * request, GstRTSPMessage * response,
5007 GstRTSPStatusCode * code)
5009 GstRTSPStatusCode int_code = GST_RTSP_STS_OK;
5010 GstRTSPResult res = GST_RTSP_ERROR;
5013 GstRTSPMethod method = GST_RTSP_INVALID;
5019 /* make sure we don't loop forever */
5023 /* save method so we can disable it when the server complains */
5024 method = request->type_data.request.method;
5027 gst_rtspsrc_try_send (src, conn, request, response, &int_code)) < 0)
5031 case GST_RTSP_STS_UNAUTHORIZED:
5032 if (gst_rtspsrc_setup_auth (src, response)) {
5033 /* Try the request/response again after configuring the auth info
5041 } while (retry == TRUE);
5043 /* If the user requested the code, let them handle errors, otherwise
5044 * post an error below */
5047 else if (int_code != GST_RTSP_STS_OK)
5048 goto error_response;
5055 GST_DEBUG_OBJECT (src, "got error %d", res);
5060 res = GST_RTSP_ERROR;
5062 switch (response->type_data.response.code) {
5063 case GST_RTSP_STS_NOT_FOUND:
5064 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), ("%s",
5065 response->type_data.response.reason));
5067 case GST_RTSP_STS_MOVED_PERMANENTLY:
5068 case GST_RTSP_STS_MOVE_TEMPORARILY:
5070 gchar *new_location;
5071 GstRTSPLowerTrans transports;
5073 GST_DEBUG_OBJECT (src, "got redirection");
5074 /* if we don't have a Location Header, we must error */
5075 if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_LOCATION,
5076 &new_location, 0) < 0)
5079 /* When we receive a redirect result, we go back to the INIT state after
5080 * parsing the new URI. The caller should do the needed steps to issue
5081 * a new setup when it detects this state change. */
5082 GST_DEBUG_OBJECT (src, "redirection to %s", new_location);
5084 /* save current transports */
5085 if (src->conninfo.url)
5086 transports = src->conninfo.url->transports;
5088 transports = GST_RTSP_LOWER_TRANS_UNKNOWN;
5090 gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (src), new_location, NULL);
5092 /* set old transports */
5093 if (src->conninfo.url && transports != GST_RTSP_LOWER_TRANS_UNKNOWN)
5094 src->conninfo.url->transports = transports;
5096 src->need_redirect = TRUE;
5097 src->state = GST_RTSP_STATE_INIT;
5101 case GST_RTSP_STS_NOT_ACCEPTABLE:
5102 case GST_RTSP_STS_NOT_IMPLEMENTED:
5103 case GST_RTSP_STS_METHOD_NOT_ALLOWED:
5104 GST_WARNING_OBJECT (src, "got NOT IMPLEMENTED, disable method %s",
5105 gst_rtsp_method_as_text (method));
5106 src->methods &= ~method;
5110 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5111 ("Got error response: %d (%s).", response->type_data.response.code,
5112 response->type_data.response.reason));
5115 /* if we return ERROR we should unset the response ourselves */
5116 if (res == GST_RTSP_ERROR)
5117 gst_rtsp_message_unset (response);
5123 static GstRTSPResult
5124 gst_rtspsrc_send_cb (GstRTSPExtension * ext, GstRTSPMessage * request,
5125 GstRTSPMessage * response, GstRTSPSrc * src)
5127 return gst_rtspsrc_send (src, src->conninfo.connection, request, response,
5132 /* parse the response and collect all the supported methods. We need this
5133 * information so that we don't try to send an unsupported request to the
5137 gst_rtspsrc_parse_methods (GstRTSPSrc * src, GstRTSPMessage * response)
5139 GstRTSPHeaderField field;
5143 /* reset supported methods */
5146 /* Try Allow Header first */
5147 field = GST_RTSP_HDR_ALLOW;
5150 gst_rtsp_message_get_header (response, field, &respoptions, indx);
5151 if (indx == 0 && !respoptions) {
5152 /* if no Allow header was found then try the Public header... */
5153 field = GST_RTSP_HDR_PUBLIC;
5154 gst_rtsp_message_get_header (response, field, &respoptions, indx);
5159 src->methods |= gst_rtsp_options_from_text (respoptions);
5164 if (src->methods == 0) {
5165 /* neither Allow nor Public are required, assume the server supports
5166 * at least DESCRIBE, SETUP, we always assume it supports PLAY as
5168 GST_DEBUG_OBJECT (src, "could not get OPTIONS");
5169 src->methods = GST_RTSP_DESCRIBE | GST_RTSP_SETUP;
5171 /* always assume PLAY, FIXME, extensions should be able to override
5173 src->methods |= GST_RTSP_PLAY;
5174 /* also assume it will support Range */
5175 src->seekable = TRUE;
5177 /* we need describe and setup */
5178 if (!(src->methods & GST_RTSP_DESCRIBE))
5180 if (!(src->methods & GST_RTSP_SETUP))
5188 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
5189 ("Server does not support DESCRIBE."));
5194 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
5195 ("Server does not support SETUP."));
5200 /* masks to be kept in sync with the hardcoded protocol order of preference
5202 static guint protocol_masks[] = {
5203 GST_RTSP_LOWER_TRANS_UDP,
5204 GST_RTSP_LOWER_TRANS_UDP_MCAST,
5205 GST_RTSP_LOWER_TRANS_TCP,
5209 static GstRTSPResult
5210 gst_rtspsrc_create_transports_string (GstRTSPSrc * src,
5211 GstRTSPLowerTrans protocols, gchar ** transports)
5215 gboolean add_udp_str;
5220 gst_rtsp_ext_list_get_transports (src->extensions, protocols, transports);
5225 GST_DEBUG_OBJECT (src, "got transports %s", GST_STR_NULL (*transports));
5227 /* extension listed transports, use those */
5228 if (*transports != NULL)
5231 /* it's the default */
5232 add_udp_str = FALSE;
5234 /* the default RTSP transports */
5235 result = g_string_new ("");
5236 if (protocols & GST_RTSP_LOWER_TRANS_UDP) {
5237 GST_DEBUG_OBJECT (src, "adding UDP unicast");
5239 g_string_append (result, "RTP/AVP");
5241 g_string_append (result, "/UDP");
5242 g_string_append (result, ";unicast;client_port=%%u1-%%u2");
5243 } else if (protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST) {
5244 GST_DEBUG_OBJECT (src, "adding UDP multicast");
5246 /* we don't have to allocate any UDP ports yet, if the selected transport
5247 * turns out to be multicast we can create them and join the multicast
5248 * group indicated in the transport reply */
5249 if (result->len > 0)
5250 g_string_append (result, ",");
5251 g_string_append (result, "RTP/AVP");
5253 g_string_append (result, "/UDP");
5254 g_string_append (result, ";multicast");
5255 if (src->next_port_num != 0) {
5256 if (src->client_port_range.max > 0 &&
5257 src->next_port_num >= src->client_port_range.max)
5260 g_string_append_printf (result, ";client_port=%d-%d",
5261 src->next_port_num, src->next_port_num + 1);
5263 } else if (protocols & GST_RTSP_LOWER_TRANS_TCP) {
5264 GST_DEBUG_OBJECT (src, "adding TCP");
5266 if (result->len > 0)
5267 g_string_append (result, ",");
5268 g_string_append (result, "RTP/AVP/TCP;unicast;interleaved=%%i1-%%i2");
5270 *transports = g_string_free (result, FALSE);
5272 GST_DEBUG_OBJECT (src, "prepared transports %s", GST_STR_NULL (*transports));
5279 GST_ERROR ("extension gave error %d", res);
5284 GST_ERROR ("no more ports available");
5285 return GST_RTSP_ERROR;
5289 static GstRTSPResult
5290 gst_rtspsrc_prepare_transports (GstRTSPStream * stream, gchar ** transports,
5291 gint orig_rtpport, gint orig_rtcpport)
5294 gint nr_udp, nr_int;
5296 gint rtpport = 0, rtcpport = 0;
5299 src = stream->parent;
5301 /* find number of placeholders first */
5302 if (strstr (*transports, "%%i2"))
5304 else if (strstr (*transports, "%%i1"))
5309 if (strstr (*transports, "%%u2"))
5311 else if (strstr (*transports, "%%u1"))
5316 if (nr_udp == 0 && nr_int == 0)
5320 if (!orig_rtpport || !orig_rtcpport) {
5321 if (!gst_rtspsrc_alloc_udp_ports (stream, &rtpport, &rtcpport))
5324 rtpport = orig_rtpport;
5325 rtcpport = orig_rtcpport;
5329 str = g_string_new ("");
5331 while ((next = strstr (p, "%%"))) {
5332 g_string_append_len (str, p, next - p);
5333 if (next[2] == 'u') {
5335 g_string_append_printf (str, "%d", rtpport);
5336 else if (next[3] == '2')
5337 g_string_append_printf (str, "%d", rtcpport);
5339 if (next[2] == 'i') {
5341 g_string_append_printf (str, "%d", src->free_channel);
5342 else if (next[3] == '2')
5343 g_string_append_printf (str, "%d", src->free_channel + 1);
5348 /* append final part */
5349 g_string_append (str, p);
5351 g_free (*transports);
5352 *transports = g_string_free (str, FALSE);
5360 GST_ERROR ("failed to allocate udp ports");
5361 return GST_RTSP_ERROR;
5366 gst_rtspsrc_stream_is_real_media (GstRTSPStream * stream)
5368 gboolean res = FALSE;
5372 const gchar *enc = NULL;
5374 s = gst_caps_get_structure (stream->caps, 0);
5375 if ((enc = gst_structure_get_string (s, "encoding-name"))) {
5376 res = (strstr (enc, "-REAL") != NULL);
5382 /* Perform the SETUP request for all the streams.
5384 * We ask the server for a specific transport, which initially includes all the
5385 * ones we can support (UDP/TCP/MULTICAST). For the UDP transport we allocate
5386 * two local UDP ports that we send to the server.
5388 * Once the server replied with a transport, we configure the other streams
5389 * with the same transport.
5391 * This function will also configure the stream for the selected transport,
5392 * which basically means creating the pipeline.
5394 static GstRTSPResult
5395 gst_rtspsrc_setup_streams (GstRTSPSrc * src, gboolean async)
5398 GstRTSPResult res = GST_RTSP_ERROR;
5399 GstRTSPMessage request = { 0 };
5400 GstRTSPMessage response = { 0 };
5401 GstRTSPStream *stream = NULL;
5402 GstRTSPLowerTrans protocols;
5403 GstRTSPStatusCode code;
5404 gboolean unsupported_real = FALSE;
5405 gint rtpport, rtcpport;
5409 if (src->conninfo.connection) {
5410 url = gst_rtsp_connection_get_url (src->conninfo.connection);
5411 /* we initially allow all configured lower transports. based on the URL
5412 * transports and the replies from the server we narrow them down. */
5413 protocols = url->transports & src->cur_protocols;
5416 protocols = src->cur_protocols;
5422 /* reset some state */
5423 src->free_channel = 0;
5424 src->interleaved = FALSE;
5425 src->need_activate = FALSE;
5426 /* keep track of next port number, 0 is random */
5427 src->next_port_num = src->client_port_range.min;
5428 rtpport = rtcpport = 0;
5430 if (G_UNLIKELY (src->streams == NULL))
5433 for (walk = src->streams; walk; walk = g_list_next (walk)) {
5434 GstRTSPConnection *conn;
5440 stream = (GstRTSPStream *) walk->data;
5442 /* see if we need to configure this stream */
5443 if (!gst_rtsp_ext_list_configure_stream (src->extensions, stream->caps)) {
5444 GST_DEBUG_OBJECT (src, "skipping stream %p, disabled by extension",
5446 stream->disabled = TRUE;
5450 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_SELECT_STREAM], 0,
5451 stream->id, stream->caps, &selected);
5453 GST_DEBUG_OBJECT (src, "skipping stream %p, disabled by signal", stream);
5454 stream->disabled = TRUE;
5457 stream->disabled = FALSE;
5459 /* merge/overwrite global caps */
5464 s = gst_caps_get_structure (stream->caps, 0);
5466 num = gst_structure_n_fields (src->props);
5467 for (j = 0; j < num; j++) {
5471 name = gst_structure_nth_field_name (src->props, j);
5472 val = gst_structure_get_value (src->props, name);
5473 gst_structure_set_value (s, name, val);
5475 GST_DEBUG_OBJECT (src, "copied %s", name);
5479 /* skip setup if we have no URL for it */
5480 if (stream->conninfo.location == NULL) {
5481 GST_DEBUG_OBJECT (src, "skipping stream %p, no setup", stream);
5485 if (src->conninfo.connection == NULL) {
5486 if (!gst_rtsp_conninfo_connect (src, &stream->conninfo, async)) {
5487 GST_DEBUG_OBJECT (src, "skipping stream %p, failed to connect", stream);
5490 conn = stream->conninfo.connection;
5492 conn = src->conninfo.connection;
5494 GST_DEBUG_OBJECT (src, "doing setup of stream %p with %s", stream,
5495 stream->conninfo.location);
5497 /* if we have a multicast connection, only suggest multicast from now on */
5498 if (stream->is_multicast)
5499 protocols &= GST_RTSP_LOWER_TRANS_UDP_MCAST;
5502 /* first selectable protocol */
5503 while (protocol_masks[mask] && !(protocols & protocol_masks[mask]))
5505 if (!protocol_masks[mask])
5509 GST_DEBUG_OBJECT (src, "protocols = 0x%x, protocol mask = 0x%x", protocols,
5510 protocol_masks[mask]);
5511 /* create a string with first transport in line */
5513 res = gst_rtspsrc_create_transports_string (src,
5514 protocols & protocol_masks[mask], &transports);
5515 if (res < 0 || transports == NULL)
5516 goto setup_transport_failed;
5518 if (strlen (transports) == 0) {
5519 g_free (transports);
5520 GST_DEBUG_OBJECT (src, "no transports found");
5525 GST_DEBUG_OBJECT (src, "replace ports in %s", GST_STR_NULL (transports));
5527 /* replace placeholders with real values, this function will optionally
5528 * allocate UDP ports and other info needed to execute the setup request */
5529 res = gst_rtspsrc_prepare_transports (stream, &transports,
5530 retry > 0 ? rtpport : 0, retry > 0 ? rtcpport : 0);
5532 g_free (transports);
5533 goto setup_transport_failed;
5536 GST_DEBUG_OBJECT (src, "transport is now %s", GST_STR_NULL (transports));
5538 /* create SETUP request */
5540 gst_rtsp_message_init_request (&request, GST_RTSP_SETUP,
5541 stream->conninfo.location);
5543 g_free (transports);
5544 goto create_request_failed;
5547 /* select transport */
5548 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_TRANSPORT, transports);
5550 /* if the user wants a non default RTP packet size we add the blocksize
5552 if (src->rtp_blocksize > 0) {
5553 hval = g_strdup_printf ("%d", src->rtp_blocksize);
5554 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_BLOCKSIZE, hval);
5558 GST_ELEMENT_PROGRESS (src, CONTINUE, "request", ("SETUP stream %d",
5561 /* handle the code ourselves */
5562 if ((res = gst_rtspsrc_send (src, conn, &request, &response, &code) < 0))
5566 case GST_RTSP_STS_OK:
5568 case GST_RTSP_STS_UNSUPPORTED_TRANSPORT:
5569 gst_rtsp_message_unset (&request);
5570 gst_rtsp_message_unset (&response);
5571 /* cleanup of leftover transport */
5572 gst_rtspsrc_stream_free_udp (stream);
5573 /* MS WMServer RTSP MUST use same UDP pair in all SETUP requests;
5574 * we might be in this case */
5575 if (stream->container && rtpport && rtcpport && !retry) {
5576 GST_DEBUG_OBJECT (src, "retrying with original port pair %u-%u",
5581 /* this transport did not go down well, but we may have others to try
5582 * that we did not send yet, try those and only give up then
5583 * but not without checking for lost cause/extension so we can
5584 * post a nicer/more useful error message later */
5585 if (!unsupported_real)
5586 unsupported_real = gst_rtspsrc_stream_is_real_media (stream);
5587 /* select next available protocol, give up on this stream if none */
5589 while (protocol_masks[mask] && !(protocols & protocol_masks[mask]))
5591 if (!protocol_masks[mask] || unsupported_real)
5596 /* cleanup of leftover transport and move to the next stream */
5597 gst_rtspsrc_stream_free_udp (stream);
5598 goto response_error;
5601 /* parse response transport */
5603 gchar *resptrans = NULL;
5604 GstRTSPTransport transport = { 0 };
5606 gst_rtsp_message_get_header (&response, GST_RTSP_HDR_TRANSPORT,
5609 gst_rtspsrc_stream_free_udp (stream);
5613 /* parse transport, go to next stream on parse error */
5614 if (gst_rtsp_transport_parse (resptrans, &transport) != GST_RTSP_OK) {
5615 GST_WARNING_OBJECT (src, "failed to parse transport %s", resptrans);
5619 /* update allowed transports for other streams. once the transport of
5620 * one stream has been determined, we make sure that all other streams
5621 * are configured in the same way */
5622 switch (transport.lower_transport) {
5623 case GST_RTSP_LOWER_TRANS_TCP:
5624 GST_DEBUG_OBJECT (src, "stream %p as TCP interleaved", stream);
5625 protocols = GST_RTSP_LOWER_TRANS_TCP;
5626 src->interleaved = TRUE;
5627 /* update free channels */
5629 MAX (transport.interleaved.min, src->free_channel);
5631 MAX (transport.interleaved.max, src->free_channel);
5632 src->free_channel++;
5634 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
5635 /* only allow multicast for other streams */
5636 GST_DEBUG_OBJECT (src, "stream %p as UDP multicast", stream);
5637 protocols = GST_RTSP_LOWER_TRANS_UDP_MCAST;
5638 /* if the server selected our ports, increment our counters so that
5639 * we select a new port later */
5640 if (src->next_port_num == transport.port.min &&
5641 src->next_port_num + 1 == transport.port.max) {
5642 src->next_port_num += 2;
5645 case GST_RTSP_LOWER_TRANS_UDP:
5646 /* only allow unicast for other streams */
5647 GST_DEBUG_OBJECT (src, "stream %p as UDP unicast", stream);
5648 protocols = GST_RTSP_LOWER_TRANS_UDP;
5651 GST_DEBUG_OBJECT (src, "stream %p unknown transport %d", stream,
5652 transport.lower_transport);
5656 if (!stream->container || (!src->interleaved && !retry)) {
5657 /* now configure the stream with the selected transport */
5658 if (!gst_rtspsrc_stream_configure_transport (stream, &transport)) {
5659 GST_DEBUG_OBJECT (src,
5660 "could not configure stream %p transport, skipping stream",
5663 } else if (stream->udpsrc[0] && stream->udpsrc[1]) {
5664 /* retain the first allocated UDP port pair */
5665 g_object_get (G_OBJECT (stream->udpsrc[0]), "port", &rtpport, NULL);
5666 g_object_get (G_OBJECT (stream->udpsrc[1]), "port", &rtcpport, NULL);
5669 /* we need to activate at least one streams when we detect activity */
5670 src->need_activate = TRUE;
5672 /* clean up our transport struct */
5673 gst_rtsp_transport_init (&transport);
5674 /* clean up used RTSP messages */
5675 gst_rtsp_message_unset (&request);
5676 gst_rtsp_message_unset (&response);
5680 /* store the transport protocol that was configured */
5681 src->cur_protocols = protocols;
5683 gst_rtsp_ext_list_stream_select (src->extensions, url);
5685 /* if there is nothing to activate, error out */
5686 if (!src->need_activate)
5687 goto nothing_to_activate;
5694 /* no transport possible, post an error and stop */
5695 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5696 ("Could not connect to server, no protocols left"));
5697 return GST_RTSP_ERROR;
5701 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
5702 ("SDP contains no streams"));
5703 return GST_RTSP_ERROR;
5705 create_request_failed:
5707 gchar *str = gst_rtsp_strresult (res);
5709 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
5710 ("Could not create request. (%s)", str));
5714 setup_transport_failed:
5716 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
5717 ("Could not setup transport."));
5718 res = GST_RTSP_ERROR;
5723 const gchar *str = gst_rtsp_status_as_text (code);
5725 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
5726 ("Error (%d): %s", code, GST_STR_NULL (str)));
5727 res = GST_RTSP_ERROR;
5732 gchar *str = gst_rtsp_strresult (res);
5734 if (res != GST_RTSP_EINTR) {
5735 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
5736 ("Could not send message. (%s)", str));
5738 GST_WARNING_OBJECT (src, "send interrupted");
5745 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
5746 ("Server did not select transport."));
5747 res = GST_RTSP_ERROR;
5750 nothing_to_activate:
5752 /* none of the available error codes is really right .. */
5753 if (unsupported_real) {
5754 GST_ELEMENT_ERROR (src, STREAM, CODEC_NOT_FOUND,
5755 (_("No supported stream was found. You might need to install a "
5756 "GStreamer RTSP extension plugin for Real media streams.")),
5759 GST_ELEMENT_ERROR (src, STREAM, CODEC_NOT_FOUND,
5760 (_("No supported stream was found. You might need to allow "
5761 "more transport protocols or may otherwise be missing "
5762 "the right GStreamer RTSP extension plugin.")), (NULL));
5764 return GST_RTSP_ERROR;
5768 gst_rtsp_message_unset (&request);
5769 gst_rtsp_message_unset (&response);
5775 gst_rtspsrc_parse_range (GstRTSPSrc * src, const gchar * range,
5776 GstSegment * segment)
5779 GstRTSPTimeRange *therange;
5782 gst_rtsp_range_free (src->range);
5784 if (gst_rtsp_range_parse (range, &therange) == GST_RTSP_OK) {
5785 GST_DEBUG_OBJECT (src, "parsed range %s", range);
5786 src->range = therange;
5788 GST_DEBUG_OBJECT (src, "failed to parse range %s", range);
5790 gst_segment_init (segment, GST_FORMAT_TIME);
5794 GST_DEBUG_OBJECT (src, "range: type %d, min %f - type %d, max %f ",
5795 therange->min.type, therange->min.seconds, therange->max.type,
5796 therange->max.seconds);
5798 if (therange->min.type == GST_RTSP_TIME_NOW)
5800 else if (therange->min.type == GST_RTSP_TIME_END)
5803 seconds = therange->min.seconds * GST_SECOND;
5805 GST_DEBUG_OBJECT (src, "range: min %" GST_TIME_FORMAT,
5806 GST_TIME_ARGS (seconds));
5808 /* we need to start playback without clipping from the position reported by
5810 segment->start = seconds;
5811 segment->position = seconds;
5813 if (therange->max.type == GST_RTSP_TIME_NOW)
5815 else if (therange->max.type == GST_RTSP_TIME_END)
5818 seconds = therange->max.seconds * GST_SECOND;
5820 GST_DEBUG_OBJECT (src, "range: max %" GST_TIME_FORMAT,
5821 GST_TIME_ARGS (seconds));
5823 /* live (WMS) server might send overflowed large max as its idea of infinity,
5824 * compensate to prevent problems later on */
5825 if (seconds != -1 && seconds < 0) {
5827 GST_DEBUG_OBJECT (src, "insane range, set to NONE");
5830 /* live (WMS) might send min == max, which is not worth recording */
5831 if (segment->duration == -1 && seconds == segment->start)
5834 /* don't change duration with unknown value, we might have a valid value
5835 * there that we want to keep. */
5837 segment->duration = seconds;
5842 /* Parse clock profived by the server with following syntax:
5844 * "GstNetTimeProvider <wrapped-clock> <server-IP:port> <clock-time>"
5847 gst_rtspsrc_parse_gst_clock (GstRTSPSrc * src, const gchar * gstclock)
5849 gboolean res = FALSE;
5851 if (g_str_has_prefix (gstclock, "GstNetTimeProvider ")) {
5852 gchar **fields = NULL, **parts = NULL;
5853 gchar *remote_ip, *str;
5855 GstClockTime base_time;
5858 fields = g_strsplit (gstclock, " ", 0);
5860 /* wrapped clock, not very interesting for now */
5861 if (fields[1] == NULL)
5864 /* remote IP address and port */
5865 if ((str = fields[2]) == NULL)
5868 parts = g_strsplit (str, ":", 0);
5870 if ((remote_ip = parts[0]) == NULL)
5873 if ((str = parts[1]) == NULL)
5881 if ((str = fields[3]) == NULL)
5884 base_time = g_ascii_strtoull (str, NULL, 10);
5887 gst_net_client_clock_new ((gchar *) "GstRTSPClock", remote_ip, port,
5890 if (src->provided_clock)
5891 gst_object_unref (src->provided_clock);
5892 src->provided_clock = netclock;
5894 gst_element_post_message (GST_ELEMENT_CAST (src),
5895 gst_message_new_clock_provide (GST_OBJECT_CAST (src),
5896 src->provided_clock, TRUE));
5900 g_strfreev (fields);
5906 /* must be called with the RTSP state lock */
5907 static GstRTSPResult
5908 gst_rtspsrc_open_from_sdp (GstRTSPSrc * src, GstSDPMessage * sdp,
5914 /* prepare global stream caps properties */
5916 gst_structure_remove_all_fields (src->props);
5918 src->props = gst_structure_new_empty ("RTSPProperties");
5921 gst_sdp_message_dump (sdp);
5923 gst_rtsp_ext_list_parse_sdp (src->extensions, sdp, src->props);
5925 /* let the app inspect and change the SDP */
5926 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_ON_SDP], 0, sdp);
5928 gst_segment_init (&src->segment, GST_FORMAT_TIME);
5930 /* parse range for duration reporting. */
5935 range = gst_sdp_message_get_attribute_val_n (sdp, "range", i);
5939 /* keep track of the range and configure it in the segment */
5940 if (gst_rtspsrc_parse_range (src, range, &src->segment))
5944 /* parse clock information. This is GStreamer specific, a server can tell the
5945 * client what clock it is using and wrap that in a network clock. The
5946 * advantage of that is that we can slave to it. */
5948 const gchar *gstclock;
5951 gstclock = gst_sdp_message_get_attribute_val_n (sdp, "x-gst-clock", i);
5952 if (gstclock == NULL)
5955 /* parse the clock and expose it in the provide_clock method */
5956 if (gst_rtspsrc_parse_gst_clock (src, gstclock))
5960 /* try to find a global control attribute. Note that a '*' means that we should
5961 * do aggregate control with the current url (so we don't do anything and
5962 * leave the current connection as is) */
5964 const gchar *control;
5967 control = gst_sdp_message_get_attribute_val_n (sdp, "control", i);
5968 if (control == NULL)
5971 /* only take fully qualified urls */
5972 if (g_str_has_prefix (control, "rtsp://"))
5976 g_free (src->conninfo.location);
5977 src->conninfo.location = g_strdup (control);
5978 /* make a connection for this, if there was a connection already, nothing
5980 if (gst_rtsp_conninfo_connect (src, &src->conninfo, async) < 0) {
5981 GST_ERROR_OBJECT (src, "could not connect");
5984 /* we need to keep the control url separate from the connection url because
5985 * the rules for constructing the media control url need it */
5986 g_free (src->control);
5987 src->control = g_strdup (control);
5990 /* create streams */
5991 n_streams = gst_sdp_message_medias_len (sdp);
5992 for (i = 0; i < n_streams; i++) {
5993 gst_rtspsrc_create_stream (src, sdp, i);
5996 src->state = GST_RTSP_STATE_INIT;
5999 if ((res = gst_rtspsrc_setup_streams (src, async)) < 0)
6002 /* reset our state */
6003 src->need_range = TRUE;
6006 src->state = GST_RTSP_STATE_READY;
6013 GST_ERROR_OBJECT (src, "setup failed");
6014 gst_rtspsrc_cleanup (src);
6019 static GstRTSPResult
6020 gst_rtspsrc_retrieve_sdp (GstRTSPSrc * src, GstSDPMessage ** sdp,
6024 GstRTSPMessage request = { 0 };
6025 GstRTSPMessage response = { 0 };
6028 gchar *respcont = NULL;
6031 src->need_redirect = FALSE;
6033 /* can't continue without a valid url */
6034 if (G_UNLIKELY (src->conninfo.url == NULL)) {
6035 res = GST_RTSP_EINVAL;
6038 src->tried_url_auth = FALSE;
6040 if ((res = gst_rtsp_conninfo_connect (src, &src->conninfo, async)) < 0)
6041 goto connect_failed;
6043 /* create OPTIONS */
6044 GST_DEBUG_OBJECT (src, "create options...");
6046 gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
6047 src->conninfo.url_str);
6049 goto create_request_failed;
6052 GST_DEBUG_OBJECT (src, "send options...");
6055 GST_ELEMENT_PROGRESS (src, CONTINUE, "open", ("Retrieving server options"));
6058 gst_rtspsrc_send (src, src->conninfo.connection, &request, &response,
6063 if (!gst_rtspsrc_parse_methods (src, &response))
6066 /* create DESCRIBE */
6067 GST_DEBUG_OBJECT (src, "create describe...");
6069 gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
6070 src->conninfo.url_str);
6072 goto create_request_failed;
6074 /* we only accept SDP for now */
6075 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_ACCEPT,
6079 GST_DEBUG_OBJECT (src, "send describe...");
6082 GST_ELEMENT_PROGRESS (src, CONTINUE, "open", ("Retrieving media info"));
6085 gst_rtspsrc_send (src, src->conninfo.connection, &request, &response,
6089 /* we only perform redirect for the describe, currently */
6090 if (src->need_redirect) {
6091 /* close connection, we don't have to send a TEARDOWN yet, ignore the
6093 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
6095 gst_rtsp_message_unset (&request);
6096 gst_rtsp_message_unset (&response);
6102 /* it could be that the DESCRIBE method was not implemented */
6103 if (!src->methods & GST_RTSP_DESCRIBE)
6106 /* check if reply is SDP */
6107 gst_rtsp_message_get_header (&response, GST_RTSP_HDR_CONTENT_TYPE, &respcont,
6109 /* could not be set but since the request returned OK, we assume it
6110 * was SDP, else check it. */
6112 if (!g_ascii_strcasecmp (respcont, "application/sdp") == 0)
6113 goto wrong_content_type;
6116 /* get message body and parse as SDP */
6117 gst_rtsp_message_get_body (&response, &data, &size);
6118 if (data == NULL || size == 0)
6121 GST_DEBUG_OBJECT (src, "parse SDP...");
6122 gst_sdp_message_new (sdp);
6123 gst_sdp_message_parse_buffer (data, size, *sdp);
6125 /* clean up any messages */
6126 gst_rtsp_message_unset (&request);
6127 gst_rtsp_message_unset (&response);
6134 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
6135 ("No valid RTSP URL was provided"));
6140 gchar *str = gst_rtsp_strresult (res);
6142 if (res != GST_RTSP_EINTR) {
6143 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
6144 ("Failed to connect. (%s)", str));
6146 GST_WARNING_OBJECT (src, "connect interrupted");
6151 create_request_failed:
6153 gchar *str = gst_rtsp_strresult (res);
6155 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
6156 ("Could not create request. (%s)", str));
6162 /* Don't post a message - the rtsp_send method will have
6163 * taken care of it because we passed NULL for the response code */
6168 /* error was posted */
6169 res = GST_RTSP_ERROR;
6174 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
6175 ("Server does not support SDP, got %s.", respcont));
6176 res = GST_RTSP_ERROR;
6181 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
6182 ("Server can not provide an SDP."));
6183 res = GST_RTSP_ERROR;
6188 if (src->conninfo.connection) {
6189 GST_DEBUG_OBJECT (src, "free connection");
6190 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
6192 gst_rtsp_message_unset (&request);
6193 gst_rtsp_message_unset (&response);
6198 static GstRTSPResult
6199 gst_rtspsrc_open (GstRTSPSrc * src, gboolean async)
6204 GST_RTSP_SETUP | GST_RTSP_PLAY | GST_RTSP_PAUSE | GST_RTSP_TEARDOWN;
6206 if (src->sdp == NULL) {
6207 if ((ret = gst_rtspsrc_retrieve_sdp (src, &src->sdp, async)) < 0)
6211 if ((ret = gst_rtspsrc_open_from_sdp (src, src->sdp, async)) < 0)
6216 gst_rtspsrc_loop_end_cmd (src, CMD_OPEN, ret);
6223 GST_WARNING_OBJECT (src, "can't get sdp");
6224 src->open_error = TRUE;
6229 GST_WARNING_OBJECT (src, "can't setup streaming from sdp");
6230 src->open_error = TRUE;
6235 static GstRTSPResult
6236 gst_rtspsrc_close (GstRTSPSrc * src, gboolean async, gboolean only_close)
6238 GstRTSPMessage request = { 0 };
6239 GstRTSPMessage response = { 0 };
6240 GstRTSPResult res = GST_RTSP_OK;
6244 GST_DEBUG_OBJECT (src, "TEARDOWN...");
6246 gst_rtspsrc_set_state (src, GST_STATE_READY);
6248 if (src->state < GST_RTSP_STATE_READY) {
6249 GST_DEBUG_OBJECT (src, "not ready, doing cleanup");
6256 /* construct a control url */
6258 control = src->control;
6260 control = src->conninfo.url_str;
6262 if (!(src->methods & (GST_RTSP_PLAY | GST_RTSP_TEARDOWN)))
6265 for (walk = src->streams; walk; walk = g_list_next (walk)) {
6266 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
6268 GstRTSPConnInfo *info;
6270 /* try aggregate control first but do non-aggregate control otherwise */
6272 setup_url = control;
6273 else if ((setup_url = stream->conninfo.location) == NULL)
6276 if (src->conninfo.connection) {
6277 info = &src->conninfo;
6278 } else if (stream->conninfo.connection) {
6279 info = &stream->conninfo;
6283 if (!info->connected)
6288 gst_rtsp_message_init_request (&request, GST_RTSP_TEARDOWN, setup_url);
6290 goto create_request_failed;
6293 GST_ELEMENT_PROGRESS (src, CONTINUE, "close", ("Closing stream"));
6296 gst_rtspsrc_send (src, info->connection, &request, &response,
6300 /* FIXME, parse result? */
6301 gst_rtsp_message_unset (&request);
6302 gst_rtsp_message_unset (&response);
6305 /* early exit when we did aggregate control */
6311 /* close connections */
6312 GST_DEBUG_OBJECT (src, "closing connection...");
6313 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
6314 for (walk = src->streams; walk; walk = g_list_next (walk)) {
6315 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
6316 gst_rtsp_conninfo_close (src, &stream->conninfo, TRUE);
6320 gst_rtspsrc_cleanup (src);
6322 src->state = GST_RTSP_STATE_INVALID;
6325 gst_rtspsrc_loop_end_cmd (src, CMD_CLOSE, res);
6330 create_request_failed:
6332 gchar *str = gst_rtsp_strresult (res);
6334 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
6335 ("Could not create request. (%s)", str));
6341 gchar *str = gst_rtsp_strresult (res);
6343 gst_rtsp_message_unset (&request);
6344 if (res != GST_RTSP_EINTR) {
6345 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
6346 ("Could not send message. (%s)", str));
6348 GST_WARNING_OBJECT (src, "TEARDOWN interrupted");
6355 GST_DEBUG_OBJECT (src,
6356 "TEARDOWN and PLAY not supported, can't do TEARDOWN");
6361 /* RTP-Info is of the format:
6363 * url=<URL>;[seq=<seqbase>;rtptime=<timebase>] [, url=...]
6365 * rtptime corresponds to the timestamp for the NPT time given in the header
6366 * seqbase corresponds to the next sequence number we received. This number
6367 * indicates the first seqnum after the seek and should be used to discard
6368 * packets that are from before the seek.
6371 gst_rtspsrc_parse_rtpinfo (GstRTSPSrc * src, gchar * rtpinfo)
6376 GST_DEBUG_OBJECT (src, "parsing RTP-Info %s", rtpinfo);
6378 infos = g_strsplit (rtpinfo, ",", 0);
6379 for (i = 0; infos[i]; i++) {
6381 GstRTSPStream *stream;
6385 GST_DEBUG_OBJECT (src, "parsing info %s", infos[i]);
6387 /* init values, types of seqbase and timebase are bigger than needed so we
6388 * can store -1 as uninitialized values */
6393 /* parse url, find stream for url.
6394 * parse seq and rtptime. The seq number should be configured in the rtp
6395 * depayloader or session manager to detect gaps. Same for the rtptime, it
6396 * should be used to create an initial time newsegment. */
6397 fields = g_strsplit (infos[i], ";", 0);
6398 for (j = 0; fields[j]; j++) {
6399 GST_DEBUG_OBJECT (src, "parsing field %s", fields[j]);
6400 /* remove leading whitespace */
6401 fields[j] = g_strchug (fields[j]);
6402 if (g_str_has_prefix (fields[j], "url=")) {
6403 /* get the url and the stream */
6405 find_stream (src, (fields[j] + 4), (gpointer) find_stream_by_setup);
6406 } else if (g_str_has_prefix (fields[j], "seq=")) {
6407 seqbase = atoi (fields[j] + 4);
6408 } else if (g_str_has_prefix (fields[j], "rtptime=")) {
6409 timebase = g_ascii_strtoll (fields[j] + 8, NULL, 10);
6412 g_strfreev (fields);
6413 /* now we need to store the values for the caps of the stream */
6414 if (stream != NULL) {
6415 GST_DEBUG_OBJECT (src,
6416 "found stream %p, setting: seqbase %d, timebase %" G_GINT64_FORMAT,
6417 stream, seqbase, timebase);
6419 /* we have a stream, configure detected params */
6420 stream->seqbase = seqbase;
6421 stream->timebase = timebase;
6430 gst_rtspsrc_handle_rtcp_interval (GstRTSPSrc * src, gchar * rtcp)
6435 interval = strtoul (rtcp, NULL, 10);
6436 GST_DEBUG_OBJECT (src, "rtcp interval: %" G_GUINT64_FORMAT " ms", interval);
6441 interval *= GST_MSECOND;
6443 for (walk = src->streams; walk; walk = g_list_next (walk)) {
6444 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
6446 /* already (optionally) retrieved this when configuring manager */
6447 if (stream->session) {
6448 GObject *rtpsession = stream->session;
6450 GST_DEBUG_OBJECT (src, "configure rtcp interval in session %p",
6452 g_object_set (rtpsession, "rtcp-min-interval", interval, NULL);
6456 /* now it happens that (Xenon) server sending this may also provide bogus
6457 * RTCP SR sync data (i.e. with quite some jitter), so never mind those
6458 * and just use RTP-Info to sync */
6460 GObjectClass *klass;
6462 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
6463 if (g_object_class_find_property (klass, "rtcp-sync")) {
6464 GST_DEBUG_OBJECT (src, "configuring rtp sync method");
6465 g_object_set (src->manager, "rtcp-sync", RTCP_SYNC_RTP, NULL);
6471 gst_rtspsrc_get_float (const gchar * dstr)
6473 gchar s[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
6475 /* canonicalise floating point string so we can handle float strings
6476 * in the form "24.930" or "24,930" irrespective of the current locale */
6477 g_strlcpy (s, dstr, sizeof (s));
6478 g_strdelimit (s, ",", '.');
6479 return g_ascii_strtod (s, NULL);
6483 gen_range_header (GstRTSPSrc * src, GstSegment * segment)
6485 gchar val_str[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
6487 if (src->range && src->range->min.type == GST_RTSP_TIME_NOW) {
6488 g_strlcpy (val_str, "now", sizeof (val_str));
6490 if (segment->position == 0) {
6491 g_strlcpy (val_str, "0", sizeof (val_str));
6493 g_ascii_dtostr (val_str, sizeof (val_str),
6494 ((gdouble) segment->position) / GST_SECOND);
6497 return g_strdup_printf ("npt=%s-", val_str);
6501 clear_rtp_base (GstRTSPSrc * src, GstRTSPStream * stream)
6503 stream->timebase = -1;
6504 stream->seqbase = -1;
6508 stream->caps = gst_caps_make_writable (stream->caps);
6509 s = gst_caps_get_structure (stream->caps, 0);
6510 gst_structure_remove_fields (s, "clock-base", "seqnum-base", NULL);
6514 static GstRTSPResult
6515 gst_rtspsrc_ensure_open (GstRTSPSrc * src, gboolean async)
6517 GstRTSPResult res = GST_RTSP_OK;
6519 if (src->state < GST_RTSP_STATE_READY) {
6520 res = GST_RTSP_ERROR;
6521 if (src->open_error) {
6522 GST_DEBUG_OBJECT (src, "the stream was in error");
6526 gst_rtspsrc_loop_start_cmd (src, CMD_OPEN);
6528 if ((res = gst_rtspsrc_open (src, async)) < 0) {
6529 GST_DEBUG_OBJECT (src, "failed to open stream");
6538 static GstRTSPResult
6539 gst_rtspsrc_play (GstRTSPSrc * src, GstSegment * segment, gboolean async)
6541 GstRTSPMessage request = { 0 };
6542 GstRTSPMessage response = { 0 };
6543 GstRTSPResult res = GST_RTSP_OK;
6549 GST_DEBUG_OBJECT (src, "PLAY...");
6551 if ((res = gst_rtspsrc_ensure_open (src, async)) < 0)
6554 if (!(src->methods & GST_RTSP_PLAY))
6557 if (src->state == GST_RTSP_STATE_PLAYING)
6560 if (!src->conninfo.connection || !src->conninfo.connected)
6563 /* send some dummy packets before we activate the receive in the
6565 gst_rtspsrc_send_dummy_packets (src);
6567 /* require new SR packets */
6569 g_signal_emit_by_name (src->manager, "reset-sync", NULL);
6571 gst_rtspsrc_set_state (src, GST_STATE_PLAYING);
6573 /* construct a control url */
6575 control = src->control;
6577 control = src->conninfo.url_str;
6579 for (walk = src->streams; walk; walk = g_list_next (walk)) {
6580 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
6582 GstRTSPConnection *conn;
6584 /* try aggregate control first but do non-aggregate control otherwise */
6586 setup_url = control;
6587 else if ((setup_url = stream->conninfo.location) == NULL)
6590 if (src->conninfo.connection) {
6591 conn = src->conninfo.connection;
6592 } else if (stream->conninfo.connection) {
6593 conn = stream->conninfo.connection;
6599 res = gst_rtsp_message_init_request (&request, GST_RTSP_PLAY, setup_url);
6601 goto create_request_failed;
6603 if (src->need_range) {
6604 hval = gen_range_header (src, segment);
6606 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_RANGE, hval);
6608 /* store the newsegment event so it can be sent from the streaming thread. */
6609 if (src->start_segment)
6610 gst_event_unref (src->start_segment);
6611 src->start_segment = gst_event_new_segment (&src->segment);
6614 if (segment->rate != 1.0) {
6615 gchar hval[G_ASCII_DTOSTR_BUF_SIZE];
6617 g_ascii_dtostr (hval, sizeof (hval), segment->rate);
6619 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SCALE, hval);
6621 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SPEED, hval);
6625 GST_ELEMENT_PROGRESS (src, CONTINUE, "request", ("Sending PLAY request"));
6627 if ((res = gst_rtspsrc_send (src, conn, &request, &response, NULL)) < 0)
6630 /* seek may have silently failed as it is not supported */
6631 if (!(src->methods & GST_RTSP_PLAY)) {
6632 GST_DEBUG_OBJECT (src, "PLAY Range not supported; re-enable PLAY");
6633 /* obviously it is supported as we made it here */
6634 src->methods |= GST_RTSP_PLAY;
6635 src->seekable = FALSE;
6636 /* but there is nothing to parse in the response,
6637 * so convey we have no idea and not to expect anything particular */
6638 clear_rtp_base (src, stream);
6642 /* need to do for all streams */
6643 for (run = src->streams; run; run = g_list_next (run))
6644 clear_rtp_base (src, (GstRTSPStream *) run->data);
6646 /* NOTE the above also disables npt based eos detection */
6647 /* and below forces position to 0,
6648 * which is visible feedback we lost the plot */
6649 segment->start = segment->position = src->last_pos;
6652 gst_rtsp_message_unset (&request);
6654 /* parse RTP npt field. This is the current position in the stream (Normal
6655 * Play Time) and should be put in the NEWSEGMENT position field. */
6656 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RANGE, &hval,
6658 gst_rtspsrc_parse_range (src, hval, segment);
6660 /* assume 1.0 rate now, overwrite when the SCALE or SPEED headers are present. */
6661 segment->rate = 1.0;
6663 /* parse Speed header. This is the intended playback rate of the stream
6664 * and should be put in the NEWSEGMENT rate field. */
6665 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_SPEED, &hval,
6666 0) == GST_RTSP_OK) {
6667 segment->rate = gst_rtspsrc_get_float (hval);
6668 } else if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_SCALE,
6669 &hval, 0) == GST_RTSP_OK) {
6670 segment->rate = gst_rtspsrc_get_float (hval);
6673 /* parse the RTP-Info header field (if ANY) to get the base seqnum and timestamp
6674 * for the RTP packets. If this is not present, we assume all starts from 0...
6675 * This is info for the RTP session manager that we pass to it in caps. */
6677 while (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RTP_INFO,
6678 &hval, hval_idx++) == GST_RTSP_OK)
6679 gst_rtspsrc_parse_rtpinfo (src, hval);
6681 /* some servers indicate RTCP parameters in PLAY response,
6682 * rather than properly in SDP */
6683 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RTCP_INTERVAL,
6684 &hval, 0) == GST_RTSP_OK)
6685 gst_rtspsrc_handle_rtcp_interval (src, hval);
6687 gst_rtsp_message_unset (&response);
6689 /* early exit when we did aggregate control */
6693 /* configure the caps of the streams after we parsed all headers. Only reset
6694 * the manager object when we set a new Range header (we did a seek) */
6695 gst_rtspsrc_configure_caps (src, segment, src->need_range);
6697 /* set again when needed */
6698 src->need_range = FALSE;
6700 src->running = TRUE;
6701 src->base_time = -1;
6702 src->state = GST_RTSP_STATE_PLAYING;
6705 GST_DEBUG_OBJECT (src, "mark DISCONT, we did a seek to another position");
6706 for (walk = src->streams; walk; walk = g_list_next (walk)) {
6707 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
6708 stream->discont = TRUE;
6713 gst_rtspsrc_loop_end_cmd (src, CMD_PLAY, res);
6720 GST_DEBUG_OBJECT (src, "failed to open stream");
6725 GST_DEBUG_OBJECT (src, "PLAY is not supported");
6730 GST_DEBUG_OBJECT (src, "we were already PLAYING");
6733 create_request_failed:
6735 gchar *str = gst_rtsp_strresult (res);
6737 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
6738 ("Could not create request. (%s)", str));
6744 gchar *str = gst_rtsp_strresult (res);
6746 gst_rtsp_message_unset (&request);
6747 if (res != GST_RTSP_EINTR) {
6748 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
6749 ("Could not send message. (%s)", str));
6751 GST_WARNING_OBJECT (src, "PLAY interrupted");
6758 static GstRTSPResult
6759 gst_rtspsrc_pause (GstRTSPSrc * src, gboolean async)
6761 GstRTSPResult res = GST_RTSP_OK;
6762 GstRTSPMessage request = { 0 };
6763 GstRTSPMessage response = { 0 };
6767 GST_DEBUG_OBJECT (src, "PAUSE...");
6769 if ((res = gst_rtspsrc_ensure_open (src, async)) < 0)
6772 if (!(src->methods & GST_RTSP_PAUSE))
6775 if (src->state == GST_RTSP_STATE_READY)
6778 if (!src->conninfo.connection || !src->conninfo.connected)
6781 /* construct a control url */
6783 control = src->control;
6785 control = src->conninfo.url_str;
6787 /* loop over the streams. We might exit the loop early when we could do an
6788 * aggregate control */
6789 for (walk = src->streams; walk; walk = g_list_next (walk)) {
6790 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
6791 GstRTSPConnection *conn;
6794 /* try aggregate control first but do non-aggregate control otherwise */
6796 setup_url = control;
6797 else if ((setup_url = stream->conninfo.location) == NULL)
6800 if (src->conninfo.connection) {
6801 conn = src->conninfo.connection;
6802 } else if (stream->conninfo.connection) {
6803 conn = stream->conninfo.connection;
6809 GST_ELEMENT_PROGRESS (src, CONTINUE, "request",
6810 ("Sending PAUSE request"));
6813 gst_rtsp_message_init_request (&request, GST_RTSP_PAUSE,
6815 goto create_request_failed;
6817 if ((res = gst_rtspsrc_send (src, conn, &request, &response, NULL)) < 0)
6820 gst_rtsp_message_unset (&request);
6821 gst_rtsp_message_unset (&response);
6823 /* exit early when we did agregate control */
6828 /* change element states now */
6829 gst_rtspsrc_set_state (src, GST_STATE_PAUSED);
6832 src->state = GST_RTSP_STATE_READY;
6836 gst_rtspsrc_loop_end_cmd (src, CMD_PAUSE, res);
6843 GST_DEBUG_OBJECT (src, "failed to open stream");
6848 GST_DEBUG_OBJECT (src, "PAUSE is not supported");
6853 GST_DEBUG_OBJECT (src, "we were already PAUSED");
6856 create_request_failed:
6858 gchar *str = gst_rtsp_strresult (res);
6860 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
6861 ("Could not create request. (%s)", str));
6867 gchar *str = gst_rtsp_strresult (res);
6869 gst_rtsp_message_unset (&request);
6870 if (res != GST_RTSP_EINTR) {
6871 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
6872 ("Could not send message. (%s)", str));
6874 GST_WARNING_OBJECT (src, "PAUSE interrupted");
6882 gst_rtspsrc_handle_message (GstBin * bin, GstMessage * message)
6884 GstRTSPSrc *rtspsrc;
6886 rtspsrc = GST_RTSPSRC (bin);
6888 switch (GST_MESSAGE_TYPE (message)) {
6889 case GST_MESSAGE_EOS:
6890 gst_message_unref (message);
6892 case GST_MESSAGE_ELEMENT:
6894 const GstStructure *s = gst_message_get_structure (message);
6896 if (gst_structure_has_name (s, "GstUDPSrcTimeout")) {
6897 gboolean ignore_timeout;
6899 GST_DEBUG_OBJECT (bin, "timeout on UDP port");
6901 GST_OBJECT_LOCK (rtspsrc);
6902 ignore_timeout = rtspsrc->ignore_timeout;
6903 rtspsrc->ignore_timeout = TRUE;
6904 GST_OBJECT_UNLOCK (rtspsrc);
6906 /* we only act on the first udp timeout message, others are irrelevant
6907 * and can be ignored. */
6908 if (!ignore_timeout)
6909 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_RECONNECT, CMD_LOOP);
6911 gst_message_unref (message);
6914 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
6917 case GST_MESSAGE_ERROR:
6920 GstRTSPStream *stream;
6923 udpsrc = GST_MESSAGE_SRC (message);
6925 GST_DEBUG_OBJECT (rtspsrc, "got error from %s",
6926 GST_ELEMENT_NAME (udpsrc));
6928 stream = find_stream (rtspsrc, udpsrc, (gpointer) find_stream_by_udpsrc);
6932 /* we ignore the RTCP udpsrc */
6933 if (stream->udpsrc[1] == GST_ELEMENT_CAST (udpsrc))
6936 /* if we get error messages from the udp sources, that's not a problem as
6937 * long as not all of them error out. We also don't really know what the
6938 * problem is, the message does not give enough detail... */
6939 ret = gst_rtspsrc_combine_flows (rtspsrc, stream, GST_FLOW_NOT_LINKED);
6940 GST_DEBUG_OBJECT (rtspsrc, "combined flows: %s", gst_flow_get_name (ret));
6941 if (ret != GST_FLOW_OK)
6945 gst_message_unref (message);
6949 /* fatal but not our message, forward */
6950 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
6955 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
6961 /* the thread where everything happens */
6963 gst_rtspsrc_thread (GstRTSPSrc * src)
6967 GST_OBJECT_LOCK (src);
6968 cmd = src->pending_cmd;
6969 if (cmd == CMD_RECONNECT || cmd == CMD_PLAY || cmd == CMD_PAUSE
6971 src->pending_cmd = CMD_LOOP;
6973 src->pending_cmd = CMD_WAIT;
6974 GST_DEBUG_OBJECT (src, "got command %d", cmd);
6976 /* we got the message command, so ensure communication is possible again */
6977 gst_rtspsrc_connection_flush (src, FALSE);
6979 src->busy_cmd = cmd;
6980 GST_OBJECT_UNLOCK (src);
6984 gst_rtspsrc_open (src, TRUE);
6987 gst_rtspsrc_play (src, &src->segment, TRUE);
6990 gst_rtspsrc_pause (src, TRUE);
6993 gst_rtspsrc_close (src, TRUE, FALSE);
6996 gst_rtspsrc_loop (src);
6999 gst_rtspsrc_reconnect (src, FALSE);
7005 GST_OBJECT_LOCK (src);
7006 /* and go back to sleep */
7007 if (src->pending_cmd == CMD_WAIT) {
7009 gst_task_pause (src->task);
7012 src->busy_cmd = CMD_WAIT;
7013 GST_OBJECT_UNLOCK (src);
7017 gst_rtspsrc_start (GstRTSPSrc * src)
7019 GST_DEBUG_OBJECT (src, "starting");
7021 GST_OBJECT_LOCK (src);
7023 src->pending_cmd = CMD_WAIT;
7025 if (src->task == NULL) {
7026 src->task = gst_task_new ((GstTaskFunction) gst_rtspsrc_thread, src, NULL);
7027 if (src->task == NULL)
7030 gst_task_set_lock (src->task, GST_RTSP_STREAM_GET_LOCK (src));
7032 GST_OBJECT_UNLOCK (src);
7039 GST_ERROR_OBJECT (src, "failed to create task");
7045 gst_rtspsrc_stop (GstRTSPSrc * src)
7049 GST_DEBUG_OBJECT (src, "stopping");
7051 /* also cancels pending task */
7052 gst_rtspsrc_loop_send_cmd (src, CMD_WAIT, CMD_ALL);
7054 GST_OBJECT_LOCK (src);
7055 if ((task = src->task)) {
7057 GST_OBJECT_UNLOCK (src);
7059 gst_task_stop (task);
7061 /* make sure it is not running */
7062 GST_RTSP_STREAM_LOCK (src);
7063 GST_RTSP_STREAM_UNLOCK (src);
7065 /* now wait for the task to finish */
7066 gst_task_join (task);
7068 /* and free the task */
7069 gst_object_unref (GST_OBJECT (task));
7071 GST_OBJECT_LOCK (src);
7073 GST_OBJECT_UNLOCK (src);
7075 /* ensure synchronously all is closed and clean */
7076 gst_rtspsrc_close (src, FALSE, TRUE);
7081 static GstStateChangeReturn
7082 gst_rtspsrc_change_state (GstElement * element, GstStateChange transition)
7084 GstRTSPSrc *rtspsrc;
7085 GstStateChangeReturn ret;
7087 rtspsrc = GST_RTSPSRC (element);
7089 switch (transition) {
7090 case GST_STATE_CHANGE_NULL_TO_READY:
7091 if (!gst_rtspsrc_start (rtspsrc))
7094 case GST_STATE_CHANGE_READY_TO_PAUSED:
7095 /* init some state */
7096 rtspsrc->cur_protocols = rtspsrc->protocols;
7097 /* first attempt, don't ignore timeouts */
7098 rtspsrc->ignore_timeout = FALSE;
7099 rtspsrc->open_error = FALSE;
7100 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_OPEN, 0);
7102 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
7103 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
7104 /* unblock the tcp tasks and make the loop waiting */
7105 if (gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_WAIT, CMD_LOOP)) {
7106 /* make sure it is waiting before we send PAUSE or PLAY below */
7107 GST_RTSP_STREAM_LOCK (rtspsrc);
7108 GST_RTSP_STREAM_UNLOCK (rtspsrc);
7111 case GST_STATE_CHANGE_PAUSED_TO_READY:
7117 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
7118 if (ret == GST_STATE_CHANGE_FAILURE)
7121 switch (transition) {
7122 case GST_STATE_CHANGE_NULL_TO_READY:
7123 ret = GST_STATE_CHANGE_SUCCESS;
7125 case GST_STATE_CHANGE_READY_TO_PAUSED:
7126 ret = GST_STATE_CHANGE_NO_PREROLL;
7128 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
7129 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_PLAY, 0);
7130 ret = GST_STATE_CHANGE_SUCCESS;
7132 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
7133 /* send pause request and keep the idle task around */
7134 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_PAUSE, CMD_LOOP);
7135 ret = GST_STATE_CHANGE_NO_PREROLL;
7137 case GST_STATE_CHANGE_PAUSED_TO_READY:
7138 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_CLOSE, CMD_PAUSE);
7139 ret = GST_STATE_CHANGE_SUCCESS;
7141 case GST_STATE_CHANGE_READY_TO_NULL:
7142 gst_rtspsrc_stop (rtspsrc);
7143 ret = GST_STATE_CHANGE_SUCCESS;
7154 GST_DEBUG_OBJECT (rtspsrc, "start failed");
7155 return GST_STATE_CHANGE_FAILURE;
7160 gst_rtspsrc_send_event (GstElement * element, GstEvent * event)
7163 GstRTSPSrc *rtspsrc;
7165 rtspsrc = GST_RTSPSRC (element);
7167 if (GST_EVENT_IS_DOWNSTREAM (event)) {
7168 res = gst_rtspsrc_push_event (rtspsrc, event);
7170 res = GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
7177 /*** GSTURIHANDLER INTERFACE *************************************************/
7180 gst_rtspsrc_uri_get_type (GType type)
7185 static const gchar *const *
7186 gst_rtspsrc_uri_get_protocols (GType type)
7188 static const gchar *protocols[] =
7189 { "rtsp", "rtspu", "rtspt", "rtsph", "rtsp-sdp",
7190 "rtsps", "rtspsu", "rtspst", "rtspsh", NULL
7197 gst_rtspsrc_uri_get_uri (GstURIHandler * handler)
7199 GstRTSPSrc *src = GST_RTSPSRC (handler);
7201 /* FIXME: make thread-safe */
7202 return g_strdup (src->conninfo.location);
7206 gst_rtspsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri,
7211 GstRTSPUrl *newurl = NULL;
7212 GstSDPMessage *sdp = NULL;
7214 src = GST_RTSPSRC (handler);
7216 /* same URI, we're fine */
7217 if (src->conninfo.location && uri && !strcmp (uri, src->conninfo.location))
7220 if (g_str_has_prefix (uri, "rtsp-sdp://")) {
7221 if ((res = gst_sdp_message_new (&sdp) < 0))
7224 GST_DEBUG_OBJECT (src, "parsing SDP message");
7225 if ((res = gst_sdp_message_parse_uri (uri, sdp) < 0))
7229 GST_DEBUG_OBJECT (src, "parsing URI");
7230 if ((res = gst_rtsp_url_parse (uri, &newurl)) < 0)
7234 /* if worked, free previous and store new url object along with the original
7236 GST_DEBUG_OBJECT (src, "configuring URI");
7237 g_free (src->conninfo.location);
7238 src->conninfo.location = g_strdup (uri);
7239 gst_rtsp_url_free (src->conninfo.url);
7240 src->conninfo.url = newurl;
7241 g_free (src->conninfo.url_str);
7243 src->conninfo.url_str = gst_rtsp_url_get_request_uri (src->conninfo.url);
7245 src->conninfo.url_str = NULL;
7248 gst_sdp_message_free (src->sdp);
7250 src->from_sdp = sdp != NULL;
7252 GST_DEBUG_OBJECT (src, "set uri: %s", GST_STR_NULL (uri));
7253 GST_DEBUG_OBJECT (src, "request uri is: %s",
7254 GST_STR_NULL (src->conninfo.url_str));
7261 GST_DEBUG_OBJECT (src, "URI was ok: '%s'", GST_STR_NULL (uri));
7266 GST_ERROR_OBJECT (src, "Could not create new SDP (%d)", res);
7267 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
7268 "Could not create SDP");
7273 GST_ERROR_OBJECT (src, "Not a valid SDP (%d) '%s'", res,
7274 GST_STR_NULL (uri));
7275 gst_sdp_message_free (sdp);
7276 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
7282 GST_ERROR_OBJECT (src, "Not a valid RTSP url '%s' (%d)",
7283 GST_STR_NULL (uri), res);
7284 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
7285 "Invalid RTSP URI");
7291 gst_rtspsrc_uri_handler_init (gpointer g_iface, gpointer iface_data)
7293 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
7295 iface->get_type = gst_rtspsrc_uri_get_type;
7296 iface->get_protocols = gst_rtspsrc_uri_get_protocols;
7297 iface->get_uri = gst_rtspsrc_uri_get_uri;
7298 iface->set_uri = gst_rtspsrc_uri_set_uri;