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
47 * Makes a connection to an RTSP server and read the data.
48 * rtspsrc strictly follows RFC 2326 and therefore does not (yet) support
49 * RealMedia/Quicktime/Microsoft extensions.
51 * RTSP supports transport over TCP or UDP in unicast or multicast mode. By
52 * default rtspsrc will negotiate a connection in the following order:
53 * UDP unicast/UDP multicast/TCP. The order cannot be changed but the allowed
54 * protocols can be controlled with the #GstRTSPSrc:protocols property.
56 * rtspsrc currently understands SDP as the format of the session description.
57 * For each stream listed in the SDP a new rtp_stream\%d pad will be created
58 * with caps derived from the SDP media description. This is a caps of mime type
59 * "application/x-rtp" that can be connected to any available RTP depayloader
62 * rtspsrc will internally instantiate an RTP session manager element
63 * that will handle the RTCP messages to and from the server, jitter removal,
64 * packet reordering along with providing a clock for the pipeline.
65 * This feature is implemented using the gstrtpbin element.
67 * rtspsrc acts like a live source and will therefore only generate data in the
70 * If a RTP session times out then the rtspsrc will generate an element message
71 * named "GstRTSPSrcTimeout". Currently this is only supported for timeouts
74 * The message's structure contains three fields:
76 * GstRTSPSrcTimeoutCause `cause`: the cause of the timeout.
78 * #gint `stream-number`: an internal identifier of the stream that timed out.
80 * #guint `ssrc`: the SSRC of the stream that timed out.
82 * ## Example launch line
84 * gst-launch-1.0 rtspsrc location=rtsp://some.server/url ! fakesink
85 * ]| Establish a connection to an RTSP server and send the raw RTP packets to a
88 * NOTE: rtspsrc will send a PAUSE command to the server if you set the
89 * element to the PAUSED state, and will send a PLAY command if you set it to
92 * Unfortunately, going to the NULL state involves going through PAUSED, so
93 * rtspsrc does not know the difference and will send a PAUSE when you wanted
94 * a TEARDOWN. The workaround is to hook into the `before-send` signal and
95 * return FALSE in this case.
104 #endif /* HAVE_UNISTD_H */
110 #include <gst/net/gstnet.h>
111 #include <gst/sdp/gstsdpmessage.h>
112 #include <gst/sdp/gstmikey.h>
113 #include <gst/rtp/rtp.h>
115 #include "gst/gst-i18n-plugin.h"
117 #include "gstrtspelements.h"
118 #include "gstrtspsrc.h"
120 GST_DEBUG_CATEGORY_STATIC (rtspsrc_debug);
121 #define GST_CAT_DEFAULT (rtspsrc_debug)
123 static GstStaticPadTemplate rtptemplate = GST_STATIC_PAD_TEMPLATE ("stream_%u",
126 GST_STATIC_CAPS ("application/x-rtp; application/x-rdt"));
128 /* templates used internally */
129 static GstStaticPadTemplate anysrctemplate =
130 GST_STATIC_PAD_TEMPLATE ("internalsrc_%u",
133 GST_STATIC_CAPS_ANY);
135 static GstStaticPadTemplate anysinktemplate =
136 GST_STATIC_PAD_TEMPLATE ("internalsink_%u",
139 GST_STATIC_CAPS_ANY);
143 SIGNAL_HANDLE_REQUEST,
145 SIGNAL_SELECT_STREAM,
147 SIGNAL_REQUEST_RTCP_KEY,
148 SIGNAL_ACCEPT_CERTIFICATE,
150 SIGNAL_PUSH_BACKCHANNEL_BUFFER,
151 SIGNAL_GET_PARAMETER,
152 SIGNAL_GET_PARAMETERS,
153 SIGNAL_SET_PARAMETER,
157 enum _GstRtspSrcRtcpSyncMode
164 enum _GstRtspSrcBufferMode
173 #define GST_TYPE_RTSP_SRC_BUFFER_MODE (gst_rtsp_src_buffer_mode_get_type())
175 gst_rtsp_src_buffer_mode_get_type (void)
177 static GType buffer_mode_type = 0;
178 static const GEnumValue buffer_modes[] = {
179 {BUFFER_MODE_NONE, "Only use RTP timestamps", "none"},
180 {BUFFER_MODE_SLAVE, "Slave receiver to sender clock", "slave"},
181 {BUFFER_MODE_BUFFER, "Do low/high watermark buffering", "buffer"},
182 {BUFFER_MODE_AUTO, "Choose mode depending on stream live", "auto"},
183 {BUFFER_MODE_SYNCED, "Synchronized sender and receiver clocks", "synced"},
187 if (!buffer_mode_type) {
189 g_enum_register_static ("GstRTSPSrcBufferMode", buffer_modes);
191 return buffer_mode_type;
194 enum _GstRtspSrcNtpTimeSource
197 NTP_TIME_SOURCE_UNIX,
198 NTP_TIME_SOURCE_RUNNING_TIME,
199 NTP_TIME_SOURCE_CLOCK_TIME
202 #define DEBUG_RTSP(__self,msg) gst_rtspsrc_print_rtsp_message (__self, msg)
203 #define DEBUG_SDP(__self,msg) gst_rtspsrc_print_sdp_message (__self, msg)
205 #define GST_TYPE_RTSP_SRC_NTP_TIME_SOURCE (gst_rtsp_src_ntp_time_source_get_type())
207 gst_rtsp_src_ntp_time_source_get_type (void)
209 static GType ntp_time_source_type = 0;
210 static const GEnumValue ntp_time_source_values[] = {
211 {NTP_TIME_SOURCE_NTP, "NTP time based on realtime clock", "ntp"},
212 {NTP_TIME_SOURCE_UNIX, "UNIX time based on realtime clock", "unix"},
213 {NTP_TIME_SOURCE_RUNNING_TIME,
214 "Running time based on pipeline clock",
216 {NTP_TIME_SOURCE_CLOCK_TIME, "Pipeline clock time", "clock-time"},
220 if (!ntp_time_source_type) {
221 ntp_time_source_type =
222 g_enum_register_static ("GstRTSPSrcNtpTimeSource",
223 ntp_time_source_values);
225 return ntp_time_source_type;
228 enum _GstRtspBackchannel
234 #define GST_TYPE_RTSP_BACKCHANNEL (gst_rtsp_backchannel_get_type())
236 gst_rtsp_backchannel_get_type (void)
238 static GType backchannel_type = 0;
239 static const GEnumValue backchannel_values[] = {
240 {BACKCHANNEL_NONE, "No backchannel", "none"},
241 {BACKCHANNEL_ONVIF, "ONVIF audio backchannel", "onvif"},
245 if (G_UNLIKELY (backchannel_type == 0)) {
247 g_enum_register_static ("GstRTSPBackchannel", backchannel_values);
249 return backchannel_type;
252 #define BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL "www.onvif.org/ver20/backchannel"
254 #define DEFAULT_LOCATION NULL
255 #define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | GST_RTSP_LOWER_TRANS_TCP
256 #define DEFAULT_DEBUG FALSE
257 #define DEFAULT_RETRY 20
258 #define DEFAULT_TIMEOUT 5000000
259 #define DEFAULT_UDP_BUFFER_SIZE 0x80000
260 #define DEFAULT_TCP_TIMEOUT 20000000
261 #define DEFAULT_LATENCY_MS 2000
262 #define DEFAULT_DROP_ON_LATENCY FALSE
263 #define DEFAULT_CONNECTION_SPEED 0
264 #define DEFAULT_NAT_METHOD GST_RTSP_NAT_DUMMY
265 #define DEFAULT_DO_RTCP TRUE
266 #define DEFAULT_DO_RTSP_KEEP_ALIVE TRUE
267 #define DEFAULT_PROXY NULL
268 #define DEFAULT_RTP_BLOCKSIZE 0
269 #define DEFAULT_USER_ID NULL
270 #define DEFAULT_USER_PW NULL
271 #define DEFAULT_BUFFER_MODE BUFFER_MODE_AUTO
272 #define DEFAULT_PORT_RANGE NULL
273 #define DEFAULT_SHORT_HEADER FALSE
274 #define DEFAULT_PROBATION 2
275 #define DEFAULT_UDP_RECONNECT TRUE
276 #define DEFAULT_MULTICAST_IFACE NULL
277 #define DEFAULT_NTP_SYNC FALSE
278 #define DEFAULT_USE_PIPELINE_CLOCK FALSE
279 #define DEFAULT_TLS_VALIDATION_FLAGS G_TLS_CERTIFICATE_VALIDATE_ALL
280 #define DEFAULT_TLS_DATABASE NULL
281 #define DEFAULT_TLS_INTERACTION NULL
282 #define DEFAULT_DO_RETRANSMISSION TRUE
283 #define DEFAULT_NTP_TIME_SOURCE NTP_TIME_SOURCE_NTP
284 #define DEFAULT_USER_AGENT "GStreamer/" PACKAGE_VERSION
285 #define DEFAULT_MAX_RTCP_RTP_TIME_DIFF 1000
286 #define DEFAULT_RFC7273_SYNC FALSE
287 #define DEFAULT_MAX_TS_OFFSET_ADJUSTMENT G_GUINT64_CONSTANT(0)
288 #define DEFAULT_MAX_TS_OFFSET G_GINT64_CONSTANT(3000000000)
289 #define DEFAULT_VERSION GST_RTSP_VERSION_1_0
290 #define DEFAULT_BACKCHANNEL GST_RTSP_BACKCHANNEL_NONE
291 #define DEFAULT_TEARDOWN_TIMEOUT (100 * GST_MSECOND)
292 #define DEFAULT_ONVIF_MODE FALSE
293 #define DEFAULT_ONVIF_RATE_CONTROL TRUE
294 #define DEFAULT_IS_LIVE TRUE
306 PROP_DROP_ON_LATENCY,
307 PROP_CONNECTION_SPEED,
310 PROP_DO_RTSP_KEEP_ALIVE,
319 PROP_UDP_BUFFER_SIZE,
323 PROP_MULTICAST_IFACE,
325 PROP_USE_PIPELINE_CLOCK,
327 PROP_TLS_VALIDATION_FLAGS,
329 PROP_TLS_INTERACTION,
330 PROP_DO_RETRANSMISSION,
331 PROP_NTP_TIME_SOURCE,
333 PROP_MAX_RTCP_RTP_TIME_DIFF,
335 PROP_MAX_TS_OFFSET_ADJUSTMENT,
337 PROP_DEFAULT_VERSION,
339 PROP_TEARDOWN_TIMEOUT,
341 PROP_ONVIF_RATE_CONTROL,
345 #define GST_TYPE_RTSP_NAT_METHOD (gst_rtsp_nat_method_get_type())
347 gst_rtsp_nat_method_get_type (void)
349 static GType rtsp_nat_method_type = 0;
350 static const GEnumValue rtsp_nat_method[] = {
351 {GST_RTSP_NAT_NONE, "None", "none"},
352 {GST_RTSP_NAT_DUMMY, "Send Dummy packets", "dummy"},
356 if (!rtsp_nat_method_type) {
357 rtsp_nat_method_type =
358 g_enum_register_static ("GstRTSPNatMethod", rtsp_nat_method);
360 return rtsp_nat_method_type;
363 #define RTSP_SRC_RESPONSE_ERROR(src, response_msg, err_cat, err_code, error_message) \
365 GST_ELEMENT_ERROR_WITH_DETAILS((src), err_cat, err_code, ("%s", error_message), \
366 ("%s (%d)", (response_msg)->type_data.response.reason, (response_msg)->type_data.response.code), \
367 ("rtsp-status-code", G_TYPE_UINT, (response_msg)->type_data.response.code, \
368 "rtsp-status-reason", G_TYPE_STRING, GST_STR_NULL((response_msg)->type_data.response.reason), NULL)); \
371 typedef struct _ParameterRequest
379 static void gst_rtspsrc_finalize (GObject * object);
381 static void gst_rtspsrc_set_property (GObject * object, guint prop_id,
382 const GValue * value, GParamSpec * pspec);
383 static void gst_rtspsrc_get_property (GObject * object, guint prop_id,
384 GValue * value, GParamSpec * pspec);
386 static GstClock *gst_rtspsrc_provide_clock (GstElement * element);
388 static void gst_rtspsrc_uri_handler_init (gpointer g_iface,
389 gpointer iface_data);
391 static gboolean gst_rtspsrc_set_proxy (GstRTSPSrc * rtsp, const gchar * proxy);
392 static void gst_rtspsrc_set_tcp_timeout (GstRTSPSrc * rtspsrc, guint64 timeout);
394 static GstStateChangeReturn gst_rtspsrc_change_state (GstElement * element,
395 GstStateChange transition);
396 static gboolean gst_rtspsrc_send_event (GstElement * element, GstEvent * event);
397 static void gst_rtspsrc_handle_message (GstBin * bin, GstMessage * message);
399 static gboolean gst_rtspsrc_setup_auth (GstRTSPSrc * src,
400 GstRTSPMessage * response);
402 static gboolean gst_rtspsrc_loop_send_cmd (GstRTSPSrc * src, gint cmd,
404 static GstRTSPResult gst_rtspsrc_send_cb (GstRTSPExtension * ext,
405 GstRTSPMessage * request, GstRTSPMessage * response, GstRTSPSrc * src);
407 static GstRTSPResult gst_rtspsrc_open (GstRTSPSrc * src, gboolean async);
408 static GstRTSPResult gst_rtspsrc_play (GstRTSPSrc * src, GstSegment * segment,
409 gboolean async, const gchar * seek_style);
410 static GstRTSPResult gst_rtspsrc_pause (GstRTSPSrc * src, gboolean async);
411 static GstRTSPResult gst_rtspsrc_close (GstRTSPSrc * src, gboolean async,
412 gboolean only_close);
414 static gboolean gst_rtspsrc_uri_set_uri (GstURIHandler * handler,
415 const gchar * uri, GError ** error);
416 static gchar *gst_rtspsrc_uri_get_uri (GstURIHandler * handler);
418 static gboolean gst_rtspsrc_activate_streams (GstRTSPSrc * src);
419 static gboolean gst_rtspsrc_loop (GstRTSPSrc * src);
420 static gboolean gst_rtspsrc_stream_push_event (GstRTSPSrc * src,
421 GstRTSPStream * stream, GstEvent * event);
422 static gboolean gst_rtspsrc_push_event (GstRTSPSrc * src, GstEvent * event);
423 static void gst_rtspsrc_connection_flush (GstRTSPSrc * src, gboolean flush);
424 static GstRTSPResult gst_rtsp_conninfo_close (GstRTSPSrc * src,
425 GstRTSPConnInfo * info, gboolean free);
427 gst_rtspsrc_print_rtsp_message (GstRTSPSrc * src, const GstRTSPMessage * msg);
429 gst_rtspsrc_print_sdp_message (GstRTSPSrc * src, const GstSDPMessage * msg);
432 gst_rtspsrc_get_parameter (GstRTSPSrc * src, ParameterRequest * req);
435 gst_rtspsrc_set_parameter (GstRTSPSrc * src, ParameterRequest * req);
437 static gboolean get_parameter (GstRTSPSrc * src, const gchar * parameter,
438 const gchar * content_type, GstPromise * promise);
440 static gboolean get_parameters (GstRTSPSrc * src, gchar ** parameters,
441 const gchar * content_type, GstPromise * promise);
443 static gboolean set_parameter (GstRTSPSrc * src, const gchar * name,
444 const gchar * value, const gchar * content_type, GstPromise * promise);
446 static GstFlowReturn gst_rtspsrc_push_backchannel_buffer (GstRTSPSrc * src,
447 guint id, GstSample * sample);
455 /* commands we send to out loop to notify it of events */
456 #define CMD_OPEN (1 << 0)
457 #define CMD_PLAY (1 << 1)
458 #define CMD_PAUSE (1 << 2)
459 #define CMD_CLOSE (1 << 3)
460 #define CMD_WAIT (1 << 4)
461 #define CMD_RECONNECT (1 << 5)
462 #define CMD_LOOP (1 << 6)
463 #define CMD_GET_PARAMETER (1 << 7)
464 #define CMD_SET_PARAMETER (1 << 8)
466 /* mask for all commands */
467 #define CMD_ALL ((CMD_SET_PARAMETER << 1) - 1)
469 #define GST_ELEMENT_PROGRESS(el, type, code, text) \
471 gchar *__txt = _gst_element_error_printf text; \
472 gst_element_post_message (GST_ELEMENT_CAST (el), \
473 gst_message_new_progress (GST_OBJECT_CAST (el), \
474 GST_PROGRESS_TYPE_ ##type, code, __txt)); \
478 static guint gst_rtspsrc_signals[LAST_SIGNAL] = { 0 };
480 #define gst_rtspsrc_parent_class parent_class
481 G_DEFINE_TYPE_WITH_CODE (GstRTSPSrc, gst_rtspsrc, GST_TYPE_BIN,
482 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_rtspsrc_uri_handler_init));
483 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtspsrc, "rtspsrc", GST_RANK_NONE,
484 GST_TYPE_RTSPSRC, rtsp_element_init (plugin));
486 #ifndef GST_DISABLE_GST_DEBUG
487 static inline const char *
488 cmd_to_string (guint cmd)
505 case CMD_GET_PARAMETER:
506 return "GET_PARAMETER";
507 case CMD_SET_PARAMETER:
508 return "SET_PARAMETER";
516 default_select_stream (GstRTSPSrc * src, guint id, GstCaps * caps)
518 GST_DEBUG_OBJECT (src, "default handler");
523 select_stream_accum (GSignalInvocationHint * ihint,
524 GValue * return_accu, const GValue * handler_return, gpointer data)
528 myboolean = g_value_get_boolean (handler_return);
529 GST_DEBUG ("accum %d", myboolean);
530 g_value_set_boolean (return_accu, myboolean);
532 /* stop emission if FALSE */
537 default_before_send (GstRTSPSrc * src, GstRTSPMessage * msg)
539 GST_DEBUG_OBJECT (src, "default handler");
544 before_send_accum (GSignalInvocationHint * ihint,
545 GValue * return_accu, const GValue * handler_return, gpointer data)
549 myboolean = g_value_get_boolean (handler_return);
550 g_value_set_boolean (return_accu, myboolean);
552 /* prevent send if FALSE */
557 gst_rtspsrc_class_init (GstRTSPSrcClass * klass)
559 GObjectClass *gobject_class;
560 GstElementClass *gstelement_class;
561 GstBinClass *gstbin_class;
563 gobject_class = (GObjectClass *) klass;
564 gstelement_class = (GstElementClass *) klass;
565 gstbin_class = (GstBinClass *) klass;
567 GST_DEBUG_CATEGORY_INIT (rtspsrc_debug, "rtspsrc", 0, "RTSP src");
569 gobject_class->set_property = gst_rtspsrc_set_property;
570 gobject_class->get_property = gst_rtspsrc_get_property;
572 gobject_class->finalize = gst_rtspsrc_finalize;
574 g_object_class_install_property (gobject_class, PROP_LOCATION,
575 g_param_spec_string ("location", "RTSP Location",
576 "Location of the RTSP url to read",
577 DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
579 g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
580 g_param_spec_flags ("protocols", "Protocols",
581 "Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
582 DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
584 g_object_class_install_property (gobject_class, PROP_DEBUG,
585 g_param_spec_boolean ("debug", "Debug",
586 "Dump request and response messages to stdout"
587 "(DEPRECATED: Printed all RTSP message to gstreamer log as 'log' level)",
589 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
591 g_object_class_install_property (gobject_class, PROP_RETRY,
592 g_param_spec_uint ("retry", "Retry",
593 "Max number of retries when allocating RTP ports.",
594 0, G_MAXUINT16, DEFAULT_RETRY,
595 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
597 g_object_class_install_property (gobject_class, PROP_TIMEOUT,
598 g_param_spec_uint64 ("timeout", "Timeout",
599 "Retry TCP transport after UDP timeout microseconds (0 = disabled)",
600 0, G_MAXUINT64, DEFAULT_TIMEOUT,
601 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
603 g_object_class_install_property (gobject_class, PROP_TCP_TIMEOUT,
604 g_param_spec_uint64 ("tcp-timeout", "TCP Timeout",
605 "Fail after timeout microseconds on TCP connections (0 = disabled)",
606 0, G_MAXUINT64, DEFAULT_TCP_TIMEOUT,
607 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
609 g_object_class_install_property (gobject_class, PROP_LATENCY,
610 g_param_spec_uint ("latency", "Buffer latency in ms",
611 "Amount of ms to buffer", 0, G_MAXUINT, DEFAULT_LATENCY_MS,
612 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
614 g_object_class_install_property (gobject_class, PROP_DROP_ON_LATENCY,
615 g_param_spec_boolean ("drop-on-latency",
616 "Drop buffers when maximum latency is reached",
617 "Tells the jitterbuffer to never exceed the given latency in size",
618 DEFAULT_DROP_ON_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
620 g_object_class_install_property (gobject_class, PROP_CONNECTION_SPEED,
621 g_param_spec_uint64 ("connection-speed", "Connection Speed",
622 "Network connection speed in kbps (0 = unknown)",
623 0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
624 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
626 g_object_class_install_property (gobject_class, PROP_NAT_METHOD,
627 g_param_spec_enum ("nat-method", "NAT Method",
628 "Method to use for traversing firewalls and NAT",
629 GST_TYPE_RTSP_NAT_METHOD, DEFAULT_NAT_METHOD,
630 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
633 * GstRTSPSrc:do-rtcp:
635 * Enable RTCP support. Some old server don't like RTCP and then this property
636 * needs to be set to FALSE.
638 g_object_class_install_property (gobject_class, PROP_DO_RTCP,
639 g_param_spec_boolean ("do-rtcp", "Do RTCP",
640 "Send RTCP packets, disable for old incompatible server.",
641 DEFAULT_DO_RTCP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
644 * GstRTSPSrc:do-rtsp-keep-alive:
646 * Enable RTSP keep alive support. Some old server don't like RTSP
647 * keep alive and then this property needs to be set to FALSE.
649 g_object_class_install_property (gobject_class, PROP_DO_RTSP_KEEP_ALIVE,
650 g_param_spec_boolean ("do-rtsp-keep-alive", "Do RTSP Keep Alive",
651 "Send RTSP keep alive packets, disable for old incompatible server.",
652 DEFAULT_DO_RTSP_KEEP_ALIVE,
653 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
658 * Set the proxy parameters. This has to be a string of the format
659 * [http://][user:passwd@]host[:port].
661 g_object_class_install_property (gobject_class, PROP_PROXY,
662 g_param_spec_string ("proxy", "Proxy",
663 "Proxy settings for HTTP tunneling. Format: [http://][user:passwd@]host[:port]",
664 DEFAULT_PROXY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
666 * GstRTSPSrc:proxy-id:
668 * Sets the proxy URI user id for authentication. If the URI set via the
669 * "proxy" property contains a user-id already, that will take precedence.
673 g_object_class_install_property (gobject_class, PROP_PROXY_ID,
674 g_param_spec_string ("proxy-id", "proxy-id",
675 "HTTP proxy URI user id for authentication", "",
676 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
678 * GstRTSPSrc:proxy-pw:
680 * Sets the proxy URI password for authentication. If the URI set via the
681 * "proxy" property contains a password already, that will take precedence.
685 g_object_class_install_property (gobject_class, PROP_PROXY_PW,
686 g_param_spec_string ("proxy-pw", "proxy-pw",
687 "HTTP proxy URI user password for authentication", "",
688 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
691 * GstRTSPSrc:rtp-blocksize:
693 * RTP package size to suggest to server.
695 g_object_class_install_property (gobject_class, PROP_RTP_BLOCKSIZE,
696 g_param_spec_uint ("rtp-blocksize", "RTP Blocksize",
697 "RTP package size to suggest to server (0 = disabled)",
698 0, 65536, DEFAULT_RTP_BLOCKSIZE,
699 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
701 g_object_class_install_property (gobject_class,
703 g_param_spec_string ("user-id", "user-id",
704 "RTSP location URI user id for authentication", DEFAULT_USER_ID,
705 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
706 g_object_class_install_property (gobject_class, PROP_USER_PW,
707 g_param_spec_string ("user-pw", "user-pw",
708 "RTSP location URI user password for authentication", DEFAULT_USER_PW,
709 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
712 * GstRTSPSrc:buffer-mode:
714 * Control the buffering and timestamping mode used by the jitterbuffer.
716 g_object_class_install_property (gobject_class, PROP_BUFFER_MODE,
717 g_param_spec_enum ("buffer-mode", "Buffer Mode",
718 "Control the buffering algorithm in use",
719 GST_TYPE_RTSP_SRC_BUFFER_MODE, DEFAULT_BUFFER_MODE,
720 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
723 * GstRTSPSrc:port-range:
725 * Configure the client port numbers that can be used to receive RTP and
728 g_object_class_install_property (gobject_class, PROP_PORT_RANGE,
729 g_param_spec_string ("port-range", "Port range",
730 "Client port range that can be used to receive RTP and RTCP data, "
731 "eg. 3000-3005 (NULL = no restrictions)", DEFAULT_PORT_RANGE,
732 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
735 * GstRTSPSrc:udp-buffer-size:
737 * Size of the kernel UDP receive buffer in bytes.
739 g_object_class_install_property (gobject_class, PROP_UDP_BUFFER_SIZE,
740 g_param_spec_int ("udp-buffer-size", "UDP Buffer Size",
741 "Size of the kernel UDP receive buffer in bytes, 0=default",
742 0, G_MAXINT, DEFAULT_UDP_BUFFER_SIZE,
743 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
746 * GstRTSPSrc:short-header:
748 * Only send the basic RTSP headers for broken encoders.
750 g_object_class_install_property (gobject_class, PROP_SHORT_HEADER,
751 g_param_spec_boolean ("short-header", "Short Header",
752 "Only send the basic RTSP headers for broken encoders",
753 DEFAULT_SHORT_HEADER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
755 g_object_class_install_property (gobject_class, PROP_PROBATION,
756 g_param_spec_uint ("probation", "Number of probations",
757 "Consecutive packet sequence numbers to accept the source",
758 0, G_MAXUINT, DEFAULT_PROBATION,
759 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
761 g_object_class_install_property (gobject_class, PROP_UDP_RECONNECT,
762 g_param_spec_boolean ("udp-reconnect", "Reconnect to the server",
763 "Reconnect to the server if RTSP connection is closed when doing UDP",
764 DEFAULT_UDP_RECONNECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
766 g_object_class_install_property (gobject_class, PROP_MULTICAST_IFACE,
767 g_param_spec_string ("multicast-iface", "Multicast Interface",
768 "The network interface on which to join the multicast group",
769 DEFAULT_MULTICAST_IFACE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
771 g_object_class_install_property (gobject_class, PROP_NTP_SYNC,
772 g_param_spec_boolean ("ntp-sync", "Sync on NTP clock",
773 "Synchronize received streams to the NTP clock", DEFAULT_NTP_SYNC,
774 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
776 g_object_class_install_property (gobject_class, PROP_USE_PIPELINE_CLOCK,
777 g_param_spec_boolean ("use-pipeline-clock", "Use pipeline clock",
778 "Use the pipeline running-time to set the NTP time in the RTCP SR messages"
779 "(DEPRECATED: Use ntp-time-source property)",
780 DEFAULT_USE_PIPELINE_CLOCK,
781 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_DEPRECATED));
783 g_object_class_install_property (gobject_class, PROP_SDES,
784 g_param_spec_boxed ("sdes", "SDES",
785 "The SDES items of this session",
786 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
789 * GstRTSPSrc::tls-validation-flags:
791 * TLS certificate validation flags used to validate server
796 g_object_class_install_property (gobject_class, PROP_TLS_VALIDATION_FLAGS,
797 g_param_spec_flags ("tls-validation-flags", "TLS validation flags",
798 "TLS certificate validation flags used to validate the server certificate",
799 G_TYPE_TLS_CERTIFICATE_FLAGS, DEFAULT_TLS_VALIDATION_FLAGS,
800 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
803 * GstRTSPSrc::tls-database:
805 * TLS database with anchor certificate authorities used to validate
806 * the server certificate.
810 g_object_class_install_property (gobject_class, PROP_TLS_DATABASE,
811 g_param_spec_object ("tls-database", "TLS database",
812 "TLS database with anchor certificate authorities used to validate the server certificate",
813 G_TYPE_TLS_DATABASE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
816 * GstRTSPSrc::tls-interaction:
818 * A #GTlsInteraction object to be used when the connection or certificate
819 * database need to interact with the user. This will be used to prompt the
820 * user for passwords where necessary.
824 g_object_class_install_property (gobject_class, PROP_TLS_INTERACTION,
825 g_param_spec_object ("tls-interaction", "TLS interaction",
826 "A GTlsInteraction object to prompt the user for password or certificate",
827 G_TYPE_TLS_INTERACTION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
830 * GstRTSPSrc::do-retransmission:
832 * Attempt to ask the server to retransmit lost packets according to RFC4588.
834 * Note: currently only works with SSRC-multiplexed retransmission streams
838 g_object_class_install_property (gobject_class, PROP_DO_RETRANSMISSION,
839 g_param_spec_boolean ("do-retransmission", "Retransmission",
840 "Ask the server to retransmit lost packets",
841 DEFAULT_DO_RETRANSMISSION,
842 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
845 * GstRTSPSrc::ntp-time-source:
847 * allows to select the time source that should be used
848 * for the NTP time in RTCP packets
852 g_object_class_install_property (gobject_class, PROP_NTP_TIME_SOURCE,
853 g_param_spec_enum ("ntp-time-source", "NTP Time Source",
854 "NTP time source for RTCP packets",
855 GST_TYPE_RTSP_SRC_NTP_TIME_SOURCE, DEFAULT_NTP_TIME_SOURCE,
856 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
859 * GstRTSPSrc::user-agent:
861 * The string to set in the User-Agent header.
865 g_object_class_install_property (gobject_class, PROP_USER_AGENT,
866 g_param_spec_string ("user-agent", "User Agent",
867 "The User-Agent string to send to the server",
868 DEFAULT_USER_AGENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
870 g_object_class_install_property (gobject_class, PROP_MAX_RTCP_RTP_TIME_DIFF,
871 g_param_spec_int ("max-rtcp-rtp-time-diff", "Max RTCP RTP Time Diff",
872 "Maximum amount of time in ms that the RTP time in RTCP SRs "
873 "is allowed to be ahead (-1 disabled)", -1, G_MAXINT,
874 DEFAULT_MAX_RTCP_RTP_TIME_DIFF,
875 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
877 g_object_class_install_property (gobject_class, PROP_RFC7273_SYNC,
878 g_param_spec_boolean ("rfc7273-sync", "Sync on RFC7273 clock",
879 "Synchronize received streams to the RFC7273 clock "
880 "(requires clock and offset to be provided)", DEFAULT_RFC7273_SYNC,
881 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
884 * GstRTSPSrc:default-rtsp-version:
886 * The preferred RTSP version to use while negotiating the version with the server.
890 g_object_class_install_property (gobject_class, PROP_DEFAULT_VERSION,
891 g_param_spec_enum ("default-rtsp-version",
892 "The RTSP version to try first",
893 "The RTSP version that should be tried first when negotiating version.",
894 GST_TYPE_RTSP_VERSION, DEFAULT_VERSION,
895 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
898 * GstRTSPSrc:max-ts-offset-adjustment:
900 * Syncing time stamps to NTP time adds a time offset. This parameter
901 * specifies the maximum number of nanoseconds per frame that this time offset
902 * may be adjusted with. This is used to avoid sudden large changes to time
905 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET_ADJUSTMENT,
906 g_param_spec_uint64 ("max-ts-offset-adjustment",
907 "Max Timestamp Offset Adjustment",
908 "The maximum number of nanoseconds per frame that time stamp offsets "
909 "may be adjusted (0 = no limit).", 0, G_MAXUINT64,
910 DEFAULT_MAX_TS_OFFSET_ADJUSTMENT, G_PARAM_READWRITE |
911 G_PARAM_STATIC_STRINGS));
914 * GstRTSPSrc:max-ts-offset:
916 * Used to set an upper limit of how large a time offset may be. This
917 * is used to protect against unrealistic values as a result of either
918 * client,server or clock issues.
920 g_object_class_install_property (gobject_class, PROP_MAX_TS_OFFSET,
921 g_param_spec_int64 ("max-ts-offset", "Max TS Offset",
922 "The maximum absolute value of the time offset in (nanoseconds). "
923 "Note, if the ntp-sync parameter is set the default value is "
924 "changed to 0 (no limit)", 0, G_MAXINT64, DEFAULT_MAX_TS_OFFSET,
925 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
928 * GstRTSPSrc:backchannel
930 * Select a type of backchannel to setup with the RTSP server.
931 * Default value is "none". Allowed values are "none" and "onvif".
935 g_object_class_install_property (gobject_class, PROP_BACKCHANNEL,
936 g_param_spec_enum ("backchannel", "Backchannel type",
937 "The type of backchannel to setup. Default is 'none'.",
938 GST_TYPE_RTSP_BACKCHANNEL, BACKCHANNEL_NONE,
939 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
942 * GstRTSPSrc:teardown-timeout
944 * When transitioning PAUSED-READY, allow up to timeout (in nanoseconds)
945 * delay in order to send teardown (0 = disabled)
949 g_object_class_install_property (gobject_class, PROP_TEARDOWN_TIMEOUT,
950 g_param_spec_uint64 ("teardown-timeout", "Teardown Timeout",
951 "When transitioning PAUSED-READY, allow up to timeout (in nanoseconds) "
952 "delay in order to send teardown (0 = disabled)",
953 0, G_MAXUINT64, DEFAULT_TEARDOWN_TIMEOUT,
954 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
957 * GstRTSPSrc:onvif-mode
959 * Act as an ONVIF client. When set to %TRUE:
961 * - seeks will be interpreted as nanoseconds since prime epoch (1900-01-01)
963 * - #GstRTSPSrc:onvif-rate-control can be used to request that the server sends
964 * data as fast as it can
966 * - TCP is picked as the transport protocol
968 * - Trickmode flags in seek events are transformed into the appropriate ONVIF
973 g_object_class_install_property (gobject_class, PROP_ONVIF_MODE,
974 g_param_spec_boolean ("onvif-mode", "Onvif Mode",
975 "Act as an ONVIF client",
976 DEFAULT_ONVIF_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
979 * GstRTSPSrc:onvif-rate-control
981 * When in onvif-mode, whether to set Rate-Control to yes or no. When set
982 * to %FALSE, the server will deliver data as fast as the client can consume
987 g_object_class_install_property (gobject_class, PROP_ONVIF_RATE_CONTROL,
988 g_param_spec_boolean ("onvif-rate-control", "Onvif Rate Control",
989 "When in onvif-mode, whether to set Rate-Control to yes or no",
990 DEFAULT_ONVIF_RATE_CONTROL,
991 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
996 * Whether to act as a live source. This is useful in combination with
997 * #GstRTSPSrc:onvif-rate-control set to %FALSE and usage of the TCP
998 * protocol. In that situation, data delivery rate can be entirely
999 * controlled from the client side, enabling features such as frame
1000 * stepping and instantaneous rate changes.
1004 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
1005 g_param_spec_boolean ("is-live", "Is live",
1006 "Whether to act as a live source",
1007 DEFAULT_IS_LIVE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1010 * GstRTSPSrc::handle-request:
1011 * @rtspsrc: a #GstRTSPSrc
1012 * @request: a #GstRTSPMessage
1013 * @response: a #GstRTSPMessage
1015 * Handle a server request in @request and prepare @response.
1017 * This signal is called from the streaming thread, you should therefore not
1018 * do any state changes on @rtspsrc because this might deadlock. If you want
1019 * to modify the state as a result of this signal, post a
1020 * #GST_MESSAGE_REQUEST_STATE message on the bus or signal the main thread
1021 * in some other way.
1025 gst_rtspsrc_signals[SIGNAL_HANDLE_REQUEST] =
1026 g_signal_new ("handle-request", G_TYPE_FROM_CLASS (klass), 0,
1027 0, NULL, NULL, NULL, G_TYPE_NONE, 2,
1028 GST_TYPE_RTSP_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE,
1029 GST_TYPE_RTSP_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE);
1032 * GstRTSPSrc::on-sdp:
1033 * @rtspsrc: a #GstRTSPSrc
1034 * @sdp: a #GstSDPMessage
1036 * Emitted when the client has retrieved the SDP and before it configures the
1037 * streams in the SDP. @sdp can be inspected and modified.
1039 * This signal is called from the streaming thread, you should therefore not
1040 * do any state changes on @rtspsrc because this might deadlock. If you want
1041 * to modify the state as a result of this signal, post a
1042 * #GST_MESSAGE_REQUEST_STATE message on the bus or signal the main thread
1043 * in some other way.
1047 gst_rtspsrc_signals[SIGNAL_ON_SDP] =
1048 g_signal_new ("on-sdp", G_TYPE_FROM_CLASS (klass), 0,
1049 0, NULL, NULL, NULL, G_TYPE_NONE, 1,
1050 GST_TYPE_SDP_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE);
1053 * GstRTSPSrc::select-stream:
1054 * @rtspsrc: a #GstRTSPSrc
1055 * @num: the stream number
1056 * @caps: the stream caps
1058 * Emitted before the client decides to configure the stream @num with
1061 * Returns: %TRUE when the stream should be selected, %FALSE when the stream
1066 gst_rtspsrc_signals[SIGNAL_SELECT_STREAM] =
1067 g_signal_new_class_handler ("select-stream", G_TYPE_FROM_CLASS (klass),
1069 (GCallback) default_select_stream, select_stream_accum, NULL, NULL,
1070 G_TYPE_BOOLEAN, 2, G_TYPE_UINT, GST_TYPE_CAPS);
1072 * GstRTSPSrc::new-manager:
1073 * @rtspsrc: a #GstRTSPSrc
1074 * @manager: a #GstElement
1076 * Emitted after a new manager (like rtpbin) was created and the default
1077 * properties were configured.
1081 gst_rtspsrc_signals[SIGNAL_NEW_MANAGER] =
1082 g_signal_new_class_handler ("new-manager", G_TYPE_FROM_CLASS (klass),
1083 0, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
1086 * GstRTSPSrc::request-rtcp-key:
1087 * @rtspsrc: a #GstRTSPSrc
1088 * @num: the stream number
1090 * Signal emitted to get the crypto parameters relevant to the RTCP
1091 * stream. User should provide the key and the RTCP encryption ciphers
1092 * and authentication, and return them wrapped in a GstCaps.
1096 gst_rtspsrc_signals[SIGNAL_REQUEST_RTCP_KEY] =
1097 g_signal_new ("request-rtcp-key", G_TYPE_FROM_CLASS (klass),
1098 0, 0, NULL, NULL, NULL, GST_TYPE_CAPS, 1, G_TYPE_UINT);
1101 * GstRTSPSrc::accept-certificate:
1102 * @rtspsrc: a #GstRTSPSrc
1103 * @peer_cert: the peer's #GTlsCertificate
1104 * @errors: the problems with @peer_cert
1105 * @user_data: user data set when the signal handler was connected.
1107 * This will directly map to #GTlsConnection 's "accept-certificate"
1108 * signal and be performed after the default checks of #GstRTSPConnection
1109 * (checking against the #GTlsDatabase with the given #GTlsCertificateFlags)
1110 * have failed. If no #GTlsDatabase is set on this connection, only this
1111 * signal will be emitted.
1115 gst_rtspsrc_signals[SIGNAL_ACCEPT_CERTIFICATE] =
1116 g_signal_new ("accept-certificate", G_TYPE_FROM_CLASS (klass),
1117 G_SIGNAL_RUN_LAST, 0, g_signal_accumulator_true_handled, NULL, NULL,
1118 G_TYPE_BOOLEAN, 3, G_TYPE_TLS_CONNECTION, G_TYPE_TLS_CERTIFICATE,
1119 G_TYPE_TLS_CERTIFICATE_FLAGS);
1122 * GstRTSPSrc::before-send:
1123 * @rtspsrc: a #GstRTSPSrc
1124 * @num: the stream number
1126 * Emitted before each RTSP request is sent, in order to allow
1127 * the application to modify send parameters or to skip the message entirely.
1128 * This can be used, for example, to work with ONVIF Profile G servers,
1129 * which need a different/additional range, rate-control, and intra/x
1132 * Returns: %TRUE when the command should be sent, %FALSE when the
1133 * command should be dropped.
1137 gst_rtspsrc_signals[SIGNAL_BEFORE_SEND] =
1138 g_signal_new_class_handler ("before-send", G_TYPE_FROM_CLASS (klass),
1140 (GCallback) default_before_send, before_send_accum, NULL, NULL,
1141 G_TYPE_BOOLEAN, 1, GST_TYPE_RTSP_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE);
1144 * GstRTSPSrc::push-backchannel-buffer:
1145 * @rtspsrc: a #GstRTSPSrc
1146 * @sample: RTP sample to send back
1150 gst_rtspsrc_signals[SIGNAL_PUSH_BACKCHANNEL_BUFFER] =
1151 g_signal_new ("push-backchannel-buffer", G_TYPE_FROM_CLASS (klass),
1152 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRTSPSrcClass,
1153 push_backchannel_buffer), NULL, NULL, NULL,
1154 GST_TYPE_FLOW_RETURN, 2, G_TYPE_UINT, GST_TYPE_SAMPLE);
1157 * GstRTSPSrc::get-parameter:
1158 * @rtspsrc: a #GstRTSPSrc
1159 * @parameter: the parameter name
1160 * @parameter: the content type
1161 * @parameter: a pointer to #GstPromise
1163 * Handle the GET_PARAMETER signal.
1165 * Returns: %TRUE when the command could be issued, %FALSE otherwise
1168 gst_rtspsrc_signals[SIGNAL_GET_PARAMETER] =
1169 g_signal_new ("get-parameter", G_TYPE_FROM_CLASS (klass),
1170 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRTSPSrcClass,
1171 get_parameter), NULL, NULL, NULL,
1172 G_TYPE_BOOLEAN, 3, G_TYPE_STRING, G_TYPE_STRING, GST_TYPE_PROMISE);
1175 * GstRTSPSrc::get-parameters:
1176 * @rtspsrc: a #GstRTSPSrc
1177 * @parameter: a NULL-terminated array of parameters
1178 * @parameter: the content type
1179 * @parameter: a pointer to #GstPromise
1181 * Handle the GET_PARAMETERS signal.
1183 * Returns: %TRUE when the command could be issued, %FALSE otherwise
1186 gst_rtspsrc_signals[SIGNAL_GET_PARAMETERS] =
1187 g_signal_new ("get-parameters", G_TYPE_FROM_CLASS (klass),
1188 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRTSPSrcClass,
1189 get_parameters), NULL, NULL, NULL,
1190 G_TYPE_BOOLEAN, 3, G_TYPE_STRV, G_TYPE_STRING, GST_TYPE_PROMISE);
1193 * GstRTSPSrc::set-parameter:
1194 * @rtspsrc: a #GstRTSPSrc
1195 * @parameter: the parameter name
1196 * @parameter: the parameter value
1197 * @parameter: the content type
1198 * @parameter: a pointer to #GstPromise
1200 * Handle the SET_PARAMETER signal.
1202 * Returns: %TRUE when the command could be issued, %FALSE otherwise
1205 gst_rtspsrc_signals[SIGNAL_SET_PARAMETER] =
1206 g_signal_new ("set-parameter", G_TYPE_FROM_CLASS (klass),
1207 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRTSPSrcClass,
1208 set_parameter), NULL, NULL, NULL, G_TYPE_BOOLEAN, 4, G_TYPE_STRING,
1209 G_TYPE_STRING, G_TYPE_STRING, GST_TYPE_PROMISE);
1211 gstelement_class->send_event = gst_rtspsrc_send_event;
1212 gstelement_class->provide_clock = gst_rtspsrc_provide_clock;
1213 gstelement_class->change_state = gst_rtspsrc_change_state;
1215 gst_element_class_add_static_pad_template (gstelement_class, &rtptemplate);
1217 gst_element_class_set_static_metadata (gstelement_class,
1218 "RTSP packet receiver", "Source/Network",
1219 "Receive data over the network via RTSP (RFC 2326)",
1220 "Wim Taymans <wim@fluendo.com>, "
1221 "Thijs Vermeir <thijs.vermeir@barco.com>, "
1222 "Lutz Mueller <lutz@topfrose.de>");
1224 gstbin_class->handle_message = gst_rtspsrc_handle_message;
1226 klass->push_backchannel_buffer = gst_rtspsrc_push_backchannel_buffer;
1227 klass->get_parameter = GST_DEBUG_FUNCPTR (get_parameter);
1228 klass->get_parameters = GST_DEBUG_FUNCPTR (get_parameters);
1229 klass->set_parameter = GST_DEBUG_FUNCPTR (set_parameter);
1231 gst_rtsp_ext_list_init ();
1233 gst_type_mark_as_plugin_api (GST_TYPE_RTSP_SRC_BUFFER_MODE, 0);
1234 gst_type_mark_as_plugin_api (GST_TYPE_RTSP_SRC_NTP_TIME_SOURCE, 0);
1235 gst_type_mark_as_plugin_api (GST_TYPE_RTSP_BACKCHANNEL, 0);
1236 gst_type_mark_as_plugin_api (GST_TYPE_RTSP_NAT_METHOD, 0);
1240 validate_set_get_parameter_name (const gchar * parameter_name)
1242 gchar *ptr = (gchar *) parameter_name;
1245 /* Don't allow '\r', '\n', \'t', ' ' etc in the parameter name */
1246 if (g_ascii_isspace (*ptr) || g_ascii_iscntrl (*ptr)) {
1247 GST_DEBUG ("invalid parameter name '%s'", parameter_name);
1256 validate_set_get_parameters (gchar ** parameter_names)
1258 while (*parameter_names) {
1259 if (!validate_set_get_parameter_name (*parameter_names)) {
1268 get_parameter (GstRTSPSrc * src, const gchar * parameter,
1269 const gchar * content_type, GstPromise * promise)
1271 gchar *parameters[] = { (gchar *) parameter, NULL };
1273 GST_LOG_OBJECT (src, "get_parameter: %s", GST_STR_NULL (parameter));
1275 if (parameter == NULL || parameter[0] == '\0' || promise == NULL) {
1276 GST_DEBUG ("invalid input");
1280 return get_parameters (src, parameters, content_type, promise);
1284 get_parameters (GstRTSPSrc * src, gchar ** parameters,
1285 const gchar * content_type, GstPromise * promise)
1287 ParameterRequest *req;
1289 GST_LOG_OBJECT (src, "get_parameters: %d", g_strv_length (parameters));
1291 if (parameters == NULL || promise == NULL) {
1292 GST_DEBUG ("invalid input");
1296 if (src->state == GST_RTSP_STATE_INVALID) {
1297 GST_DEBUG ("invalid state");
1301 if (!validate_set_get_parameters (parameters)) {
1305 req = g_new0 (ParameterRequest, 1);
1306 req->promise = gst_promise_ref (promise);
1307 req->cmd = CMD_GET_PARAMETER;
1308 /* Set the request body according to RFC 2326 or RFC 7826 */
1309 req->body = g_string_new (NULL);
1310 while (*parameters) {
1311 g_string_append_printf (req->body, "%s:\r\n", *parameters);
1315 req->content_type = g_strdup (content_type);
1317 GST_OBJECT_LOCK (src);
1318 g_queue_push_tail (&src->set_get_param_q, req);
1319 GST_OBJECT_UNLOCK (src);
1321 gst_rtspsrc_loop_send_cmd (src, CMD_GET_PARAMETER, CMD_LOOP);
1327 set_parameter (GstRTSPSrc * src, const gchar * name, const gchar * value,
1328 const gchar * content_type, GstPromise * promise)
1330 ParameterRequest *req;
1332 GST_LOG_OBJECT (src, "set_parameter: %s: %s", GST_STR_NULL (name),
1333 GST_STR_NULL (value));
1335 if (name == NULL || name[0] == '\0' || value == NULL || promise == NULL) {
1336 GST_DEBUG ("invalid input");
1340 if (src->state == GST_RTSP_STATE_INVALID) {
1341 GST_DEBUG ("invalid state");
1345 if (!validate_set_get_parameter_name (name)) {
1349 req = g_new0 (ParameterRequest, 1);
1350 req->cmd = CMD_SET_PARAMETER;
1351 req->promise = gst_promise_ref (promise);
1352 req->body = g_string_new (NULL);
1353 /* Set the request body according to RFC 2326 or RFC 7826 */
1354 g_string_append_printf (req->body, "%s: %s\r\n", name, value);
1356 req->content_type = g_strdup (content_type);
1358 GST_OBJECT_LOCK (src);
1359 g_queue_push_tail (&src->set_get_param_q, req);
1360 GST_OBJECT_UNLOCK (src);
1362 gst_rtspsrc_loop_send_cmd (src, CMD_SET_PARAMETER, CMD_LOOP);
1368 gst_rtspsrc_init (GstRTSPSrc * src)
1370 src->conninfo.location = g_strdup (DEFAULT_LOCATION);
1371 src->protocols = DEFAULT_PROTOCOLS;
1372 src->debug = DEFAULT_DEBUG;
1373 src->retry = DEFAULT_RETRY;
1374 src->udp_timeout = DEFAULT_TIMEOUT;
1375 gst_rtspsrc_set_tcp_timeout (src, DEFAULT_TCP_TIMEOUT);
1376 src->latency = DEFAULT_LATENCY_MS;
1377 src->drop_on_latency = DEFAULT_DROP_ON_LATENCY;
1378 src->connection_speed = DEFAULT_CONNECTION_SPEED;
1379 src->nat_method = DEFAULT_NAT_METHOD;
1380 src->do_rtcp = DEFAULT_DO_RTCP;
1381 src->do_rtsp_keep_alive = DEFAULT_DO_RTSP_KEEP_ALIVE;
1382 gst_rtspsrc_set_proxy (src, DEFAULT_PROXY);
1383 src->rtp_blocksize = DEFAULT_RTP_BLOCKSIZE;
1384 src->user_id = g_strdup (DEFAULT_USER_ID);
1385 src->user_pw = g_strdup (DEFAULT_USER_PW);
1386 src->buffer_mode = DEFAULT_BUFFER_MODE;
1387 src->client_port_range.min = 0;
1388 src->client_port_range.max = 0;
1389 src->udp_buffer_size = DEFAULT_UDP_BUFFER_SIZE;
1390 src->short_header = DEFAULT_SHORT_HEADER;
1391 src->probation = DEFAULT_PROBATION;
1392 src->udp_reconnect = DEFAULT_UDP_RECONNECT;
1393 src->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
1394 src->ntp_sync = DEFAULT_NTP_SYNC;
1395 src->use_pipeline_clock = DEFAULT_USE_PIPELINE_CLOCK;
1397 src->tls_validation_flags = DEFAULT_TLS_VALIDATION_FLAGS;
1398 src->tls_database = DEFAULT_TLS_DATABASE;
1399 src->tls_interaction = DEFAULT_TLS_INTERACTION;
1400 src->do_retransmission = DEFAULT_DO_RETRANSMISSION;
1401 src->ntp_time_source = DEFAULT_NTP_TIME_SOURCE;
1402 src->user_agent = g_strdup (DEFAULT_USER_AGENT);
1403 src->max_rtcp_rtp_time_diff = DEFAULT_MAX_RTCP_RTP_TIME_DIFF;
1404 src->rfc7273_sync = DEFAULT_RFC7273_SYNC;
1405 src->max_ts_offset_adjustment = DEFAULT_MAX_TS_OFFSET_ADJUSTMENT;
1406 src->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
1407 src->max_ts_offset_is_set = FALSE;
1408 src->default_version = DEFAULT_VERSION;
1409 src->version = GST_RTSP_VERSION_INVALID;
1410 src->teardown_timeout = DEFAULT_TEARDOWN_TIMEOUT;
1411 src->onvif_mode = DEFAULT_ONVIF_MODE;
1412 src->onvif_rate_control = DEFAULT_ONVIF_RATE_CONTROL;
1413 src->is_live = DEFAULT_IS_LIVE;
1414 src->seek_seqnum = GST_SEQNUM_INVALID;
1415 src->group_id = GST_GROUP_ID_INVALID;
1417 /* get a list of all extensions */
1418 src->extensions = gst_rtsp_ext_list_get ();
1420 /* connect to send signal */
1421 gst_rtsp_ext_list_connect (src->extensions, "send",
1422 (GCallback) gst_rtspsrc_send_cb, src);
1424 /* protects the streaming thread in interleaved mode or the polling
1425 * thread in UDP mode. */
1426 g_rec_mutex_init (&src->stream_rec_lock);
1428 /* protects our state changes from multiple invocations */
1429 g_rec_mutex_init (&src->state_rec_lock);
1431 g_queue_init (&src->set_get_param_q);
1433 src->state = GST_RTSP_STATE_INVALID;
1435 g_mutex_init (&src->conninfo.send_lock);
1436 g_mutex_init (&src->conninfo.recv_lock);
1437 g_cond_init (&src->cmd_cond);
1439 g_mutex_init (&src->group_lock);
1441 GST_OBJECT_FLAG_SET (src, GST_ELEMENT_FLAG_SOURCE);
1442 gst_bin_set_suppressed_flags (GST_BIN (src),
1443 GST_ELEMENT_FLAG_SOURCE | GST_ELEMENT_FLAG_SINK);
1447 free_param_data (ParameterRequest * req)
1449 gst_promise_unref (req->promise);
1451 g_string_free (req->body, TRUE);
1452 g_free (req->content_type);
1457 gst_rtspsrc_finalize (GObject * object)
1459 GstRTSPSrc *rtspsrc;
1461 rtspsrc = GST_RTSPSRC (object);
1463 gst_rtsp_ext_list_free (rtspsrc->extensions);
1464 g_free (rtspsrc->conninfo.location);
1465 gst_rtsp_url_free (rtspsrc->conninfo.url);
1466 g_free (rtspsrc->conninfo.url_str);
1467 g_free (rtspsrc->user_id);
1468 g_free (rtspsrc->user_pw);
1469 g_free (rtspsrc->multi_iface);
1470 g_free (rtspsrc->user_agent);
1473 gst_sdp_message_free (rtspsrc->sdp);
1474 rtspsrc->sdp = NULL;
1476 if (rtspsrc->provided_clock)
1477 gst_object_unref (rtspsrc->provided_clock);
1480 gst_structure_free (rtspsrc->sdes);
1482 if (rtspsrc->tls_database)
1483 g_object_unref (rtspsrc->tls_database);
1485 if (rtspsrc->tls_interaction)
1486 g_object_unref (rtspsrc->tls_interaction);
1489 g_rec_mutex_clear (&rtspsrc->stream_rec_lock);
1490 g_rec_mutex_clear (&rtspsrc->state_rec_lock);
1492 g_mutex_clear (&rtspsrc->conninfo.send_lock);
1493 g_mutex_clear (&rtspsrc->conninfo.recv_lock);
1494 g_cond_clear (&rtspsrc->cmd_cond);
1496 g_mutex_clear (&rtspsrc->group_lock);
1498 G_OBJECT_CLASS (parent_class)->finalize (object);
1502 gst_rtspsrc_provide_clock (GstElement * element)
1504 GstRTSPSrc *src = GST_RTSPSRC (element);
1507 if ((clock = src->provided_clock) != NULL)
1508 return gst_object_ref (clock);
1510 return GST_ELEMENT_CLASS (parent_class)->provide_clock (element);
1513 /* a proxy string of the format [user:passwd@]host[:port] */
1515 gst_rtspsrc_set_proxy (GstRTSPSrc * rtsp, const gchar * proxy)
1517 gchar *p, *at, *col;
1519 g_free (rtsp->proxy_user);
1520 rtsp->proxy_user = NULL;
1521 g_free (rtsp->proxy_passwd);
1522 rtsp->proxy_passwd = NULL;
1523 g_free (rtsp->proxy_host);
1524 rtsp->proxy_host = NULL;
1525 rtsp->proxy_port = 0;
1527 p = (gchar *) proxy;
1532 /* we allow http:// in front but ignore it */
1533 if (g_str_has_prefix (p, "http://"))
1536 at = strchr (p, '@');
1538 /* look for user:passwd */
1539 col = strchr (proxy, ':');
1540 if (col == NULL || col > at)
1543 rtsp->proxy_user = g_strndup (p, col - p);
1545 rtsp->proxy_passwd = g_strndup (col, at - col);
1550 if (rtsp->prop_proxy_id != NULL && *rtsp->prop_proxy_id != '\0')
1551 rtsp->proxy_user = g_strdup (rtsp->prop_proxy_id);
1552 if (rtsp->prop_proxy_pw != NULL && *rtsp->prop_proxy_pw != '\0')
1553 rtsp->proxy_passwd = g_strdup (rtsp->prop_proxy_pw);
1554 if (rtsp->proxy_user != NULL || rtsp->proxy_passwd != NULL) {
1555 GST_LOG_OBJECT (rtsp, "set proxy user/pw from properties: %s:%s",
1556 GST_STR_NULL (rtsp->proxy_user), GST_STR_NULL (rtsp->proxy_passwd));
1559 col = strchr (p, ':');
1562 /* everything before the colon is the hostname */
1563 rtsp->proxy_host = g_strndup (p, col - p);
1565 rtsp->proxy_port = strtoul (p, (char **) &p, 10);
1567 rtsp->proxy_host = g_strdup (p);
1568 rtsp->proxy_port = 8080;
1574 gst_rtspsrc_set_tcp_timeout (GstRTSPSrc * rtspsrc, guint64 timeout)
1576 rtspsrc->tcp_timeout = timeout;
1580 gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value,
1583 GstRTSPSrc *rtspsrc;
1585 rtspsrc = GST_RTSPSRC (object);
1589 gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (rtspsrc),
1590 g_value_get_string (value), NULL);
1592 case PROP_PROTOCOLS:
1593 rtspsrc->protocols = g_value_get_flags (value);
1596 rtspsrc->debug = g_value_get_boolean (value);
1599 rtspsrc->retry = g_value_get_uint (value);
1602 rtspsrc->udp_timeout = g_value_get_uint64 (value);
1604 case PROP_TCP_TIMEOUT:
1605 gst_rtspsrc_set_tcp_timeout (rtspsrc, g_value_get_uint64 (value));
1608 rtspsrc->latency = g_value_get_uint (value);
1610 case PROP_DROP_ON_LATENCY:
1611 rtspsrc->drop_on_latency = g_value_get_boolean (value);
1613 case PROP_CONNECTION_SPEED:
1614 rtspsrc->connection_speed = g_value_get_uint64 (value);
1616 case PROP_NAT_METHOD:
1617 rtspsrc->nat_method = g_value_get_enum (value);
1620 rtspsrc->do_rtcp = g_value_get_boolean (value);
1622 case PROP_DO_RTSP_KEEP_ALIVE:
1623 rtspsrc->do_rtsp_keep_alive = g_value_get_boolean (value);
1626 gst_rtspsrc_set_proxy (rtspsrc, g_value_get_string (value));
1629 g_free (rtspsrc->prop_proxy_id);
1630 rtspsrc->prop_proxy_id = g_value_dup_string (value);
1633 g_free (rtspsrc->prop_proxy_pw);
1634 rtspsrc->prop_proxy_pw = g_value_dup_string (value);
1636 case PROP_RTP_BLOCKSIZE:
1637 rtspsrc->rtp_blocksize = g_value_get_uint (value);
1640 g_free (rtspsrc->user_id);
1641 rtspsrc->user_id = g_value_dup_string (value);
1644 g_free (rtspsrc->user_pw);
1645 rtspsrc->user_pw = g_value_dup_string (value);
1647 case PROP_BUFFER_MODE:
1648 rtspsrc->buffer_mode = g_value_get_enum (value);
1650 case PROP_PORT_RANGE:
1654 str = g_value_get_string (value);
1655 if (str == NULL || sscanf (str, "%u-%u", &rtspsrc->client_port_range.min,
1656 &rtspsrc->client_port_range.max) != 2) {
1657 rtspsrc->client_port_range.min = 0;
1658 rtspsrc->client_port_range.max = 0;
1662 case PROP_UDP_BUFFER_SIZE:
1663 rtspsrc->udp_buffer_size = g_value_get_int (value);
1665 case PROP_SHORT_HEADER:
1666 rtspsrc->short_header = g_value_get_boolean (value);
1668 case PROP_PROBATION:
1669 rtspsrc->probation = g_value_get_uint (value);
1671 case PROP_UDP_RECONNECT:
1672 rtspsrc->udp_reconnect = g_value_get_boolean (value);
1674 case PROP_MULTICAST_IFACE:
1675 g_free (rtspsrc->multi_iface);
1677 if (g_value_get_string (value) == NULL)
1678 rtspsrc->multi_iface = g_strdup (DEFAULT_MULTICAST_IFACE);
1680 rtspsrc->multi_iface = g_value_dup_string (value);
1683 rtspsrc->ntp_sync = g_value_get_boolean (value);
1684 /* The default value of max_ts_offset depends on ntp_sync. If user
1685 * hasn't set it then change default value */
1686 if (!rtspsrc->max_ts_offset_is_set) {
1687 if (rtspsrc->ntp_sync) {
1688 rtspsrc->max_ts_offset = 0;
1690 rtspsrc->max_ts_offset = DEFAULT_MAX_TS_OFFSET;
1694 case PROP_USE_PIPELINE_CLOCK:
1695 rtspsrc->use_pipeline_clock = g_value_get_boolean (value);
1698 rtspsrc->sdes = g_value_dup_boxed (value);
1700 case PROP_TLS_VALIDATION_FLAGS:
1701 rtspsrc->tls_validation_flags = g_value_get_flags (value);
1703 case PROP_TLS_DATABASE:
1704 g_clear_object (&rtspsrc->tls_database);
1705 rtspsrc->tls_database = g_value_dup_object (value);
1707 case PROP_TLS_INTERACTION:
1708 g_clear_object (&rtspsrc->tls_interaction);
1709 rtspsrc->tls_interaction = g_value_dup_object (value);
1711 case PROP_DO_RETRANSMISSION:
1712 rtspsrc->do_retransmission = g_value_get_boolean (value);
1714 case PROP_NTP_TIME_SOURCE:
1715 rtspsrc->ntp_time_source = g_value_get_enum (value);
1717 case PROP_USER_AGENT:
1718 g_free (rtspsrc->user_agent);
1719 rtspsrc->user_agent = g_value_dup_string (value);
1721 case PROP_MAX_RTCP_RTP_TIME_DIFF:
1722 rtspsrc->max_rtcp_rtp_time_diff = g_value_get_int (value);
1724 case PROP_RFC7273_SYNC:
1725 rtspsrc->rfc7273_sync = g_value_get_boolean (value);
1727 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
1728 rtspsrc->max_ts_offset_adjustment = g_value_get_uint64 (value);
1730 case PROP_MAX_TS_OFFSET:
1731 rtspsrc->max_ts_offset = g_value_get_int64 (value);
1732 rtspsrc->max_ts_offset_is_set = TRUE;
1734 case PROP_DEFAULT_VERSION:
1735 rtspsrc->default_version = g_value_get_enum (value);
1737 case PROP_BACKCHANNEL:
1738 rtspsrc->backchannel = g_value_get_enum (value);
1740 case PROP_TEARDOWN_TIMEOUT:
1741 rtspsrc->teardown_timeout = g_value_get_uint64 (value);
1743 case PROP_ONVIF_MODE:
1744 rtspsrc->onvif_mode = g_value_get_boolean (value);
1746 case PROP_ONVIF_RATE_CONTROL:
1747 rtspsrc->onvif_rate_control = g_value_get_boolean (value);
1750 rtspsrc->is_live = g_value_get_boolean (value);
1753 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1759 gst_rtspsrc_get_property (GObject * object, guint prop_id, GValue * value,
1762 GstRTSPSrc *rtspsrc;
1764 rtspsrc = GST_RTSPSRC (object);
1768 g_value_set_string (value, rtspsrc->conninfo.location);
1770 case PROP_PROTOCOLS:
1771 g_value_set_flags (value, rtspsrc->protocols);
1774 g_value_set_boolean (value, rtspsrc->debug);
1777 g_value_set_uint (value, rtspsrc->retry);
1780 g_value_set_uint64 (value, rtspsrc->udp_timeout);
1782 case PROP_TCP_TIMEOUT:
1783 g_value_set_uint64 (value, rtspsrc->tcp_timeout);
1786 g_value_set_uint (value, rtspsrc->latency);
1788 case PROP_DROP_ON_LATENCY:
1789 g_value_set_boolean (value, rtspsrc->drop_on_latency);
1791 case PROP_CONNECTION_SPEED:
1792 g_value_set_uint64 (value, rtspsrc->connection_speed);
1794 case PROP_NAT_METHOD:
1795 g_value_set_enum (value, rtspsrc->nat_method);
1798 g_value_set_boolean (value, rtspsrc->do_rtcp);
1800 case PROP_DO_RTSP_KEEP_ALIVE:
1801 g_value_set_boolean (value, rtspsrc->do_rtsp_keep_alive);
1807 if (rtspsrc->proxy_host) {
1809 g_strdup_printf ("%s:%d", rtspsrc->proxy_host, rtspsrc->proxy_port);
1813 g_value_take_string (value, str);
1817 g_value_set_string (value, rtspsrc->prop_proxy_id);
1820 g_value_set_string (value, rtspsrc->prop_proxy_pw);
1822 case PROP_RTP_BLOCKSIZE:
1823 g_value_set_uint (value, rtspsrc->rtp_blocksize);
1826 g_value_set_string (value, rtspsrc->user_id);
1829 g_value_set_string (value, rtspsrc->user_pw);
1831 case PROP_BUFFER_MODE:
1832 g_value_set_enum (value, rtspsrc->buffer_mode);
1834 case PROP_PORT_RANGE:
1838 if (rtspsrc->client_port_range.min != 0) {
1839 str = g_strdup_printf ("%u-%u", rtspsrc->client_port_range.min,
1840 rtspsrc->client_port_range.max);
1844 g_value_take_string (value, str);
1847 case PROP_UDP_BUFFER_SIZE:
1848 g_value_set_int (value, rtspsrc->udp_buffer_size);
1850 case PROP_SHORT_HEADER:
1851 g_value_set_boolean (value, rtspsrc->short_header);
1853 case PROP_PROBATION:
1854 g_value_set_uint (value, rtspsrc->probation);
1856 case PROP_UDP_RECONNECT:
1857 g_value_set_boolean (value, rtspsrc->udp_reconnect);
1859 case PROP_MULTICAST_IFACE:
1860 g_value_set_string (value, rtspsrc->multi_iface);
1863 g_value_set_boolean (value, rtspsrc->ntp_sync);
1865 case PROP_USE_PIPELINE_CLOCK:
1866 g_value_set_boolean (value, rtspsrc->use_pipeline_clock);
1869 g_value_set_boxed (value, rtspsrc->sdes);
1871 case PROP_TLS_VALIDATION_FLAGS:
1872 g_value_set_flags (value, rtspsrc->tls_validation_flags);
1874 case PROP_TLS_DATABASE:
1875 g_value_set_object (value, rtspsrc->tls_database);
1877 case PROP_TLS_INTERACTION:
1878 g_value_set_object (value, rtspsrc->tls_interaction);
1880 case PROP_DO_RETRANSMISSION:
1881 g_value_set_boolean (value, rtspsrc->do_retransmission);
1883 case PROP_NTP_TIME_SOURCE:
1884 g_value_set_enum (value, rtspsrc->ntp_time_source);
1886 case PROP_USER_AGENT:
1887 g_value_set_string (value, rtspsrc->user_agent);
1889 case PROP_MAX_RTCP_RTP_TIME_DIFF:
1890 g_value_set_int (value, rtspsrc->max_rtcp_rtp_time_diff);
1892 case PROP_RFC7273_SYNC:
1893 g_value_set_boolean (value, rtspsrc->rfc7273_sync);
1895 case PROP_MAX_TS_OFFSET_ADJUSTMENT:
1896 g_value_set_uint64 (value, rtspsrc->max_ts_offset_adjustment);
1898 case PROP_MAX_TS_OFFSET:
1899 g_value_set_int64 (value, rtspsrc->max_ts_offset);
1901 case PROP_DEFAULT_VERSION:
1902 g_value_set_enum (value, rtspsrc->default_version);
1904 case PROP_BACKCHANNEL:
1905 g_value_set_enum (value, rtspsrc->backchannel);
1907 case PROP_TEARDOWN_TIMEOUT:
1908 g_value_set_uint64 (value, rtspsrc->teardown_timeout);
1910 case PROP_ONVIF_MODE:
1911 g_value_set_boolean (value, rtspsrc->onvif_mode);
1913 case PROP_ONVIF_RATE_CONTROL:
1914 g_value_set_boolean (value, rtspsrc->onvif_rate_control);
1917 g_value_set_boolean (value, rtspsrc->is_live);
1920 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1926 find_stream_by_id (GstRTSPStream * stream, gint * id)
1928 if (stream->id == *id)
1935 find_stream_by_channel (GstRTSPStream * stream, gint * channel)
1937 /* ignore unconfigured channels here (e.g., those that
1938 * were explicitly skipped during SETUP) */
1939 if ((stream->channelpad[0] != NULL) &&
1940 (stream->channel[0] == *channel || stream->channel[1] == *channel))
1947 find_stream_by_udpsrc (GstRTSPStream * stream, gconstpointer a)
1949 GstElement *src = (GstElement *) a;
1951 if (stream->udpsrc[0] == src)
1953 if (stream->udpsrc[1] == src)
1960 find_stream_by_setup (GstRTSPStream * stream, gconstpointer a)
1962 if (stream->conninfo.location) {
1963 /* check qualified setup_url */
1964 if (!strcmp (stream->conninfo.location, (gchar *) a))
1967 if (stream->control_url) {
1968 /* check original control_url */
1969 if (!strcmp (stream->control_url, (gchar *) a))
1972 /* check if qualified setup_url ends with string */
1973 if (g_str_has_suffix (stream->control_url, (gchar *) a))
1980 static GstRTSPStream *
1981 find_stream (GstRTSPSrc * src, gconstpointer data, gconstpointer func)
1985 /* find and get stream */
1986 if ((lstream = g_list_find_custom (src->streams, data, (GCompareFunc) func)))
1987 return (GstRTSPStream *) lstream->data;
1992 static const GstSDPBandwidth *
1993 gst_rtspsrc_get_bandwidth (GstRTSPSrc * src, const GstSDPMessage * sdp,
1994 const GstSDPMedia * media, const gchar * type)
1998 /* first look in the media specific section */
1999 len = gst_sdp_media_bandwidths_len (media);
2000 for (i = 0; i < len; i++) {
2001 const GstSDPBandwidth *bw = gst_sdp_media_get_bandwidth (media, i);
2003 if (strcmp (bw->bwtype, type) == 0)
2006 /* then look in the message specific section */
2007 len = gst_sdp_message_bandwidths_len (sdp);
2008 for (i = 0; i < len; i++) {
2009 const GstSDPBandwidth *bw = gst_sdp_message_get_bandwidth (sdp, i);
2011 if (strcmp (bw->bwtype, type) == 0)
2018 gst_rtspsrc_collect_bandwidth (GstRTSPSrc * src, const GstSDPMessage * sdp,
2019 const GstSDPMedia * media, GstRTSPStream * stream)
2021 const GstSDPBandwidth *bw;
2023 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_AS)))
2024 stream->as_bandwidth = bw->bandwidth;
2026 stream->as_bandwidth = -1;
2028 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_RR)))
2029 stream->rr_bandwidth = bw->bandwidth;
2031 stream->rr_bandwidth = -1;
2033 if ((bw = gst_rtspsrc_get_bandwidth (src, sdp, media, GST_SDP_BWTYPE_RS)))
2034 stream->rs_bandwidth = bw->bandwidth;
2036 stream->rs_bandwidth = -1;
2040 gst_rtspsrc_do_stream_connection (GstRTSPSrc * src, GstRTSPStream * stream,
2041 const GstSDPConnection * conn)
2043 if (conn->nettype == NULL || strcmp (conn->nettype, "IN") != 0)
2046 if (conn->addrtype == NULL)
2049 /* check for IPV6 */
2050 if (strcmp (conn->addrtype, "IP4") == 0)
2051 stream->is_ipv6 = FALSE;
2052 else if (strcmp (conn->addrtype, "IP6") == 0)
2053 stream->is_ipv6 = TRUE;
2058 g_free (stream->destination);
2059 stream->destination = g_strdup (conn->address);
2061 /* check for multicast */
2062 stream->is_multicast =
2063 gst_sdp_address_is_multicast (conn->nettype, conn->addrtype,
2065 stream->ttl = conn->ttl;
2068 /* Go over the connections for a stream.
2069 * - If we are dealing with IPV6, we will setup IPV6 sockets for sending and
2071 * - If we are dealing with a localhost address, we disable multicast
2074 gst_rtspsrc_collect_connections (GstRTSPSrc * src, const GstSDPMessage * sdp,
2075 const GstSDPMedia * media, GstRTSPStream * stream)
2077 const GstSDPConnection *conn;
2080 /* first look in the media specific section */
2081 len = gst_sdp_media_connections_len (media);
2082 for (i = 0; i < len; i++) {
2083 conn = gst_sdp_media_get_connection (media, i);
2085 gst_rtspsrc_do_stream_connection (src, stream, conn);
2087 /* then look in the message specific section */
2088 if ((conn = gst_sdp_message_get_connection (sdp))) {
2089 gst_rtspsrc_do_stream_connection (src, stream, conn);
2094 make_stream_id (GstRTSPStream * stream, const GstSDPMedia * media)
2097 g_strdup_printf ("%s:%d:%d:%s:%d", media->media, media->port,
2098 media->num_ports, media->proto, stream->default_pt);
2100 g_strcanon (stream_id, G_CSET_a_2_z G_CSET_A_2_Z G_CSET_DIGITS, ':');
2105 /* m=<media> <UDP port> RTP/AVP <payload>
2108 gst_rtspsrc_collect_payloads (GstRTSPSrc * src, const GstSDPMessage * sdp,
2109 const GstSDPMedia * media, GstRTSPStream * stream)
2113 GstCaps *global_caps;
2116 proto = gst_sdp_media_get_proto (media);
2120 if (g_str_equal (proto, "RTP/AVP"))
2121 stream->profile = GST_RTSP_PROFILE_AVP;
2122 else if (g_str_equal (proto, "RTP/SAVP"))
2123 stream->profile = GST_RTSP_PROFILE_SAVP;
2124 else if (g_str_equal (proto, "RTP/AVPF"))
2125 stream->profile = GST_RTSP_PROFILE_AVPF;
2126 else if (g_str_equal (proto, "RTP/SAVPF"))
2127 stream->profile = GST_RTSP_PROFILE_SAVPF;
2131 if (gst_sdp_media_get_attribute_val (media, "sendonly") != NULL &&
2132 /* We want to setup caps for streams configured as backchannel */
2133 !stream->is_backchannel && src->backchannel != BACKCHANNEL_NONE)
2134 goto sendonly_media;
2136 /* Parse global SDP attributes once */
2137 global_caps = gst_caps_new_empty_simple ("application/x-unknown");
2138 GST_DEBUG ("mapping sdp session level attributes to caps");
2139 gst_sdp_message_attributes_to_caps (sdp, global_caps);
2140 GST_DEBUG ("mapping sdp media level attributes to caps");
2141 gst_sdp_media_attributes_to_caps (media, global_caps);
2143 /* Keep a copy of the SDP key management */
2144 gst_sdp_media_parse_keymgmt (media, &stream->mikey);
2145 if (stream->mikey == NULL)
2146 gst_sdp_message_parse_keymgmt (sdp, &stream->mikey);
2148 len = gst_sdp_media_formats_len (media);
2149 for (i = 0; i < len; i++) {
2151 GstCaps *caps, *outcaps;
2156 pt = atoi (gst_sdp_media_get_format (media, i));
2158 GST_DEBUG_OBJECT (src, " looking at %d pt: %d", i, pt);
2161 caps = gst_sdp_media_get_caps_from_media (media, pt);
2163 GST_WARNING_OBJECT (src, " skipping pt %d without caps", pt);
2167 /* do some tweaks */
2168 s = gst_caps_get_structure (caps, 0);
2169 if ((enc = gst_structure_get_string (s, "encoding-name"))) {
2170 stream->is_real = (strstr (enc, "-REAL") != NULL);
2171 if (strcmp (enc, "X-ASF-PF") == 0)
2172 stream->container = TRUE;
2175 /* Merge in global caps */
2176 /* Intersect will merge in missing fields to the current caps */
2177 outcaps = gst_caps_intersect (caps, global_caps);
2178 gst_caps_unref (caps);
2180 /* the first pt will be the default */
2181 if (stream->ptmap->len == 0)
2182 stream->default_pt = pt;
2185 item.caps = outcaps;
2187 g_array_append_val (stream->ptmap, item);
2190 stream->stream_id = make_stream_id (stream, media);
2192 gst_caps_unref (global_caps);
2197 GST_ERROR_OBJECT (src, "can't find proto in media");
2202 GST_ERROR_OBJECT (src, "unknown proto in media: '%s'", proto);
2207 GST_DEBUG_OBJECT (src, "sendonly media ignored, no backchannel");
2212 static const gchar *
2213 get_aggregate_control (GstRTSPSrc * src)
2218 base = src->control;
2219 else if (src->content_base)
2220 base = src->content_base;
2221 else if (src->conninfo.url_str)
2222 base = src->conninfo.url_str;
2230 clear_ptmap_item (PtMapItem * item)
2233 gst_caps_unref (item->caps);
2236 static GstRTSPStream *
2237 gst_rtspsrc_create_stream (GstRTSPSrc * src, GstSDPMessage * sdp, gint idx,
2240 GstRTSPStream *stream;
2241 const gchar *control_path;
2242 const GstSDPMedia *media;
2244 /* get media, should not return NULL */
2245 media = gst_sdp_message_get_media (sdp, idx);
2249 stream = g_new0 (GstRTSPStream, 1);
2250 stream->parent = src;
2251 /* we mark the pad as not linked, we will mark it as OK when we add the pad to
2253 stream->last_ret = GST_FLOW_NOT_LINKED;
2254 stream->added = FALSE;
2255 stream->setup = FALSE;
2256 stream->skipped = FALSE;
2258 stream->eos = FALSE;
2259 stream->discont = TRUE;
2260 stream->seqbase = -1;
2261 stream->timebase = -1;
2262 stream->send_ssrc = g_random_int ();
2263 stream->profile = GST_RTSP_PROFILE_AVP;
2264 stream->ptmap = g_array_new (FALSE, FALSE, sizeof (PtMapItem));
2265 stream->mikey = NULL;
2266 stream->stream_id = NULL;
2267 stream->is_backchannel = FALSE;
2268 g_mutex_init (&stream->conninfo.send_lock);
2269 g_mutex_init (&stream->conninfo.recv_lock);
2270 g_array_set_clear_func (stream->ptmap, (GDestroyNotify) clear_ptmap_item);
2272 /* stream is sendonly and onvif backchannel is requested */
2273 if (gst_sdp_media_get_attribute_val (media, "sendonly") != NULL &&
2274 src->backchannel != BACKCHANNEL_NONE)
2275 stream->is_backchannel = TRUE;
2277 /* collect bandwidth information for this steam. FIXME, configure in the RTP
2278 * session manager to scale RTCP. */
2279 gst_rtspsrc_collect_bandwidth (src, sdp, media, stream);
2281 /* collect connection info */
2282 gst_rtspsrc_collect_connections (src, sdp, media, stream);
2284 /* make the payload type map */
2285 gst_rtspsrc_collect_payloads (src, sdp, media, stream);
2287 /* collect port number */
2288 stream->port = gst_sdp_media_get_port (media);
2290 /* get control url to construct the setup url. The setup url is used to
2291 * configure the transport of the stream and is used to identity the stream in
2292 * the RTP-Info header field returned from PLAY. */
2293 control_path = gst_sdp_media_get_attribute_val (media, "control");
2294 if (control_path == NULL)
2295 control_path = gst_sdp_message_get_attribute_val_n (sdp, "control", 0);
2297 GST_DEBUG_OBJECT (src, "stream %d, (%p)", stream->id, stream);
2298 GST_DEBUG_OBJECT (src, " port: %d", stream->port);
2299 GST_DEBUG_OBJECT (src, " container: %d", stream->container);
2300 GST_DEBUG_OBJECT (src, " control: %s", GST_STR_NULL (control_path));
2302 /* RFC 2326, C.3: missing control_path permitted in case of a single stream */
2303 if (control_path == NULL && n_streams == 1) {
2307 if (control_path != NULL) {
2308 stream->control_url = g_strdup (control_path);
2309 /* Build a fully qualified url using the content_base if any or by prefixing
2310 * the original request.
2311 * If the control_path starts with a non rtsp: protocol we will most
2312 * likely build a URL that the server will fail to understand, this is ok,
2313 * we will fail then. */
2314 if (g_str_has_prefix (control_path, "rtsp://"))
2315 stream->conninfo.location = g_strdup (control_path);
2317 if (g_strcmp0 (control_path, "*") == 0)
2319 /* handle url with query */
2320 if (src->conninfo.url && src->conninfo.url->query) {
2321 stream->conninfo.location =
2322 gst_rtsp_url_get_request_uri_with_control (src->conninfo.url,
2328 const gchar *actual_control_path = NULL;
2330 base = get_aggregate_control (src);
2331 has_slash = g_str_has_suffix (base, "/");
2332 /* manage existence or non-existence of / in control path */
2333 if (control_path && strlen (control_path) > 0) {
2334 gboolean control_has_slash = g_str_has_prefix (control_path, "/");
2336 actual_control_path = control_path;
2337 if (has_slash && control_has_slash) {
2338 if (strlen (control_path) == 1) {
2339 actual_control_path = NULL;
2341 actual_control_path = control_path + 1;
2344 has_slash = has_slash || control_has_slash;
2347 slash = (!has_slash && (actual_control_path != NULL)) ? "/" : "";
2348 /* concatenate the two strings, insert / when not present */
2349 stream->conninfo.location =
2350 g_strdup_printf ("%s%s%s", base, slash, control_path);
2354 GST_DEBUG_OBJECT (src, " setup: %s",
2355 GST_STR_NULL (stream->conninfo.location));
2357 /* we keep track of all streams */
2358 src->streams = g_list_append (src->streams, stream);
2366 gst_rtspsrc_stream_free (GstRTSPSrc * src, GstRTSPStream * stream)
2370 GST_DEBUG_OBJECT (src, "free stream %p", stream);
2372 g_array_free (stream->ptmap, TRUE);
2374 g_free (stream->destination);
2375 g_free (stream->control_url);
2376 g_free (stream->conninfo.location);
2377 g_free (stream->stream_id);
2379 for (i = 0; i < 2; i++) {
2380 if (stream->udpsrc[i]) {
2381 gst_element_set_state (stream->udpsrc[i], GST_STATE_NULL);
2382 if (gst_object_has_as_parent (GST_OBJECT (stream->udpsrc[i]),
2384 gst_bin_remove (GST_BIN_CAST (src), stream->udpsrc[i]);
2385 gst_object_unref (stream->udpsrc[i]);
2387 if (stream->channelpad[i])
2388 gst_object_unref (stream->channelpad[i]);
2390 if (stream->udpsink[i]) {
2391 gst_element_set_state (stream->udpsink[i], GST_STATE_NULL);
2392 if (gst_object_has_as_parent (GST_OBJECT (stream->udpsink[i]),
2394 gst_bin_remove (GST_BIN_CAST (src), stream->udpsink[i]);
2395 gst_object_unref (stream->udpsink[i]);
2398 if (stream->rtpsrc) {
2399 gst_element_set_state (stream->rtpsrc, GST_STATE_NULL);
2400 gst_bin_remove (GST_BIN_CAST (src), stream->rtpsrc);
2401 gst_object_unref (stream->rtpsrc);
2403 if (stream->srcpad) {
2404 gst_pad_set_active (stream->srcpad, FALSE);
2406 gst_element_remove_pad (GST_ELEMENT_CAST (src), stream->srcpad);
2408 if (stream->srtpenc)
2409 gst_object_unref (stream->srtpenc);
2410 if (stream->srtpdec)
2411 gst_object_unref (stream->srtpdec);
2412 if (stream->srtcpparams)
2413 gst_caps_unref (stream->srtcpparams);
2415 gst_mikey_message_unref (stream->mikey);
2416 if (stream->rtcppad)
2417 gst_object_unref (stream->rtcppad);
2418 if (stream->session)
2419 g_object_unref (stream->session);
2420 if (stream->rtx_pt_map)
2421 gst_structure_free (stream->rtx_pt_map);
2423 g_mutex_clear (&stream->conninfo.send_lock);
2424 g_mutex_clear (&stream->conninfo.recv_lock);
2430 gst_rtspsrc_cleanup (GstRTSPSrc * src)
2433 ParameterRequest *req;
2435 GST_DEBUG_OBJECT (src, "cleanup");
2437 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2438 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2440 gst_rtspsrc_stream_free (src, stream);
2442 g_list_free (src->streams);
2443 src->streams = NULL;
2445 if (src->manager_sig_id) {
2446 g_signal_handler_disconnect (src->manager, src->manager_sig_id);
2447 src->manager_sig_id = 0;
2449 gst_element_set_state (src->manager, GST_STATE_NULL);
2450 gst_bin_remove (GST_BIN_CAST (src), src->manager);
2451 src->manager = NULL;
2454 gst_structure_free (src->props);
2457 g_free (src->content_base);
2458 src->content_base = NULL;
2460 g_free (src->control);
2461 src->control = NULL;
2464 gst_rtsp_range_free (src->range);
2467 /* don't clear the SDP when it was used in the url */
2468 if (src->sdp && !src->from_sdp) {
2469 gst_sdp_message_free (src->sdp);
2473 src->need_segment = FALSE;
2474 src->clip_out_segment = FALSE;
2476 if (src->provided_clock) {
2477 gst_object_unref (src->provided_clock);
2478 src->provided_clock = NULL;
2481 GST_OBJECT_LOCK (src);
2482 /* free parameter requests queue */
2483 while ((req = g_queue_pop_head (&src->set_get_param_q))) {
2484 gst_promise_expire (req->promise);
2485 free_param_data (req);
2487 GST_OBJECT_UNLOCK (src);
2492 gst_rtspsrc_alloc_udp_ports (GstRTSPStream * stream,
2493 gint * rtpport, gint * rtcpport)
2496 GstStateChangeReturn ret;
2497 GstElement *udpsrc0, *udpsrc1;
2498 gint tmp_rtp, tmp_rtcp;
2502 src = stream->parent;
2508 /* Start at next port */
2509 tmp_rtp = src->next_port_num;
2511 if (stream->is_ipv6)
2512 host = "udp://[::0]";
2514 host = "udp://0.0.0.0";
2516 /* try to allocate 2 UDP ports, the RTP port should be an even
2517 * number and the RTCP port should be the next (uneven) port */
2520 if (tmp_rtp != 0 && src->client_port_range.max > 0 &&
2521 tmp_rtp >= src->client_port_range.max)
2524 udpsrc0 = gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
2525 if (udpsrc0 == NULL)
2526 goto no_udp_protocol;
2527 g_object_set (G_OBJECT (udpsrc0), "port", tmp_rtp, "reuse", FALSE, NULL);
2529 if (src->udp_buffer_size != 0)
2530 g_object_set (G_OBJECT (udpsrc0), "buffer-size", src->udp_buffer_size,
2533 ret = gst_element_set_state (udpsrc0, GST_STATE_READY);
2534 if (ret == GST_STATE_CHANGE_FAILURE) {
2536 GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTP port %d", tmp_rtp);
2539 if (++count > src->retry)
2542 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
2543 gst_element_set_state (udpsrc0, GST_STATE_NULL);
2544 gst_object_unref (udpsrc0);
2547 GST_DEBUG_OBJECT (src, "retry %d", count);
2550 goto no_udp_protocol;
2553 g_object_get (G_OBJECT (udpsrc0), "port", &tmp_rtp, NULL);
2554 GST_DEBUG_OBJECT (src, "got RTP port %d", tmp_rtp);
2556 /* check if port is even */
2557 if ((tmp_rtp & 0x01) != 0) {
2558 /* port not even, close and allocate another */
2559 if (++count > src->retry)
2562 GST_DEBUG_OBJECT (src, "RTP port not even");
2564 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
2565 gst_element_set_state (udpsrc0, GST_STATE_NULL);
2566 gst_object_unref (udpsrc0);
2569 GST_DEBUG_OBJECT (src, "retry %d", count);
2574 /* allocate port+1 for RTCP now */
2575 udpsrc1 = gst_element_make_from_uri (GST_URI_SRC, host, NULL, NULL);
2576 if (udpsrc1 == NULL)
2577 goto no_udp_rtcp_protocol;
2580 tmp_rtcp = tmp_rtp + 1;
2581 if (src->client_port_range.max > 0 && tmp_rtcp > src->client_port_range.max)
2584 g_object_set (G_OBJECT (udpsrc1), "port", tmp_rtcp, "reuse", FALSE, NULL);
2586 GST_DEBUG_OBJECT (src, "starting RTCP on port %d", tmp_rtcp);
2587 ret = gst_element_set_state (udpsrc1, GST_STATE_READY);
2588 /* tmp_rtcp port is busy already : retry to make rtp/rtcp pair */
2589 if (ret == GST_STATE_CHANGE_FAILURE) {
2590 GST_DEBUG_OBJECT (src, "Unable to make udpsrc from RTCP port %d", tmp_rtcp);
2592 if (++count > src->retry)
2595 GST_DEBUG_OBJECT (src, "free RTP udpsrc");
2596 gst_element_set_state (udpsrc0, GST_STATE_NULL);
2597 gst_object_unref (udpsrc0);
2600 GST_DEBUG_OBJECT (src, "free RTCP udpsrc");
2601 gst_element_set_state (udpsrc1, GST_STATE_NULL);
2602 gst_object_unref (udpsrc1);
2606 GST_DEBUG_OBJECT (src, "retry %d", count);
2610 /* all fine, do port check */
2611 g_object_get (G_OBJECT (udpsrc0), "port", rtpport, NULL);
2612 g_object_get (G_OBJECT (udpsrc1), "port", rtcpport, NULL);
2614 /* this should not happen... */
2615 if (*rtpport != tmp_rtp || *rtcpport != tmp_rtcp)
2618 /* we keep these elements, we configure all in configure_transport when the
2619 * server told us to really use the UDP ports. */
2620 stream->udpsrc[0] = gst_object_ref_sink (udpsrc0);
2621 stream->udpsrc[1] = gst_object_ref_sink (udpsrc1);
2622 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
2623 gst_element_set_locked_state (stream->udpsrc[1], TRUE);
2625 /* keep track of next available port number when we have a range
2627 if (src->next_port_num != 0)
2628 src->next_port_num = tmp_rtcp + 1;
2635 GST_DEBUG_OBJECT (src, "could not get UDP source");
2640 GST_DEBUG_OBJECT (src, "could not allocate UDP port pair after %d retries",
2644 no_udp_rtcp_protocol:
2646 GST_DEBUG_OBJECT (src, "could not get UDP source for RTCP");
2651 GST_DEBUG_OBJECT (src, "ports don't match rtp: %d<->%d, rtcp: %d<->%d",
2652 tmp_rtp, *rtpport, tmp_rtcp, *rtcpport);
2658 gst_element_set_state (udpsrc0, GST_STATE_NULL);
2659 gst_object_unref (udpsrc0);
2662 gst_element_set_state (udpsrc1, GST_STATE_NULL);
2663 gst_object_unref (udpsrc1);
2670 gst_rtspsrc_set_state (GstRTSPSrc * src, GstState state)
2675 gst_element_set_state (GST_ELEMENT_CAST (src->manager), state);
2677 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2678 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2681 for (i = 0; i < 2; i++) {
2682 if (stream->udpsrc[i])
2683 gst_element_set_state (stream->udpsrc[i], state);
2689 gst_rtspsrc_flush (GstRTSPSrc * src, gboolean flush, gboolean playing,
2697 event = gst_event_new_flush_start ();
2698 gst_event_set_seqnum (event, seqnum);
2699 GST_DEBUG_OBJECT (src, "start flush");
2701 state = GST_STATE_PAUSED;
2703 event = gst_event_new_flush_stop (TRUE);
2704 gst_event_set_seqnum (event, seqnum);
2705 GST_DEBUG_OBJECT (src, "stop flush; playing %d", playing);
2708 state = GST_STATE_PLAYING;
2710 state = GST_STATE_PAUSED;
2712 gst_rtspsrc_push_event (src, event);
2713 gst_rtspsrc_loop_send_cmd (src, cmd, CMD_LOOP);
2714 gst_rtspsrc_set_state (src, state);
2717 static GstRTSPResult
2718 gst_rtspsrc_connection_send (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
2719 GstRTSPMessage * message, gint64 timeout)
2723 if (conninfo->connection) {
2724 g_mutex_lock (&conninfo->send_lock);
2726 gst_rtsp_connection_send_usec (conninfo->connection, message, timeout);
2727 g_mutex_unlock (&conninfo->send_lock);
2729 ret = GST_RTSP_ERROR;
2735 static GstRTSPResult
2736 gst_rtspsrc_connection_receive (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
2737 GstRTSPMessage * message, gint64 timeout)
2741 if (conninfo->connection) {
2742 g_mutex_lock (&conninfo->recv_lock);
2743 ret = gst_rtsp_connection_receive_usec (conninfo->connection, message,
2745 g_mutex_unlock (&conninfo->recv_lock);
2747 ret = GST_RTSP_ERROR;
2754 gst_rtspsrc_get_position (GstRTSPSrc * src)
2759 query = gst_query_new_position (GST_FORMAT_TIME);
2760 /* should be known somewhere down the stream (e.g. jitterbuffer) */
2761 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2762 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2766 if (stream->srcpad) {
2767 if (gst_pad_query (stream->srcpad, query)) {
2768 gst_query_parse_position (query, &fmt, &pos);
2769 GST_DEBUG_OBJECT (src, "retaining position %" GST_TIME_FORMAT,
2770 GST_TIME_ARGS (pos));
2771 src->last_pos = pos;
2781 gst_query_unref (query);
2785 gst_rtspsrc_perform_seek (GstRTSPSrc * src, GstEvent * event)
2790 GstSeekType cur_type = GST_SEEK_TYPE_NONE, stop_type = GST_SEEK_TYPE_NONE;
2792 gboolean flush, server_side_trickmode;
2795 GstSegment seeksegment = { 0, };
2797 const gchar *seek_style = NULL;
2798 gboolean rate_change_only = FALSE;
2799 gboolean rate_change_same_direction = FALSE;
2801 GST_DEBUG_OBJECT (src, "doing seek with event %" GST_PTR_FORMAT, event);
2803 gst_event_parse_seek (event, &rate, &format, &flags,
2804 &cur_type, &cur, &stop_type, &stop);
2805 rate_change_only = cur_type == GST_SEEK_TYPE_NONE
2806 && stop_type == GST_SEEK_TYPE_NONE;
2808 /* we need TIME format */
2809 if (format != src->segment.format)
2812 /* Check if we are not at all seekable */
2813 if (src->seekable == -1.0)
2816 /* Additional seeking-to-beginning-only check */
2817 if (src->seekable == 0.0 && cur != 0)
2820 if (flags & GST_SEEK_FLAG_SEGMENT)
2821 goto invalid_segment_flag;
2823 /* get flush flag */
2824 flush = flags & GST_SEEK_FLAG_FLUSH;
2825 server_side_trickmode = flags & GST_SEEK_FLAG_TRICKMODE;
2827 gst_event_parse_seek_trickmode_interval (event, &src->trickmode_interval);
2829 /* now we need to make sure the streaming thread is stopped. We do this by
2830 * either sending a FLUSH_START event downstream which will cause the
2831 * streaming thread to stop with a WRONG_STATE.
2832 * For a non-flushing seek we simply pause the task, which will happen as soon
2833 * as it completes one iteration (and thus might block when the sink is
2834 * blocking in preroll). */
2836 GST_DEBUG_OBJECT (src, "starting flush");
2837 gst_rtspsrc_flush (src, TRUE, FALSE, gst_event_get_seqnum (event));
2840 gst_task_pause (src->task);
2844 /* we should now be able to grab the streaming thread because we stopped it
2845 * with the above flush/pause code */
2846 GST_RTSP_STREAM_LOCK (src);
2848 GST_DEBUG_OBJECT (src, "stopped streaming");
2850 /* stop flushing the rtsp connection so we can send PAUSE/PLAY below */
2851 gst_rtspsrc_connection_flush (src, FALSE);
2853 /* copy segment, we need this because we still need the old
2854 * segment when we close the current segment. */
2855 seeksegment = src->segment;
2857 /* configure the seek parameters in the seeksegment. We will then have the
2858 * right values in the segment to perform the seek */
2859 GST_DEBUG_OBJECT (src, "configuring seek");
2860 rate_change_same_direction = (rate * seeksegment.rate) > 0;
2861 gst_segment_do_seek (&seeksegment, rate, format, flags,
2862 cur_type, cur, stop_type, stop, &update);
2864 /* if we were playing, pause first */
2865 playing = (src->state == GST_RTSP_STATE_PLAYING);
2867 /* obtain current position in case seek fails */
2868 gst_rtspsrc_get_position (src);
2869 gst_rtspsrc_pause (src, FALSE);
2871 src->server_side_trickmode = server_side_trickmode;
2873 src->state = GST_RTSP_STATE_SEEKING;
2875 /* PLAY will add the range header now. */
2876 src->need_range = TRUE;
2878 /* prepare for streaming again */
2880 /* if we started flush, we stop now */
2881 GST_DEBUG_OBJECT (src, "stopping flush");
2882 gst_rtspsrc_flush (src, FALSE, playing, gst_event_get_seqnum (event));
2885 /* now we did the seek and can activate the new segment values */
2886 src->segment = seeksegment;
2888 /* if we're doing a segment seek, post a SEGMENT_START message */
2889 if (src->segment.flags & GST_SEEK_FLAG_SEGMENT) {
2890 gst_element_post_message (GST_ELEMENT_CAST (src),
2891 gst_message_new_segment_start (GST_OBJECT_CAST (src),
2892 src->segment.format, src->segment.position));
2895 /* mark discont when needed */
2896 if (!(rate_change_only && rate_change_same_direction)) {
2897 GST_DEBUG_OBJECT (src, "mark DISCONT, we did a seek to another position");
2898 for (walk = src->streams; walk; walk = g_list_next (walk)) {
2899 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
2900 stream->discont = TRUE;
2904 /* and continue playing if needed. If we are not acting as a live source,
2905 * then only the RTSP PLAYING state, set earlier, matters. */
2906 GST_OBJECT_LOCK (src);
2908 playing = (GST_STATE_PENDING (src) == GST_STATE_VOID_PENDING
2909 && GST_STATE (src) == GST_STATE_PLAYING)
2910 || (GST_STATE_PENDING (src) == GST_STATE_PLAYING);
2912 GST_OBJECT_UNLOCK (src);
2914 if (src->version >= GST_RTSP_VERSION_2_0) {
2915 if (flags & GST_SEEK_FLAG_ACCURATE)
2917 else if (flags & GST_SEEK_FLAG_KEY_UNIT)
2918 seek_style = "CoRAP";
2919 else if (flags & GST_SEEK_FLAG_KEY_UNIT
2920 && flags & GST_SEEK_FLAG_SNAP_BEFORE)
2921 seek_style = "First-Prior";
2922 else if (flags & GST_SEEK_FLAG_KEY_UNIT && flags & GST_SEEK_FLAG_SNAP_AFTER)
2923 seek_style = "Next";
2926 /* If an accurate seek was requested, we want to clip the segment we
2927 * output in ONVIF mode to the requested bounds */
2928 src->clip_out_segment = ! !(flags & GST_SEEK_FLAG_ACCURATE);
2929 src->seek_seqnum = gst_event_get_seqnum (event);
2932 gst_rtspsrc_play (src, &seeksegment, FALSE, seek_style);
2934 GST_RTSP_STREAM_UNLOCK (src);
2941 GST_DEBUG_OBJECT (src, "unsupported format given, seek aborted.");
2946 GST_DEBUG_OBJECT (src, "stream is not seekable");
2949 invalid_segment_flag:
2951 GST_WARNING_OBJECT (src, "Segment seeks not supported");
2957 gst_rtspsrc_handle_src_event (GstPad * pad, GstObject * parent,
2961 gboolean res = TRUE;
2964 src = GST_RTSPSRC_CAST (parent);
2966 GST_DEBUG_OBJECT (src, "pad %s:%s received event %s",
2967 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
2969 switch (GST_EVENT_TYPE (event)) {
2970 case GST_EVENT_SEEK:
2972 guint32 seqnum = gst_event_get_seqnum (event);
2973 if (seqnum == src->seek_seqnum) {
2974 GST_LOG_OBJECT (pad, "Drop duplicated SEEK event seqnum %"
2975 G_GUINT32_FORMAT, seqnum);
2977 res = gst_rtspsrc_perform_seek (src, event);
2983 case GST_EVENT_NAVIGATION:
2984 case GST_EVENT_LATENCY:
2992 if ((target = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (pad)))) {
2993 res = gst_pad_send_event (target, event);
2994 gst_object_unref (target);
2996 gst_event_unref (event);
2999 gst_event_unref (event);
3006 gst_rtspsrc_stream_start_event_add_group_id (GstRTSPSrc * src, GstEvent * event)
3008 g_mutex_lock (&src->group_lock);
3010 if (src->group_id == GST_GROUP_ID_INVALID)
3011 src->group_id = gst_util_group_id_next ();
3013 g_mutex_unlock (&src->group_lock);
3015 gst_event_set_group_id (event, src->group_id);
3019 gst_rtspsrc_handle_src_sink_event (GstPad * pad, GstObject * parent,
3022 GstRTSPStream *stream;
3023 GstRTSPSrc *self = GST_RTSPSRC (GST_OBJECT_PARENT (parent));
3025 stream = gst_pad_get_element_private (pad);
3027 switch (GST_EVENT_TYPE (event)) {
3028 case GST_EVENT_STREAM_START:{
3033 cs = g_checksum_new (G_CHECKSUM_SHA256);
3034 uri = self->conninfo.location;
3035 g_checksum_update (cs, (const guchar *) uri, strlen (uri));
3038 g_strdup_printf ("%s/%s", g_checksum_get_string (cs),
3041 g_checksum_free (cs);
3042 gst_event_unref (event);
3043 event = gst_event_new_stream_start (stream_id);
3044 gst_rtspsrc_stream_start_event_add_group_id (self, event);
3048 case GST_EVENT_SEGMENT:
3049 if (self->seek_seqnum != GST_SEQNUM_INVALID)
3050 GST_EVENT_SEQNUM (event) = self->seek_seqnum;
3056 return gst_pad_push_event (stream->srcpad, event);
3059 /* this is the final event function we receive on the internal source pad when
3060 * we deal with TCP connections */
3062 gst_rtspsrc_handle_internal_src_event (GstPad * pad, GstObject * parent,
3067 GST_DEBUG_OBJECT (pad, "received event %s", GST_EVENT_TYPE_NAME (event));
3069 switch (GST_EVENT_TYPE (event)) {
3070 case GST_EVENT_SEEK:
3072 case GST_EVENT_NAVIGATION:
3073 case GST_EVENT_LATENCY:
3075 gst_event_unref (event);
3082 /* this is the final query function we receive on the internal source pad when
3083 * we deal with TCP connections */
3085 gst_rtspsrc_handle_internal_src_query (GstPad * pad, GstObject * parent,
3089 gboolean res = FALSE;
3091 src = GST_RTSPSRC_CAST (gst_pad_get_element_private (pad));
3093 GST_DEBUG_OBJECT (src, "pad %s:%s received query %s",
3094 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3096 switch (GST_QUERY_TYPE (query)) {
3097 case GST_QUERY_POSITION:
3102 case GST_QUERY_DURATION:
3106 gst_query_parse_duration (query, &format, NULL);
3109 case GST_FORMAT_TIME:
3110 gst_query_set_duration (query, format, src->segment.duration);
3118 case GST_QUERY_LATENCY:
3120 /* we are live with a min latency of 0 and unlimited max latency, this
3121 * result will be updated by the session manager if there is any. */
3122 gst_query_set_latency (query, src->is_live, 0, -1);
3133 /* this query is executed on the ghost source pad exposed on rtspsrc. */
3135 gst_rtspsrc_handle_src_query (GstPad * pad, GstObject * parent,
3139 gboolean res = FALSE;
3141 src = GST_RTSPSRC_CAST (parent);
3143 GST_DEBUG_OBJECT (src, "pad %s:%s received query %s",
3144 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3146 switch (GST_QUERY_TYPE (query)) {
3147 case GST_QUERY_DURATION:
3151 gst_query_parse_duration (query, &format, NULL);
3154 case GST_FORMAT_TIME:
3155 gst_query_set_duration (query, format, src->segment.duration);
3163 case GST_QUERY_SEEKING:
3167 gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
3168 if (format == GST_FORMAT_TIME) {
3169 gboolean seekable = TRUE;
3170 GstClockTime start = 0, duration = src->segment.duration;
3172 /* seeking without duration is unlikely */
3173 seekable = seekable && src->seekable >= 0.0 && src->segment.duration &&
3174 GST_CLOCK_TIME_IS_VALID (src->segment.duration);
3177 if (src->seekable > 0.0) {
3178 start = src->last_pos - src->seekable * GST_SECOND;
3180 /* src->seekable == 0 means that we can only seek to 0 */
3186 GST_LOG_OBJECT (src, "seekable: %d, duration: %" GST_TIME_FORMAT
3187 ", src->seekable: %f", seekable,
3188 GST_TIME_ARGS (src->segment.duration), src->seekable);
3190 gst_query_set_seeking (query, GST_FORMAT_TIME, seekable, start,
3200 uri = gst_rtspsrc_uri_get_uri (GST_URI_HANDLER (src));
3202 gst_query_set_uri (query, uri);
3210 GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD_CAST (pad));
3212 /* forward the query to the proxy target pad */
3214 res = gst_pad_query (target, query);
3215 gst_object_unref (target);
3224 /* callback for RTCP messages to be sent to the server when operating in TCP
3226 static GstFlowReturn
3227 gst_rtspsrc_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
3230 GstRTSPStream *stream;
3231 GstFlowReturn res = GST_FLOW_OK;
3233 GstRTSPMessage message = { 0 };
3234 GstRTSPConnInfo *conninfo;
3236 stream = (GstRTSPStream *) gst_pad_get_element_private (pad);
3237 src = stream->parent;
3239 gst_rtsp_message_init_data (&message, stream->channel[1]);
3241 /* lend the body data to the message */
3242 gst_rtsp_message_set_body_buffer (&message, buffer);
3244 if (stream->conninfo.connection)
3245 conninfo = &stream->conninfo;
3247 conninfo = &src->conninfo;
3249 GST_DEBUG_OBJECT (src, "sending %u bytes RTCP",
3250 (guint) gst_buffer_get_size (buffer));
3251 ret = gst_rtspsrc_connection_send (src, conninfo, &message, 0);
3252 GST_DEBUG_OBJECT (src, "sent RTCP, %d", ret);
3254 gst_rtsp_message_unset (&message);
3256 gst_buffer_unref (buffer);
3261 static GstFlowReturn
3262 gst_rtspsrc_push_backchannel_buffer (GstRTSPSrc * src, guint id,
3265 GstFlowReturn res = GST_FLOW_OK;
3266 GstRTSPStream *stream;
3268 if (!src->conninfo.connected || src->state != GST_RTSP_STATE_PLAYING)
3271 stream = find_stream (src, &id, (gpointer) find_stream_by_id);
3272 if (stream == NULL) {
3273 GST_ERROR_OBJECT (src, "no stream with id %u", id);
3277 if (src->interleaved) {
3280 GstRTSPMessage message = { 0 };
3281 GstRTSPConnInfo *conninfo;
3283 buffer = gst_sample_get_buffer (sample);
3285 gst_rtsp_message_init_data (&message, stream->channel[0]);
3287 /* lend the body data to the message */
3288 gst_rtsp_message_set_body_buffer (&message, buffer);
3290 if (stream->conninfo.connection)
3291 conninfo = &stream->conninfo;
3293 conninfo = &src->conninfo;
3295 GST_DEBUG_OBJECT (src, "sending %u bytes backchannel RTP",
3296 (guint) gst_buffer_get_size (buffer));
3297 ret = gst_rtspsrc_connection_send (src, conninfo, &message, 0);
3298 GST_DEBUG_OBJECT (src, "sent backchannel RTP, %d", ret);
3300 gst_rtsp_message_unset (&message);
3304 g_signal_emit_by_name (stream->rtpsrc, "push-sample", sample, &res);
3305 GST_DEBUG_OBJECT (src, "sent backchannel RTP sample %p: %s", sample,
3306 gst_flow_get_name (res));
3310 gst_sample_unref (sample);
3315 static GstPadProbeReturn
3316 pad_blocked (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
3318 GstRTSPSrc *src = user_data;
3320 GST_DEBUG_OBJECT (src, "pad %s:%s blocked, activating streams",
3321 GST_DEBUG_PAD_NAME (pad));
3323 /* activate the streams */
3324 GST_OBJECT_LOCK (src);
3325 if (!src->need_activate)
3328 src->need_activate = FALSE;
3329 GST_OBJECT_UNLOCK (src);
3331 gst_rtspsrc_activate_streams (src);
3333 return GST_PAD_PROBE_OK;
3337 GST_OBJECT_UNLOCK (src);
3338 return GST_PAD_PROBE_OK;
3342 static GstPadProbeReturn
3343 udpsrc_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
3345 guint32 *segment_seqnum = user_data;
3347 switch (GST_EVENT_TYPE (info->data)) {
3348 case GST_EVENT_SEGMENT:
3349 if (!gst_event_is_writable (info->data))
3350 info->data = gst_event_make_writable (info->data);
3352 *segment_seqnum = gst_event_get_seqnum (info->data);
3357 return GST_PAD_PROBE_OK;
3361 copy_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
3363 GstPad *gpad = GST_PAD_CAST (user_data);
3365 GST_DEBUG_OBJECT (gpad, "store sticky event %" GST_PTR_FORMAT, *event);
3366 gst_pad_store_sticky_event (gpad, *event);
3372 add_backchannel_fakesink (GstRTSPSrc * src, GstRTSPStream * stream,
3376 GstElement *fakesink;
3378 fakesink = gst_element_factory_make ("fakesink", NULL);
3379 if (fakesink == NULL) {
3380 GST_ERROR_OBJECT (src, "no fakesink");
3384 sinkpad = gst_element_get_static_pad (fakesink, "sink");
3386 GST_DEBUG_OBJECT (src, "backchannel stream %p, hooking fakesink", stream);
3388 gst_bin_add (GST_BIN_CAST (src), fakesink);
3389 if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) {
3390 GST_WARNING_OBJECT (src, "could not link to fakesink");
3394 gst_object_unref (sinkpad);
3396 gst_element_sync_state_with_parent (fakesink);
3400 /* this callback is called when the session manager generated a new src pad with
3401 * payloaded RTP packets. We simply ghost the pad here. */
3403 new_manager_pad (GstElement * manager, GstPad * pad, GstRTSPSrc * src)
3406 GstPadTemplate *template;
3409 GstRTSPStream *stream;
3411 GstPad *internal_src;
3413 GST_DEBUG_OBJECT (src, "got new manager pad %" GST_PTR_FORMAT, pad);
3415 GST_RTSP_STATE_LOCK (src);
3417 name = gst_object_get_name (GST_OBJECT_CAST (pad));
3418 if (sscanf (name, "recv_rtp_src_%u_%u_%u", &id, &ssrc, &pt) != 3)
3419 goto unknown_stream;
3421 GST_DEBUG_OBJECT (src, "stream: %u, SSRC %08x, PT %d", id, ssrc, pt);
3423 stream = find_stream (src, &id, (gpointer) find_stream_by_id);
3425 goto unknown_stream;
3428 stream->ssrc = ssrc;
3430 /* we'll add it later see below */
3431 stream->added = TRUE;
3433 /* check if we added all streams */
3435 for (ostreams = src->streams; ostreams; ostreams = g_list_next (ostreams)) {
3436 GstRTSPStream *ostream = (GstRTSPStream *) ostreams->data;
3438 GST_DEBUG_OBJECT (src, "stream %p, container %d, added %d, setup %d",
3439 ostream, ostream->container, ostream->added, ostream->setup);
3441 /* if we find a stream for which we did a setup that is not added, we
3442 * need to wait some more */
3443 if (ostream->setup && !ostream->added) {
3448 GST_RTSP_STATE_UNLOCK (src);
3450 /* create a new pad we will use to stream to */
3451 template = gst_static_pad_template_get (&rtptemplate);
3452 stream->srcpad = gst_ghost_pad_new_from_template (name, pad, template);
3453 gst_object_unref (template);
3456 /* We intercept and modify the stream start event */
3458 GST_PAD (gst_proxy_pad_get_internal (GST_PROXY_PAD (stream->srcpad)));
3459 gst_pad_set_element_private (internal_src, stream);
3460 gst_pad_set_event_function (internal_src, gst_rtspsrc_handle_src_sink_event);
3461 gst_object_unref (internal_src);
3463 gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
3464 gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
3465 gst_pad_set_active (stream->srcpad, TRUE);
3466 gst_pad_sticky_events_foreach (pad, copy_sticky_events, stream->srcpad);
3468 /* don't add the srcpad if this is a sendonly stream */
3469 if (stream->is_backchannel)
3470 add_backchannel_fakesink (src, stream, stream->srcpad);
3472 gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
3475 GST_DEBUG_OBJECT (src, "We added all streams");
3476 /* when we get here, all stream are added and we can fire the no-more-pads
3478 gst_element_no_more_pads (GST_ELEMENT_CAST (src));
3486 GST_DEBUG_OBJECT (src, "ignoring unknown stream");
3487 GST_RTSP_STATE_UNLOCK (src);
3494 stream_get_caps_for_pt (GstRTSPStream * stream, guint pt)
3498 len = stream->ptmap->len;
3499 for (i = 0; i < len; i++) {
3500 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
3508 request_pt_map (GstElement * manager, guint session, guint pt, GstRTSPSrc * src)
3510 GstRTSPStream *stream;
3513 GST_DEBUG_OBJECT (src, "getting pt map for pt %d in session %d", pt, session);
3515 GST_RTSP_STATE_LOCK (src);
3516 stream = find_stream (src, &session, (gpointer) find_stream_by_id);
3518 goto unknown_stream;
3520 if ((caps = stream_get_caps_for_pt (stream, pt)))
3521 gst_caps_ref (caps);
3522 GST_RTSP_STATE_UNLOCK (src);
3528 GST_DEBUG_OBJECT (src, "unknown stream %d", session);
3529 GST_RTSP_STATE_UNLOCK (src);
3535 gst_rtspsrc_do_stream_eos (GstRTSPSrc * src, GstRTSPStream * stream)
3537 GST_DEBUG_OBJECT (src, "setting stream for session %u to EOS", stream->id);
3543 gst_rtspsrc_stream_push_event (src, stream, gst_event_new_eos ());
3549 GST_DEBUG_OBJECT (src, "stream for session %u was already EOS", stream->id);
3555 on_bye_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
3557 GstRTSPSrc *src = stream->parent;
3560 g_object_get (source, "ssrc", &ssrc, NULL);
3562 GST_DEBUG_OBJECT (src, "source %08x, stream %08x, session %u received BYE",
3563 ssrc, stream->ssrc, stream->id);
3565 if (ssrc == stream->ssrc)
3566 gst_rtspsrc_do_stream_eos (src, stream);
3570 on_timeout_common (GObject * session, GObject * source, GstRTSPStream * stream)
3572 GstRTSPSrc *src = stream->parent;
3575 g_object_get (source, "ssrc", &ssrc, NULL);
3577 GST_WARNING_OBJECT (src, "source %08x, stream %08x in session %u timed out",
3578 ssrc, stream->ssrc, stream->id);
3580 if (ssrc == stream->ssrc)
3581 gst_rtspsrc_do_stream_eos (src, stream);
3585 on_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
3587 GstRTSPSrc *src = stream->parent;
3589 /* timeout, post element message */
3590 gst_element_post_message (GST_ELEMENT_CAST (src),
3591 gst_message_new_element (GST_OBJECT_CAST (src),
3592 gst_structure_new ("GstRTSPSrcTimeout",
3593 "cause", G_TYPE_ENUM, GST_RTSP_SRC_TIMEOUT_CAUSE_RTCP,
3594 "stream-number", G_TYPE_INT, stream->id, "ssrc", G_TYPE_UINT,
3595 stream->ssrc, NULL)));
3597 /* In non-live mode, timeouts can occur if we are PAUSED, this doesn't mean
3598 * the stream is EOS, it may simply be blocked */
3599 if (src->is_live || !src->interleaved)
3600 on_timeout_common (session, source, stream);
3604 on_npt_stop (GstElement * rtpbin, guint session, guint ssrc, GstRTSPSrc * src)
3606 GstRTSPStream *stream;
3608 GST_DEBUG_OBJECT (src, "source in session %u reached NPT stop", session);
3610 /* get stream for session */
3611 stream = find_stream (src, &session, (gpointer) find_stream_by_id);
3613 gst_rtspsrc_do_stream_eos (src, stream);
3618 on_ssrc_active (GObject * session, GObject * source, GstRTSPStream * stream)
3620 GST_DEBUG_OBJECT (stream->parent, "source in session %u is active",
3625 set_manager_buffer_mode (GstRTSPSrc * src)
3627 GObjectClass *klass;
3629 if (src->manager == NULL)
3632 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
3634 if (!g_object_class_find_property (klass, "buffer-mode"))
3637 if (src->buffer_mode != BUFFER_MODE_AUTO) {
3638 g_object_set (src->manager, "buffer-mode", src->buffer_mode, NULL);
3643 GST_DEBUG_OBJECT (src,
3644 "auto buffering mode, have clock %" GST_PTR_FORMAT, src->provided_clock);
3646 if (src->provided_clock) {
3647 GstClock *clock = gst_element_get_clock (GST_ELEMENT_CAST (src));
3649 if (clock == src->provided_clock) {
3650 GST_DEBUG_OBJECT (src, "selected synced");
3651 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_SYNCED, NULL);
3654 gst_object_unref (clock);
3659 /* Otherwise fall-through and use another buffer mode */
3661 gst_object_unref (clock);
3664 GST_DEBUG_OBJECT (src, "auto buffering mode");
3665 if (src->use_buffering) {
3666 GST_DEBUG_OBJECT (src, "selected buffer");
3667 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_BUFFER, NULL);
3669 GST_DEBUG_OBJECT (src, "selected slave");
3670 g_object_set (src->manager, "buffer-mode", BUFFER_MODE_SLAVE, NULL);
3675 request_key (GstElement * srtpdec, guint ssrc, GstRTSPStream * stream)
3679 GstMIKEYMessage *msg = stream->mikey;
3681 GST_DEBUG ("request key SSRC %u", ssrc);
3683 caps = gst_caps_ref (stream_get_caps_for_pt (stream, stream->default_pt));
3684 caps = gst_caps_make_writable (caps);
3686 /* parse crypto sessions and look for the SSRC rollover counter */
3687 msg = stream->mikey;
3688 for (i = 0; msg && i < gst_mikey_message_get_n_cs (msg); i++) {
3689 const GstMIKEYMapSRTP *map = gst_mikey_message_get_cs_srtp (msg, i);
3691 if (ssrc == map->ssrc) {
3692 gst_caps_set_simple (caps, "roc", G_TYPE_UINT, map->roc, NULL);
3701 request_rtp_decoder (GstElement * rtpbin, guint session, GstRTSPStream * stream)
3703 GST_DEBUG ("decoder session %u, stream %p, %d", session, stream, stream->id);
3704 if (stream->id != session)
3707 if (stream->profile != GST_RTSP_PROFILE_SAVP &&
3708 stream->profile != GST_RTSP_PROFILE_SAVPF)
3711 if (stream->srtpdec == NULL) {
3714 name = g_strdup_printf ("srtpdec_%u", session);
3715 stream->srtpdec = gst_element_factory_make ("srtpdec", name);
3718 if (stream->srtpdec == NULL) {
3719 GST_ELEMENT_ERROR (stream->parent, CORE, MISSING_PLUGIN, (NULL),
3720 ("no srtpdec element present!"));
3723 g_signal_connect (stream->srtpdec, "request-key",
3724 (GCallback) request_key, stream);
3726 return gst_object_ref (stream->srtpdec);
3730 request_rtcp_encoder (GstElement * rtpbin, guint session,
3731 GstRTSPStream * stream)
3736 GST_DEBUG ("decoder session %u, stream %p, %d", session, stream, stream->id);
3737 if (stream->id != session)
3740 if (stream->profile != GST_RTSP_PROFILE_SAVP &&
3741 stream->profile != GST_RTSP_PROFILE_SAVPF)
3744 if (stream->srtpenc == NULL) {
3747 name = g_strdup_printf ("srtpenc_%u", session);
3748 stream->srtpenc = gst_element_factory_make ("srtpenc", name);
3751 if (stream->srtpenc == NULL) {
3752 GST_ELEMENT_ERROR (stream->parent, CORE, MISSING_PLUGIN, (NULL),
3753 ("no srtpenc element present!"));
3757 /* get RTCP crypto parameters from caps */
3758 s = gst_caps_get_structure (stream->srtcpparams, 0);
3762 GType ciphertype, authtype;
3763 GValue rtcp_cipher = G_VALUE_INIT, rtcp_auth = G_VALUE_INIT;
3765 ciphertype = g_type_from_name ("GstSrtpCipherType");
3766 authtype = g_type_from_name ("GstSrtpAuthType");
3767 g_value_init (&rtcp_cipher, ciphertype);
3768 g_value_init (&rtcp_auth, authtype);
3770 str = gst_structure_get_string (s, "srtcp-cipher");
3771 gst_value_deserialize (&rtcp_cipher, str);
3772 str = gst_structure_get_string (s, "srtcp-auth");
3773 gst_value_deserialize (&rtcp_auth, str);
3774 gst_structure_get (s, "srtp-key", GST_TYPE_BUFFER, &buf, NULL);
3776 g_object_set_property (G_OBJECT (stream->srtpenc), "rtp-cipher",
3778 g_object_set_property (G_OBJECT (stream->srtpenc), "rtp-auth",
3780 g_object_set_property (G_OBJECT (stream->srtpenc), "rtcp-cipher",
3782 g_object_set_property (G_OBJECT (stream->srtpenc), "rtcp-auth",
3784 g_object_set (stream->srtpenc, "key", buf, NULL);
3786 g_value_unset (&rtcp_cipher);
3787 g_value_unset (&rtcp_auth);
3788 gst_buffer_unref (buf);
3791 name = g_strdup_printf ("rtcp_sink_%d", session);
3792 pad = gst_element_get_request_pad (stream->srtpenc, name);
3794 gst_object_unref (pad);
3796 return gst_object_ref (stream->srtpenc);
3800 request_aux_receiver (GstElement * rtpbin, guint sessid, GstRTSPSrc * src)
3802 GstElement *rtx, *bin;
3805 GstRTSPStream *stream;
3807 stream = find_stream (src, &sessid, (gpointer) find_stream_by_id);
3809 GST_WARNING_OBJECT (src, "Stream %u not found", sessid);
3813 GST_INFO_OBJECT (src, "creating retransmision receiver for session %u "
3814 "with map %" GST_PTR_FORMAT, sessid, stream->rtx_pt_map);
3815 bin = gst_bin_new (NULL);
3816 rtx = gst_element_factory_make ("rtprtxreceive", NULL);
3817 g_object_set (rtx, "payload-type-map", stream->rtx_pt_map, NULL);
3818 gst_bin_add (GST_BIN (bin), rtx);
3820 pad = gst_element_get_static_pad (rtx, "src");
3821 name = g_strdup_printf ("src_%u", sessid);
3822 gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
3824 gst_object_unref (pad);
3826 pad = gst_element_get_static_pad (rtx, "sink");
3827 name = g_strdup_printf ("sink_%u", sessid);
3828 gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
3830 gst_object_unref (pad);
3836 add_retransmission (GstRTSPSrc * src, GstRTSPTransport * transport)
3840 gboolean do_retransmission = FALSE;
3842 if (transport->trans != GST_RTSP_TRANS_RTP)
3844 if (transport->profile != GST_RTSP_PROFILE_AVPF &&
3845 transport->profile != GST_RTSP_PROFILE_SAVPF)
3848 signal_id = g_signal_lookup ("request-aux-receiver",
3849 G_OBJECT_TYPE (src->manager));
3850 /* there's already something connected */
3851 if (g_signal_handler_find (src->manager, G_SIGNAL_MATCH_ID, signal_id, 0,
3852 NULL, NULL, NULL) != 0) {
3853 GST_DEBUG_OBJECT (src, "Not adding RTX AUX element as "
3854 "\"request-aux-receiver\" signal is "
3855 "already used by the application");
3859 /* build the retransmission payload type map */
3860 for (walk = src->streams; walk; walk = g_list_next (walk)) {
3861 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
3862 gboolean do_retransmission_stream = FALSE;
3865 if (stream->rtx_pt_map)
3866 gst_structure_free (stream->rtx_pt_map);
3867 stream->rtx_pt_map = gst_structure_new_empty ("application/x-rtp-pt-map");
3869 for (i = 0; i < stream->ptmap->len; i++) {
3870 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
3871 GstStructure *s = gst_caps_get_structure (item->caps, 0);
3872 const gchar *encoding;
3874 /* we only care about RTX streams */
3875 if ((encoding = gst_structure_get_string (s, "encoding-name"))
3876 && g_strcmp0 (encoding, "RTX") == 0) {
3877 const gchar *stream_pt_s;
3880 if (gst_structure_get_int (s, "payload", &rtx_pt)
3881 && (stream_pt_s = gst_structure_get_string (s, "apt"))) {
3884 gst_structure_set (stream->rtx_pt_map, stream_pt_s, G_TYPE_UINT,
3886 do_retransmission_stream = TRUE;
3892 if (do_retransmission_stream) {
3893 GST_DEBUG_OBJECT (src, "built retransmission payload map for stream "
3894 "id %i: %" GST_PTR_FORMAT, stream->id, stream->rtx_pt_map);
3895 do_retransmission = TRUE;
3897 GST_DEBUG_OBJECT (src, "no retransmission payload map for stream "
3898 "id %i", stream->id);
3899 gst_structure_free (stream->rtx_pt_map);
3900 stream->rtx_pt_map = NULL;
3904 if (do_retransmission) {
3905 GST_DEBUG_OBJECT (src, "Enabling retransmissions");
3907 g_object_set (src->manager, "do-retransmission", TRUE, NULL);
3909 /* enable RFC4588 retransmission handling by setting rtprtxreceive
3910 * as the "aux" element of rtpbin */
3911 g_signal_connect (src->manager, "request-aux-receiver",
3912 (GCallback) request_aux_receiver, src);
3914 GST_DEBUG_OBJECT (src,
3915 "Not enabling retransmissions as no stream had a retransmission payload map");
3919 /* try to get and configure a manager */
3921 gst_rtspsrc_stream_configure_manager (GstRTSPSrc * src, GstRTSPStream * stream,
3922 GstRTSPTransport * transport)
3924 const gchar *manager;
3926 GstStateChangeReturn ret;
3929 goto use_no_manager;
3931 /* find a manager */
3932 if (gst_rtsp_transport_get_manager (transport->trans, &manager, 0) < 0)
3936 GST_DEBUG_OBJECT (src, "using manager %s", manager);
3938 /* configure the manager */
3939 if (src->manager == NULL) {
3940 GObjectClass *klass;
3942 if (!(src->manager = gst_element_factory_make (manager, "manager"))) {
3944 if (gst_rtsp_transport_get_manager (transport->trans, &manager, 1) < 0)
3948 goto use_no_manager;
3950 if (!(src->manager = gst_element_factory_make (manager, "manager")))
3951 goto manager_failed;
3954 /* we manage this element */
3955 gst_element_set_locked_state (src->manager, TRUE);
3956 gst_bin_add (GST_BIN_CAST (src), src->manager);
3958 ret = gst_element_set_state (src->manager, GST_STATE_PAUSED);
3959 if (ret == GST_STATE_CHANGE_FAILURE)
3960 goto start_manager_failure;
3962 g_object_set (src->manager, "latency", src->latency, NULL);
3964 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
3966 if (g_object_class_find_property (klass, "ntp-sync")) {
3967 g_object_set (src->manager, "ntp-sync", src->ntp_sync, NULL);
3970 if (g_object_class_find_property (klass, "rfc7273-sync")) {
3971 g_object_set (src->manager, "rfc7273-sync", src->rfc7273_sync, NULL);
3974 if (src->use_pipeline_clock) {
3975 if (g_object_class_find_property (klass, "use-pipeline-clock")) {
3976 g_object_set (src->manager, "use-pipeline-clock", TRUE, NULL);
3979 if (g_object_class_find_property (klass, "ntp-time-source")) {
3980 g_object_set (src->manager, "ntp-time-source", src->ntp_time_source,
3985 if (src->sdes && g_object_class_find_property (klass, "sdes")) {
3986 g_object_set (src->manager, "sdes", src->sdes, NULL);
3989 if (g_object_class_find_property (klass, "drop-on-latency")) {
3990 g_object_set (src->manager, "drop-on-latency", src->drop_on_latency,
3994 if (g_object_class_find_property (klass, "max-rtcp-rtp-time-diff")) {
3995 g_object_set (src->manager, "max-rtcp-rtp-time-diff",
3996 src->max_rtcp_rtp_time_diff, NULL);
3999 if (g_object_class_find_property (klass, "max-ts-offset-adjustment")) {
4000 g_object_set (src->manager, "max-ts-offset-adjustment",
4001 src->max_ts_offset_adjustment, NULL);
4004 if (g_object_class_find_property (klass, "max-ts-offset")) {
4005 gint64 max_ts_offset;
4007 /* setting max-ts-offset in the manager has side effects so only do it
4008 * if the value differs */
4009 g_object_get (src->manager, "max-ts-offset", &max_ts_offset, NULL);
4010 if (max_ts_offset != src->max_ts_offset) {
4011 g_object_set (src->manager, "max-ts-offset", src->max_ts_offset,
4016 /* buffer mode pauses are handled by adding offsets to buffer times,
4017 * but some depayloaders may have a hard time syncing output times
4018 * with such input times, e.g. container ones, most notably ASF */
4019 /* TODO alternatives are having an event that indicates these shifts,
4020 * or having rtsp extensions provide suggestion on buffer mode */
4021 /* valid duration implies not likely live pipeline,
4022 * so slaving in jitterbuffer does not make much sense
4023 * (and might mess things up due to bursts) */
4024 if (GST_CLOCK_TIME_IS_VALID (src->segment.duration) &&
4025 src->segment.duration && stream->container) {
4026 src->use_buffering = TRUE;
4028 src->use_buffering = FALSE;
4031 set_manager_buffer_mode (src);
4033 /* connect to signals */
4034 GST_DEBUG_OBJECT (src, "connect to signals on session manager, stream %p",
4036 src->manager_sig_id =
4037 g_signal_connect (src->manager, "pad-added",
4038 (GCallback) new_manager_pad, src);
4039 src->manager_ptmap_id =
4040 g_signal_connect (src->manager, "request-pt-map",
4041 (GCallback) request_pt_map, src);
4043 g_signal_connect (src->manager, "on-npt-stop", (GCallback) on_npt_stop,
4046 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_NEW_MANAGER], 0,
4049 if (src->do_retransmission)
4050 add_retransmission (src, transport);
4052 g_signal_connect (src->manager, "request-rtp-decoder",
4053 (GCallback) request_rtp_decoder, stream);
4054 g_signal_connect (src->manager, "request-rtcp-decoder",
4055 (GCallback) request_rtp_decoder, stream);
4056 g_signal_connect (src->manager, "request-rtcp-encoder",
4057 (GCallback) request_rtcp_encoder, stream);
4059 /* we stream directly to the manager, get some pads. Each RTSP stream goes
4060 * into a separate RTP session. */
4061 name = g_strdup_printf ("recv_rtp_sink_%u", stream->id);
4062 stream->channelpad[0] = gst_element_get_request_pad (src->manager, name);
4064 name = g_strdup_printf ("recv_rtcp_sink_%u", stream->id);
4065 stream->channelpad[1] = gst_element_get_request_pad (src->manager, name);
4068 /* now configure the bandwidth in the manager */
4069 if (g_signal_lookup ("get-internal-session",
4070 G_OBJECT_TYPE (src->manager)) != 0) {
4071 GObject *rtpsession;
4073 g_signal_emit_by_name (src->manager, "get-internal-session", stream->id,
4076 GstRTPProfile rtp_profile;
4078 GST_INFO_OBJECT (src, "configure bandwidth in session %p", rtpsession);
4080 stream->session = rtpsession;
4082 if (stream->as_bandwidth != -1) {
4083 GST_INFO_OBJECT (src, "setting AS: %f",
4084 (gdouble) (stream->as_bandwidth * 1000));
4085 g_object_set (rtpsession, "bandwidth",
4086 (gdouble) (stream->as_bandwidth * 1000), NULL);
4088 if (stream->rr_bandwidth != -1) {
4089 GST_INFO_OBJECT (src, "setting RR: %u", stream->rr_bandwidth);
4090 g_object_set (rtpsession, "rtcp-rr-bandwidth", stream->rr_bandwidth,
4093 if (stream->rs_bandwidth != -1) {
4094 GST_INFO_OBJECT (src, "setting RS: %u", stream->rs_bandwidth);
4095 g_object_set (rtpsession, "rtcp-rs-bandwidth", stream->rs_bandwidth,
4099 switch (stream->profile) {
4100 case GST_RTSP_PROFILE_AVPF:
4101 rtp_profile = GST_RTP_PROFILE_AVPF;
4103 case GST_RTSP_PROFILE_SAVP:
4104 rtp_profile = GST_RTP_PROFILE_SAVP;
4106 case GST_RTSP_PROFILE_SAVPF:
4107 rtp_profile = GST_RTP_PROFILE_SAVPF;
4109 case GST_RTSP_PROFILE_AVP:
4111 rtp_profile = GST_RTP_PROFILE_AVP;
4115 g_object_set (rtpsession, "rtp-profile", rtp_profile, NULL);
4117 g_object_set (rtpsession, "probation", src->probation, NULL);
4119 g_object_set (rtpsession, "internal-ssrc", stream->send_ssrc, NULL);
4121 g_signal_connect (rtpsession, "on-bye-ssrc", (GCallback) on_bye_ssrc,
4123 g_signal_connect (rtpsession, "on-bye-timeout",
4124 (GCallback) on_timeout_common, stream);
4125 g_signal_connect (rtpsession, "on-timeout", (GCallback) on_timeout,
4127 g_signal_connect (rtpsession, "on-ssrc-active",
4128 (GCallback) on_ssrc_active, stream);
4139 GST_DEBUG_OBJECT (src, "cannot get a session manager");
4144 GST_DEBUG_OBJECT (src, "no session manager element %s found", manager);
4147 start_manager_failure:
4149 GST_DEBUG_OBJECT (src, "could not start session manager");
4154 /* free the UDP sources allocated when negotiating a transport.
4155 * This function is called when the server negotiated to a transport where the
4156 * UDP sources are not needed anymore, such as TCP or multicast. */
4158 gst_rtspsrc_stream_free_udp (GstRTSPStream * stream)
4162 for (i = 0; i < 2; i++) {
4163 if (stream->udpsrc[i]) {
4164 GST_DEBUG ("free UDP source %d for stream %p", i, stream);
4165 gst_element_set_state (stream->udpsrc[i], GST_STATE_NULL);
4166 gst_object_unref (stream->udpsrc[i]);
4167 stream->udpsrc[i] = NULL;
4172 /* for TCP, create pads to send and receive data to and from the manager and to
4173 * intercept various events and queries
4176 gst_rtspsrc_stream_configure_tcp (GstRTSPSrc * src, GstRTSPStream * stream,
4177 GstRTSPTransport * transport, GstPad ** outpad)
4180 GstPadTemplate *template;
4181 GstPad *pad0, *pad1;
4183 /* configure for interleaved delivery, nothing needs to be done
4184 * here, the loop function will call the chain functions of the
4185 * session manager. */
4186 stream->channel[0] = transport->interleaved.min;
4187 stream->channel[1] = transport->interleaved.max;
4188 GST_DEBUG_OBJECT (src, "stream %p on channels %d-%d", stream,
4189 stream->channel[0], stream->channel[1]);
4191 /* we can remove the allocated UDP ports now */
4192 gst_rtspsrc_stream_free_udp (stream);
4194 /* no session manager, send data to srcpad directly */
4195 if (!stream->channelpad[0]) {
4196 GST_DEBUG_OBJECT (src, "no manager, creating pad");
4198 /* create a new pad we will use to stream to */
4199 name = g_strdup_printf ("stream_%u", stream->id);
4200 template = gst_static_pad_template_get (&rtptemplate);
4201 stream->channelpad[0] = gst_pad_new_from_template (template, name);
4202 gst_object_unref (template);
4205 /* set caps and activate */
4206 gst_pad_use_fixed_caps (stream->channelpad[0]);
4207 gst_pad_set_active (stream->channelpad[0], TRUE);
4209 *outpad = gst_object_ref (stream->channelpad[0]);
4211 GST_DEBUG_OBJECT (src, "using manager source pad");
4213 template = gst_static_pad_template_get (&anysrctemplate);
4215 /* allocate pads for sending the channel data into the manager */
4216 pad0 = gst_pad_new_from_template (template, "internalsrc_0");
4217 gst_pad_link_full (pad0, stream->channelpad[0], GST_PAD_LINK_CHECK_NOTHING);
4218 gst_object_unref (stream->channelpad[0]);
4219 stream->channelpad[0] = pad0;
4220 gst_pad_set_event_function (pad0, gst_rtspsrc_handle_internal_src_event);
4221 gst_pad_set_query_function (pad0, gst_rtspsrc_handle_internal_src_query);
4222 gst_pad_set_element_private (pad0, src);
4223 gst_pad_set_active (pad0, TRUE);
4225 if (stream->channelpad[1]) {
4226 /* if we have a sinkpad for the other channel, create a pad and link to the
4228 pad1 = gst_pad_new_from_template (template, "internalsrc_1");
4229 gst_pad_set_event_function (pad1, gst_rtspsrc_handle_internal_src_event);
4230 gst_pad_link_full (pad1, stream->channelpad[1],
4231 GST_PAD_LINK_CHECK_NOTHING);
4232 gst_object_unref (stream->channelpad[1]);
4233 stream->channelpad[1] = pad1;
4234 gst_pad_set_active (pad1, TRUE);
4236 gst_object_unref (template);
4238 /* setup RTCP transport back to the server if we have to. */
4239 if (src->manager && src->do_rtcp) {
4242 template = gst_static_pad_template_get (&anysinktemplate);
4244 stream->rtcppad = gst_pad_new_from_template (template, "internalsink_0");
4245 gst_pad_set_chain_function (stream->rtcppad, gst_rtspsrc_sink_chain);
4246 gst_pad_set_element_private (stream->rtcppad, stream);
4247 gst_pad_set_active (stream->rtcppad, TRUE);
4249 /* get session RTCP pad */
4250 name = g_strdup_printf ("send_rtcp_src_%u", stream->id);
4251 pad = gst_element_get_request_pad (src->manager, name);
4256 gst_pad_link_full (pad, stream->rtcppad, GST_PAD_LINK_CHECK_NOTHING);
4257 gst_object_unref (pad);
4260 gst_object_unref (template);
4266 gst_rtspsrc_get_transport_info (GstRTSPSrc * src, GstRTSPStream * stream,
4267 GstRTSPTransport * transport, const gchar ** destination, gint * min,
4268 gint * max, guint * ttl)
4270 if (transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
4272 if (!(*destination = transport->destination))
4273 *destination = stream->destination;
4276 /* transport first */
4277 *min = transport->port.min;
4278 *max = transport->port.max;
4279 if (*min == -1 && *max == -1) {
4280 /* then try from SDP */
4281 if (stream->port != 0) {
4282 *min = stream->port;
4283 *max = stream->port + 1;
4289 if (!(*ttl = transport->ttl))
4294 /* first take the source, then the endpoint to figure out where to send
4296 if (!(*destination = transport->source)) {
4297 if (src->conninfo.connection)
4298 *destination = gst_rtsp_connection_get_ip (src->conninfo.connection);
4299 else if (stream->conninfo.connection)
4301 gst_rtsp_connection_get_ip (stream->conninfo.connection);
4305 /* for unicast we only expect the ports here */
4306 *min = transport->server_port.min;
4307 *max = transport->server_port.max;
4312 /* For multicast create UDP sources and join the multicast group. */
4314 gst_rtspsrc_stream_configure_mcast (GstRTSPSrc * src, GstRTSPStream * stream,
4315 GstRTSPTransport * transport, GstPad ** outpad)
4318 const gchar *destination;
4321 GST_DEBUG_OBJECT (src, "creating UDP sources for multicast");
4323 /* we can remove the allocated UDP ports now */
4324 gst_rtspsrc_stream_free_udp (stream);
4326 gst_rtspsrc_get_transport_info (src, stream, transport, &destination, &min,
4329 /* we need a destination now */
4330 if (destination == NULL)
4331 goto no_destination;
4333 /* we really need ports now or we won't be able to receive anything at all */
4334 if (min == -1 && max == -1)
4337 GST_DEBUG_OBJECT (src, "have destination '%s' and ports (%d)-(%d)",
4338 destination, min, max);
4340 /* creating UDP source for RTP */
4342 uri = g_strdup_printf ("udp://%s:%d", destination, min);
4344 gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
4346 if (stream->udpsrc[0] == NULL)
4349 /* take ownership */
4350 gst_object_ref_sink (stream->udpsrc[0]);
4352 if (src->udp_buffer_size != 0)
4353 g_object_set (G_OBJECT (stream->udpsrc[0]), "buffer-size",
4354 src->udp_buffer_size, NULL);
4356 if (src->multi_iface != NULL)
4357 g_object_set (G_OBJECT (stream->udpsrc[0]), "multicast-iface",
4358 src->multi_iface, NULL);
4361 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
4362 gst_element_set_state (stream->udpsrc[0], GST_STATE_READY);
4365 /* creating another UDP source for RTCP */
4369 uri = g_strdup_printf ("udp://%s:%d", destination, max);
4371 gst_element_make_from_uri (GST_URI_SRC, uri, NULL, NULL);
4373 if (stream->udpsrc[1] == NULL)
4376 if (stream->profile == GST_RTSP_PROFILE_SAVP ||
4377 stream->profile == GST_RTSP_PROFILE_SAVPF)
4378 caps = gst_caps_new_empty_simple ("application/x-srtcp");
4380 caps = gst_caps_new_empty_simple ("application/x-rtcp");
4381 g_object_set (stream->udpsrc[1], "caps", caps, NULL);
4382 gst_caps_unref (caps);
4384 /* take ownership */
4385 gst_object_ref_sink (stream->udpsrc[1]);
4387 if (src->multi_iface != NULL)
4388 g_object_set (G_OBJECT (stream->udpsrc[1]), "multicast-iface",
4389 src->multi_iface, NULL);
4391 gst_element_set_state (stream->udpsrc[1], GST_STATE_READY);
4398 GST_DEBUG_OBJECT (src, "no UDP source element found");
4403 GST_DEBUG_OBJECT (src, "no destination found");
4408 GST_DEBUG_OBJECT (src, "no ports found");
4413 /* configure the remainder of the UDP ports */
4415 gst_rtspsrc_stream_configure_udp (GstRTSPSrc * src, GstRTSPStream * stream,
4416 GstRTSPTransport * transport, GstPad ** outpad)
4418 /* we manage the UDP elements now. For unicast, the UDP sources where
4419 * allocated in the stream when we suggested a transport. */
4420 if (stream->udpsrc[0]) {
4423 gst_element_set_locked_state (stream->udpsrc[0], TRUE);
4424 gst_bin_add (GST_BIN_CAST (src), stream->udpsrc[0]);
4426 GST_DEBUG_OBJECT (src, "setting up UDP source");
4428 /* configure a timeout on the UDP port. When the timeout message is
4429 * posted, we assume UDP transport is not possible. We reconnect using TCP
4431 g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout",
4432 src->udp_timeout * 1000, NULL);
4434 if ((caps = stream_get_caps_for_pt (stream, stream->default_pt)))
4435 g_object_set (stream->udpsrc[0], "caps", caps, NULL);
4437 /* get output pad of the UDP source. */
4438 *outpad = gst_element_get_static_pad (stream->udpsrc[0], "src");
4440 /* save it so we can unblock */
4441 stream->blockedpad = *outpad;
4443 /* configure pad block on the pad. As soon as there is dataflow on the
4444 * UDP source, we know that UDP is not blocked by a firewall and we can
4445 * configure all the streams to let the application autoplug decoders. */
4447 gst_pad_add_probe (stream->blockedpad,
4448 GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER |
4449 GST_PAD_PROBE_TYPE_BUFFER_LIST, pad_blocked, src, NULL);
4451 gst_pad_add_probe (stream->blockedpad,
4452 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, udpsrc_probe_cb,
4453 &(stream->segment_seqnum[0]), NULL);
4455 if (stream->channelpad[0]) {
4456 GST_DEBUG_OBJECT (src, "connecting UDP source 0 to manager");
4457 /* configure for UDP delivery, we need to connect the UDP pads to
4458 * the session plugin. */
4459 gst_pad_link_full (*outpad, stream->channelpad[0],
4460 GST_PAD_LINK_CHECK_NOTHING);
4461 gst_object_unref (*outpad);
4463 /* we connected to pad-added signal to get pads from the manager */
4465 GST_DEBUG_OBJECT (src, "using UDP src pad as output");
4470 if (stream->udpsrc[1]) {
4473 gst_element_set_locked_state (stream->udpsrc[1], TRUE);
4474 gst_bin_add (GST_BIN_CAST (src), stream->udpsrc[1]);
4476 if (stream->profile == GST_RTSP_PROFILE_SAVP ||
4477 stream->profile == GST_RTSP_PROFILE_SAVPF)
4478 caps = gst_caps_new_empty_simple ("application/x-srtcp");
4480 caps = gst_caps_new_empty_simple ("application/x-rtcp");
4481 g_object_set (stream->udpsrc[1], "caps", caps, NULL);
4482 gst_caps_unref (caps);
4484 if (stream->channelpad[1]) {
4487 GST_DEBUG_OBJECT (src, "connecting UDP source 1 to manager");
4489 pad = gst_element_get_static_pad (stream->udpsrc[1], "src");
4490 gst_pad_add_probe (pad,
4491 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, udpsrc_probe_cb,
4492 &(stream->segment_seqnum[1]), NULL);
4493 gst_pad_link_full (pad, stream->channelpad[1],
4494 GST_PAD_LINK_CHECK_NOTHING);
4495 gst_object_unref (pad);
4497 /* leave unlinked */
4503 /* configure the UDP sink back to the server for status reports */
4505 gst_rtspsrc_stream_configure_udp_sinks (GstRTSPSrc * src,
4506 GstRTSPStream * stream, GstRTSPTransport * transport)
4509 gint rtp_port, rtcp_port;
4510 gboolean do_rtp, do_rtcp;
4511 const gchar *destination;
4516 /* get transport info */
4517 gst_rtspsrc_get_transport_info (src, stream, transport, &destination,
4518 &rtp_port, &rtcp_port, &ttl);
4520 /* see what we need to do */
4521 do_rtp = (rtp_port != -1);
4522 /* it's possible that the server does not want us to send RTCP in which case
4524 do_rtcp = (rtcp_port != -1 && src->manager != NULL && src->do_rtcp);
4526 /* we need a destination when we have RTP or RTCP ports */
4527 if (destination == NULL && (do_rtp || do_rtcp))
4528 goto no_destination;
4530 /* try to construct the fakesrc to the RTP port of the server to open up any
4531 * NAT firewalls or, if backchannel, construct an appsrc */
4533 GST_DEBUG_OBJECT (src, "configure RTP UDP sink for %s:%d", destination,
4536 uri = g_strdup_printf ("udp://%s:%d", destination, rtp_port);
4537 stream->udpsink[0] =
4538 gst_element_make_from_uri (GST_URI_SINK, uri, NULL, NULL);
4540 if (stream->udpsink[0] == NULL)
4541 goto no_sink_element;
4543 /* don't join multicast group, we will have the source socket do that */
4544 /* no sync or async state changes needed */
4545 g_object_set (G_OBJECT (stream->udpsink[0]), "auto-multicast", FALSE,
4546 "loop", FALSE, "sync", FALSE, "async", FALSE, NULL);
4548 g_object_set (G_OBJECT (stream->udpsink[0]), "ttl", ttl, NULL);
4550 if (stream->udpsrc[0]) {
4551 /* configure socket, we give it the same UDP socket as the udpsrc for RTP
4552 * so that NAT firewalls will open a hole for us */
4553 g_object_get (G_OBJECT (stream->udpsrc[0]), "used-socket", &socket, NULL);
4557 GST_DEBUG_OBJECT (src, "RTP UDP src has sock %p", socket);
4558 /* configure socket and make sure udpsink does not close it when shutting
4559 * down, it belongs to udpsrc after all. */
4560 g_object_set (G_OBJECT (stream->udpsink[0]), "socket", socket,
4561 "close-socket", FALSE, NULL);
4562 g_object_unref (socket);
4565 if (stream->is_backchannel) {
4566 /* appsrc is for the app to shovel data using push-backchannel-buffer */
4567 stream->rtpsrc = gst_element_factory_make ("appsrc", NULL);
4568 if (stream->rtpsrc == NULL)
4569 goto no_appsrc_element;
4571 /* interal use only, don't emit signals */
4572 g_object_set (G_OBJECT (stream->rtpsrc), "emit-signals", TRUE,
4573 "is-live", TRUE, NULL);
4575 /* the source for the dummy packets to open up NAT */
4576 stream->rtpsrc = gst_element_factory_make ("fakesrc", NULL);
4577 if (stream->rtpsrc == NULL)
4578 goto no_fakesrc_element;
4580 /* random data in 5 buffers, a size of 200 bytes should be fine */
4581 g_object_set (G_OBJECT (stream->rtpsrc), "filltype", 3, "num-buffers", 5,
4582 "sizetype", 2, "sizemax", 200, "silent", TRUE, NULL);
4585 /* keep everything locked */
4586 gst_element_set_locked_state (stream->udpsink[0], TRUE);
4587 gst_element_set_locked_state (stream->rtpsrc, TRUE);
4589 gst_object_ref (stream->udpsink[0]);
4590 gst_bin_add (GST_BIN_CAST (src), stream->udpsink[0]);
4591 gst_object_ref (stream->rtpsrc);
4592 gst_bin_add (GST_BIN_CAST (src), stream->rtpsrc);
4594 gst_element_link_pads_full (stream->rtpsrc, "src", stream->udpsink[0],
4595 "sink", GST_PAD_LINK_CHECK_NOTHING);
4598 GST_DEBUG_OBJECT (src, "configure RTCP UDP sink for %s:%d", destination,
4601 uri = g_strdup_printf ("udp://%s:%d", destination, rtcp_port);
4602 stream->udpsink[1] =
4603 gst_element_make_from_uri (GST_URI_SINK, uri, NULL, NULL);
4605 if (stream->udpsink[1] == NULL)
4606 goto no_sink_element;
4608 /* don't join multicast group, we will have the source socket do that */
4609 /* no sync or async state changes needed */
4610 g_object_set (G_OBJECT (stream->udpsink[1]), "auto-multicast", FALSE,
4611 "loop", FALSE, "sync", FALSE, "async", FALSE, NULL);
4613 g_object_set (G_OBJECT (stream->udpsink[0]), "ttl", ttl, NULL);
4615 if (stream->udpsrc[1]) {
4616 /* configure socket, we give it the same UDP socket as the udpsrc for RTCP
4617 * because some servers check the port number of where it sends RTCP to identify
4618 * the RTCP packets it receives */
4619 g_object_get (G_OBJECT (stream->udpsrc[1]), "used-socket", &socket, NULL);
4623 GST_DEBUG_OBJECT (src, "RTCP UDP src has sock %p", socket);
4624 /* configure socket and make sure udpsink does not close it when shutting
4625 * down, it belongs to udpsrc after all. */
4626 g_object_set (G_OBJECT (stream->udpsink[1]), "socket", socket,
4627 "close-socket", FALSE, NULL);
4628 g_object_unref (socket);
4631 /* we keep this playing always */
4632 gst_element_set_locked_state (stream->udpsink[1], TRUE);
4633 gst_element_set_state (stream->udpsink[1], GST_STATE_PLAYING);
4635 gst_object_ref (stream->udpsink[1]);
4636 gst_bin_add (GST_BIN_CAST (src), stream->udpsink[1]);
4638 stream->rtcppad = gst_element_get_static_pad (stream->udpsink[1], "sink");
4640 /* get session RTCP pad */
4641 name = g_strdup_printf ("send_rtcp_src_%u", stream->id);
4642 pad = gst_element_get_request_pad (src->manager, name);
4647 gst_pad_link_full (pad, stream->rtcppad, GST_PAD_LINK_CHECK_NOTHING);
4648 gst_object_unref (pad);
4657 GST_ERROR_OBJECT (src, "no destination address specified");
4662 GST_ERROR_OBJECT (src, "no UDP sink element found");
4667 GST_ERROR_OBJECT (src, "no appsrc element found");
4672 GST_ERROR_OBJECT (src, "no fakesrc element found");
4677 GST_ERROR_OBJECT (src, "failed to create socket");
4682 /* sets up all elements needed for streaming over the specified transport.
4683 * Does not yet expose the element pads, this will be done when there is actuall
4684 * dataflow detected, which might never happen when UDP is blocked in a
4685 * firewall, for example.
4688 gst_rtspsrc_stream_configure_transport (GstRTSPStream * stream,
4689 GstRTSPTransport * transport)
4692 GstPad *outpad = NULL;
4693 GstPadTemplate *template;
4695 const gchar *media_type;
4698 src = stream->parent;
4700 GST_DEBUG_OBJECT (src, "configuring transport for stream %p", stream);
4702 /* get the proper media type for this stream now */
4703 if (gst_rtsp_transport_get_media_type (transport, &media_type) < 0)
4704 goto unknown_transport;
4706 goto unknown_transport;
4708 /* configure the final media type */
4709 GST_DEBUG_OBJECT (src, "setting media type to %s", media_type);
4711 len = stream->ptmap->len;
4712 for (i = 0; i < len; i++) {
4714 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
4716 if (item->caps == NULL)
4719 s = gst_caps_get_structure (item->caps, 0);
4720 gst_structure_set_name (s, media_type);
4721 /* set ssrc if known */
4722 if (transport->ssrc)
4723 gst_structure_set (s, "ssrc", G_TYPE_UINT, transport->ssrc, NULL);
4726 /* try to get and configure a manager, channelpad[0-1] will be configured with
4727 * the pads for the manager, or NULL when no manager is needed. */
4728 if (!gst_rtspsrc_stream_configure_manager (src, stream, transport))
4731 switch (transport->lower_transport) {
4732 case GST_RTSP_LOWER_TRANS_TCP:
4733 if (!gst_rtspsrc_stream_configure_tcp (src, stream, transport, &outpad))
4734 goto transport_failed;
4736 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
4737 if (!gst_rtspsrc_stream_configure_mcast (src, stream, transport, &outpad))
4738 goto transport_failed;
4739 /* fallthrough, the rest is the same for UDP and MCAST */
4740 case GST_RTSP_LOWER_TRANS_UDP:
4741 if (!gst_rtspsrc_stream_configure_udp (src, stream, transport, &outpad))
4742 goto transport_failed;
4743 /* configure udpsinks back to the server for RTCP messages, for the
4744 * dummy RTP messages to open NAT, and for the backchannel */
4745 if (!gst_rtspsrc_stream_configure_udp_sinks (src, stream, transport))
4746 goto transport_failed;
4749 goto unknown_transport;
4752 /* using backchannel and no manager, hence no srcpad for this stream */
4753 if (outpad && stream->is_backchannel) {
4754 add_backchannel_fakesink (src, stream, outpad);
4755 gst_object_unref (outpad);
4756 } else if (outpad) {
4757 GST_DEBUG_OBJECT (src, "creating ghostpad for stream %p", stream);
4759 gst_pad_use_fixed_caps (outpad);
4761 /* create ghostpad, don't add just yet, this will be done when we activate
4763 name = g_strdup_printf ("stream_%u", stream->id);
4764 template = gst_static_pad_template_get (&rtptemplate);
4765 stream->srcpad = gst_ghost_pad_new_from_template (name, outpad, template);
4766 gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
4767 gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
4768 gst_object_unref (template);
4771 gst_object_unref (outpad);
4773 /* mark pad as ok */
4774 stream->last_ret = GST_FLOW_OK;
4781 GST_WARNING_OBJECT (src, "failed to configure transport");
4786 GST_WARNING_OBJECT (src, "unknown transport");
4791 GST_WARNING_OBJECT (src, "cannot get a session manager");
4796 /* send a couple of dummy random packets on the receiver RTP port to the server,
4797 * this should make a firewall think we initiated the data transfer and
4798 * hopefully allow packets to go from the sender port to our RTP receiver port */
4800 gst_rtspsrc_send_dummy_packets (GstRTSPSrc * src)
4804 if (src->nat_method != GST_RTSP_NAT_DUMMY)
4807 for (walk = src->streams; walk; walk = g_list_next (walk)) {
4808 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
4810 if (!stream->rtpsrc || !stream->udpsink[0])
4813 if (stream->is_backchannel)
4814 GST_DEBUG_OBJECT (src, "starting backchannel stream %p", stream);
4816 GST_DEBUG_OBJECT (src, "sending dummy packet to stream %p", stream);
4818 gst_element_set_state (stream->udpsink[0], GST_STATE_NULL);
4819 gst_element_set_state (stream->rtpsrc, GST_STATE_NULL);
4820 gst_element_set_state (stream->udpsink[0], GST_STATE_PLAYING);
4821 gst_element_set_state (stream->rtpsrc, GST_STATE_PLAYING);
4826 /* Adds the source pads of all configured streams to the element.
4827 * This code is performed when we detected dataflow.
4829 * We detect dataflow from either the _loop function or with pad probes on the
4833 gst_rtspsrc_activate_streams (GstRTSPSrc * src)
4837 GST_DEBUG_OBJECT (src, "activating streams");
4839 for (walk = src->streams; walk; walk = g_list_next (walk)) {
4840 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
4842 if (stream->udpsrc[0]) {
4843 /* remove timeout, we are streaming now and timeouts will be handled by
4844 * the session manager and jitter buffer */
4845 g_object_set (G_OBJECT (stream->udpsrc[0]), "timeout", (guint64) 0, NULL);
4847 if (stream->srcpad) {
4848 GST_DEBUG_OBJECT (src, "activating stream pad %p", stream);
4849 gst_pad_set_active (stream->srcpad, TRUE);
4851 /* if we don't have a session manager, set the caps now. If we have a
4852 * session, we will get a notification of the pad and the caps. */
4853 if (!src->manager) {
4856 caps = stream_get_caps_for_pt (stream, stream->default_pt);
4857 GST_DEBUG_OBJECT (src, "setting pad caps for stream %p", stream);
4858 gst_pad_set_caps (stream->srcpad, caps);
4861 if (!stream->added) {
4862 GST_DEBUG_OBJECT (src, "adding stream pad %p", stream);
4863 if (stream->is_backchannel)
4864 add_backchannel_fakesink (src, stream, stream->srcpad);
4866 gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
4867 stream->added = TRUE;
4872 /* unblock all pads */
4873 for (walk = src->streams; walk; walk = g_list_next (walk)) {
4874 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
4876 if (stream->blockid) {
4877 GST_DEBUG_OBJECT (src, "unblocking stream pad %p", stream);
4878 gst_pad_remove_probe (stream->blockedpad, stream->blockid);
4879 stream->blockid = 0;
4887 gst_rtspsrc_configure_caps (GstRTSPSrc * src, GstSegment * segment,
4888 gboolean reset_manager)
4891 guint64 start, stop;
4892 gdouble play_speed, play_scale;
4894 GST_DEBUG_OBJECT (src, "configuring stream caps");
4896 start = segment->rate > 0.0 ? segment->start : segment->stop;
4897 stop = segment->rate > 0.0 ? segment->stop : segment->start;
4898 play_speed = segment->rate;
4899 play_scale = segment->applied_rate;
4901 for (walk = src->streams; walk; walk = g_list_next (walk)) {
4902 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
4908 len = stream->ptmap->len;
4909 for (j = 0; j < len; j++) {
4911 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, j);
4913 if (item->caps == NULL)
4916 caps = gst_caps_make_writable (item->caps);
4918 if (stream->timebase != -1)
4919 gst_caps_set_simple (caps, "clock-base", G_TYPE_UINT,
4920 (guint) stream->timebase, NULL);
4921 if (stream->seqbase != -1)
4922 gst_caps_set_simple (caps, "seqnum-base", G_TYPE_UINT,
4923 (guint) stream->seqbase, NULL);
4924 gst_caps_set_simple (caps, "npt-start", G_TYPE_UINT64, start, NULL);
4926 gst_caps_set_simple (caps, "npt-stop", G_TYPE_UINT64, stop, NULL);
4927 gst_caps_set_simple (caps, "play-speed", G_TYPE_DOUBLE, play_speed, NULL);
4928 gst_caps_set_simple (caps, "play-scale", G_TYPE_DOUBLE, play_scale, NULL);
4929 gst_caps_set_simple (caps, "onvif-mode", G_TYPE_BOOLEAN, src->onvif_mode,
4933 GST_DEBUG_OBJECT (src, "stream %p, pt %d, caps %" GST_PTR_FORMAT, stream,
4936 if (item->pt == stream->default_pt) {
4937 if (stream->udpsrc[0])
4938 g_object_set (stream->udpsrc[0], "caps", caps, NULL);
4939 stream->need_caps = TRUE;
4943 if (reset_manager && src->manager) {
4944 GST_DEBUG_OBJECT (src, "clear session");
4945 g_signal_emit_by_name (src->manager, "clear-pt-map", NULL);
4949 static GstFlowReturn
4950 gst_rtspsrc_combine_flows (GstRTSPSrc * src, GstRTSPStream * stream,
4955 /* store the value */
4956 stream->last_ret = ret;
4958 /* if it's success we can return the value right away */
4959 if (ret == GST_FLOW_OK)
4962 /* any other error that is not-linked can be returned right
4964 if (ret != GST_FLOW_NOT_LINKED)
4967 /* only return NOT_LINKED if all other pads returned NOT_LINKED */
4968 for (streams = src->streams; streams; streams = g_list_next (streams)) {
4969 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
4971 ret = ostream->last_ret;
4972 /* some other return value (must be SUCCESS but we can return
4973 * other values as well) */
4974 if (ret != GST_FLOW_NOT_LINKED)
4977 /* if we get here, all other pads were unlinked and we return
4978 * NOT_LINKED then */
4984 gst_rtspsrc_stream_push_event (GstRTSPSrc * src, GstRTSPStream * stream,
4987 gboolean res = TRUE;
4989 /* only streams that have a connection to the outside world */
4993 if (stream->udpsrc[0]) {
4994 GstEvent *sent_event;
4996 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
4997 sent_event = gst_event_new_eos ();
4998 gst_event_set_seqnum (sent_event, stream->segment_seqnum[0]);
5000 sent_event = gst_event_ref (event);
5003 res = gst_element_send_event (stream->udpsrc[0], sent_event);
5004 } else if (stream->channelpad[0]) {
5005 gst_event_ref (event);
5006 if (GST_PAD_IS_SRC (stream->channelpad[0]))
5007 res = gst_pad_push_event (stream->channelpad[0], event);
5009 res = gst_pad_send_event (stream->channelpad[0], event);
5012 if (stream->udpsrc[1]) {
5013 GstEvent *sent_event;
5015 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
5016 sent_event = gst_event_new_eos ();
5017 if (stream->segment_seqnum[1] != GST_SEQNUM_INVALID) {
5018 gst_event_set_seqnum (sent_event, stream->segment_seqnum[1]);
5021 sent_event = gst_event_ref (event);
5024 res &= gst_element_send_event (stream->udpsrc[1], sent_event);
5025 } else if (stream->channelpad[1]) {
5026 gst_event_ref (event);
5027 if (GST_PAD_IS_SRC (stream->channelpad[1]))
5028 res &= gst_pad_push_event (stream->channelpad[1], event);
5030 res &= gst_pad_send_event (stream->channelpad[1], event);
5034 gst_event_unref (event);
5040 gst_rtspsrc_push_event (GstRTSPSrc * src, GstEvent * event)
5043 gboolean res = TRUE;
5045 for (streams = src->streams; streams; streams = g_list_next (streams)) {
5046 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
5048 gst_event_ref (event);
5049 res &= gst_rtspsrc_stream_push_event (src, ostream, event);
5051 gst_event_unref (event);
5057 accept_certificate_cb (GTlsConnection * conn, GTlsCertificate * peer_cert,
5058 GTlsCertificateFlags errors, gpointer user_data)
5060 GstRTSPSrc *src = user_data;
5061 gboolean accept = FALSE;
5063 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_ACCEPT_CERTIFICATE], 0, conn,
5064 peer_cert, errors, &accept);
5069 static GstRTSPResult
5070 gst_rtsp_conninfo_connect (GstRTSPSrc * src, GstRTSPConnInfo * info,
5074 GstRTSPMessage response;
5075 gboolean retry = FALSE;
5076 memset (&response, 0, sizeof (response));
5077 gst_rtsp_message_init (&response);
5079 if (info->connection == NULL) {
5080 if (info->url == NULL) {
5081 GST_DEBUG_OBJECT (src, "parsing uri (%s)...", info->location);
5082 if ((res = gst_rtsp_url_parse (info->location, &info->url)) < 0)
5085 /* create connection */
5086 GST_DEBUG_OBJECT (src, "creating connection (%s)...", info->location);
5087 if ((res = gst_rtsp_connection_create (info->url, &info->connection)) < 0)
5088 goto could_not_create;
5091 gst_rtspsrc_setup_auth (src, &response);
5094 g_free (info->url_str);
5095 info->url_str = gst_rtsp_url_get_request_uri (info->url);
5097 GST_DEBUG_OBJECT (src, "sanitized uri %s", info->url_str);
5099 if (info->url->transports & GST_RTSP_LOWER_TRANS_TLS) {
5100 if (!gst_rtsp_connection_set_tls_validation_flags (info->connection,
5101 src->tls_validation_flags))
5102 GST_WARNING_OBJECT (src, "Unable to set TLS validation flags");
5104 if (src->tls_database)
5105 gst_rtsp_connection_set_tls_database (info->connection,
5108 if (src->tls_interaction)
5109 gst_rtsp_connection_set_tls_interaction (info->connection,
5110 src->tls_interaction);
5111 gst_rtsp_connection_set_accept_certificate_func (info->connection,
5112 accept_certificate_cb, src, NULL);
5115 if (info->url->transports & GST_RTSP_LOWER_TRANS_HTTP)
5116 gst_rtsp_connection_set_tunneled (info->connection, TRUE);
5118 if (src->proxy_host) {
5119 GST_DEBUG_OBJECT (src, "setting proxy %s:%d", src->proxy_host,
5121 gst_rtsp_connection_set_proxy (info->connection, src->proxy_host,
5126 if (!info->connected) {
5129 GST_ELEMENT_PROGRESS (src, CONTINUE, "connect",
5130 ("Connecting to %s", info->location));
5131 GST_DEBUG_OBJECT (src, "connecting (%s)...", info->location);
5132 res = gst_rtsp_connection_connect_with_response_usec (info->connection,
5133 src->tcp_timeout, &response);
5135 if (response.type == GST_RTSP_MESSAGE_HTTP_RESPONSE &&
5136 response.type_data.response.code == GST_RTSP_STS_UNAUTHORIZED) {
5137 gst_rtsp_conninfo_close (src, info, TRUE);
5141 retry = FALSE; // we should not retry more than once
5146 if (res == GST_RTSP_OK)
5147 info->connected = TRUE;
5149 goto could_not_connect;
5151 } while (!info->connected && retry);
5153 gst_rtsp_message_unset (&response);
5159 GST_ERROR_OBJECT (src, "No valid RTSP URL was provided");
5160 gst_rtsp_message_unset (&response);
5165 gchar *str = gst_rtsp_strresult (res);
5166 GST_ERROR_OBJECT (src, "Could not create connection. (%s)", str);
5168 gst_rtsp_message_unset (&response);
5173 gchar *str = gst_rtsp_strresult (res);
5174 GST_ERROR_OBJECT (src, "Could not connect to server. (%s)", str);
5176 gst_rtsp_message_unset (&response);
5181 static GstRTSPResult
5182 gst_rtsp_conninfo_close (GstRTSPSrc * src, GstRTSPConnInfo * info,
5185 GST_RTSP_STATE_LOCK (src);
5186 if (info->connected) {
5187 GST_DEBUG_OBJECT (src, "closing connection...");
5188 gst_rtsp_connection_close (info->connection);
5189 info->connected = FALSE;
5191 if (free && info->connection) {
5192 /* free connection */
5193 GST_DEBUG_OBJECT (src, "freeing connection...");
5194 gst_rtsp_connection_free (info->connection);
5195 info->connection = NULL;
5196 info->flushing = FALSE;
5198 GST_RTSP_STATE_UNLOCK (src);
5202 static GstRTSPResult
5203 gst_rtsp_conninfo_reconnect (GstRTSPSrc * src, GstRTSPConnInfo * info,
5208 GST_DEBUG_OBJECT (src, "reconnecting connection...");
5209 gst_rtsp_conninfo_close (src, info, FALSE);
5210 res = gst_rtsp_conninfo_connect (src, info, async);
5216 gst_rtspsrc_connection_flush (GstRTSPSrc * src, gboolean flush)
5220 GST_DEBUG_OBJECT (src, "set flushing %d", flush);
5221 GST_RTSP_STATE_LOCK (src);
5222 if (src->conninfo.connection && src->conninfo.flushing != flush) {
5223 GST_DEBUG_OBJECT (src, "connection flush");
5224 gst_rtsp_connection_flush (src->conninfo.connection, flush);
5225 src->conninfo.flushing = flush;
5227 for (walk = src->streams; walk; walk = g_list_next (walk)) {
5228 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
5229 if (stream->conninfo.connection && stream->conninfo.flushing != flush) {
5230 GST_DEBUG_OBJECT (src, "stream %p flush", stream);
5231 gst_rtsp_connection_flush (stream->conninfo.connection, flush);
5232 stream->conninfo.flushing = flush;
5235 GST_RTSP_STATE_UNLOCK (src);
5238 static GstRTSPResult
5239 gst_rtspsrc_init_request (GstRTSPSrc * src, GstRTSPMessage * msg,
5240 GstRTSPMethod method, const gchar * uri)
5244 res = gst_rtsp_message_init_request (msg, method, uri);
5248 /* set user-agent */
5249 if (src->user_agent)
5250 gst_rtsp_message_add_header (msg, GST_RTSP_HDR_USER_AGENT, src->user_agent);
5255 /* FIXME, handle server request, reply with OK, for now */
5256 static GstRTSPResult
5257 gst_rtspsrc_handle_request (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
5258 GstRTSPMessage * request)
5260 GstRTSPMessage response = { 0 };
5263 GST_DEBUG_OBJECT (src, "got server request message");
5265 DEBUG_RTSP (src, request);
5267 res = gst_rtsp_ext_list_receive_request (src->extensions, request);
5269 if (res == GST_RTSP_ENOTIMPL) {
5270 /* default implementation, send OK */
5271 GST_DEBUG_OBJECT (src, "prepare OK reply");
5273 gst_rtsp_message_init_response (&response, GST_RTSP_STS_OK, "OK",
5278 /* let app parse and reply */
5279 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_HANDLE_REQUEST],
5280 0, request, &response);
5282 DEBUG_RTSP (src, &response);
5284 res = gst_rtspsrc_connection_send (src, conninfo, &response, 0);
5288 gst_rtsp_message_unset (&response);
5289 } else if (res == GST_RTSP_EEOF)
5297 gst_rtsp_message_unset (&response);
5302 /* send server keep-alive */
5303 static GstRTSPResult
5304 gst_rtspsrc_send_keep_alive (GstRTSPSrc * src)
5306 GstRTSPMessage request = { 0 };
5308 GstRTSPMethod method;
5309 const gchar *control;
5311 if (src->do_rtsp_keep_alive == FALSE) {
5312 GST_DEBUG_OBJECT (src, "do-rtsp-keep-alive is FALSE, not sending.");
5313 gst_rtsp_connection_reset_timeout (src->conninfo.connection);
5317 GST_DEBUG_OBJECT (src, "creating server keep-alive");
5319 /* find a method to use for keep-alive */
5320 if (src->methods & GST_RTSP_GET_PARAMETER)
5321 method = GST_RTSP_GET_PARAMETER;
5323 method = GST_RTSP_OPTIONS;
5325 control = get_aggregate_control (src);
5326 if (control == NULL)
5329 res = gst_rtspsrc_init_request (src, &request, method, control);
5333 request.type_data.request.version = src->version;
5335 res = gst_rtspsrc_connection_send (src, &src->conninfo, &request, 0);
5339 gst_rtsp_connection_reset_timeout (src->conninfo.connection);
5340 gst_rtsp_message_unset (&request);
5347 GST_WARNING_OBJECT (src, "no control url to send keepalive");
5352 gchar *str = gst_rtsp_strresult (res);
5354 gst_rtsp_message_unset (&request);
5355 GST_ELEMENT_WARNING (src, RESOURCE, WRITE, (NULL),
5356 ("Could not send keep-alive. (%s)", str));
5362 static GstFlowReturn
5363 gst_rtspsrc_handle_data (GstRTSPSrc * src, GstRTSPMessage * message)
5365 GstFlowReturn ret = GST_FLOW_OK;
5367 GstRTSPStream *stream;
5368 GstPad *outpad = NULL;
5374 channel = message->type_data.data.channel;
5376 stream = find_stream (src, &channel, (gpointer) find_stream_by_channel);
5378 goto unknown_stream;
5380 if (channel == stream->channel[0]) {
5381 outpad = stream->channelpad[0];
5383 } else if (channel == stream->channel[1]) {
5384 outpad = stream->channelpad[1];
5390 /* take a look at the body to figure out what we have */
5391 gst_rtsp_message_get_body (message, &data, &size);
5393 goto invalid_length;
5395 /* channels are not correct on some servers, do extra check */
5396 if (data[1] >= 200 && data[1] <= 204) {
5397 /* hmm RTCP message switch to the RTCP pad of the same stream. */
5398 outpad = stream->channelpad[1];
5402 /* we have no clue what this is, just ignore then. */
5404 goto unknown_stream;
5406 /* take the message body for further processing */
5407 gst_rtsp_message_steal_body (message, &data, &size);
5409 /* strip the trailing \0 */
5412 buf = gst_buffer_new ();
5413 gst_buffer_append_memory (buf,
5414 gst_memory_new_wrapped (0, data, size, 0, size, data, g_free));
5416 /* don't need message anymore */
5417 gst_rtsp_message_unset (message);
5419 GST_DEBUG_OBJECT (src, "pushing data of size %d on channel %d", size,
5422 if (src->need_activate) {
5429 /* generate an SHA256 sum of the URI */
5430 cs = g_checksum_new (G_CHECKSUM_SHA256);
5431 uri = src->conninfo.location;
5432 g_checksum_update (cs, (const guchar *) uri, strlen (uri));
5434 for (streams = src->streams; streams; streams = g_list_next (streams)) {
5435 GstRTSPStream *ostream = (GstRTSPStream *) streams->data;
5438 /* Activate in advance so that the stream-start event is registered */
5439 if (stream->srcpad) {
5440 gst_pad_set_active (stream->srcpad, TRUE);
5444 g_strdup_printf ("%s/%d", g_checksum_get_string (cs), ostream->id);
5446 event = gst_event_new_stream_start (stream_id);
5448 gst_rtspsrc_stream_start_event_add_group_id (src, event);
5451 gst_rtspsrc_stream_push_event (src, ostream, event);
5453 if ((caps = stream_get_caps_for_pt (ostream, ostream->default_pt))) {
5454 /* only streams that have a connection to the outside world */
5455 if (ostream->setup) {
5456 if (ostream->udpsrc[0]) {
5457 gst_element_send_event (ostream->udpsrc[0],
5458 gst_event_new_caps (caps));
5459 } else if (ostream->channelpad[0]) {
5460 if (GST_PAD_IS_SRC (ostream->channelpad[0]))
5461 gst_pad_push_event (ostream->channelpad[0],
5462 gst_event_new_caps (caps));
5464 gst_pad_send_event (ostream->channelpad[0],
5465 gst_event_new_caps (caps));
5467 ostream->need_caps = FALSE;
5469 if (ostream->profile == GST_RTSP_PROFILE_SAVP ||
5470 ostream->profile == GST_RTSP_PROFILE_SAVPF)
5471 caps = gst_caps_new_empty_simple ("application/x-srtcp");
5473 caps = gst_caps_new_empty_simple ("application/x-rtcp");
5475 if (ostream->udpsrc[1]) {
5476 gst_element_send_event (ostream->udpsrc[1],
5477 gst_event_new_caps (caps));
5478 } else if (ostream->channelpad[1]) {
5479 if (GST_PAD_IS_SRC (ostream->channelpad[1]))
5480 gst_pad_push_event (ostream->channelpad[1],
5481 gst_event_new_caps (caps));
5483 gst_pad_send_event (ostream->channelpad[1],
5484 gst_event_new_caps (caps));
5487 gst_caps_unref (caps);
5491 g_checksum_free (cs);
5493 gst_rtspsrc_activate_streams (src);
5494 src->need_activate = FALSE;
5495 src->need_segment = TRUE;
5498 if (src->base_time == -1) {
5499 /* Take current running_time. This timestamp will be put on
5500 * the first buffer of each stream because we are a live source and so we
5501 * timestamp with the running_time. When we are dealing with TCP, we also
5502 * only timestamp the first buffer (using the DISCONT flag) because a server
5503 * typically bursts data, for which we don't want to compensate by speeding
5504 * up the media. The other timestamps will be interpollated from this one
5505 * using the RTP timestamps. */
5506 GST_OBJECT_LOCK (src);
5507 if (GST_ELEMENT_CLOCK (src)) {
5509 GstClockTime base_time;
5511 now = gst_clock_get_time (GST_ELEMENT_CLOCK (src));
5512 base_time = GST_ELEMENT_CAST (src)->base_time;
5514 src->base_time = now - base_time;
5516 GST_DEBUG_OBJECT (src, "first buffer at time %" GST_TIME_FORMAT ", base %"
5517 GST_TIME_FORMAT, GST_TIME_ARGS (now), GST_TIME_ARGS (base_time));
5519 GST_OBJECT_UNLOCK (src);
5522 /* If needed send a new segment, don't forget we are live and buffer are
5523 * timestamped with running time */
5524 if (src->need_segment) {
5525 src->need_segment = FALSE;
5526 if (src->onvif_mode) {
5527 gst_rtspsrc_push_event (src, gst_event_new_segment (&src->out_segment));
5531 gst_segment_init (&segment, GST_FORMAT_TIME);
5532 gst_rtspsrc_push_event (src, gst_event_new_segment (&segment));
5536 if (stream->need_caps) {
5539 if ((caps = stream_get_caps_for_pt (stream, stream->default_pt))) {
5540 /* only streams that have a connection to the outside world */
5541 if (stream->setup) {
5542 /* Only need to update the TCP caps here, UDP is already handled */
5543 if (stream->channelpad[0]) {
5544 if (GST_PAD_IS_SRC (stream->channelpad[0]))
5545 gst_pad_push_event (stream->channelpad[0],
5546 gst_event_new_caps (caps));
5548 gst_pad_send_event (stream->channelpad[0],
5549 gst_event_new_caps (caps));
5551 stream->need_caps = FALSE;
5555 stream->need_caps = FALSE;
5558 if (stream->discont && !is_rtcp) {
5559 /* mark first RTP buffer as discont */
5560 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
5561 stream->discont = FALSE;
5562 /* first buffer gets the timestamp, other buffers are not timestamped and
5563 * their presentation time will be interpollated from the rtp timestamps. */
5564 GST_DEBUG_OBJECT (src, "setting timestamp %" GST_TIME_FORMAT,
5565 GST_TIME_ARGS (src->base_time));
5567 GST_BUFFER_TIMESTAMP (buf) = src->base_time;
5570 /* chain to the peer pad */
5571 if (GST_PAD_IS_SINK (outpad))
5572 ret = gst_pad_chain (outpad, buf);
5574 ret = gst_pad_push (outpad, buf);
5577 /* combine all stream flows for the data transport */
5578 ret = gst_rtspsrc_combine_flows (src, stream, ret);
5585 GST_DEBUG_OBJECT (src, "unknown stream on channel %d, ignored", channel);
5586 gst_rtsp_message_unset (message);
5591 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5592 ("Short message received, ignoring."));
5593 gst_rtsp_message_unset (message);
5598 static GstFlowReturn
5599 gst_rtspsrc_loop_interleaved (GstRTSPSrc * src)
5601 GstRTSPMessage message = { 0 };
5603 GstFlowReturn ret = GST_FLOW_OK;
5606 gst_rtsp_message_unset (&message);
5608 if (src->conninfo.flushing) {
5609 /* do not attempt to receive if flushing */
5610 res = GST_RTSP_EINTR;
5612 /* protect the connection with the connection lock so that we can see when
5613 * we are finished doing server communication */
5614 res = gst_rtspsrc_connection_receive (src, &src->conninfo, &message,
5620 GST_DEBUG_OBJECT (src, "we received a server message");
5622 case GST_RTSP_EINTR:
5623 /* we got interrupted this means we need to stop */
5625 case GST_RTSP_ETIMEOUT:
5626 /* no reply, send keep alive */
5627 GST_DEBUG_OBJECT (src, "timeout, sending keep-alive");
5628 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
5632 /* go EOS when the server closed the connection */
5638 switch (message.type) {
5639 case GST_RTSP_MESSAGE_REQUEST:
5640 /* server sends us a request message, handle it */
5641 res = gst_rtspsrc_handle_request (src, &src->conninfo, &message);
5642 if (res == GST_RTSP_EEOF)
5645 goto handle_request_failed;
5647 case GST_RTSP_MESSAGE_RESPONSE:
5648 /* we ignore response messages */
5649 GST_DEBUG_OBJECT (src, "ignoring response message");
5650 DEBUG_RTSP (src, &message);
5652 case GST_RTSP_MESSAGE_DATA:
5653 GST_DEBUG_OBJECT (src, "got data message");
5654 ret = gst_rtspsrc_handle_data (src, &message);
5655 if (ret != GST_FLOW_OK)
5656 goto handle_data_failed;
5659 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
5664 g_assert_not_reached ();
5669 GST_DEBUG_OBJECT (src, "we got an eof from the server");
5670 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5671 ("The server closed the connection."));
5672 src->conninfo.connected = FALSE;
5673 gst_rtsp_message_unset (&message);
5674 return GST_FLOW_EOS;
5678 gst_rtsp_message_unset (&message);
5679 GST_DEBUG_OBJECT (src, "got interrupted");
5680 return GST_FLOW_FLUSHING;
5684 gchar *str = gst_rtsp_strresult (res);
5686 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5687 ("Could not receive message. (%s)", str));
5690 gst_rtsp_message_unset (&message);
5691 return GST_FLOW_ERROR;
5693 handle_request_failed:
5695 gchar *str = gst_rtsp_strresult (res);
5697 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
5698 ("Could not handle server message. (%s)", str));
5700 gst_rtsp_message_unset (&message);
5701 return GST_FLOW_ERROR;
5705 GST_DEBUG_OBJECT (src, "could no handle data message");
5710 static GstFlowReturn
5711 gst_rtspsrc_loop_udp (GstRTSPSrc * src)
5714 GstRTSPMessage message = { 0 };
5720 /* get the next timeout interval */
5721 timeout = gst_rtsp_connection_next_timeout_usec (src->conninfo.connection);
5723 GST_DEBUG_OBJECT (src, "doing receive with timeout %d seconds",
5724 (gint) timeout / G_USEC_PER_SEC);
5726 gst_rtsp_message_unset (&message);
5728 /* we should continue reading the TCP socket because the server might
5729 * send us requests. When the session timeout expires, we need to send a
5730 * keep-alive request to keep the session open. */
5731 if (src->conninfo.flushing) {
5732 /* do not attempt to receive if flushing */
5733 res = GST_RTSP_EINTR;
5735 res = gst_rtspsrc_connection_receive (src, &src->conninfo, &message,
5741 GST_DEBUG_OBJECT (src, "we received a server message");
5743 case GST_RTSP_EINTR:
5744 /* we got interrupted, see what we have to do */
5746 case GST_RTSP_ETIMEOUT:
5747 /* send keep-alive, ignore the result, a warning will be posted. */
5748 GST_DEBUG_OBJECT (src, "timeout, sending keep-alive");
5749 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
5753 /* server closed the connection. not very fatal for UDP, reconnect and
5754 * see what happens. */
5755 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5756 ("The server closed the connection."));
5757 if (src->udp_reconnect) {
5759 gst_rtsp_conninfo_reconnect (src, &src->conninfo, FALSE)) < 0)
5766 GST_DEBUG_OBJECT (src, "An ethernet problem occurred.");
5768 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5769 ("Unhandled return value %d.", res));
5773 switch (message.type) {
5774 case GST_RTSP_MESSAGE_REQUEST:
5775 /* server sends us a request message, handle it */
5776 res = gst_rtspsrc_handle_request (src, &src->conninfo, &message);
5777 if (res == GST_RTSP_EEOF)
5780 goto handle_request_failed;
5782 case GST_RTSP_MESSAGE_RESPONSE:
5783 /* we ignore response and data messages */
5784 GST_DEBUG_OBJECT (src, "ignoring response message");
5785 DEBUG_RTSP (src, &message);
5786 if (message.type_data.response.code == GST_RTSP_STS_UNAUTHORIZED) {
5787 GST_DEBUG_OBJECT (src, "but is Unauthorized response ...");
5788 if (gst_rtspsrc_setup_auth (src, &message) && !(retry++)) {
5789 GST_DEBUG_OBJECT (src, "so retrying keep-alive");
5790 if ((res = gst_rtspsrc_send_keep_alive (src)) == GST_RTSP_EINTR)
5797 case GST_RTSP_MESSAGE_DATA:
5798 /* we ignore response and data messages */
5799 GST_DEBUG_OBJECT (src, "ignoring data message");
5802 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
5807 g_assert_not_reached ();
5809 /* we get here when the connection got interrupted */
5812 gst_rtsp_message_unset (&message);
5813 GST_DEBUG_OBJECT (src, "got interrupted");
5814 return GST_FLOW_FLUSHING;
5818 gchar *str = gst_rtsp_strresult (res);
5821 src->conninfo.connected = FALSE;
5822 if (res != GST_RTSP_EINTR) {
5823 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
5824 ("Could not connect to server. (%s)", str));
5826 ret = GST_FLOW_ERROR;
5828 ret = GST_FLOW_FLUSHING;
5834 gchar *str = gst_rtsp_strresult (res);
5836 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5837 ("Could not receive message. (%s)", str));
5839 return GST_FLOW_ERROR;
5841 handle_request_failed:
5843 gchar *str = gst_rtsp_strresult (res);
5846 gst_rtsp_message_unset (&message);
5847 if (res != GST_RTSP_EINTR) {
5848 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
5849 ("Could not handle server message. (%s)", str));
5851 ret = GST_FLOW_ERROR;
5853 ret = GST_FLOW_FLUSHING;
5859 GST_DEBUG_OBJECT (src, "we got an eof from the server");
5860 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5861 ("The server closed the connection."));
5862 src->conninfo.connected = FALSE;
5863 gst_rtsp_message_unset (&message);
5864 return GST_FLOW_EOS;
5868 static GstRTSPResult
5869 gst_rtspsrc_reconnect (GstRTSPSrc * src, gboolean async)
5871 GstRTSPResult res = GST_RTSP_OK;
5874 GST_DEBUG_OBJECT (src, "doing reconnect");
5876 GST_OBJECT_LOCK (src);
5877 /* only restart when the pads were not yet activated, else we were
5878 * streaming over UDP */
5879 restart = src->need_activate;
5880 GST_OBJECT_UNLOCK (src);
5882 /* no need to restart, we're done */
5886 /* we can try only TCP now */
5887 src->cur_protocols = GST_RTSP_LOWER_TRANS_TCP;
5889 /* close and cleanup our state */
5890 if ((res = gst_rtspsrc_close (src, async, FALSE)) < 0)
5893 /* see if we have TCP left to try. Also don't try TCP when we were configured
5895 if (!(src->protocols & GST_RTSP_LOWER_TRANS_TCP) || src->from_sdp)
5898 /* We post a warning message now to inform the user
5899 * that nothing happened. It's most likely a firewall thing. */
5900 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
5901 ("Could not receive any UDP packets for %.4f seconds, maybe your "
5902 "firewall is blocking it. Retrying using a tcp connection.",
5903 gst_guint64_to_gdouble (src->udp_timeout) / 1000000.0));
5905 /* open new connection using tcp */
5906 if (gst_rtspsrc_open (src, async) < 0)
5909 /* start playback */
5910 if (gst_rtspsrc_play (src, &src->segment, async, NULL) < 0)
5919 src->cur_protocols = 0;
5920 /* no transport possible, post an error and stop */
5921 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
5922 ("Could not receive any UDP packets for %.4f seconds, maybe your "
5923 "firewall is blocking it. No other protocols to try.",
5924 gst_guint64_to_gdouble (src->udp_timeout) / 1000000.0));
5925 return GST_RTSP_ERROR;
5929 GST_DEBUG_OBJECT (src, "open failed");
5934 GST_DEBUG_OBJECT (src, "play failed");
5940 gst_rtspsrc_loop_start_cmd (GstRTSPSrc * src, gint cmd)
5944 GST_ELEMENT_PROGRESS (src, START, "open", ("Opening Stream"));
5947 GST_ELEMENT_PROGRESS (src, START, "request", ("Sending PLAY request"));
5950 GST_ELEMENT_PROGRESS (src, START, "request", ("Sending PAUSE request"));
5952 case CMD_GET_PARAMETER:
5953 GST_ELEMENT_PROGRESS (src, START, "request",
5954 ("Sending GET_PARAMETER request"));
5956 case CMD_SET_PARAMETER:
5957 GST_ELEMENT_PROGRESS (src, START, "request",
5958 ("Sending SET_PARAMETER request"));
5961 GST_ELEMENT_PROGRESS (src, START, "close", ("Closing Stream"));
5969 gst_rtspsrc_loop_complete_cmd (GstRTSPSrc * src, gint cmd)
5973 GST_ELEMENT_PROGRESS (src, COMPLETE, "open", ("Opened Stream"));
5976 GST_ELEMENT_PROGRESS (src, COMPLETE, "request", ("Sent PLAY request"));
5979 GST_ELEMENT_PROGRESS (src, COMPLETE, "request", ("Sent PAUSE request"));
5981 case CMD_GET_PARAMETER:
5982 GST_ELEMENT_PROGRESS (src, COMPLETE, "request",
5983 ("Sent GET_PARAMETER request"));
5985 case CMD_SET_PARAMETER:
5986 GST_ELEMENT_PROGRESS (src, COMPLETE, "request",
5987 ("Sent SET_PARAMETER request"));
5990 GST_ELEMENT_PROGRESS (src, COMPLETE, "close", ("Closed Stream"));
5998 gst_rtspsrc_loop_cancel_cmd (GstRTSPSrc * src, gint cmd)
6002 GST_ELEMENT_PROGRESS (src, CANCELED, "open", ("Open canceled"));
6005 GST_ELEMENT_PROGRESS (src, CANCELED, "request", ("PLAY canceled"));
6008 GST_ELEMENT_PROGRESS (src, CANCELED, "request", ("PAUSE canceled"));
6010 case CMD_GET_PARAMETER:
6011 GST_ELEMENT_PROGRESS (src, CANCELED, "request",
6012 ("GET_PARAMETER canceled"));
6014 case CMD_SET_PARAMETER:
6015 GST_ELEMENT_PROGRESS (src, CANCELED, "request",
6016 ("SET_PARAMETER canceled"));
6019 GST_ELEMENT_PROGRESS (src, CANCELED, "close", ("Close canceled"));
6027 gst_rtspsrc_loop_error_cmd (GstRTSPSrc * src, gint cmd)
6031 GST_ELEMENT_PROGRESS (src, ERROR, "open", ("Open failed"));
6034 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("PLAY failed"));
6037 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("PAUSE failed"));
6039 case CMD_GET_PARAMETER:
6040 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("GET_PARAMETER failed"));
6042 case CMD_SET_PARAMETER:
6043 GST_ELEMENT_PROGRESS (src, ERROR, "request", ("SET_PARAMETER failed"));
6046 GST_ELEMENT_PROGRESS (src, ERROR, "close", ("Close failed"));
6054 gst_rtspsrc_loop_end_cmd (GstRTSPSrc * src, gint cmd, GstRTSPResult ret)
6056 if (ret == GST_RTSP_OK)
6057 gst_rtspsrc_loop_complete_cmd (src, cmd);
6058 else if (ret == GST_RTSP_EINTR)
6059 gst_rtspsrc_loop_cancel_cmd (src, cmd);
6061 gst_rtspsrc_loop_error_cmd (src, cmd);
6065 gst_rtspsrc_loop_send_cmd (GstRTSPSrc * src, gint cmd, gint mask)
6068 gboolean flushed = FALSE;
6070 /* start new request */
6071 gst_rtspsrc_loop_start_cmd (src, cmd);
6073 GST_DEBUG_OBJECT (src, "sending cmd %s", cmd_to_string (cmd));
6075 GST_OBJECT_LOCK (src);
6076 old = src->pending_cmd;
6078 if (old == CMD_RECONNECT) {
6079 GST_DEBUG_OBJECT (src, "ignore, we were reconnecting");
6080 cmd = CMD_RECONNECT;
6081 } else if (old == CMD_CLOSE) {
6082 /* our CMD_CLOSE might have interrutped CMD_LOOP. gst_rtspsrc_loop
6083 * will send a CMD_WAIT which would cancel our pending CMD_CLOSE (if
6084 * still pending). We just avoid it here by making sure CMD_CLOSE is
6085 * still the pending command. */
6086 GST_DEBUG_OBJECT (src, "ignore, we were closing");
6088 } else if (old == CMD_SET_PARAMETER) {
6089 GST_DEBUG_OBJECT (src, "ignore, we have a pending %s", cmd_to_string (old));
6090 cmd = CMD_SET_PARAMETER;
6091 } else if (old == CMD_GET_PARAMETER) {
6092 GST_DEBUG_OBJECT (src, "ignore, we have a pending %s", cmd_to_string (old));
6093 cmd = CMD_GET_PARAMETER;
6094 } else if (old != CMD_WAIT) {
6095 src->pending_cmd = CMD_WAIT;
6096 GST_OBJECT_UNLOCK (src);
6097 /* cancel previous request */
6098 GST_DEBUG_OBJECT (src, "cancel previous request %s", cmd_to_string (old));
6099 gst_rtspsrc_loop_cancel_cmd (src, old);
6100 GST_OBJECT_LOCK (src);
6102 src->pending_cmd = cmd;
6103 /* interrupt if allowed */
6104 if (src->busy_cmd & mask) {
6105 GST_DEBUG_OBJECT (src, "connection flush busy %s",
6106 cmd_to_string (src->busy_cmd));
6107 gst_rtspsrc_connection_flush (src, TRUE);
6110 GST_DEBUG_OBJECT (src, "not interrupting busy cmd %s",
6111 cmd_to_string (src->busy_cmd));
6114 gst_task_start (src->task);
6115 GST_OBJECT_UNLOCK (src);
6121 gst_rtspsrc_loop_send_cmd_and_wait (GstRTSPSrc * src, gint cmd, gint mask,
6122 GstClockTime timeout)
6124 gboolean flushed = gst_rtspsrc_loop_send_cmd (src, cmd, mask);
6127 gint64 end_time = g_get_monotonic_time () + (timeout / 1000);
6128 GST_OBJECT_LOCK (src);
6129 while (src->pending_cmd == cmd || src->busy_cmd == cmd) {
6130 if (!g_cond_wait_until (&src->cmd_cond, GST_OBJECT_GET_LOCK (src),
6132 GST_WARNING_OBJECT (src,
6133 "Timed out waiting for TEARDOWN to be processed.");
6134 break; /* timeout passed */
6137 GST_OBJECT_UNLOCK (src);
6143 gst_rtspsrc_loop (GstRTSPSrc * src)
6147 if (!src->conninfo.connection || !src->conninfo.connected)
6150 if (src->interleaved)
6151 ret = gst_rtspsrc_loop_interleaved (src);
6153 ret = gst_rtspsrc_loop_udp (src);
6155 if (ret != GST_FLOW_OK)
6163 GST_WARNING_OBJECT (src, "we are not connected");
6164 ret = GST_FLOW_FLUSHING;
6169 const gchar *reason = gst_flow_get_name (ret);
6171 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
6172 src->running = FALSE;
6173 if (ret == GST_FLOW_EOS) {
6174 /* perform EOS logic */
6175 if (src->segment.flags & GST_SEEK_FLAG_SEGMENT) {
6176 gst_element_post_message (GST_ELEMENT_CAST (src),
6177 gst_message_new_segment_done (GST_OBJECT_CAST (src),
6178 src->segment.format, src->segment.position));
6179 gst_rtspsrc_push_event (src,
6180 gst_event_new_segment_done (src->segment.format,
6181 src->segment.position));
6183 gst_rtspsrc_push_event (src, gst_event_new_eos ());
6185 } else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS) {
6186 /* for fatal errors we post an error message, post the error before the
6187 * EOS so the app knows about the error first. */
6188 GST_ELEMENT_FLOW_ERROR (src, ret);
6189 gst_rtspsrc_push_event (src, gst_event_new_eos ());
6191 gst_rtspsrc_loop_send_cmd (src, CMD_WAIT, CMD_LOOP);
6196 #ifndef GST_DISABLE_GST_DEBUG
6197 static const gchar *
6198 gst_rtsp_auth_method_to_string (GstRTSPAuthMethod method)
6202 while (method != 0) {
6219 /* Parse a WWW-Authenticate Response header and determine the
6220 * available authentication methods
6222 * This code should also cope with the fact that each WWW-Authenticate
6223 * header can contain multiple challenge methods + tokens
6225 * At the moment, for Basic auth, we just do a minimal check and don't
6226 * even parse out the realm */
6228 gst_rtspsrc_parse_auth_hdr (GstRTSPMessage * response,
6229 GstRTSPAuthMethod * methods, GstRTSPConnection * conn, gboolean * stale)
6231 GstRTSPAuthCredential **credentials, **credential;
6233 g_return_if_fail (response != NULL);
6234 g_return_if_fail (methods != NULL);
6235 g_return_if_fail (stale != NULL);
6238 gst_rtsp_message_parse_auth_credentials (response,
6239 GST_RTSP_HDR_WWW_AUTHENTICATE);
6243 credential = credentials;
6244 while (*credential) {
6245 if ((*credential)->scheme == GST_RTSP_AUTH_BASIC) {
6246 *methods |= GST_RTSP_AUTH_BASIC;
6247 } else if ((*credential)->scheme == GST_RTSP_AUTH_DIGEST) {
6248 GstRTSPAuthParam **param = (*credential)->params;
6250 *methods |= GST_RTSP_AUTH_DIGEST;
6252 gst_rtsp_connection_clear_auth_params (conn);
6256 if (strcmp ((*param)->name, "stale") == 0
6257 && g_ascii_strcasecmp ((*param)->value, "TRUE") == 0)
6259 gst_rtsp_connection_set_auth_param (conn, (*param)->name,
6268 gst_rtsp_auth_credentials_free (credentials);
6272 * gst_rtspsrc_setup_auth:
6273 * @src: the rtsp source
6275 * Configure a username and password and auth method on the
6276 * connection object based on a response we received from the
6279 * Currently, this requires that a username and password were supplied
6280 * in the uri. In the future, they may be requested on demand by sending
6281 * a message up the bus.
6283 * Returns: TRUE if authentication information could be set up correctly.
6286 gst_rtspsrc_setup_auth (GstRTSPSrc * src, GstRTSPMessage * response)
6290 GstRTSPAuthMethod avail_methods = GST_RTSP_AUTH_NONE;
6291 GstRTSPAuthMethod method;
6292 GstRTSPResult auth_result;
6294 GstRTSPConnection *conn;
6295 gboolean stale = FALSE;
6297 conn = src->conninfo.connection;
6299 /* Identify the available auth methods and see if any are supported */
6300 gst_rtspsrc_parse_auth_hdr (response, &avail_methods, conn, &stale);
6302 if (avail_methods == GST_RTSP_AUTH_NONE)
6303 goto no_auth_available;
6305 /* For digest auth, if the response indicates that the session
6306 * data are stale, we just update them in the connection object and
6307 * return TRUE to retry the request */
6309 src->tried_url_auth = FALSE;
6311 url = gst_rtsp_connection_get_url (conn);
6313 /* Do we have username and password available? */
6314 if (url != NULL && !src->tried_url_auth && url->user != NULL
6315 && url->passwd != NULL) {
6318 src->tried_url_auth = TRUE;
6319 GST_DEBUG_OBJECT (src,
6320 "Attempting authentication using credentials from the URL");
6322 user = src->user_id;
6323 pass = src->user_pw;
6324 GST_DEBUG_OBJECT (src,
6325 "Attempting authentication using credentials from the properties");
6328 /* FIXME: If the url didn't contain username and password or we tried them
6329 * already, request a username and passwd from the application via some kind
6330 * of credentials request message */
6332 /* If we don't have a username and passwd at this point, bail out. */
6333 if (user == NULL || pass == NULL)
6336 /* Try to configure for each available authentication method, strongest to
6338 for (method = GST_RTSP_AUTH_MAX; method != GST_RTSP_AUTH_NONE; method >>= 1) {
6339 /* Check if this method is available on the server */
6340 if ((method & avail_methods) == 0)
6343 /* Pass the credentials to the connection to try on the next request */
6344 auth_result = gst_rtsp_connection_set_auth (conn, method, user, pass);
6345 /* INVAL indicates an invalid username/passwd were supplied, so we'll just
6346 * ignore it and end up retrying later */
6347 if (auth_result == GST_RTSP_OK || auth_result == GST_RTSP_EINVAL) {
6348 GST_DEBUG_OBJECT (src, "Attempting %s authentication",
6349 gst_rtsp_auth_method_to_string (method));
6354 if (method == GST_RTSP_AUTH_NONE)
6355 goto no_auth_available;
6361 /* Output an error indicating that we couldn't connect because there were
6362 * no supported authentication protocols */
6363 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
6364 ("No supported authentication protocol was found"));
6369 /* We don't fire an error message, we just return FALSE and let the
6370 * normal NOT_AUTHORIZED error be propagated */
6375 static GstRTSPResult
6376 gst_rtsp_src_receive_response (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
6377 GstRTSPMessage * response, GstRTSPStatusCode * code)
6379 GstRTSPStatusCode thecode;
6380 gchar *content_base = NULL;
6384 if (conninfo->flushing) {
6385 /* do not attempt to receive if flushing */
6386 res = GST_RTSP_EINTR;
6388 res = gst_rtspsrc_connection_receive (src, conninfo, response,
6395 DEBUG_RTSP (src, response);
6397 switch (response->type) {
6398 case GST_RTSP_MESSAGE_REQUEST:
6399 res = gst_rtspsrc_handle_request (src, conninfo, response);
6400 if (res == GST_RTSP_EEOF)
6403 goto handle_request_failed;
6405 /* Not a response, receive next message */
6407 case GST_RTSP_MESSAGE_RESPONSE:
6408 /* ok, a response is good */
6409 GST_DEBUG_OBJECT (src, "received response message");
6411 case GST_RTSP_MESSAGE_DATA:
6412 /* get next response */
6413 GST_DEBUG_OBJECT (src, "handle data response message");
6414 gst_rtspsrc_handle_data (src, response);
6416 /* Not a response, receive next message */
6419 GST_WARNING_OBJECT (src, "ignoring unknown message type %d",
6422 /* Not a response, receive next message */
6426 thecode = response->type_data.response.code;
6428 GST_DEBUG_OBJECT (src, "got response message %d", thecode);
6430 /* if the caller wanted the result code, we store it. */
6434 /* If the request didn't succeed, bail out before doing any more */
6435 if (thecode != GST_RTSP_STS_OK)
6438 /* store new content base if any */
6439 gst_rtsp_message_get_header (response, GST_RTSP_HDR_CONTENT_BASE,
6442 g_free (src->content_base);
6443 src->content_base = g_strdup (content_base);
6453 return GST_RTSP_EEOF;
6456 gchar *str = gst_rtsp_strresult (res);
6458 if (res != GST_RTSP_EINTR) {
6459 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
6460 ("Could not receive message. (%s)", str));
6462 GST_WARNING_OBJECT (src, "receive interrupted");
6470 handle_request_failed:
6472 /* ERROR was posted */
6473 gst_rtsp_message_unset (response);
6478 GST_DEBUG_OBJECT (src, "we got an eof from the server");
6479 GST_ELEMENT_WARNING (src, RESOURCE, READ, (NULL),
6480 ("The server closed the connection."));
6481 gst_rtsp_message_unset (response);
6487 static GstRTSPResult
6488 gst_rtspsrc_try_send (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
6489 GstRTSPMessage * request, GstRTSPMessage * response,
6490 GstRTSPStatusCode * code)
6494 gboolean allow_send = TRUE;
6497 if (!src->short_header)
6498 gst_rtsp_ext_list_before_send (src->extensions, request);
6500 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_BEFORE_SEND], 0,
6501 request, &allow_send);
6503 GST_DEBUG_OBJECT (src, "skipping message, disabled by signal");
6507 GST_DEBUG_OBJECT (src, "sending message");
6509 DEBUG_RTSP (src, request);
6511 res = gst_rtspsrc_connection_send (src, conninfo, request, src->tcp_timeout);
6515 gst_rtsp_connection_reset_timeout (conninfo->connection);
6519 res = gst_rtsp_src_receive_response (src, conninfo, response, code);
6520 if (res == GST_RTSP_EEOF) {
6521 GST_WARNING_OBJECT (src, "server closed connection");
6522 /* only try once after reconnect, then fallthrough and error out */
6523 if ((try == 0) && !src->interleaved && src->udp_reconnect) {
6525 /* if reconnect succeeds, try again */
6526 if ((res = gst_rtsp_conninfo_reconnect (src, &src->conninfo, FALSE)) == 0)
6534 gst_rtsp_ext_list_after_send (src->extensions, request, response);
6540 gchar *str = gst_rtsp_strresult (res);
6542 if (res != GST_RTSP_EINTR) {
6543 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
6544 ("Could not send message. (%s)", str));
6546 GST_WARNING_OBJECT (src, "send interrupted");
6554 gchar *str = gst_rtsp_strresult (res);
6556 if (res != GST_RTSP_EINTR) {
6557 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
6558 ("Could not receive message. (%s)", str));
6560 GST_WARNING_OBJECT (src, "receive interrupted");
6569 * @src: the rtsp source
6570 * @conninfo: the connection information to send on
6571 * @request: must point to a valid request
6572 * @response: must point to an empty #GstRTSPMessage
6573 * @code: an optional code result
6574 * @versions: List of versions to try, setting it back onto the @request message
6575 * if not set, `src->version` will be used as RTSP version.
6577 * send @request and retrieve the response in @response. optionally @code can be
6578 * non-NULL in which case it will contain the status code of the response.
6580 * If This function returns #GST_RTSP_OK, @response will contain a valid response
6581 * message that should be cleaned with gst_rtsp_message_unset() after usage.
6583 * If @code is NULL, this function will return #GST_RTSP_ERROR (with an invalid
6584 * @response message) if the response code was not 200 (OK).
6586 * If the attempt results in an authentication failure, then this will attempt
6587 * to retrieve authentication credentials via gst_rtspsrc_setup_auth and retry
6590 * Returns: #GST_RTSP_OK if the processing was successful.
6592 static GstRTSPResult
6593 gst_rtspsrc_send (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
6594 GstRTSPMessage * request, GstRTSPMessage * response,
6595 GstRTSPStatusCode * code, GstRTSPVersion * versions)
6597 GstRTSPStatusCode int_code = GST_RTSP_STS_OK;
6598 GstRTSPResult res = GST_RTSP_ERROR;
6601 GstRTSPMethod method = GST_RTSP_INVALID;
6602 gint version_retry = 0;
6608 /* make sure we don't loop forever */
6612 /* save method so we can disable it when the server complains */
6613 method = request->type_data.request.method;
6616 request->type_data.request.version = src->version;
6619 gst_rtspsrc_try_send (src, conninfo, request, response,
6624 case GST_RTSP_STS_UNAUTHORIZED:
6625 case GST_RTSP_STS_NOT_FOUND:
6626 if (gst_rtspsrc_setup_auth (src, response)) {
6627 /* Try the request/response again after configuring the auth info
6632 case GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED:
6633 GST_INFO_OBJECT (src, "Version %s not supported by the server",
6634 versions ? gst_rtsp_version_as_text (versions[version_retry]) :
6636 if (versions && versions[version_retry] != GST_RTSP_VERSION_INVALID) {
6637 GST_INFO_OBJECT (src, "Unsupported version %s => trying %s",
6638 gst_rtsp_version_as_text (request->type_data.request.version),
6639 gst_rtsp_version_as_text (versions[version_retry]));
6640 request->type_data.request.version = versions[version_retry];
6649 } while (retry == TRUE);
6651 /* If the user requested the code, let them handle errors, otherwise
6652 * post an error below */
6655 else if (int_code != GST_RTSP_STS_OK)
6656 goto error_response;
6663 GST_DEBUG_OBJECT (src, "got error %d", res);
6668 res = GST_RTSP_ERROR;
6670 switch (response->type_data.response.code) {
6671 case GST_RTSP_STS_NOT_FOUND:
6672 RTSP_SRC_RESPONSE_ERROR (src, response, RESOURCE, NOT_FOUND,
6675 case GST_RTSP_STS_UNAUTHORIZED:
6676 RTSP_SRC_RESPONSE_ERROR (src, response, RESOURCE, NOT_AUTHORIZED,
6679 case GST_RTSP_STS_MOVED_PERMANENTLY:
6680 case GST_RTSP_STS_MOVE_TEMPORARILY:
6682 gchar *new_location;
6683 GstRTSPLowerTrans transports;
6685 GST_DEBUG_OBJECT (src, "got redirection");
6686 /* if we don't have a Location Header, we must error */
6687 if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_LOCATION,
6688 &new_location, 0) < 0)
6691 /* When we receive a redirect result, we go back to the INIT state after
6692 * parsing the new URI. The caller should do the needed steps to issue
6693 * a new setup when it detects this state change. */
6694 GST_DEBUG_OBJECT (src, "redirection to %s", new_location);
6696 /* save current transports */
6697 if (src->conninfo.url)
6698 transports = src->conninfo.url->transports;
6700 transports = GST_RTSP_LOWER_TRANS_UNKNOWN;
6702 gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (src), new_location, NULL);
6704 /* set old transports */
6705 if (src->conninfo.url && transports != GST_RTSP_LOWER_TRANS_UNKNOWN)
6706 src->conninfo.url->transports = transports;
6708 src->need_redirect = TRUE;
6712 case GST_RTSP_STS_NOT_ACCEPTABLE:
6713 case GST_RTSP_STS_NOT_IMPLEMENTED:
6714 case GST_RTSP_STS_METHOD_NOT_ALLOWED:
6715 /* Some cameras (e.g. HikVision DS-2CD2732F-IS) return "551
6716 * Option not supported" when a command is sent that is not implemented
6717 * (e.g. PAUSE). Instead; it should return "501 Not Implemented".
6719 * This is wrong, as previously, the camera did announce support
6720 * for PAUSE in the OPTIONS.
6722 * In this case, handle the 551 as if it was 501 to avoid throwing
6723 * errors to application level. */
6724 case GST_RTSP_STS_OPTION_NOT_SUPPORTED:
6725 GST_WARNING_OBJECT (src, "got NOT IMPLEMENTED, disable method %s",
6726 gst_rtsp_method_as_text (method));
6727 src->methods &= ~method;
6731 RTSP_SRC_RESPONSE_ERROR (src, response, RESOURCE, READ,
6735 /* if we return ERROR we should unset the response ourselves */
6736 if (res == GST_RTSP_ERROR)
6737 gst_rtsp_message_unset (response);
6743 static GstRTSPResult
6744 gst_rtspsrc_send_cb (GstRTSPExtension * ext, GstRTSPMessage * request,
6745 GstRTSPMessage * response, GstRTSPSrc * src)
6747 return gst_rtspsrc_send (src, &src->conninfo, request, response, NULL, NULL);
6751 /* parse the response and collect all the supported methods. We need this
6752 * information so that we don't try to send an unsupported request to the
6756 gst_rtspsrc_parse_methods (GstRTSPSrc * src, GstRTSPMessage * response)
6758 GstRTSPHeaderField field;
6762 /* reset supported methods */
6765 /* Try Allow Header first */
6766 field = GST_RTSP_HDR_ALLOW;
6769 gst_rtsp_message_get_header (response, field, &respoptions, indx);
6773 src->methods |= gst_rtsp_options_from_text (respoptions);
6779 field = GST_RTSP_HDR_PUBLIC;
6782 gst_rtsp_message_get_header (response, field, &respoptions, indx);
6786 src->methods |= gst_rtsp_options_from_text (respoptions);
6791 if (src->methods == 0) {
6792 /* neither Allow nor Public are required, assume the server supports
6793 * at least DESCRIBE, SETUP, we always assume it supports PLAY as
6795 GST_DEBUG_OBJECT (src, "could not get OPTIONS");
6796 src->methods = GST_RTSP_DESCRIBE | GST_RTSP_SETUP;
6798 /* always assume PLAY, FIXME, extensions should be able to override
6800 src->methods |= GST_RTSP_PLAY;
6801 /* also assume it will support Range */
6802 src->seekable = G_MAXFLOAT;
6804 /* we need describe and setup */
6805 if (!(src->methods & GST_RTSP_DESCRIBE))
6807 if (!(src->methods & GST_RTSP_SETUP))
6815 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
6816 ("Server does not support DESCRIBE."));
6821 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
6822 ("Server does not support SETUP."));
6827 /* masks to be kept in sync with the hardcoded protocol order of preference
6829 static const guint protocol_masks[] = {
6830 GST_RTSP_LOWER_TRANS_UDP,
6831 GST_RTSP_LOWER_TRANS_UDP_MCAST,
6832 GST_RTSP_LOWER_TRANS_TCP,
6836 static GstRTSPResult
6837 gst_rtspsrc_create_transports_string (GstRTSPSrc * src,
6838 GstRTSPLowerTrans protocols, GstRTSPProfile profile, gchar ** transports)
6842 gboolean add_udp_str;
6847 gst_rtsp_ext_list_get_transports (src->extensions, protocols, transports);
6852 GST_DEBUG_OBJECT (src, "got transports %s", GST_STR_NULL (*transports));
6854 /* extension listed transports, use those */
6855 if (*transports != NULL)
6858 /* it's the default */
6859 add_udp_str = FALSE;
6861 /* the default RTSP transports */
6862 result = g_string_new ("RTP");
6865 case GST_RTSP_PROFILE_AVP:
6866 g_string_append (result, "/AVP");
6868 case GST_RTSP_PROFILE_SAVP:
6869 g_string_append (result, "/SAVP");
6871 case GST_RTSP_PROFILE_AVPF:
6872 g_string_append (result, "/AVPF");
6874 case GST_RTSP_PROFILE_SAVPF:
6875 g_string_append (result, "/SAVPF");
6881 if (protocols & GST_RTSP_LOWER_TRANS_UDP) {
6882 GST_DEBUG_OBJECT (src, "adding UDP unicast");
6884 g_string_append (result, "/UDP");
6885 g_string_append (result, ";unicast;client_port=%%u1-%%u2");
6886 } else if (protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST) {
6887 GST_DEBUG_OBJECT (src, "adding UDP multicast");
6888 /* we don't have to allocate any UDP ports yet, if the selected transport
6889 * turns out to be multicast we can create them and join the multicast
6890 * group indicated in the transport reply */
6892 g_string_append (result, "/UDP");
6893 g_string_append (result, ";multicast");
6894 if (src->next_port_num != 0) {
6895 if (src->client_port_range.max > 0 &&
6896 src->next_port_num >= src->client_port_range.max)
6899 g_string_append_printf (result, ";client_port=%d-%d",
6900 src->next_port_num, src->next_port_num + 1);
6902 } else if (protocols & GST_RTSP_LOWER_TRANS_TCP) {
6903 GST_DEBUG_OBJECT (src, "adding TCP");
6905 g_string_append (result, "/TCP;unicast;interleaved=%%i1-%%i2");
6907 *transports = g_string_free (result, FALSE);
6909 GST_DEBUG_OBJECT (src, "prepared transports %s", GST_STR_NULL (*transports));
6916 GST_ERROR ("extension gave error %d", res);
6921 GST_ERROR ("no more ports available");
6922 return GST_RTSP_ERROR;
6926 static GstRTSPResult
6927 gst_rtspsrc_prepare_transports (GstRTSPStream * stream, gchar ** transports,
6928 gint orig_rtpport, gint orig_rtcpport)
6931 gint nr_udp, nr_int;
6933 gint rtpport = 0, rtcpport = 0;
6936 src = stream->parent;
6938 /* find number of placeholders first */
6939 if (strstr (*transports, "%%i2"))
6941 else if (strstr (*transports, "%%i1"))
6946 if (strstr (*transports, "%%u2"))
6948 else if (strstr (*transports, "%%u1"))
6953 if (nr_udp == 0 && nr_int == 0)
6957 if (!orig_rtpport || !orig_rtcpport) {
6958 if (!gst_rtspsrc_alloc_udp_ports (stream, &rtpport, &rtcpport))
6961 rtpport = orig_rtpport;
6962 rtcpport = orig_rtcpport;
6966 str = g_string_new ("");
6968 while ((next = strstr (p, "%%"))) {
6969 g_string_append_len (str, p, next - p);
6970 if (next[2] == 'u') {
6972 g_string_append_printf (str, "%d", rtpport);
6973 else if (next[3] == '2')
6974 g_string_append_printf (str, "%d", rtcpport);
6976 if (next[2] == 'i') {
6978 g_string_append_printf (str, "%d", src->free_channel);
6979 else if (next[3] == '2')
6980 g_string_append_printf (str, "%d", src->free_channel + 1);
6986 if (src->version >= GST_RTSP_VERSION_2_0)
6987 src->free_channel += 2;
6989 /* append final part */
6990 g_string_append (str, p);
6992 g_free (*transports);
6993 *transports = g_string_free (str, FALSE);
7001 GST_ERROR ("failed to allocate udp ports");
7002 return GST_RTSP_ERROR;
7007 signal_get_srtcp_params (GstRTSPSrc * src, GstRTSPStream * stream)
7009 GstCaps *caps = NULL;
7011 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_REQUEST_RTCP_KEY], 0,
7015 GST_DEBUG_OBJECT (src, "SRTP parameters received");
7021 default_srtcp_params (void)
7028 guint data_size = GST_ROUND_UP_4 (KEY_SIZE);
7030 /* create a random key */
7031 key_data = g_malloc (data_size);
7032 for (i = 0; i < data_size; i += 4)
7033 GST_WRITE_UINT32_BE (key_data + i, g_random_int ());
7035 buf = gst_buffer_new_wrapped (key_data, KEY_SIZE);
7037 caps = gst_caps_new_simple ("application/x-srtcp",
7038 "srtp-key", GST_TYPE_BUFFER, buf,
7039 "srtp-cipher", G_TYPE_STRING, "aes-128-icm",
7040 "srtp-auth", G_TYPE_STRING, "hmac-sha1-80",
7041 "srtcp-cipher", G_TYPE_STRING, "aes-128-icm",
7042 "srtcp-auth", G_TYPE_STRING, "hmac-sha1-80", NULL);
7044 gst_buffer_unref (buf);
7050 gst_rtspsrc_stream_make_keymgmt (GstRTSPSrc * src, GstRTSPStream * stream)
7052 gchar *base64, *result = NULL;
7053 GstMIKEYMessage *mikey_msg;
7055 stream->srtcpparams = signal_get_srtcp_params (src, stream);
7056 if (stream->srtcpparams == NULL)
7057 stream->srtcpparams = default_srtcp_params ();
7059 mikey_msg = gst_mikey_message_new_from_caps (stream->srtcpparams);
7061 /* add policy '0' for our SSRC */
7062 gst_mikey_message_add_cs_srtp (mikey_msg, 0, stream->send_ssrc, 0);
7064 base64 = gst_mikey_message_base64_encode (mikey_msg);
7065 gst_mikey_message_unref (mikey_msg);
7068 result = gst_sdp_make_keymgmt (stream->conninfo.location, base64);
7076 static GstRTSPResult
7077 gst_rtsp_src_setup_stream_from_response (GstRTSPSrc * src,
7078 GstRTSPStream * stream, GstRTSPMessage * response,
7079 GstRTSPLowerTrans * protocols, gint retry, gint * rtpport, gint * rtcpport)
7081 gchar *resptrans = NULL;
7082 GstRTSPTransport transport = { 0 };
7084 gst_rtsp_message_get_header (response, GST_RTSP_HDR_TRANSPORT, &resptrans, 0);
7086 gst_rtspsrc_stream_free_udp (stream);
7090 /* parse transport, go to next stream on parse error */
7091 if (gst_rtsp_transport_parse (resptrans, &transport) != GST_RTSP_OK) {
7092 GST_WARNING_OBJECT (src, "failed to parse transport %s", resptrans);
7093 return GST_RTSP_ELAST;
7096 /* update allowed transports for other streams. once the transport of
7097 * one stream has been determined, we make sure that all other streams
7098 * are configured in the same way */
7099 switch (transport.lower_transport) {
7100 case GST_RTSP_LOWER_TRANS_TCP:
7101 GST_DEBUG_OBJECT (src, "stream %p as TCP interleaved", stream);
7103 *protocols = GST_RTSP_LOWER_TRANS_TCP;
7104 src->interleaved = TRUE;
7105 if (src->version < GST_RTSP_VERSION_2_0) {
7106 /* update free channels */
7107 src->free_channel = MAX (transport.interleaved.min, src->free_channel);
7108 src->free_channel = MAX (transport.interleaved.max, src->free_channel);
7109 src->free_channel++;
7112 case GST_RTSP_LOWER_TRANS_UDP_MCAST:
7113 /* only allow multicast for other streams */
7114 GST_DEBUG_OBJECT (src, "stream %p as UDP multicast", stream);
7116 *protocols = GST_RTSP_LOWER_TRANS_UDP_MCAST;
7117 /* if the server selected our ports, increment our counters so that
7118 * we select a new port later */
7119 if (src->next_port_num == transport.port.min &&
7120 src->next_port_num + 1 == transport.port.max) {
7121 src->next_port_num += 2;
7124 case GST_RTSP_LOWER_TRANS_UDP:
7125 /* only allow unicast for other streams */
7126 GST_DEBUG_OBJECT (src, "stream %p as UDP unicast", stream);
7128 *protocols = GST_RTSP_LOWER_TRANS_UDP;
7131 GST_DEBUG_OBJECT (src, "stream %p unknown transport %d", stream,
7132 transport.lower_transport);
7136 if (!src->interleaved || !retry) {
7137 /* now configure the stream with the selected transport */
7138 if (!gst_rtspsrc_stream_configure_transport (stream, &transport)) {
7139 GST_DEBUG_OBJECT (src,
7140 "could not configure stream %p transport, skipping stream", stream);
7142 } else if (stream->udpsrc[0] && stream->udpsrc[1] && rtpport && rtcpport) {
7143 /* retain the first allocated UDP port pair */
7144 g_object_get (G_OBJECT (stream->udpsrc[0]), "port", rtpport, NULL);
7145 g_object_get (G_OBJECT (stream->udpsrc[1]), "port", rtcpport, NULL);
7148 /* we need to activate at least one stream when we detect activity */
7149 src->need_activate = TRUE;
7151 /* stream is setup now */
7152 stream->setup = TRUE;
7153 stream->waiting_setup_response = FALSE;
7155 if (src->version >= GST_RTSP_VERSION_2_0) {
7156 gchar *prop, *media_properties;
7160 if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_MEDIA_PROPERTIES,
7161 &media_properties, 0) != GST_RTSP_OK) {
7162 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
7163 ("Error: No MEDIA_PROPERTY header in a SETUP request in RTSP 2.0"
7164 " - this header is mandatory."));
7166 gst_rtsp_message_unset (response);
7167 return GST_RTSP_ERROR;
7170 props = g_strsplit (media_properties, ",", -2);
7171 for (i = 0; props[i]; i++) {
7174 while (*prop == ' ')
7177 if (strstr (prop, "Random-Access")) {
7178 gchar **random_seekable_val = g_strsplit (prop, "=", 2);
7180 if (!random_seekable_val[1])
7181 src->seekable = G_MAXFLOAT;
7183 src->seekable = g_ascii_strtod (random_seekable_val[1], NULL);
7185 g_strfreev (random_seekable_val);
7186 } else if (!g_strcmp0 (prop, "No-Seeking")) {
7187 src->seekable = -1.0;
7188 } else if (!g_strcmp0 (prop, "Beginning-Only")) {
7189 src->seekable = 0.0;
7197 /* clean up our transport struct */
7198 gst_rtsp_transport_init (&transport);
7199 /* clean up used RTSP messages */
7200 gst_rtsp_message_unset (response);
7206 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
7207 ("Server did not select transport."));
7209 gst_rtsp_message_unset (response);
7210 return GST_RTSP_ERROR;
7214 static GstRTSPResult
7215 gst_rtspsrc_setup_streams_end (GstRTSPSrc * src, gboolean async)
7218 GstRTSPConnInfo *conninfo;
7220 g_assert (src->version >= GST_RTSP_VERSION_2_0);
7222 conninfo = &src->conninfo;
7223 for (tmp = src->streams; tmp; tmp = tmp->next) {
7224 GstRTSPStream *stream = (GstRTSPStream *) tmp->data;
7225 GstRTSPMessage response = { 0, };
7227 if (!stream->waiting_setup_response)
7230 if (!src->conninfo.connection)
7231 conninfo = &((GstRTSPStream *) tmp->data)->conninfo;
7233 gst_rtsp_src_receive_response (src, conninfo, &response, NULL);
7235 gst_rtsp_src_setup_stream_from_response (src, stream,
7236 &response, NULL, 0, NULL, NULL);
7242 /* Perform the SETUP request for all the streams.
7244 * We ask the server for a specific transport, which initially includes all the
7245 * ones we can support (UDP/TCP/MULTICAST). For the UDP transport we allocate
7246 * two local UDP ports that we send to the server.
7248 * Once the server replied with a transport, we configure the other streams
7249 * with the same transport.
7251 * In case setup request are not pipelined, this function will also configure the
7252 * stream for the selected transport, * which basically means creating the pipeline.
7253 * Otherwise, the first stream is setup right away from the reply and a
7254 * CMD_FINALIZE_SETUP command is set for the stream pipelines to happen on the
7255 * remaining streams from the RTSP thread.
7257 static GstRTSPResult
7258 gst_rtspsrc_setup_streams_start (GstRTSPSrc * src, gboolean async)
7261 GstRTSPResult res = GST_RTSP_ERROR;
7262 GstRTSPMessage request = { 0 };
7263 GstRTSPMessage response = { 0 };
7264 GstRTSPStream *stream = NULL;
7265 GstRTSPLowerTrans protocols;
7266 GstRTSPStatusCode code;
7267 gboolean unsupported_real = FALSE;
7268 gint rtpport, rtcpport;
7271 gchar *pipelined_request_id = NULL;
7273 if (src->conninfo.connection) {
7274 url = gst_rtsp_connection_get_url (src->conninfo.connection);
7275 /* we initially allow all configured lower transports. based on the URL
7276 * transports and the replies from the server we narrow them down. */
7277 protocols = url->transports & src->cur_protocols;
7280 protocols = src->cur_protocols;
7283 /* In ONVIF mode, we only want to try TCP transport */
7284 if (src->onvif_mode && (protocols & GST_RTSP_LOWER_TRANS_TCP))
7285 protocols = GST_RTSP_LOWER_TRANS_TCP;
7290 /* reset some state */
7291 src->free_channel = 0;
7292 src->interleaved = FALSE;
7293 src->need_activate = FALSE;
7294 /* keep track of next port number, 0 is random */
7295 src->next_port_num = src->client_port_range.min;
7296 rtpport = rtcpport = 0;
7298 if (G_UNLIKELY (src->streams == NULL))
7301 for (walk = src->streams; walk; walk = g_list_next (walk)) {
7302 GstRTSPConnInfo *conninfo;
7309 stream = (GstRTSPStream *) walk->data;
7311 caps = stream_get_caps_for_pt (stream, stream->default_pt);
7313 GST_WARNING_OBJECT (src, "skipping stream %p, no caps", stream);
7317 if (stream->skipped) {
7318 GST_DEBUG_OBJECT (src, "skipping stream %p", stream);
7322 /* see if we need to configure this stream */
7323 if (!gst_rtsp_ext_list_configure_stream (src->extensions, caps)) {
7324 GST_DEBUG_OBJECT (src, "skipping stream %p, disabled by extension",
7329 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_SELECT_STREAM], 0,
7330 stream->id, caps, &selected);
7332 GST_DEBUG_OBJECT (src, "skipping stream %p, disabled by signal", stream);
7336 /* merge/overwrite global caps */
7341 s = gst_caps_get_structure (caps, 0);
7343 num = gst_structure_n_fields (src->props);
7344 for (j = 0; j < num; j++) {
7348 name = gst_structure_nth_field_name (src->props, j);
7349 val = gst_structure_get_value (src->props, name);
7350 gst_structure_set_value (s, name, val);
7352 GST_DEBUG_OBJECT (src, "copied %s", name);
7356 /* skip setup if we have no URL for it */
7357 if (stream->conninfo.location == NULL) {
7358 GST_WARNING_OBJECT (src, "skipping stream %p, no setup", stream);
7362 if (src->conninfo.connection == NULL) {
7363 if (!gst_rtsp_conninfo_connect (src, &stream->conninfo, async)) {
7364 GST_WARNING_OBJECT (src, "skipping stream %p, failed to connect",
7368 conninfo = &stream->conninfo;
7370 conninfo = &src->conninfo;
7372 GST_DEBUG_OBJECT (src, "doing setup of stream %p with %s", stream,
7373 stream->conninfo.location);
7375 /* if we have a multicast connection, only suggest multicast from now on */
7376 if (stream->is_multicast)
7377 protocols &= GST_RTSP_LOWER_TRANS_UDP_MCAST;
7380 /* first selectable protocol */
7381 while (protocol_masks[mask] && !(protocols & protocol_masks[mask]))
7383 if (!protocol_masks[mask])
7387 GST_DEBUG_OBJECT (src, "protocols = 0x%x, protocol mask = 0x%x", protocols,
7388 protocol_masks[mask]);
7389 /* create a string with first transport in line */
7391 res = gst_rtspsrc_create_transports_string (src,
7392 protocols & protocol_masks[mask], stream->profile, &transports);
7393 if (res < 0 || transports == NULL)
7394 goto setup_transport_failed;
7396 if (strlen (transports) == 0) {
7397 g_free (transports);
7398 GST_DEBUG_OBJECT (src, "no transports found");
7403 GST_DEBUG_OBJECT (src, "replace ports in %s", GST_STR_NULL (transports));
7405 /* replace placeholders with real values, this function will optionally
7406 * allocate UDP ports and other info needed to execute the setup request */
7407 res = gst_rtspsrc_prepare_transports (stream, &transports,
7408 retry > 0 ? rtpport : 0, retry > 0 ? rtcpport : 0);
7410 g_free (transports);
7411 goto setup_transport_failed;
7414 GST_DEBUG_OBJECT (src, "transport is now %s", GST_STR_NULL (transports));
7415 /* create SETUP request */
7417 gst_rtspsrc_init_request (src, &request, GST_RTSP_SETUP,
7418 stream->conninfo.location);
7420 g_free (transports);
7421 goto create_request_failed;
7424 if (src->version >= GST_RTSP_VERSION_2_0) {
7425 if (!pipelined_request_id)
7426 pipelined_request_id = g_strdup_printf ("%d",
7427 g_random_int_range (0, G_MAXINT32));
7429 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_PIPELINED_REQUESTS,
7430 pipelined_request_id);
7431 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_ACCEPT_RANGES,
7432 "npt, clock, smpte, clock");
7435 /* select transport */
7436 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_TRANSPORT, transports);
7438 if (stream->is_backchannel && src->backchannel == BACKCHANNEL_ONVIF)
7439 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
7440 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
7443 if (stream->profile == GST_RTSP_PROFILE_SAVP ||
7444 stream->profile == GST_RTSP_PROFILE_SAVPF) {
7445 hval = gst_rtspsrc_stream_make_keymgmt (src, stream);
7446 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_KEYMGMT, hval);
7449 /* if the user wants a non default RTP packet size we add the blocksize
7451 if (src->rtp_blocksize > 0) {
7452 hval = g_strdup_printf ("%d", src->rtp_blocksize);
7453 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_BLOCKSIZE, hval);
7457 GST_ELEMENT_PROGRESS (src, CONTINUE, "request", ("SETUP stream %d",
7460 /* handle the code ourselves */
7462 gst_rtspsrc_send (src, conninfo, &request,
7463 pipelined_request_id ? NULL : &response, &code, NULL);
7468 case GST_RTSP_STS_OK:
7470 case GST_RTSP_STS_UNSUPPORTED_TRANSPORT:
7471 gst_rtsp_message_unset (&request);
7472 gst_rtsp_message_unset (&response);
7473 /* cleanup of leftover transport */
7474 gst_rtspsrc_stream_free_udp (stream);
7475 /* MS WMServer RTSP MUST use same UDP pair in all SETUP requests;
7476 * we might be in this case */
7477 if (stream->container && rtpport && rtcpport && !retry) {
7478 GST_DEBUG_OBJECT (src, "retrying with original port pair %u-%u",
7483 /* this transport did not go down well, but we may have others to try
7484 * that we did not send yet, try those and only give up then
7485 * but not without checking for lost cause/extension so we can
7486 * post a nicer/more useful error message later */
7487 if (!unsupported_real)
7488 unsupported_real = stream->is_real;
7489 /* select next available protocol, give up on this stream if none */
7491 while (protocol_masks[mask] && !(protocols & protocol_masks[mask]))
7493 if (!protocol_masks[mask] || unsupported_real)
7498 /* cleanup of leftover transport and move to the next stream */
7499 gst_rtspsrc_stream_free_udp (stream);
7500 goto response_error;
7504 if (!pipelined_request_id) {
7505 /* parse response transport */
7506 res = gst_rtsp_src_setup_stream_from_response (src, stream,
7507 &response, &protocols, retry, &rtpport, &rtcpport);
7509 case GST_RTSP_ERROR:
7511 case GST_RTSP_ELAST:
7517 stream->waiting_setup_response = TRUE;
7518 /* we need to activate at least one stream when we detect activity */
7519 src->need_activate = TRUE;
7526 GstRTSPStream *sskip;
7528 skip = g_list_next (skip);
7532 sskip = (GstRTSPStream *) skip->data;
7534 /* skip all streams with the same control url */
7535 if (g_str_equal (stream->conninfo.location, sskip->conninfo.location)) {
7536 GST_DEBUG_OBJECT (src, "found stream %p with same control %s",
7537 sskip, sskip->conninfo.location);
7538 sskip->skipped = TRUE;
7542 gst_rtsp_message_unset (&request);
7545 if (pipelined_request_id) {
7546 gst_rtspsrc_setup_streams_end (src, TRUE);
7549 /* store the transport protocol that was configured */
7550 src->cur_protocols = protocols;
7552 gst_rtsp_ext_list_stream_select (src->extensions, url);
7554 if (pipelined_request_id)
7555 g_free (pipelined_request_id);
7557 /* if there is nothing to activate, error out */
7558 if (!src->need_activate)
7559 goto nothing_to_activate;
7566 /* no transport possible, post an error and stop */
7567 GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
7568 ("Could not connect to server, no protocols left"));
7569 return GST_RTSP_ERROR;
7573 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
7574 ("SDP contains no streams"));
7575 return GST_RTSP_ERROR;
7577 create_request_failed:
7579 gchar *str = gst_rtsp_strresult (res);
7581 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
7582 ("Could not create request. (%s)", str));
7586 setup_transport_failed:
7588 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
7589 ("Could not setup transport."));
7590 res = GST_RTSP_ERROR;
7595 const gchar *str = gst_rtsp_status_as_text (code);
7597 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
7598 ("Error (%d): %s", code, GST_STR_NULL (str)));
7599 res = GST_RTSP_ERROR;
7604 gchar *str = gst_rtsp_strresult (res);
7606 if (res != GST_RTSP_EINTR) {
7607 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
7608 ("Could not send message. (%s)", str));
7610 GST_WARNING_OBJECT (src, "send interrupted");
7615 nothing_to_activate:
7617 /* none of the available error codes is really right .. */
7618 if (unsupported_real) {
7619 GST_ELEMENT_ERROR (src, STREAM, CODEC_NOT_FOUND,
7620 (_("No supported stream was found. You might need to install a "
7621 "GStreamer RTSP extension plugin for Real media streams.")),
7624 GST_ELEMENT_ERROR (src, STREAM, CODEC_NOT_FOUND,
7625 (_("No supported stream was found. You might need to allow "
7626 "more transport protocols or may otherwise be missing "
7627 "the right GStreamer RTSP extension plugin.")), (NULL));
7629 return GST_RTSP_ERROR;
7633 if (pipelined_request_id)
7634 g_free (pipelined_request_id);
7635 gst_rtsp_message_unset (&request);
7636 gst_rtsp_message_unset (&response);
7642 gst_rtspsrc_parse_range (GstRTSPSrc * src, const gchar * range,
7643 GstSegment * segment, gboolean update_duration)
7645 GstClockTime begin_seconds, end_seconds;
7647 GstRTSPTimeRange *therange;
7650 gst_rtsp_range_free (src->range);
7652 if (gst_rtsp_range_parse (range, &therange) == GST_RTSP_OK) {
7653 GST_DEBUG_OBJECT (src, "parsed range %s", range);
7654 src->range = therange;
7656 GST_DEBUG_OBJECT (src, "failed to parse range %s", range);
7658 gst_segment_init (segment, GST_FORMAT_TIME);
7662 gst_rtsp_range_get_times (therange, &begin_seconds, &end_seconds);
7664 GST_DEBUG_OBJECT (src, "range: type %d, min %f - type %d, max %f ",
7665 therange->min.type, therange->min.seconds, therange->max.type,
7666 therange->max.seconds);
7668 if (therange->min.type == GST_RTSP_TIME_NOW)
7670 else if (therange->min.type == GST_RTSP_TIME_END)
7673 seconds = begin_seconds;
7675 GST_DEBUG_OBJECT (src, "range: min %" GST_TIME_FORMAT,
7676 GST_TIME_ARGS (seconds));
7678 /* we need to start playback without clipping from the position reported by
7680 if (segment->rate > 0.0)
7681 segment->start = seconds;
7683 segment->stop = seconds;
7685 segment->position = seconds;
7687 if (therange->max.type == GST_RTSP_TIME_NOW)
7689 else if (therange->max.type == GST_RTSP_TIME_END)
7692 seconds = end_seconds;
7694 GST_DEBUG_OBJECT (src, "range: max %" GST_TIME_FORMAT,
7695 GST_TIME_ARGS (seconds));
7697 /* live (WMS) server might send overflowed large max as its idea of infinity,
7698 * compensate to prevent problems later on */
7699 if (seconds != -1 && seconds < 0) {
7701 GST_DEBUG_OBJECT (src, "insane range, set to NONE");
7704 /* live (WMS) might send min == max, which is not worth recording */
7705 if (segment->duration == -1 && seconds == begin_seconds)
7708 /* don't change duration with unknown value, we might have a valid value
7709 * there that we want to keep. Also, the total duration of the stream
7710 * can only be determined from the response to a DESCRIBE request, not
7711 * from a PLAY request where we might have requested a custom range, so
7712 * don't update duration in that case */
7713 if (update_duration && seconds != -1) {
7714 segment->duration = seconds;
7715 GST_DEBUG_OBJECT (src, "set duration from range as %" GST_TIME_FORMAT,
7716 GST_TIME_ARGS (seconds));
7718 GST_DEBUG_OBJECT (src, "not updating existing duration %" GST_TIME_FORMAT
7719 " from range %" GST_TIME_FORMAT, GST_TIME_ARGS (segment->duration),
7720 GST_TIME_ARGS (seconds));
7723 if (segment->rate > 0.0)
7724 segment->stop = seconds;
7726 segment->start = seconds;
7731 /* Parse clock profived by the server with following syntax:
7733 * "GstNetTimeProvider <wrapped-clock> <server-IP:port> <clock-time>"
7736 gst_rtspsrc_parse_gst_clock (GstRTSPSrc * src, const gchar * gstclock)
7738 gboolean res = FALSE;
7740 if (g_str_has_prefix (gstclock, "GstNetTimeProvider ")) {
7741 gchar **fields = NULL, **parts = NULL;
7742 gchar *remote_ip, *str;
7744 GstClockTime base_time;
7747 fields = g_strsplit (gstclock, " ", 0);
7749 /* wrapped clock, not very interesting for now */
7750 if (fields[1] == NULL)
7753 /* remote IP address and port */
7754 if ((str = fields[2]) == NULL)
7757 parts = g_strsplit (str, ":", 0);
7759 if ((remote_ip = parts[0]) == NULL)
7762 if ((str = parts[1]) == NULL)
7770 if ((str = fields[3]) == NULL)
7773 base_time = g_ascii_strtoull (str, NULL, 10);
7776 gst_net_client_clock_new ((gchar *) "GstRTSPClock", remote_ip, port,
7779 if (src->provided_clock)
7780 gst_object_unref (src->provided_clock);
7781 src->provided_clock = netclock;
7783 gst_element_post_message (GST_ELEMENT_CAST (src),
7784 gst_message_new_clock_provide (GST_OBJECT_CAST (src),
7785 src->provided_clock, TRUE));
7789 g_strfreev (fields);
7795 /* must be called with the RTSP state lock */
7796 static GstRTSPResult
7797 gst_rtspsrc_open_from_sdp (GstRTSPSrc * src, GstSDPMessage * sdp,
7803 /* prepare global stream caps properties */
7805 gst_structure_remove_all_fields (src->props);
7807 src->props = gst_structure_new_empty ("RTSPProperties");
7809 DEBUG_SDP (src, sdp);
7811 gst_rtsp_ext_list_parse_sdp (src->extensions, sdp, src->props);
7813 /* let the app inspect and change the SDP */
7814 g_signal_emit (src, gst_rtspsrc_signals[SIGNAL_ON_SDP], 0, sdp);
7816 gst_segment_init (&src->segment, GST_FORMAT_TIME);
7818 /* parse range for duration reporting. */
7823 range = gst_sdp_message_get_attribute_val_n (sdp, "range", i);
7827 /* keep track of the range and configure it in the segment */
7828 if (gst_rtspsrc_parse_range (src, range, &src->segment, TRUE))
7832 /* parse clock information. This is GStreamer specific, a server can tell the
7833 * client what clock it is using and wrap that in a network clock. The
7834 * advantage of that is that we can slave to it. */
7836 const gchar *gstclock;
7839 gstclock = gst_sdp_message_get_attribute_val_n (sdp, "x-gst-clock", i);
7840 if (gstclock == NULL)
7843 /* parse the clock and expose it in the provide_clock method */
7844 if (gst_rtspsrc_parse_gst_clock (src, gstclock))
7848 /* try to find a global control attribute. Note that a '*' means that we should
7849 * do aggregate control with the current url (so we don't do anything and
7850 * leave the current connection as is) */
7852 const gchar *control;
7855 control = gst_sdp_message_get_attribute_val_n (sdp, "control", i);
7856 if (control == NULL)
7859 /* only take fully qualified urls */
7860 if (g_str_has_prefix (control, "rtsp://"))
7864 g_free (src->conninfo.location);
7865 src->conninfo.location = g_strdup (control);
7866 /* make a connection for this, if there was a connection already, nothing
7868 if (gst_rtsp_conninfo_connect (src, &src->conninfo, async) < 0) {
7869 GST_ERROR_OBJECT (src, "could not connect");
7872 /* we need to keep the control url separate from the connection url because
7873 * the rules for constructing the media control url need it */
7874 g_free (src->control);
7875 src->control = g_strdup (control);
7878 /* create streams */
7879 n_streams = gst_sdp_message_medias_len (sdp);
7880 for (i = 0; i < n_streams; i++) {
7881 gst_rtspsrc_create_stream (src, sdp, i, n_streams);
7884 src->state = GST_RTSP_STATE_INIT;
7887 if ((res = gst_rtspsrc_setup_streams_start (src, async)) < 0)
7890 /* reset our state */
7891 src->need_range = TRUE;
7892 src->server_side_trickmode = FALSE;
7893 src->trickmode_interval = 0;
7895 src->state = GST_RTSP_STATE_READY;
7902 GST_ERROR_OBJECT (src, "setup failed");
7903 gst_rtspsrc_cleanup (src);
7908 static GstRTSPResult
7909 gst_rtspsrc_retrieve_sdp (GstRTSPSrc * src, GstSDPMessage ** sdp,
7913 GstRTSPMessage request = { 0 };
7914 GstRTSPMessage response = { 0 };
7917 gchar *respcont = NULL;
7918 GstRTSPVersion versions[] =
7919 { GST_RTSP_VERSION_2_0, GST_RTSP_VERSION_INVALID };
7921 src->version = src->default_version;
7922 if (src->default_version == GST_RTSP_VERSION_2_0) {
7923 versions[0] = GST_RTSP_VERSION_1_0;
7927 src->need_redirect = FALSE;
7929 /* can't continue without a valid url */
7930 if (G_UNLIKELY (src->conninfo.url == NULL)) {
7931 res = GST_RTSP_EINVAL;
7934 src->tried_url_auth = FALSE;
7936 if ((res = gst_rtsp_conninfo_connect (src, &src->conninfo, async)) < 0)
7937 goto connect_failed;
7939 /* create OPTIONS */
7940 GST_DEBUG_OBJECT (src, "create options... (%s)", async ? "async" : "sync");
7942 gst_rtspsrc_init_request (src, &request, GST_RTSP_OPTIONS,
7943 src->conninfo.url_str);
7945 goto create_request_failed;
7948 request.type_data.request.version = src->version;
7949 GST_DEBUG_OBJECT (src, "send options...");
7952 GST_ELEMENT_PROGRESS (src, CONTINUE, "open", ("Retrieving server options"));
7955 gst_rtspsrc_send (src, &src->conninfo, &request, &response,
7956 NULL, versions)) < 0) {
7960 src->version = request.type_data.request.version;
7961 GST_INFO_OBJECT (src, "Now using version: %s",
7962 gst_rtsp_version_as_text (src->version));
7965 if (!gst_rtspsrc_parse_methods (src, &response))
7968 /* create DESCRIBE */
7969 GST_DEBUG_OBJECT (src, "create describe...");
7971 gst_rtspsrc_init_request (src, &request, GST_RTSP_DESCRIBE,
7972 src->conninfo.url_str);
7974 goto create_request_failed;
7976 /* we only accept SDP for now */
7977 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_ACCEPT,
7980 if (src->backchannel == BACKCHANNEL_ONVIF)
7981 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
7982 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
7983 /* TODO: Handle the case when backchannel is unsupported and goto restart */
7986 GST_DEBUG_OBJECT (src, "send describe...");
7989 GST_ELEMENT_PROGRESS (src, CONTINUE, "open", ("Retrieving media info"));
7992 gst_rtspsrc_send (src, &src->conninfo, &request, &response,
7996 /* we only perform redirect for describe and play, currently */
7997 if (src->need_redirect) {
7998 /* close connection, we don't have to send a TEARDOWN yet, ignore the
8000 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
8002 gst_rtsp_message_unset (&request);
8003 gst_rtsp_message_unset (&response);
8009 /* it could be that the DESCRIBE method was not implemented */
8010 if (!(src->methods & GST_RTSP_DESCRIBE))
8013 /* check if reply is SDP */
8014 gst_rtsp_message_get_header (&response, GST_RTSP_HDR_CONTENT_TYPE, &respcont,
8016 /* could not be set but since the request returned OK, we assume it
8017 * was SDP, else check it. */
8019 const gchar *props = strchr (respcont, ';');
8022 gchar *mimetype = g_strndup (respcont, props - respcont);
8024 mimetype = g_strstrip (mimetype);
8025 if (g_ascii_strcasecmp (mimetype, "application/sdp") != 0) {
8027 goto wrong_content_type;
8030 /* TODO: Check for charset property and do conversions of all messages if
8031 * needed. Some servers actually send that property */
8034 } else if (g_ascii_strcasecmp (respcont, "application/sdp") != 0) {
8035 goto wrong_content_type;
8039 /* get message body and parse as SDP */
8040 gst_rtsp_message_get_body (&response, &data, &size);
8041 if (data == NULL || size == 0)
8044 GST_DEBUG_OBJECT (src, "parse SDP...");
8045 gst_sdp_message_new (sdp);
8046 gst_sdp_message_parse_buffer (data, size, *sdp);
8048 /* clean up any messages */
8049 gst_rtsp_message_unset (&request);
8050 gst_rtsp_message_unset (&response);
8057 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
8058 ("No valid RTSP URL was provided"));
8063 gchar *str = gst_rtsp_strresult (res);
8065 if (res != GST_RTSP_EINTR) {
8066 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
8067 ("Failed to connect. (%s)", str));
8069 GST_WARNING_OBJECT (src, "connect interrupted");
8074 create_request_failed:
8076 gchar *str = gst_rtsp_strresult (res);
8078 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
8079 ("Could not create request. (%s)", str));
8085 /* Don't post a message - the rtsp_send method will have
8086 * taken care of it because we passed NULL for the response code */
8091 /* error was posted */
8092 res = GST_RTSP_ERROR;
8097 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
8098 ("Server does not support SDP, got %s.", respcont));
8099 res = GST_RTSP_ERROR;
8104 GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
8105 ("Server can not provide an SDP."));
8106 res = GST_RTSP_ERROR;
8111 if (src->conninfo.connection) {
8112 GST_DEBUG_OBJECT (src, "free connection");
8113 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
8115 gst_rtsp_message_unset (&request);
8116 gst_rtsp_message_unset (&response);
8121 static GstRTSPResult
8122 gst_rtspsrc_open (GstRTSPSrc * src, gboolean async)
8127 GST_RTSP_SETUP | GST_RTSP_PLAY | GST_RTSP_PAUSE | GST_RTSP_TEARDOWN;
8129 if (src->sdp == NULL) {
8130 if ((ret = gst_rtspsrc_retrieve_sdp (src, &src->sdp, async)) < 0)
8134 if ((ret = gst_rtspsrc_open_from_sdp (src, src->sdp, async)) < 0)
8137 if (src->initial_seek) {
8138 if (!gst_rtspsrc_perform_seek (src, src->initial_seek))
8139 goto initial_seek_failed;
8140 gst_event_replace (&src->initial_seek, NULL);
8145 gst_rtspsrc_loop_end_cmd (src, CMD_OPEN, ret);
8152 GST_WARNING_OBJECT (src, "can't get sdp");
8153 src->open_error = TRUE;
8158 GST_WARNING_OBJECT (src, "can't setup streaming from sdp");
8159 src->open_error = TRUE;
8162 initial_seek_failed:
8164 GST_WARNING_OBJECT (src, "Failed to perform initial seek");
8165 ret = GST_RTSP_ERROR;
8166 src->open_error = TRUE;
8171 static GstRTSPResult
8172 gst_rtspsrc_close (GstRTSPSrc * src, gboolean async, gboolean only_close)
8174 GstRTSPMessage request = { 0 };
8175 GstRTSPMessage response = { 0 };
8176 GstRTSPResult res = GST_RTSP_OK;
8178 const gchar *control;
8180 GST_DEBUG_OBJECT (src, "TEARDOWN...");
8182 gst_rtspsrc_set_state (src, GST_STATE_READY);
8184 if (src->state < GST_RTSP_STATE_READY) {
8185 GST_DEBUG_OBJECT (src, "not ready, doing cleanup");
8192 /* construct a control url */
8193 control = get_aggregate_control (src);
8195 if (!(src->methods & (GST_RTSP_PLAY | GST_RTSP_TEARDOWN)))
8198 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8199 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8200 const gchar *setup_url;
8201 GstRTSPConnInfo *info;
8203 /* try aggregate control first but do non-aggregate control otherwise */
8205 setup_url = control;
8206 else if ((setup_url = stream->conninfo.location) == NULL)
8209 if (src->conninfo.connection) {
8210 info = &src->conninfo;
8211 } else if (stream->conninfo.connection) {
8212 info = &stream->conninfo;
8216 if (!info->connected)
8221 gst_rtspsrc_init_request (src, &request, GST_RTSP_TEARDOWN, setup_url);
8222 GST_LOG_OBJECT (src, "Teardown on %s", setup_url);
8224 goto create_request_failed;
8226 if (stream->is_backchannel && src->backchannel == BACKCHANNEL_ONVIF)
8227 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
8228 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
8231 GST_ELEMENT_PROGRESS (src, CONTINUE, "close", ("Closing stream"));
8234 gst_rtspsrc_send (src, info, &request, &response, NULL, NULL)) < 0)
8237 /* FIXME, parse result? */
8238 gst_rtsp_message_unset (&request);
8239 gst_rtsp_message_unset (&response);
8242 /* early exit when we did aggregate control */
8248 /* close connections */
8249 GST_DEBUG_OBJECT (src, "closing connection...");
8250 gst_rtsp_conninfo_close (src, &src->conninfo, TRUE);
8251 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8252 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8253 gst_rtsp_conninfo_close (src, &stream->conninfo, TRUE);
8257 gst_rtspsrc_cleanup (src);
8259 src->state = GST_RTSP_STATE_INVALID;
8262 gst_rtspsrc_loop_end_cmd (src, CMD_CLOSE, res);
8267 create_request_failed:
8269 gchar *str = gst_rtsp_strresult (res);
8271 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
8272 ("Could not create request. (%s)", str));
8278 gchar *str = gst_rtsp_strresult (res);
8280 gst_rtsp_message_unset (&request);
8281 if (res != GST_RTSP_EINTR) {
8282 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
8283 ("Could not send message. (%s)", str));
8285 GST_WARNING_OBJECT (src, "TEARDOWN interrupted");
8292 GST_DEBUG_OBJECT (src,
8293 "TEARDOWN and PLAY not supported, can't do TEARDOWN");
8298 /* RTP-Info is of the format:
8300 * url=<URL>;[seq=<seqbase>;rtptime=<timebase>] [, url=...]
8302 * rtptime corresponds to the timestamp for the NPT time given in the header
8303 * seqbase corresponds to the next sequence number we received. This number
8304 * indicates the first seqnum after the seek and should be used to discard
8305 * packets that are from before the seek.
8308 gst_rtspsrc_parse_rtpinfo (GstRTSPSrc * src, gchar * rtpinfo)
8313 GST_DEBUG_OBJECT (src, "parsing RTP-Info %s", rtpinfo);
8315 infos = g_strsplit (rtpinfo, ",", 0);
8316 for (i = 0; infos[i]; i++) {
8318 GstRTSPStream *stream;
8322 GST_DEBUG_OBJECT (src, "parsing info %s", infos[i]);
8324 /* init values, types of seqbase and timebase are bigger than needed so we
8325 * can store -1 as uninitialized values */
8330 /* parse url, find stream for url.
8331 * parse seq and rtptime. The seq number should be configured in the rtp
8332 * depayloader or session manager to detect gaps. Same for the rtptime, it
8333 * should be used to create an initial time newsegment. */
8334 fields = g_strsplit (infos[i], ";", 0);
8335 for (j = 0; fields[j]; j++) {
8336 GST_DEBUG_OBJECT (src, "parsing field %s", fields[j]);
8337 /* remove leading whitespace */
8338 fields[j] = g_strchug (fields[j]);
8339 if (g_str_has_prefix (fields[j], "url=")) {
8340 /* get the url and the stream */
8342 find_stream (src, (fields[j] + 4), (gpointer) find_stream_by_setup);
8343 } else if (g_str_has_prefix (fields[j], "seq=")) {
8344 seqbase = atoi (fields[j] + 4);
8345 } else if (g_str_has_prefix (fields[j], "rtptime=")) {
8346 timebase = g_ascii_strtoll (fields[j] + 8, NULL, 10);
8349 g_strfreev (fields);
8350 /* now we need to store the values for the caps of the stream */
8351 if (stream != NULL) {
8352 GST_DEBUG_OBJECT (src,
8353 "found stream %p, setting: seqbase %d, timebase %" G_GINT64_FORMAT,
8354 stream, seqbase, timebase);
8356 /* we have a stream, configure detected params */
8357 stream->seqbase = seqbase;
8358 stream->timebase = timebase;
8367 gst_rtspsrc_handle_rtcp_interval (GstRTSPSrc * src, gchar * rtcp)
8372 interval = strtoul (rtcp, NULL, 10);
8373 GST_DEBUG_OBJECT (src, "rtcp interval: %" G_GUINT64_FORMAT " ms", interval);
8378 interval *= GST_MSECOND;
8380 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8381 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8383 /* already (optionally) retrieved this when configuring manager */
8384 if (stream->session) {
8385 GObject *rtpsession = stream->session;
8387 GST_DEBUG_OBJECT (src, "configure rtcp interval in session %p",
8389 g_object_set (rtpsession, "rtcp-min-interval", interval, NULL);
8393 /* now it happens that (Xenon) server sending this may also provide bogus
8394 * RTCP SR sync data (i.e. with quite some jitter), so never mind those
8395 * and just use RTP-Info to sync */
8397 GObjectClass *klass;
8399 klass = G_OBJECT_GET_CLASS (G_OBJECT (src->manager));
8400 if (g_object_class_find_property (klass, "rtcp-sync")) {
8401 GST_DEBUG_OBJECT (src, "configuring rtp sync method");
8402 g_object_set (src->manager, "rtcp-sync", RTCP_SYNC_RTP, NULL);
8408 gst_rtspsrc_get_float (const gchar * dstr)
8410 gchar s[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
8412 /* canonicalise floating point string so we can handle float strings
8413 * in the form "24.930" or "24,930" irrespective of the current locale */
8414 g_strlcpy (s, dstr, sizeof (s));
8415 g_strdelimit (s, ",", '.');
8416 return g_ascii_strtod (s, NULL);
8420 gen_range_header (GstRTSPSrc * src, GstSegment * segment)
8422 GstRTSPTimeRange range = { 0, };
8423 gdouble begin_seconds, end_seconds;
8425 if (segment->rate > 0) {
8426 begin_seconds = (gdouble) segment->start / GST_SECOND;
8427 end_seconds = (gdouble) segment->stop / GST_SECOND;
8429 begin_seconds = (gdouble) segment->stop / GST_SECOND;
8430 end_seconds = (gdouble) segment->start / GST_SECOND;
8433 if (src->onvif_mode) {
8434 GDateTime *prime_epoch, *datetime;
8436 range.unit = GST_RTSP_RANGE_CLOCK;
8438 prime_epoch = g_date_time_new_utc (1900, 1, 1, 0, 0, 0);
8440 datetime = g_date_time_add_seconds (prime_epoch, begin_seconds);
8442 range.min.type = GST_RTSP_TIME_UTC;
8443 range.min2.year = g_date_time_get_year (datetime);
8444 range.min2.month = g_date_time_get_month (datetime);
8445 range.min2.day = g_date_time_get_day_of_month (datetime);
8447 g_date_time_get_seconds (datetime) +
8448 g_date_time_get_minute (datetime) * 60 +
8449 g_date_time_get_hour (datetime) * 60 * 60;
8451 g_date_time_unref (datetime);
8453 datetime = g_date_time_add_seconds (prime_epoch, end_seconds);
8455 range.max.type = GST_RTSP_TIME_UTC;
8456 range.max2.year = g_date_time_get_year (datetime);
8457 range.max2.month = g_date_time_get_month (datetime);
8458 range.max2.day = g_date_time_get_day_of_month (datetime);
8460 g_date_time_get_seconds (datetime) +
8461 g_date_time_get_minute (datetime) * 60 +
8462 g_date_time_get_hour (datetime) * 60 * 60;
8464 g_date_time_unref (datetime);
8465 g_date_time_unref (prime_epoch);
8467 range.unit = GST_RTSP_RANGE_NPT;
8469 if (src->range && src->range->min.type == GST_RTSP_TIME_NOW) {
8470 range.min.type = GST_RTSP_TIME_NOW;
8472 range.min.type = GST_RTSP_TIME_SECONDS;
8473 range.min.seconds = begin_seconds;
8476 if (src->range && src->range->max.type == GST_RTSP_TIME_END) {
8477 range.max.type = GST_RTSP_TIME_END;
8479 range.max.type = GST_RTSP_TIME_SECONDS;
8480 range.max.seconds = end_seconds;
8484 /* Don't set end bounds when not required to */
8485 if (!GST_CLOCK_TIME_IS_VALID (segment->stop)) {
8486 if (segment->rate > 0)
8487 range.max.type = GST_RTSP_TIME_END;
8489 range.min.type = GST_RTSP_TIME_END;
8492 return gst_rtsp_range_to_string (&range);
8496 clear_rtp_base (GstRTSPSrc * src, GstRTSPStream * stream)
8500 stream->timebase = -1;
8501 stream->seqbase = -1;
8503 len = stream->ptmap->len;
8504 for (i = 0; i < len; i++) {
8505 PtMapItem *item = &g_array_index (stream->ptmap, PtMapItem, i);
8508 if (item->caps == NULL)
8511 item->caps = gst_caps_make_writable (item->caps);
8512 s = gst_caps_get_structure (item->caps, 0);
8513 gst_structure_remove_fields (s, "clock-base", "seqnum-base", NULL);
8514 if (item->pt == stream->default_pt && stream->udpsrc[0])
8515 g_object_set (stream->udpsrc[0], "caps", item->caps, NULL);
8517 stream->need_caps = TRUE;
8520 static GstRTSPResult
8521 gst_rtspsrc_ensure_open (GstRTSPSrc * src, gboolean async)
8523 GstRTSPResult res = GST_RTSP_OK;
8525 if (src->state < GST_RTSP_STATE_READY) {
8526 res = GST_RTSP_ERROR;
8527 if (src->open_error) {
8528 GST_DEBUG_OBJECT (src, "the stream was in error");
8532 gst_rtspsrc_loop_start_cmd (src, CMD_OPEN);
8534 if ((res = gst_rtspsrc_open (src, async)) < 0) {
8535 GST_DEBUG_OBJECT (src, "failed to open stream");
8544 static GstRTSPResult
8545 gst_rtspsrc_play (GstRTSPSrc * src, GstSegment * segment, gboolean async,
8546 const gchar * seek_style)
8548 GstRTSPMessage request = { 0 };
8549 GstRTSPMessage response = { 0 };
8550 GstRTSPResult res = GST_RTSP_OK;
8554 const gchar *control;
8555 GstSegment requested;
8557 GST_DEBUG_OBJECT (src, "PLAY...");
8560 if ((res = gst_rtspsrc_ensure_open (src, async)) < 0)
8563 if (!(src->methods & GST_RTSP_PLAY))
8566 if (src->state == GST_RTSP_STATE_PLAYING)
8569 if (!src->conninfo.connection || !src->conninfo.connected)
8572 requested = *segment;
8574 /* send some dummy packets before we activate the receive in the
8576 gst_rtspsrc_send_dummy_packets (src);
8578 /* require new SR packets */
8580 g_signal_emit_by_name (src->manager, "reset-sync", NULL);
8582 /* construct a control url */
8583 control = get_aggregate_control (src);
8585 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8586 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8587 const gchar *setup_url;
8588 GstRTSPConnInfo *conninfo;
8590 /* try aggregate control first but do non-aggregate control otherwise */
8592 setup_url = control;
8593 else if ((setup_url = stream->conninfo.location) == NULL)
8596 if (src->conninfo.connection) {
8597 conninfo = &src->conninfo;
8598 } else if (stream->conninfo.connection) {
8599 conninfo = &stream->conninfo;
8605 res = gst_rtspsrc_init_request (src, &request, GST_RTSP_PLAY, setup_url);
8607 goto create_request_failed;
8609 if (src->need_range && src->seekable >= 0.0) {
8610 hval = gen_range_header (src, segment);
8612 gst_rtsp_message_take_header (&request, GST_RTSP_HDR_RANGE, hval);
8614 /* store the newsegment event so it can be sent from the streaming thread. */
8615 src->need_segment = TRUE;
8618 if (segment->rate != 1.0) {
8619 gchar scale_val[G_ASCII_DTOSTR_BUF_SIZE];
8620 gchar speed_val[G_ASCII_DTOSTR_BUF_SIZE];
8622 if (src->server_side_trickmode) {
8623 g_ascii_dtostr (scale_val, sizeof (scale_val), segment->rate);
8624 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SCALE, scale_val);
8625 } else if (segment->rate < 0.0) {
8626 g_ascii_dtostr (scale_val, sizeof (scale_val), -1.0);
8627 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SCALE, scale_val);
8629 if (ABS (segment->rate) != 1.0) {
8630 g_ascii_dtostr (speed_val, sizeof (speed_val), ABS (segment->rate));
8631 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SPEED, speed_val);
8634 g_ascii_dtostr (speed_val, sizeof (speed_val), segment->rate);
8635 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SPEED, speed_val);
8639 if (src->onvif_mode) {
8640 if (segment->flags & GST_SEEK_FLAG_TRICKMODE_KEY_UNITS) {
8643 if (src->trickmode_interval)
8645 g_strdup_printf ("intra/%" G_GUINT64_FORMAT,
8646 src->trickmode_interval / GST_MSECOND);
8648 hval = g_strdup ("intra");
8650 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_FRAMES, hval);
8653 } else if (segment->flags & GST_SEEK_FLAG_TRICKMODE_FORWARD_PREDICTED) {
8654 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_FRAMES,
8660 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SEEK_STYLE,
8663 /* when we have an ONVIF audio backchannel, the PLAY request must have the
8664 * Require: header when doing either aggregate or non-aggregate control */
8665 if (src->backchannel == BACKCHANNEL_ONVIF &&
8666 (control || stream->is_backchannel))
8667 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
8668 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
8670 if (src->onvif_mode) {
8671 if (src->onvif_rate_control)
8672 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_RATE_CONTROL,
8675 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_RATE_CONTROL, "no");
8679 GST_ELEMENT_PROGRESS (src, CONTINUE, "request", ("Sending PLAY request"));
8682 gst_rtspsrc_send (src, conninfo, &request, &response, NULL, NULL))
8686 if (src->need_redirect) {
8687 GST_DEBUG_OBJECT (src,
8688 "redirect: tearing down and restarting with new url");
8689 /* teardown and restart with new url */
8690 gst_rtspsrc_close (src, TRUE, FALSE);
8691 /* reset protocols to force re-negotiation with redirected url */
8692 src->cur_protocols = src->protocols;
8693 gst_rtsp_message_unset (&request);
8694 gst_rtsp_message_unset (&response);
8698 /* seek may have silently failed as it is not supported */
8699 if (!(src->methods & GST_RTSP_PLAY)) {
8700 GST_DEBUG_OBJECT (src, "PLAY Range not supported; re-enable PLAY");
8702 if (src->version >= GST_RTSP_VERSION_2_0 && src->seekable >= 0.0) {
8703 GST_WARNING_OBJECT (src, "Server declared stream as seekable but"
8704 " playing with range failed... Ignoring information.");
8706 /* obviously it is supported as we made it here */
8707 src->methods |= GST_RTSP_PLAY;
8708 src->seekable = -1.0;
8709 /* but there is nothing to parse in the response,
8710 * so convey we have no idea and not to expect anything particular */
8711 clear_rtp_base (src, stream);
8715 /* need to do for all streams */
8716 for (run = src->streams; run; run = g_list_next (run))
8717 clear_rtp_base (src, (GstRTSPStream *) run->data);
8719 /* NOTE the above also disables npt based eos detection */
8720 /* and below forces position to 0,
8721 * which is visible feedback we lost the plot */
8722 segment->start = segment->position = src->last_pos;
8725 gst_rtsp_message_unset (&request);
8727 /* parse RTP npt field. This is the current position in the stream (Normal
8728 * Play Time) and should be put in the NEWSEGMENT position field. */
8729 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RANGE, &hval,
8731 gst_rtspsrc_parse_range (src, hval, segment, FALSE);
8733 /* assume 1.0 rate now, overwrite when the SCALE or SPEED headers are present. */
8734 segment->rate = 1.0;
8736 /* parse Speed header. This is the intended playback rate of the stream
8737 * and should be put in the NEWSEGMENT rate field. */
8738 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_SPEED, &hval,
8739 0) == GST_RTSP_OK) {
8740 segment->rate = gst_rtspsrc_get_float (hval);
8741 } else if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_SCALE,
8742 &hval, 0) == GST_RTSP_OK) {
8743 segment->rate = gst_rtspsrc_get_float (hval);
8746 /* parse the RTP-Info header field (if ANY) to get the base seqnum and timestamp
8747 * for the RTP packets. If this is not present, we assume all starts from 0...
8748 * This is info for the RTP session manager that we pass to it in caps. */
8750 while (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RTP_INFO,
8751 &hval, hval_idx++) == GST_RTSP_OK)
8752 gst_rtspsrc_parse_rtpinfo (src, hval);
8754 /* some servers indicate RTCP parameters in PLAY response,
8755 * rather than properly in SDP */
8756 if (gst_rtsp_message_get_header (&response, GST_RTSP_HDR_RTCP_INTERVAL,
8757 &hval, 0) == GST_RTSP_OK)
8758 gst_rtspsrc_handle_rtcp_interval (src, hval);
8760 gst_rtsp_message_unset (&response);
8762 /* early exit when we did aggregate control */
8767 src->out_segment = *segment;
8769 if (src->clip_out_segment) {
8770 /* Only clip the output segment when the server has answered with valid
8771 * values, we cannot know otherwise whether the requested bounds were
8773 if (GST_CLOCK_TIME_IS_VALID (src->segment.start) &&
8774 GST_CLOCK_TIME_IS_VALID (requested.start))
8775 src->out_segment.start = MAX (src->out_segment.start, requested.start);
8776 if (GST_CLOCK_TIME_IS_VALID (src->segment.stop) &&
8777 GST_CLOCK_TIME_IS_VALID (requested.stop))
8778 src->out_segment.stop = MIN (src->out_segment.stop, requested.stop);
8781 /* configure the caps of the streams after we parsed all headers. Only reset
8782 * the manager object when we set a new Range header (we did a seek) */
8783 gst_rtspsrc_configure_caps (src, segment, src->need_range);
8785 /* set to PLAYING after we have configured the caps, otherwise we
8786 * might end up calling request_key (with SRTP) while caps are still
8787 * being configured. */
8788 gst_rtspsrc_set_state (src, GST_STATE_PLAYING);
8790 /* set again when needed */
8791 src->need_range = FALSE;
8793 src->running = TRUE;
8794 src->base_time = -1;
8795 src->state = GST_RTSP_STATE_PLAYING;
8798 GST_DEBUG_OBJECT (src, "mark DISCONT, we did a seek to another position");
8799 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8800 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8801 stream->discont = TRUE;
8806 gst_rtspsrc_loop_end_cmd (src, CMD_PLAY, res);
8813 GST_WARNING_OBJECT (src, "failed to open stream");
8818 GST_WARNING_OBJECT (src, "PLAY is not supported");
8823 GST_WARNING_OBJECT (src, "we were already PLAYING");
8826 create_request_failed:
8828 gchar *str = gst_rtsp_strresult (res);
8830 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
8831 ("Could not create request. (%s)", str));
8837 gchar *str = gst_rtsp_strresult (res);
8839 gst_rtsp_message_unset (&request);
8840 if (res != GST_RTSP_EINTR) {
8841 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
8842 ("Could not send message. (%s)", str));
8844 GST_WARNING_OBJECT (src, "PLAY interrupted");
8851 static GstRTSPResult
8852 gst_rtspsrc_pause (GstRTSPSrc * src, gboolean async)
8854 GstRTSPResult res = GST_RTSP_OK;
8855 GstRTSPMessage request = { 0 };
8856 GstRTSPMessage response = { 0 };
8858 const gchar *control;
8860 GST_DEBUG_OBJECT (src, "PAUSE...");
8862 if ((res = gst_rtspsrc_ensure_open (src, async)) < 0)
8865 if (!(src->methods & GST_RTSP_PAUSE))
8868 if (src->state == GST_RTSP_STATE_READY)
8871 if (!src->conninfo.connection || !src->conninfo.connected)
8874 /* construct a control url */
8875 control = get_aggregate_control (src);
8877 /* loop over the streams. We might exit the loop early when we could do an
8878 * aggregate control */
8879 for (walk = src->streams; walk; walk = g_list_next (walk)) {
8880 GstRTSPStream *stream = (GstRTSPStream *) walk->data;
8881 GstRTSPConnInfo *conninfo;
8882 const gchar *setup_url;
8884 /* try aggregate control first but do non-aggregate control otherwise */
8886 setup_url = control;
8887 else if ((setup_url = stream->conninfo.location) == NULL)
8890 if (src->conninfo.connection) {
8891 conninfo = &src->conninfo;
8892 } else if (stream->conninfo.connection) {
8893 conninfo = &stream->conninfo;
8899 GST_ELEMENT_PROGRESS (src, CONTINUE, "request",
8900 ("Sending PAUSE request"));
8903 gst_rtspsrc_init_request (src, &request, GST_RTSP_PAUSE,
8905 goto create_request_failed;
8907 /* when we have an ONVIF audio backchannel, the PAUSE request must have the
8908 * Require: header when doing either aggregate or non-aggregate control */
8909 if (src->backchannel == BACKCHANNEL_ONVIF &&
8910 (control || stream->is_backchannel))
8911 gst_rtsp_message_add_header (&request, GST_RTSP_HDR_REQUIRE,
8912 BACKCHANNEL_ONVIF_HDR_REQUIRE_VAL);
8915 gst_rtspsrc_send (src, conninfo, &request, &response, NULL,
8919 gst_rtsp_message_unset (&request);
8920 gst_rtsp_message_unset (&response);
8922 /* exit early when we did aggregate control */
8927 /* change element states now */
8928 gst_rtspsrc_set_state (src, GST_STATE_PAUSED);
8931 src->state = GST_RTSP_STATE_READY;
8935 gst_rtspsrc_loop_end_cmd (src, CMD_PAUSE, res);
8942 GST_DEBUG_OBJECT (src, "failed to open stream");
8947 GST_DEBUG_OBJECT (src, "PAUSE is not supported");
8952 GST_DEBUG_OBJECT (src, "we were already PAUSED");
8955 create_request_failed:
8957 gchar *str = gst_rtsp_strresult (res);
8959 GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL),
8960 ("Could not create request. (%s)", str));
8966 gchar *str = gst_rtsp_strresult (res);
8968 gst_rtsp_message_unset (&request);
8969 if (res != GST_RTSP_EINTR) {
8970 GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
8971 ("Could not send message. (%s)", str));
8973 GST_WARNING_OBJECT (src, "PAUSE interrupted");
8981 gst_rtspsrc_handle_message (GstBin * bin, GstMessage * message)
8983 GstRTSPSrc *rtspsrc;
8985 rtspsrc = GST_RTSPSRC (bin);
8987 switch (GST_MESSAGE_TYPE (message)) {
8988 case GST_MESSAGE_STREAM_START:
8989 case GST_MESSAGE_EOS:
8990 gst_message_unref (message);
8992 case GST_MESSAGE_ELEMENT:
8994 const GstStructure *s = gst_message_get_structure (message);
8996 if (gst_structure_has_name (s, "GstUDPSrcTimeout")) {
8997 gboolean ignore_timeout;
8999 GST_DEBUG_OBJECT (bin, "timeout on UDP port");
9001 GST_OBJECT_LOCK (rtspsrc);
9002 ignore_timeout = rtspsrc->ignore_timeout;
9003 rtspsrc->ignore_timeout = TRUE;
9004 GST_OBJECT_UNLOCK (rtspsrc);
9006 /* we only act on the first udp timeout message, others are irrelevant
9007 * and can be ignored. */
9008 if (!ignore_timeout)
9009 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_RECONNECT, CMD_LOOP);
9011 gst_message_unref (message);
9014 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
9017 case GST_MESSAGE_ERROR:
9020 GstRTSPStream *stream;
9023 udpsrc = GST_MESSAGE_SRC (message);
9025 GST_DEBUG_OBJECT (rtspsrc, "got error from %s",
9026 GST_ELEMENT_NAME (udpsrc));
9028 stream = find_stream (rtspsrc, udpsrc, (gpointer) find_stream_by_udpsrc);
9032 /* we ignore the RTCP udpsrc */
9033 if (stream->udpsrc[1] == GST_ELEMENT_CAST (udpsrc))
9036 /* if we get error messages from the udp sources, that's not a problem as
9037 * long as not all of them error out. We also don't really know what the
9038 * problem is, the message does not give enough detail... */
9039 ret = gst_rtspsrc_combine_flows (rtspsrc, stream, GST_FLOW_NOT_LINKED);
9040 GST_DEBUG_OBJECT (rtspsrc, "combined flows: %s", gst_flow_get_name (ret));
9041 if (ret != GST_FLOW_OK)
9045 gst_message_unref (message);
9049 /* fatal but not our message, forward */
9050 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
9055 GST_BIN_CLASS (parent_class)->handle_message (bin, message);
9061 /* the thread where everything happens */
9063 gst_rtspsrc_thread (GstRTSPSrc * src)
9066 ParameterRequest *req = NULL;
9068 GST_OBJECT_LOCK (src);
9069 cmd = src->pending_cmd;
9070 if (cmd == CMD_RECONNECT || cmd == CMD_PLAY || cmd == CMD_PAUSE
9071 || cmd == CMD_LOOP || cmd == CMD_OPEN || cmd == CMD_GET_PARAMETER
9072 || cmd == CMD_SET_PARAMETER) {
9073 if (g_queue_is_empty (&src->set_get_param_q)) {
9074 src->pending_cmd = CMD_LOOP;
9076 ParameterRequest *next_req;
9077 if (cmd == CMD_GET_PARAMETER || cmd == CMD_SET_PARAMETER) {
9078 req = g_queue_pop_head (&src->set_get_param_q);
9080 next_req = g_queue_peek_head (&src->set_get_param_q);
9081 src->pending_cmd = next_req ? next_req->cmd : CMD_LOOP;
9084 src->pending_cmd = CMD_WAIT;
9085 GST_DEBUG_OBJECT (src, "got command %s", cmd_to_string (cmd));
9087 /* we got the message command, so ensure communication is possible again */
9088 gst_rtspsrc_connection_flush (src, FALSE);
9090 src->busy_cmd = cmd;
9091 GST_OBJECT_UNLOCK (src);
9095 gst_rtspsrc_open (src, TRUE);
9098 gst_rtspsrc_play (src, &src->segment, TRUE, NULL);
9101 gst_rtspsrc_pause (src, TRUE);
9104 gst_rtspsrc_close (src, TRUE, FALSE);
9106 case CMD_GET_PARAMETER:
9107 gst_rtspsrc_get_parameter (src, req);
9109 case CMD_SET_PARAMETER:
9110 gst_rtspsrc_set_parameter (src, req);
9113 gst_rtspsrc_loop (src);
9116 gst_rtspsrc_reconnect (src, FALSE);
9122 GST_OBJECT_LOCK (src);
9123 /* No more cmds, wake any waiters */
9124 g_cond_broadcast (&src->cmd_cond);
9125 /* and go back to sleep */
9126 if (src->pending_cmd == CMD_WAIT) {
9128 gst_task_pause (src->task);
9131 src->busy_cmd = CMD_WAIT;
9132 GST_OBJECT_UNLOCK (src);
9136 gst_rtspsrc_start (GstRTSPSrc * src)
9138 GST_DEBUG_OBJECT (src, "starting");
9140 GST_OBJECT_LOCK (src);
9142 src->pending_cmd = CMD_WAIT;
9144 if (src->task == NULL) {
9145 src->task = gst_task_new ((GstTaskFunction) gst_rtspsrc_thread, src, NULL);
9146 if (src->task == NULL)
9149 gst_task_set_lock (src->task, GST_RTSP_STREAM_GET_LOCK (src));
9151 GST_OBJECT_UNLOCK (src);
9158 GST_OBJECT_UNLOCK (src);
9159 GST_ERROR_OBJECT (src, "failed to create task");
9165 gst_rtspsrc_stop (GstRTSPSrc * src)
9169 GST_DEBUG_OBJECT (src, "stopping");
9171 /* also cancels pending task */
9172 gst_rtspsrc_loop_send_cmd (src, CMD_WAIT, CMD_ALL);
9174 GST_OBJECT_LOCK (src);
9175 if ((task = src->task)) {
9177 GST_OBJECT_UNLOCK (src);
9179 gst_task_stop (task);
9181 /* make sure it is not running */
9182 GST_RTSP_STREAM_LOCK (src);
9183 GST_RTSP_STREAM_UNLOCK (src);
9185 /* now wait for the task to finish */
9186 gst_task_join (task);
9188 /* and free the task */
9189 gst_object_unref (GST_OBJECT (task));
9191 GST_OBJECT_LOCK (src);
9193 GST_OBJECT_UNLOCK (src);
9195 /* ensure synchronously all is closed and clean */
9196 gst_rtspsrc_close (src, FALSE, TRUE);
9201 static GstStateChangeReturn
9202 gst_rtspsrc_change_state (GstElement * element, GstStateChange transition)
9204 GstRTSPSrc *rtspsrc;
9205 GstStateChangeReturn ret;
9207 rtspsrc = GST_RTSPSRC (element);
9209 switch (transition) {
9210 case GST_STATE_CHANGE_NULL_TO_READY:
9211 if (!gst_rtspsrc_start (rtspsrc))
9214 case GST_STATE_CHANGE_READY_TO_PAUSED:
9215 /* init some state */
9216 rtspsrc->cur_protocols = rtspsrc->protocols;
9217 /* first attempt, don't ignore timeouts */
9218 rtspsrc->ignore_timeout = FALSE;
9219 rtspsrc->open_error = FALSE;
9220 if (rtspsrc->is_live)
9221 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_OPEN, 0);
9223 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_PLAY, 0);
9225 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
9226 set_manager_buffer_mode (rtspsrc);
9228 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
9229 if (rtspsrc->is_live) {
9230 /* unblock the tcp tasks and make the loop waiting */
9231 if (gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_WAIT, CMD_LOOP)) {
9232 /* make sure it is waiting before we send PAUSE or PLAY below */
9233 GST_RTSP_STREAM_LOCK (rtspsrc);
9234 GST_RTSP_STREAM_UNLOCK (rtspsrc);
9238 case GST_STATE_CHANGE_PAUSED_TO_READY:
9239 rtspsrc->group_id = GST_GROUP_ID_INVALID;
9245 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
9246 if (ret == GST_STATE_CHANGE_FAILURE)
9249 switch (transition) {
9250 case GST_STATE_CHANGE_NULL_TO_READY:
9251 ret = GST_STATE_CHANGE_SUCCESS;
9253 case GST_STATE_CHANGE_READY_TO_PAUSED:
9254 if (rtspsrc->is_live)
9255 ret = GST_STATE_CHANGE_NO_PREROLL;
9257 ret = GST_STATE_CHANGE_SUCCESS;
9259 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
9260 if (rtspsrc->is_live)
9261 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_PLAY, 0);
9262 ret = GST_STATE_CHANGE_SUCCESS;
9264 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
9265 if (rtspsrc->is_live) {
9266 /* send pause request and keep the idle task around */
9267 gst_rtspsrc_loop_send_cmd (rtspsrc, CMD_PAUSE, CMD_LOOP);
9269 ret = GST_STATE_CHANGE_SUCCESS;
9271 case GST_STATE_CHANGE_PAUSED_TO_READY:
9272 rtspsrc->seek_seqnum = GST_SEQNUM_INVALID;
9273 gst_rtspsrc_loop_send_cmd_and_wait (rtspsrc, CMD_CLOSE, CMD_ALL,
9274 rtspsrc->teardown_timeout);
9275 ret = GST_STATE_CHANGE_SUCCESS;
9277 case GST_STATE_CHANGE_READY_TO_NULL:
9278 gst_rtspsrc_stop (rtspsrc);
9279 ret = GST_STATE_CHANGE_SUCCESS;
9282 /* Otherwise it's success, we don't want to return spurious
9283 * NO_PREROLL or ASYNC from internal elements as we care for
9284 * state changes ourselves here
9286 * This is to catch PAUSED->PAUSED and PLAYING->PLAYING transitions.
9288 if (GST_STATE_TRANSITION_NEXT (transition) == GST_STATE_PAUSED)
9289 ret = GST_STATE_CHANGE_NO_PREROLL;
9291 ret = GST_STATE_CHANGE_SUCCESS;
9300 GST_DEBUG_OBJECT (rtspsrc, "start failed");
9301 return GST_STATE_CHANGE_FAILURE;
9306 gst_rtspsrc_send_event (GstElement * element, GstEvent * event)
9309 GstRTSPSrc *rtspsrc;
9311 rtspsrc = GST_RTSPSRC (element);
9313 if (GST_EVENT_TYPE (event) == GST_EVENT_SEEK) {
9314 if (rtspsrc->state >= GST_RTSP_STATE_READY) {
9315 res = gst_rtspsrc_perform_seek (rtspsrc, event);
9316 gst_event_unref (event);
9318 /* Store for later use */
9320 rtspsrc->initial_seek = event;
9322 } else if (GST_EVENT_IS_DOWNSTREAM (event)) {
9323 res = gst_rtspsrc_push_event (rtspsrc, event);
9325 res = GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
9332 /*** GSTURIHANDLER INTERFACE *************************************************/
9335 gst_rtspsrc_uri_get_type (GType type)
9340 static const gchar *const *
9341 gst_rtspsrc_uri_get_protocols (GType type)
9343 static const gchar *protocols[] =
9344 { "rtsp", "rtspu", "rtspt", "rtsph", "rtsp-sdp",
9345 "rtsps", "rtspsu", "rtspst", "rtspsh", NULL
9352 gst_rtspsrc_uri_get_uri (GstURIHandler * handler)
9354 GstRTSPSrc *src = GST_RTSPSRC (handler);
9356 /* FIXME: make thread-safe */
9357 return g_strdup (src->conninfo.location);
9361 gst_rtspsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri,
9367 GstRTSPUrl *newurl = NULL;
9368 GstSDPMessage *sdp = NULL;
9370 src = GST_RTSPSRC (handler);
9372 /* same URI, we're fine */
9373 if (src->conninfo.location && uri && !strcmp (uri, src->conninfo.location))
9376 if (g_str_has_prefix (uri, "rtsp-sdp://")) {
9377 sres = gst_sdp_message_new (&sdp);
9381 GST_DEBUG_OBJECT (src, "parsing SDP message");
9382 sres = gst_sdp_message_parse_uri (uri, sdp);
9387 GST_DEBUG_OBJECT (src, "parsing URI");
9388 if ((res = gst_rtsp_url_parse (uri, &newurl)) < 0)
9392 /* if worked, free previous and store new url object along with the original
9394 GST_DEBUG_OBJECT (src, "configuring URI");
9395 g_free (src->conninfo.location);
9396 src->conninfo.location = g_strdup (uri);
9397 gst_rtsp_url_free (src->conninfo.url);
9398 src->conninfo.url = newurl;
9399 g_free (src->conninfo.url_str);
9401 src->conninfo.url_str = gst_rtsp_url_get_request_uri (src->conninfo.url);
9403 src->conninfo.url_str = NULL;
9406 gst_sdp_message_free (src->sdp);
9408 src->from_sdp = sdp != NULL;
9410 GST_DEBUG_OBJECT (src, "set uri: %s", GST_STR_NULL (uri));
9411 GST_DEBUG_OBJECT (src, "request uri is: %s",
9412 GST_STR_NULL (src->conninfo.url_str));
9419 GST_DEBUG_OBJECT (src, "URI was ok: '%s'", GST_STR_NULL (uri));
9424 GST_ERROR_OBJECT (src, "Could not create new SDP (%d)", sres);
9425 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
9426 "Could not create SDP");
9431 GST_ERROR_OBJECT (src, "Not a valid SDP (%d) '%s'", sres,
9432 GST_STR_NULL (uri));
9433 gst_sdp_message_free (sdp);
9434 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
9440 GST_ERROR_OBJECT (src, "Not a valid RTSP url '%s' (%d)",
9441 GST_STR_NULL (uri), res);
9442 g_set_error_literal (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
9443 "Invalid RTSP URI");
9449 gst_rtspsrc_uri_handler_init (gpointer g_iface, gpointer iface_data)
9451 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
9453 iface->get_type = gst_rtspsrc_uri_get_type;
9454 iface->get_protocols = gst_rtspsrc_uri_get_protocols;
9455 iface->get_uri = gst_rtspsrc_uri_get_uri;
9456 iface->set_uri = gst_rtspsrc_uri_set_uri;
9460 /* send GET_PARAMETER */
9461 static GstRTSPResult
9462 gst_rtspsrc_get_parameter (GstRTSPSrc * src, ParameterRequest * req)
9464 GstRTSPMessage request = { 0 };
9465 GstRTSPMessage response = { 0 };
9467 GstRTSPStatusCode code = GST_RTSP_STS_OK;
9468 const gchar *control;
9469 gchar *recv_body = NULL;
9470 guint recv_body_len;
9472 GST_DEBUG_OBJECT (src, "creating server get_parameter");
9476 if ((res = gst_rtspsrc_ensure_open (src, FALSE)) < 0)
9479 control = get_aggregate_control (src);
9480 if (control == NULL)
9483 if (!(src->methods & GST_RTSP_GET_PARAMETER))
9486 gst_rtspsrc_connection_flush (src, FALSE);
9488 res = gst_rtsp_message_init_request (&request, GST_RTSP_GET_PARAMETER,
9491 goto create_request_failed;
9493 res = gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CONTENT_TYPE,
9494 req->content_type == NULL ? "text/parameters" : req->content_type);
9496 goto add_content_hdr_failed;
9498 if (req->body && req->body->len) {
9500 gst_rtsp_message_set_body (&request, (guint8 *) req->body->str,
9503 goto set_body_failed;
9506 if ((res = gst_rtspsrc_send (src, &src->conninfo,
9507 &request, &response, &code, NULL)) < 0)
9510 res = gst_rtsp_message_get_body (&response, (guint8 **) & recv_body,
9513 goto get_body_failed;
9517 gst_promise_reply (req->promise,
9518 gst_structure_new ("get-parameter-reply",
9519 "rtsp-result", G_TYPE_INT, res,
9520 "rtsp-code", G_TYPE_INT, code,
9521 "rtsp-reason", G_TYPE_STRING, gst_rtsp_status_as_text (code),
9522 "body", G_TYPE_STRING, GST_STR_NULL (recv_body), NULL));
9523 free_param_data (req);
9526 gst_rtsp_message_unset (&request);
9527 gst_rtsp_message_unset (&response);
9535 GST_DEBUG_OBJECT (src, "failed to open stream");
9540 GST_DEBUG_OBJECT (src, "no control url to send GET_PARAMETER");
9541 res = GST_RTSP_ERROR;
9546 GST_DEBUG_OBJECT (src, "GET_PARAMETER is not supported");
9547 res = GST_RTSP_ERROR;
9550 create_request_failed:
9552 GST_DEBUG_OBJECT (src, "could not create GET_PARAMETER request");
9555 add_content_hdr_failed:
9557 GST_DEBUG_OBJECT (src, "could not add content header");
9562 GST_DEBUG_OBJECT (src, "could not set body");
9567 gchar *str = gst_rtsp_strresult (res);
9569 GST_ELEMENT_WARNING (src, RESOURCE, WRITE, (NULL),
9570 ("Could not send get-parameter. (%s)", str));
9576 GST_DEBUG_OBJECT (src, "could not get body");
9581 /* send SET_PARAMETER */
9582 static GstRTSPResult
9583 gst_rtspsrc_set_parameter (GstRTSPSrc * src, ParameterRequest * req)
9585 GstRTSPMessage request = { 0 };
9586 GstRTSPMessage response = { 0 };
9587 GstRTSPResult res = GST_RTSP_OK;
9588 GstRTSPStatusCode code = GST_RTSP_STS_OK;
9589 const gchar *control;
9591 GST_DEBUG_OBJECT (src, "creating server set_parameter");
9595 if ((res = gst_rtspsrc_ensure_open (src, FALSE)) < 0)
9598 control = get_aggregate_control (src);
9599 if (control == NULL)
9602 if (!(src->methods & GST_RTSP_SET_PARAMETER))
9605 gst_rtspsrc_connection_flush (src, FALSE);
9608 gst_rtsp_message_init_request (&request, GST_RTSP_SET_PARAMETER, control);
9612 res = gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CONTENT_TYPE,
9613 req->content_type == NULL ? "text/parameters" : req->content_type);
9615 goto add_content_hdr_failed;
9617 if (req->body && req->body->len) {
9619 gst_rtsp_message_set_body (&request, (guint8 *) req->body->str,
9623 goto set_body_failed;
9626 if ((res = gst_rtspsrc_send (src, &src->conninfo,
9627 &request, &response, &code, NULL)) < 0)
9632 gst_promise_reply (req->promise, gst_structure_new ("set-parameter-reply",
9633 "rtsp-result", G_TYPE_INT, res,
9634 "rtsp-code", G_TYPE_INT, code,
9635 "rtsp-reason", G_TYPE_STRING, gst_rtsp_status_as_text (code),
9637 free_param_data (req);
9639 gst_rtsp_message_unset (&request);
9640 gst_rtsp_message_unset (&response);
9648 GST_DEBUG_OBJECT (src, "failed to open stream");
9653 GST_DEBUG_OBJECT (src, "no control url to send SET_PARAMETER");
9654 res = GST_RTSP_ERROR;
9659 GST_DEBUG_OBJECT (src, "SET_PARAMETER is not supported");
9660 res = GST_RTSP_ERROR;
9663 add_content_hdr_failed:
9665 GST_DEBUG_OBJECT (src, "could not add content header");
9670 GST_DEBUG_OBJECT (src, "could not set body");
9675 gchar *str = gst_rtsp_strresult (res);
9677 GST_ELEMENT_WARNING (src, RESOURCE, WRITE, (NULL),
9678 ("Could not send set-parameter. (%s)", str));
9684 typedef struct _RTSPKeyValue
9686 GstRTSPHeaderField field;
9688 gchar *custom_key; /* custom header string (field is INVALID then) */
9692 key_value_foreach (GArray * array, GFunc func, gpointer user_data)
9696 g_return_if_fail (array != NULL);
9698 for (i = 0; i < array->len; i++) {
9699 (*func) (&g_array_index (array, RTSPKeyValue, i), user_data);
9704 dump_key_value (gpointer data, gpointer user_data G_GNUC_UNUSED)
9706 RTSPKeyValue *key_value = (RTSPKeyValue *) data;
9707 GstRTSPSrc *src = GST_RTSPSRC (user_data);
9708 const gchar *key_string;
9710 if (key_value->custom_key != NULL)
9711 key_string = key_value->custom_key;
9713 key_string = gst_rtsp_header_as_text (key_value->field);
9715 GST_LOG_OBJECT (src, " key: '%s', value: '%s'", key_string,
9720 gst_rtspsrc_print_rtsp_message (GstRTSPSrc * src, const GstRTSPMessage * msg)
9724 GString *body_string = NULL;
9726 g_return_if_fail (src != NULL);
9727 g_return_if_fail (msg != NULL);
9729 if (gst_debug_category_get_threshold (GST_CAT_DEFAULT) < GST_LEVEL_LOG)
9732 GST_LOG_OBJECT (src, "--------------------------------------------");
9733 switch (msg->type) {
9734 case GST_RTSP_MESSAGE_REQUEST:
9735 GST_LOG_OBJECT (src, "RTSP request message %p", msg);
9736 GST_LOG_OBJECT (src, " request line:");
9737 GST_LOG_OBJECT (src, " method: '%s'",
9738 gst_rtsp_method_as_text (msg->type_data.request.method));
9739 GST_LOG_OBJECT (src, " uri: '%s'", msg->type_data.request.uri);
9740 GST_LOG_OBJECT (src, " version: '%s'",
9741 gst_rtsp_version_as_text (msg->type_data.request.version));
9742 GST_LOG_OBJECT (src, " headers:");
9743 key_value_foreach (msg->hdr_fields, dump_key_value, src);
9744 GST_LOG_OBJECT (src, " body:");
9745 gst_rtsp_message_get_body (msg, &data, &size);
9747 body_string = g_string_new_len ((const gchar *) data, size);
9748 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9749 g_string_free (body_string, TRUE);
9753 case GST_RTSP_MESSAGE_RESPONSE:
9754 GST_LOG_OBJECT (src, "RTSP response message %p", msg);
9755 GST_LOG_OBJECT (src, " status line:");
9756 GST_LOG_OBJECT (src, " code: '%d'", msg->type_data.response.code);
9757 GST_LOG_OBJECT (src, " reason: '%s'", msg->type_data.response.reason);
9758 GST_LOG_OBJECT (src, " version: '%s",
9759 gst_rtsp_version_as_text (msg->type_data.response.version));
9760 GST_LOG_OBJECT (src, " headers:");
9761 key_value_foreach (msg->hdr_fields, dump_key_value, src);
9762 gst_rtsp_message_get_body (msg, &data, &size);
9763 GST_LOG_OBJECT (src, " body: length %d", size);
9765 body_string = g_string_new_len ((const gchar *) data, size);
9766 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9767 g_string_free (body_string, TRUE);
9771 case GST_RTSP_MESSAGE_HTTP_REQUEST:
9772 GST_LOG_OBJECT (src, "HTTP request message %p", msg);
9773 GST_LOG_OBJECT (src, " request line:");
9774 GST_LOG_OBJECT (src, " method: '%s'",
9775 gst_rtsp_method_as_text (msg->type_data.request.method));
9776 GST_LOG_OBJECT (src, " uri: '%s'", msg->type_data.request.uri);
9777 GST_LOG_OBJECT (src, " version: '%s'",
9778 gst_rtsp_version_as_text (msg->type_data.request.version));
9779 GST_LOG_OBJECT (src, " headers:");
9780 key_value_foreach (msg->hdr_fields, dump_key_value, src);
9781 GST_LOG_OBJECT (src, " body:");
9782 gst_rtsp_message_get_body (msg, &data, &size);
9784 body_string = g_string_new_len ((const gchar *) data, size);
9785 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9786 g_string_free (body_string, TRUE);
9790 case GST_RTSP_MESSAGE_HTTP_RESPONSE:
9791 GST_LOG_OBJECT (src, "HTTP response message %p", msg);
9792 GST_LOG_OBJECT (src, " status line:");
9793 GST_LOG_OBJECT (src, " code: '%d'", msg->type_data.response.code);
9794 GST_LOG_OBJECT (src, " reason: '%s'", msg->type_data.response.reason);
9795 GST_LOG_OBJECT (src, " version: '%s'",
9796 gst_rtsp_version_as_text (msg->type_data.response.version));
9797 GST_LOG_OBJECT (src, " headers:");
9798 key_value_foreach (msg->hdr_fields, dump_key_value, src);
9799 gst_rtsp_message_get_body (msg, &data, &size);
9800 GST_LOG_OBJECT (src, " body: length %d", size);
9802 body_string = g_string_new_len ((const gchar *) data, size);
9803 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9804 g_string_free (body_string, TRUE);
9808 case GST_RTSP_MESSAGE_DATA:
9809 GST_LOG_OBJECT (src, "RTSP data message %p", msg);
9810 GST_LOG_OBJECT (src, " channel: '%d'", msg->type_data.data.channel);
9811 GST_LOG_OBJECT (src, " size: '%d'", msg->body_size);
9812 gst_rtsp_message_get_body (msg, &data, &size);
9814 body_string = g_string_new_len ((const gchar *) data, size);
9815 GST_LOG_OBJECT (src, " %s(%d)", body_string->str, size);
9816 g_string_free (body_string, TRUE);
9821 GST_LOG_OBJECT (src, "unsupported message type %d", msg->type);
9824 GST_LOG_OBJECT (src, "--------------------------------------------");
9828 gst_rtspsrc_print_sdp_media (GstRTSPSrc * src, GstSDPMedia * media)
9830 GST_LOG_OBJECT (src, " media: '%s'", GST_STR_NULL (media->media));
9831 GST_LOG_OBJECT (src, " port: '%u'", media->port);
9832 GST_LOG_OBJECT (src, " num_ports: '%u'", media->num_ports);
9833 GST_LOG_OBJECT (src, " proto: '%s'", GST_STR_NULL (media->proto));
9834 if (media->fmts && media->fmts->len > 0) {
9837 GST_LOG_OBJECT (src, " formats:");
9838 for (i = 0; i < media->fmts->len; i++) {
9839 GST_LOG_OBJECT (src, " format '%s'", g_array_index (media->fmts,
9843 GST_LOG_OBJECT (src, " information: '%s'",
9844 GST_STR_NULL (media->information));
9845 if (media->connections && media->connections->len > 0) {
9848 GST_LOG_OBJECT (src, " connections:");
9849 for (i = 0; i < media->connections->len; i++) {
9850 GstSDPConnection *conn =
9851 &g_array_index (media->connections, GstSDPConnection, i);
9853 GST_LOG_OBJECT (src, " nettype: '%s'",
9854 GST_STR_NULL (conn->nettype));
9855 GST_LOG_OBJECT (src, " addrtype: '%s'",
9856 GST_STR_NULL (conn->addrtype));
9857 GST_LOG_OBJECT (src, " address: '%s'",
9858 GST_STR_NULL (conn->address));
9859 GST_LOG_OBJECT (src, " ttl: '%u'", conn->ttl);
9860 GST_LOG_OBJECT (src, " addr_number: '%u'", conn->addr_number);
9863 if (media->bandwidths && media->bandwidths->len > 0) {
9866 GST_LOG_OBJECT (src, " bandwidths:");
9867 for (i = 0; i < media->bandwidths->len; i++) {
9868 GstSDPBandwidth *bw =
9869 &g_array_index (media->bandwidths, GstSDPBandwidth, i);
9871 GST_LOG_OBJECT (src, " type: '%s'", GST_STR_NULL (bw->bwtype));
9872 GST_LOG_OBJECT (src, " bandwidth: '%u'", bw->bandwidth);
9875 GST_LOG_OBJECT (src, " key:");
9876 GST_LOG_OBJECT (src, " type: '%s'", GST_STR_NULL (media->key.type));
9877 GST_LOG_OBJECT (src, " data: '%s'", GST_STR_NULL (media->key.data));
9878 if (media->attributes && media->attributes->len > 0) {
9881 GST_LOG_OBJECT (src, " attributes:");
9882 for (i = 0; i < media->attributes->len; i++) {
9883 GstSDPAttribute *attr =
9884 &g_array_index (media->attributes, GstSDPAttribute, i);
9886 GST_LOG_OBJECT (src, " attribute '%s' : '%s'", attr->key, attr->value);
9892 gst_rtspsrc_print_sdp_message (GstRTSPSrc * src, const GstSDPMessage * msg)
9894 g_return_if_fail (src != NULL);
9895 g_return_if_fail (msg != NULL);
9897 if (gst_debug_category_get_threshold (GST_CAT_DEFAULT) < GST_LEVEL_LOG)
9900 GST_LOG_OBJECT (src, "--------------------------------------------");
9901 GST_LOG_OBJECT (src, "sdp packet %p:", msg);
9902 GST_LOG_OBJECT (src, " version: '%s'", GST_STR_NULL (msg->version));
9903 GST_LOG_OBJECT (src, " origin:");
9904 GST_LOG_OBJECT (src, " username: '%s'",
9905 GST_STR_NULL (msg->origin.username));
9906 GST_LOG_OBJECT (src, " sess_id: '%s'",
9907 GST_STR_NULL (msg->origin.sess_id));
9908 GST_LOG_OBJECT (src, " sess_version: '%s'",
9909 GST_STR_NULL (msg->origin.sess_version));
9910 GST_LOG_OBJECT (src, " nettype: '%s'",
9911 GST_STR_NULL (msg->origin.nettype));
9912 GST_LOG_OBJECT (src, " addrtype: '%s'",
9913 GST_STR_NULL (msg->origin.addrtype));
9914 GST_LOG_OBJECT (src, " addr: '%s'", GST_STR_NULL (msg->origin.addr));
9915 GST_LOG_OBJECT (src, " session_name: '%s'",
9916 GST_STR_NULL (msg->session_name));
9917 GST_LOG_OBJECT (src, " information: '%s'", GST_STR_NULL (msg->information));
9918 GST_LOG_OBJECT (src, " uri: '%s'", GST_STR_NULL (msg->uri));
9920 if (msg->emails && msg->emails->len > 0) {
9923 GST_LOG_OBJECT (src, " emails:");
9924 for (i = 0; i < msg->emails->len; i++) {
9925 GST_LOG_OBJECT (src, " email '%s'", g_array_index (msg->emails, gchar *,
9929 if (msg->phones && msg->phones->len > 0) {
9932 GST_LOG_OBJECT (src, " phones:");
9933 for (i = 0; i < msg->phones->len; i++) {
9934 GST_LOG_OBJECT (src, " phone '%s'", g_array_index (msg->phones, gchar *,
9938 GST_LOG_OBJECT (src, " connection:");
9939 GST_LOG_OBJECT (src, " nettype: '%s'",
9940 GST_STR_NULL (msg->connection.nettype));
9941 GST_LOG_OBJECT (src, " addrtype: '%s'",
9942 GST_STR_NULL (msg->connection.addrtype));
9943 GST_LOG_OBJECT (src, " address: '%s'",
9944 GST_STR_NULL (msg->connection.address));
9945 GST_LOG_OBJECT (src, " ttl: '%u'", msg->connection.ttl);
9946 GST_LOG_OBJECT (src, " addr_number: '%u'", msg->connection.addr_number);
9947 if (msg->bandwidths && msg->bandwidths->len > 0) {
9950 GST_LOG_OBJECT (src, " bandwidths:");
9951 for (i = 0; i < msg->bandwidths->len; i++) {
9952 GstSDPBandwidth *bw =
9953 &g_array_index (msg->bandwidths, GstSDPBandwidth, i);
9955 GST_LOG_OBJECT (src, " type: '%s'", GST_STR_NULL (bw->bwtype));
9956 GST_LOG_OBJECT (src, " bandwidth: '%u'", bw->bandwidth);
9959 GST_LOG_OBJECT (src, " key:");
9960 GST_LOG_OBJECT (src, " type: '%s'", GST_STR_NULL (msg->key.type));
9961 GST_LOG_OBJECT (src, " data: '%s'", GST_STR_NULL (msg->key.data));
9962 if (msg->attributes && msg->attributes->len > 0) {
9965 GST_LOG_OBJECT (src, " attributes:");
9966 for (i = 0; i < msg->attributes->len; i++) {
9967 GstSDPAttribute *attr =
9968 &g_array_index (msg->attributes, GstSDPAttribute, i);
9970 GST_LOG_OBJECT (src, " attribute '%s' : '%s'", attr->key, attr->value);
9973 if (msg->medias && msg->medias->len > 0) {
9976 GST_LOG_OBJECT (src, " medias:");
9977 for (i = 0; i < msg->medias->len; i++) {
9978 GST_LOG_OBJECT (src, " media %u:", i);
9979 gst_rtspsrc_print_sdp_media (src, &g_array_index (msg->medias,
9983 GST_LOG_OBJECT (src, "--------------------------------------------");